protected function Countries::_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 Countries::_getData()
- Countries::display in src/
Controller/ Report/ Countries.php - Returns a countries page.
File
- src/
Controller/ Report/ Countries.php, line 114 - Contains Drupal\visitors\Controller\Report\Countries.
Class
Namespace
Drupal\visitors\Controller\ReportCode
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_country_name)', 'count');
$query
->fields('v', array(
'visitors_country_name',
));
visitors_date_filter_sql_condition($query);
$query
->groupBy('visitors_country_name');
$query
->orderByHeader($header);
$query
->limit($items_per_page);
$count_query = \Drupal::database()
->select('visitors', 'v');
$count_query
->addExpression('COUNT(DISTINCT visitors_country_name)');
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;
foreach ($results as $data) {
if ($data->visitors_country_name == '') {
$data->visitors_country_name = '(none)';
}
$visitors_country_url = Url::fromRoute('visitors.cities', array(
"country" => $data->visitors_country_name,
));
$visitors_country_link = Link::fromTextAndUrl($this
->t($data->visitors_country_name), $visitors_country_url);
$visitors_country_link = $visitors_country_link
->toRenderable();
$rows[] = array(
++$i,
render($visitors_country_link),
$data->count,
);
}
return $rows;
}