Fixed categories without topics not being browseable.
This commit is contained in:
parent
af476491b2
commit
5ec7dddd0e
1 changed files with 38 additions and 34 deletions
|
@ -197,16 +197,9 @@ class ForumCategoriesRoutes implements RouteHandler, UrlSource {
|
|||
if($this->usersCtx->hasActiveBan($this->authInfo->userInfo))
|
||||
$perms = $perms->apply(fn(int $calc) => $calc & (Perm::F_CATEGORY_LIST | Perm::F_CATEGORY_VIEW));
|
||||
|
||||
$pagination = Pagination::fromRequest($request, $this->forum->topics->countTopics(
|
||||
categoryInfo: $category,
|
||||
global: true,
|
||||
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false
|
||||
), 20);
|
||||
if(!$pagination->validOffset)
|
||||
return 404;
|
||||
|
||||
$children = [];
|
||||
$topics = [];
|
||||
$pagination = null;
|
||||
|
||||
if($category->mayHaveChildren) {
|
||||
$children = $this->forum->categories->getCategoryChildren($category, hidden: false, asTree: true);
|
||||
|
@ -283,42 +276,53 @@ class ForumCategoriesRoutes implements RouteHandler, UrlSource {
|
|||
}
|
||||
|
||||
if($category->mayHaveTopics) {
|
||||
$topicInfos = $this->forum->topics->getTopics(
|
||||
$pagination = Pagination::fromRequest($request, $this->forum->topics->countTopics(
|
||||
categoryInfo: $category,
|
||||
global: true,
|
||||
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false,
|
||||
pagination: $pagination,
|
||||
);
|
||||
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false
|
||||
), 20);
|
||||
|
||||
foreach($topicInfos as $topicInfo) {
|
||||
$topics[] = $topic = new stdClass;
|
||||
$topic->info = $topicInfo;
|
||||
$topic->unread = $this->forum->topics->checkTopicUnread($topicInfo, $this->authInfo->userInfo);
|
||||
$topic->participated = $this->forum->topics->checkTopicParticipated($topicInfo, $this->authInfo->userInfo);
|
||||
if($pagination->validOffset) {
|
||||
$topicInfos = $this->forum->topics->getTopics(
|
||||
categoryInfo: $category,
|
||||
global: true,
|
||||
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false,
|
||||
pagination: $pagination,
|
||||
);
|
||||
|
||||
if($topicInfo->userId !== null) {
|
||||
$topic->user = $this->usersCtx->getUserInfo($topicInfo->userId);
|
||||
$topic->colour = $this->usersCtx->getUserColour($topic->user);
|
||||
}
|
||||
foreach($topicInfos as $topicInfo) {
|
||||
$topics[] = $topic = new stdClass;
|
||||
$topic->info = $topicInfo;
|
||||
$topic->unread = $this->forum->topics->checkTopicUnread($topicInfo, $this->authInfo->userInfo);
|
||||
$topic->participated = $this->forum->topics->checkTopicParticipated($topicInfo, $this->authInfo->userInfo);
|
||||
|
||||
try {
|
||||
$topic->lastPost = new stdClass;
|
||||
$topic->lastPost->info = $lastPostInfo = $this->forum->posts->getPost(
|
||||
topicInfo: $topicInfo,
|
||||
getLast: true,
|
||||
deleted: $topicInfo->deleted ? null : false,
|
||||
);
|
||||
|
||||
if($lastPostInfo->userId !== null) {
|
||||
$topic->lastPost->user = $this->usersCtx->getUserInfo($lastPostInfo->userId);
|
||||
$topic->lastPost->colour = $this->usersCtx->getUserColour($topic->lastPost->user);
|
||||
if($topicInfo->userId !== null) {
|
||||
$topic->user = $this->usersCtx->getUserInfo($topicInfo->userId);
|
||||
$topic->colour = $this->usersCtx->getUserColour($topic->user);
|
||||
}
|
||||
|
||||
try {
|
||||
$topic->lastPost = new stdClass;
|
||||
$topic->lastPost->info = $lastPostInfo = $this->forum->posts->getPost(
|
||||
topicInfo: $topicInfo,
|
||||
getLast: true,
|
||||
deleted: $topicInfo->deleted ? null : false,
|
||||
);
|
||||
|
||||
if($lastPostInfo->userId !== null) {
|
||||
$topic->lastPost->user = $this->usersCtx->getUserInfo($lastPostInfo->userId);
|
||||
$topic->lastPost->colour = $this->usersCtx->getUserColour($topic->lastPost->user);
|
||||
}
|
||||
} catch(RuntimeException $ex) {
|
||||
$topic->lastPost = null;
|
||||
}
|
||||
} catch(RuntimeException $ex) {
|
||||
$topic->lastPost = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($children) && empty($topics))
|
||||
return 404;
|
||||
|
||||
return Template::renderRaw('forum.forum', [
|
||||
'forum_breadcrumbs' => iterator_to_array($this->forum->categories->getCategoryAncestry($category)),
|
||||
'global_accent_colour' => $this->forum->categories->getCategoryColour($category),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue