2023-07-25 14:40:31 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
|
|
|
use RuntimeException;
|
|
|
|
|
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_NOTES_MANAGE))
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(403);
|
2023-07-25 14:40:31 +00:00
|
|
|
|
|
|
|
$filterUser = null;
|
|
|
|
if(filter_has_var(INPUT_GET, 'u')) {
|
2023-08-02 22:12:47 +00:00
|
|
|
$filterUserId = filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT);
|
2023-07-25 14:40:31 +00:00
|
|
|
try {
|
2024-11-30 04:09:29 +00:00
|
|
|
$filterUser = $msz->usersCtx->getUserInfo($filterUserId);
|
2023-07-25 14:40:31 +00:00
|
|
|
} catch(RuntimeException $ex) {
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(404);
|
2023-07-25 14:40:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$pagination = new Pagination($msz->usersCtx->modNotes->countNotes(userInfo: $filterUser), 10);
|
2023-07-25 14:40:31 +00:00
|
|
|
|
2023-08-31 15:59:53 +00:00
|
|
|
if(!$pagination->hasValidOffset())
|
|
|
|
Template::throwError(404);
|
2023-07-25 14:40:31 +00:00
|
|
|
|
|
|
|
$notes = [];
|
2024-11-30 04:09:29 +00:00
|
|
|
$noteInfos = $msz->usersCtx->modNotes->getNotes(userInfo: $filterUser, pagination: $pagination);
|
2023-07-25 14:40:31 +00:00
|
|
|
|
|
|
|
foreach($noteInfos as $noteInfo) {
|
2024-11-30 04:09:29 +00:00
|
|
|
$userInfo = $msz->usersCtx->getUserInfo($noteInfo->userId);
|
|
|
|
$userColour = $msz->usersCtx->getUserColour($userInfo);
|
2023-08-02 22:12:47 +00:00
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
if($noteInfo->authorId === null) {
|
2023-08-02 22:12:47 +00:00
|
|
|
$authorInfo = null;
|
|
|
|
$authorColour = null;
|
|
|
|
} else {
|
2024-11-30 04:09:29 +00:00
|
|
|
$authorInfo = $msz->usersCtx->getUserInfo($noteInfo->authorId);
|
|
|
|
$authorColour = $msz->usersCtx->getUserColour($authorInfo);
|
2023-08-02 22:12:47 +00:00
|
|
|
}
|
2023-07-25 14:40:31 +00:00
|
|
|
|
|
|
|
$notes[] = [
|
|
|
|
'info' => $noteInfo,
|
|
|
|
'user' => $userInfo,
|
2023-08-02 22:12:47 +00:00
|
|
|
'user_colour' => $userColour,
|
2023-07-25 14:40:31 +00:00
|
|
|
'author' => $authorInfo,
|
2023-08-02 22:12:47 +00:00
|
|
|
'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,
|
|
|
|
]);
|