You are here

public function CommentStatistics::read in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/CommentStatistics.php \Drupal\comment\CommentStatistics::read()

Read comment statistics records for an array of entities.

Parameters

\Drupal\Core\Entity\EntityInterface[] $entities: Array of entities on which commenting is enabled, keyed by id

string $entity_type: The entity type of the passed entities.

bool $accurate: (optional) Indicates if results must be completely up to date. If set to FALSE, a replica database will used if available. Defaults to TRUE.

Return value

object[] Array of statistics records.

Overrides CommentStatisticsInterface::read

File

core/modules/comment/src/CommentStatistics.php, line 71
Contains \Drupal\comment\CommentStatistics.

Class

CommentStatistics

Namespace

Drupal\comment

Code

public function read($entities, $entity_type, $accurate = TRUE) {
  $options = $accurate ? array() : array(
    'target' => 'replica',
  );
  $stats = $this->database
    ->select('comment_entity_statistics', 'ces', $options)
    ->fields('ces')
    ->condition('ces.entity_id', array_keys($entities), 'IN')
    ->condition('ces.entity_type', $entity_type)
    ->execute();
  $statistics_records = array();
  while ($entry = $stats
    ->fetchObject()) {
    $statistics_records[] = $entry;
  }
  return $statistics_records;
}