you can try to hook into em_event_save filter and to check if the event date already exists or not.
Thread Starter
grebos
(@grebos)
Thanks, I thought, that it should be something like that. How can I check if the event date already exists?
you might need to use custom sql query to check if the event date exists using wpdb – https://codex.ww.wp.xz.cn/Class_Reference/wpdb
Thread Starter
grebos
(@grebos)
Thanks, i made it now like this with the em_event_validate filter and a ckeckbox field to ignore the collision
I used the fpllowing function to get the events which collide with the new one
$dateCollisionArray = EM_Events::get(array('scope'=>$startdate.','.$enddate));
add_filter('em_event_validate','my_em_validateFunction');
function my_em_validateFunction( $isValid ) {
global $EM_Event;
$startdate = $EM_Event ->event_start_date;
$enddate = $EM_Event ->event_end_date;
$hasNoDateCollisionProblem = true;
$ignoreCollision = $EM_Event->event_attributes["Ignore date collision"] != "";
$dateCollisionArray = EM_Events::get(array('scope'=>$startdate.','.$enddate));
//Delete current event from collision array
if(($key = array_search($EM_Event, $dateCollisionArray)) !== false) {
unset($dateCollisionArray[$key]);
}
if($startdate != "" && count($dateCollisionArray)>0 && !$ignoreCollision){
$hasNoDateCollisionProblem = false;
$dateCollisionError = 'The event is at the same time as: <ul>';
foreach($dateCollisionArray as $collisionDate){
$eventStartDate = $collisionDate->event_start_date;
$eventEndDate = $collisionDate->event_end_date;
//make that the date is displayed properly
$dateCollisionError .= '<li> '.implode('.', array_reverse(explode('-', $eventStartDate)));
if($eventStartDate != $eventEndDate){
$dateCollisionError .= ' - '.implode('.', array_reverse(explode('-', $eventEndDate)));
}
//EM_URI is th URL of the event directory, slug is the URL name of the event, target="_blank" opens new tab
$dateCollisionError .= ' <a target="_blank" href="'.EM_URI.'/'.$collisionDate->slug.'">'.$collisionDate->event_name.'</a></li>';
}
$dateCollisionError .= '</ul>';
$EM_Event->add_error($dateCollisionError);
}
return $isValid && $hasNoDateCollisionProblem;
}
-
This reply was modified 8 years, 9 months ago by
grebos.