You are here

protected function ForumManager::getForumStatistics in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::getForumStatistics()

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.

1 call to ForumManager::getForumStatistics()
ForumManager::getChildren in core/modules/forum/src/ForumManager.php
Utility method to fetch the child forums for a given forum.

File

core/modules/forum/src/ForumManager.php, line 377
Contains \Drupal\forum\ForumManager.

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];
  }
}