public function testPageLoadBindsAllSchedulesAndProperResourcesWhenNotPostingBack() { $user = $this->fakeServer->GetUserSession(); $resources = array(); $reservations = $this->getMock('IReservationListing'); $layout = $this->getMock('IScheduleLayout'); $bindingDates = new DateRange(Date::Now(), Date::Now()); $groups = new ResourceGroupTree(); $resourceTypes = array(new ResourceType(1, 'n', 'd')); $resourceAttributes = array(new FakeCustomAttribute()); $resourceTypeAttributes = array(new FakeCustomAttribute()); $page = $this->getMock('ISchedulePage'); $scheduleService = $this->getMock('IScheduleService'); $resourceService = $this->getMock('IResourceService'); $pageBuilder = $this->getMock('ISchedulePageBuilder'); $reservationService = $this->getMock('IReservationService'); $dailyLayoutFactory = $this->getMock('IDailyLayoutFactory'); $dailyLayout = $this->getMock('IDailyLayout'); $presenter = new SchedulePresenter($page, $scheduleService, $resourceService, $pageBuilder, $reservationService, $dailyLayoutFactory); $page->expects($this->once())->method('ShowInaccessibleResources')->will($this->returnValue($this->showInaccessibleResources)); $page->expects($this->once())->method('GetDisplayTimezone')->will($this->returnValue($user->Timezone)); $scheduleService->expects($this->once())->method('GetAll')->with($this->equalTo($this->showInaccessibleResources), $this->equalTo($this->fakeUser))->will($this->returnValue($this->schedules)); $scheduleService->expects($this->once())->method('GetLayout')->with($this->equalTo($this->scheduleId), $this->equalTo(new ScheduleLayoutFactory($user->Timezone)))->will($this->returnValue($layout)); $pageBuilder->expects($this->once())->method('GetCurrentSchedule')->with($this->equalTo($page), $this->equalTo($this->schedules), $this->equalTo($user))->will($this->returnValue($this->currentSchedule)); $pageBuilder->expects($this->once())->method('BindSchedules')->with($this->equalTo($page), $this->equalTo($this->schedules), $this->equalTo($this->currentSchedule)); $resourceFilter = new ScheduleResourceFilter(); $pageBuilder->expects($this->once())->method('GetResourceFilter')->with($this->equalTo($this->scheduleId), $this->equalTo($page))->will($this->returnValue($resourceFilter)); $pageBuilder->expects($this->once())->method('BindResourceFilter')->with($this->equalTo($page), $this->equalTo($resourceFilter), $this->equalTo($resourceAttributes), $this->equalTo($resourceTypeAttributes)); $resourceService->expects($this->once())->method('GetScheduleResources')->with($this->equalTo($this->scheduleId), $this->equalTo($this->showInaccessibleResources), $this->equalTo($user), $this->equalTo($resourceFilter))->will($this->returnValue($resources)); $resourceService->expects($this->once())->method('GetResourceGroups')->with($this->equalTo($this->scheduleId))->will($this->returnValue($groups)); $pageBuilder->expects($this->once())->method('BindResourceGroups')->with($this->equalTo($page), $this->equalTo($groups)); $pageBuilder->expects($this->once())->method('GetScheduleDates')->with($this->equalTo($user), $this->equalTo($this->currentSchedule), $this->equalTo($page))->will($this->returnValue($bindingDates)); $pageBuilder->expects($this->once())->method('BindDisplayDates')->with($this->equalTo($page), $this->equalTo($bindingDates), $this->equalTo($this->schedules[0])); $reservationService->expects($this->once())->method('GetReservations')->with($this->equalTo($bindingDates), $this->equalTo($this->scheduleId), $this->equalTo($user->Timezone))->will($this->returnValue($reservations)); $dailyLayoutFactory->expects($this->once())->method('Create')->with($this->equalTo($reservations), $this->equalTo($layout))->will($this->returnValue($dailyLayout)); $pageBuilder->expects($this->once())->method('BindReservations')->with($this->equalTo($page), $this->equalTo($resources), $this->equalTo($dailyLayout)); $resourceService->expects($this->once())->method('GetResourceTypes')->will($this->returnValue($resourceTypes)); $pageBuilder->expects($this->once())->method('BindResourceTypes')->with($this->equalTo($page), $this->equalTo($resourceTypes)); $resourceService->expects($this->once())->method('GetResourceAttributes')->will($this->returnValue($resourceAttributes)); $resourceService->expects($this->once())->method('GetResourceTypeAttributes')->will($this->returnValue($resourceTypeAttributes)); $presenter->PageLoad($this->fakeUser); }
/** * @name GetSlots * @description Loads slots for a specific schedule * Optional query string parameters: resourceId, startDateTime, endDateTime. * If no dates are provided the default schedule dates will be returned. * If dates do not include the timezone offset, the timezone of the authenticated user will be assumed. * @response ScheduleSlotsResponse * @param $scheduleId * @return void */ public function GetSlots($scheduleId) { $startDate = $this->GetDate(WebServiceQueryStringKeys::START_DATE_TIME); $endDate = $this->GetDate(WebServiceQueryStringKeys::END_DATE_TIME); $resourceId = $this->server->GetQueryString(WebServiceQueryStringKeys::RESOURCE_ID); $scheduleWebServiceView = new ScheduleWebServiceView($scheduleId, $startDate); $permissionServiceFactory = new PermissionServiceFactory(); $scheduleRepository = new ScheduleRepository(); $userRepository = new UserRepository(); $resourceService = new ResourceService(new ResourceRepository(), $permissionServiceFactory->GetPermissionService(), new AttributeService(new AttributeRepository()), $userRepository); $builder = new ScheduleWebServicePageBuilder($startDate, $endDate, $resourceId); $reservationService = new ReservationService(new ReservationViewRepository(), new ReservationListingFactory()); $dailyLayoutFactory = new DailyLayoutFactory(); $scheduleService = new ScheduleService($scheduleRepository, $resourceService); $presenter = new SchedulePresenter($scheduleWebServiceView, $scheduleService, $resourceService, $builder, $reservationService, $dailyLayoutFactory); $presenter->PageLoad($this->server->GetSession()); $layout = $scheduleWebServiceView->GetDailyLayout(); $isError = $scheduleWebServiceView->IsPermissionError(); $dates = $scheduleWebServiceView->GetDates(); $resources = $scheduleWebServiceView->GetResources(); if ($isError) { $this->server->WriteResponse(RestResponse::Unauthorized(), RestResponse::UNAUTHORIZED_CODE); } else { $response = new ScheduleSlotsResponse($this->server, $scheduleId, $layout, $dates, $resources, $this->privacyFilter); $this->server->WriteResponse($response); } }
public function ProcessPageLoad() { $start = microtime(true); $user = ServiceLocator::GetServer()->GetUserSession(); $this->_presenter->PageLoad($user); $endLoad = microtime(true); if ($user->IsAdmin && $this->resourceCount == 0 && !$this->_isFiltered) { $this->Set('ShowResourceWarning', true); } $this->Set('SlotLabelFactory', $user->IsAdmin ? new AdminSlotLabelFactory() : new SlotLabelFactory($user)); $this->Set('DisplaySlotFactory', new DisplaySlotFactory()); if (array_key_exists($this->ScheduleStyle, $this->_styles)) { $this->Display($this->_styles[$this->ScheduleStyle]); } else { $this->Display('Schedule/schedule.tpl'); } $endDisplay = microtime(true); $load = $endLoad - $start; $display = $endDisplay - $endLoad; $total = $endDisplay - $start; Log::Debug('Schedule took %s sec to load, %s sec to render. Total %s sec', $load, $display, $total); }