misuzu/public-legacy/manage/users/warnings.php

54 lines
1.6 KiB
PHP

<?php
namespace Misuzu;
use RuntimeException;
if(!isset($msz) || !($msz instanceof \Misuzu\MisuzuContext))
die('Script must be called through the Misuzu route dispatcher.');
if(!$msz->authInfo->getPerms('user')->check(Perm::U_WARNINGS_MANAGE))
Template::throwError(403);
$filterUser = null;
if(filter_has_var(INPUT_GET, 'u')) {
$filterUserId = filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT);
try {
$filterUser = $msz->usersCtx->getUserInfo($filterUserId);
} catch(RuntimeException $ex) {
Template::throwError(404);
}
}
$pagination = Pagination::fromInput($msz->usersCtx->warnings->countWarnings(userInfo: $filterUser), 10);
if(!$pagination->validOffset)
Template::throwError(404);
$warnList = [];
$warnInfos = $msz->usersCtx->warnings->getWarnings(userInfo: $filterUser, pagination: $pagination);
foreach($warnInfos as $warnInfo) {
$userInfo = $msz->usersCtx->getUserInfo($warnInfo->userId);
$userColour = $msz->usersCtx->getUserColour($userInfo);
if($warnInfo->modId === null) {
$modInfo = null;
$modColour = null;
} else {
$modInfo = $msz->usersCtx->getUserInfo($warnInfo->modId);
$modColour = $msz->usersCtx->getUserColour($modInfo);
}
$warnList[] = [
'info' => $warnInfo,
'user' => $userInfo,
'user_colour' => $userColour,
'mod' => $modInfo,
'mod_colour' => $modColour,
];
}
Template::render('manage.users.warnings', [
'manage_warns' => $warnList,
'manage_warns_pagination' => $pagination,
'manage_warns_filter_user' => $filterUser,
]);