/** * @param Message $message * @param BackendUser $user * * @return mixed|void */ protected function execute(Message $message, \BackendUser $user) { global $container; $general = new \ContaoCommunityAlliance\DcGeneral\DC_General('orm_avisota_message'); $environment = $general->getEnvironment(); $translator = $environment->getTranslator(); $GLOBALS['TL_LANGUAGE'] = $message->getLanguage(); /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ $eventDispatcher = $GLOBALS['container']['event-dispatcher']; $email = \Input::get('recipient_email'); $idSerializer = new ModelId('orm_avisota_message', $message->getId()); $pidSerializer = new ModelId('orm_avisota_message_category', $message->getCategory()->getId()); if (!$email) { $_SESSION['AVISOTA_SEND_PREVIEW_TO_EMAIL_EMPTY'] = true; header('Location: ' . sprintf('%scontao/main.php?do=avisota_newsletter&table=orm_avisota_message&act=preview&id=%s&pid=%s', \Environment::get('base'), $idSerializer->getSerialized(), $pidSerializer->getSerialized())); exit; } $url = sprintf('%scontao/main.php?do=avisota_newsletter&table=orm_avisota_message&act=preview&id=%s&pid=%s', \Environment::get('base'), $idSerializer->getSerialized(), $pidSerializer->getSerialized()); if ($message->getCategory()->getViewOnlinePage()) { $event = new LoadLanguageFileEvent('avisota_message'); $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event); $viewOnlineLink = sprintf($translator->translate('viewOnline', 'avisota_message'), $url); } else { $viewOnlineLink = false; } $event = new \Avisota\Contao\Core\Event\CreateFakeRecipientEvent($message); $eventDispatcher->dispatch(\Avisota\Contao\Core\CoreEvents::CREATE_FAKE_RECIPIENT, $event); $recipient = $event->getRecipient(); $recipient->setEmail($email); $additionalData = array('view_online_link' => $viewOnlineLink); /** @var \Avisota\Contao\Message\Core\Renderer\MessageRendererInterface $renderer */ $renderer = $container['avisota.message.renderer']; $messageTemplate = $renderer->renderMessage($message); $messageMail = $messageTemplate->render($recipient, $additionalData); /** @var \Avisota\Transport\TransportInterface $transport */ $transport = $GLOBALS['container']['avisota.transport.' . $message->getQueue()->getTransport()->getId()]; $transport->send($messageMail); $event = new \ContaoCommunityAlliance\Contao\Bindings\Events\System\LoadLanguageFileEvent('avisota_message_preview'); $eventDispatcher->dispatch(\ContaoCommunityAlliance\Contao\Bindings\ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event); $_SESSION['TL_CONFIRM'][] = sprintf($translator->translate('previewSend', 'avisota_message_preview'), $email); header('Location: ' . $url); exit; }
/** * @SuppressWarnings(PHPMD.ShortVariable) */ public function generate() { $do = \Input::get('do'); $id = preg_replace('#^avisota_category_(.*)$#', '$1', $do); $serializer = new ModelId('orm_avisota_message_category', $id); $this->redirect('contao/main.php?do=avisota_newsletter&table=orm_avisota_message&pid=' . $serializer->getSerialized()); }