/** * @param AB_Appointment $appointment */ private function handleEventData(AB_Appointment $appointment) { $start_datetime = new Google_Service_Calendar_EventDateTime(); $start_datetime->setDateTime(DateTime::createFromFormat('Y-m-d H:i:s', $appointment->get('start_date'), new DateTimeZone(AB_Utils::getTimezoneString()))->format(DateTime::RFC3339)); $end_datetime = new Google_Service_Calendar_EventDateTime(); $end_datetime->setDateTime(DateTime::createFromFormat('Y-m-d H:i:s', $appointment->get('end_date'), new DateTimeZone(AB_Utils::getTimezoneString()))->format(DateTime::RFC3339)); $service = new AB_Service(); $service->load($appointment->get('service_id')); $description = __('Service', 'bookly') . ": " . $service->get('title') . PHP_EOL; $client_names = array(); foreach ($appointment->getCustomerAppointments() as $ca) { $description .= sprintf("%s: %s\n%s: %s\n%s: %s\n", __('Name', 'bookly'), $ca->customer->get('name'), __('Email', 'bookly'), $ca->customer->get('email'), __('Phone', 'bookly'), $ca->customer->get('phone')); $description .= $ca->getFormattedCustomFields('text'); $description .= PHP_EOL; $client_names[] = $ca->customer->get('name'); } $staff = new AB_Staff(); $staff->load($appointment->get('staff_id')); $title = strtr(get_option('ab_settings_google_event_title', '[[SERVICE_NAME]]'), array('[[SERVICE_NAME]]' => $service->get('title'), '[[CLIENT_NAMES]]' => implode(', ', $client_names), '[[STAFF_NAME]]' => $staff->get('full_name'))); $this->event->setStart($start_datetime); $this->event->setEnd($end_datetime); $this->event->setSummary($title); $this->event->setDescription($description); $extended_property = new Google_Service_Calendar_EventExtendedProperties(); $extended_property->setPrivate(array('customers' => json_encode(array_map(function ($ca) { return $ca->customer->get('id'); }, $appointment->getCustomerAppointments())), 'service_id' => $service->get('id'), 'appointment_id' => $appointment->get('id'))); $this->event->setExtendedProperties($extended_property); }
public function onRaidCreate($aRaidId) { if ($this->authenticate()) { // Query the given raid, make sure we include canceled and closed // raids $Parameters = array('raid' => $aRaidId, 'canceled' => true, 'closed' => true); $RaidResult = Api::queryRaid($Parameters); if (count($RaidResult) > 0) { // As we specified a specific raid id, we are only // interested in the first (and only) raid. // Cache and set UTC timezone just to be sure. $Raid = $RaidResult[0]; $LocationName = $this->mLocations[$Raid['LocationId']]; $Url = getBaseURL() . 'index.php#raid,' . $aRaidId; $Timezone = date_default_timezone_get(); try { date_default_timezone_set('UTC'); $Start = new Google_Service_Calendar_EventDateTime(); $Start->setDateTime(date($this->mDateFormat, intval($Raid['Start']))); $Start->setTimeZone('UTC'); $End = new Google_Service_Calendar_EventDateTime(); $End->setDateTime(date($this->mDateFormat, intval($Raid['End']))); $End->setTimeZone('UTC'); $Properties = new Google_Service_Calendar_EventExtendedProperties(); $Properties->setShared(array('RaidId' => $aRaidId)); $Source = new Google_Service_Calendar_EventSource(); $Source->setTitle('Raidplaner link'); $Source->setUrl($Url); $Event = new Google_Service_Calendar_Event(); $Event->setSummary($LocationName . ' (' . $Raid['Size'] . ')'); $Event->setLocation($LocationName); $Event->setDescription($Raid['Description']); $Event->setOriginalStartTime($Start); $Event->setStart($Start); $Event->setEnd($End); $Event->setExtendedProperties($Properties); $Event->setSource($Source); $this->mCalService->events->insert(GOOGLE_CAL_ID, $Event); } catch (Exception $Ex) { $Out = Out::getInstance(); $Out->pushError($Ex->getMessage()); } date_default_timezone_set($Timezone); } } }