Пример #1
0
 public function ChangeGroups($user, $groupIds)
 {
     if ($groupIds == null) {
         return;
     }
     $existingGroupIds = array();
     foreach ($user->Groups() as $group) {
         $existingGroupIds[] = $group->GroupId;
     }
     foreach ($groupIds as $targetGroupId) {
         if (!in_array($targetGroupId, $existingGroupIds)) {
             // add group
             $group = $this->groupRepository->LoadById($targetGroupId);
             $group->AddUser($user->Id());
             $this->groupRepository->Update($group);
         }
     }
     foreach ($existingGroupIds as $existingId) {
         if (!in_array($existingId, $groupIds)) {
             // remove user
             $group = $this->groupRepository->LoadById($existingId);
             $group->RemoveUser($user->Id());
             $this->groupRepository->Update($group);
         }
     }
 }
Пример #2
0
 public function AddUser()
 {
     $userId = $this->manageUsersService->AddUser($this->page->GetUserName(), $this->page->GetEmail(), $this->page->GetFirstName(), $this->page->GetLastName(), $this->page->GetPassword(), $this->page->GetTimezone(), Configuration::Instance()->GetKey(ConfigKeys::LANGUAGE), Pages::DEFAULT_HOMEPAGE_ID, array(), $this->GetAttributeValues());
     $groupId = $this->page->GetUserGroup();
     if (!empty($groupId)) {
         $group = $this->groupRepository->LoadById($groupId);
         $group->AddUser($userId);
         $this->groupRepository->Update($group);
     }
 }