コード例 #1
0
ファイル: CloseperiodPeer.php プロジェクト: jfesquet/tempos
 public static function getWeekCriteria($date, $c = null)
 {
     if (is_null($c)) {
         $c = new Criteria();
     }
     $cton1 = $c->getNewCriterion(CloseperiodPeer::STOP, strftime('%Y-%m-%d', ReservationPeer::getWeekStart($date)), Criteria::GREATER_THAN);
     $cton2 = $c->getNewCriterion(CloseperiodPeer::START, strftime('%Y-%m-%d', ReservationPeer::getWeekStop($date)), Criteria::LESS_THAN);
     $cton1->addAnd($cton2);
     $c->addAnd($cton1);
     return $c;
 }
コード例 #2
0
ファイル: actions.class.php プロジェクト: jfesquet/tempos
 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->getUserAttributes();
     if ($request->hasParameter('activityId')) {
         $this->forward404Unless($this->activity = ActivityPeer::retrieveByPk($request->getParameter('activityId')), sprintf('Object activity does not exist (%s).', $request->getParameter('activityId')));
         $this->forward404Unless($this->person->hasActivity($this->activity->getId()), sprintf('Cannot access entry ("%s").', $this->activity));
         $this->getUser()->setAttribute('activityId', $this->activity->getId());
     } else {
         $this->forward404Unless($this->activity = ActivityPeer::retrieveByPk($this->getUser()->getAttribute('activityId')), sprintf('Object activity does not exist (%s).', $this->getUser()->getAttribute('activityId')));
     }
     $this->checkRoomAccess($this->room->getId(), $this->activity->getId());
     $this->forward404Unless($this->realPerson = $this->getUser()->getPerson(), 'No user or card logged-in.');
     $this->is_admin = $this->isAdmin();
     $this->getUser()->syncParameters($this, 'reservation', 'index', array('displayPeriod'), $request);
     $this->getUser()->syncParameters($this, 'general', 'index', array('date'), $request);
     if (is_null($this->date)) {
         $this->date = time();
     } else {
         $this->date = strtotime($this->date);
     }
     if ($request->hasParameter('displayPeriod')) {
         $this->displayPeriod = $request->getParameter('displayPeriod');
     } else {
         $this->displayPeriod = 'week';
     }
     if ($this->displayPeriod == 'week') {
         $this->weekStart = ReservationPeer::getWeekStart($this->date);
         $this->reservation_list = ReservationPeer::doSelectWeekOrderbyDate($this->room->getId(), $this->date);
     } else {
         $this->forward404(sprintf('No valid display period set (%s).', $this->displayPeriod));
     }
     if ($this->getUser()->hasFlash('deleteError')) {
         $this->deleteError = $this->getUser()->getFlash('deleteError');
     }
 }
コード例 #3
0
ファイル: RoomPeer.php プロジェクト: jfesquet/tempos
 protected static function getWeekAvailability($room_id_list, $activityId, $person, $timestamp)
 {
     $now = time();
     // Get the week start
     $weekStart = ReservationPeer::getWeekStart($timestamp);
     // We get all the reservations for the current room list in the week containing the given timestamp.
     $c = ReservationPeer::getWeekCriteria($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.
     $c = new Criteria();
     $c->addAnd(DayperiodPeer::ROOM_ID, $room_id_list, Criteria::IN);
     $c->addAscendingOrderByColumn(DayperiodPeer::DAY_OF_WEEK);
     $c->addAscendingOrderByColumn(DayperiodPeer::START);
     $dayPeriods = DayperiodPeer::doSelect($c);
     // We get all the close periods for the current room list.
     $c = CloseperiodPeer::getWeekCriteria($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();
     for ($i = 0; $i < 7; ++$i) {
         $result[$i] = array();
         for ($j = 0; $j < 48; ++$j) {
             $tst = strtotime(date('Y-m-d H:i:s', $weekStart) . ' + ' . $i . ' day + ' . $j * 30 . ' minute');
             $value = RoomPeer::COMPLETE;
             $roomsId = array();
             $cnt = 0;
             foreach ($dayPeriods as $dayPeriod) {
                 if ($dayPeriod->matchTimestamp($tst)) {
                     if ($j < $startIndex) {
                         $startIndex = $j;
                     }
                     if ($j >= $stopIndex) {
                         $stopIndex = $j + 1;
                     }
                     ++$cnt;
                     $roomsId[] = $dayPeriod->getRoomId();
                 } elseif ($dayPeriod->getDayOfWeek() > $i) {
                     break;
                 }
             }
             if ($cnt == count($room_id_list)) {
                 $value = RoomPeer::FREE;
             } elseif ($cnt > 0) {
                 $value = RoomPeer::OCCUPIED;
             }
             $cnt = 0;
             foreach ($closePeriods as $closePeriod) {
                 if ($closePeriod->matchTimestamp($tst)) {
                     ++$cnt;
                     unset($roomsId[array_search($closePeriod->getRoomId(), $roomsId)]);
                 }
                 if (strtotime($closePeriod->getStart()) > $tst) {
                     break;
                 }
             }
             if ($cnt == count($room_id_list)) {
                 $value = RoomPeer::COMPLETE;
             } else {
                 if ($cnt > 0) {
                     $value = RoomPeer::OCCUPIED;
                 }
             }
             if ($value != RoomPeer::COMPLETE) {
                 if ($tst <= $now) {
                     $value = RoomPeer::PAST;
                 } else {
                     $cnt = 0;
                     foreach ($room_id_list as $roomId) {
                         $maximumTimestamp = $person->getMaximumDate($activityId, $roomId);
                         if ($maximumTimestamp <= $tst || !$person->hasSubscription($activityId, $roomId, $tst)) {
                             ++$cnt;
                             unset($roomsId[array_search($roomId, $roomsId)]);
                         }
                     }
                     if ($cnt == count($room_id_list)) {
                         $value = RoomPeer::TOOFAR;
                     } else {
                         if ($cnt > 0) {
                             $value = RoomPeer::OCCUPIED;
                         }
                         $cnt = 0;
                         foreach ($reservations as $reservation) {
                             if ($reservation->matchTimestamp($tst)) {
                                 ++$cnt;
                                 unset($roomsId[array_search($reservation->getRoomprofile()->getRoomId(), $roomsId)]);
                             } elseif (strtotime($reservation->getDate()) > $tst) {
                                 break;
                             }
                         }
                         if (count($roomsId) == 0) {
                             $value = RoomPeer::COMPLETE;
                         } else {
                             if ($cnt > 0) {
                                 $value = RoomPeer::OCCUPIED;
                             }
                         }
                     }
                 }
             }
             $result[$i][$j]['value'] = $value;
             $result[$i][$j]['rooms'] = $roomsId;
             $result[$i][$j]['timestamp'] = $tst;
         }
     }
     $result['startIndex'] = $startIndex;
     $result['stopIndex'] = $stopIndex;
     return $result;
 }