Esempio n. 1
0
 /**
  * @param int $pageNumber
  * @param int $pageSize
  * @param BlackoutFilter $filter
  * @param UserSession $user
  * @return BlackoutItemView[]|PageableData
  */
 public function LoadFiltered($pageNumber, $pageSize, $filter, $user)
 {
     $blackoutFilter = $filter->GetFilter();
     if (!$user->IsAdmin) {
         $groups = $this->userRepository->LoadGroups($user->UserId, array(RoleLevel::RESOURCE_ADMIN, RoleLevel::SCHEDULE_ADMIN));
         $groupIds = array();
         foreach ($groups as $group) {
             $groupIds[] = $group->GroupId;
         }
         $adminFilter = new SqlFilterIn(new SqlFilterColumn('r', ColumnNames::RESOURCE_ADMIN_GROUP_ID), $groupIds);
         $adminFilter->_Or(new SqlFilterIn(new SqlFilterColumn(TableNames::SCHEDULES, ColumnNames::SCHEDULE_ADMIN_GROUP_ID), $groupIds));
         $blackoutFilter->_And($adminFilter);
     }
     return $this->reservationViewRepository->GetBlackoutList($pageNumber, $pageSize, null, null, $blackoutFilter);
 }
 public function testGetsBlackoutsThatUserCanManageIfNotAdmin()
 {
     $userId = $this->fakeUser->UserId;
     $this->fakeUser->IsAdmin = false;
     $pageNumber = 10;
     $pageSize = 20;
     $filter = new BlackoutFilter();
     $groupIds = array(1, 2, 3);
     $groups = array(new UserGroup(1, null), new UserGroup(2, null), new UserGroup(3, null));
     $expectedFilter = $filter->GetFilter();
     $adminFilter = new SqlFilterIn(new SqlFilterColumn('r', ColumnNames::RESOURCE_ADMIN_GROUP_ID), $groupIds);
     $adminFilter->_Or(new SqlFilterIn(new SqlFilterColumn(TableNames::SCHEDULES, ColumnNames::SCHEDULE_ADMIN_GROUP_ID), $groupIds));
     $expectedFilter->_And($adminFilter);
     $date = Date::Now();
     $resourceId1 = 111;
     $resourceId2 = 222;
     $b1 = new TestBlackoutItemView(1, $date, $date, $resourceId1);
     $b2 = new TestBlackoutItemView(2, $date, $date, $resourceId2);
     $blackouts = array($b1, $b2);
     $roles = array(RoleLevel::RESOURCE_ADMIN, RoleLevel::SCHEDULE_ADMIN);
     $this->userRepository->expects($this->once())->method('LoadGroups')->with($this->equalTo($userId), $this->equalTo($roles))->will($this->returnValue($groups));
     $this->reservationViewRepository->expects($this->once())->method('GetBlackoutList')->with($this->equalTo($pageNumber), $this->equalTo($pageSize), $this->isNull(), $this->isNull(), $this->equalTo($expectedFilter))->will($this->returnValue(new PageableData($blackouts)));
     $this->service->LoadFiltered($pageNumber, $pageSize, $filter, $this->fakeUser);
 }