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))
|
if($this->usersCtx->hasActiveBan($this->authInfo->userInfo))
|
||||||
$perms = $perms->apply(fn(int $calc) => $calc & (Perm::F_CATEGORY_LIST | Perm::F_CATEGORY_VIEW));
|
$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 = [];
|
$children = [];
|
||||||
$topics = [];
|
$topics = [];
|
||||||
|
$pagination = null;
|
||||||
|
|
||||||
if($category->mayHaveChildren) {
|
if($category->mayHaveChildren) {
|
||||||
$children = $this->forum->categories->getCategoryChildren($category, hidden: false, asTree: true);
|
$children = $this->forum->categories->getCategoryChildren($category, hidden: false, asTree: true);
|
||||||
|
@ -283,42 +276,53 @@ class ForumCategoriesRoutes implements RouteHandler, UrlSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
if($category->mayHaveTopics) {
|
if($category->mayHaveTopics) {
|
||||||
$topicInfos = $this->forum->topics->getTopics(
|
$pagination = Pagination::fromRequest($request, $this->forum->topics->countTopics(
|
||||||
categoryInfo: $category,
|
categoryInfo: $category,
|
||||||
global: true,
|
global: true,
|
||||||
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false,
|
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false
|
||||||
pagination: $pagination,
|
), 20);
|
||||||
);
|
|
||||||
|
|
||||||
foreach($topicInfos as $topicInfo) {
|
if($pagination->validOffset) {
|
||||||
$topics[] = $topic = new stdClass;
|
$topicInfos = $this->forum->topics->getTopics(
|
||||||
$topic->info = $topicInfo;
|
categoryInfo: $category,
|
||||||
$topic->unread = $this->forum->topics->checkTopicUnread($topicInfo, $this->authInfo->userInfo);
|
global: true,
|
||||||
$topic->participated = $this->forum->topics->checkTopicParticipated($topicInfo, $this->authInfo->userInfo);
|
deleted: $perms->check(Perm::F_POST_DELETE_ANY) ? null : false,
|
||||||
|
pagination: $pagination,
|
||||||
|
);
|
||||||
|
|
||||||
if($topicInfo->userId !== null) {
|
foreach($topicInfos as $topicInfo) {
|
||||||
$topic->user = $this->usersCtx->getUserInfo($topicInfo->userId);
|
$topics[] = $topic = new stdClass;
|
||||||
$topic->colour = $this->usersCtx->getUserColour($topic->user);
|
$topic->info = $topicInfo;
|
||||||
}
|
$topic->unread = $this->forum->topics->checkTopicUnread($topicInfo, $this->authInfo->userInfo);
|
||||||
|
$topic->participated = $this->forum->topics->checkTopicParticipated($topicInfo, $this->authInfo->userInfo);
|
||||||
|
|
||||||
try {
|
if($topicInfo->userId !== null) {
|
||||||
$topic->lastPost = new stdClass;
|
$topic->user = $this->usersCtx->getUserInfo($topicInfo->userId);
|
||||||
$topic->lastPost->info = $lastPostInfo = $this->forum->posts->getPost(
|
$topic->colour = $this->usersCtx->getUserColour($topic->user);
|
||||||
topicInfo: $topicInfo,
|
}
|
||||||
getLast: true,
|
|
||||||
deleted: $topicInfo->deleted ? null : false,
|
try {
|
||||||
);
|
$topic->lastPost = new stdClass;
|
||||||
|
$topic->lastPost->info = $lastPostInfo = $this->forum->posts->getPost(
|
||||||
if($lastPostInfo->userId !== null) {
|
topicInfo: $topicInfo,
|
||||||
$topic->lastPost->user = $this->usersCtx->getUserInfo($lastPostInfo->userId);
|
getLast: true,
|
||||||
$topic->lastPost->colour = $this->usersCtx->getUserColour($topic->lastPost->user);
|
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', [
|
return Template::renderRaw('forum.forum', [
|
||||||
'forum_breadcrumbs' => iterator_to_array($this->forum->categories->getCategoryAncestry($category)),
|
'forum_breadcrumbs' => iterator_to_array($this->forum->categories->getCategoryAncestry($category)),
|
||||||
'global_accent_colour' => $this->forum->categories->getCategoryColour($category),
|
'global_accent_colour' => $this->forum->categories->getCategoryColour($category),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue