public function PageLoad(UserSession $user) { $now = Date::Now(); $resources = $this->resourceService->GetAllResources(false, $user); $reservations = $this->GetReservations($this->reservationViewRepository->GetReservationList($now, $now)); $next = $this->reservationViewRepository->GetNextReservations($now); $available = array(); $unavailable = array(); $allday = array(); foreach ($resources as $resource) { $reservation = $this->GetOngoingReservation($resource, $reservations); if ($reservation != null) { if (!$reservation->EndDate->DateEquals(Date::Now())) { $allday[] = new UnavailableDashboardItem($resource, $reservation); } else { $unavailable[] = new UnavailableDashboardItem($resource, $reservation); } } else { if (array_key_exists($resource->GetId(), $next)) { $available[] = new AvailableDashboardItem($resource, $next[$resource->GetId()]); } else { $available[] = new AvailableDashboardItem($resource); } } } $this->control->SetAvailable($available); $this->control->SetUnavailable($unavailable); $this->control->SetUnavailableAllDay($allday); }
public function PageLoad(UserSession $user) { $now = Date::Now(); $resources = $this->resourceService->GetAllResources(false, $user); $reservations = $this->GetReservations($this->reservationViewRepository->GetReservationList($now, $now->AddDays(30))); $available = array(); $unavailable = array(); $allday = array(); foreach ($resources as $resource) { $reservation = $this->GetOngoingReservation($resource, $reservations); if ($reservation != null) { $lastReservationBeforeOpening = $this->GetLastReservationBeforeAnOpening($resource, $reservations); if ($lastReservationBeforeOpening == null) { $lastReservationBeforeOpening = $reservation; } if (!$reservation->EndDate->DateEquals($now)) { $allday[] = new UnavailableDashboardItem($resource, $lastReservationBeforeOpening); } else { $unavailable[] = new UnavailableDashboardItem($resource, $lastReservationBeforeOpening); } } else { $resourceId = $resource->GetId(); if (array_key_exists($resourceId, $reservations)) { $available[] = new AvailableDashboardItem($resource, $reservations[$resourceId][0]); } else { $available[] = new AvailableDashboardItem($resource); } } } $this->control->SetAvailable($available); $this->control->SetUnavailable($unavailable); $this->control->SetUnavailableAllDay($allday); }
/** * @name GetReservations * @description Gets a list of reservations for the specified parameters. * Optional query string parameters: userId, resourceId, scheduleId, startDateTime, endDateTime. * If no dates are provided, reservations for the next two weeks will be returned. * If dates do not include the timezone offset, the timezone of the authenticated user will be assumed. * @response ReservationsResponse * @return void */ public function GetReservations() { $startDate = $this->GetStartDate(); $endDate = $this->GetEndDate(); $userId = $this->GetUserId(); $resourceId = $this->GetResourceId(); $scheduleId = $this->GetScheduleId(); Log::Debug('GetReservations called. userId=%s, startDate=%s, endDate=%s', $userId, $startDate, $endDate); $reservations = $this->reservationViewRepository->GetReservationList($startDate, $endDate, $userId, null, $scheduleId, $resourceId); $response = new ReservationsResponse($this->server, $reservations, $this->privacyFilter, $startDate, $endDate); $this->server->WriteResponse($response); }
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; }
public function PageLoad() { $user = ServiceLocator::GetServer()->GetUserSession(); $timezone = $user->Timezone; $now = Date::Now(); $today = $now->ToTimezone($timezone)->GetDate(); $dayOfWeek = $today->Weekday(); $lastDate = $now->AddDays(13 - $dayOfWeek - 1); $reservations = $this->repository->GetReservationList($now, $lastDate, $this->searchUserId, $this->searchUserLevel); $tomorrow = $today->AddDays(1); $startOfNextWeek = $today->AddDays(7 - $dayOfWeek); $todays = array(); $tomorrows = array(); $thisWeeks = array(); $nextWeeks = array(); /* @var $reservation ReservationItemView */ /*foreach ($reservations as $reservation) { $start = $reservation->StartDate->ToTimezone($timezone); if ($start->DateEquals($today)) { $todays[] = $reservation; } else if ($start->DateEquals($tomorrow)) { $tomorrows[] = $reservation; } else if ($start->LessThan($startOfNextWeek)) { $thisWeeks[] = $reservation; } else { $nextWeeks[] = $reservation; } }*/ $this->control->SetTotal(count($reservations)); $this->control->SetTimezone($timezone); $this->control->SetUserId($user->UserId); $this->control->BindReservations($reservations); $this->control->BindExperiment($reservations->experiment); $this->control->BindTodayDate(); /*$this->control->BindToday($todays); $this->control->BindTomorrow($tomorrows); $this->control->BindThisWeek($thisWeeks); $this->control->BindNextWeek($nextWeeks);*/ }
/** * @param UserSession $userSession * @param string $timezone */ public function PageLoad($userSession, $timezone) { $type = $this->page->GetCalendarType(); $year = $this->page->GetYear(); $month = $this->page->GetMonth(); $day = $this->page->GetDay(); $defaultDate = Date::Now()->ToTimezone($timezone); if (empty($year)) { $year = $defaultDate->Year(); } if (empty($month)) { $month = $defaultDate->Month(); } if (empty($day)) { $day = $defaultDate->Day(); } $schedules = $this->scheduleRepository->GetAll(); $showInaccessible = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, new BooleanConverter()); $resources = $this->resourceService->GetAllResources($showInaccessible, $userSession); $selectedScheduleId = $this->page->GetScheduleId(); $selectedSchedule = $this->GetDefaultSchedule($schedules); $selectedResourceId = $this->page->GetResourceId(); $calendar = $this->calendarFactory->Create($type, $year, $month, $day, $timezone, $selectedSchedule->GetWeekdayStart()); $reservations = $this->reservationRepository->GetReservationList($calendar->FirstDay(), $calendar->LastDay()->AddDays(1), $userSession->UserId, ReservationUserLevel::ALL, $selectedScheduleId, $selectedResourceId); $calendar->AddReservations(CalendarReservation::FromViewList($reservations, $timezone)); $this->page->BindCalendar($calendar); $this->page->SetDisplayDate($calendar->FirstDay()); $this->page->BindFilters(new CalendarFilters($schedules, $resources, $selectedScheduleId, $selectedResourceId)); $this->page->SetScheduleId($selectedScheduleId); $this->page->SetResourceId($selectedResourceId); $this->page->SetFirstDay($selectedSchedule->GetWeekdayStart()); $details = $this->subscriptionService->ForUser($userSession->UserId); $this->page->BindSubscription($details); }
/** * @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)); }
public function PageLoad() { if (!$this->validator->IsValid()) { return; } $userId = $this->page->GetUserId(); $scheduleId = $this->page->GetScheduleId(); $resourceId = $this->page->GetResourceId(); $accessoryIds = $this->page->GetAccessoryIds(); $resourceGroupId = $this->page->GetResourceGroupId(); $weekAgo = Date::Now()->AddDays(-7); $nextYear = Date::Now()->AddDays(365); $sid = null; $rid = null; $uid = null; $aid = null; $resourceIds = array(); $reservations = array(); $res = array(); $summaryFormat = Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION_LABELS, ConfigKeys::RESERVATION_LABELS_ICS_SUMMARY); $reservationUserLevel = ReservationUserLevel::OWNER; if (!empty($scheduleId)) { $schedule = $this->subscriptionService->GetSchedule($scheduleId); $sid = $schedule->GetId(); } if (!empty($resourceId)) { $resource = $this->subscriptionService->GetResource($resourceId); $rid = $resource->GetId(); } if (!empty($accessoryIds)) { ## No transformation is implemented. It is assumed the accessoryIds is provided as AccessoryName ## filter is defined by LIKE "PATTERN%" $aid = $accessoryIds; } if (!empty($userId)) { $user = $this->subscriptionService->GetUser($userId); $uid = $user->Id(); $reservationUserLevel = ReservationUserLevel::ALL; $summaryFormat = Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION_LABELS, ConfigKeys::RESERVATION_LABELS_MY_ICS_SUMMARY); } if (!empty($resourceGroupId)) { $resourceIds = $this->subscriptionService->GetResourcesInGroup($resourceGroupId); } if (!empty($uid) || !empty($sid) || !empty($rid) || !empty($resourceIds)) { $res = $this->reservationViewRepository->GetReservationList($weekAgo, $nextYear, $uid, $reservationUserLevel, $sid, $rid); } elseif (!empty($aid)) { throw new Exception('need to give an accessory a public id, allow subscriptions'); $res = $this->reservationViewRepository->GetAccessoryReservationList($weekAgo, $nextYear, $accessoryIds); } Log::Debug('Loading calendar subscription for userId %s, scheduleId %s, resourceId %s. Found %s reservations.', $userId, $scheduleId, $resourceId, count($res)); $session = ServiceLocator::GetServer()->GetUserSession(); foreach ($res as $r) { if (empty($resourceIds) || in_array($r->ResourceId, $resourceIds)) { $reservations[] = new iCalendarReservationView($r, $session, $this->privacyFilter, $summaryFormat); } } $this->page->SetReservations($reservations); }
public function PageLoad() { $invitationAction = $this->page->GetInvitationAction(); if (!empty($invitationAction)) { $resultString = $this->HandleInvitationAction($invitationAction); if ($this->page->GetResponseType() == 'json') { $this->page->DisplayResult($resultString); return; } $this->page->SetResult($resultString); } $startDate = Date::Now(); $endDate = $startDate->AddDays(30); $user = ServiceLocator::GetServer()->GetUserSession(); $userId = $user->UserId; $reservations = $this->reservationViewRepository->GetReservationList($startDate, $endDate, $userId, ReservationUserLevel::INVITEE); $this->page->SetTimezone($user->Timezone); $this->page->BindReservations($reservations); $this->page->DisplayParticipation(); }
public function PageLoad($userSession, $timezone) { $type = $this->page->GetCalendarType(); $year = $this->page->GetYear(); $month = $this->page->GetMonth(); $day = $this->page->GetDay(); $defaultDate = Date::Now()->ToTimezone($timezone); if (empty($year)) { $year = $defaultDate->Year(); } if (empty($month)) { $month = $defaultDate->Month(); } if (empty($day)) { $day = $defaultDate->Day(); } $schedules = $this->scheduleRepository->GetAll(); $showInaccessible = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, new BooleanConverter()); $resources = $this->resourceService->GetAllResources($showInaccessible, $userSession); $selectedScheduleId = $this->page->GetScheduleId(); $selectedSchedule = $this->GetDefaultSchedule($schedules); $selectedResourceId = $this->page->GetResourceId(); $selectedGroupId = $this->page->GetGroupId(); $resourceGroups = $this->resourceService->GetResourceGroups($selectedScheduleId, $userSession); if (!empty($selectedGroupId)) { $tempResources = array(); $resourceIds = $resourceGroups->GetResourceIds($selectedGroupId); $selectedGroup = $resourceGroups->GetGroup($selectedGroupId); $this->page->BindSelectedGroup($selectedGroup); foreach ($resources as $resource) { if (in_array($resource->GetId(), $resourceIds)) { $tempResources[] = $resource; } } $resources = $tempResources; } if (!empty($selectedResourceId)) { $subscriptionDetails = $this->subscriptionService->ForResource($selectedResourceId); } else { $subscriptionDetails = $this->subscriptionService->ForSchedule($selectedSchedule->GetId()); } $calendar = $this->calendarFactory->Create($type, $year, $month, $day, $timezone, $selectedSchedule->GetWeekdayStart()); $reservations = $this->reservationRepository->GetReservationList($calendar->FirstDay(), $calendar->LastDay()->AddDays(1), null, null, $selectedScheduleId, $selectedResourceId); $calendar->AddReservations(CalendarReservation::FromScheduleReservationList($reservations, $resources, $userSession, true)); $this->page->BindCalendar($calendar); $this->page->BindFilters(new CalendarFilters($schedules, $resources, $selectedScheduleId, $selectedResourceId, $resourceGroups)); $this->page->SetDisplayDate($calendar->FirstDay()); $this->page->SetScheduleId($selectedScheduleId); $this->page->SetResourceId($selectedResourceId); $this->page->SetFirstDay($selectedSchedule->GetWeekdayStart()); $this->page->BindSubscription($subscriptionDetails); }
/** * @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)); }
/** * @param BlackoutSeries $blackoutSeries * @param IReservationConflictResolution $reservationConflictResolution * @return array|ReservationItemView[] */ private function GetConflictingReservations($blackoutSeries, $reservationConflictResolution) { $conflictingReservations = array(); $blackouts = $blackoutSeries->AllBlackouts(); foreach ($blackouts as $blackout) { $existingReservations = $this->reservationViewRepository->GetReservationList($blackout->StartDate(), $blackout->EndDate()); foreach ($existingReservations as $existingReservation) { if ($blackoutSeries->ContainsResource($existingReservation->ResourceId) && $blackout->Date()->Overlaps($existingReservation->Date)) { if (!$reservationConflictResolution->Handle($existingReservation)) { $conflictingReservations[] = $existingReservation; } } } } return $conflictingReservations; }
public function PageLoad() { if (!$this->validator->IsValid()) { return; } $userId = $this->page->GetUserId(); $scheduleId = $this->page->GetScheduleId(); $resourceId = $this->page->GetResourceId(); $accessoryIds = $this->page->GetAccessoryIds(); $weekAgo = Date::Now()->AddDays(-7); $nextYear = Date::Now()->AddDays(365); $sid = null; $rid = null; $uid = null; $aid = null; $reservations = array(); $res = array(); if (!empty($scheduleId)) { $schedule = $this->subscriptionService->GetSchedule($scheduleId); $sid = $schedule->GetId(); } if (!empty($resourceId)) { $resource = $this->subscriptionService->GetResource($resourceId); $rid = $resource->GetId(); } if (!empty($accessoryIds)) { ## No transformation is implemented. It is assumed the accessoryIds is provided as AccessoryName ## filter is defined by LIKE "PATTERN%" $aid = $accessoryIds; } if (!empty($userId)) { $user = $this->subscriptionService->GetUser($userId); $uid = $user->Id(); } if (!empty($uid) || !empty($sid) || !empty($rid)) { $res = $this->reservationViewRepository->GetReservationList($weekAgo, $nextYear, $uid, null, $sid, $rid); } elseif (!empty($aid)) { throw new Exception('need to give an accessory a public id, allow subscriptions'); $res = $this->reservationViewRepository->GetAccessoryReservationList($weekAgo, $nextYear, $accessoryIds); } Log::Debug('Loading calendar subscription for userId %s, scheduleId %s, resourceId %s. Found %s reservations.', $userId, $scheduleId, $resourceId, count($res)); foreach ($res as $r) { $reservations[] = new iCalendarReservationView($r, ServiceLocator::GetServer()->GetUserSession(), $this->privacyFilter); } $this->page->SetReservations($reservations); }
public function GetItemsBetween(Date $startDate, Date $endDate) { return $this->_repository->GetReservationList($startDate, $endDate); }
/** * @param ReservationSeries $reservationSeries * @param User $user * @param Schedule $schedule * @param IReservationViewRepository $reservationViewRepository * @return bool */ public function ExceedsQuota($reservationSeries, $user, $schedule, IReservationViewRepository $reservationViewRepository) { $timezone = $schedule->GetTimezone(); if (!is_null($this->resourceId)) { $appliesToResource = false; foreach ($reservationSeries->AllResourceIds() as $resourceId) { if (!$appliesToResource && $this->AppliesToResource($resourceId)) { $appliesToResource = true; } } if (!$appliesToResource) { return false; } } if (!is_null($this->groupId)) { $appliesToGroup = false; foreach ($user->Groups() as $group) { if (!$appliesToGroup && $this->AppliesToGroup($group->GroupId)) { $appliesToGroup = true; } } if (!$appliesToGroup) { return false; } } if (!$this->AppliesToSchedule($reservationSeries->ScheduleId())) { return false; } if (count($reservationSeries->Instances()) == 0) { return false; } $dates = $this->duration->GetSearchDates($reservationSeries, $timezone); $reservationsWithinRange = $reservationViewRepository->GetReservationList($dates->Start(), $dates->End(), $reservationSeries->UserId(), ReservationUserLevel::OWNER); try { $this->CheckAll($reservationsWithinRange, $reservationSeries, $timezone); } catch (QuotaExceededException $ex) { return true; } return false; }