Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /**
  * @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));
 }
Esempio n. 5
0
 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));
 }