Пример #1
0
 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();
     }
 }
Пример #2
0
 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;
 }