protected function UserActivity::_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 UserActivity::_getData()
- UserActivity::display in src/
Controller/ Report/ UserActivity.php - Returns a user activity page.
File
- src/
Controller/ Report/ UserActivity.php, line 129 - Contains Drupal\visitors\Controller\Report\UserActivity.
Class
Namespace
Drupal\visitors\Controller\ReportCode
protected function _getData($header) {
$is_comment_module_exist = \Drupal::moduleHandler()
->moduleExists('comment');
$items_per_page = \Drupal::config('visitors.config')
->get('items_per_page');
$query = \Drupal::database()
->select('users_field_data', 'u')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->leftJoin('visitors', 'v', 'u.uid=v.visitors_uid');
$query
->leftJoin('node_field_data', 'nfd', 'nfd.uid=v.visitors_uid');
$query
->leftJoin('node', 'n', 'nfd.nid=n.nid');
if ($is_comment_module_exist) {
$query
->leftJoin('comment_field_data', 'c', 'u.uid=c.uid');
}
$query
->fields('u', array(
'name',
'uid',
));
$query
->addExpression('COUNT(DISTINCT v.visitors_id)', 'hits');
$query
->addExpression('COUNT(DISTINCT n.nid)', 'nodes');
if ($is_comment_module_exist) {
$query
->addExpression('COUNT(DISTINCT c.cid)', 'comments');
}
visitors_date_filter_sql_condition($query);
$query
->groupBy('u.name');
$query
->groupBy('u.uid');
$query
->groupBy('v.visitors_uid');
$query
->groupBy('nfd.uid');
if ($is_comment_module_exist) {
$query
->groupBy('c.uid');
}
$query
->orderByHeader($header);
$query
->limit($items_per_page);
$count_query = \Drupal::database()
->select('users_field_data', 'u');
$count_query
->leftJoin('visitors', 'v', 'u.uid=v.visitors_uid');
$count_query
->addExpression('COUNT(DISTINCT u.uid)');
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) {
$user = \Drupal::entityTypeManager()
->getStorage('user')
->load($data->uid);
if ($is_comment_module_exist) {
$rows[] = array(
++$i,
$user
->id() == 0 ? 'Anonymous User' : $user
->getAccountName(),
$data->hits,
$data->nodes,
$data->comments,
);
}
else {
$rows[] = array(
++$i,
$user
->id() == 0 ? 'Anonymous User' : $user
->getAccountName(),
$data->hits,
$data->nodes,
);
}
}
return $rows;
}