Exemplo n.º 1
0
 public function addEvent(GoogleEvent $event)
 {
     $this->events[$event->getStart()->format(self::DATE_FORMAT)][$event->id] = $event;
     $this->events[$event->getEnd()->format(self::DATE_FORMAT)][$event->id] = $event;
 }
Exemplo n.º 2
0
 /**
  * Load events from Google Calendar via API or from cache
  * @return \EventCalendar\Goog\GoogData
  * @throws GoogApiException
  */
 public function loadEvents()
 {
     // return from cache
     if (isset($this->cache)) {
         $alreadySaved = $this->cache->load($this->year . '-' . $this->month);
         if ($alreadySaved) {
             return $alreadySaved;
         }
     }
     // load via api
     $json = json_decode($this->loadByApi());
     if (isset($json->error)) {
         throw new GoogApiException($json->error->message, $json->error->code);
     }
     $googData = new GoogData();
     $googData->setName($json->summary);
     $googData->setDescription($json->description);
     if (isset($json->items)) {
         foreach ($json->items as $item) {
             $event = new GoogleEvent($item->id);
             $event->setStatus($item->status)->setSummary($item->summary)->setCreated($item->created)->setUpdated($item->updated)->setHtmlLink($item->htmlLink)->setStart($item->start->dateTime)->setEnd($item->end->dateTime);
             if (isset($item->location)) {
                 $event->setLocation($item->location);
             }
             if (isset($item->description)) {
                 $event->setDescription($item->description);
             }
             $googData->addEvent($event);
         }
     }
     // save loaded data to cache
     if (isset($this->cache)) {
         if (isset($this->cacheExpiration)) {
             $dependencies = array(Cache::EXPIRATION => $this->cacheExpiration->getTimestamp());
         } else {
             $dependencies = null;
         }
         $this->cache->save($this->year . '-' . $this->month, $googData, $dependencies);
     }
     return $googData;
 }