container->get('domain.notificationLog.repository'); /** @var UserRepository $userRepository */ $userRepository = $this->container->get('domain.users.repository'); /** @var CustomerBookingRepository $bookingRepository */ $bookingRepository = $this->container->get('domain.booking.customerBooking.repository'); $token = isset($appointmentArray['bookings'][$bookingKey]) ? $bookingRepository->getToken($appointmentArray['bookings'][$bookingKey]['id']) : null; /** @var PHPMailService|SMTPService|MailgunService $mailService */ $mailService = $this->container->get('infrastructure.mail.service'); /** @var PlaceholderService $placeholderService */ $placeholderService = $this->container->get("application.placeholder.{$appointmentArray['type']}.service"); $data = $placeholderService->getPlaceholdersData( $appointmentArray, $bookingKey, isset($token['token']) ? $token['token'] : null ); $subject = $placeholderService->applyPlaceholders($notification->getSubject()->getValue(), $data); $body = $placeholderService->applyPlaceholders($notification->getContent()->getValue(), $data); /** @var SettingsService $bccEmail*/ $bccEmail = $this->container->get('domain.settings.service')->getSetting('notifications', 'bccEmail'); ($bccEmail !== '') ? $bcc = $bccEmail : $bcc = false; $users = $this->getUsersInfo( $notification->getSendTo()->getValue(), $appointmentArray, $bookingKey, $data ); foreach ($users as $user) { try { if ($user['email']) { $mailService->send( $user['email'], $subject, $body, $bcc ); if ($logNotification) { $notificationLogRepo->add( $notification, $userRepository->getById($user['id']), $appointmentArray['type'] === Entities::APPOINTMENT ? $appointmentArray['id'] : null, $appointmentArray['type'] === Entities::EVENT ? $appointmentArray['id'] : null ); } } } catch (\Exception $e) { } } } /** * @throws NotFoundException * @throws QueryExecutionException * @throws \AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException * @throws \Interop\Container\Exception\ContainerException * @throws \Exception */ public function sendBirthdayGreetingNotifications() { /** @var Notification $notification */ $notification = $this->getByNameAndType('customer_birthday_greeting', $this->type); // Check if notification is enabled and it is time to send notification if ($notification->getStatus()->getValue() === NotificationStatus::ENABLED && DateTimeService::getNowDateTimeObject() >= DateTimeService::getCustomDateTimeObject($notification->getTime()->getValue()) ) { /** @var NotificationLogRepository $notificationLogRepo */ $notificationLogRepo = $this->container->get('domain.notificationLog.repository'); /** @var PHPMailService|SMTPService|MailgunService $mailService */ $mailService = $this->container->get('infrastructure.mail.service'); /** @var PlaceholderService $placeholderService */ $placeholderService = $this->container->get('application.placeholder.appointment.service'); $customers = $notificationLogRepo->getBirthdayCustomers($this->type); $companyData = $placeholderService->getCompanyData(); $customersArray = $customers->toArray(); /** @var SettingsService $bccEmail */ $bccEmail = $this->container->get('domain.settings.service')->getSetting('notifications', 'bccEmail'); ($bccEmail !== '') ? $bcc = $bccEmail : $bcc = false; foreach ($customersArray as $bookingKey => $customerArray) { if ($customerArray['email']) { $data = [ 'customer_email' => $customerArray['email'], 'customer_first_name' => $customerArray['firstName'], 'customer_last_name' => $customerArray['lastName'], 'customer_full_name' => $customerArray['firstName'] . ' ' . $customerArray['lastName'], 'customer_phone' => $customerArray['phone'] ]; /** @noinspection AdditionOperationOnArraysInspection */ $data += $companyData; $subject = $placeholderService->applyPlaceholders( $notification->getSubject()->getValue(), $data ); $body = $placeholderService->applyPlaceholders( $notification->getContent()->getValue(), $data ); try { $mailService->send($data['customer_email'], $subject, $body, $bcc); $notificationLogRepo->add( $notification, $customers->getItem($bookingKey) ); } catch (\Exception $e) { } } } } } }