container->get('domain.settings.service'); /** @var HelperService $helperService */ $helperService = $this->container->get('application.helper.service'); $companySettings = $settingsService->getCategorySettings('company'); $dateFormat = $settingsService->getSetting('wordpress', 'dateFormat'); $timeFormat = $settingsService->getSetting('wordpress', 'timeFormat'); $timestamp = date_create()->getTimestamp(); return [ 'appointment_date' => date_i18n($dateFormat, strtotime($timestamp)), 'appointment_date_time' => date_i18n($dateFormat . ' ' . $timeFormat, strtotime($timestamp)), 'appointment_start_time' => date_i18n($timeFormat, $timestamp), 'appointment_end_time' => date_i18n($timeFormat, date_create('1 hour')->getTimestamp()), 'appointment_notes' => 'Appointment note', 'appointment_price' => $helperService->getFormattedPrice(100), 'employee_email' => 'employee@domain.com', 'employee_first_name' => 'Richard', 'employee_last_name' => 'Roe', 'employee_full_name' => 'Richard Roe', 'employee_phone' => '150-698-1858', 'location_address' => $companySettings['address'], 'location_name' => 'Location Name', 'category_name' => 'Category Name', 'service_description' => 'Service Description', 'service_duration' => $helperService->secondsToNiceDuration(5400), 'service_name' => 'Service Name', 'service_price' => $helperService->getFormattedPrice(100) ]; } /** * @param array $appointment * @param int $bookingKey * @param string $token * * @return array * * @throws \Slim\Exception\ContainerValueNotFoundException * @throws NotFoundException * @throws QueryExecutionException * @throws \Interop\Container\Exception\ContainerException * @throws \Exception */ public function getEntityPlaceholdersData($appointment, $bookingKey = null, $token = null) { $data = []; $data = array_merge($data, $this->getAppointmentData($appointment, $bookingKey)); $data = array_merge($data, $this->getEmployeeData($appointment)); $data = array_merge($data, $this->getServiceData($appointment)); return $data; } /** * @param $appointment * @param null $bookingKey * * @return array * * @throws \Interop\Container\Exception\ContainerException * @throws \Exception */ private function getAppointmentData($appointment, $bookingKey = null) { /** @var SettingsService $settingsService */ $settingsService = $this->container->get('domain.settings.service'); $dateFormat = $settingsService->getSetting('wordpress', 'dateFormat'); $timeFormat = $settingsService->getSetting('wordpress', 'timeFormat'); if ($bookingKey !== null && $appointment['bookings'][$bookingKey]['utcOffset'] !== null && $settingsService->getSetting('general', 'showClientTimeZone')) { $bookingStart = DateTimeService::getClientUtcCustomDateTimeObject( DateTimeService::getCustomDateTimeInUtc($appointment['bookingStart']), $appointment['bookings'][$bookingKey]['utcOffset'] ); $bookingEnd = DateTimeService::getClientUtcCustomDateTimeObject( DateTimeService::getCustomDateTimeInUtc($appointment['bookingEnd']), $appointment['bookings'][$bookingKey]['utcOffset'] ); } else { $bookingStart = DateTime::createFromFormat('Y-m-d H:i:s', $appointment['bookingStart']); $bookingEnd = DateTime::createFromFormat('Y-m-d H:i:s', $appointment['bookingEnd']); } return [ 'appointment_notes' => $appointment['internalNotes'], 'appointment_date' => date_i18n($dateFormat, $bookingStart->getTimestamp()), 'appointment_date_time' => date_i18n($dateFormat . ' ' . $timeFormat, $bookingStart->getTimestamp()), 'appointment_start_time' => date_i18n($timeFormat, $bookingStart->getTimestamp()), 'appointment_end_time' => date_i18n($timeFormat, $bookingEnd->getTimestamp()), ]; } /** * @param $appointmentArray * * @return array * @throws \Slim\Exception\ContainerValueNotFoundException * @throws NotFoundException * @throws QueryExecutionException * @throws \Interop\Container\Exception\ContainerException */ private function getServiceData($appointmentArray) { /** @var CategoryRepository $categoryRepository */ $categoryRepository = $this->container->get('domain.bookable.category.repository'); /** @var ServiceRepository $serviceRepository */ $serviceRepository = $this->container->get('domain.bookable.service.repository'); /** @var HelperService $helperService */ $helperService = $this->container->get('application.helper.service'); /** @var Service $service */ $service = $serviceRepository->getByIdWithExtras($appointmentArray['serviceId']); /** @var Category $category */ $category = $categoryRepository->getById($service->getCategoryId()->getValue()); $data = [ 'category_name' => $category->getName()->getValue(), 'service_description' => $service->getDescription()->getValue(), 'service_duration' => $helperService->secondsToNiceDuration($service->getDuration()->getValue()), 'service_name' => $service->getName()->getValue(), 'service_price' => $helperService->getFormattedPrice($service->getPrice()->getValue()) ]; $bookingExtras = []; foreach ((array)$appointmentArray['bookings'] as $booking) { foreach ((array)$booking['extras'] as $bookingExtra) { $bookingExtras[$bookingExtra['extraId']] = [ 'quantity' => $bookingExtra['quantity'] ]; } } /** @var Extra $extra */ foreach ($service->getExtras()->getItems() as $extra) { $extraId = $extra->getId()->getValue(); $data["service_extra_{$extraId}_name"] = array_key_exists($extraId, $bookingExtras) ? $extra->getName()->getValue() : ''; $data["service_extra_{$extraId}_quantity"] = array_key_exists($extraId, $bookingExtras) ? $bookingExtras[$extraId]['quantity'] : ''; } return $data; } /** * @param $appointment * * @return array * * @throws \Slim\Exception\ContainerValueNotFoundException * @throws NotFoundException * @throws QueryExecutionException * @throws \Interop\Container\Exception\ContainerException */ private function getEmployeeData($appointment) { /** @var UserRepository $userRepository */ $userRepository = $this->container->get('domain.users.repository'); /** @var LocationRepository $locationRepository */ $locationRepository = $this->container->get('domain.locations.repository'); /** @var ProviderLocationRepository $providerLocationRepo */ $providerLocationRepo = $this->container->get('domain.bookable.service.providerLocation.repository'); /** @var SettingsService $settingsService */ $settingsService = $this->container->get('domain.settings.service'); /** @var Provider $user */ $user = $userRepository->getById($appointment['providerId']); /** @var Location $location */ if ($locationId = $providerLocationRepo->getLocationIdByUserId($appointment['providerId'])) { $location = $locationRepository->getById($locationId); } return [ 'employee_email' => $user->getEmail()->getValue(), 'employee_first_name' => $user->getFirstName()->getValue(), 'employee_last_name' => $user->getLastName()->getValue(), 'employee_full_name' => $user->getFirstName()->getValue() . ' ' . $user->getLastName()->getValue(), 'employee_phone' => $user->getPhone()->getValue(), 'location_address' => $locationId === null ? $settingsService->getSetting('company', 'address') : $location->getAddress()->getValue(), 'location_name' => $locationId === null ? $settingsService->getSetting('company', 'address') : $location->getName()->getValue() ]; } }