/** * Fill data from google object into model * * @param \Google_Service_Calendar_EventAttendee $attendeeItem * @param \KevinDitscheid\KdCalendar\Domain\Model\Attendees $attendee * * @return \KevinDitscheid\KdCalendar\Domain\Model\Attendees */ public static function convert($attendeeItem, $attendee = NULL) { $feUserRepository = self::getFrontendUserRepositoryInstance(); $feUser = $feUserRepository->findByEmail($attendeeItem->getEmail())->getFirst(); if ($feUser === NULL) { $feUser = new \TYPO3\CMS\Extbase\Domain\Model\FrontendUser(); $feUser->setUsername($attendeeItem->getEmail()); $feUser->setName($attendeeItem->getDisplayName()); $feUser->setEmail($attendeeItem->getEmail()); $feUserRepository->add($feUser); self::persist(); } if ($attendee === NULL) { $attendee = new \KevinDitscheid\KdCalendar\Domain\Model\Attendees(); } $attendee->setAdditionalGuests($attendeeItem->getAdditionalGuests()); $attendee->setComment($attendeeItem->getComment()); $attendee->setId($attendeeItem->getId()); $attendee->setOptional($attendeeItem->getOptional()); $attendee->setOrganizer($attendeeItem->getOrganizer()); $attendee->setResource($attendeeItem->getResource()); $attendee->setResponseStatus($attendeeItem->getResponseStatus()); $attendee->setSelf($attendeeItem->getSelf()); return $attendee; }
/** * Converts a Google Calendar Event Attendee object into a standard Attendee * object. * * @param \Google_Service_Calendar_EventAttendee $googleAttendee * * @return Attendee */ private function createAttendeeObject(\Google_Service_Calendar_EventAttendee $googleAttendee, Event $event) { $attendee = new Attendee(['id' => $googleAttendee->getId(), 'name' => $googleAttendee->getDisplayName(), 'status' => $googleAttendee->getResponseStatus(), 'email' => $googleAttendee->getEmail(), 'comment' => $googleAttendee->getComment()]); $attendee->event = $event; $attendee->apiObject = $googleAttendee; return $attendee; }
/** * @param string $calendarId * @param Google_Service_Calendar_EventAttendee $attendee */ public static function attendAllEvents($calendarId, \Google_Service_Calendar_EventAttendee $attendee) { $service = self::getService(); $opts = ['fields' => 'items(attendees,id),nextPageToken', 'showDeleted' => true, 'singleEvents' => false]; $pageToken = 1; while ($pageToken) { if ($pageToken !== 1) { $opts['pageToken'] = $pageToken; } $events = $service->events->listEvents($calendarId, $opts); foreach ($events as $event) { # Create a patch $attendees = $event->getAttendees(); if (self::hasAttendee($attendees, $attendee->getEmail()) === false) { $attendees[] = $attendee; $patch = new \Google_Service_Calendar_Event(); $patch->setAttendees($attendees); self::patchEvent($calendarId, $event->id, $patch); } } $pageToken = $events->getNextPageToken(); } }