public function switchantennaAction()
 {
     $json = array();
     $messages = array();
     if ($this->isGranted('events.write') && $this->zfcUserAuthentication()->hasIdentity()) {
         $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         $state = $this->params()->fromQuery('state', null);
         $antennaid = $this->params()->fromQuery('antennaid', null);
         $freqid = $this->params()->fromQuery('freq', null);
         $now = new \DateTime('NOW');
         $now->setTimezone(new \DateTimeZone("UTC"));
         if ($state != null && $antennaid) {
             $events = $em->getRepository('Application\\Entity\\Event')->getCurrentEvents('Application\\Entity\\AntennaCategory');
             // on récupère les évènements de l'antenne
             $antennaEvents = array();
             foreach ($events as $event) {
                 $antennafield = $event->getCategory()->getAntennafield();
                 foreach ($event->getCustomFieldsValues() as $value) {
                     if ($value->getCustomField()->getId() == $antennafield->getId()) {
                         if ($value->getValue() == $antennaid) {
                             $antennaEvents[] = $event;
                         }
                     }
                 }
             }
             if ($state == 'true') {
                 // recherche de l'evt à fermer
                 if (count($antennaEvents) == 1) {
                     $event = $antennaEvents[0];
                     if ($freqid) {
                         $freqidEventValue = $event->getCustomFieldValue($event->getCategory()->getFrequenciesField());
                         if ($freqidEventValue) {
                             $freqids = explode("\r", $freqidEventValue->getValue());
                             if (in_array($freqid, $freqids)) {
                                 $newfreqvalue = "";
                                 foreach ($freqids as $freq) {
                                     if ($freq != $freqid) {
                                         $newfreqvalue .= $freq . "\r";
                                     }
                                 }
                                 $newfreqvalue = trim($newfreqvalue);
                                 if (strlen($newfreqvalue) === 0) {
                                     // fermer l'evt
                                     $endstatus = $em->getRepository('Application\\Entity\\Status')->find('3');
                                     $event->setStatus($endstatus);
                                     // ferme evts fils de type frequencycategory
                                     foreach ($event->getChildren() as $child) {
                                         if ($child->getCategory() instanceof FrequencyCategory) {
                                             $child->setEnddate($now);
                                             $child->setStatus($endstatus);
                                             $em->persist($child);
                                         }
                                     }
                                     $event->setEnddate($now);
                                     $em->persist($event);
                                     try {
                                         $em->flush();
                                         $messages['success'][] = "Evènement antenne correctement terminé.";
                                     } catch (\Exception $e) {
                                         $messages['error'][] = $e->getMessage();
                                     }
                                 } else {
                                     $freqidEventValue->setValue(trim($newfreqvalue));
                                     $em->persist($freqidEventValue);
                                     try {
                                         $em->flush();
                                         $messages['success'][] = "Evènement antenne correctement terminé.";
                                     } catch (\Exception $e) {
                                         $messages['error'][] = $e->getMessage();
                                     }
                                 }
                             } else {
                                 $messages['error'][] = "Evènement en cours incompatible.";
                             }
                         } else {
                             $messages['error'][] = "Evènement en cours incompatible.";
                         }
                     } else {
                         $endstatus = $em->getRepository('Application\\Entity\\Status')->find('3');
                         $event->setStatus($endstatus);
                         // ferme evts fils de type frequencycategory
                         foreach ($event->getChildren() as $child) {
                             if ($child->getCategory() instanceof FrequencyCategory) {
                                 $child->setEnddate($now);
                                 $child->setStatus($endstatus);
                                 $em->persist($child);
                             }
                         }
                         $event->setEnddate($now);
                         $em->persist($event);
                         try {
                             $em->flush();
                             $messages['success'][] = "Evènement antenne correctement terminé.";
                         } catch (\Exception $e) {
                             $messages['error'][] = $e->getMessage();
                         }
                     }
                 } else {
                     $messages['error'][] = "Impossible de déterminer l'évènement à terminer";
                 }
             } else {
                 //antenne indisponible
                 if (count($antennaEvents) > 0) {
                     $messages['error'][] = "Un évènement est déjà en cours, impossible d'en créer un nouveau.";
                 } else {
                     $event = new Event();
                     $status = $em->getRepository('Application\\Entity\\Status')->find('2');
                     $impact = $em->getRepository('Application\\Entity\\Impact')->find('3');
                     $event->setStatus($status);
                     $event->setStartdate($now);
                     $event->setImpact($impact);
                     $event->setPunctual(false);
                     $antenna = $em->getRepository('Application\\Entity\\Antenna')->find($antennaid);
                     $event->setOrganisation($antenna->getOrganisation());
                     // TODO et si une antenne appartient à plusieurs orga ?
                     $event->setAuthor($this->zfcUserAuthentication()->getIdentity());
                     $categories = $em->getRepository('Application\\Entity\\AntennaCategory')->findBy(array('defaultantennacategory' => true));
                     $frequency = null;
                     if ($freqid) {
                         $frequency = $em->getRepository('Application\\Entity\\Frequency')->find($freqid);
                     }
                     if ($categories) {
                         $em->persist($event);
                         $cat = $categories[0];
                         $antennafieldvalue = new CustomFieldValue();
                         $antennafieldvalue->setCustomField($cat->getAntennaField());
                         $antennafieldvalue->setValue($antennaid);
                         $antennafieldvalue->setEvent($event);
                         $event->addCustomFieldValue($antennafieldvalue);
                         $statusvalue = new CustomFieldValue();
                         $statusvalue->setCustomField($cat->getStateField());
                         $statusvalue->setValue(true);
                         $statusvalue->setEvent($event);
                         $event->addCustomFieldValue($statusvalue);
                         if ($frequency && $frequency->hasAntenna($antenna)) {
                             $freqvalue = new CustomFieldValue();
                             $freqvalue->setCustomField($cat->getFrequenciesField());
                             $freqvalue->setValue($frequency->getId());
                             $freqvalue->setEvent($event);
                             $event->addCustomFieldValue($freqvalue);
                             $em->persist($freqvalue);
                         }
                         $event->setCategory($categories[0]);
                         // création des evts fils pour le passage en secours
                         if ($frequency && $frequency->hasAntenna($antenna)) {
                             // une seule fréquence impactée
                             if ($frequency->hasMainAntenna($antenna) || $frequency->hasMainClimaxAntenna($antenna)) {
                                 $em->getRepository('Application\\Entity\\Event')->addChangeFrequencyCovEvent($frequency, 1, 0, "Antenne principale indisponible", $now, null, $this->zfcUserAuthentication()->getIdentity(), $event, $messages);
                             }
                         } else {
                             // toutes les fréquences impactées
                             foreach ($antenna->getMainfrequencies() as $frequency) {
                                 $em->getRepository('Application\\Entity\\Event')->addChangeFrequencyCovEvent($frequency, 1, 0, "Antenne principale indisponible", $now, null, $this->zfcUserAuthentication()->getIdentity(), $event, $messages);
                             }
                             foreach ($antenna->getMainfrequenciesclimax() as $frequency) {
                                 $em->getRepository('Application\\Entity\\Event')->addChangeFrequencyCovEvent($frequency, 1, 0, "Antenne principale indisponible", $now, null, $this->zfcUserAuthentication()->getIdentity(), $event, $messages);
                             }
                             // création de la fiche réflexe
                             if ($antenna->getModel()) {
                                 foreach ($em->getRepository('Application\\Entity\\PredefinedEvent')->findBy(array('parent' => $antenna->getModel()->getId())) as $action) {
                                     $child = new Event();
                                     $child->setParent($event);
                                     $child->setAuthor($event->getAuthor());
                                     $child->setOrganisation($event->getOrganisation());
                                     $child->createFromPredefinedEvent($action);
                                     $child->setStatus($em->getRepository('Application\\Entity\\Status')->findOneBy(array('defaut' => true, 'open' => true)));
                                     foreach ($action->getCustomFieldsValues() as $value) {
                                         $newvalue = new CustomFieldValue();
                                         $newvalue->setEvent($child);
                                         $newvalue->setCustomField($value->getCustomField());
                                         $newvalue->setValue($value->getValue());
                                         $child->addCustomFieldValue($newvalue);
                                         $em->persist($newvalue);
                                     }
                                     $child->updateAlarmDate();
                                     $em->persist($child);
                                 }
                                 // ajout des fichiers
                                 foreach ($antenna->getModel()->getFiles() as $file) {
                                     $file->addEvent($event);
                                 }
                             }
                         }
                         try {
                             $event->updateAlarms();
                             $em->persist($event);
                             $em->flush();
                             $messages['success'][] = "Nouvel évènement antenne créé.";
                         } catch (\Exception $e) {
                             $messages['error'][] = $e->getMessage();
                         }
                     } else {
                         $messages['error'][] = "Impossible de créer un nouvel évènement. Contactez l'administrateur.";
                     }
                 }
             }
         } else {
             $messages['error'][] = "Requête incorrecte, impossible de trouver l'antenne correspondante.";
         }
     } else {
         $messages['error'][] = 'Droits insuffisants pour modifier l\'état de l\'antenne.';
     }
     $json['messages'] = $messages;
     $json['frequencies'] = $this->getFrequencies();
     return new JsonModel($json);
 }
