Ejemplo n.º 1
0
 /**
  * @param Message $message
  * @return Message
  */
 public function storeMessage(Message $message)
 {
     try {
         $message->setCreateAt(new \DateTime());
         $this->getDocumentManager()->persist($message);
         $this->getDocumentManager()->flush();
         return $message;
     } catch (InvalidArgumentException $e) {
         throw new InvalidArgumentException($e->getMessage(), $e->getCode());
     }
 }
Ejemplo n.º 2
0
 /**
  * Post new message to specific question
  *
  * @ApiDoc()
  *
  * @param $id
  * @param Request $request
  * @return JsonResponse
  */
 public function postQuestionsMessagesAction($id, Request $request)
 {
     $question = $this->get('question.repository')->getQuestionById($id);
     if ($question) {
         //            var_dump($request->request->get('message'));die;
         $message = new Message();
         $message->setQuestionId($id);
         $message->setMessage($request->request->get('message'));
         $message = $this->get('messsage.repository')->storeMessage($message);
         return new JsonResponse(json_encode($message), JsonResponse::HTTP_ACCEPTED);
         //            $form = $this->getForm($message);
         //            $form->handleRequest($request);
         //            if (!$form->isValid()) {
         //                throw new HttpException(400, "New message is not valid.");
         //            } else {
         //                $this->get('messsage.repository')->storeMessage($message);
         //            }
     }
 }