Example #1
0
 /** {@inheritDoc} */
 public function getEventApi(AbstractCalendar $calendar)
 {
     if (!$calendar instanceof Calendar) {
         throw new InvalidArgumentException('Wrong calendar provided, expected a google calendar');
     }
     if (!isset($this->eventApis[$calendar->getId()])) {
         $this->eventApis[$calendar->getId()] = new EventApi($this->guzzle, $this, $calendar);
     }
     return $this->eventApis[$calendar->getId()];
 }
Example #2
0
 public function __construct(AbstractCalendar $calendar, User $owner, $name, Datetime $start, Datetime $end)
 {
     $this->name = $name;
     $this->owner = $owner;
     $this->calendar = $calendar;
     $this->participations = new ArrayCollection();
     if ($start > $end) {
         throw new InvalidArgumentException('An event cannot start after it was ended');
     }
     $this->end = $end;
     $this->start = $start;
     $owner->addEvent($this);
     $calendar->getEvents()->add($this);
 }
Example #3
0
 /** {@inheritDoc} */
 public function getPermissions(AbstractCalendar $calendar, AbstractCriterion $criterion = null)
 {
     $query = new Collection([new Collection([new Field('items', [new Field('id'), new Field('scope'), new Field('role')])], 'fields')]);
     if (null !== $criterion) {
         $query = $query->merge($criterion);
     }
     $response = $this->guzzle->get(sprintf('calendars/%s/acl', $calendar->getId()), ['query' => $query->build()]);
     if (200 > $response->getStatusCode() || 300 <= $response->getStatusCode()) {
         throw new ApiErrorException($response);
     }
     $result = $response->json();
     $list = new ArrayCollection();
     foreach ($result['items'] as $item) {
         // only user scope are supported
         if ('user' !== $item['scope']['type']) {
             continue;
         }
         $user = in_array($item['scope']['value'], $this->adapter->getUser()->getEmail(true)) ? $this->adapter->getUser() : User::hydrate(['email' => $item['scope']['value']]);
         $list[$item['id']] = UserPermission::hydrate($calendar, $user, $item['role']);
     }
     $calendar->setPermissions($list);
     return $list;
 }
Example #4
0
 public function __construct($id, $name, DateTimeZone $timeZone)
 {
     $this->id = $id;
     $this->timeZone = $timeZone;
     parent::__construct($name);
 }