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