diff --git a/app/controllers/admin/role.php b/app/controllers/admin/role.php index f932b0db3cd1f7084fbca2de79e0d0d4541035ea..6d1a82a43f08ec403cbf5f530fe4bc0aa007cddc 100644 --- a/app/controllers/admin/role.php +++ b/app/controllers/admin/role.php @@ -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; } diff --git a/app/views/admin/role/assign_plugin_role.php b/app/views/admin/role/assign_plugin_role.php index 18ff2cc059278c9f7a2b70a26fb581c293cf3595..471a087388dea5f9e750a4f672eaa6e74be4ba51 100644 --- a/app/views/admin/role/assign_plugin_role.php +++ b/app/views/admin/role/assign_plugin_role.php @@ -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> diff --git a/app/views/admin/role/assign_role.php b/app/views/admin/role/assign_role.php index b82b451421904c491f528cb008421340acb7fcf6..67c8b1e60421ca4a8d677418d3bf8f226b02dc4b 100644 --- a/app/views/admin/role/assign_role.php +++ b/app/views/admin/role/assign_role.php @@ -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> diff --git a/lib/plugins/db/RolePersistence.class.php b/lib/plugins/db/RolePersistence.class.php index d24c2a6298f1479090d06f9f1ee5844fb2610681..1b03a0132c91558980bfa3da350e274f2f422309 100644 --- a/lib/plugins/db/RolePersistence.class.php +++ b/lib/plugins/db/RolePersistence.class.php @@ -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)