示例#1
0
 public static function checkControllersIdentifierName($controller, $name, $nb_controller)
 {
     $controllers = BasePhysicalAccessController::getControllers();
     $results = array();
     if (!empty($controllers)) {
         for ($i = 1; $i <= $nb_controller; $i++) {
             foreach ($controllers as $key => $value) {
                 $c_name = $key . $i;
                 // print '<br /> ====> '.$c_name.' : ';
                 $i_name = self::getParameter($c_name, 'controller_name');
                 // print $i_name.'<br />';
                 // print '<br /> SI '.$name.' == '.$i_name.' ET SI '.$c_name.' != '.$controller.'<br /><br />';
                 if ($name == $i_name && $c_name != $controller) {
                     // print '<br /> ERREUR : NOM RETROUVE <br/>';
                     $results['valid'] = false;
                     $results['cname1'] = $c_name;
                     $results['cname2'] = $controller;
                     return $results;
                 }
             }
         }
     }
     // print '<br/> OK : NOM DISPO <br/>';
     $results['valid'] = true;
     return $results;
 }
 public function __construct($name, $configuration = null)
 {
     if (empty($name)) {
         throw new InvalidArgumentException('`$name`cannot be empty');
     }
     $this->name = $name;
     $this->physical_access_controller = BasePhysicalAccessController::create($this->name, $configuration);
     parent::__construct();
 }
