diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2023-03-22 12:27:53 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2023-03-22 12:27:53 +0000 |
| commit | d79463e9605fcb1bef250ab3e9cf717227fe04ed (patch) | |
| tree | 41217c17318b2b0969099c9bd5806fb00d2668d9 /app | |
| parent | d8fe98cc4178a6f49355633c0441e6a45c83945b (diff) | |
implement RolePersistence::getUsersWithRoleByName() and RolePersistence::getUsersWithRoleById(), fixes #2014
Closes #2014
Merge request studip/studip!1311
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/admin/role.php | 24 | ||||
| -rw-r--r-- | app/views/admin/role/show_role.php | 24 |
2 files changed, 24 insertions, 24 deletions
diff --git a/app/controllers/admin/role.php b/app/controllers/admin/role.php index 513bcbd..c316021 100644 --- a/app/controllers/admin/role.php +++ b/app/controllers/admin/role.php @@ -288,18 +288,17 @@ class Admin_RoleController extends AuthenticatedController $this->roleid = ''; if ($roleid) { - $sql = "SELECT DISTINCT Vorname,Nachname,user_id,username,perms - FROM auth_user_md5 - JOIN roles_user ON userid = user_id - WHERE roleid = ? - ORDER BY Nachname, Vorname"; - $statement = DBManager::get()->prepare($sql); - $statement->execute([$roleid]); - - $users = $statement->fetchAll(PDO::FETCH_ASSOC); - foreach ($users as $key => $user) { - $institutes = new SimpleCollection(Institute::findMany(RolePersistence::getAssignedRoleInstitutes($user['user_id'], $roleid))); - $users[$key]['institutes'] = $institutes->orderBy('name')->pluck('name'); + $this->users = RolePersistence::getUsersWithRoleById($roleid); + + $this->user_institutes = []; + foreach ($this->users as $user) { + $this->user_institutes[$user->id] = Institute::findAndMapMany( + function (Institute $institute) { + return $institute->name; + }, + RolePersistence::getAssignedRoleInstitutes($user['user_id'], $roleid), + 'ORDER BY name' + ); } $plugins = PluginManager::getInstance()->getPluginInfos(); @@ -311,7 +310,6 @@ class Admin_RoleController extends AuthenticatedController $this->implicit_count = RolePersistence::countImplicitUsers($roleid); - $this->users = $users; $this->plugins = $plugins; $this->role = self::getRole($roleid); $this->roleid = $roleid; diff --git a/app/views/admin/role/show_role.php b/app/views/admin/role/show_role.php index e01a952..196f9bf 100644 --- a/app/views/admin/role/show_role.php +++ b/app/views/admin/role/show_role.php @@ -5,7 +5,8 @@ * @var string $roleid * @var Role[] $roles * @var QuickSearch $mps - * @var array $users + * @var User[] $users + * @var array $user_institutes * @var array $plugins * @var int $implicit_count */ @@ -90,29 +91,30 @@ use Studip\Button; <? foreach (array_values($users) as $index => $user): ?> <tr> <td> - <input type="checkbox" name="ids[]" value="<?= $user['user_id'] ?>"> + <input type="checkbox" name="ids[]" value="<?= htmlReady($user->id) ?>"> </td> <td style="text-align: right;"> <?= $index + 1 ?>. </td> <td> - <a href="<?= $controller->url_for('admin/role/assign_role', $user['user_id']) ?>"> - <?= htmlReady(sprintf('%s %s (%s)', $user['Vorname'], $user['Nachname'], $user['username'])) ?> + <a href="<?= $controller->link_for('admin/role/assign_role', $user->id) ?>"> + <?= htmlReady(sprintf('%s %s (%s)', $user->vorname, $user->nachname, $user->username)) ?> </a> </td> - <td><?= $user['perms'] ?></td> + <td><?= htmlReady($user->perms) ?></td> <td> - <? $institutes = join(', ', $user['institutes']); ?> + <? $institutes = join(', ', $user_institutes[$user->id]); ?> <?= htmlReady(mb_substr($institutes, 0, 60)) ?> <? if (mb_strlen($institutes) > 60): ?> - ...<?= tooltipIcon(join("\n", $user['institutes']))?> + ...<?= tooltipIcon(join("\n", $user_institutes[$user->id]))?> <? endif ?> </td> <td class="actions"> - <?= Icon::create('trash', 'clickable', ['title' => _('Rolle entziehen')]) - ->asInput([ - "data-confirm" => _('Soll dieser Person wirklich die Rolle entzogen werden?'), - "formaction" => $controller->url_for('admin/role/remove_user/'.$roleid.'/'.$user['user_id'])]) ?> + <?= Icon::create('trash')->asInput([ + 'title' => _('Rolle entziehen'), + 'data-confirm' => _('Soll dieser Person wirklich die Rolle entzogen werden?'), + 'formaction' => $controller->url_for('admin/role/remove_user', $roleid, $user->id), + ]) ?> </td> </tr> <? endforeach; ?> |
