/** * @param array|ReservationListItem[] $items * @param IScheduleLayout $layout * @param Date $layoutDate * @param bool $hideBlockedPeriods */ public function __construct($items, IScheduleLayout $layout, Date $layoutDate, $hideBlockedPeriods = false) { $this->_items = $items; $this->_layout = $layout; $this->_destinationTimezone = $this->_layout->Timezone(); $this->_layoutDateStart = $layoutDate->ToTimezone($this->_destinationTimezone)->GetDate(); $this->_layoutDateEnd = $this->_layoutDateStart->AddDays(1); $this->_layoutItems = $this->_layout->GetLayout($layoutDate, $hideBlockedPeriods); $this->_midnight = new Time(0, 0, 0, $this->_destinationTimezone); $this->IndexLayout(); $this->IndexItems(); }
public function testSucceedsWhenStartAndEndTimeMatchPeriods() { $date = Date::Now(); $dates = new DateRange($date, $date); $scheduleId = 1232; $resource = new FakeBookableResource(1); $resource->SetScheduleId($scheduleId); $series = ReservationSeries::Create(1, $resource, null, null, $dates, new RepeatNone(), $this->fakeUser); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)))->will($this->returnValue($this->layout)); $period = new SchedulePeriod($date, $date); $this->layout->expects($this->at(0))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->StartDate()))->will($this->returnValue($period)); $this->layout->expects($this->at(1))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->EndDate()))->will($this->returnValue($period)); $result = $this->rule->Validate($series); $this->assertTrue($result->IsValid()); }
public function GetPeriods(Date $displayDate, $fitToHours = false) { $hideBlocked = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_HIDE_BLOCKED_PERIODS, new BooleanConverter()); $periods = $this->_scheduleLayout->GetLayout($displayDate, $hideBlocked); if (!$fitToHours) { return $periods; } /** @var $periodsToReturn SpanablePeriod[] */ $periodsToReturn = array(); $tempPeriod = $periods[0]; for ($i = 0; $i < count($periods); $i++) { $span = 1; $currentPeriod = $periods[$i]; $periodStart = $currentPeriod->BeginDate(); $periodLength = $periodStart->GetDifference($currentPeriod->EndDate())->Hours(); if (!$currentPeriod->IsLabelled() && ($periodStart->Minute() == 0 && $periodLength < 1)) { $span = 0; $nextPeriodTime = $periodStart->AddMinutes(60); $tempPeriod = $currentPeriod; while ($tempPeriod != null && $tempPeriod->BeginDate()->LessThan($nextPeriodTime)) { $span++; $tempPeriod = $periods[++$i]; } if ($span > 0) { $i--; } } $periodsToReturn[] = new SpanablePeriod($currentPeriod, $span); } return $periodsToReturn; }
public function __construct(IRestServer $server, Schedule $schedule, IScheduleLayout $layout) { $this->daysVisible = $schedule->GetDaysVisible(); $this->id = $schedule->GetId(); $this->isDefault = $schedule->GetIsDefault(); $this->name = $schedule->GetName(); $this->timezone = $schedule->GetTimezone(); $this->weekdayStart = $schedule->GetWeekdayStart(); if ($schedule->GetIsCalendarSubscriptionAllowed()) { $url = new CalendarSubscriptionUrl(null, $schedule->GetPublicId(), null); $this->icsUrl = $url->__toString(); } $layoutDate = Date::Now()->ToTimezone($server->GetSession()->Timezone); for ($day = 0; $day < 7; $day++) { $periods = $layout->GetLayout($layoutDate); foreach ($periods as $period) { $this->periods[$layoutDate->Weekday()][] = new SchedulePeriodResponse($period); } $layoutDate = $layoutDate->AddDays(1); } }
public function testWhenPeriodStartTimeIsInPast() { $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::CURRENT); $scheduleId = 123; $now = Date::Parse('2011-04-04 12:13:15', 'UTC'); Date::_SetNow($now); $start = $now->AddDays(-5); $end = $now->AddDays(5); $periodStart = Date::Parse('2011-04-04 12:13:14', 'UTC'); $periodEnd = Date::Parse('2011-04-04 12:13:16', 'UTC'); $reservation = new TestReservationSeries(); $reservation->WithScheduleId($scheduleId); $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end))); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory('UTC')))->will($this->returnValue($this->layout)); $period = new SchedulePeriod($periodStart, $periodEnd); $this->layout->expects($this->once())->method('GetPeriod')->with($this->equalTo($end))->will($this->returnValue($period)); $rule = new ReservationStartTimeRule($this->scheduleRepository); $result = $rule->Validate($reservation); $this->assertFalse($result->IsValid()); }