You are here

protected function Hours::_getData in Visitors 8.2

Returns a table content.

Parameters

array $header: Table header configuration.

Return value

array Array representing the table content.

1 call to Hours::_getData()
Hours::display in src/Controller/Report/Hours.php
Returns a hours page.

File

src/Controller/Report/Hours.php, line 131
Contains Drupal\visitors\Controller\Report\Hours.

Class

Hours

Namespace

Drupal\visitors\Controller\Report

Code

protected function _getData($header) {
  $items_per_page = \Drupal::config('visitors.config')
    ->get('items_per_page');
  $query = \Drupal::database()
    ->select('visitors', 'v');
  $query
    ->addExpression('COUNT(*)', 'count');
  $query
    ->addExpression(visitors_date_format_sql('visitors_date_time', '%H'), 'hour');
  visitors_date_filter_sql_condition($query);
  $query
    ->groupBy('hour');
  if (!is_null($header)) {
    $query
      ->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')
      ->orderByHeader($header);
  }
  $results = $query
    ->execute();
  $rows = array();
  $i = 0;
  foreach ($results as $data) {
    $rows[] = array(
      ++$i,
      $data->hour,
      $data->count,
    );
  }
  return $rows;
}