I have a complex scenario in which i want to implement. I am using Full Calendar v4.4.0 and for showing recurring events i am using rrule plugin. I am loading events from mysql. I am succesfull in loading them and showing them on website. Its working perfectly fine but now the client has come up with another requirement.
As told earlier i am using rrule plugin to show recurring events. In my portal there are only 2 recurring events
- Weekly
- Monthly
Now client wants to delete an event e.g, an event which is occurring weekly he wants to delete it for one time. For example an event is added on 13th April and is repeated every week. That is he wants to delete the event for 27th April only and want to continue with the sequence as it is. How can i achieve it as the event id is same for all repeating events.
It needs to be mention that i am using Mysql from where the events are coming.
My Code for Loading events
$model = Event::find()->all(); // getting all events
foreach ($model as $mod)
{
$day=array();
if ($mod->event_frequency==2)
{
$start=date('N', strtotime($mod->start_time));
$end=date('N', strtotime($mod->end_time));
if($start==$end)
{
$day[]=$start;
}
else
{
$day[]=$start;
$day[]=$end;
}
$data[]=[
'id' =>$mod->id,
'title'=>$mod->event_name,
// 'start' => $mod->start_time,
// 'end' => $mod->end_time,
'backgroundColor' => $mod->event_tag_color,
'textColor' => '#FFF',
'rrule'=> [
'freq'=> 'WEEKLY',
'interval'=> 1,
'dtstart'=> $mod->start_time,
'until' => '2022-12-31',
],
];
}
else if($mod->event_frequency==3)
{
$start=date('N', strtotime($mod->start_time));
$end=date('N', strtotime($mod->end_time));
if($start==$end)
{
$day[]=$start;
}
else
{
$day[]=$start;
$day[]=$end;
}
$data[]=[
'id' =>$mod->id,
'title'=>$mod->event_name,
// 'start' => $mod->start_time,
// 'end' => $mod->end_time,
'backgroundColor' => $mod->event_tag_color,
'textColor' => '#FFF',
'rrule'=> [
'freq'=> 'MONTHLY',
'interval'=> 1,
'dtstart'=> $mod->start_time,
'until' => '2022-12-31',
],
];
}
else
{
$data[]=[
'id' =>$mod->id,
'title'=>$mod->event_name,
'start' => $mod->start_time,
'end' => $mod->end_time,
'backgroundColor' => $mod->event_tag_color,
'textColor' => '#FFF',
];
}
}
return JSON::encode($data);
the calender.js for loading is as follows
var calendarEl = document.getElementById('calendar-event');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['interaction', 'dayGrid', 'timeGrid', 'list','rrule'],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
},
navLinks: true, // can click day/week names to navigate views
businessHours: true, // display business hours
editable: true,
//uncomment to have a default date
//defaultDate: '2020-04-07',
events: url+'calender/load', // loading events
}
Deleting an event on server
$event_id=Yii::$app->request->post('event_id');
$model= Event::findOne($event_id);
$model->delete();
$response= array();
$response['status']="ok";
return JSON::encode($response);
The js file calling the action delete action
$(".delete-event-calender").on("click",function(evt) {
$data=$('form').serialize();
$url=$(this).data('url');
$.ajax({
type: "POST",
url: $url,
data: $data,
dataType: "json",
traditional: true,
success: function (response) {
//alert(response.status);
if (response.status==="ok"){
calendar.refetchEvents();
$(".ajax_form").trigger("reset");
}
else
{
}
},
error: function (response) {
debugger;
alert(response.d);
}
});
});
If i try to delete the event for 27th April it will take the event id of main event (The day it was set) and will delete whole sequence? How can i prevent it.
How can i achieve it? Any suggestions please
Thanks