You are here

public function DatabaseAggregatorSensorPlugin::verboseResultHistory in Monitoring 8

Adds history verbose output to the render array $output.

Parameters

array &$output: Render array where the result will be added.

2 calls to DatabaseAggregatorSensorPlugin::verboseResultHistory()
DatabaseAggregatorSensorPlugin::resultVerbose in src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php
Provide additional info about sensor call.
WatchdogAggregatorSensorPlugin::verboseResultHistory in src/Plugin/monitoring/SensorPlugin/WatchdogAggregatorSensorPlugin.php
Adds history verbose output to the render array $output.
1 method overrides DatabaseAggregatorSensorPlugin::verboseResultHistory()
WatchdogAggregatorSensorPlugin::verboseResultHistory in src/Plugin/monitoring/SensorPlugin/WatchdogAggregatorSensorPlugin.php
Adds history verbose output to the render array $output.

File

src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php, line 292
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin.

Class

DatabaseAggregatorSensorPlugin
Database aggregator able to query a single db table.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function verboseResultHistory(array &$output) {
  $output['verbose_sensor_history'] = array(
    '#type' => 'verbose_table_result',
    '#title' => t('History'),
  );

  // Fetch the last 10 matching entries, aggregated.
  $query = $this
    ->getHistoryQuery();
  $query_result = $query
    ->range(0, 10)
    ->execute();
  $rows = $this
    ->buildTableRows($query_result
    ->fetchAll());

  // Reformat the timestamp.
  foreach ($rows as $key => $row) {
    $rows[$key]['timestamp'] = \Drupal::service('date.formatter')
      ->format($row['timestamp'], 'short');
  }
  $output['verbose_sensor_history']['#header'] = $this
    ->buildTableHeader($rows);
  $output['verbose_sensor_history']['#rows'] = $rows;

  // Show query.
  $output['verbose_sensor_history']['#query'] = $query_result
    ->getQueryString();
  $output['verbose_sensor_history']['#query_args'] = $query
    ->getArguments();

  // Add oldest record info message.
  if ($oldest_entry = $this
    ->getOldestEntry()) {
    $output['verbose_sensor_history']['#description'] = t('Oldest timestamp record is from :oldest_timestamp', [
      ':oldest_timestamp' => \Drupal::service('date.formatter')
        ->format($oldest_entry, 'short'),
    ]);
  }
}