Beispiel #1
0
 /**
  * Creates a new user message and adds it to the message que db
  *
  * @param string $userId
  * @param string $subject
  * @param string $body
  * @param string $level
  * @param string $source
  */
 public function createUserMessage($userId, $subject, $body, $level, $source)
 {
     $message = new Message();
     $message->setSubject($subject);
     $message->setMessage($body);
     $message->setLevel($level);
     $message->setSource($source);
     $this->entityMgr->persist($message);
     $this->entityMgr->flush($message);
     $userMessage = new UserMessage($userId);
     $userMessage->setMessage($message);
     $this->entityMgr->persist($userMessage);
     $this->entityMgr->flush($userMessage);
 }
 /**
  * create
  *
  * @param mixed $data
  *
  * @return ApiJsonModel|\Zend\Stdlib\ResponseInterface
  */
 public function create($data)
 {
     if (!$this->rcmIsAllowed('sites', 'admin')) {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_401);
         return $this->getResponse();
     }
     $userId = $this->getEvent()->getRouteMatch()->getParam('userId', null);
     $newUserMessage = new UserMessage($userId);
     $newUserMessage->populate($data, ['id', 'dateViewed', 'message']);
     // @todo Should we force creation????
     $newMessage = new Message();
     $newMessage->populate($data['message'], ['id', 'dateCreated']);
     $newUserMessage->setMessage($newMessage);
     $entityManager = $this->getEntityManager();
     try {
         $entityManager->persist($newUserMessage);
         $entityManager->flush();
     } catch (\Exception $e) {
         return new ApiJsonModel(null, 1, $e->getMessage());
     }
     return new ApiJsonModel($newUserMessage);
 }