public function Bind(IReservationComponentInitializer $initializer) { $timezone = $initializer->GetTimezone(); $reservationDate = $initializer->GetReservationDate(); $requestedEndDate = $initializer->GetEndDate(); $requestedStartDate = $initializer->GetStartDate(); $requestedScheduleId = $initializer->GetScheduleId(); $requestedDate = $reservationDate == null ? Date::Now()->ToTimezone($timezone) : $reservationDate->ToTimezone($timezone); $startDate = $requestedStartDate == null ? $requestedDate : $requestedStartDate->ToTimezone($timezone); $endDate = $requestedEndDate == null ? $requestedDate : $requestedEndDate->ToTimezone($timezone); if ($initializer->IsNew()) { $resource = $initializer->PrimaryResource(); if ($resource->GetMinimumLength() != null && !$resource->GetMinimumLength()->Interval()->IsNull()) { $endDate = $startDate->ApplyDifference($resource->GetMinimumLength()->Interval()); } } $layout = $this->scheduleRepository->GetLayout($requestedScheduleId, new ReservationLayoutFactory($timezone)); $startPeriods = $layout->GetLayout($startDate); if (count($startPeriods) > 1 && $startPeriods[0]->Begin()->Compare($startPeriods[1]->Begin()) > 0) { $period = array_shift($startPeriods); $startPeriods[] = $period; } $endPeriods = $layout->GetLayout($endDate); $initializer->SetDates($startDate, $endDate, $startPeriods, $endPeriods); $hideRecurrence = !$initializer->CurrentUser()->IsAdmin && Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_PREVENT_RECURRENCE, new BooleanConverter()); $initializer->HideRecurrence($hideRecurrence); }
public function PageLoad() { $this->page->BindResources($this->resourceRepo->GetResourceList()); $this->page->BindAccessories($this->resourceRepo->GetAccessoryList()); $this->page->BindSchedules($this->scheduleRepo->GetAll()); $this->page->BindGroups($this->groupRepo->GetList()->Results()); }
public function testWhenScheduleNotFound() { $scheduleId = 89181; $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($scheduleId))->will($this->returnValue(null)); $this->service->GetSchedule($scheduleId); $this->assertEquals(RestResponse::NotFound(), $this->server->_LastResponse); }
public function testGetsScheduleByPublicId() { $expected = new FakeSchedule(); $publicId = uniqid(); $this->scheduleRepo->expects($this->once())->method('LoadByPublicId')->with($this->equalTo($publicId))->will($this->returnValue($expected)); $actual = $this->service->GetSchedule($publicId); $this->assertEquals($expected, $actual); }
/** * @name GetSchedule * @description Loads a specific schedule by id * @response ScheduleResponse * @param $scheduleId * @return void */ public function GetSchedule($scheduleId) { $schedule = $this->scheduleRepository->LoadById($scheduleId); if ($schedule != null) { $layout = $this->scheduleRepository->GetLayout($schedule->GetId(), new ScheduleLayoutFactory($this->server->GetSession()->Timezone)); $this->server->WriteResponse(new ScheduleResponse($this->server, $schedule, $layout)); } else { $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE); } }
public function Validate($reservationSeries) { foreach ($reservationSeries->AllResources() as $resource) { if (!$resource->GetAllowMultiday()) { $schedule = $this->scheduleRepository->LoadById($reservationSeries->ScheduleId()); $tz = $schedule->GetTimezone(); $isSameDay = $reservationSeries->CurrentInstance()->StartDate()->ToTimezone($tz)->DateEquals($reservationSeries->CurrentInstance()->EndDate()->ToTimezone($tz)); return new ReservationRuleResult($isSameDay, Resources::GetInstance()->GetString('MultiDayRule', $resource->GetName())); } } return new ReservationRuleResult(); }
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); }
/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $quotas = $this->quotaRepository->LoadAll(); $user = $this->userRepository->LoadById($reservationSeries->UserId()); $schedule = $this->scheduleRepository->LoadById($reservationSeries->ScheduleId()); foreach ($quotas as $quota) { if ($quota->ExceedsQuota($reservationSeries, $user, $schedule, $this->reservationViewRepository)) { Log::Debug('Quota exceeded. %s', $quota->ToString()); return new ReservationRuleResult(false, Resources::GetInstance()->GetString('QuotaExceeded')); } } return new ReservationRuleResult(); }
public function testSucceedsWhenStartAndEndTimeMatchPeriods() { $date = Date::Now(); $dates = new DateRange($date, $date); $scheduleId = 1232; $resource = new FakeBookableResource(1); $resource->SetScheduleId($scheduleId); $series = ReservationSeries::Create(1, $resource, null, null, $dates, new RepeatNone(), $this->fakeUser); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)))->will($this->returnValue($this->layout)); $period = new SchedulePeriod($date, $date); $this->layout->expects($this->at(0))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->StartDate()))->will($this->returnValue($period)); $this->layout->expects($this->at(1))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->EndDate()))->will($this->returnValue($period)); $result = $this->rule->Validate($series); $this->assertTrue($result->IsValid()); }
public function testWhenInitializing() { $groups = array(); $bookableResources = array(); $schedules = array(); $groupResult = new PageableData($groups); $quotaList = array(); $this->resourceRepository->expects($this->once())->method('GetResourceList')->will($this->returnValue($bookableResources)); $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($bookableResources)); $this->groupRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupResult)); $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups)); $this->scheduleRepository->expects($this->once())->method('GetAll')->will($this->returnValue($schedules)); $this->page->expects($this->once())->method('BindSchedules')->with($this->equalTo($schedules)); $this->quotaRepository->expects($this->once())->method('GetAll')->will($this->returnValue($quotaList)); $this->presenter->PageLoad(); }
public function testFirstQuotaExceeded() { $scheduleId = 971243; $timezone = 'America/New_York'; $userId = 10; $groupId1 = 8287; $groupId2 = 102; $user = new FakeUser(); $user->SetGroups(array($groupId1, $groupId2)); $schedule = new Schedule(1, null, null, null, null, $timezone); $resource = new FakeBookableResource(20); $resource->SetScheduleId($scheduleId); $series = ReservationSeries::Create($userId, $resource, null, null, new TestDateRange(), new RepeatNone(), new FakeUserSession()); $series->AddResource(new FakeBookableResource(22)); $quota1 = $this->mockQuota('IQuota'); $quota2 = $this->mockQuota('IQuota'); $quotas = array($quota1, $quota2); $this->quotaRepository->expects($this->once())->method('LoadAll')->will($this->returnValue($quotas)); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($scheduleId))->will($this->returnValue($schedule)); $this->ChecksAgainstQuota($quota1, $series, $this->reservationViewRepository, $schedule, $user, true); $quota2->expects($this->never())->method('ExceedsQuota'); $rule = new QuotaRule($this->quotaRepository, $this->reservationViewRepository, $this->userRepository, $this->scheduleRepository); $result = $rule->Validate($series); $this->assertFalse($result->IsValid(), 'first quotas was exceeded'); }
/** * @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 testRuleIsInValidIfReservationCrossesDayInScheduleTimezone() { $start = Date::Now(); $end = Date::Now()->AddDays(1); $reservation = new TestReservationSeries(); $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end))); $resource = new FakeBookableResource(1); $resource->SetAllowMultiday(true); $resource2 = new FakeBookableResource(2); $resource2->SetAllowMultiday(false); $reservation->WithResource($resource); $reservation->AddResource($resource2); $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($reservation->ScheduleId()))->will($this->returnValue($this->schedule)); $rule = new ResourceCrossDayRule($this->scheduleRepository); $result = $rule->Validate($reservation); $this->assertFalse($result->IsValid()); }
public function GetScheduleId() { if (!empty($this->scheduleId)) { return $this->scheduleId; } $this->scheduleId = $this->page->GetRequestedScheduleId(); if (empty($this->scheduleId)) { $schedules = $this->scheduleRepository->GetAll(); foreach ($schedules as $s) { if ($s->GetIsDefault()) { $this->scheduleId = $s->GetId(); break; } } } return $this->scheduleId; }
/** * @param ReservationSeries $reservationSeries * @return ReservationRuleResult */ public function Validate($reservationSeries) { $layout = $this->repository->GetLayout($reservationSeries->Resource()->GetScheduleId(), new ScheduleLayoutFactory($this->session->Timezone)); $startDate = $reservationSeries->CurrentInstance()->StartDate(); $startPeriod = $layout->GetPeriod($startDate); $endDate = $reservationSeries->CurrentInstance()->EndDate(); $endPeriod = $layout->GetPeriod($endDate); $errors = new StringBuilder(); if ($startPeriod == null || !$startPeriod->IsReservable() || !$startPeriod->BeginDate()->Equals($startDate)) { $errors->AppendLine(Resources::GetInstance()->GetString('InvalidStartSlot')); } if ($endPeriod == null || !$endPeriod->BeginDate()->Equals($endDate)) { $errors->AppendLine(Resources::GetInstance()->GetString('InvalidEndSlot')); } $errorMessage = $errors->ToString(); return new ReservationRuleResult(strlen($errorMessage) == 0, $errorMessage); }
public function PageLoad($userTimezone) { $session = ServiceLocator::GetServer()->GetUserSession(); $this->page->BindSchedules($this->scheduleRepository->GetAll()); $this->page->BindResources($this->resourceRepository->GetResourceList()); $startDateString = $this->page->GetStartDate(); $endDateString = $this->page->GetEndDate(); $startDate = $this->GetDate($startDateString, $userTimezone, -7); $endDate = $this->GetDate($endDateString, $userTimezone, 7); $scheduleId = $this->page->GetScheduleId(); $resourceId = $this->page->GetResourceId(); $this->page->SetStartDate($startDate); $this->page->SetEndDate($endDate); $this->page->SetScheduleId($scheduleId); $this->page->SetResourceId($resourceId); $filter = new BlackoutFilter($startDate, $endDate, $scheduleId, $resourceId); $blackouts = $this->manageBlackoutsService->LoadFiltered($this->page->GetPageNumber(), $this->page->GetPageSize(), $filter, $session); $this->page->BindBlackouts($blackouts->Results()); $this->page->BindPageInfo($blackouts->PageInfo()); $this->page->ShowPage(); }
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 GetScheduleId() { if (!empty($this->scheduleId)) { return $this->scheduleId; } $this->scheduleId = $this->page->GetRequestedScheduleId(); if (empty($this->scheduleId)) { $requestedResourceId = $this->page->GetRequestedResourceId(); if (!empty($requestedResourceId)) { $resource = $this->resourceRepository->LoadById($requestedResourceId); $this->scheduleId = $resource->GetScheduleId(); } else { $schedules = $this->scheduleRepository->GetAll(); foreach ($schedules as $s) { if ($s->GetIsDefault()) { $this->scheduleId = $s->GetId(); break; } } } } return $this->scheduleId; }
public function testWhenPeriodStartTimeIsInPast() { $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::CURRENT); $scheduleId = 123; $now = Date::Parse('2011-04-04 12:13:15', 'UTC'); Date::_SetNow($now); $start = $now->AddDays(-5); $end = $now->AddDays(5); $periodStart = Date::Parse('2011-04-04 12:13:14', 'UTC'); $periodEnd = Date::Parse('2011-04-04 12:13:16', 'UTC'); $reservation = new TestReservationSeries(); $reservation->WithScheduleId($scheduleId); $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end))); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory('UTC')))->will($this->returnValue($this->layout)); $period = new SchedulePeriod($periodStart, $periodEnd); $this->layout->expects($this->once())->method('GetPeriod')->with($this->equalTo($end))->will($this->returnValue($period)); $rule = new ReservationStartTimeRule($this->scheduleRepository); $result = $rule->Validate($reservation); $this->assertFalse($result->IsValid()); }
public function testBindsEmptyCalendarToPageWhenNoReservationsAreFound() { $userId = 10; $this->fakeUser->UserId = $userId; $userTimezone = "America/New_York"; $calendarType = CalendarTypes::Month; $requestedDay = 4; $requestedMonth = 3; $requestedYear = 2011; $month = new CalendarMonth($requestedMonth, $requestedYear, $userTimezone); $reservations = array(); $showInaccessible = true; $this->fakeConfig->SetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, 'true'); $resourceId = 1; $resourceName = 'rn'; $defaultScheduleId = 12; $r1 = new FakeBookableResource(1, 'dude1'); $r2 = new FakeBookableResource($resourceId, $resourceName); $resources = array($r1, $r2); $resourceGroupTree = new ResourceGroupTree(); $schedules = array(new Schedule(1, null, false, 2, null), new Schedule($defaultScheduleId, null, true, 3, null)); $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->once())->method('GetReservationList')->with($this->equalTo($month->FirstDay()), $this->equalTo($month->LastDay()->AddDays(1)), $this->equalTo($userId), $this->equalTo(ReservationUserLevel::ALL), $this->isNull(), $this->isNull())->will($this->returnValue($reservations)); $this->page->expects($this->once())->method('GetCalendarType')->will($this->returnValue($calendarType)); $this->page->expects($this->once())->method('GetDay')->will($this->returnValue($requestedDay)); $this->page->expects($this->once())->method('GetMonth')->will($this->returnValue($requestedMonth)); $this->page->expects($this->once())->method('GetYear')->will($this->returnValue($requestedYear)); $this->calendarFactory->expects($this->once())->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->once())->method('BindCalendar')->with($this->equalTo($month)); $details = new CalendarSubscriptionDetails(true); $this->subscriptionService->expects($this->once())->method('ForUser')->with($this->equalTo($userId))->will($this->returnValue($details)); $this->page->expects($this->once())->method('BindSubscription')->with($this->equalTo($details)); $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->anything(), $this->equalTo($this->fakeUser))->will($this->returnValue($resourceGroupTree)); $this->page->expects($this->atLeastOnce())->method('SetFirstDay')->with($this->equalTo($schedules[1]->GetWeekdayStart())); $calendarFilters = new CalendarFilters($schedules, $resources, null, null, $resourceGroupTree); $this->page->expects($this->atLeastOnce())->method('BindFilters')->with($this->equalTo($calendarFilters)); $this->presenter->PageLoad($this->fakeUser, $userTimezone); }
public function PageLoad() { $resourceAttributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESOURCE); $filterValues = $this->page->GetFilterValues(); $results = $this->resourceRepository->GetList($this->page->GetPageNumber(), $this->page->GetPageSize(), null, null, $filterValues->AsFilter($resourceAttributes)); $resources = $results->Results(); $this->page->BindResources($resources); $this->page->BindPageInfo($results->PageInfo()); $schedules = $this->scheduleRepository->GetAll(); $scheduleList = array(); /* @var $schedule Schedule */ foreach ($schedules as $schedule) { $scheduleList[$schedule->GetId()] = $schedule->GetName(); } $this->page->BindSchedules($scheduleList); $this->page->AllSchedules($schedules); $resourceTypes = $this->resourceRepository->GetResourceTypes(); $resourceTypeList = array(); /* @var $resourceType ResourceType */ foreach ($resourceTypes as $resourceType) { $resourceTypeList[$resourceType->Id()] = $resourceType; } $this->page->BindResourceTypes($resourceTypeList); $statusReasons = $this->resourceRepository->GetStatusReasons(); $statusReasonList = array(); foreach ($statusReasons as $reason) { $statusReasonList[$reason->Id()] = $reason; } $this->page->BindResourceStatusReasons($statusReasonList); $groups = $this->groupRepository->GetGroupsByRole(RoleLevel::RESOURCE_ADMIN); $this->page->BindAdminGroups($groups); $resourceIds = array(); foreach ($resources as $resource) { $resourceIds[] = $resource->GetId(); } $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE, $resourceIds); $this->page->BindAttributeList($attributeList); $this->InitializeFilter($filterValues, $resourceAttributes); }
public function testMovesFirstPeriodToEndIfTimeIsLaterInTheDay() { $timezone = 'UTC'; $scheduleId = 1; $dateString = Date::Now()->AddDays(1)->SetTimeString('02:55:22')->Format('Y-m-d H:i:s'); $dateInUserTimezone = Date::Parse($dateString, $timezone); $requestedDate = Date::Parse($dateString, $timezone); $this->initializer->expects($this->any())->method('CurrentUser')->will($this->returnValue($this->fakeUser)); $this->initializer->expects($this->any())->method('GetTimezone')->will($this->returnValue($timezone)); $this->initializer->expects($this->any())->method('GetReservationDate')->will($this->returnValue($dateInUserTimezone)); $this->initializer->expects($this->any())->method('GetStartDate')->will($this->returnValue($requestedDate)); $this->initializer->expects($this->any())->method('GetEndDate')->will($this->returnValue($requestedDate)); $this->initializer->expects($this->any())->method('GetScheduleId')->will($this->returnValue($scheduleId)); $periods = array(new SchedulePeriod(Date::Parse('2012-01-22 22:00', $timezone), Date::Parse('2012-01-22 10:00', $timezone)), new SchedulePeriod(Date::Parse('2012-01-22 10:00', $timezone), Date::Parse('2012-01-23 22:00', $timezone))); $startPeriods = array($periods[1], $periods[0]); $layout = $this->getMock('IScheduleLayout'); $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ReservationLayoutFactory($timezone)))->will($this->returnValue($layout)); $layout->expects($this->any())->method('GetLayout')->with($this->equalTo($requestedDate))->will($this->returnValue($periods)); $this->initializer->expects($this->once())->method('SetDates')->with($this->equalTo($requestedDate), $this->equalTo($requestedDate), $this->equalTo($startPeriods), $this->equalTo($periods)); $binder = new ReservationDateBinder($this->scheduleRepository); $binder->Bind($this->initializer); }
/** * @param int $pageNumber * @param int $pageSize * @return PageableData|BookableResource[] */ public function GetList($pageNumber, $pageSize) { return $this->scheduleRepository->GetList($pageNumber, $pageSize); }
/** * @param int $scheduleId * @param int $adminGroupId */ public function ChangeAdminGroup($scheduleId, $adminGroupId) { $schedule = $this->scheduleRepository->LoadById($scheduleId); $schedule->SetAdminGroupId($adminGroupId); $this->scheduleRepository->Update($schedule); }
public function GetLayout($scheduleId, ILayoutFactory $layoutFactory) { return $this->scheduleRepository->GetLayout($scheduleId, $layoutFactory); }
public function GetSourceSchedules() { return $this->scheduleRepo->GetAll(); }
public function PageLoad($userTimezone) { $session = ServiceLocator::GetServer()->GetUserSession(); $this->page->BindSchedules($this->scheduleRepository->GetAll()); $this->page->BindResources($this->resourceRepository->GetResourceList()); $statusReasonList = array(); foreach ($this->resourceRepository->GetStatusReasons() as $reason) { $statusReasonList[$reason->Id()] = $reason; } $this->page->BindResourceStatuses($statusReasonList); $startDateString = $this->page->GetStartDate(); $endDateString = $this->page->GetEndDate(); $filterPreferences = new ReservationFilterPreferences(); $filterPreferences->Load($this->userPreferenceRepository, $session->UserId); $startDate = $this->GetDate($startDateString, $userTimezone, $filterPreferences->GetFilterStartDateDelta()); $endDate = $this->GetDate($endDateString, $userTimezone, $filterPreferences->GetFilterEndDateDelta()); $scheduleId = $this->page->GetScheduleId(); $resourceId = $this->page->GetResourceId(); $userId = $this->page->GetUserId(); $userName = $this->page->GetUserName(); $reservationStatusId = $this->page->GetReservationStatusId(); $referenceNumber = $this->page->GetReferenceNumber(); $resourceStatusId = $this->page->GetResourceStatusFilterId(); $resourceReasonId = $this->page->GetResourceStatusReasonFilterId(); if (!$this->page->FilterButtonPressed()) { // Get filter settings from db $referenceNumber = $filterPreferences->GetFilterReferenceNumber(); $scheduleId = $filterPreferences->GetFilterScheduleId(); $resourceId = $filterPreferences->GetFilterResourceId(); $userId = $filterPreferences->GetFilterUserId(); $userName = $filterPreferences->GetFilterUserName(); $reservationStatusId = $filterPreferences->GetFilterReservationStatusId(); $resourceStatusId = $filterPreferences->GetFilterResourceStatusId(); $resourceReasonId = $filterPreferences->GetFilterResourceReasonId(); $filters = $filterPreferences->GetFilterCustomAttributes(); } else { $startOffset = $this->GetDateOffsetFromToday($startDate, $userTimezone); $endOffset = $this->GetDateOffsetFromToday($endDate, $userTimezone); $formFilters = $this->page->GetAttributeFilters(); $filters = array(); foreach ($formFilters as $filter) { $filters[$filter->Id] = $filter->Value; } $filterPreferences->SetFilterStartDateDelta($startOffset == null ? -14 : $startOffset); $filterPreferences->SetFilterEndDateDelta($endOffset == null ? 14 : $endOffset); $filterPreferences->SetFilterReferenceNumber($referenceNumber); $filterPreferences->SetFilterScheduleId($scheduleId); $filterPreferences->SetFilterResourceId($resourceId); $filterPreferences->SetFilterUserId($userId); $filterPreferences->SetFilterUserName($userName); $filterPreferences->SetFilterReservationStatusId($reservationStatusId); $filterPreferences->SetFilterResourceStatusId($resourceStatusId); $filterPreferences->SetFilterResourceReasonId($resourceReasonId); $filterPreferences->SetFilterCustomAttributes($filters); $filterPreferences->Update($this->userPreferenceRepository, $session->UserId); } $reservationAttributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESERVATION); $attributeFilters = array(); foreach ($reservationAttributes as $attribute) { $attributeValue = null; if (array_key_exists($attribute->Id(), $filters)) { $attributeValue = $filters[$attribute->Id()]; } $attributeFilters[] = new Attribute($attribute, $attributeValue); } $this->page->SetStartDate($startDate); $this->page->SetEndDate($endDate); $this->page->SetReferenceNumber($referenceNumber); $this->page->SetScheduleId($scheduleId); $this->page->SetResourceId($resourceId); $this->page->SetUserId($userId); $this->page->SetUserName($userName); $this->page->SetReservationStatusId($reservationStatusId); $this->page->SetResourceStatusFilterId($resourceStatusId); $this->page->SetResourceStatusReasonFilterId($resourceReasonId); $this->page->SetAttributeFilters($attributeFilters); $this->page->SetReservationAttributes($reservationAttributes); $filter = new ReservationFilter($startDate, $endDate, $referenceNumber, $scheduleId, $resourceId, $userId, $reservationStatusId, $resourceStatusId, $resourceReasonId, $attributeFilters); $reservations = $this->manageReservationsService->LoadFiltered($this->page->GetPageNumber(), $this->page->GetPageSize(), $filter, $session); /** @var ReservationItemView[] $reservationList */ $reservationList = $reservations->Results(); $this->page->BindReservations($reservationList); $this->page->BindPageInfo($reservations->PageInfo()); $seriesIds = array(); /** @var $reservationItemView ReservationItemView */ foreach ($reservationList as $reservationItemView) { $seriesIds[] = $reservationItemView->SeriesId; } if ($this->page->GetFormat() == 'csv') { $this->page->ShowCsv(); } else { $this->page->ShowPage(); } }
/** * @param int $scheduleId * @return CalendarSubscriptionDetails */ public function ForSchedule($scheduleId) { $schedule = $this->scheduleRepository->LoadById($scheduleId); return new CalendarSubscriptionDetails($schedule->GetIsCalendarSubscriptionAllowed(), new CalendarSubscriptionUrl(null, $schedule->GetPublicId(), null)); }