/** * @see https://developers.google.com/google-apps/calendar/v3/reference/events/list * @param string $calendarId * @param DateTime $start * @param DateTime $end * @param boolean $singleEvents * @param int $maxResults * @return Google_Service_Calendar_EventList */ function cob_calendar_events($calendarId, \DateTime $start = null, \DateTime $end = null, $singleEvents = true, $maxResults = null) { $FIELDS = 'description,end,endTimeUnspecified,htmlLink,id,location,' . 'originalStartTime,recurrence,recurringEventId,sequence,' . 'start,summary,attendees,organizer'; $opts = ['fields' => "items({$FIELDS})", 'singleEvents' => $singleEvents, 'maxResults' => $maxResults]; if ($singleEvents) { $opts['orderBy'] = 'startTime'; } if ($start) { $opts['timeMin'] = $start->format(\DateTime::RFC3339); } if ($end) { $opts['timeMax'] = $end->format(\DateTime::RFC3339); } $service = cob_calendar_service(); $events = $service->events->listEvents($calendarId, $opts); return $events; }
<?php /** * @copyright 2015 City of Bloomington, Indiana * @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt * @param array $data['calendarId' => '', 'type' => ''] */ $service = cob_calendar_service(); $calendar = $service->calendars->get($data['calendarId']); $events = cob_calendar_events($data['calendarId'], new \DateTime(), null, true, 4); /*echo '<pre>'; print_r($events); echo '</pre>'; */ if ($calendar) { $title = $data['type'] == 'board_commission' ? 'Meeting Schedule' : $calendar->summary; $url = cob_calendar_url($data['calendarId']); echo "\n <section class=\"cob-upcomingEvents\">\n <header class=\"cob-upcomingEvents-header\">\n <h1>{$title}</h1>\n <a href=\"{$url}\" target=\"_blank\">View Google Calendar</a>\n </header>\n "; if (count($events)) { echo '<ol class="cob-upcomingEvents-list">'; foreach ($events as $e) { if ($e->start->dateTime) { $allDay = false; $start = new \DateTime($e->start->dateTime); $end = new \DateTime($e->end->dateTime); } else { # All day event $allDay = true; $start = new \DateTime($e->start->date); $end = new \DateTime($e->end->date); }