コード例 #1
0
ファイル: Room.php プロジェクト: jfesquet/tempos
 public function getEnergyactions()
 {
     $c = new Criteria();
     $c->addJoin(EnergyactionPeer::ID, RoomHasEnergyactionPeer::ENERGYACTION_ID);
     $c->add(RoomHasEnergyactionPeer::ROOM_ID, $this->getId(), Criteria::EQUAL);
     $c->addAscendingOrderByColumn(EnergyactionPeer::NAME);
     return EnergyactionPeer::doSelect($c);
 }
コード例 #2
0
ファイル: actions.class.php プロジェクト: jfesquet/tempos
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         if (!is_null($form->getValue('home_automation_controller'))) {
             $nb = $form->getValue('home_automation_controller');
             // Récupère le contrôleur domotique sélectionné (grâce à sa position dans le ConfigurationHelper)
             $hac = ConfigurationHelper::getParameter(null, 'home_automation_controller' . ($nb + 1));
             $hac .= $nb + 1;
             $controller = ConfigurationHelper::getParameter($hac, 'controller_name');
             $name = EnergyactionPeer::buildName($controller, $form->getvalue('name'));
             $energyaction = $form->save();
             $energyaction->setName($name);
             $energyaction->save();
         } else {
             $energyaction = $form->save();
         }
         $this->redirect('energyaction/index');
     }
 }
コード例 #3
0
ファイル: BaseEnergyaction.php プロジェクト: jfesquet/tempos
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = EnergyactionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setName($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDelayup($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDelaydown($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setIdentifier($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setProcessidup($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setProcessiddown($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setStart($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setStop($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setStatus($arr[$keys[9]]);
     }
 }
コード例 #4
0
 /**
  * Selects a collection of RoomHasEnergyaction objects pre-filled with all related objects except Room.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of RoomHasEnergyaction objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptRoom(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     foreach (sfMixer::getCallables('BaseRoomHasEnergyactionPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) {
         call_user_func($callable, 'BaseRoomHasEnergyactionPeer', $c, $con);
     }
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     // $c->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     RoomHasEnergyactionPeer::addSelectColumns($c);
     $startcol2 = RoomHasEnergyactionPeer::NUM_COLUMNS - RoomHasEnergyactionPeer::NUM_LAZY_LOAD_COLUMNS;
     EnergyactionPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (EnergyactionPeer::NUM_COLUMNS - EnergyactionPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(RoomHasEnergyactionPeer::ENERGYACTION_ID), array(EnergyactionPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = RoomHasEnergyactionPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = RoomHasEnergyactionPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $omClass = RoomHasEnergyactionPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             RoomHasEnergyactionPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Energyaction rows
         $key2 = EnergyactionPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = EnergyactionPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = EnergyactionPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 EnergyactionPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (RoomHasEnergyaction) to the collection in $obj2 (Energyaction)
             $obj2->addRoomHasEnergyaction($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
コード例 #5
0
ファイル: actions.class.php プロジェクト: jfesquet/tempos
 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');
 }
コード例 #6
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();
     $now = time();
     $this->logSection('tempos', sprintf('Checking energy actions at: %s.', strftime('%c', $now)), 1024);
     // Creates physical access controller
     /* 
     $hac = BaseHomeAutomationController::create();
     
     		$hac->setVerbose($options['verbose']);
     		$hac->setUpdateStatus($options['update-status']);
     
     		$this->logSection('tempos', sprintf('Creating a home automation controller: %s', $hac->getName()), 1024);
     */
     // Refresh statuses
     $actions = EnergyactionPeer::doSelect(new Criteria());
     if (empty($actions)) {
         $this->logSection('tempos', sprintf('Refreshing statuses for all actions: no actions.'), 1024);
     } else {
         $this->logSection('tempos', sprintf('Refreshing statuses for all actions: %d action(s) to refresh.', count($actions)), 1024);
         foreach ($actions as $action) {
             $hac = self::findHac($action);
             if (is_null($hac)) {
                 $this->logSection('tempos', sprintf('Can\'t create a home automation controller for this action: id(%s) HAC is null', $action->getId()), 1024);
                 continue;
             }
             $hac->setVerbose($options['verbose']);
             $hac->setUpdateStatus($options['update-status']);
             $this->logSection('tempos', sprintf('Creating a home automation controller: %s for action: %s', $hac->getName(), $action->getId(), 1024));
             $this->refreshAction($hac, $action);
         }
     }
     // Check out of period actions
     $actions = EnergyactionPeer::doSelectOutOfPeriod(true, $now);
     if (empty($actions)) {
         $this->logSection('tempos', sprintf('Checking out-of-period active actions: no action is out-of-period.'), 1024);
     } else {
         $this->logSection('tempos', sprintf('Checking out-of-period active actions: %d action(s) to shut down.', count($actions)), 1024);
         foreach ($actions as $action) {
             $hac = self::findHac($action);
             if (is_null($hac)) {
                 $this->logSection('tempos', sprintf('Can\'t check out-of-period with this action: id(%s) HAC is null', $action->getId()), 1024);
                 continue;
             }
             $this->updateAction($hac, $action, false, $options['force']);
         }
     }
     // Check the ready actions
     $actions = EnergyactionPeer::doSelectReady($now);
     if (empty($actions)) {
         $this->logSection('tempos', sprintf('Checking reservation ready actions: no action must be triggered.'), 1024);
     } else {
         $this->logSection('tempos', sprintf('Checking reservation ready actions: %d action(s) to power on.', count($actions)), 1024);
         foreach ($actions as $action) {
             $hac = self::findHac($action);
             if (is_null($hac)) {
                 $this->logSection('tempos', sprintf('Can\'t update this action: id(%s) HAC is null', $action->getId()), 1024);
                 continue;
             }
             $this->updateAction($hac, $action, true, $options['force']);
         }
     }
     // Check the over actions
     $actions = EnergyactionPeer::doSelectOver($now, $actions);
     if (empty($actions)) {
         $this->logSection('tempos', sprintf('Checking reservation over actions: no action must be triggered.'), 1024);
     } else {
         $this->logSection('tempos', sprintf('Checking reservation over actions: %d action(s) to shut down.', count($actions)), 1024);
         foreach ($actions as $action) {
             $hac = self::findHac($action);
             if (is_null($hac)) {
                 $this->logSection('tempos', sprintf('Can\'t update this action: id(%s) HAC is null', $action->getId()), 1024);
                 continue;
             }
             $this->updateAction($hac, $action, false, $options['force']);
         }
     }
 }
コード例 #7
0
 /**
  * Get the associated Energyaction object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Energyaction The associated Energyaction object.
  * @throws     PropelException
  */
 public function getEnergyaction(PropelPDO $con = null)
 {
     if ($this->aEnergyaction === null && $this->energyaction_id !== null) {
         $c = new Criteria(EnergyactionPeer::DATABASE_NAME);
         $c->add(EnergyactionPeer::ID, $this->energyaction_id);
         $this->aEnergyaction = EnergyactionPeer::doSelectOne($c, $con);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aEnergyaction->addRoomHasEnergyactions($this);
         		 */
     }
     return $this->aEnergyaction;
 }
コード例 #8
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(EnergyactionPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(EnergyactionPeer::DATABASE_NAME);
         $criteria->add(EnergyactionPeer::ID, $pks, Criteria::IN);
         $objs = EnergyactionPeer::doSelect($criteria, $con);
     }
     return $objs;
 }