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

53 lines
1.5 KiB
PHP
Raw Normal View History

2023-07-25 14:40:31 +00:00
<?php
namespace Misuzu;
use RuntimeException;
if(!$msz->authInfo->getPerms('user')->check(Perm::U_NOTES_MANAGE))
Template::throwError(403);
2023-07-25 14:40:31 +00:00
$filterUser = null;
if(filter_has_var(INPUT_GET, 'u')) {
$filterUserId = filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT);
2023-07-25 14:40:31 +00:00
try {
$filterUser = $msz->usersCtx->getUserInfo($filterUserId);
2023-07-25 14:40:31 +00:00
} catch(RuntimeException $ex) {
Template::throwError(404);
2023-07-25 14:40:31 +00:00
}
}
$pagination = new Pagination($msz->usersCtx->modNotes->countNotes(userInfo: $filterUser), 10);
2023-07-25 14:40:31 +00:00
if(!$pagination->hasValidOffset())
Template::throwError(404);
2023-07-25 14:40:31 +00:00
$notes = [];
$noteInfos = $msz->usersCtx->modNotes->getNotes(userInfo: $filterUser, pagination: $pagination);
2023-07-25 14:40:31 +00:00
foreach($noteInfos as $noteInfo) {
$userInfo = $msz->usersCtx->getUserInfo($noteInfo->userId);
$userColour = $msz->usersCtx->getUserColour($userInfo);
if($noteInfo->authorId === null) {
$authorInfo = null;
$authorColour = null;
} else {
$authorInfo = $msz->usersCtx->getUserInfo($noteInfo->authorId);
$authorColour = $msz->usersCtx->getUserColour($authorInfo);
}
2023-07-25 14:40:31 +00:00
$notes[] = [
'info' => $noteInfo,
'user' => $userInfo,
'user_colour' => $userColour,
2023-07-25 14:40:31 +00:00
'author' => $authorInfo,
'author_colour' => $authorColour,
2023-07-25 14:40:31 +00:00
];
}
Template::render('manage.users.notes', [
'manage_notes' => $notes,
'manage_notes_pagination' => $pagination,
'manage_notes_filter_user' => $filterUser,
]);