Reputation: 367
I try realize two ways sync app with google calendar. I didn't find reasonable description how recurrence events work. Are they physically duplicated (have own IDs) within main event? Google calendar API (listEvents) return only main event with recurrences (string). When recurrences have not own IDs, how can I delete them? When I delete one recurrenced event from series (in google calendar) in data from API (listEvents) isn't any mention about that missing recurrenced event.
Upvotes: 0
Views: 2279
Reputation: 51
Recurring event is the series of single events (instances). You can read about instances by the following link: https://developers.google.com/google-apps/calendar/v3/reference/events/instances
If you want to delete recurring event (all instances) you need to use the following code:
$rec_event = $this->calendar->events->get('primary', $google_event_id);
if ($rec_event && $rec_event->getStatus() != "cancelled") {
$this->calendar->events->delete('primary', $google_event_id); // $google_event_id is id of main event with recurrences
}
If you want to delete all following instances from some date you need to get all instances after that date and then delete them in cycle:
$opt_params = array('timeMin' => $isoDate); // date of DATE_RFC3339 format, "Y-m-d\TH:i:sP"
$instances = $this->calendar->events->instances($this->calendar_id, $google_event_id, $opt_params);
if ($instances && count($instances->getItems())) {
foreach ($instances->getItems() as $instance) {
$this->calendar->events->delete('primary', $instance->getId());
}
}
If you want to add exception (remove only one instance of recurred event) need to use almost the same code but with another filter:
$opt_params = array('originalStart' => $isoDate); // exception date
$instances = $this->calendar->events->instances($this->calendar_id, $google_event_id, $opt_params);
if ($instances && count($instances->getItems())) {
foreach ($instances->getItems() as $instance) {
$this->calendar->events->delete('primary', $instance->getId());
}
}
Upvotes: 1