/**
  * Initialize the calendar repository
  */
 public function loadCalendars()
 {
     $calendars = $this->googleCalendarService->fetchCalendars();
     foreach ($calendars->getItems() as $calendarItem) {
         $calendar = $this->findById($calendarItem->getId())->getFirst();
         if ($calendar === NULL) {
             $calendar = \KevinDitscheid\KdCalendar\Domain\Model\Calendar::convert($calendarItem);
             $this->add($calendar);
         } else {
             $calendar = \KevinDitscheid\KdCalendar\Domain\Model\Calendar::convert($calendarItem, $calendar);
             $this->update($calendar);
         }
     }
     $this->persistCalendars();
 }
Example #2
0
 /**
  * Initialize the event repository
  *
  * @param int $limit
  * @param \DateTime $date
  *
  * @return void
  */
 public function loadEvents($limit = 0, $date = NULL)
 {
     $events = $this->googleCalendarService->fetchEvents($this->calendar->getId(), $limit, $date);
     foreach ($events->getItems() as $eventItem) {
         $event = $this->findById($eventItem->getId())->getFirst();
         if ($event === NULL) {
             $event = \KevinDitscheid\KdCalendar\Domain\Model\Event::convert($eventItem);
             $event->setCalendar($this->calendar);
             $this->add($event);
         } else {
             $event = \KevinDitscheid\KdCalendar\Domain\Model\Event::convert($eventItem, $event);
             $event->setCalendar($this->calendar);
             $this->update($event);
         }
     }
     $this->persistEvents();
 }
 /**
  * Action to authenticate the google calendar
  *
  * @param string $authCode
  * @param bool $eventsLoaded
  * @param bool $eventsFlushed
  */
 public function authenticateAction($authCode = NULL, $eventsLoaded = FALSE, $eventsFlushed = FALSE)
 {
     if ($authCode) {
         $this->googleService->createCredentials($authCode);
     }
     try {
         $credentials = $this->googleService->getCredentials();
     } catch (\KevinDitscheid\KdCalendar\Exception\NoCredentialsException $ex) {
         $authUrl = $this->googleService->getAuthUrl();
     }
     $this->view->assignMultiple(array('authUrl' => $authUrl, 'credentials' => $credentials));
     if ($this->calendarRepository->calendarsLoaded()) {
         $this->view->assign('calendarsLoaded', TRUE);
         $this->view->assign('calendars', $this->calendarRepository->findAll());
     }
     $this->view->assign('eventsLoaded', $eventsLoaded);
     $this->view->assign('eventsFlushed', $eventsFlushed);
 }