Example #2
0
 public function switchradarAction()
 {
     $messages = array();
     if ($this->isGranted('events.write') && $this->zfcUserAuthentication()->hasIdentity()) {
         $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         $post = $this->getRequest()->getPost();
         $state = $this->params()->fromQuery('state', null);
         $radarid = $this->params()->fromQuery('radarid', null);
         $now = new \DateTime('NOW');
         $now->setTimezone(new \DateTimeZone("UTC"));
         if ($state != null && $radarid) {
             $events = $em->getRepository('Application\\Entity\\Event')->getCurrentEvents('Application\\Entity\\RadarCategory');
             $radarevents = array();
             foreach ($events as $event) {
                 $radarfield = $event->getCategory()->getRadarfield();
                 foreach ($event->getCustomFieldsValues() as $value) {
                     if ($value->getCustomField()->getId() == $radarfield->getId()) {
                         if ($value->getValue() == $radarid) {
                             $radarevents[] = $event;
                         }
                     }
                 }
             }
             if ($state == 'true') {
                 // passage d'un radar à l'état OPE -> recherche de l'evt à fermer
                 if (count($radarevents) == 1) {
                     $event = $radarevents[0];
                     $endstatus = $em->getRepository('Application\\Entity\\Status')->find('3');
                     $event->setStatus($endstatus);
                     $event->setEnddate($now);
                     $em->persist($event);
                     try {
                         $em->flush();
                         $messages['success'][] = "Evènement radar correctement terminé.";
                     } catch (\Exception $e) {
                         $messages['error'][] = $e->getMessage();
                     }
                 } else {
                     $messages['error'][] = "Impossible de déterminer l'évènement à terminer.";
                 }
             } else {
                 // passage d'un radar à l'état HS -> on vérifie qu'il n'y a pas d'evt en cours
                 if (count($radarevents) > 0) {
                     $messages['error'][] = "Un évènement est déjà en cours pour ce radar, impossible d'en créer un nouveau";
                 } else {
                     $event = new Event();
                     $status = $em->getRepository('Application\\Entity\\Status')->find('2');
                     $impact = $em->getRepository('Application\\Entity\\Impact')->find('3');
                     $event->setStatus($status);
                     $event->setStartdate($now);
                     $event->setImpact($impact);
                     $event->setPunctual(false);
                     $radar = $em->getRepository('Application\\Entity\\Radar')->find($radarid);
                     $event->setOrganisation($radar->getOrganisation());
                     $event->setAuthor($this->zfcUserAuthentication()->getIdentity());
                     $categories = $em->getRepository('Application\\Entity\\RadarCategory')->findBy(array('defaultradarcategory' => true));
                     if ($categories) {
                         $cat = $categories[0];
                         $radarfieldvalue = new CustomFieldValue();
                         $radarfieldvalue->setCustomField($cat->getRadarfield());
                         $radarfieldvalue->setValue($radarid);
                         $radarfieldvalue->setEvent($event);
                         $event->addCustomFieldValue($radarfieldvalue);
                         $statusvalue = new CustomFieldValue();
                         $statusvalue->setCustomField($cat->getStatefield());
                         $statusvalue->setValue(true);
                         $statusvalue->setEvent($event);
                         $event->addCustomFieldValue($statusvalue);
                         $event->setCategory($categories[0]);
                         $em->persist($radarfieldvalue);
                         $em->persist($statusvalue);
                         //on ajoute les valeurs des champs persos
                         if (isset($post['custom_fields'])) {
                             foreach ($post['custom_fields'] as $key => $value) {
                                 // génération des customvalues si un customfield dont le nom est $key est trouvé
                                 $customfield = $em->getRepository('Application\\Entity\\CustomField')->findOneBy(array('id' => $key));
                                 if ($customfield) {
                                     if (is_array($value)) {
                                         $temp = "";
                                         foreach ($value as $v) {
                                             $temp .= (string) $v . "\r";
                                         }
                                         $value = trim($temp);
                                     }
                                     $customvalue = new CustomFieldValue();
                                     $customvalue->setEvent($event);
                                     $customvalue->setCustomField($customfield);
                                     $event->addCustomFieldValue($customvalue);
                                     $customvalue->setValue($value);
                                     $em->persist($customvalue);
                                 }
                             }
                         }
                         //et on sauve le tout
                         $em->persist($event);
                         try {
                             $em->flush();
                             $messages['success'][] = "Nouvel évènement radar créé.";
                         } catch (\Exception $e) {
                             $messages['error'][] = $e->getMessage();
                         }
                     } else {
                         $messages['error'][] = "Impossible de créer un nouvel évènement.";
                     }
                 }
             }
         } else {
             $messages['error'][] = "Requête incorrecte, impossible de trouver le radar correspondant.";
         }
     } else {
         $messages['error'][] = "Droits insuffisants pour modifier l'état du radar";
     }
     return new JsonModel($messages);
 }
