recipientIds = $recipientIds; $this->contextId = $contextId; $this->announcementId = $announcementId; $this->locale = $locale; $this->sender = $sender; } public function handle() { $announcement = Repo::announcement()->get($this->announcementId); // Announcement was removed if (!$announcement) { throw new JobException(JobException::INVALID_PAYLOAD); } $announcementNotificationManager = new AnnouncementNotificationManager(Notification::NOTIFICATION_TYPE_NEW_ANNOUNCEMENT); $announcementNotificationManager->initialize($announcement); $context = Application::getContextDAO()->getById($this->contextId); $template = Repo::emailTemplate()->getByKey($context->getId(), AnnouncementNotify::getEmailTemplateKey()); foreach ($this->recipientIds as $recipientId) { /** @var int $recipientId */ $recipient = Repo::user()->get($recipientId); if (!$recipient) { continue; } $notification = $announcementNotificationManager->notify($recipient); if (!$this->sender) { continue; } // Send email $mailable = $this->createMailable($context, $recipient, $announcement, $template) ->allowUnsubscribe($notification); $mailable->setData($this->locale); Mail::send($mailable); } } /** * Creates new announcement notification email */ protected function createMailable( Context $context, User $recipient, Announcement $announcement, EmailTemplate $template ): AnnouncementNotify { $mailable = new AnnouncementNotify($context, $announcement); $mailable->sender($this->sender); $mailable->recipients([$recipient]); $mailable->body($template->getLocalizedData('body', $this->locale)); $mailable->subject($template->getLocalizedData('subject', $this->locale)); return $mailable; } }