Ejemplo n.º 1
0
 /**
  * @param ChatUser $user
  * @param Chat $chat
  */
 public function removeUserFromChat($user, $chat)
 {
     if ($chat->getIsCompleted()) {
         $chat->removeUser($user);
         $chat->setIsCompleted(false);
     } else {
         $this->om->remove($chat);
     }
     $this->om->remove($user);
     $this->om->flush();
 }
Ejemplo n.º 2
0
 /**
  * @Route ("/save_msg", name="_saveMsg")
  * @param Request $request
  * @return Response
  */
 public function saveMsgAction(Request $request)
 {
     $session = $request->getSession();
     $userId = $session->get('userId');
     $userService = $this->container->get('user_service');
     $postData = $request->request->all();
     if ($userId != $postData['userId'] || !$userService->checkIsUserExists($postData['userId'])) {
         return new JsonResponse(['status' => false, 'error' => 'Auth error!Try to re-login']);
     }
     $postData['message'] = htmlspecialchars($postData['message'], ENT_NOQUOTES);
     $postData['message'] = trim($postData['message']);
     if ($postData['message']) {
         $saveMsg = new Chat();
         $saveMsg->setFromUser($userId);
         $saveMsg->setMsgTime(new \DateTime($postData['time']));
         $saveMsg->setMessage($postData['message']);
         $saveMsg->setColor($postData['color']);
         $em = $this->getDoctrine()->getManager();
         $em->persist($saveMsg);
         $em->flush();
         return new Response('Message saved');
     } else {
         return new Response('Message is empty');
     }
 }
Ejemplo n.º 3
0
 /**
  * @Route("/send")
  * @Method({"POST"})
  * @param Request $request
  */
 public function sendAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $message = htmlspecialchars($request->get('message'));
     $profile = $request->getSession()->get('profile');
     $id = floor(microtime(true) * 1000);
     $chat = new Entity\Chat();
     $chat->setId($id);
     $chat->setNickname($profile['nickname']);
     $chat->setHash($profile['hash']);
     $chat->setMessage($message);
     $em->persist($chat);
     $em->flush();
     $this->sendBrocastMessage(array('type' => 'update', 'id' => $id, 'from' => $profile, 'msg' => $message));
     return new JsonResponse(array('status' => true));
 }