2022-09-13 13:14:49 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
use Misuzu\Users\Roles;
|
|
|
|
|
2024-12-02 02:28:08 +00:00
|
|
|
if(!isset($msz) || !($msz instanceof \Misuzu\MisuzuContext))
|
|
|
|
die('Script must be called through the Misuzu route dispatcher.');
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
if(!$msz->authInfo->getPerms('user')->check(Perm::U_USERS_MANAGE))
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(403);
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2024-12-19 01:22:26 +00:00
|
|
|
$pagination = Pagination::fromInput($msz->usersCtx->users->countUsers(), 30);
|
|
|
|
if(!$pagination->validOffset)
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(404);
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
$userList = [];
|
2024-11-30 04:09:29 +00:00
|
|
|
$userInfos = $msz->usersCtx->users->getUsers(pagination: $pagination, orderBy: 'id');
|
2023-08-02 22:12:47 +00:00
|
|
|
$roleInfos = [];
|
|
|
|
|
|
|
|
foreach($userInfos as $userInfo) {
|
2024-11-30 04:09:29 +00:00
|
|
|
$displayRoleId = $userInfo->displayRoleId ?? Roles::DEFAULT_ROLE;
|
2023-08-02 22:12:47 +00:00
|
|
|
if(array_key_exists($displayRoleId, $roleInfos))
|
|
|
|
$roleInfo = $roleInfos[$displayRoleId];
|
|
|
|
else
|
2024-11-30 04:09:29 +00:00
|
|
|
$roleInfos[$displayRoleId] = $roleInfo = $msz->usersCtx->roles->getRole($displayRoleId);
|
2023-08-02 22:12:47 +00:00
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$colour = $userInfo->hasColour ? $userInfo->colour : $roleInfo->colour;
|
2023-08-02 22:12:47 +00:00
|
|
|
|
|
|
|
$userList[] = [
|
|
|
|
'info' => $userInfo,
|
|
|
|
'role' => $roleInfo,
|
|
|
|
'colour' => $colour,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-09-13 13:14:49 +00:00
|
|
|
Template::render('manage.users.users', [
|
2023-08-02 22:12:47 +00:00
|
|
|
'manage_users' => $userList,
|
2022-09-13 13:14:49 +00:00
|
|
|
'manage_users_pagination' => $pagination,
|
|
|
|
]);
|