You are here

protected function Referers::_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 Referers::_getData()
Referers::display in src/Controller/Report/Referers.php
Returns a referers page.

File

src/Controller/Report/Referers.php, line 119
Contains Drupal\visitors\Controller\Report\Referers.

Class

Referers

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')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
  $query
    ->addExpression('COUNT(*)', 'count');
  $query
    ->fields('v', array(
    'visitors_referer',
  ));
  visitors_date_filter_sql_condition($query);
  $this
    ->_setReferersCondition($query);
  $query
    ->groupBy('visitors_referer');
  $query
    ->orderByHeader($header);
  $query
    ->limit($items_per_page);
  $count_query = \Drupal::database()
    ->select('visitors', 'v');
  $count_query
    ->addExpression('COUNT(DISTINCT visitors_referer)');
  visitors_date_filter_sql_condition($count_query);
  $this
    ->_setReferersCondition($count_query);
  $query
    ->setCountQuery($count_query);
  $results = $query
    ->execute();
  $rows = array();
  $page = isset($_GET['page']) ? (int) $_GET['page'] : '';
  $i = 0 + $page * $items_per_page;
  foreach ($results as $data) {
    $rows[] = array(
      ++$i,
      empty($data->visitors_referer) ? $this
        ->t('No Referer') : $data->visitors_referer,
      $data->count,
    );
  }
  return $rows;
}