コード例 #1
0
 /**
  * @ApiDoc(
  *  resource=true,
  *  description="Met à jour une alerte partiellement",
  *  statusCodes = {
  *     204 = "Retourné lorsque bien modifié",
  *     400 = "Retourné lorsque probleme de paramètre invalide",
  *     404 = "Retourné quand l'alerte n'est pas trouvé"
  *   }
  * )
  * @RequestParam(name="positionLong", requirements="[-+]?(\d*[.])?\d+", description="longitude like 45.187637")
  * @RequestParam(name="positionLat", requirements="[-+]?(\d*[.])?\d+", description="latitude like -5.773306")
  * @RequestParam(name="category", description="category name 'vol','help' ")
  * @RequestParam(name="description", description="description")
  * @RequestParam(name="finished",requirements="[0-1]", description="is the alert finished? ")
  * @Route("/alerts/{id}", name="alert_patch")
  * @Method("PATCH")
  */
 public function patchAlertAction($id, ParamFetcherInterface $paramFetcher)
 {
     $errors = [];
     try {
         $alert = $this->get("doctrine.orm.default_entity_manager")->getRepository("AppBundle:Alert")->getAlertById($id);
     } catch (NoResultException $e) {
         throw $this->createNotFoundException("Alerte d'id {$id} n'existe pas");
     }
     $positionLat = $paramFetcher->get("positionLat", false);
     $positionLong = $paramFetcher->get("positionLong", false);
     $category = $paramFetcher->get("category", false);
     $description = $paramFetcher->get("description", false);
     $finished = $paramFetcher->get("finished", false);
     if ($positionLong != "" && $positionLat == "" || $positionLong == "" && $positionLat != "") {
         $errors[] = "La lattitude et la longitude doivent être renseigné";
     } elseif ($positionLong != "") {
         $alert->setPositionLat($positionLat);
         $alert->setPositionLong($positionLong);
     }
     if ($category != "") {
         $alert->setCategory($category);
     }
     if ($description != "") {
         $alert->setDescription($description);
     }
     if ($finished != "") {
         if ($finished) {
             $alert->setFinishedAt(new \DateTime());
         } else {
             $alert->setFinishedAt(null);
         }
     }
     //beurk dégeulasse mais probleme pour valider le formulaire
     if ($positionLat == "" && $category == "" && $finished == "" && $description == "" && $positionLong == "") {
         $errors[] = "aucun parametre";
     }
     if (count($errors) == 0) {
         $this->get('service.alert')->updateAlert($alert);
         $response = new Response();
         $response->setStatusCode(204);
         $infos = Geocoder::getLocation($alert->getPositionLat(), $alert->getPositionLong());
         return $response;
     } else {
         return View::create($errors, 400);
     }
 }
コード例 #2
0
 /**
  * @param Alert $alert
  *
  * @return AlertDTO
  */
 public function updateAlert(Alert $alert)
 {
     $infos = Geocoder::getLocation($alert->getPositionLat(), $alert->getPositionLong());
     $city = Geocoder::getCityFromAddress($infos);
     $department = Geocoder::getDepartmentFromAddress($infos);
     $country = Geocoder::getCountryFromAddress($infos);
     $alert->setPositionCity($city);
     $alert->setPositionDep($department);
     $alert->setPositionCountry($country);
     $this->em->persist($alert);
     $this->em->flush();
     return new AlertDTO($alert);
 }
コード例 #3
0
 /**
  * @param User $user
  *
  * @return UserDTO
  */
 public function updateUser(User $user)
 {
     $infos = Geocoder::getLocation($user->getPositionLat(), $user->getPositionLong());
     $city = Geocoder::getCityFromAddress($infos);
     $department = Geocoder::getDepartmentFromAddress($infos);
     $country = Geocoder::getCountryFromAddress($infos);
     $user->setPositionCity($city);
     $user->setPositionDep($department);
     $user->setPositionCountry($country);
     $this->em->persist($user);
     $this->em->flush();
     return new UserDTO($user);
 }