示例#3
0
 public function executeUpdate(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     $post_parameters = $request->getParameter('configuration');
     $this->nb_controller = intval($post_parameters['number_of_physical_access']);
     $this->nb_home_automation = intval($post_parameters['number_of_home_automation']);
     $this->physical_access_controllers = BasePhysicalAccessController::getControllers();
     $this->home_automation_controllers = BaseHomeAutomationController::getControllers();
     $this->form = new ConfigurationForm(null, array('nb_pac' => $this->nb_controller, 'nb_hac' => $this->nb_home_automation));
     if ($this->nb_controller > $this->form->getMaxControllers()) {
         $this->nb_controller = $this->form->getMaxControllers();
     }
     if ($this->nb_home_automation > $this->form->getMaxHomeAutomation()) {
         $this->nb_home_automation = $this->form->getMaxHomeAutomation();
     }
     // Gestion des contrôleurs d'accès supplémentaires et de leurs valeurs par défaut (si l'on augmente le nombre de contrôleurs d'accès)
     for ($i = 1; $i <= $this->nb_controller; $i++) {
         if (!isset($post_parameters['physical_access_controller' . $i])) {
             foreach ($this->physical_access_controllers as $pac => $name) {
                 $controller = BasePhysicalAccessController::create($pac);
                 $post_parameters[$pac . $i] = $controller->getDefaultValues();
                 // On modifie le nom identifiant par défaut et on y ajoute i
                 $post_parameters[$pac . $i]['controller_name'] = $controller->getName() . $i;
             }
         }
     }
     // Gestion des contrôleurs domotiques supplémentaires et de leurs valeurs par défaut (si l'on augmente le nombre de contrôleurs domotiques)
     for ($i = 1; $i <= $this->nb_home_automation; $i++) {
         if (!isset($post_parameters['home_automation_controller' . $i])) {
             foreach ($this->home_automation_controllers as $hac => $name) {
                 $controller = BaseHomeAutomationController::create($hac);
                 $post_parameters[$hac . $i] = $controller->getDefaultValues();
                 // On modifie le nom identifiant par défaut et on y ajoute i
                 $post_parameters[$hac . $i]['controller_name'] = $controller->getName() . $i;
             }
         }
     }
     // Gestion des contrôleurs d'accès en trop (si l'on réduit le nombre de contrôleurs d'accès)
     for ($i = $this->nb_controller + 1; $i <= $this->form->getMaxControllers(); $i++) {
         if (isset($post_parameters['physical_access_controller' . $i])) {
             unset($post_parameters['physical_access_controller' . $i]);
             foreach ($this->physical_access_controllers as $pac => $name) {
                 unset($post_parameters[$pac . $i]);
             }
         }
     }
     // Gestion des contrôleurs domotiques en trop (si l'on réduit le nombre de contrôleurs domotiques)
     for ($i = $this->nb_home_automation + 1; $i <= $this->form->getMaxHomeAutomation(); $i++) {
         if (isset($post_parameters['home_automation_controller' . $i])) {
             unset($post_parameters['home_automation_controller' . $i]);
             foreach ($this->home_automation_controllers as $hac => $name) {
                 unset($post_parameters[$hac . $i]);
             }
         }
     }
     $this->form->bind($post_parameters, $request->getFiles($this->form->getName()));
     if ($this->form->isValid()) {
         $isout = false;
         // Modifie les noms de chaque profil d'accès si un nom identifiant change et vérifie que chaque nom est unique
         if (!empty($this->physical_access_controllers)) {
             for ($i = 1; $i <= $this->nb_controller; $i++) {
                 foreach ($this->physical_access_controllers as $key => $value) {
                     $roomprofiles = array();
                     $controller_name = $key . $i;
                     // print  '<br/>------------------------------<br/>'.$controller_name.'<br />';
                     $params = $post_parameters[$controller_name];
                     $exname = ConfigurationHelper::getParameter($controller_name, 'controller_name');
                     $newname = $params['controller_name'];
                     // print 'ex-new : '.$exname.' - '.$newname.'<br />';
                     if ($exname != $newname) {
                         $roomprofiles = RoomprofilePeer::setAllNewIdentifierName($exname, $newname);
                     }
                     $this->checkError = ConfigurationHelper::checkControllersIdentifierName($controller_name, $newname, $this->nb_controller);
                     if (!$this->checkError['valid']) {
                         $isout = true;
                         break;
                     }
                     if (isset($roomprofiles)) {
                         if (!empty($roomprofiles)) {
                             foreach ($roomprofiles as $roomprofile) {
                                 $roomprofile->save();
                             }
                         }
                     }
                 }
                 if ($isout) {
                     break;
                 }
             }
         }
         // Modifie les noms de chaque contrôleur domotique si un nom identifiant change et vérifie que chaque nom est unique
         if (!empty($this->home_automation_controllers) && !$isout) {
             for ($i = 1; $i <= $this->nb_home_automation; $i++) {
                 foreach ($this->home_automation_controllers as $key => $value) {
                     $energyactions = array();
                     $controller_name = $key . $i;
                     // print  '<br/>------------------------------<br/>'.$controller_name.'<br />';
                     $params = $post_parameters[$controller_name];
                     $exname = ConfigurationHelper::getParameter($controller_name, 'controller_name');
                     $newname = $params['controller_name'];
                     // print 'ex-new : '.$exname.' - '.$newname.'<br />';
                     if ($exname != $newname) {
                         $energyactions = EnergyactionPeer::setAllNewIdentifierName($exname, $newname);
                     }
                     $this->checkError = ConfigurationHelper::checkAutomationsIdentifierName($controller_name, $newname, $this->nb_home_automation);
                     if (!$this->checkError['valid']) {
                         $isout = true;
                         break;
                     }
                     if (isset($energyactions)) {
                         if (!empty($energyactions)) {
                             foreach ($energyactions as $energyaction) {
                                 $energyaction->save();
                             }
                         }
                     }
                 }
                 if ($isout) {
                     break;
                 }
             }
         }
         if (!$isout) {
             $this->form->save();
             $this->saved = true;
         } else {
             $this->saved = false;
         }
     } else {
         $this->saved = false;
     }
     $this->setTemplate('home');
 }
