public function getDayCloseDuration($tst) { $start = strtotime($this->getStart()); $stop = strtotime($this->getStop()); $dayStart = mktime(0, 0, 0, date('m', $tst), date('d', $tst), date('Y', $tst)); $dayStop = mktime(0, 0, 0, date('m', $tst), date('d', $tst) + 1, date('Y', $tst)); if ($start < $dayStart) { $start = $dayStart; } if ($stop > $dayStop) { $stop = $dayStop; } $dayOfWeek = date('N', $tst) - 1; $c = DayperiodPeer::getFromRoomCriteria($this->getRoomId()); $c->addAnd(DayperiodPeer::DAY_OF_WEEK, $dayOfWeek, Criteria::EQUAL); $dayperiods = DayperiodPeer::doSelect($c); if (count($dayperiods) > 0) { $result = 0; foreach ($dayperiods as $dayperiod) { $result += $dayperiod->getDurationIn($start, $stop, $dayStart); } return $result; } else { return 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; }
public static function checkDayperiods($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 = DayperiodPeer::getFromRoomCriteria($roomId); $c->addAnd(DayperiodPeer::DAY_OF_WEEK, self::getWeekDaysFromInterval($starttime, $stoptime), Criteria::IN); $dayperiods = DayperiodPeer::doSelect($c); while ($starttime < $stoptime) { // Check if the start matches one dayperiod $tst = null; foreach ($dayperiods as $index => $dayperiod) { if ($dayperiod->matchTimestamp($starttime)) { $tst = $dayperiod->getStopTimestamp($starttime); unset($dayperiods[$index]); break; } } if (is_null($tst)) { return false; } $starttime = $tst; } return true; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(DayperiodPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(DayperiodPeer::DATABASE_NAME); $criteria->add(DayperiodPeer::ID, $pks, Criteria::IN); $objs = DayperiodPeer::doSelect($criteria, $con); } return $objs; }
public function getOverlappingDayperiods() { $c = $this->getOverlappingDayperiodsCriteria(); return DayperiodPeer::doSelect($c); }
/** * Gets an array of Dayperiod objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this Room has previously been saved, it will retrieve * related Dayperiods from storage. If this Room is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array Dayperiod[] * @throws PropelException */ public function getDayperiods($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(RoomPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collDayperiods === null) { if ($this->isNew()) { $this->collDayperiods = array(); } else { $criteria->add(DayperiodPeer::ROOM_ID, $this->id); DayperiodPeer::addSelectColumns($criteria); $this->collDayperiods = DayperiodPeer::doSelect($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 the collection. $criteria->add(DayperiodPeer::ROOM_ID, $this->id); DayperiodPeer::addSelectColumns($criteria); if (!isset($this->lastDayperiodCriteria) || !$this->lastDayperiodCriteria->equals($criteria)) { $this->collDayperiods = DayperiodPeer::doSelect($criteria, $con); } } } $this->lastDayperiodCriteria = $criteria; return $this->collDayperiods; }