public function processCalendarData() { $rawData = GoogleCalenderUtil::create()->getEvents(); if (!$rawData) { $this->log("Error fetching google calendar events"); return; } $calEventsData = $rawData['items']; $total = count($calEventsData); $count = 0; $this->log("{$total} events to processed"); foreach ($calEventsData as $calEventData) { $count++; $gcEvent = GoogleCalendarEvent::create_or_update($calEventData); if ($gcEvent->EventID) { // Update existing $action = "Updated"; $event = $gcEvent->updateExistingEvent(); } else { // Create new $action = "Created"; $event = $gcEvent->createNewEvent(); } $this->log("{$count}/{$total} :: {$action} event {$event->Title} ({$event->ID})"); } }
/** * Add event to calendar * * @param GoogleCalendarEvent $event */ function AddEvent($event) { $req = $this->Request( "http://www.google.com/calendar/feeds/default/private/full", $event->__toString(), array("Content-type: application/atom+xml"), "POST", 0 ); // Get confirm URL preg_match("/Location: ([^\n]+)\n/i", $req, $matches); $confirm_url = $matches[1]; // Get result data $result = $this->Request(trim($confirm_url), $event->__toString(), array("Content-type: application/atom+xml"), "POST"); return stristr($result, "201 Created"); }