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

56 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2023-07-25 14:40:31 +00:00
<?php
namespace Misuzu;
use RuntimeException;
if(!$msz->getAuthInfo()->getPerms('user')->check(Perm::U_NOTES_MANAGE))
Template::throwError(403);
2023-07-25 14:40:31 +00:00
$usersCtx = $msz->getUsersContext();
$modNotes = $usersCtx->getModNotes();
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 = $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($modNotes->countNotes(userInfo: $filterUser), 10);
if(!$pagination->hasValidOffset())
Template::throwError(404);
2023-07-25 14:40:31 +00:00
$notes = [];
$noteInfos = $modNotes->getNotes(userInfo: $filterUser, pagination: $pagination);
foreach($noteInfos as $noteInfo) {
$userInfo = $usersCtx->getUserInfo($noteInfo->getUserId());
$userColour = $usersCtx->getUserColour($userInfo);
if(!$noteInfo->hasAuthorId()) {
$authorInfo = null;
$authorColour = null;
} else {
$authorInfo = $usersCtx->getUserInfo($noteInfo->getAuthorId());
$authorColour = $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,
]);