private function GetDate($queryStringKey) { $dateQueryString = $this->server->GetQueryString($queryStringKey); if (empty($dateQueryString)) { return null; } return WebServiceDate::GetDate($dateQueryString, $this->server->GetSession()); }
/** * @param string $queryStringKey * @return Date */ private function GetBaseDate($queryStringKey, $defaultNumberOfDays = 0) { $dateQueryString = $this->server->GetQueryString($queryStringKey); if (empty($dateQueryString)) { return Date::Now()->AddDays($defaultNumberOfDays); } return WebServiceDate::GetDate($dateQueryString, $this->server->GetSession()); }
/** * @name GetAvailability * @description Returns resource availability for the requested time. "availableAt" and "availableUntil" will include availability through the next 7 days * Optional query string parameter: dateTime. If no dateTime is requested the current datetime will be used. * @response ResourcesAvailabilityResponse * @return void */ public function GetAvailability($resourceId = null) { $dateQueryString = $this->server->GetQueryString(WebServiceQueryStringKeys::DATE_TIME); if (!empty($dateQueryString)) { $requestedTime = WebServiceDate::GetDate($dateQueryString, $this->server->GetSession()); } else { $requestedTime = Date::Now(); } if (empty($resourceId)) { $resources = $this->resourceRepository->GetResourceList(); } else { $resources[] = $this->resourceRepository->LoadById($resourceId); } $lastDateSearched = $requestedTime->AddDays(30); $reservations = $this->GetReservations($this->reservationRepository->GetReservationList($requestedTime, $lastDateSearched, null, null, null, $resourceId)); $resourceAvailability = array(); foreach ($resources as $resource) { $reservation = $this->GetOngoingReservation($resource, $reservations); if ($reservation != null) { $lastReservationBeforeOpening = $this->GetLastReservationBeforeAnOpening($resource, $reservations); if ($lastReservationBeforeOpening == null) { $lastReservationBeforeOpening = $reservation; } $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, $lastReservationBeforeOpening, null, $lastReservationBeforeOpening->EndDate, $lastDateSearched); } else { $resourceId = $resource->GetId(); if (array_key_exists($resourceId, $reservations)) { $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, null, $reservations[$resourceId][0], null, $lastDateSearched); } else { $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, null, null, null, $lastDateSearched); } } } $this->server->WriteResponse(new ResourcesAvailabilityResponse($this->server, $resourceAvailability)); }
/** * @name GetAvailability * @description Returns resource availability for the requested time. "availableAt" and "availableUntil" will include availability through the next 7 days * Optional query string parameter: dateTime. If no dateTime is requested the current datetime will be used. * @response ResourcesAvailabilityResponse * @return void */ public function GetAvailability($resourceId = null) { $dateQueryString = $this->server->GetQueryString(WebServiceQueryStringKeys::DATE_TIME); if (!empty($dateQueryString)) { $requestedTime = WebServiceDate::GetDate($dateQueryString, $this->server->GetSession()); } else { $requestedTime = Date::Now(); } if (empty($resourceId)) { $resources = $this->resourceRepository->GetResourceList(); } else { $resources[] = $this->resourceRepository->LoadById($resourceId); } $startDate = $requestedTime->AddDays(-1); $endDate = $requestedTime->AddDays(7); $reservations = $this->reservationRepository->GetReservationList($startDate, $endDate, null, null, null, $resourceId); $indexedReservations = array(); foreach ($reservations as $reservation) { $key = $reservation->GetResourceId(); if (!array_key_exists($key, $indexedReservations)) { $indexedReservations[$key] = array(); } $indexedReservations[$key][] = $reservation; } $resourceAvailability = array(); foreach ($resources as $resource) { $resourceId = $resource->GetResourceId(); $conflict = null; $nextReservation = null; $opening = null; if (array_key_exists($resourceId, $indexedReservations)) { $resourceReservations = $indexedReservations[$resourceId]; /** @var $reservation ReservationItemView */ foreach ($resourceReservations as $i => $reservation) { if ($conflict == null && $reservation->BufferedTimes()->Contains($requestedTime, false)) { $conflict = $reservation; } if ($nextReservation == null && $reservation->StartDate->GreaterThan($requestedTime)) { $nextReservation = $reservation; } } $opening = $this->GetOpeningAfter($resourceReservations, $requestedTime); if ($opening == null && $conflict != null) { $opening = $conflict->BufferedTimes()->GetEnd(); } } $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, $conflict, $nextReservation, $opening, $endDate); } $this->server->WriteResponse(new ResourcesAvailabilityResponse($this->server, $resourceAvailability)); }
/** * @return Date */ private function GetModifiedSinceDate() { $dateQueryString = $this->server->GetQueryString(WebServiceQueryStringKeys::MODIFIED_DATE); if (empty($dateQueryString)) { return Date::Min(); } else { return WebServiceDate::GetDate($dateQueryString, $this->server->GetSession()); } }
/** * @param string $dateString * @param string $format * @return string|null */ private function GetDate($dateString, $format = Date::SHORT_FORMAT) { if (!empty($dateString)) { return WebServiceDate::GetDate($dateString, $this->session)->ToTimezone($this->session->Timezone)->Format($format); } return null; }