@@ -310,7 +310,12 @@ public function getLatestPost()
310310 */
311311 public function getNumTopics ()
312312 {
313- return ForumThread::get ()->filter (["ForumID " => $ this ->ID ])->count ();
313+ $ threadIDs = Post::get ()->filter ([
314+ 'ForumID ' => $ this ->ID ,
315+ 'Author.ForumStatus ' => 'Normal ' ,
316+ ])->columnUnique ('ThreadID ' );
317+
318+ return count ($ threadIDs );
314319 }
315320
316321 /**
@@ -319,8 +324,8 @@ public function getNumTopics()
319324 public function getNumPosts ()
320325 {
321326 return Post::get ()->filter ([
322- " ForumID " => $ this ->ID ,
323- " Author.ForumStatus " => " Normal "
327+ ' ForumID ' => $ this ->ID ,
328+ ' Author.ForumStatus ' => ' Normal ' ,
324329 ])->count ();
325330 }
326331
@@ -330,10 +335,12 @@ public function getNumPosts()
330335 */
331336 public function getNumAuthors (): int
332337 {
333- return Post::get ()->filter ([
334- "ForumID " => $ this ->ID ,
335- "Author.ForumStatus " => "Normal "
336- ])->distinct ("AuthorID " )->count ();
338+ $ authorIDs = Post::get ()->filter ([
339+ 'ForumID ' => $ this ->ID ,
340+ 'Author.ForumStatus ' => 'Normal ' ,
341+ ])->columnUnique ('AuthorID ' );
342+
343+ return count ($ authorIDs );
337344 }
338345
339346 /**
@@ -373,23 +380,26 @@ public function getTopics(): ?PaginatedList
373380 ->addOrderBy (['"PostMax"."PostCreatedMax" DESC ' , '"PostMax"."PostIDMax" DESC ' ])
374381 ->setDistinct (false );
375382
376- // And return the results
383+ if (!$ threads ->exists ()) {
384+ return null ;
385+ }
386+
377387 return PaginatedList::create ($ threads );
378388 }
379389
380390
381391
382392 /*
383393 * Returns the Sticky Threads
384- * @param boolean $include_global Include Global Sticky Threads in the results (default: true)
394+ * @param bool $include_global Include Global Sticky Threads in the results (default: true)
385395 * @return DataList
386396 */
387- public function getStickyTopics ($ include_global = true )
397+ public function getStickyTopics (bool $ includeGlobalSticky = true )
388398 {
389399 // Get Threads that are sticky & in this forum
390400 $ where = '("ForumThread"."ForumID" = ' . $ this ->ID . ' AND "ForumThread"."IsSticky" = 1) ' ;
391401 // Get Threads that are globally sticky
392- if ($ include_global ) {
402+ if ($ includeGlobalSticky ) {
393403 $ where .= ' OR ("ForumThread"."IsGlobalSticky" = 1) ' ;
394404 }
395405
0 commit comments