2022-09-13 13:14:49 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
2023-07-22 15:02:41 +00:00
|
|
|
use RuntimeException;
|
2022-09-13 13:14:49 +00:00
|
|
|
use Misuzu\Users\User;
|
|
|
|
|
|
|
|
if(!User::hasCurrent() || !perms_check_user(MSZ_PERMS_USER, User::getCurrent()->getId(), MSZ_PERM_USER_MANAGE_WARNINGS)) {
|
|
|
|
echo render_error(403);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-26 22:43:50 +00:00
|
|
|
$userInfos = [
|
|
|
|
(string)User::getCurrent()->getId() => User::getCurrent(),
|
|
|
|
];
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-07-26 22:43:50 +00:00
|
|
|
$filterUser = null;
|
|
|
|
if(filter_has_var(INPUT_GET, 'u')) {
|
|
|
|
$filterUserId = (int)filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT);
|
2022-09-13 13:14:49 +00:00
|
|
|
try {
|
2023-07-26 22:43:50 +00:00
|
|
|
$filterUser = User::byId($filterUserId);
|
|
|
|
$userInfos[(string)$filterUser->getId()] = $filterUser;
|
2023-07-22 15:02:41 +00:00
|
|
|
} catch(RuntimeException $ex) {
|
2023-07-26 22:43:50 +00:00
|
|
|
echo render_error(404);
|
|
|
|
return;
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 22:43:50 +00:00
|
|
|
$warns = $msz->getWarnings();
|
|
|
|
$pagination = new Pagination($warns->countWarnings(userInfo: $filterUser), 10);
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2023-07-26 22:43:50 +00:00
|
|
|
if(!$pagination->hasValidOffset()) {
|
2022-09-13 13:14:49 +00:00
|
|
|
echo render_error(404);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-26 22:43:50 +00:00
|
|
|
$warnList = [];
|
|
|
|
$warnInfos = $warns->getWarnings(userInfo: $filterUser, pagination: $pagination);
|
|
|
|
|
|
|
|
foreach($warnInfos as $warnInfo) {
|
|
|
|
if(array_key_exists($warnInfo->getUserId(), $userInfos))
|
|
|
|
$userInfo = $userInfos[$warnInfo->getUserId()];
|
|
|
|
else
|
|
|
|
$userInfos[$warnInfo->getUserId()] = $userInfo = User::byId((int)$warnInfo->getUserId());
|
|
|
|
|
|
|
|
if(!$warnInfo->hasModId())
|
|
|
|
$modInfo = null;
|
|
|
|
elseif(array_key_exists($warnInfo->getModId(), $userInfos))
|
|
|
|
$modInfo = $userInfos[$warnInfo->getModId()];
|
|
|
|
else
|
|
|
|
$userInfos[$warnInfo->getModId()] = $modInfo = User::byId((int)$warnInfo->getModId());
|
|
|
|
|
|
|
|
$warnList[] = [
|
|
|
|
'info' => $warnInfo,
|
|
|
|
'user' => $userInfo,
|
|
|
|
'mod' => $modInfo,
|
|
|
|
];
|
|
|
|
}
|
2022-09-13 13:14:49 +00:00
|
|
|
|
|
|
|
Template::render('manage.users.warnings', [
|
2023-07-26 22:43:50 +00:00
|
|
|
'manage_warns' => $warnList,
|
|
|
|
'manage_warns_pagination' => $pagination,
|
|
|
|
'manage_warns_filter_user' => $filterUser,
|
2022-09-13 13:14:49 +00:00
|
|
|
]);
|