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 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 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 PageLoad(UserSession $user) { $showInaccessibleResources = $this->_page->ShowInaccessibleResources(); $schedules = $this->_scheduleService->GetAll($showInaccessibleResources, $user); if (count($schedules) == 0) { $this->_page->ShowPermissionError(true); return; } $this->_page->ShowPermissionError(false); $currentSchedule = $this->_builder->GetCurrentSchedule($this->_page, $schedules, $user); $targetTimezone = $this->_page->GetDisplayTimezone($user, $currentSchedule); $activeScheduleId = $currentSchedule->GetId(); $this->_builder->BindSchedules($this->_page, $schedules, $currentSchedule); $scheduleDates = $this->_builder->GetScheduleDates($user, $currentSchedule, $this->_page); $this->_builder->BindDisplayDates($this->_page, $scheduleDates, $currentSchedule); $resourceGroups = $this->_resourceService->GetResourceGroups($activeScheduleId, $user); $this->_builder->BindResourceGroups($this->_page, $resourceGroups); $resourceTypes = $this->_resourceService->GetResourceTypes(); $this->_builder->BindResourceTypes($this->_page, $resourceTypes); $resourceAttributes = $this->_resourceService->GetResourceAttributes(); $resourceTypeAttributes = $this->_resourceService->GetResourceTypeAttributes(); $layout = $this->_scheduleService->GetLayout($activeScheduleId, new ScheduleLayoutFactory($targetTimezone)); $reservationListing = $this->_reservationService->GetReservations($scheduleDates, $activeScheduleId, $targetTimezone); $dailyLayout = $this->_dailyLayoutFactory->Create($reservationListing, $layout); $filter = $this->_builder->GetResourceFilter($activeScheduleId, $this->_page); $this->_builder->BindResourceFilter($this->_page, $filter, $resourceAttributes, $resourceTypeAttributes); $resources = $this->_resourceService->GetScheduleResources($activeScheduleId, $showInaccessibleResources, $user, $filter); $this->_builder->BindReservations($this->_page, $resources, $dailyLayout); }
public function GetAll($includeInaccessible = true, UserSession $session = null) { $schedules = $this->scheduleRepository->GetAll(); if ($includeInaccessible == false) { $resources = $this->resourceService->GetAllResources($includeInaccessible, $session); $availableSchedules = array(); if (count($resources) > 0) { foreach ($schedules as $schedule) { foreach ($resources as $resource) { if ($resource->ScheduleId == $schedule->GetId()) { $availableSchedules[] = $schedule; break; } } } } return $availableSchedules; } else { return $schedules; } }
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 testRedirectsIfUserHasPermissionToZeroResources() { $requestedScheduleId = 10; $requestedResourceId = null; $this->initializer->expects($this->once())->method('GetScheduleId')->will($this->returnValue($requestedScheduleId)); $this->initializer->expects($this->once())->method('GetResourceId')->will($this->returnValue($requestedResourceId)); $this->initializer->expects($this->once())->method('CurrentUser')->will($this->returnValue($this->fakeUser)); $resourceList = array(); $groups = new FakeResourceGroupTree(); $groups->WithAllResources($resourceList); $this->resourceService->expects($this->once())->method('GetResourceGroups')->with($this->equalTo($requestedScheduleId), $this->equalTo($this->fakeUser))->will($this->returnValue($groups)); $this->initializer->expects($this->once())->method('RedirectToError')->with($this->equalTo(ErrorMessages::INSUFFICIENT_PERMISSIONS)); $binder = new ReservationResourceBinder($this->resourceService); $binder->Bind($this->initializer); }
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 Bind(IReservationComponentInitializer $initializer) { $requestedScheduleId = $initializer->GetScheduleId(); $requestedResourceId = $initializer->GetResourceId(); $groups = $this->resourceService->GetResourceGroups($requestedScheduleId, $initializer->CurrentUser()); $resources = $groups->GetAllResources(); if (empty($requestedResourceId) && count($resources) > 0) { $first = reset($resources); $requestedResourceId = $first->Id; } $bindableResourceData = $this->GetBindableResourceData($resources, $requestedResourceId); if ($bindableResourceData->NumberAccessible <= 0) { $initializer->RedirectToError(ErrorMessages::INSUFFICIENT_PERMISSIONS); return; } $initializer->BindResourceGroups($groups); $initializer->BindAvailableResources($resources); $accessories = $this->resourceService->GetAccessories(); $initializer->BindAvailableAccessories($accessories); $initializer->ShowAdditionalResources($bindableResourceData->NumberAccessible > 0); $initializer->SetReservationResource($bindableResourceData->ReservationResource); }