protected function DatabaseAggregatorSensorPlugin::getHistoryQuery in Monitoring 8
Builds history query over one db table.
Return value
\Drupal\Core\Database\Query\Select The select query object.
1 call to DatabaseAggregatorSensorPlugin::getHistoryQuery()
- DatabaseAggregatorSensorPlugin::verboseResultHistory in src/
Plugin/ monitoring/ SensorPlugin/ DatabaseAggregatorSensorPlugin.php - Adds history verbose output to the render array $output.
File
- src/
Plugin/ monitoring/ SensorPlugin/ DatabaseAggregatorSensorPlugin.php, line 189 - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin.
Class
- DatabaseAggregatorSensorPlugin
- Database aggregator able to query a single db table.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginCode
protected function getHistoryQuery() {
/* @var \Drupal\Core\Database\Connection $database */
$database = $this
->getService('database');
// Get aggregate query for the table.
$query = $database
->select($this->sensorConfig
->getSetting('table'));
// Add conditions.
foreach ($this
->getConditions() as $condition) {
$this
->translateCondition($condition, $query);
$query
->condition($condition['field'], $condition['value'], isset($condition['operator']) ? $condition['operator'] : NULL);
}
// Group by time intervals of timestamp.
$query
->addExpression('MIN(' . $this
->getTimeIntervalField() . ') DIV ' . $this
->getTimeIntervalValue() . ' * ' . $this
->getTimeIntervalValue(), 'timestamp');
$query
->groupBy($this
->getTimeIntervalField() . ' DIV ' . $this
->getTimeIntervalValue());
$this
->addAggregateExpression($query);
return $query;
}