/** * @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 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); } }