/** * Convert the google object to model * * @param \Google_Service_Calendar_EventOrganizer $organizerItem * @param \KevinDitscheid\KdCalendar\Domain\Model\Organizer $organizer * * @return \KevinDitscheid\KdCalendar\Domain\Model\Organizer */ public static function convert($organizerItem, $organizer = NULL) { $feUserRepository = self::getFrontendUserRepositoryInstance(); $feUser = $feUserRepository->findByEmail($organizerItem->getEmail())->getFirst(); if ($feUser === NULL) { $feUser = new \TYPO3\CMS\Extbase\Domain\Model\FrontendUser(); $feUser->setUsername($organizerItem->getEmail()); $feUser->setName($organizerItem->getDisplayName()); $feUser->setEmail($organizerItem->getEmail()); $feUserRepository->add($feUser); self::persist(); } if ($organizer === NULL) { $organizer = new \KevinDitscheid\KdCalendar\Domain\Model\Organizer(); } $organizer->setFeUser($feUser); $organizer->setId($organizerItem->getId()); $organizer->setSelf($organizerItem->getSelf()); return $organizer; }
public function addInstructorCalendarEvent($reservationsInfo, $instructorInfo, $prevInsrtuctorInfo, $hoursInfo) { $date = ""; $description = ""; $total_choosen_places = 0; $attendee_index = 0; $instructorID = $instructorInfo['id']; $hour_id = $hoursInfo['id']; $prevInsrtuctorID = $prevInsrtuctorInfo['id']; $reservationsInfoSize = count($reservationsInfo); for ($resIndex = 0; $resIndex < $reservationsInfoSize; $resIndex++) { if ($resIndex == 0) { $date = $reservationsInfo[$resIndex]['resDate']; $hourCursor = Dispatcher::$mysqli->query("select * from event join instructor " . "on event.`instructor_Person_id`=instructor.`Person_id` " . "where event.`date`='{$date}' " . "and (event.`instructor_Person_id`={$prevInsrtuctorID} or event.`instructor_Person_id`={$instructorID}) " . "and event.hours_id={$hour_id}"); print_r(Dispatcher::$mysqli->error); if ($hourCursor->num_rows > 0) { $hourRow = $hourCursor->fetch_assoc(); $prev_calendar_id = $hourRow['calendar_id']; $prev_event_id = $hourRow['clndr_event_id']; $event = $this->google_api_service->events->get($prev_calendar_id, $prev_event_id); } else { $event = new Google_Service_Calendar_Event(); $event->setLocation('Saska, Praha 1'); $start = new Google_Service_Calendar_EventDateTime(); $start->setDateTime($reservationsInfo[$resIndex]['resDate'] . 'T' . $reservationsInfo[$resIndex]['hour_from'] . ':00.000+02:00'); $start->setTimeZone('Europe/Prague'); $event->setStart($start); $end = new Google_Service_Calendar_EventDateTime(); $end->setDateTime($reservationsInfo[$resIndex]['resDate'] . 'T' . $reservationsInfo[$resIndex]['hour_to'] . ':00.000+02:00'); $end->setTimeZone('Europe/Prague'); $event->setEnd($end); } } $client_email = $reservationsInfo[$resIndex]['email']; $client_name = $reservationsInfo[$resIndex]['name']; $client_telefon = $reservationsInfo[$resIndex]['telefone']; $choosen_places = $reservationsInfo[$resIndex]['choosen_places']; $voucherName = $reservationsInfo[$resIndex]['vocuherName']; $total_choosen_places += $choosen_places; MainController::printArray($reservationsInfo); $description .= $client_name . "\n" . $client_email . "\n" . $client_telefon . "\n" . $choosen_places . "\n\n"; $attendee[$attendee_index] = new Google_Service_Calendar_EventAttendee(); $attendee[$attendee_index]->setEmail($client_email); $attendee[$attendee_index]->setDisplayName($client_name); $attendee[$attendee_index]->setOptional($client_telefon); $attendee_index++; } if ($reservationsInfoSize > 0) { if ($hourCursor->num_rows > 0) { try { $event->setSummary($total_choosen_places . " " . $voucherName); $event->description = $description; $event->attendees = $attendee; $updatedEvent = $this->google_api_service->events->update($prevInsrtuctorInfo['calendar_id'], $event->getId(), $event); } catch (Google_Service_Exception $e) { echo '<pre>'; print_r($e); syslog(LOG_ERR, $e->getMessage()); } $event = $this->google_api_service->events->get($prevInsrtuctorInfo['calendar_id'], $updatedEvent->getId()); $event_id = $event->getId(); Dispatcher::$mysqli->query("update event set clndr_event_id='{$event_id}', `instructor_Person_id`={$instructorID} " . "where date='{$date}' and hours_id={$hour_id} and `instructor_Person_id`={$prevInsrtuctorID}"); if ($prev_calendar_id != $instructorInfo['calendar_id']) { $result = $this->google_api_service->events->move($prev_calendar_id, $event_id, $instructorInfo['calendar_id']); print_r(Dispatcher::$mysqli->error); echo '<pre>'; print_r($result); } } else { try { $event->attendees = $attendee; $event->description = $description; $organizer = new Google_Service_Calendar_EventOrganizer(); $organizer->setEmail($instructorInfo['email']); $organizer->setDisplayName($instructorInfo['name']); $event->setOrganizer($organizer); $new_event = $this->google_api_service->events->insert($instructorInfo['calendar_id'], $event); } catch (Google_Service_Exception $e) { echo '<pre>'; print_r($e); syslog(LOG_ERR, $e->getMessage()); } $event = $this->google_api_service->events->get($instructorInfo['calendar_id'], $new_event->getId()); $instructorID = $instructorInfo['id']; $hour_id = $hoursInfo['id']; $event_id = $event->getId(); Dispatcher::$mysqli->query("insert into event(clndr_event_id, `instructor_Person_id`, hours_id, date, has_changes) " . "values('{$event_id}', {$instructorID}, {$hour_id}, '{$date}', 0)"); if ($event != null) { // echo "Inserted:<br>"; // echo "EventID=" . $event->getId() . " <br>"; // echo "Summary=" . $event->getSummary() . " <br>"; // echo "Status=" . $event->getStatus(); } } } }