public function doClean($values) { if (is_null($values)) { $values = array(); } if (!is_array($values)) { throw new InvalidArgumentException('You must pass an array parameter to the clean() method'); } if (is_null($values['date'])) { $valid = true; } else { $roomprofileId = $values['RoomProfile_id']; $roomprofile = RoomprofilePeer::retrieveByPk($roomprofileId); if (is_null($roomprofile)) { $valid = true; } else { $roomId = $roomprofile->getRoomId(); $valid = !ReservationPeer::overlaps($values['id'], $values['date'], date('Y-m-d H:i:s', strtotime($values['date'] . ' +' . $values['duration'] . ' minute')), $roomId); } } if (!$valid) { $error = new sfValidatorError($this, 'invalid', array()); if ($this->getOption('throw_global_error')) { throw $error; } throw new sfValidatorErrorSchema($this, array('date' => $error)); } return $values; }
protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $nb = $form->getValue('physical_access_controller'); // Récupère le contrôle d'accès physique sélectionné (grâce à sa position dans le ConfigurationHelper) $pac = ConfigurationHelper::getParameter(null, 'physical_access_controller' . ($nb + 1)); $pac .= $nb + 1; $controller = ConfigurationHelper::getParameter($pac, 'controller_name'); $name = RoomprofilePeer::buildName($controller, $form->getvalue('name')); $roomprofile = $form->save(); $roomprofile->setName($name); $roomprofile->save(); $this->redirect('roomprofile/index?roomId=' . $roomprofile->getRoomId()); } $this->setTemplate('edit'); }
public static function reportTime($activities, $rooms, $begin_date, $end_date, $begin_hour, $end_hour, $periodicity, $number, $c = null) { if (is_null($c)) { $c = new Criteria(); } /*print '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>'; $l = ReservationPEER::doSelect($c); foreach ($l as $t) { $tab_res = $t->getReservationsRelatedByReservationparentId(); print 'ID : '.$t->getId().'<br/>'; print 'DT : '.$t->getDate().'<br/>'; print 'AC : '.$t->getActivity().'<br/>'; print 'CT : '.$t->countReservationsRelatedByReservationparentId().'<br/>'; print 'RP : '.$t->getReservationRelatedByReservationparentId().'<br/>'; print 'RF : '.$tab_res[0].'<br/><br/>'; }*/ $begin_date = date('Y-m-d', $begin_date); $end_date = date('Y-m-d', $end_date); // Tableaux contenant les heures de début et fin $begin_hour = date('H:i', $begin_hour); $tab_begin_hour = explode(":", $begin_hour); $end_hour = date('H:i', $end_hour); $tab_end_hour = explode(":", $end_hour); // Heure pour dates curseurs $cursor_date = strtotime("{$begin_date} + {$tab_begin_hour['0']} hours + {$tab_begin_hour['1']} minutes"); if ($end_hour <= $begin_hour) { $end_cursor = strtotime("{$begin_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes + 1 day"); if ($begin_date == $end_date || $begin_hour == '00:00' && $begin_hour == $end_hour) { $end_date = strtotime("{$end_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes + 1 day"); } else { $end_date = strtotime("{$end_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes"); } } else { $end_cursor = strtotime("{$begin_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes"); $end_date = strtotime("{$end_date} + {$tab_end_hour['0']} hours + {$tab_end_hour['1']} minutes"); } // print "DATE : ".date('Y-m-d H:i:s', $cursor_date)." - ".date('Y-m-d H:i:s', $end_cursor)."<br/>"; // print "DATE : ".date('Y-m-d H:i:s', strtotime($begin_date))." - ".date('Y-m-d H:i:s', $end_date)."<br/>"; // Définition du pas switch ($periodicity) { case 'dayly': $period = 'day'; break; case 'weekly': $period = 'week'; break; case 'monthly': $period = 'month'; break; case 'annual': $period = 'year'; break; default: $period = 'day'; break; } $count = 0; $crit = null; while ($end_cursor <= $end_date) { $count++; // print "DATE $count => cursor_date : ".date('Y-m-d H:i:s', $cursor_date)." - end_cursor : ".date('Y-m-d H:i:s', $end_cursor)." - end_date : ". date('Y-m-d H:i:s', $end_date)."<br/>"; // Requête Criteria $crit1 = $c->getNewCriterion(ReservationPeer::DATE, $cursor_date, Criteria::GREATER_EQUAL); $crit2 = $c->getNewCriterion(ReservationPeer::DATE, strtotime(date('Y-m-d H:i:s')), Criteria::GREATER_EQUAL); $crit3 = $c->getNewCriterion(ReservationPeer::DATE, "DATE_ADD(" . ReservationPeer::DATE . ", INTERVAL " . ReservationPeer::DURATION . " MINUTE) <= '" . date('Y-m-d H:i:s', $end_cursor) . "'", Criteria::CUSTOM); $crit1->addAnd($crit2); $crit1->addAnd($crit3); if ($count > 1) { $crit->addOr($crit1); } else { $crit = $crit1; } $cursor_date = strtotime(date('Y-m-d H:i:s', $cursor_date) . ' + ' . $number . ' ' . $period); $end_cursor = strtotime(date('Y-m-d H:i:s', $end_cursor) . ' + ' . $number . ' ' . $period); } $c->add($crit); if (!empty($activities)) { $c->addAnd(ReservationPeer::ACTIVITY_ID, $activities, Criteria::IN); } if (is_null($rooms)) { $rooms = array(); } if (!empty($rooms) && is_array($rooms) && count($rooms) > 0) { // Retrieve room profile ID from all rooms $roomsProfiles = array(); foreach ($rooms as $room) { //print (' Current room: '.$room.'<br>'); $rpp = RoomprofilePeer::doSelectFromRoom($room); if (!is_null($rpp) && is_array($rpp)) { foreach ($rpp as $prof) { //print (' Room profile: '.$prof->getId().'<br>'); $roomsProfiles[] = $prof->getId(); } } } //print_r ($roomsProfiles); if (!empty($roomsProfiles) && is_array($roomsProfiles) && count($roomsProfiles) > 0) { $c->addAnd(ReservationPeer::ROOMPROFILE_ID, $roomsProfiles, Criteria::IN); } } // These joins are needed for sorting purposes $c->addJoin(ReservationPeer::ACTIVITY_ID, ActivityPeer::ID); $c->addJoin(ReservationPeer::ROOMPROFILE_ID, RoomprofilePeer::ID); $c->addJoin(RoomprofilePeer::ROOM_ID, RoomPeer::ID); $c->addGroupByColumn(ReservationPeer::ID); // print ($c->toString().'<br>'); return self::doSelect($c); }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = RoomPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Closeperiod objects $c = new Criteria(CloseperiodPeer::DATABASE_NAME); $c->add(CloseperiodPeer::ROOM_ID, $obj->getId()); $affectedRows += CloseperiodPeer::doDelete($c, $con); // delete related Dayperiod objects $c = new Criteria(DayperiodPeer::DATABASE_NAME); $c->add(DayperiodPeer::ROOM_ID, $obj->getId()); $affectedRows += DayperiodPeer::doDelete($c, $con); // delete related Roomprofile objects $c = new Criteria(RoomprofilePeer::DATABASE_NAME); $c->add(RoomprofilePeer::ROOM_ID, $obj->getId()); $affectedRows += RoomprofilePeer::doDelete($c, $con); // delete related RoomHasActivity objects $c = new Criteria(RoomHasActivityPeer::DATABASE_NAME); $c->add(RoomHasActivityPeer::ROOM_ID, $obj->getId()); $affectedRows += RoomHasActivityPeer::doDelete($c, $con); // delete related RoomHasEnergyaction objects $c = new Criteria(RoomHasEnergyactionPeer::DATABASE_NAME); $c->add(RoomHasEnergyactionPeer::ROOM_ID, $obj->getId()); $affectedRows += RoomHasEnergyactionPeer::doDelete($c, $con); // delete related RoomHasFeaturevalue objects $c = new Criteria(RoomHasFeaturevaluePeer::DATABASE_NAME); $c->add(RoomHasFeaturevaluePeer::ROOM_ID, $obj->getId()); $affectedRows += RoomHasFeaturevaluePeer::doDelete($c, $con); // delete related ZoneHasRoom objects $c = new Criteria(ZoneHasRoomPeer::DATABASE_NAME); $c->add(ZoneHasRoomPeer::ROOM_ID, $obj->getId()); $affectedRows += ZoneHasRoomPeer::doDelete($c, $con); } return $affectedRows; }
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'); }
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++; } } }
/** * 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(RoomprofilePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(RoomprofilePeer::DATABASE_NAME); $criteria->add(RoomprofilePeer::ID, $pks, Criteria::IN); $objs = RoomprofilePeer::doSelect($criteria, $con); } return $objs; }
/** * Selects a collection of Reservation objects pre-filled with all related objects except ReservationRelatedByReservationparentId. * * @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 Reservation objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptReservationRelatedByReservationparentId(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $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); } ReservationPeer::addSelectColumns($c); $startcol2 = ReservationPeer::NUM_COLUMNS - ReservationPeer::NUM_LAZY_LOAD_COLUMNS; RoomprofilePeer::addSelectColumns($c); $startcol3 = $startcol2 + (RoomprofilePeer::NUM_COLUMNS - RoomprofilePeer::NUM_LAZY_LOAD_COLUMNS); ActivityPeer::addSelectColumns($c); $startcol4 = $startcol3 + (ActivityPeer::NUM_COLUMNS - ActivityPeer::NUM_LAZY_LOAD_COLUMNS); ReservationreasonPeer::addSelectColumns($c); $startcol5 = $startcol4 + (ReservationreasonPeer::NUM_COLUMNS - ReservationreasonPeer::NUM_LAZY_LOAD_COLUMNS); UsergroupPeer::addSelectColumns($c); $startcol6 = $startcol5 + (UsergroupPeer::NUM_COLUMNS - UsergroupPeer::NUM_LAZY_LOAD_COLUMNS); CardPeer::addSelectColumns($c); $startcol7 = $startcol6 + (CardPeer::NUM_COLUMNS - CardPeer::NUM_LAZY_LOAD_COLUMNS); UserPeer::addSelectColumns($c); $startcol8 = $startcol7 + (UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(ReservationPeer::ROOMPROFILE_ID), array(RoomprofilePeer::ID), $join_behavior); $c->addJoin(array(ReservationPeer::ACTIVITY_ID), array(ActivityPeer::ID), $join_behavior); $c->addJoin(array(ReservationPeer::RESERVATIONREASON_ID), array(ReservationreasonPeer::ID), $join_behavior); $c->addJoin(array(ReservationPeer::USERGROUP_ID), array(UsergroupPeer::ID), $join_behavior); $c->addJoin(array(ReservationPeer::CARD_ID), array(CardPeer::ID), $join_behavior); $c->addJoin(array(ReservationPeer::USER_ID), array(UserPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ReservationPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ReservationPeer::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 = ReservationPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); ReservationPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Roomprofile rows $key2 = RoomprofilePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = RoomprofilePeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = RoomprofilePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); RoomprofilePeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (Reservation) to the collection in $obj2 (Roomprofile) $obj2->addReservation($obj1); } // if joined row is not null // Add objects for joined Activity rows $key3 = ActivityPeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = ActivityPeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = ActivityPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); ActivityPeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (Reservation) to the collection in $obj3 (Activity) $obj3->addReservation($obj1); } // if joined row is not null // Add objects for joined Reservationreason rows $key4 = ReservationreasonPeer::getPrimaryKeyHashFromRow($row, $startcol4); if ($key4 !== null) { $obj4 = ReservationreasonPeer::getInstanceFromPool($key4); if (!$obj4) { $omClass = ReservationreasonPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj4 = new $cls(); $obj4->hydrate($row, $startcol4); ReservationreasonPeer::addInstanceToPool($obj4, $key4); } // if $obj4 already loaded // Add the $obj1 (Reservation) to the collection in $obj4 (Reservationreason) $obj4->addReservation($obj1); } // if joined row is not null // Add objects for joined Usergroup rows $key5 = UsergroupPeer::getPrimaryKeyHashFromRow($row, $startcol5); if ($key5 !== null) { $obj5 = UsergroupPeer::getInstanceFromPool($key5); if (!$obj5) { $omClass = UsergroupPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj5 = new $cls(); $obj5->hydrate($row, $startcol5); UsergroupPeer::addInstanceToPool($obj5, $key5); } // if $obj5 already loaded // Add the $obj1 (Reservation) to the collection in $obj5 (Usergroup) $obj5->addReservation($obj1); } // if joined row is not null // Add objects for joined Card rows $key6 = CardPeer::getPrimaryKeyHashFromRow($row, $startcol6); if ($key6 !== null) { $obj6 = CardPeer::getInstanceFromPool($key6); if (!$obj6) { $omClass = CardPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj6 = new $cls(); $obj6->hydrate($row, $startcol6); CardPeer::addInstanceToPool($obj6, $key6); } // if $obj6 already loaded // Add the $obj1 (Reservation) to the collection in $obj6 (Card) $obj6->addReservation($obj1); } // if joined row is not null // Add objects for joined User rows $key7 = UserPeer::getPrimaryKeyHashFromRow($row, $startcol7); if ($key7 !== null) { $obj7 = UserPeer::getInstanceFromPool($key7); if (!$obj7) { $omClass = UserPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj7 = new $cls(); $obj7->hydrate($row, $startcol7); UserPeer::addInstanceToPool($obj7, $key7); } // if $obj7 already loaded // Add the $obj1 (Reservation) to the collection in $obj7 (User) $obj7->addReservation($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Get the associated Roomprofile object * * @param PropelPDO Optional Connection object. * @return Roomprofile The associated Roomprofile object. * @throws PropelException */ public function getRoomprofile(PropelPDO $con = null) { if ($this->aRoomprofile === null && $this->roomprofile_id !== null) { $c = new Criteria(RoomprofilePeer::DATABASE_NAME); $c->add(RoomprofilePeer::ID, $this->roomprofile_id); $this->aRoomprofile = RoomprofilePeer::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->aRoomprofile->addReservations($this); */ } return $this->aRoomprofile; }
/** * Returns the number of related Roomprofile objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Roomprofile objects. * @throws PropelException */ public function countRoomprofiles(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(RoomPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collRoomprofiles === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(RoomprofilePeer::ROOM_ID, $this->id); $count = RoomprofilePeer::doCount($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. $criteria->add(RoomprofilePeer::ROOM_ID, $this->id); if (!isset($this->lastRoomprofileCriteria) || !$this->lastRoomprofileCriteria->equals($criteria)) { $count = RoomprofilePeer::doCount($criteria, $con); } else { $count = count($this->collRoomprofiles); } } else { $count = count($this->collRoomprofiles); } } return $count; }
public function setDefaultRoom($room) { $this->room = $room; $this->widgetSchema['RoomProfile_id']->setOption('criteria', RoomprofilePeer::getFromRoomCriteria($room->getId())); }
/** * 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 = RoomprofilePeer::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->setPhysicalAccessId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setRoomId($arr[$keys[3]]); } }
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++; } } }