Exemple #1
0
 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;
 }
Exemple #2
0
 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);
 }