protected ForumManager::getForumStatistics($tid)
Provides statistics for a forum.
Parameters
int $tid: The forum tid.
Return value
\stdClass|null Statistics for the given forum if statistics exist, else NULL.
File
- core/modules/forum/src/ForumManager.php, line 372
Class
- ForumManager
- Provides forum manager service.
Namespace
Drupal\forum
Code
protected function getForumStatistics($tid) { if (empty($this->forumStatistics)) { // Prime the statistics. $query = $this->connection->select('node_field_data', 'n'); $query->join('comment_entity_statistics', 'ces', "n.nid = ces.entity_id AND ces.field_name = 'comment_forum' AND ces.entity_type = 'node'"); $query->join('forum', 'f', 'n.vid = f.vid'); $query->addExpression('COUNT(n.nid)', 'topic_count'); $query->addExpression('SUM(ces.comment_count)', 'comment_count'); $this->forumStatistics = $query ->fields('f', array('tid')) ->condition('n.status', 1) ->condition('n.default_langcode', 1) ->groupBy('tid') ->addTag('node_access') ->execute() ->fetchAllAssoc('tid'); } if (!empty($this->forumStatistics[$tid])) { return $this->forumStatistics[$tid]; } }
Please login to continue.