Example #3
0
 /**
  * Renvoit un nouvel évènement créé à partir d'un évènement et d'une date de début
  * Les notes ne sont pas copiées, le statut est mis à "nouveau"
  * @param Event $event
  * @param \DateTime $start UTC start date
  */
 public function createFromEvent(Event $event, $start)
 {
     $newevent = new Event();
     $newevent->setAuthor($event->getAuthor());
     $newevent->setOrganisation($event->getOrganisation());
     $newevent->setCategory($event->getCategory());
     $newevent->setImpact($event->getImpact());
     $newevent->setStatus($this->getEntityManager()->getRepository('Application\\Entity\\Status')->find(1));
     if ($event->getPlace() !== null) {
         $newevent->setPlace($event->getPlace());
     }
     //horaires
     $newevent->setScheduled($event->isScheduled());
     $newevent->setPunctual($event->isPunctual());
     if ($start !== null) {
         //actions can have no start date
         $newevent->setStartdate($start);
         if (!$event->isPunctual() && $event->getEnddate() !== null) {
             $diff = $event->getStartdate()->diff($event->getEnddate());
             $end = clone $start;
             $end->add($diff);
             $newevent->setEnddate($end);
         }
     }
     //enfants
     foreach ($event->getChildren() as $child) {
         $childdate = $start;
         if ($child->getCategory() instanceof AlarmCategory) {
             $diff = $event->getStartdate()->diff($child->getStartdate());
             $alarmdate = clone $newevent->getStartdate();
             $alarmdate->add($diff);
             $childdate = $alarmdate;
         } else {
             if ($child->getCategory() instanceof ActionCategory) {
                 $childdate = null;
             }
         }
         $childEvent = $this->createFromEvent($child, $childdate);
         $childEvent->setParent($newevent);
         $newevent->addChild($childEvent);
     }
     //champs
     foreach ($event->getCustomFieldsValues() as $customFieldsValue) {
         $customFieldValue = new CustomFieldValue();
         $customFieldValue->setEvent($newevent);
         $customFieldValue->setCustomField($customFieldsValue->getCustomField());
         $customFieldValue->setValue($customFieldsValue->getValue());
         $newevent->addCustomFieldValue($customFieldValue);
     }
     //fichiers
     foreach ($event->getFiles() as $file) {
         $newevent->addFile($file);
     }
     return $newevent;
 }
