Esempio n. 1
0
 /**
  * Sauvegarde d'un matériel.
  *
  * @param array $data
  * @param array $id_materiel Optionnel
  *
  * @return SDIS62\Core\Ops\Entity\Centre
  */
 public function save($data, $id_materiel = null)
 {
     $centre = $this->centre_repository->find($data['centre']);
     if (empty($centre)) {
         return;
     }
     $materiel = empty($id_materiel) ? new Materiel($centre, $data['name']) : $this->materiel_repository->find($id_materiel);
     if (!empty($data['name'])) {
         $materiel->setName($data['name']);
     }
     if (!empty($data['centre'])) {
         $materiel->setCentre($centre);
     }
     if (!empty($data['statut'])) {
         $materiel->setStatut(Statut::getByName($data['statut']));
     }
     if (!empty($data['coordinates']) && is_array($data['coordinates']) && count($data['coordinates']) == 2) {
         $materiel->setCoordinates(new Coordinates($data['coordinates'][0], $data['coordinates'][1]));
     }
     $this->materiel_repository->save($materiel);
     return $materiel;
 }
Esempio n. 2
0
 /**
  * Get the value of Etat du pompier.
  *
  * @return SDIS62\Core\Ops\Entity\Statut
  */
 public function getStatut()
 {
     return $this->statut instanceof Statut ? $this->statut : Statut::getByName($this->statut);
 }
Esempio n. 3
0
 /**
  * Sauvegarde d'un pompier.
  *
  * @param array $data
  * @param array $id_pompier Optionnel
  *
  * @return SDIS62\Core\Ops\Entity\Pompier
  */
 public function save($data)
 {
     if (!empty($data['matricule'])) {
         $pompier = $this->pompier_repository->find($data['matricule']);
     }
     if (empty($pompier)) {
         $centre = $this->centre_repository->find($data['centre']);
         if (empty($centre)) {
             return;
         }
         switch ($data['type']) {
             case 'pompier':
                 $pompier = new Pompier($data['name'], $data['matricule'], $centre);
                 break;
             case 'specialiste':
                 $pompier = new Pompier\SpecialistePompier($data['name'], $data['matricule'], $centre);
                 break;
             default:
                 throw new InvalidPompierException();
         }
     }
     if (!empty($data['centre'])) {
         $pompier->setCentre($this->centre_repository->find($data['centre']));
     }
     if (!empty($data['name'])) {
         $pompier->setName($data['name']);
     }
     if (!empty($data['specialites'])) {
         $pompier->setSpecialites($data['specialites']);
     }
     if (!empty($data['phone_number'])) {
         $pompier->setPhoneNumber($data['phone_number']);
     }
     if (!empty($data['statut'])) {
         $pompier->setStatut(Statut::getByName($data['statut']));
     }
     if (array_key_exists('pro', $data)) {
         $pompier->setPro($data['pro'] === true);
     }
     if (!empty($data['coordinates']) && is_array($data['coordinates']) && count($data['coordinates']) >= 2) {
         $pompier->setCoordinates(new Coordinates($data['coordinates'][0], $data['coordinates'][1], array_key_exists(2, $data['coordinates']) ? $data['coordinates'][2] : null));
     }
     $this->pompier_repository->save($pompier);
     return $pompier;
 }