Exemplo n.º 1
0
 /**
  * @Security("has_role('ROLE_USER')")
  * @Route("/user/get-conversation/{conv_id}", name="user-get-conversation", options={"expose"=true})
  * @param int $conv_id
  * @return JsonResponse
  */
 public function getConversationAction($conv_id)
 {
     /** @var User $user */
     $user = $this->getUser();
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     /** @var Conversation $conversation */
     $conversation = $em->find('NaidusvoeBundle:Conversation', $conv_id);
     if ($conversation->getUser1ID() == $user->getId() || $conversation->getUser2ID() == $user->getId()) {
         $jsonConv = $conversation->getInArray($user);
         Conversation::setViewed($em, $conversation->getMessages(), $user);
         $this->get('naidusvoe.notifier')->removeNotifications($user, Notification::CONVERSATION_NOTIFICATION, ['conversation_id' => $conversation->getId()]);
         return new JsonResponse(['conversation' => $jsonConv, 'user' => $user->getInArray()]);
     } else {
         return new JsonResponse(false);
     }
 }
Exemplo n.º 2
0
 /**
  * @param EntityManager $em
  * @param int $user1_id
  * @param int $user2_id
  * @param int $adv_id
  * @return Conversation
  */
 public static function addConversation(EntityManager $em, $user1_id, $user2_id, $adv_id)
 {
     $user1 = $em->find('NaidusvoeBundle:User', $user1_id);
     $user2 = $em->find('NaidusvoeBundle:User', $user2_id);
     $adv = $em->find('NaidusvoeBundle:Advertisment', $adv_id);
     $conversation = new Conversation();
     $conversation->setUser1($user1);
     $conversation->setUser2($user2);
     $conversation->setAdvertisment($adv);
     $conversation->setLastUpdated(new \DateTime());
     $em->persist($conversation);
     $em->flush();
     return $conversation;
 }