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); }
public function LoadByReferenceNumber($referenceNumber, $user) { $reservation = $this->reservationViewRepository->GetReservationForEditing($referenceNumber); if ($this->reservationAuthorization->CanEdit($reservation, $user)) { return $reservation; } return null; }
/** * @param $pageNumber int * @param $pageSize int * @param $filter ReservationFilter * @param $user UserSession * @return PageableData|ReservationItemView[] */ public function LoadFiltered($pageNumber, $pageSize, $filter, $user) { $groupIds = array(); $groups = $this->userRepository->LoadGroups($user->UserId, RoleLevel::RESOURCE_ADMIN); foreach ($groups as $group) { $groupIds[] = $group->GroupId; } $filter->_And(new SqlFilterIn(new SqlFilterColumn(TableNames::RESOURCES, ColumnNames::RESOURCE_ADMIN_GROUP_ID), $groupIds)); return $this->reservationViewRepository->GetList($pageNumber, $pageSize, null, null, $filter->GetFilter()); }
public function testLoadsReservationIfTheUserCanEdit() { $reservation = new ReservationView(); $user = $this->fakeUser; $referenceNumber = 'rn'; $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation)); $this->reservationAuthorization->expects($this->once())->method('CanEdit')->with($this->equalTo($reservation), $this->equalTo($user))->will($this->returnValue(true)); $res = $this->service->LoadByReferenceNumber($referenceNumber, $user); $this->assertEquals($reservation, $res); }
public function testCannotSeeReservationDetailsIfConfiguredOff() { $referenceNumber = 'ref'; $reservationResult = new ReservationView(); $this->validator->expects($this->atLeastOnce())->method('IsValid')->will($this->returnValue(true)); $this->page->expects($this->once())->method('GetReferenceNumber')->will($this->returnValue($referenceNumber)); $this->repo->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservationResult)); $this->page->expects($this->once())->method('SetReservations')->with($this->arrayHasKey(0)); $this->presenter->PageLoad($this->fakeUser); }
public function testPullsReservationViewFromRepository() { $referenceNumber = '1234'; $reservationView = new ReservationView(); $this->page->expects($this->once())->method('GetReferenceNumber')->will($this->returnValue($referenceNumber)); $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($referenceNumber)->will($this->returnValue($reservationView)); $this->preconditionService->expects($this->once())->method('CheckAll')->with($this->page, $this->user, $reservationView); $this->initializerFactory->expects($this->once())->method('GetExistingInitializer')->with($this->equalTo($this->page), $this->equalTo($reservationView))->will($this->returnValue($this->initializer)); $this->initializer->expects($this->once())->method('Initialize'); $presenter = new EditReservationPresenter($this->page, $this->initializerFactory, $this->preconditionService, $this->reservationViewRepository); $presenter->PageLoad(); }
/** * @name GetReservation * @param string $referenceNumber * @description Loads a specific reservation by reference number * @response ReservationResponse * @return void */ public function GetReservation($referenceNumber) { Log::Debug('GetReservation called. $referenceNumber=%s', $referenceNumber); $reservation = $this->reservationViewRepository->GetReservationForEditing($referenceNumber); if (!empty($reservation->ReferenceNumber)) { $attributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESERVATION); $response = new ReservationResponse($this->server, $reservation, $this->privacyFilter, $attributes); $this->server->WriteResponse($response); } else { $this->server->WriteResponse($response = RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE); } }
public function PageLoad(UserSession $currentUser) { if (!$this->validator->IsValid()) { return; } $referenceNumber = $this->page->GetReferenceNumber(); $reservations = array(); if (!empty($referenceNumber)) { $res = $this->reservationViewRepository->GetReservationForEditing($referenceNumber); $reservations = array(new iCalendarReservationView($res, $currentUser, $this->privacyFilter)); } $this->page->SetReservations($reservations); }
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 testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingReservations() { $pageNumber = 1; $pageSize = 40; $groups = array(new UserGroup(1, '1'), new UserGroup(5, '5'), new UserGroup(9, '9'), new UserGroup(22, '22')); $myGroups = array(1, 5, 9, 22); $this->userRepository->expects($this->once())->method('LoadGroups')->with($this->equalTo($this->fakeUser->UserId), $this->equalTo(RoleLevel::RESOURCE_ADMIN))->will($this->returnValue($groups)); $filter = new ReservationFilter(); $expectedFilter = $filter->GetFilter(); $expectedFilter->_And(new SqlFilterIn(new SqlFilterColumn(TableNames::RESOURCES, ColumnNames::RESOURCE_ADMIN_GROUP_ID), $myGroups)); $data = new PageableData(); $this->reservationViewRepository->expects($this->once())->method('GetList')->with($pageNumber, $pageSize, null, null, $expectedFilter)->will($this->returnValue($data)); $actualData = $this->service->LoadFiltered($pageNumber, $pageSize, $filter, $this->fakeUser); $this->assertEquals($data, $actualData); }
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);*/ }
/** * @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)); }
/** * @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); }
public function testConflictHandlerReportsConflictingReservationAndDoesNotUpdateBlackout() { $userId = $this->fakeUser->UserId; $start = Date::Parse('2011-01-01 01:01:01'); $end = Date::Parse('2011-02-02 02:02:02'); $date = new DateRange($start, $end); $resourceId = 2; $resourceIds = array($resourceId); $title = 'title'; $seriesId = 111; $blackoutInstanceId = 10; $series = BlackoutSeries::Create(1, 'old title', new TestDateRange()); $series->WithId($seriesId); $user = $this->getMock('User'); $user->expects($this->any())->method('IsResourceAdminFor')->with($this->anything())->will($this->returnValue(true)); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->reservationViewRepository->expects($this->once())->method('GetBlackoutsWithin')->with($this->equalTo($date))->will($this->returnValue(array())); $reservation1 = new TestReservationItemView(1, $start, $end, 2); $reservation2 = new TestReservationItemView(2, $start, $end, 2); $this->reservationViewRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($start), $this->equalTo($end))->will($this->returnValue(array($reservation1, $reservation2))); $this->conflictHandler->expects($this->at(0))->method('Handle')->with($this->equalTo($reservation1))->will($this->returnValue(false)); $this->conflictHandler->expects($this->at(1))->method('Handle')->with($this->equalTo($reservation2))->will($this->returnValue(false)); $this->blackoutRepository->expects($this->never())->method('Update'); $this->blackoutRepository->expects($this->once())->method('LoadByBlackoutId')->with($this->equalTo($blackoutInstanceId))->will($this->returnValue($series)); $result = $this->service->Update($blackoutInstanceId, $date, $resourceIds, $title, $this->conflictHandler, new RepeatNone(), SeriesUpdateScope::FullSeries); $this->assertFalse($result->WasSuccessful()); }
/** * @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(); }
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() { $user = ServiceLocator::GetServer()->GetUserSession(); $referenceNumber = $this->page->GetReferenceNumber(); $reservationView = $this->reservationViewRepository->GetReservationForEditing($referenceNumber); $this->preconditionService->CheckAll($this->page, $user, $reservationView); $initializer = $this->initializationFactory->GetExistingInitializer($this->page, $reservationView); $initializer->Initialize(); }
public function testWhenReservationIsNotFound() { $reservation = NullReservationView::Instance(); $referenceNumber = '12323'; $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation)); $this->service->GetReservation($referenceNumber); $expectedResponse = RestResponse::NotFound(); $this->assertEquals($expectedResponse, $this->server->_LastResponse); }
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); }
public function testWhenViewingOpenInvites() { $startDate = Date::Now(); $endDate = $startDate->AddDays(30); $userId = $this->fakeUser->UserId; $inviteeLevel = ReservationUserLevel::INVITEE; $reservations[] = new ReservationItemView(); $reservations[] = new ReservationItemView(); $reservations[] = new ReservationItemView(); $this->reservationViewRepo->expects($this->once())->method('GetReservationList')->with($this->equalTo($startDate), $this->equalTo($endDate), $this->equalTo($userId), $this->equalTo($inviteeLevel))->will($this->returnValue($reservations)); $this->page->expects($this->once())->method('BindReservations')->with($this->equalTo($reservations)); $this->presenter->PageLoad(); }
public function testBindsDefaultScheduleByMonthWhenNothingSelected() { $showInaccessible = true; $this->fakeConfig->SetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, 'true'); $userId = $this->fakeUser->UserId; $defaultScheduleId = 10; $userTimezone = "America/New_York"; $calendarType = CalendarTypes::Month; $requestedDay = 4; $requestedMonth = 3; $requestedYear = 2011; $month = new CalendarMonth($requestedMonth, $requestedYear, $userTimezone); $startDate = Date::Parse('2011-01-01', 'UTC'); $endDate = Date::Parse('2011-01-02', 'UTC'); $summary = 'foo summary'; $resourceId = 3; $fname = 'fname'; $lname = 'lname'; $referenceNumber = 'refnum'; $resourceName = 'resource name'; //$res = new ScheduleReservation(1, $startDate, $endDate, null, $summary, $resourceId, $userId, $fname, $lname, $referenceNumber, ReservationStatus::Created); $res = new ReservationItemView($referenceNumber, $startDate, $endDate, 'resource name', $resourceId, 1, null, null, $summary, null, $fname, $lname, $userId); $r1 = new FakeBookableResource(1, 'dude1'); $r2 = new FakeBookableResource($resourceId, $resourceName); $reservations = array($res); $resources = array($r1, $r2); /** @var Schedule[] $schedules */ $schedules = array(new Schedule(1, null, false, 2, null), new Schedule($defaultScheduleId, null, true, 3, null)); $this->scheduleRepository->expects($this->atLeastOnce())->method('GetAll')->will($this->returnValue($schedules)); $this->resourceService->expects($this->atLeastOnce())->method('GetAllResources')->with($this->equalTo($showInaccessible), $this->equalTo($this->fakeUser))->will($this->returnValue($resources)); $this->resourceService->expects($this->atLeastOnce())->method('GetResourceGroups')->with($this->equalTo(null), $this->equalTo($this->fakeUser))->will($this->returnValue(new ResourceGroupTree())); $this->page->expects($this->atLeastOnce())->method('GetScheduleId')->will($this->returnValue(null)); $this->page->expects($this->atLeastOnce())->method('GetResourceId')->will($this->returnValue(null)); $this->repository->expects($this->atLeastOnce())->method('GetReservationList')->with($this->equalTo($month->FirstDay()), $this->equalTo($month->LastDay()->AddDays(1)), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($reservations)); $this->page->expects($this->atLeastOnce())->method('GetCalendarType')->will($this->returnValue($calendarType)); $this->page->expects($this->atLeastOnce())->method('GetDay')->will($this->returnValue($requestedDay)); $this->page->expects($this->atLeastOnce())->method('GetMonth')->will($this->returnValue($requestedMonth)); $this->page->expects($this->atLeastOnce())->method('GetYear')->will($this->returnValue($requestedYear)); $this->page->expects($this->atLeastOnce())->method('SetFirstDay')->with($this->equalTo($schedules[1]->GetWeekdayStart())); $this->calendarFactory->expects($this->atLeastOnce())->method('Create')->with($this->equalTo($calendarType), $this->equalTo($requestedYear), $this->equalTo($requestedMonth), $this->equalTo($requestedDay), $this->equalTo($userTimezone))->will($this->returnValue($month)); $this->page->expects($this->atLeastOnce())->method('BindCalendar')->with($this->equalTo($month)); $details = new CalendarSubscriptionDetails(true); $this->subscriptionService->expects($this->once())->method('ForSchedule')->with($this->equalTo($defaultScheduleId))->will($this->returnValue($details)); $this->page->expects($this->atLeastOnce())->method('BindSubscription')->with($this->equalTo($details)); $calendarFilters = new CalendarFilters($schedules, $resources, null, null, new ResourceGroupTree()); $this->page->expects($this->atLeastOnce())->method('BindFilters')->with($this->equalTo($calendarFilters)); $this->presenter->PageLoad($this->fakeUser, $userTimezone); $actualReservations = $month->Reservations(); $expectedReservations = CalendarReservation::FromScheduleReservationList($reservations, $resources, $this->fakeUser); $this->assertEquals($expectedReservations, $actualReservations); }
public function testNoConflictsButTooHigh() { $accessory1 = new ReservationAccessory(1, 5); $quantityAvailable = 4; $reservation = new TestReservationSeries(); $dr1 = new TestDateRange(); $reservation->WithDuration($dr1); $reservation->WithAccessory($accessory1); $this->accessoryRepository->expects($this->at(0))->method('LoadById')->with($accessory1->AccessoryId)->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); $this->reservationRepository->expects($this->once(0))->method('GetAccessoriesWithin')->with($this->anything())->will($this->returnValue(array())); $result = $this->rule->Validate($reservation); $this->assertFalse($result->IsValid()); $this->assertFalse(is_null($result->ErrorMessage())); }
public function testGetsUserReservationsForTheNextYearByResourceId() { $publicId = '1'; $reservationResult = array(new TestReservationItemView(1, Date::Now(), Date::Now())); $userId = 999; $user = new FakeUser($userId); $weekAgo = Date::Now()->AddDays(-7); $nextYear = Date::Now()->AddDays(365); $this->page->expects($this->once())->method('GetUserId')->will($this->returnValue($publicId)); $this->service->expects($this->once())->method('GetUser')->with($this->equalTo($publicId))->will($this->returnValue($user)); $this->repo->expects($this->once())->method('GetReservationList')->with($this->equalTo($weekAgo), $this->equalTo($nextYear), $this->equalTo($userId), $this->isNull(), $this->isNull(), $this->isNull())->will($this->returnValue($reservationResult)); $this->page->expects($this->once())->method('SetReservations')->with($this->arrayHasKey(0)); $this->presenter->PageLoad(); }
/** * @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)); }
public function testGroupsReservations() { $now = Date::Parse('2011-03-24'); // thursday Date::_SetNow($now); $today = new ReservationItemView('1', $now, $now); $tomorrow = new ReservationItemView('2', $now->AddDays(1), $now->AddDays(1)); // friday $thisWeek = new ReservationItemView('3', $now->AddDays(2), $now->AddDays(2)); // saturday $nextWeek = new ReservationItemView('3', $now->AddDays(3), $now->AddDays(3)); // sunday of next week $reservations[] = $today; $reservations[] = $tomorrow; $reservations[] = $thisWeek; $reservations[] = $nextWeek; $this->repository->expects($this->once())->method('GetReservationList')->with($this->anything(), $this->anything(), $this->anything())->will($this->returnValue($reservations)); $this->control->expects($this->once())->method('BindToday')->with($this->equalTo(array($today))); $this->control->expects($this->once())->method('BindTomorrow')->with($this->equalTo(array($tomorrow))); $this->control->expects($this->once())->method('BindThisWeek')->with($this->equalTo(array($thisWeek))); $this->control->expects($this->once())->method('BindNextWeek')->with($this->equalTo(array($nextWeek))); $presenter = new UpcomingReservationsPresenter($this->control, $this->repository); $presenter->PageLoad(); }
/** * @param BlackoutSeries $blackoutSeries * @return array|BlackoutItemView[] */ private function GetConflictingBlackouts($blackoutSeries) { $conflictingBlackouts = array(); $blackouts = $blackoutSeries->AllBlackouts(); foreach ($blackouts as $blackout) { $existingBlackouts = $this->reservationViewRepository->GetBlackoutsWithin($blackout->Date()); foreach ($existingBlackouts as $existingBlackout) { if ($existingBlackout->SeriesId == $blackoutSeries->Id()) { continue; } if ($blackoutSeries->ContainsResource($existingBlackout->ResourceId) && $blackout->Date()->Overlaps($existingBlackout->Date)) { $conflictingBlackouts[] = $existingBlackout; } } } return $conflictingBlackouts; }
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 testNoConflictsIfReservationExistsAtSameTimeForDifferentResource() { $resourceId1 = 1; $resourceId2 = 2; $resourceId3 = 3; $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($resourceId1)); $series->WithResource(new FakeBookableResource($resourceId2)); $series->WithCurrentInstance($current); $reservations = array(new TestReservationItemView($currentId + 1, Date::Now(), Date::Now(), $resourceId3)); $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->assertTrue($ruleResult->IsValid()); }