You are here

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

File

src/Controller/Report/TopPages.php, line 112
Contains Drupal\visitors\Controller\Report\TopPages.

Class

TopPages

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(visitors_id)', 'count');
  $query
    ->addExpression('MIN(visitors_title)', 'visitors_title');
  $query
    ->addExpression('MIN(visitors_url)', 'visitors_url');
  $query
    ->fields('v', array(
    'visitors_path',
  ));
  visitors_date_filter_sql_condition($query);
  $query
    ->groupBy('visitors_path');
  $query
    ->orderByHeader($header);
  $query
    ->limit($items_per_page);
  $count_query = \Drupal::database()
    ->select('visitors', 'v');
  $count_query
    ->addExpression('COUNT(DISTINCT visitors_path)');
  visitors_date_filter_sql_condition($count_query);
  $query
    ->setCountQuery($count_query);
  $results = $query
    ->execute();
  $rows = array();
  $page = isset($_GET['page']) ? $_GET['page'] : 0;
  $i = 0 + $page * $items_per_page;

  //@TODO add links
  foreach ($results as $data) {
    $rows[] = array(
      ++$i,
      //SafeMarkup::checkPlain($data->visitors_title) . '<br/>' .$data->visitors_url,
      $data->visitors_url,
      // l($data->visitors_path, $data->visitors_url),
      $data->count,
    );
  }
  return $rows;
}