You are here

protected function ContentEntityAggregatorSensorPlugin::getEntityQueryAggregate in Monitoring 8

Builds the entity aggregate query.

Return value

\Drupal\Core\Entity\Query\QueryAggregateInterface The entity query object.

1 call to ContentEntityAggregatorSensorPlugin::getEntityQueryAggregate()
CommerceTurnoverSensorPlugin::getEntityQueryAggregate in src/Plugin/monitoring/SensorPlugin/CommerceTurnoverSensorPlugin.php
Builds the entity aggregate query.
1 method overrides ContentEntityAggregatorSensorPlugin::getEntityQueryAggregate()
CommerceTurnoverSensorPlugin::getEntityQueryAggregate in src/Plugin/monitoring/SensorPlugin/CommerceTurnoverSensorPlugin.php
Builds the entity aggregate query.

File

src/Plugin/monitoring/SensorPlugin/ContentEntityAggregatorSensorPlugin.php, line 77
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ContentEntityAggregatorSensorPlugin.

Class

ContentEntityAggregatorSensorPlugin
Content entity database aggregator.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

protected function getEntityQueryAggregate() {
  $entity_info = $this->entityTypeManager
    ->getDefinition($this->sensorConfig
    ->getSetting('entity_type'), TRUE);

  // Get aggregate query for the entity type.
  $query = $this->entityTypeManager
    ->getStorage($this->sensorConfig
    ->getSetting('entity_type'))
    ->getAggregateQuery()
    ->accessCheck(FALSE);
  $this->aggregateField = $entity_info
    ->getKey('id');
  $this
    ->addAggregate($query);

  // Add conditions.
  foreach ($this
    ->getConditions() as $condition) {
    if (empty($condition['field'])) {
      continue;
    }
    $query
      ->condition($condition['field'], $condition['value'], isset($condition['operator']) ? $condition['operator'] : NULL);
  }

  // Apply time interval on field.
  if ($this
    ->getTimeIntervalField() && $this
    ->getTimeIntervalValue()) {
    $query
      ->condition($this
      ->getTimeIntervalField(), \Drupal::time()
      ->getRequestTime() - $this
      ->getTimeIntervalValue(), '>');
  }
  return $query;
}