示例#4
0
 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $this->context = sfContext::createInstance($this->configuration);
     $databaseManager = new sfDatabaseManager($this->configuration);
     ConfigurationHelper::load();
     $nb_controllers = ConfigurationHelper::get('number_of_physical_access');
     $reservations = ReservationPeer::doSelectPendingReservations($options['include-inactive'], $delayedTime);
     if (empty($reservations)) {
         $this->logSection('tempos', 'check - No reservations pending. Doing nothing.', 1024);
     } else {
         $this->logSection('tempos', sprintf('check - %d reservation(s) pending.', count($reservations)), 1024);
         $i = 0;
         foreach ($reservations as $reservation) {
             $roomprofile_id = $reservation->getRoomprofile()->getId();
             $roomprofile = RoomprofilePeer::doSelectFromId($roomprofile_id);
             $rp_controllername = $roomprofile->getConfiguredControllerName();
             $pac_infos = BasePhysicalAccessController::findPacFromNameIdentifier($rp_controllername);
             if (is_null($pac_infos) || empty($pac_infos)) {
                 $this->logSection('tempos', sprintf('check - Can\'t create a physical access controller for this reservation: id(%s)', $reservation->getId()), 1024);
                 continue;
             }
             $pac_name = $pac_infos['name'];
             // print 'pac_name: ';
             // var_dump($pac_name);
             $pac_id = $pac_infos['id'];
             // print 'pac_id: ';
             // var_dump($pac_id);
             $pac_selec = ConfigurationHelper::getParameter(null, $pac_name);
             // print 'pac_selec: ';
             // var_dump($pac_selec);
             $pac_conf = ConfigurationHelper::getNamespace($pac_selec . $pac_id);
             // print 'pac_conf: ';
             // var_dump($pac_conf);
             // var_dump($pac_infos);
             $pac = BasePhysicalAccessController::create($pac_selec, $pac_conf);
             // var_dump($pac);
             $delay = $pac->getParameter('delay');
             // print 'delay: ';
             // var_dump($delay);
             $pac->setVerbose($options['verbose']);
             $this->logSection('tempos', sprintf('check - Creating a physical access controller: %s', $pac->getName()), 1024);
             if (is_null($delay) || empty($delay)) {
                 $delay = 0;
             }
             $now = time();
             $delayedTime = time() + $delay * 60;
             // Need to add the delay in milliseconds to the time() function
             $this->logSection('tempos', sprintf('check - Checking reservations at: %s', strftime('%c', $now)), 1024);
             if ($delay > 0) {
                 $this->logSection('tempos', sprintf('check - There is a starting delay ! Need to start reservation %s minutes before the reservation date !', $delay), 1024);
                 $this->logSection('tempos', sprintf('check - Finally looking reservations at: %s', strftime('%c', $delayedTime)), 1024);
             }
             if ($delay > 0) {
                 $this->logSection('tempos', sprintf("check - \t(%d)\tBefore delay: %s", $i, $reservation->__toString()), 1024);
                 $reservation->updateDateWithDelay($delay);
                 $this->logSection('tempos', sprintf("check - \t(%d)\tAfter delay: %s", $i, $reservation->__toString()), 1024);
             } else {
                 $this->logSection('tempos', sprintf("check - \t(%d)\tReservation: %s", $i, $reservation->__toString()), 1024);
             }
             $results = $pac->sendReservation($reservation, $options['update-status']);
             if (empty($results)) {
                 $this->logSection('tempos', sprintf("check - \t\tSuccess."), 1024);
             } else {
                 foreach ($results as $result) {
                     $this->logSection('tempos', sprintf("check - \t\t%s: %s", $result['person'], $result['exception']->getMessage()), 1024, 'ERROR');
                 }
             }
             $i++;
         }
     }
 }
 public function configure()
 {
     $physical_access_controllers = BasePhysicalAccessController::getControllers();
     $home_automation_controllers = BaseHomeAutomationController::getControllers();
     $this->widgetSchema['number_of_physical_access'] = new sfWidgetFormInput();
     $this->validatorSchema['number_of_physical_access'] = new sfValidatorInteger(array('min' => 0, 'max' => $this->max_controllers, 'required' => true));
     $this->widgetSchema->setLabel('number_of_physical_access', 'Number of physical access controllers');
     if (!is_null($this->getOption('nb_pac'))) {
         $nb_pac = $this->getOption('nb_pac');
     } else {
         $nb_pac = ConfigurationHelper::getParameter(null, 'number_of_physical_access');
     }
     if ($nb_pac > $this->max_controllers) {
         $nb_pac = $this->max_controllers;
     }
     if (count($physical_access_controllers) > 0) {
         for ($i = 1; $i <= $nb_pac; $i++) {
             $this->widgetSchema['physical_access_controller' . $i] = new sfWidgetFormChoice(array('choices' => $physical_access_controllers));
             $this->validatorSchema['physical_access_controller' . $i] = new sfValidatorChoice(array('choices' => array_keys($physical_access_controllers), 'required' => false));
             $this->widgetSchema->setLabel('physical_access_controller' . $i, 'Physical Access Controller');
             foreach ($physical_access_controllers as $physical_access_controller => $name) {
                 $form = PhysicalAccessControllerConfigurationForm::create($physical_access_controller, null);
                 $labelName = $form->getPhysicalAccessController()->getName() . $i;
                 $this->embedForm($labelName, $form);
                 $this->widgetSchema->setLabel($labelName, $name);
             }
         }
     }
     $this->widgetSchema['number_of_home_automation'] = new sfWidgetFormInput();
     $this->validatorSchema['number_of_home_automation'] = new sfValidatorInteger(array('min' => 0, 'max' => $this->max_home_automation, 'required' => true));
     $this->widgetSchema->setLabel('number_of_home_automation', 'Number of home automation controllers');
     if (!is_null($this->getOption('nb_hac'))) {
         $nb_hac = $this->getOption('nb_hac');
     } else {
         $nb_hac = ConfigurationHelper::getParameter(null, 'number_of_home_automation');
     }
     if ($nb_hac > $this->max_home_automation) {
         $nb_hac = $this->max_home_automation;
     }
     if (count($home_automation_controllers) > 0) {
         for ($i = 1; $i <= $nb_hac; $i++) {
             $this->widgetSchema['home_automation_controller' . $i] = new sfWidgetFormChoice(array('choices' => $home_automation_controllers));
             $this->validatorSchema['home_automation_controller' . $i] = new sfValidatorChoice(array('choices' => array_keys($home_automation_controllers), 'required' => false));
             $this->widgetSchema->setLabel('home_automation_controller' . $i, 'Home automation controller');
             foreach ($home_automation_controllers as $home_automation_controller => $name) {
                 $form = HomeAutomationControllerConfigurationForm::create($home_automation_controller, null);
                 $labelName = $form->getHomeAutomationController()->getName() . $i;
                 $this->embedForm($labelName, $form);
                 $this->widgetSchema->setLabel($labelName, $name);
             }
         }
     }
     $this->addSubConfigurationForm('Network', 'Network');
     $this->addSubConfigurationForm('Email', 'Email');
     $this->addSubConfigurationForm('General', 'General');
     $this->addSubConfigurationForm('Rename', 'Rename');
     $this->addSubConfigurationForm('Backup', 'Backup');
     $this->addSubConfigurationForm('Print', 'Print');
     $this->setDefault('number_of_physical_access', 1);
     $this->setDefault('number_of_home_automation', 1);
     $this->setDefaults(ConfigurationHelper::get());
     $this->widgetSchema->setNameFormat('configuration[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $this->context = sfContext::createInstance($this->configuration);
     $databaseManager = new sfDatabaseManager($this->configuration);
     ConfigurationHelper::load();
     $nb_controllers = ConfigurationHelper::get('number_of_physical_access');
     $now = time();
     $startCheckTime = $now + $delay * 60;
     // Need to add the delay in milliseconds to the time() function
     $stopCheckTime = $startCheckTime + $options['hours'] * 60 * 60;
     $this->logSection('tempos', sprintf("check-for-next-hours - Checking reservations started at: %s", strftime('%c', $now)), 1024);
     $this->logSection('tempos', sprintf("check-for-next-hours - Start delay (%s) minutes --> Start date reservation is: %s", $delay, strftime('%c', $startCheckTime)), 1024);
     $this->logSection('tempos', sprintf("check-for-next-hours - NB hours to check (%s) --> End date reservation check: %s", $options['hours'], strftime('%c', $stopCheckTime)), 1024);
     $reservations = ReservationPeer::doSelectPendingReservationsForNextHours($options['include-inactive'], $startCheckTime, $stopCheckTime);
     if (empty($reservations)) {
         $this->logSection('tempos', "check-for-next-hours - No reservations pending. Doing nothing.", 1024);
     } else {
         $this->logSection('tempos', sprintf("check-for-next-hours - %d reservation(s) pending.", count($reservations)), 1024);
         $uniquePersonsArray = array();
         $i = 0;
         foreach ($reservations as $reservation) {
             $roomprofile_id = $reservation->getRoomprofile()->getId();
             $roomprofile = RoomprofilePeer::doSelectFromId($roomprofile_id);
             $rp_controllername = $roomprofile->getConfiguredControllerName();
             $pac_infos = BasePhysicalAccessController::findPacFromNameIdentifier($rp_controllername);
             if (is_null($pac_infos) || empty($pac_infos)) {
                 continue;
             }
             $pac_name = $pac_infos['name'];
             // print 'pac_name';
             // var_dump($pac_name);
             $pac_id = $pac_infos['id'];
             // print 'pac_id';
             // var_dump($pac_id);
             $pac_selec = ConfigurationHelper::getParameter(null, $pac_name);
             // print 'pac_selec';
             // var_dump($pac_selec);
             $pac_conf = ConfigurationHelper::getNamespace($pac_selec . $pac_id);
             // print 'pac_conf';
             // var_dump($pac_conf);
             // var_dump($pac_infos);
             $pac = BasePhysicalAccessController::create($pac_selec, $pac_conf);
             // var_dump($pac);
             $delay = $pac->getParameter('delay');
             // print 'delay';
             // var_dump($delay);
             $pac->setVerbose($options['verbose']);
             if (is_null($delay) || empty($delay)) {
                 $delay = 0;
             }
             $this->logSection('tempos', sprintf('check - Creating a physical access controller: %s', $pac->getName()), 1024);
             $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tProcessing reservation: %s...", $i, $reservation->__toString()), 1024);
             $persons = $reservation->getAllPersons();
             $finalPersons = array();
             // Filter the list of persons. We only send the first reservation for each member.
             // If the user is already in the list, we remove him from the reservation.
             foreach ($persons as $person) {
                 $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tProcessing user (%s)...", $i, $person), 1024);
                 $uniqueId = $person->getUniqueId();
                 if (isset($uniquePersonsArray[$uniqueId])) {
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tUser (%s) had already a reservation... Ignoring him...", $i, $person->__toString()), 1024);
                 } else {
                     $uniquePersonsArray[$uniqueId] = 1;
                     $finalPersons[] = $person;
                 }
             }
             if (!empty($finalPersons)) {
                 if ($delay > 0) {
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tDelay required ! Before delay: %s", $i, $reservation->getDateString()), 1024);
                     $reservation->updateDateWithDelay($delay);
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tAfter delay: %s", $i, $reservation->getDateString()), 1024);
                 }
                 $results = $pac->sendReservation($reservation, $options['update-status'], $finalPersons);
                 if (empty($results)) {
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t\tSuccess."), 1024);
                 } else {
                     foreach ($results as $result) {
                         $this->logSection('tempos', sprintf("check-for-next-hours - \t\t%s: %s", $result['person'], $result['exception']->getMessage()), 1024, 'ERROR');
                     }
                 }
             } else {
                 $this->logSection('tempos', sprintf("check-for-next-hours - \t\tNo more user in the reservation. Doing nothing."), 1024);
             }
             $i++;
         }
     }
 }