コード例 #1
0
 /**
  * @param string $title
  * @param string $content
  * @param \Wonderland\Application\Model\Member $author
  * @param string $recipientIdentity
  * @return \Wonderland\Application\Model\Message
  */
 public function createMessage($title, $content, Member $author, $recipientIdentity)
 {
     $recipient = $this->memberManager->getMemberByIdentity($recipientIdentity);
     $message = (new Message())->setTitle($title)->setContent($content)->setAuthor($author)->setRecipient($recipient)->setCreatedAt(new \DateTime());
     $this->repository->create($message);
     return $message;
 }
コード例 #2
0
 /**
  * @param \Wonderland\Application\Model\Member $author
  * @param string                               $recipientIdentity
  * @param string                               $title
  * @param string                               $content
  */
 public function createMessage(Member $author, $recipientIdentity, $title, $content)
 {
     $errors = [];
     if (($recipient = $this->memberManager->getMemberByIdentity($recipientIdentity)) === null) {
         $errors[] = ['message' => $this->translator->translate('messages.creation.recipient_not_found')];
     }
     if (trim($title) === '') {
         $errors[] = ['message' => $this->translator->translate('messages.creation.empty_content')];
     }
     if (trim($content) === '') {
         $errors[] = ['message' => $this->translator->translate('messages.creation.empty_content')];
     }
     if (count($errors) > 0) {
         return $errors;
     }
     $message = (new Message())->setTitle($title)->setContent($content)->setAuthor($author)->setRecipient($recipient)->setCreatedAt(new \DateTime());
     $this->repository->create($message);
     return true;
 }