コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
ファイル: CalendarPresenter.php プロジェクト: Trideon/gigolo
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
 }