Ejemplo n.º 1
0
 /**
  * @Route("/test-json")
  */
 public function testAction()
 {
     $user = new User();
     $user->setUsername('test');
     $user->setPhoneNumber('0627674523');
     $object = new Demande();
     $object->setDemandeur($user);
     /*return new JsonResponse(array(
           'object' => $object
       ));*/
     return $this->NTRender(array('object' => $object));
 }
Ejemplo n.º 2
0
 /**
  * @param $id
  * @Route("/addFriend/{id}/{token}/{friendId}/")
  * @return Response
  */
 public function addFriendAction($id, $token, $friendId)
 {
     $userService = $this->get('server.user_service');
     $em = $this->getDoctrine()->getManager();
     $repository = $this->getDoctrine()->getRepository('ServerBundle:User');
     $user = $repository->findOneBy(array('id' => $id));
     $friend = $repository->findOneBy(array('id' => $friendId));
     if (!$user || !$friend) {
         return $this->NTRender(array('response' => 404, 'message' => 'Utilisateur inconnu'));
     }
     if (!$userService->tokenExist($user, $token)) {
         return $this->NTRender(array('response' => 0, 'message' => 'Erreur d\'authentification'));
     }
     if (!$user->getFriends()->contains($friend) && !$user->getFriendsWithMe()->contains($friend) && $user != $friend) {
         if ($userService->notExistDemande($em, $user, $friend)) {
             $demande = new Demande();
             $demande->setDemandeur($user);
             $demande->setDemande($friend);
             $em->persist($demande);
             $em->flush();
             $gcmService = $this->get('server.gcm_service');
             if ($friend->getGcmToken() != null) {
                 $gcmService->send(array("type" => 'addFriend'), $friend->getGcmToken());
             }
             return $this->NTRender(array('response' => 1));
         } else {
             return $this->NTRender(array('response' => -2));
         }
     } else {
         return $this->NTRender(array('response' => -1));
     }
 }