public function executeIndex(sfWebRequest $request) { $this->forward404Unless($this->room = RoomPeer::retrieveByPk($request->getParameter('roomId')), sprintf('Object room does not exist (%s).', $request->getParameter('roomId'))); $this->step = sfConfig::get('app_max_closeperiods_on_closeperiodlist'); $this->getUser()->syncParameters($this, 'closeperiod', 'index', array('offset', 'limit', 'sort_column', 'sort_direction'), $request); if (is_null($this->sort_column)) { $this->sort_column = 'start'; $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, CloseperiodPeer::getSortAliases(), $this->sort_direction); $c->setOffset($this->offset); if ($this->limit >= 0) { $c->setLimit($this->limit); } $this->closeperiod_list = CloseperiodPeer::doSelectFromRoom($this->room->getId(), $c); $this->count = CloseperiodPeer::doCount(CloseperiodPeer::getFromRoomCriteria($this->room->getId())); if ($this->offset < 0 || $this->offset >= $this->count && $this->count > 0) { $this->forward404(); } }
public static function checkCloseperiods($start, $stop, $roomId) { $starttime = strtotime($start); $stoptime = strtotime($stop); if ($starttime >= $stoptime) { //throw new Exception('Start time cannot be superior or equal to stop time.'); return false; } $c = CloseperiodPeer::getFromRoomCriteria($roomId); $c->addAnd(CloseperiodPeer::STOP, $start, Criteria::GREATER_THAN); $c->addAnd(CloseperiodPeer::START, $stop, Criteria::LESS_THAN); return CloseperiodPeer::doCount($c) == 0; }
/** * Returns the number of related Closeperiod objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Closeperiod objects. * @throws PropelException */ public function countCloseperiods(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->collCloseperiods === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(CloseperiodPeer::ROOM_ID, $this->id); $count = CloseperiodPeer::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(CloseperiodPeer::ROOM_ID, $this->id); if (!isset($this->lastCloseperiodCriteria) || !$this->lastCloseperiodCriteria->equals($criteria)) { $count = CloseperiodPeer::doCount($criteria, $con); } else { $count = count($this->collCloseperiods); } } else { $count = count($this->collCloseperiods); } } return $count; }