public function PageLoad() { $resources = $this->resourceRepository->GetResourceList(); $groups = $this->groupRepository->GetList()->Results(); $schedules = $this->scheduleRepository->GetAll(); $this->page->BindResources($resources); $this->page->BindGroups($groups); $this->page->BindSchedules($schedules); $quotas = $this->quotaRepository->GetAll(); $this->page->BindQuotas($quotas); }
public function GetList($pageNumber, $pageSize, $sortField = null, $sortDirection = null, $filter = null, $accountStatus = AccountStatus::ALL) { if (empty($accountStatus)) { $accountStatus = AccountStatus::ALL; } $user = parent::LoadById($this->userSession->UserId); $groupIds = array(); foreach ($user->GetAdminGroups() as $group) { $groupIds[] = $group->GroupId; } return $this->groupRepository->GetUsersInGroup($groupIds, $pageNumber, $pageSize, $filter, $accountStatus); }
public function testGetsAllGroups() { $groupId = 123232; $groupItemView = new GroupItemView($groupId, 'name'); $groupItemView->Id = $groupId; $list = array($groupItemView); $groups = new PageableData($list); $this->groupViewRepository->expects($this->once())->method('GetList')->with($this->isNull(), $this->isNull())->will($this->returnValue($groups)); $this->service->GetGroups(); $expectedResponse = new GroupsResponse($this->server, $list); $this->assertEquals($expectedResponse, $this->server->_LastResponse); }
public function PageLoad() { if ($this->page->GetUserId() != null) { $userList = $this->userRepository->GetList(1, 1, null, null, new SqlFilterEquals(ColumnNames::USER_ID, $this->page->GetUserId())); } else { $userList = $this->userRepository->GetList($this->page->GetPageNumber(), $this->page->GetPageSize(), null, null, null, $this->page->GetFilterStatusId()); } $this->page->BindUsers($userList->Results()); $this->page->BindPageInfo($userList->PageInfo()); $groups = $this->groupViewRepository->GetList(); $this->page->BindGroups($groups->Results()); $resources = array(); $user = $this->userRepository->LoadById(ServiceLocator::GetServer()->GetUserSession()->UserId); $allResources = $this->resourceRepository->GetResourceList(); foreach ($allResources as $resource) { if ($user->IsResourceAdminFor($resource)) { $resources[] = $resource; } } $this->page->BindResources($resources); $userIds = array(); /** @var $user UserItemView */ foreach ($userList->Results() as $user) { $userIds[] = $user->Id; } $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::USER, $userIds); $this->page->BindAttributeList($attributeList); }
public function testWhenInitializing() { $groups = array(); $bookableResources = array(); $schedules = array(); $groupResult = new PageableData($groups); $quotaList = array(); $this->resourceRepository->expects($this->once())->method('GetResourceList')->will($this->returnValue($bookableResources)); $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($bookableResources)); $this->groupRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupResult)); $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups)); $this->scheduleRepository->expects($this->once())->method('GetAll')->will($this->returnValue($schedules)); $this->page->expects($this->once())->method('BindSchedules')->with($this->equalTo($schedules)); $this->quotaRepository->expects($this->once())->method('GetAll')->will($this->returnValue($quotaList)); $this->presenter->PageLoad(); }
public function testBindsUsersAndAttributesAndGroups() { $userId = 123; $pageNumber = 1; $pageSize = 10; $result = new UserItemView(); $result->Id = $userId; $results = array($result); $userList = new PageableData($results); $resourceList = array(new FakeBookableResource(1)); $attributeList = array(new FakeCustomAttribute(1, '1')); $this->page->expects($this->once())->method('GetPageNumber')->will($this->returnValue($pageNumber)); $this->page->expects($this->once())->method('GetPageSize')->will($this->returnValue($pageSize)); $this->page->expects($this->once())->method('GetFilterStatusId')->will($this->returnValue(AccountStatus::ALL)); $this->userRepo->expects($this->once())->method('GetList')->with($this->equalTo($pageNumber), $this->equalTo($pageSize), $this->isNull(), $this->isNull(), $this->isNull(), $this->equalTo(AccountStatus::ALL))->will($this->returnValue($userList)); $user = new FakeUser(); $this->userRepo->expects($this->once())->method('LoadById')->with($this->fakeUser->UserId)->will($this->returnValue($user)); $this->page->expects($this->once())->method('BindUsers')->with($this->equalTo($userList->Results())); $this->page->expects($this->once())->method('BindPageInfo')->with($this->equalTo($userList->PageInfo())); $this->resourceRepo->expects($this->once())->method('GetResourceList')->will($this->returnValue($resourceList)); $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($resourceList)); $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::USER))->will($this->returnValue($attributeList)); $this->page->expects($this->once())->method('BindAttributeList')->with($this->equalTo($attributeList)); $groups = array(new GroupItemView(1, 'gn')); $groupList = new PageableData($groups); $this->groupViewRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupList)); $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups)); $this->presenter->PageLoad(); }
public function PageLoad() { if ($this->page->GetUserId() != null) { $userList = $this->userRepository->GetList(1, 1, null, null, new SqlFilterEquals(ColumnNames::USER_ID, $this->page->GetUserId())); } else { $userList = $this->userRepository->GetList($this->page->GetPageNumber(), $this->page->GetPageSize(), null, null, null, $this->page->GetFilterStatusId()); } $this->page->BindUsers($userList->Results()); $this->page->BindPageInfo($userList->PageInfo()); $groups = $this->groupViewRepository->GetList(); $this->page->BindGroups($groups->Results()); $user = $this->userRepository->LoadById(ServiceLocator::GetServer()->GetUserSession()->UserId); $resources = $this->GetResourcesThatCurrentUserCanAdminister($user); $this->page->BindResources($resources); $attributeList = $this->attributeService->GetByCategory(CustomAttributeCategory::USER); $this->page->BindAttributeList($attributeList); }
public function PageLoad() { $resourceAttributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESOURCE); $filterValues = $this->page->GetFilterValues(); $results = $this->resourceRepository->GetList($this->page->GetPageNumber(), $this->page->GetPageSize(), null, null, $filterValues->AsFilter($resourceAttributes)); $resources = $results->Results(); $this->page->BindResources($resources); $this->page->BindPageInfo($results->PageInfo()); $schedules = $this->scheduleRepository->GetAll(); $scheduleList = array(); /* @var $schedule Schedule */ foreach ($schedules as $schedule) { $scheduleList[$schedule->GetId()] = $schedule->GetName(); } $this->page->BindSchedules($scheduleList); $this->page->AllSchedules($schedules); $resourceTypes = $this->resourceRepository->GetResourceTypes(); $resourceTypeList = array(); /* @var $resourceType ResourceType */ foreach ($resourceTypes as $resourceType) { $resourceTypeList[$resourceType->Id()] = $resourceType; } $this->page->BindResourceTypes($resourceTypeList); $statusReasons = $this->resourceRepository->GetStatusReasons(); $statusReasonList = array(); foreach ($statusReasons as $reason) { $statusReasonList[$reason->Id()] = $reason; } $this->page->BindResourceStatusReasons($statusReasonList); $groups = $this->groupRepository->GetGroupsByRole(RoleLevel::RESOURCE_ADMIN); $this->page->BindAdminGroups($groups); $resourceIds = array(); foreach ($resources as $resource) { $resourceIds[] = $resource->GetId(); } $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE, $resourceIds); $this->page->BindAttributeList($attributeList); $this->InitializeFilter($filterValues, $resourceAttributes); }
/** * @name GetAllGroups * @description Loads all groups * @response GroupsResponse * @return void */ public function GetGroups() { $pageable = $this->groupViewRepository->GetList(null, null); $groups = $pageable->Results(); $this->server->WriteResponse(new GroupsResponse($this->server, $groups)); }
public function ImportUsers() { set_time_limit(300); $groupsList = $this->groupViewRepository->GetList(); /** @var GroupItemView[] $groups */ $groups = $groupsList->Results(); $groupsIndexed = array(); foreach ($groups as $group) { $groupsIndexed[$group->Name()] = $group->Id(); } $importFile = $this->page->GetImportFile(); $csv = new UserImportCsv($importFile); $importCount = 0; $messages = array(); $rows = $csv->GetRows(); if (count($rows) == 0) { $this->page->SetImportResult(new CsvImportResult(0, array(), 'Empty file or missing header row')); return; } for ($i = 0; $i < count($rows); $i++) { $row = $rows[$i]; try { $emailValidator = new EmailValidator($row->email); $uniqueEmailValidator = new UniqueEmailValidator($this->userRepository, $row->email); $uniqueUsernameValidator = new UniqueUserNameValidator($this->userRepository, $row->username); $emailValidator->Validate(); $uniqueEmailValidator->Validate(); $uniqueUsernameValidator->Validate(); if (!$emailValidator->IsValid()) { $messages[] = $emailValidator->Messages()[0] . " ({$row->email})"; continue; } if (!$uniqueEmailValidator->IsValid()) { $messages[] = $uniqueEmailValidator->Messages()[0] . " ({$row->email})"; continue; } if (!$uniqueUsernameValidator->IsValid()) { $messages[] = $uniqueUsernameValidator->Messages()[0] . " ({$row->username})"; continue; } $timezone = empty($row->timezone) ? Configuration::Instance()->GetKey(ConfigKeys::DEFAULT_TIMEZONE) : $row->timezone; $password = empty($row->password) ? 'password' : $row->password; $language = empty($row->language) ? 'en_us' : $row->language; $user = $this->manageUsersService->AddUser($row->username, $row->email, $row->firstName, $row->lastName, $password, $timezone, $language, Configuration::Instance()->GetKey(ConfigKeys::DEFAULT_HOMEPAGE), array(UserAttribute::Phone => $row->phone, UserAttribute::Organization => $row->organization, UserAttribute::Position => $row->position), array()); $userGroups = array(); foreach ($row->groups as $groupName) { if (array_key_exists($groupName, $groupsIndexed)) { Log::Debug('Importing user %s with group %s', $row->username, $groupName); $userGroups[] = new UserGroup($groupsIndexed[$groupName], $groupName); } } if (count($userGroups) > 0) { $user->ChangeGroups($userGroups); $this->userRepository->Update($user); } $importCount++; } catch (Exception $ex) { Log::Error('Error importing users. %s', $ex); } } $this->page->SetImportResult(new CsvImportResult($importCount, $csv->GetSkippedRowNumbers(), $messages)); }
public function PageLoad() { $schedules = $this->manageSchedulesService->GetAll(); $sourceSchedules = $this->manageSchedulesService->GetSourceSchedules(); $layouts = array(); /* @var $schedule Schedule */ foreach ($schedules as $schedule) { $layout = $this->manageSchedulesService->GetLayout($schedule); $layouts[$schedule->GetId()] = $layout; } $this->page->BindGroups($this->groupViewRepository->GetGroupsByRole(RoleLevel::SCHEDULE_ADMIN)); $this->page->BindSchedules($schedules, $layouts, $sourceSchedules); $this->PopulateTimezones(); }