service = $service; $this->agencymanager = $agencymanager; $this->groupManager = $groupManager; $this->grouppermissionservice = $grouppermissionservice; } /** * @NoAdminRequired * * Returns all Groups of an Agency, incl. all Data (DisplayName, GId) * * TODO: Checken, ob der aktuelle Nutzer das auch darf! * TODO: Hier auch die Permissions später laden, damit das nicht nochmal requested werden muss. * */ public function getagencygroups(){ $searchGroupId = $this->agencymanager->getAgencyByUser()->getAgencygid(); $groups = $this->groupManager->search($searchGroupId); $response_groups = array(); foreach ($groups as $group) { // Checking, if group is default or not. Default Groups cant delete and cant rename by logged user! $isDefault = true; if(str_contains($group->getGId(), 'subgroup')){ $isDefault = false; } // Adding current Users to the Group $user_groups = []; foreach($group->getUsers() as $groupuser){ array_push($user_groups, array("user" => $groupuser->getUID(), "displayName" => $groupuser->getDisplayName())); } array_push($response_groups, array('name' => $group->getDisplayName(), 'gid' => $group->getGid(), 'isDefault' => $isDefault, 'users' => $user_groups)); } //Sorting the Array A-Z by GroupDisplayName $keys = array_column($response_groups, 'name'); array_multisort($keys, SORT_ASC, $response_groups); return $response_groups; } /** * * Creates a new Group by GroupName * * Not possible are groupnames which are used to seperate the agencys * * * @NoAdminRequired * */ #TODO: Check, if logged user has rights to do that! public function addagencygroup(string $groupname){ if($groupname == "agencymaingroupid" or preg_match('~[0-9]{6}+~', $groupname) == 1){ return false; } else { $searchGroupId = $this->agencymanager->getAgencyByUser()->getAgencygid(); $newGroupId = $searchGroupId.'_subgroup_'.$this->agencymanager->generateRandomId(); while($this->groupManager->groupExists($newGroupId) == true){ $newGroupId = $searchGroupId.'_subgroup_'.$this->agencymanager->generateRandomId(); } $newGroup = $this->groupManager->createGroup($newGroupId); $newGroup->setDisplayName($groupname); //Create the grouppermission-element $this->grouppermissionservice->create($newGroupId); return true; } } /** * delagencygroup * * Delete an AgencyGroup * * * @NoAdminRequired */ public function delagencygroup(string $id){ # Getting the Group $todel = $this->groupManager->get($id); # Check, that the logged user is in the same Agency! $searchGroupId = $this->agencymanager->getAgencyByUser()->getAgencygid(); $result = false; # If user is in the same Agency, then delete is possible - check permissions! # TODO: Hier noch einbauen, dass die Rechte geprüft werden! if(str_contains($todel->getGID(), $searchGroupId)) { $this->grouppermissionservice->remove($todel->getGID()); $todel->delete(); } return $result; } }