public function GetReservations(DateRange $dateRangeUtc, $scheduleId, $targetTimezone) { $reservationListing = $this->_coordinatorFactory->CreateReservationListing($targetTimezone); $reservations = $this->_repository->GetReservationList($dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd(), null, null, $scheduleId, null); Log::Debug("Found %s reservations for schedule %s between %s and %s", count($reservations), $scheduleId, $dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd()); foreach ($reservations as $reservation) { $reservationListing->Add($reservation); } $blackouts = $this->_repository->GetBlackoutsWithin($dateRangeUtc, $scheduleId); Log::Debug("Found %s blackouts for schedule %s between %s and %s", count($blackouts), $scheduleId, $dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd()); foreach ($blackouts as $blackout) { $reservationListing->AddBlackout($blackout); } return $reservationListing; }
/** * @return Date */ public function EndDate() { return $this->date->GetEnd(); }
public function GetBlackoutsWithin(DateRange $dateRange, $scheduleId = ReservationViewRepository::ALL_SCHEDULES) { $getBlackoutsCommand = new GetBlackoutListCommand($dateRange->GetBegin(), $dateRange->GetEnd(), $scheduleId); $result = ServiceLocator::GetDatabase()->Query($getBlackoutsCommand); $blackouts = array(); while ($row = $result->GetRow()) { $blackouts[] = BlackoutItemView::Populate($row); } $result->Free(); return $blackouts; }
public function SetReservationDate(DateRange $reservationDate) { $this->startDate = $reservationDate->GetBegin(); $this->endDate = $reservationDate->GetEnd(); }
public function testConflictsIfResourceReservationExistsAtSameTime() { $resourceId = 1; $currentId = 19; $currentDate = new DateRange(Date::Now()->AddDays(10), Date::Now()->AddDays(15)); $current = new TestReservation('ref', $currentDate); $current->SetReservationId($currentId); $series = new ExistingReservationSeries(); $series->WithPrimaryResource(new FakeBookableResource($resourceId)); $series->WithResource(new FakeBookableResource($resourceId + 1)); $series->WithCurrentInstance($current); $reservations = array(new TestReservationItemView($currentId + 1, $currentDate->GetBegin(), $currentDate->GetEnd(), $resourceId)); $this->strategy->expects($this->once())->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue($reservations)); $rule = new ExistingResourceAvailabilityRule($this->strategy, $this->timezone); $ruleResult = $rule->Validate($series); $this->assertFalse($ruleResult->IsValid()); }
/** * @param DateRange $otherRange * @return bool */ public function Equals(DateRange $otherRange) { return $this->_begin->Equals($otherRange->GetBegin()) && $this->_end->Equals($otherRange->GetEnd()); }
public function Update($blackoutInstanceId, DateRange $blackoutDate, $resourceIds, $title, IReservationConflictResolution $reservationConflictResolution, IRepeatOptions $repeatOptions, $scope) { if (!$blackoutDate->GetEnd()->GreaterThan($blackoutDate->GetBegin())) { return new BlackoutDateTimeValidationResult(); } $userId = ServiceLocator::GetServer()->GetUserSession()->UserId; $blackoutSeries = $this->LoadBlackout($blackoutInstanceId, $userId); if ($blackoutSeries == null) { return new BlackoutSecurityValidationResult(); } $blackoutSeries->Update($userId, $scope, $title, $blackoutDate, $repeatOptions, $resourceIds); $conflictingBlackouts = $this->GetConflictingBlackouts($blackoutSeries); $conflictingReservations = array(); if (empty($conflictingBlackouts)) { $conflictingReservations = $this->GetConflictingReservations($blackoutSeries, $reservationConflictResolution); } $blackoutValidationResult = new BlackoutValidationResult($conflictingBlackouts, $conflictingReservations); if ($blackoutValidationResult->CanBeSaved()) { $this->blackoutRepository->Update($blackoutSeries); } return $blackoutValidationResult; }
/** * @param DateRange $dateRange * @return array|DateRange[] */ public function Split(DateRange $dateRange) { $ranges = array(); $start = $dateRange->GetBegin(); $end = $dateRange->GetEnd(); if (!$this->SameYear($start, $end)) { $current = $start; while (!$this->SameYear($current, $end)) { $next = $this->GetFirstOfYear($current, 1); $ranges[] = new DateRange($current, $next); $current = $next; if ($this->SameYear($current, $end)) { $ranges[] = new DateRange($current, $end); } } } else { $ranges[] = $dateRange; } return $ranges; }
/** * @param int $instanceId * @param string $referenceNum * @param DateRange $duration * @return ReservationInstanceRow */ public function WithInstance($instanceId, $referenceNum, $duration) { $this->rows[] = array(ColumnNames::SERIES_ID => $this->seriesId, ColumnNames::RESERVATION_INSTANCE_ID => $instanceId, ColumnNames::REFERENCE_NUMBER => $referenceNum, ColumnNames::RESERVATION_START => $duration->GetBegin()->ToDatabase(), ColumnNames::RESERVATION_END => $duration->GetEnd()->ToDatabase()); return $this; }
public function GetDates(DateRange $startingRange) { $dates = array(); $begin = $startingRange->GetBegin(); $end = $startingRange->GetEnd(); $nextStartYear = $begin->Year(); $nextEndYear = $end->Year(); $timezone = $begin->Timezone(); $startDate = $begin; while ($startDate->DateCompare($this->_terminationDate) <= 0) { $nextStartYear = $nextStartYear + $this->_interval; $nextEndYear = $nextEndYear + $this->_interval; $startDate = Date::Create($nextStartYear, $begin->Month(), $begin->Day(), $begin->Hour(), $begin->Minute(), $begin->Second(), $timezone); $endDate = Date::Create($nextEndYear, $end->Month(), $end->Day(), $end->Hour(), $end->Minute(), $end->Second(), $timezone); if ($startDate->DateCompare($this->_terminationDate) <= 0) { $dates[] = new DateRange($startDate->ToUtc(), $endDate->ToUtc()); } } return $dates; }
/** * @param AccessoryReservation $accessoryReservation * @return void */ public function Add(AccessoryReservation $accessoryReservation) { if ($accessoryReservation->GetStartDate()->Equals($this->duration->GetEnd()) || $accessoryReservation->GetEndDate()->Equals($this->duration->GetBegin())) { return; } if (array_key_exists($accessoryReservation->GetReferenceNumber(), $this->addedReservations)) { return; } $this->addedReservations[$accessoryReservation->GetReferenceNumber()] = true; $accessoryId = $accessoryReservation->GetAccessoryId(); if (array_key_exists($accessoryId, $this->quantities)) { $this->quantities[$accessoryId] += $accessoryReservation->QuantityReserved(); } }
/** * @see ISchedulePageBuilder::BindDisplayDates() */ public function BindDisplayDates(ISchedulePage $page, DateRange $dateRange, UserSession $userSession, ISchedule $schedule) { $scheduleLength = $schedule->GetDaysVisible(); if ($page->GetShowFullWeek()) { $scheduleLength = 7; } // we don't want to display the last date in the range (it will be midnight of the last day) $adjustedDateRange = new DateRange($dateRange->GetBegin()->ToTimezone($userSession->Timezone), $dateRange->GetEnd()->ToTimezone($userSession->Timezone)->AddDays(-1)); $page->SetDisplayDates($adjustedDateRange); $startDate = $adjustedDateRange->GetBegin(); $startDay = $schedule->GetWeekdayStart(); if ($startDay == Schedule::Today) { $adjustment = $scheduleLength; $prevAdjustment = $scheduleLength; } else { $adjustment = max($scheduleLength, 7); $prevAdjustment = 7 * floor($adjustment / 7); // ie, if 10, we only want to go back 7 days so there is overlap } $page->SetPreviousNextDates($startDate->AddDays(-$prevAdjustment), $startDate->AddDays($adjustment)); $page->ShowFullWeekToggle($scheduleLength < 7); }