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; }
public static function getMonthCriteria($date, $c = null) { if (is_null($c)) { $c = new Criteria(); } $cton1 = $c->getNewCriterion(CloseperiodPeer::STOP, strftime('%Y-%m-%d', ReservationPeer::getMonthStart($date)), Criteria::GREATER_THAN); $cton2 = $c->getNewCriterion(CloseperiodPeer::START, strftime('%Y-%m-%d', ReservationPeer::getMonthStop($date)), Criteria::LESS_THAN); $cton1->addAnd($cton2); $c->addAnd($cton1); return $c; }
public function getAllReservationsCount($reservation_id = null) { $c = ReservationPeer::getPeriodCriteria(strtotime($this->getStart()), strtotime($this->getStop())); $c->addAnd(ReservationPeer::ACTIVITY_ID, $this->getActivityId(), Criteria::EQUAL); if (!is_null($this->getUserId())) { $c->addAnd(ReservationPeer::USER_ID, $this->getUserId(), Criteria::EQUAL); } if (!is_null($this->getCardId())) { $c->addAnd(ReservationPeer::CARD_ID, $this->getCardId(), Criteria::EQUAL); } if (!is_null($reservation_id)) { $c->addAnd(ReservationPeer::ID, $reservation_id, Criteria::NOT_EQUAL); } $c->clearSelectColumns(); $c->addSelectColumn('SUM(' . ReservationPeer::DURATION . ')'); $stmt = ReservationPeer::doSelectStmt($c); $row = $stmt->fetch(PDO::FETCH_NUM); return $row[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 executeRepeatResult(sfWebRequest $request) { // print 'executeRepeatList<br />'; $this->forward404Unless($request->isMethod('post')); $this->forward404Unless($this->reservation = ReservationPeer::retrieveByPk($request->getParameter('id')), sprintf('Object reservation does not exist (%s).', $request->getParameter('id'))); $this->room = $this->reservation->getRoomprofile()->getRoom(); $next_id = $this->reservation->getId(); $result = true; // $formRepeat = $this->getUser()->getAttribute('form_tmp'); // -------------------- $formRepeat->bind($request->getParameter($formRepeat->getName()), $request->getFiles($formRepeat->getName())); $this->forms = $formRepeat->getReservationForms(); $checked_list = $request->getPostParameters(); // var_dump($checked_list); // var_dump($forms); $ids = array(); foreach ($checked_list as $id) { array_push($ids, $id); } // var_dump($ids); if (empty($ids) || is_null($ids)) { $this->setTemplate('processRepeat'); } $j = 0; $this->formsResult = array(); foreach ($this->forms as $form) { // print '============><br />'.$j.' '.count($this->forms).'<br />'; $i = 0; $checked = false; while (!$checked && $i < count($ids)) { // print $i.' : '.$ids[$i].'<br />'; // if($this->forms[$j]->getObject()->getId() == $ids[$i]) if ($form->getObject()->getId() == $ids[$i]) { // print 'FORM '.$this->forms[$j]->getObject()->getId().' is checked<br />'; $checked = true; } $i++; } if ($checked) { // $reservation = $this->forms[$j]->getObject()->copy(); $reservation = $form->getObject()->copy(); $reservation->setReservationparentId($next_id); $resDate = $reservation->getDate(); // $this->forms[$j] = new ReservationForm($reservation); // $this->forms[$j]->bindObject($reservation); $form = new ReservationForm($reservation); $form->bindObject($reservation); // if ($this->forms[$j]->isValid()) if ($form->isValid()) { // print 'IS VALID<br />'; // var_dump($this->forms[$j]->getObject()); // var_dump($form->getObject()); // $reservation = $this->forms[$j]->save(); $reservation = $form->save(); $next_id = $reservation->getId(); foreach ($this->reservation->getReservationOtherMemberss() as $value) { $other_members = new ReservationOtherMembers(); $other_members->setReservationId($next_id); $other_members->setUserId($value->getUserId()); $other_members->save(); // print('Reservation : '.$value.'<br/>Id user : '******'<br/>'); } } else { // print 'NOT VALID<br />'; $result = false; } if ($checked) { $form->getObject()->setDate($resDate); } $this->formsResult[] = $form; // print $this->forms[$j]->renderErrors(); // print $form->renderErrors(); } $j++; } if ($result) { $this->redirect('reservation/index?roomId=' . $this->reservation->getRoomprofile()->getRoomId()); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this User is new, it will return * an empty collection; or if this User has previously * been saved, it will retrieve related Reservations from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in User. */ public function getReservationsJoinReservationRelatedByReservationparentId($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(UserPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collReservations === null) { if ($this->isNew()) { $this->collReservations = array(); } else { $criteria->add(ReservationPeer::USER_ID, $this->id); $this->collReservations = ReservationPeer::doSelectJoinReservationRelatedByReservationparentId($criteria, $con, $join_behavior); } } else { // 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 the collection. $criteria->add(ReservationPeer::USER_ID, $this->id); if (!isset($this->lastReservationCriteria) || !$this->lastReservationCriteria->equals($criteria)) { $this->collReservations = ReservationPeer::doSelectJoinReservationRelatedByReservationparentId($criteria, $con, $join_behavior); } } $this->lastReservationCriteria = $criteria; return $this->collReservations; }
public function executeIndex(sfWebRequest $request) { $i18n = sfContext::getInstance()->getI18N(); // Disable CSRF protection $this->form = new ReportingForm(array(), array(), false); $formName = $this->form->getName(); $this->step = sfConfig::get('app_max_reservations_on_reporting'); $this->getUser()->syncParameters($this, 'reporting', 'index', array('offset', 'limit', $formName, 'sort_column', 'sort_direction'), $request); if (is_null($this->sort_column)) { $this->sort_column = 'date'; $this->sort_direction = 'up'; } if (is_null($this->offset)) { $this->offset = 0; } if (is_null($this->limit) || $this->limit <= 0) { $this->limit = $this->step; } $c = new Criteria(); SortCriteria::addSortCriteria($c, $this->sort_column, ReservationPeer::getSortAliases(), $this->sort_direction); $this->filtered = false; if (!is_null($this->{$formName})) { $this->filtered = true; $this->form->bind($this->{$formName}, $request->getFiles($formName)); if ($this->form->isValid()) { $this->reservation_list = ReservationPeer::report($this->form->getValue('users'), $this->form->getValue('usergroups'), $this->form->getValue('activities'), $this->form->getValue('zones'), $this->form->getValue('rooms'), strtotime($this->form->getValue('begin_date')), strtotime($this->form->getValue('end_date')), $c); $this->count = count($this->reservation_list); $this->entire_reservation_list = $this->reservation_list; $this->reservation_list = array_slice($this->reservation_list, $this->offset, $this->limit); } else { $this->count = 0; $this->reservation_list = array(); } } else { $this->count = 0; $this->reservation_list = array(); } if ($this->offset < 0 || $this->offset >= $this->count && $this->count > 0) { $this->forward404('Invalid offset/count values.'); } if (!is_null($export = $request->getParameter('export'))) { $this->forward404Unless(in_array($export, array('csv', 'pdf')), sprintf('Unhandled value "%s" for export', $export)); sfConfig::set('sf_web_debug', false); $activity_name = ConfigurationHelper::getParameter('Rename', 'activity_label'); if (empty($activity_name)) { $activity_name = $i18n->__('Activity'); } $free_field_1_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_1'); $free_field_2_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_2'); $free_field_3_name = ConfigurationHelper::getParameter('Rename', 'reservation_custom_field_3'); $this->all_rows = array(); $fields = $this->form->getValue('fields'); foreach ($this->entire_reservation_list as $reservation) { //If there's is a temporary group, we modify the name to display "Perso. (first user, ...)" $resa_group_name = null; $ug = $reservation->getUsergroup(); if (!is_null($ug)) { $resa_group_name = $ug->getName(); } $this->all_rows[] = array(); end($this->all_rows); // Check which field we need to display. foreach ($fields as $field_id) { // See lib\form\ReportingForm.class.php for indexes switch ($field_id) { case 0: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Date'), $reservation->getDate()); break; case 1: $this->all_rows[key($this->all_rows)][] = array($i18n->__('User'), $reservation->getUser()->getFullName()); break; case 2: $this->all_rows[key($this->all_rows)][] = array($activity_name, $reservation->getActivity()->getName()); break; case 3: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Duration'), number_format($reservation->getDuration())); break; case 4: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Room'), $reservation->getRoomprofile()->getRoom()->getName()); break; case 5: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Reason'), !is_null($reservation->getReservationreason()) ? $reservation->getReservationreason()->getName() : null); break; case 6: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Comment'), $reservation->getComment()); break; case 7: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Group'), $resa_group_name); break; case 8: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Members count'), number_format($reservation->getMembersCount())); break; case 9: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Guests count'), number_format($reservation->getGuestsCount())); break; case 10: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Status'), number_format($reservation->getStatus())); break; case 11: $this->all_rows[key($this->all_rows)][] = array($i18n->__('Price'), number_format($reservation->getPrice())); break; case 12: $valuedFeaturesArray = $reservation->getRoomprofile()->getRoom()->getValuedFeaturesArray(); $concat = ''; foreach ($valuedFeaturesArray as $featureName => $values) { $concat .= $featureName . '=' . $values . ' | '; } $concat = rtrim($concat, ' | '); $this->all_rows[key($this->all_rows)][] = array($i18n->__('Features'), $concat); break; case 90: $this->all_rows[key($this->all_rows)][] = array($free_field_1_name, $reservation->getCustom1()); break; case 91: $this->all_rows[key($this->all_rows)][] = array($free_field_2_name, $reservation->getCustom2()); break; case 92: $this->all_rows[key($this->all_rows)][] = array($free_field_3_name, $reservation->getCustom3()); break; } } } if ($export == 'csv') { $this->setLayout(false); $this->getResponse()->clearHttpHeaders(); $this->getResponse()->setHttpHeader('Pragma: public', true); $this->getResponse()->setHttpHeader('Content-disposition', sprintf('attachment; filename="%s"', 'reporting-' . date('Y-m-d') . '.csv')); $this->getResponse()->setContentType('text/csv; charset=utf-8'); $this->getResponse()->sendHttpHeaders(); $this->setTemplate('exportCSV'); } else { if ($export == 'pdf') { $config = sfTCPDFPluginConfigHandler::loadConfig(); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('ISLOG Tempos'); $pdf->SetTitle('Tempos report export'); $pdf->SetSubject('Tempos export'); $pdf->SetKeywords('Tempos, report, ISLOG'); $pdf->SetHeaderData(sfConfig::get('app_has_logo'), PDF_HEADER_LOGO_WIDTH, $i18n->__('Report'), sprintf($i18n->__('Usage report from %s to %s'), $this->form->getValue('begin_date'), $this->form->getValue('end_date'))); $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128)); $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 10, '', true); $pdf->AddPage(); $this->writeHtmlTable($pdf, $this->all_rows); $pdf->Output('reporting-' . date('Y-m-d') . '.pdf', 'I'); exit; } } } }
public function checkReservations() { return !ReservationPeer::overlaps($this->getId(), $this->getDate(), $this->getStopDate(), $this->getRoomprofile()->getRoomId()); }
/** * Get the associated Reservation object * * @param PropelPDO Optional Connection object. * @return Reservation The associated Reservation object. * @throws PropelException */ public function getReservation(PropelPDO $con = null) { if ($this->aReservation === null && $this->reservation_id !== null) { $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::ID, $this->reservation_id); $this->aReservation = ReservationPeer::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->aReservation->addReservationOtherMemberss($this); */ } return $this->aReservation; }
/** * 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 = ActivityPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related ActivityHasFeature objects $c = new Criteria(ActivityHasFeaturePeer::DATABASE_NAME); $c->add(ActivityHasFeaturePeer::ACTIVITY_ID, $obj->getId()); $affectedRows += ActivityHasFeaturePeer::doDelete($c, $con); // delete related Reservation objects $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += ReservationPeer::doDelete($c, $con); // delete related Reservationreason objects $c = new Criteria(ReservationreasonPeer::DATABASE_NAME); $c->add(ReservationreasonPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += ReservationreasonPeer::doDelete($c, $con); // delete related RoomHasActivity objects $c = new Criteria(RoomHasActivityPeer::DATABASE_NAME); $c->add(RoomHasActivityPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += RoomHasActivityPeer::doDelete($c, $con); // delete related Subscription objects $c = new Criteria(SubscriptionPeer::DATABASE_NAME); $c->add(SubscriptionPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += SubscriptionPeer::doDelete($c, $con); // delete related UsergroupHasActivity objects $c = new Criteria(UsergroupHasActivityPeer::DATABASE_NAME); $c->add(UsergroupHasActivityPeer::ACTIVITY_ID, $obj->getId()); $affectedRows += UsergroupHasActivityPeer::doDelete($c, $con); } return $affectedRows; }
public static function doSelectOver($time = null, $readyActions) { if (is_null($time)) { $time = time(); } $reservations = ReservationPeer::doSelectOver(false, $time); $actions = array(); foreach ($reservations as $reservation) { foreach ($reservation->getRoomprofile()->getRoom()->getEnergyactions() as $action) { if (!array_key_exists($action->getId(), $readyActions)) { if ($action->getDownDate(strtotime($reservation->getStopDate())) <= $time) { $actions[$action->getId()] = $action; } } } } return $actions; }
<?php for ($day = 0; $day < 7; ++$day) { ?> <th><?php echo __('%week_day%', array('%week_day%' => Dayperiod::dayOfWeekToShortName($day))); ?> </th> <?php } ?> </tr> </thead> <tbody> <?php $monthStart = ReservationPeer::getMonthStart($date); $monthStop = ReservationPeer::getMonthStop($date); $startDayIndex = date('N', $monthStart) - 1; $tst = $monthStart; ?> <?php for ($weekNo = 0; $tst < $monthStop; ++$weekNo) { ?> <tr> <?php for ($day = 0; $day < 7; ++$day) { ?> <?php $tst = strtotime(date('Y-m-d', $monthStart) . ' + ' . ($day + $weekNo * 7) . ' day - ' . $startDayIndex . ' day'); ?> <?php
public function executeConfirm(sfWebRequest $request) { $this->forward404Unless($reservation = ReservationPeer::retrieveByPk($request->getParameter('id')), sprintf('Object reservation does not exist (%s).', $request->getParameter('id'))); $this->reservation = $reservation; $this->form = new ReservationDeleteConfirmForm(array(), array(), false); }
public function getUpcomingReservations($count) { if (!is_int($count) || $count <= 0) { throw new InvalidArgumentException('`$count` must be a strictly positive integer'); } $c = new Criteria(); $groups = $this->getGroupsAsMember(); $cton1 = $c->getNewCriterion(ReservationPeer::USERGROUP_ID, PropelLogic::getIdList($groups), Criteria::IN); $cton2 = $c->getNewCriterion(ReservationPeer::USER_ID, $this->getId(), Criteria::EQUAL); $cton1->addOr($cton2); $c->add($cton1); $c->addAnd(ReservationPeer::DATE, strftime('%Y-%m-%d %H:%M:%S'), Criteria::GREATER_EQUAL); $c->addAscendingOrderByColumn(ReservationPeer::DATE); $c->setLimit($count); return ReservationPeer::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 = UserPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::RECIPIENT_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::SENDER_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::OWNER_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Reservation objects $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::USER_ID, $obj->getId()); $affectedRows += ReservationPeer::doDelete($c, $con); // delete related ReservationOtherMembers objects $c = new Criteria(ReservationOtherMembersPeer::DATABASE_NAME); $c->add(ReservationOtherMembersPeer::USER_ID, $obj->getId()); $affectedRows += ReservationOtherMembersPeer::doDelete($c, $con); // delete related Subscription objects $c = new Criteria(SubscriptionPeer::DATABASE_NAME); $c->add(SubscriptionPeer::USER_ID, $obj->getId()); $affectedRows += SubscriptionPeer::doDelete($c, $con); // delete related UsergroupHasChief objects $c = new Criteria(UsergroupHasChiefPeer::DATABASE_NAME); $c->add(UsergroupHasChiefPeer::USER_ID, $obj->getId()); $affectedRows += UsergroupHasChiefPeer::doDelete($c, $con); // delete related UsergroupHasUser objects $c = new Criteria(UsergroupHasUserPeer::DATABASE_NAME); $c->add(UsergroupHasUserPeer::USER_ID, $obj->getId()); $affectedRows += UsergroupHasUserPeer::doDelete($c, $con); // delete related UserHasRole objects $c = new Criteria(UserHasRolePeer::DATABASE_NAME); $c->add(UserHasRolePeer::USER_ID, $obj->getId()); $affectedRows += UserHasRolePeer::doDelete($c, $con); } return $affectedRows; }
public function getUpcomingReservations($count) { if (!is_int($count) || $count <= 0) { throw new InvalidArgumentException('`$count` must be a strictly positive integer'); } $c = new Criteria(); $c->add(ReservationPeer::CARD_ID, $this->getId(), Criteria::EQUAL); $c->addAnd(ReservationPeer::DATE, strftime('%Y-%m-%d'), Criteria::GREATER_EQUAL); $c->addAscendingOrderByColumn(ReservationPeer::DATE); $c->setLimit($count); return ReservationPeer::doSelect($c); }
public static function getOverlappingReservationsCount($id, $start, $stop, $roomId = null, $userId = null, $cardId = null) { $c = self::getOverlappingReservationsCriteria($id, $start, $stop, $roomId, $userId, $cardId); return ReservationPeer::doCount($c); }
/** * Selects a collection of ReservationOtherMembers objects pre-filled with all related objects except User. * * @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 ReservationOtherMembers objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(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); } ReservationOtherMembersPeer::addSelectColumns($c); $startcol2 = ReservationOtherMembersPeer::NUM_COLUMNS - ReservationOtherMembersPeer::NUM_LAZY_LOAD_COLUMNS; ReservationPeer::addSelectColumns($c); $startcol3 = $startcol2 + (ReservationPeer::NUM_COLUMNS - ReservationPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(ReservationOtherMembersPeer::RESERVATION_ID), array(ReservationPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ReservationOtherMembersPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ReservationOtherMembersPeer::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 = ReservationOtherMembersPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); ReservationOtherMembersPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Reservation rows $key2 = ReservationPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ReservationPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = ReservationPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ReservationPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (ReservationOtherMembers) to the collection in $obj2 (Reservation) $obj2->addReservationOtherMembers($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public static function getGantt($room_list, $activityId, $person, $timestamp) { $now = time(); $room_id_list = PropelLogic::getIdList($room_list); // Get the day start $dayStart = ReservationPeer::getDayStart($timestamp); // We get all the reservations for the current room list in the week containing the given timestamp. $c = ReservationPeer::getDayCriteria($timestamp); $c->addJoin(ReservationPeer::ROOMPROFILE_ID, RoomprofilePeer::ID); $c->addAnd(RoomprofilePeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAscendingOrderByColumn(ReservationPeer::DATE); $reservations = ReservationPeer::doSelect($c); // We get all the day periods for the current room list. $dayOfWeek = date('N', $timestamp) - 1; $c = new Criteria(); $c->addAnd(DayperiodPeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAnd(DayperiodPeer::DAY_OF_WEEK, $dayOfWeek, Criteria::EQUAL); $c->addAscendingOrderByColumn(DayperiodPeer::START); $dayPeriods = DayperiodPeer::doSelect($c); // We get all the close periods for the current room list. $c = CloseperiodPeer::getDayCriteria($timestamp); $c->addAnd(CloseperiodPeer::ROOM_ID, $room_id_list, Criteria::IN); $c->addAscendingOrderByColumn(CloseperiodPeer::START); $c->addAscendingOrderByColumn(CloseperiodPeer::STOP); $closePeriods = CloseperiodPeer::doSelect($c); // We build the availability array $startIndex = 48; $stopIndex = 0; $result = array(); foreach ($room_list as $room) { $room_id = $room->getId(); $result[$room_id] = array(); $result[$room_id]['room'] = $room; for ($i = 0; $i < 48; ++$i) { $result[$room_id][$i] = array(); $tst = strtotime(date('Y-m-d H:i:s', $dayStart) . ' + ' . $i * 30 . ' minute'); $value = RoomPeer::COMPLETE; foreach ($dayPeriods as $dayPeriod) { if ($dayPeriod->getRoomId() == $room_id) { if ($dayPeriod->matchTimestamp($tst)) { if ($startIndex > $i) { $startIndex = $i; } if ($stopIndex <= $i) { $stopIndex = $i + 1; } $value = RoomPeer::FREE; break; } } } foreach ($closePeriods as $closePeriod) { if ($closePeriod->getRoomId() == $room_id) { if ($closePeriod->matchTimestamp($tst)) { $value = RoomPeer::COMPLETE; break; } } if (strtotime($closePeriod->getStart()) > $tst) { break; } } if ($value != RoomPeer::COMPLETE) { if ($tst < $now) { $value = RoomPeer::PAST; } else { $maximumTimestamp = $person->getMaximumDate($activityId, $room_id); if ($maximumTimestamp <= $tst || !$person->hasSubscription($activityId, $room_id, $tst)) { $value = RoomPeer::TOOFAR; } else { foreach ($reservations as $reservation) { if ($reservation->getRoomprofile()->getRoomId() == $room_id) { if ($reservation->matchTimestamp($tst)) { $value = RoomPeer::COMPLETE; break; } } if (strtotime($reservation->getDate()) > $tst) { break; } } } } } $result[$room_id][$i]['value'] = $value; $result[$room_id][$i]['timestamp'] = $tst; $result[$room_id][$i]['room'] = $room; $result['timestamps'][$i] = $tst; } } $result['startIndex'] = $startIndex; $result['stopIndex'] = $stopIndex; return $result; }
/** * 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(ReservationPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(ReservationPeer::DATABASE_NAME); $criteria->add(ReservationPeer::ID, $pks, Criteria::IN); $objs = ReservationPeer::doSelect($criteria, $con); } return $objs; }
/** * 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 = CardPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Reservation objects $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::CARD_ID, $obj->getId()); $affectedRows += ReservationPeer::doDelete($c, $con); // delete related Subscription objects $c = new Criteria(SubscriptionPeer::DATABASE_NAME); $c->add(SubscriptionPeer::CARD_ID, $obj->getId()); $affectedRows += SubscriptionPeer::doDelete($c, $con); } return $affectedRows; }
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++; } } }