/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $conflicts = array(); $reservations = $reservationSeries->Instances(); $bufferTime = $reservationSeries->MaxBufferTime(); $keyedResources = array(); foreach ($reservationSeries->AllResources() as $resource) { $keyedResources[$resource->GetId()] = $resource; } /** @var Reservation $reservation */ foreach ($reservations as $reservation) { Log::Debug("Checking for reservation conflicts, reference number %s", $reservation->ReferenceNumber()); $startDate = $reservation->StartDate(); $endDate = $reservation->EndDate(); if ($bufferTime != null && !$reservationSeries->BookedBy()->IsAdmin) { $startDate = $startDate->SubtractInterval($bufferTime); $endDate = $endDate->AddInterval($bufferTime); } $existingItems = $this->strategy->GetItemsBetween($startDate, $endDate); /** @var IReservedItemView $existingItem */ foreach ($existingItems as $existingItem) { if (($bufferTime == null || $reservationSeries->BookedBy()->IsAdmin) && ($existingItem->GetStartDate()->Equals($reservation->EndDate()) || $existingItem->GetEndDate()->Equals($reservation->StartDate()))) { continue; } if ($this->IsInConflict($reservation, $reservationSeries, $existingItem, $keyedResources)) { Log::Debug("Reference number %s conflicts with existing %s with id %s", $reservation->ReferenceNumber(), get_class($existingItem), $existingItem->GetId()); array_push($conflicts, $existingItem); } } } $thereAreConflicts = count($conflicts) > 0; if ($thereAreConflicts) { return new ReservationRuleResult(false, $this->GetErrorString($conflicts)); } return new ReservationRuleResult(); }