public function __construct(SentMessage $message) { if ($message->getId() !== null) { throw new InvalidArgumentException('Only new instances of ' . SentMessage::class . ' are allowed'); } parent::__construct($message); }
/** * @param SentMessage $message * @return array */ public function findMessageRecipients(SentMessage $message) { $mr = $this->messagesReader->findReceivedMessages($message->getId()); $recipients = []; foreach ($mr as $reference) { $recipients[$reference['recipient']['id']] = $reference['recipient']; } unset($mr); return $recipients; }
public function processNewMessageForm(Form $form) { $values = $form->getValues(); $recipients = is_array($values->recipients) ? $values->recipients : [$values->recipients]; if (!$this->authorizator->isAllowed($this->user, 'message', 'sent_to_restricted_recipients')) { $s = $this->messagesFacade->canMessageBeSentTo($values->recipients, $this->restrictedUsers, $this->users); if ($s === false) { $form->addError('Nelze odeslat zprávu vybranému příjemci.'); return; } } if ($values['isSendAsAdmin'] == true and !$this->authorizator->isAllowed($this->user, 'message', 'send_as_admin')) { $form->addError('Nemáte dostatečná oprávnění k akci.'); return; } $texy = new \Texy(); $texy->setOutputMode(\Texy::HTML4_TRANSITIONAL); $texy->encoding = 'utf-8'; $texy->allowedTags = \Texy::ALL; $text = $texy->process($values->text); $message = new SentMessage($values->subject, $text, $this->user); if ($values['isSendAsAdmin']) { $message->sendByAuthorRole(); } try { $this->messagesFacade->sendMessage($message, $recipients); } catch (MessageLengthException $ml) { $form->addError('Zprávu nelze uložit, protože je příliš dlouhá.'); return; } catch (DBALException $e) { $this->flashMessage('Zpráva nemohla být odeslána. Zkuste akci opakovat později.', 'errror'); $this->redirect('this'); } $this->presenter->flashMessage('Zpráva byla úspěšně odeslána', 'success'); $this->presenter->redirect('MailBox:sent'); }