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 testIsNotValidWhenTurnedOffForUser() { $user = new FakeUser(); $user->DisableSubscription(); $publicId = uniqid(); $this->page->expects($this->once())->method('GetUserId')->will($this->returnValue($publicId)); $this->subscriptionService->expects($this->once())->method('GetUser')->with($this->equalTo($publicId))->will($this->returnValue($user)); $this->StubSubscriptionKey(); $isValid = $this->validator->IsValid(); $this->assertFalse($isValid); }
/** * @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() { 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 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 IsValid() { $key = Configuration::Instance()->GetSectionKey(ConfigSection::ICS, ConfigKeys::ICS_SUBSCRIPTION_KEY); $providedKey = $this->page->GetSubscriptionKey(); if (empty($key) || $providedKey != $key) { Log::Debug('Empty or invalid subscription key. Key provided: %s', $providedKey); return false; } $resourceId = $this->page->GetResourceId(); $scheduleId = $this->page->GetScheduleId(); $userId = $this->page->GetUserId(); if (!empty($resourceId)) { return $this->subscriptionService->GetResource($resourceId)->GetIsCalendarSubscriptionAllowed(); } if (!empty($scheduleId)) { return $this->subscriptionService->GetSchedule($scheduleId)->GetIsCalendarSubscriptionAllowed(); } if (!empty($userId)) { return $this->subscriptionService->GetUser($userId)->GetIsCalendarSubscriptionAllowed(); } return true; }
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 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(); }
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); }