/**
  * @param int $id
  * @return \Wonderland\Application\Model\Message
  */
 public function getMessage($id)
 {
     $data = $this->repository->find($id);
     $author = $this->memberManager->getMember($data['author_id']);
     $recipient = $this->memberManager->getMember($data['recipient_id']);
     return (new Message())->setId($id)->setTitle($data['title'])->setContent($data['content'])->setAuthor($author)->setRecipient($recipient)->setCreatedAt(new \DateTime($data['created_at']));
 }
 /**
  * @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;
 }