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;
 }