- //Locked session
- if (!empty($session['locked']) && $events[$sessionId]) {
- //With events
- if (!empty($event = $events[$sessionId])) {
- try {
- //Delete the event
- $googleCalendar->events->delete($token['calendar'], $event->getId());
- //Catch exception
- } catch(\Google\Service\Exception $e) {
- //Display exception
- //TODO: handle codes here https://developers.google.com/calendar/api/guides/errors
- echo 'Exception '.$e->getCode().':'.$e->getMessage().' in '.$e->getFile().' +'.$e->getLine()."\n";
- echo $e->getTraceAsString()."\n";
-
- //Return failure
- return self::FAILURE;
- }
- }
- //Without event
- } elseif (empty($events[$sessionId])) {
- //Init event
- $event = new \Google\Service\Calendar\Event(
- [
- //TODO: replace 'airlibre' with $this->config['calendar']['prefix'] when possible with prefix validating [a-v0-9]{5,}
- //XXX: see https://developers.google.com/calendar/api/v3/reference/events/insert#id
- 'id' => $token['prefix'].$sessionId,
- #'summary' => $session['au_pseudonym'].' '.$this->translator->trans('at '.$session['l_title']),
- 'summary' => $source['title'],
- #'description' => $markdown->convert(strip_tags($session['p_description'])),
- 'description' => $description,
- 'status' => empty($session['a_canceled'])?'confirmed':'cancelled',
- 'location' => implode(' ', [$session['l_address'], $session['l_zipcode'], $session['l_city']]),
- 'source' => $source,
- 'extendedProperties' => [
- 'shared' => $shared
- ],
- //TODO: colorId ?
- //TODO: attendees[] ?
- 'start' => [
- 'dateTime' => $session['start']->format(\DateTime::ISO8601)
- ],
- 'end' => [
- 'dateTime' => $session['stop']->format(\DateTime::ISO8601)
- ]
- ]
- );
-
- try {
- //Insert the event
- $googleCalendar->events->insert($token['calendar'], $event);
- //Catch exception
- } catch(\Google\Service\Exception $e) {
- //Display exception
- //TODO: handle codes here https://developers.google.com/calendar/api/guides/errors
- echo 'Exception '.$e->getCode().':'.$e->getMessage().' in '.$e->getFile().' +'.$e->getLine()."\n";
- echo $e->getTraceAsString()."\n";
-
- //Return failure
- return self::FAILURE;
- }
- // With event
- } else {
- //Set event
- $event = $events[$sessionId];