Example #4
0
 /**
  * Change la date de début d'un evt et
  * - vérifie la cohérence des évènements fils
  * - vérifie la cohérence du statut
  * 
  * @param \Application\Entity\Event $event            
  * @param \DateTime $startdate            
  * @param
  *            array Messages
  * @return true Si tout s'est bien passé
  */
 private function changeStartDate(Event $event, \DateTime $startdate, &$messages = null)
 {
     $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $formatter = \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, 'UTC', \IntlDateFormatter::GREGORIAN, 'dd LLL, HH:mm');
     if ($event->setStartdate($startdate)) {
         if (is_array($messages)) {
             $messages['success'][] = "Date et heure de début modifiées au " . $formatter->format($event->getStartdate());
         }
         // passage au statut confirmé si pertinent, droits ok et heure de début proche de l'heure actuelle
         if ($this->isGranted('events.confirme')) {
             $now = new \DateTime('now');
             $now->setTimezone(new \DateTimeZone('UTC'));
             $status = $objectManager->getRepository('Application\\Entity\\Status')->findOneBy(array('open' => true, 'defaut' => false));
             if ($event->getStatus()->getId() == 1 && ($event->getStartDate()->format('U') - $now->format('U')) / 60 < 15) {
                 $event->setStatus($status);
                 if (is_array($messages)) {
                     $messages['success'][] = "Evènement passé au statut : confirmé.";
                 }
             }
         }
         // changement de l'heure de début des évènements fils si pertinent
         foreach ($event->getChildren() as $child) {
             if ($child->getCategory() instanceof FrequencyCategory) {
                 $child->setStartdate($startdate);
                 $objectManager->persist($child);
             }
         }
         $event->updateAlarms();
         $objectManager->persist($event);
     } else {
         if (is_array($messages)) {
             $messages['error'][] = "Impossible de changer l'heure de début.";
         }
     }
 }
