Skip to content
Snippets Groups Projects
Commit c0fd6686 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

group roles in administration, fixes #1793

Closes #1793

Merge request studip/studip!1173
parent 5600a0a2
No related branches found
No related tags found
No related merge requests found
......@@ -177,7 +177,7 @@ class Admin_RoleController extends AuthenticatedController
$this->currentuser = $this->users[$usersel];
$this->assignedroles = $this->currentuser->getRoles();
$this->all_userroles = $this->currentuser->getRoles(true);
$this->roles = RolePersistence::getAllRoles();
$this->roles = RolePersistence::getAllRoles(true);
foreach ($this->assignedroles as $role) {
$institutes = SimpleCollection::createFromArray(Institute::findMany(RolePersistence::getAssignedRoleInstitutes($usersel, $role->getRoleid())));
$this->assignedroles_institutes[$role->getRoleid()] = $institutes->orderBy('name')->pluck('name');
......@@ -227,7 +227,7 @@ class Admin_RoleController extends AuthenticatedController
$this->plugins = PluginManager::getInstance()->getPluginInfos();
$this->assigned = RolePersistence::getAssignedPluginRoles($pluginid);
$this->roles = RolePersistence::getAllRoles();
$this->roles = RolePersistence::getAllRoles(true);
$this->pluginid = $pluginid;
}
......
......@@ -63,12 +63,22 @@ use Studip\Button;
</td>
<td>
<select multiple name="rolesel[]" size="10" style="width: 300px;">
<? foreach ($roles as $role): ?>
<option value="<?= $role->getRoleid() ?>">
<?= htmlReady($role->getRolename()) ?>
<? if ($role->getSystemtype()): ?>[<?= _('Systemrolle') ?>]<? endif ?>
</option>
<? endforeach ?>
<optgroup label="<?= _('Systemrollen') ?>">
<? foreach ($roles['system'] as $role): ?>
<option value="<?= $role->getRoleid() ?>">
<?= htmlReady($role->getRolename()) ?>
</option>
<? endforeach ?>
</optgroup>
<? if (count($roles['other']) > 0): ?>
<optgroup label="<?= _('Weitere Rollen') ?>">
<? foreach ($roles['other'] as $role): ?>
<option value="<?= $role->getRoleid() ?>">
<?= htmlReady($role->getRolename()) ?>
</option>
<? endforeach ?>
</optgroup>
<? endif; ?>
</select>
</td>
</tr>
......
......@@ -82,12 +82,22 @@ use Studip\Button, Studip\LinkButton;
</td>
<td>
<select size="10" name="rolesel[]" multiple style="width: 300px;">
<? foreach ($roles as $role): ?>
<optgroup label="<?= _('Systemrollen') ?>">
<? foreach ($roles['system'] as $role): ?>
<option value="<?= $role->getRoleid() ?>">
<?= htmlReady($role->getRolename()) ?>
<? if ($role->getSystemtype()): ?>[<?= _('Systemrolle') ?>]<? endif ?>
</option>
<? endforeach ?>
</optgroup>
<? if (count($roles['other']) > 0): ?>
<optgroup label="<?= _('Weitere Rollen') ?>">
<? foreach ($roles['other'] as $role): ?>
<option value="<?= $role->getRoleid() ?>">
<?= htmlReady($role->getRolename()) ?>
</option>
<? endforeach ?>
</optgroup>
<? endif; ?>
</select>
</td>
</tr>
......
......@@ -22,7 +22,7 @@ class RolePersistence
*
* @return array Roles
*/
public static function getAllRoles(): array
public static function getAllRoles(bool $grouped = false): array
{
// read cache
$cache = StudipCacheFactory::getCache();
......@@ -44,7 +44,17 @@ class RolePersistence
$cache->write(self::ROLES_CACHE_KEY, $roles);
}
return $roles;
if (!$grouped) {
return $roles;
}
$groups = ['system' => [], 'other' => []];
foreach ($roles as $id => $role) {
$index = $role->getSystemtype() ? 'system' : 'other';
$groups[$index][$id] = $role;
}
return $groups;
}
public static function getRoleIdByName($name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment