Esempio n. 1
0
 public function saveObservationsPOST($params, $controller)
 {
     $resumeToObservationsInsert = null;
     $resumeToObservationsInsert['message'] = "";
     $resumeToObservationsInsert['result'] = "ok";
     $inscriptionService = new InscriptionService();
     $inscriptionService->setManager($this->em);
     $inscription = $inscriptionService->getInscription($params['inscription']);
     $observations = $this->getObservationByInscription($params['inscription']);
     foreach ($observations as $obs) {
         $this->deleteObservation($obs);
     }
     foreach ($params['observations'] as $objObs) {
         $result = $this->saveObservation($objObs, $inscription, $controller);
         if ($result['result'] == 'fail') {
             $resumeToObservationsInsert['message'] .= $inscription->getId() . '|' . $result['message'] . ';';
             $resumeToObservationsInsert['result'] = 'fail';
         }
     }
     return $resumeToObservationsInsert;
 }
 public function postOneObservationsAction()
 {
     $this->observationService->setManager($this->getDoctrine()->getManager());
     $inscriptionService = new InscriptionService();
     $inscriptionService->setManager($this->getDoctrine()->getManager());
     $params = array();
     $content = $this->get("request")->getContent();
     $params = json_decode($content, true);
     if (!empty($params['inscription']) && !empty($params['observation'])) {
         $inscription = $inscriptionService->getInscription($params['inscription']);
         $observations = $this->observationService->saveObservation($params['observation'], $inscription, $this);
         if ($observations['result'] == 'fail') {
             $dataToSend = json_encode(array('error' => $observations['message']));
             return $this->util->setResponse(400, $dataToSend);
         }
         $dataToSend = json_encode(array('observations' => $observations['message']));
         return $this->util->setJsonResponse(201, $dataToSend);
     } else {
         return $this->util->setResponse(400, Literals::ObservationBadFormat);
     }
 }