Example #5
0
 private function doAddMilEvent(\Application\Entity\MilCategory $cat, \Application\Entity\Organisation $organisation, \Core\Entity\User $user, $designator, \DateTime $timeBegin, \DateTime $timeEnd, $upperLevel, $lowerLevel, &$messages)
 {
     $event = new \Application\Entity\Event();
     $event->setOrganisation($organisation);
     $event->setAuthor($user);
     $event->setCategory($cat);
     $event->setScheduled(false);
     $event->setPunctual(false);
     $event->setStartdate($timeBegin);
     $status = $this->getEntityManager()->getRepository('Application\\Entity\\Status')->find('1');
     $event->setStatus($status);
     $impact = $this->getEntityManager()->getRepository('Application\\Entity\\Impact')->find('2');
     $event->setImpact($impact);
     $event->setEnddate($timeEnd);
     // name
     $name = new \Application\Entity\CustomFieldValue();
     $name->setCustomField($cat->getFieldname());
     $name->setEvent($event);
     $name->setValue($designator);
     // upperlevel
     $upper = new \Application\Entity\CustomFieldValue();
     $upper->setCustomField($cat->getUpperLevelField());
     $upper->setEvent($event);
     $upper->setValue($upperLevel);
     // lowerlevel
     $lower = new \Application\Entity\CustomFieldValue();
     $lower->setCustomField($cat->getLowerLevelField());
     $lower->setEvent($event);
     $lower->setValue($lowerLevel);
     // recherche d'un modèle existant
     $models = $this->getEntityManager()->getRepository('Application\\Entity\\PredefinedEvent')->findBy(array('name' => $designator, 'organisation' => $organisation, 'category' => $cat));
     if (count($models) === 1) {
         $model = $models[0];
         // ajout des mémos
         foreach ($model->getChildren() as $child) {
             if ($child->getCategory() instanceof \Application\Entity\AlarmCategory) {
                 $alarm = new Event();
                 $alarm->setCategory($this->getEntityManager()->getRepository('Application\\Entity\\AlarmCategory')->findAll()[0]);
                 $alarm->setAuthor($user);
                 $alarm->setOrganisation($organisation);
                 $alarm->setParent($event);
                 $alarm->setStatus($status);
                 $alarm->setPunctual(true);
                 $alarm->setImpact($impact);
                 $startdate = $timeBegin;
                 $alarm->setStartdate($startdate);
                 $namememo = new CustomFieldValue();
                 $namefield = $alarm->getCategory()->getNamefield();
                 $namememo->setCustomField($namefield);
                 $namememo->setValue($child->getCustomFieldValue($namefield)->getValue());
                 $namememo->setEvent($alarm);
                 $alarm->addCustomFieldValue($namememo);
                 $comment = new CustomFieldValue();
                 $commentfield = $alarm->getCategory()->getTextfield();
                 $comment->setCustomField($commentfield);
                 $comment->setValue($child->getCustomFieldValue($commentfield)->getValue());
                 $comment->setEvent($alarm);
                 $alarm->addCustomFieldValue($comment);
                 $deltabegin = new CustomFieldValue();
                 $beginfield = $alarm->getCategory()->getDeltaBeginField();
                 $deltabegin->setCustomField($beginfield);
                 $deltabegin->setValue($child->getCustomFieldValue($beginfield)->getValue());
                 $deltabegin->setEvent($alarm);
                 $alarm->addCustomFieldValue($deltabegin);
                 $deltaend = new CustomFieldValue();
                 $endfield = $alarm->getCategory()->getDeltaEndField();
                 $deltaend->setCustomField($endfield);
                 $deltaend->setValue($child->getCustomFieldValue($endfield)->getValue());
                 $deltaend->setEvent($alarm);
                 $alarm->addCustomFieldValue($deltaend);
                 $event->addChild($alarm);
                 $this->getEntityManager()->persist($namememo);
                 $this->getEntityManager()->persist($comment);
                 $this->getEntityManager()->persist($deltabegin);
                 $this->getEntityManager()->persist($deltaend);
                 $this->getEntityManager()->persist($alarm);
             }
         }
         //ajout des fichiers
         foreach ($model->getFiles() as $file) {
             $file->addEvent($event);
             $this->getEntityManager()->persist($file);
         }
         $event->updateAlarms();
     }
     try {
         $this->getEntityManager()->persist($name);
         $this->getEntityManager()->persist($upper);
         $this->getEntityManager()->persist($lower);
         $this->getEntityManager()->persist($event);
         $this->getEntityManager()->flush();
     } catch (\Exception $ex) {
         error_log($ex->getMessage());
         if ($messages != null) {
             $messages['error'][] = $ex->getMessage();
         }
     }
 }