private function PopulateTemplate() { $this->Set('UserName', $this->reservationOwner->FullName()); $currentInstance = $this->reservationSeries->CurrentInstance(); $this->Set('StartDate', $currentInstance->StartDate()->ToTimezone($this->timezone)); $this->Set('EndDate', $currentInstance->EndDate()->ToTimezone($this->timezone)); $this->Set('ResourceName', $this->resource->GetName()); $this->Set('Title', $this->reservationSeries->Title()); $this->Set('Description', $this->reservationSeries->Description()); $repeatDates = array(); foreach ($this->reservationSeries->Instances() as $repeated) { $repeatDates[] = $repeated->StartDate()->ToTimezone($this->timezone); } $this->Set('RequiresApproval', $this->reservationSeries->RequiresApproval()); $this->Set('RepeatDates', $repeatDates); $this->Set('ReservationUrl', Pages::RESERVATION . "?" . QueryStringKeys::REFERENCE_NUMBER . '=' . $currentInstance->ReferenceNumber()); $resourceNames = array(); foreach ($this->reservationSeries->AllResources() as $resource) { $resourceNames[] = $resource->GetName(); } $this->Set('ResourceNames', $resourceNames); $this->Set('Accessories', $this->reservationSeries->Accessories()); $attributes = $this->attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION); $attributeValues = array(); foreach ($attributes as $attribute) { $attributeValues[] = new Attribute($attribute, $this->reservationSeries->GetAttributeValue($attribute->Id())); } $this->Set('Attributes', $attributeValues); $bookedBy = $this->reservationSeries->BookedBy(); if ($bookedBy != null && $bookedBy->UserId != $this->reservationOwner->Id()) { $this->Set('CreatedBy', new FullName($bookedBy->FirstName, $bookedBy->LastName)); } }
protected function PopulateTemplate() { $currentInstance = $this->reservationSeries->CurrentInstance(); $this->Set('UserName', $this->reservationOwner->FullName()); $this->Set('StartDate', $currentInstance->StartDate()->ToTimezone($this->timezone)); $this->Set('EndDate', $currentInstance->EndDate()->ToTimezone($this->timezone)); $this->Set('ResourceName', $this->reservationSeries->Resource()->GetName()); $this->Set('Title', $this->reservationSeries->Title()); $this->Set('Description', $this->reservationSeries->Description()); $repeatDates = array(); if ($this->reservationSeries->IsRecurring()) { foreach ($this->reservationSeries->Instances() as $repeated) { $repeatDates[] = $repeated->StartDate()->ToTimezone($this->timezone); } } $this->Set('RepeatDates', $repeatDates); $this->Set('RequiresApproval', $this->reservationSeries->RequiresApproval()); $this->Set('ReservationUrl', sprintf("%s?%s=%s", Pages::RESERVATION, QueryStringKeys::REFERENCE_NUMBER, $currentInstance->ReferenceNumber())); $this->Set('ICalUrl', sprintf("export/%s?%s=%s", Pages::CALENDAR_EXPORT, QueryStringKeys::REFERENCE_NUMBER, $currentInstance->ReferenceNumber())); $resourceNames = array(); foreach ($this->reservationSeries->AllResources() as $resource) { $resourceNames[] = $resource->GetName(); } $this->Set('ResourceNames', $resourceNames); $this->Set('Accessories', $this->reservationSeries->Accessories()); $attributes = $this->attributeRepository->GetByCategory(CustomAttributeCategory::RESERVATION); $attributeValues = array(); foreach ($attributes as $attribute) { $attributeValues[] = new Attribute($attribute, $this->reservationSeries->GetAttributeValue($attribute->Id())); } $this->Set('Attributes', $attributeValues); }
/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $conflicts = array(); $reservationAccessories = $reservationSeries->Accessories(); if (count($reservationAccessories) == 0) { // no accessories to be reserved, no need to proceed return new ReservationRuleResult(); } /** @var AccessoryToCheck[] $accessories */ $accessories = array(); foreach ($reservationAccessories as $accessory) { $a = $this->accessoryRepository->LoadById($accessory->AccessoryId); if (!$a->HasUnlimitedQuantity()) { $accessories[$a->GetId()] = new AccessoryToCheck($a, $accessory); } } if (count($accessories) == 0) { // no accessories with limited quantity to be reserved, no need to proceed return new ReservationRuleResult(); } $reservations = $reservationSeries->Instances(); /** @var Reservation $reservation */ foreach ($reservations as $reservation) { Log::Debug("Checking for accessory conflicts, reference number %s", $reservation->ReferenceNumber()); $accessoryReservations = $this->reservationRepository->GetAccessoriesWithin($reservation->Duration()); $aggregation = new AccessoryAggregation($accessories, $reservation->Duration()); foreach ($accessoryReservations as $accessoryReservation) { if ($reservation->ReferenceNumber() != $accessoryReservation->GetReferenceNumber()) { $aggregation->Add($accessoryReservation); } } foreach ($accessories as $accessory) { $alreadyReserved = $aggregation->GetQuantity($accessory->GetId()); $requested = $accessory->QuantityReserved(); if ($requested + $alreadyReserved > $accessory->QuantityAvailable()) { Log::Debug("Accessory over limit. Reference Number %s, Date %s, Quantity already reserved %s, Quantity requested: %s", $reservation->ReferenceNumber(), $reservation->Duration(), $alreadyReserved, $requested); array_push($conflicts, array('name' => $accessory->GetName(), 'date' => $reservation->StartDate())); } } } $thereAreConflicts = count($conflicts) > 0; if ($thereAreConflicts) { return new ReservationRuleResult(false, $this->GetErrorString($conflicts)); } return new ReservationRuleResult(); }
/** * @param ReservationSeries $reservationSeries * @return int newly created series_id */ private function InsertSeries(ReservationSeries $reservationSeries) { $database = ServiceLocator::GetDatabase(); $insertReservationSeries = new AddReservationSeriesCommand(Date::Now(), $reservationSeries->Title(), $reservationSeries->Description(), $reservationSeries->RepeatOptions()->RepeatType(), $reservationSeries->RepeatOptions()->ConfigurationString(), ReservationTypes::Reservation, $reservationSeries->StatusId(), $reservationSeries->UserId(), $reservationSeries->GetAllowParticipation()); $reservationSeriesId = $database->ExecuteInsert($insertReservationSeries); $reservationSeries->WithSeriesId($reservationSeriesId); $insertReservationResource = new AddReservationResourceCommand($reservationSeriesId, $reservationSeries->ResourceId(), ResourceLevel::Primary); $database->Execute($insertReservationResource); foreach ($reservationSeries->AdditionalResources() as $resource) { $insertReservationResource = new AddReservationResourceCommand($reservationSeriesId, $resource->GetResourceId(), ResourceLevel::Additional); $database->Execute($insertReservationResource); } foreach ($reservationSeries->Accessories() as $accessory) { $insertAccessory = new AddReservationAccessoryCommand($accessory->AccessoryId, $accessory->QuantityReserved, $reservationSeriesId); $database->Execute($insertAccessory); } foreach ($reservationSeries->AttributeValues() as $attribute) { $insertAttributeValue = new AddAttributeValueCommand($attribute->AttributeId, $attribute->Value, $reservationSeriesId, CustomAttributeCategory::RESERVATION); $database->Execute($insertAttributeValue); } foreach ($reservationSeries->AddedAttachments() as $attachment) { $this->AddReservationAttachment($attachment); } if ($reservationSeries->GetStartReminder()->Enabled()) { $reminder = $reservationSeries->GetStartReminder(); $insertAccessory = new AddReservationReminderCommand($reservationSeriesId, $reminder->MinutesPrior(), ReservationReminderType::Start); $database->Execute($insertAccessory); } if ($reservationSeries->GetEndReminder()->Enabled()) { $reminder = $reservationSeries->GetEndReminder(); $insertAccessory = new AddReservationReminderCommand($reservationSeriesId, $reminder->MinutesPrior(), ReservationReminderType::End); $database->Execute($insertAccessory); } return $reservationSeriesId; }