public function newAlertAction()
 {
     $result = array('success' => false);
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $data = get_object_vars(json_decode(file_get_contents("php://input")));
         // Validate received datas
         if ($this->validateNewAlert($data)) {
             $alerteToAdd = new Alert();
             /// timestamps
             $dtStr = date("c", $data['timestamp_current']);
             $date = new \DateTime($dtStr);
             $alerteToAdd->setDatetimeSent($date);
             $dtStr = date("c", $data['timestamp_position']);
             $date = new \DateTime($dtStr);
             $alerteToAdd->setDatetimeReceived($date);
             // location
             $alerteToAdd->setLongPos($data['longitude']);
             $alerteToAdd->setLatPos($data['latitude']);
             // user
             $newUserToAdd = new PublicUser();
             $newUserToAdd->setFirstName($data['firstname']);
             $newUserToAdd->setLastName($data['lastname']);
             $newUserToAdd->setPhone($data['phone_number']);
             $newUserToAdd->setGenre($data['gender']);
             if (is_integer(intval($data['age']))) {
                 $newUserToAdd->setAge(intval($data['age']));
             } else {
                 $newUserToAdd->setAge(null);
             }
             $em = $this->getDoctrine()->getManager();
             $em->persist($newUserToAdd);
             $em->flush();
             // Default alert level
             $alertType = $this->getDoctrine()->getRepository('UrgenceBundle:AlertType')->find(1);
             $alerteToAdd->setAlertType($alertType);
             $severity = $this->getDoctrine()->getRepository('UrgenceBundle:Severity')->find(3);
             $alerteToAdd->setSeverity($severity);
             $alerteToAdd->setInfo($data['drive_link']);
             $alerteToAdd->setPublicUser($newUserToAdd);
             // add new datas
             $em = $this->getDoctrine()->getManager();
             $em->persist($alerteToAdd);
             $em->flush();
             $result['success'] = true;
             $result['message'] = "Alert saved";
         } else {
             $result['message'] = "Wrond datas";
         }
     } else {
         $result['message'] = "Wrong request";
     }
     return new JsonResponse($result);
 }