X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=production%2Fexample_apps%2Fshared_calendar%2Fsrc%2FView%2FCell%2FGoogleCalendarCell.php;fp=production%2Fexample_apps%2Fshared_calendar%2Fsrc%2FView%2FCell%2FGoogleCalendarCell.php;h=b1ccf47ac9e5e5f98cdc9f85c9978ef4c000c734;hb=34d1cb2e8687b826357db1d3821bf9e05cf6f13d;hp=0000000000000000000000000000000000000000;hpb=21f30bb859e6c15393e23ac0e5ef417b82f628a5;p=feisty_meow.git diff --git a/production/example_apps/shared_calendar/src/View/Cell/GoogleCalendarCell.php b/production/example_apps/shared_calendar/src/View/Cell/GoogleCalendarCell.php new file mode 100644 index 00000000..b1ccf47a --- /dev/null +++ b/production/example_apps/shared_calendar/src/View/Cell/GoogleCalendarCell.php @@ -0,0 +1,129 @@ +setTime(0, 0); + } + + if (! $endTime ) { + $endTime = new DateTime($startTime->format('c')); + $endTime->modify ( "+31 day" ); // month from now (ish). + } + + Log::debug ( 'start: ' . $startTime->format ( 'c' ) . ' end: ' . $endTime->format('c')); + + $optParams = array ( + // 'maxResults' => 100, + 'orderBy' => 'startTime', + 'singleEvents' => TRUE, + 'timeMin' => $startTime->format('c'), + 'timeMax' => $endTime->format ( 'c' ) + ); + + try { + $results = $cal->events->listEvents ( $calendarId, $optParams ); + } catch (\Exception $e) { + Log::debug('caught an exception from listing events!'); + return null; + } + + Log::debug ( 'after listEvents call.' ); + + // the calEvents array will be an associative array where the keys are the + // dates that events start. the value stored for each key is in turn an associative array of + // good stuff about the event. the good stuff includes 'info', for the appointment description, + // 'start' for the starting date (plus time perhaps), and 'event' for the raw google event + // contents. + $calEvents = [ ]; + + if (count ( $results->getItems () ) == 0) { + // nothing to add to array. + } else { + foreach ( $results->getItems () as $event ) { + $info = $event->getSummary (); + + $start = $event->start->dateTime; + if (empty ( $start )) { + // simple index by date. + $index = $event->start->date; + $start = 'All Day'; // our time mutates. + } else { + // make the index from just the date portion. + $bits = str_split($start, strpos($start, 'T')); + $index = $bits[0]; + + // clean up the time portion for presentation. + $date = new DateTime($start); + $start = $date->format('H:i:s'); + + //Log::debug('chopped time of start is: ' . $start); + } + + $existing_entry = []; + if (array_key_exists($index, $calEvents)) { + $existing_entry = $calEvents[$index]; + } + + array_push ( $existing_entry, [ + 'info' => $info, + 'start' => $start, + 'event' => $event, + ] ); + + $calEvents[$index] = $existing_entry; + } + } + + return $calEvents; + } + + /** + * Default display method. + * + * needs to be passed a GoogleClient object that has already been configured with a valid + * access token. + * + * @return void + */ + public function display($calEvents) + { + + $this->set ( 'calEvents', $calEvents ); + } +}