/** * Sends an email about expired reservations and lessons. * Expired are lessons where the reservation deadline is * before yesterday 0:00:00 h. * A MS Excel file with the results will be attached to the email * * @param string $email Recipients email address * @throws Exception */ public function reportExpiredCommand($email) { $lessons = $this->getLessonsWithExpiredDeadline(); $reservationDemand = $this->createReservationDemandByLessonDeadline('yesterday'); $reservations = $this->reservationRepository->findDemanded($reservationDemand); if (!empty($email) and (count($lessons) or count($reservations))) { try { $this->notificationService->notify($email, '*****@*****.**', 'Abgelaufene Termine und Reservierungen in ihrem Veranstaltungssystem', 'Email', NULL, 'ReportExpired', ['lessons' => $lessons, 'reservations' => $reservations], [['variables' => ['lessons' => $lessons, 'reservations' => $reservations], 'templateName' => 'Download', 'folderName' => 'CloseBooking', 'fileName' => 'anhang.xls', 'mimeType' => 'application/vnd.ms-excel']]); } catch (Exception $e) { throw new Exception($e->getMessage()); } } }
/** * @param Reservation $reservation * @param string $identifier * @param array $config * @return bool * @throws Exception */ protected function sendNotification(Reservation $reservation, $identifier, $config) { if (isset($config['fromEmail'])) { $fromEmail = $config['fromEmail']; } else { throw new Exception('Missing sender for email notification', 1454518855); } $recipientEmail = $this->settingsUtility->getValue($reservation, $config['toEmail']); if (!isset($recipientEmail)) { throw new Exception('Missing recipient for email notification ' . $identifier, 1454865240); } $subject = $this->settingsUtility->getValue($reservation, $config['subject']); if (!isset($subject)) { throw new Exception('Missing subject for email notification ' . $identifier, 1454865250); } $format = 'plain'; if (isset($config['format']) && is_string($config['format'])) { $format = $config['format']; } $fileName = ucfirst($identifier); if (isset($config['template']['fileName'])) { $fileName = $config['template']['fileName']; } $folderName = 'Reservation/Email'; if (isset($config['template']['folderName'])) { $folderName = $config['template']['folderName']; } /** @var Notification $notification */ $notification = $this->objectManager->get(Notification::class); if (isset($config['attachments']['files']) && is_array($config['attachments']['files'])) { $filesToAttach = $this->settingsUtility->getFileStorage($reservation, $config['attachments']['files']); $notification->setAttachments($filesToAttach); } $notification->setRecipient($recipientEmail); $notification->setSenderEmail($fromEmail); if (isset($config['senderName'])) { $notification->setSenderName($config['senderName']); } $notification->setSubject($subject); $notification->setFormat($format); $bodyText = $this->notificationService->render($fileName, $format, $folderName, ['reservation' => $reservation, 'settings' => $this->settings]); $notification->setBodytext($bodyText); $reservation->addNotification($notification); return $this->notificationService->send($notification); }