2007-08-23 16:34:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2012-04-19 15:17:35 +00:00
|
|
|
* User page callbacks for the Statistics module.
|
2007-08-23 16:34:44 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-02 19:41:40 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
/**
|
|
|
|
* Page callback: Displays statistics for a node.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* A render array containing node statistics. If information for the node was
|
2012-06-02 19:41:40 +00:00
|
|
|
* not found, this will throw a NotFoundHttpException.
|
2012-04-19 15:17:35 +00:00
|
|
|
*
|
|
|
|
* @see statistics_menu()
|
|
|
|
*/
|
2007-08-23 16:34:44 +00:00
|
|
|
function statistics_node_tracker() {
|
|
|
|
if ($node = node_load(arg(1))) {
|
|
|
|
$header = array(
|
2012-10-09 19:49:07 +00:00
|
|
|
array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),
|
|
|
|
array('data' => t('Referrer'), 'field' => 'a.url'),
|
|
|
|
array('data' => t('User'), 'field' => 'u.name'),
|
|
|
|
t('Operations'),
|
|
|
|
);
|
2007-08-23 16:34:44 +00:00
|
|
|
|
2012-06-05 05:42:19 +00:00
|
|
|
$query = db_select('accesslog', 'a', array('target' => 'slave'))
|
|
|
|
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
2012-06-08 12:26:56 +00:00
|
|
|
->extend('Drupal\Core\Database\Query\TableSortExtender');
|
2009-04-13 10:40:13 +00:00
|
|
|
$query->join('users', 'u', 'a.uid = u.uid');
|
|
|
|
|
|
|
|
$query
|
|
|
|
->fields('a', array('aid', 'timestamp', 'url', 'uid'))
|
|
|
|
->fields('u', array('name'))
|
2009-04-19 18:51:37 +00:00
|
|
|
->condition(db_or()
|
|
|
|
->condition('a.path', 'node/' . $node->nid)
|
|
|
|
->condition('a.path', 'node/' . $node->nid . '/%', 'LIKE'))
|
2009-04-13 10:40:13 +00:00
|
|
|
->limit(30)
|
2009-05-22 11:33:18 +00:00
|
|
|
->orderByHeader($header);
|
2009-04-13 10:40:13 +00:00
|
|
|
|
|
|
|
$result = $query->execute();
|
2007-08-23 16:34:44 +00:00
|
|
|
$rows = array();
|
2009-04-13 10:40:13 +00:00
|
|
|
foreach ($result as $log) {
|
2012-10-09 19:49:07 +00:00
|
|
|
$row = array();
|
|
|
|
$row[] = array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap'));
|
|
|
|
$row[] = _statistics_link($log->url);
|
|
|
|
$row[] = theme('username', array('account' => $log));
|
|
|
|
$links = array();
|
|
|
|
$links['details'] = array(
|
|
|
|
'title' => t('details'),
|
|
|
|
'href' => "admin/reports/access/$log->aid",
|
|
|
|
);
|
|
|
|
$row[] = array(
|
|
|
|
'data' => array(
|
|
|
|
'#type' => 'operations',
|
|
|
|
'#links' => $links,
|
|
|
|
),
|
2009-04-19 18:51:37 +00:00
|
|
|
);
|
2012-10-09 19:49:07 +00:00
|
|
|
$rows[] = $row;
|
2007-08-23 16:34:44 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:07:00 +00:00
|
|
|
// Do not use $node->label() here, because $node comes from the database.
|
2010-01-09 21:54:01 +00:00
|
|
|
drupal_set_title($node->title);
|
2009-07-29 06:39:35 +00:00
|
|
|
$build['statistics_table'] = array(
|
2009-10-29 07:17:22 +00:00
|
|
|
'#theme' => 'table',
|
|
|
|
'#header' => $header,
|
2009-12-02 14:56:32 +00:00
|
|
|
'#rows' => $rows,
|
|
|
|
'#empty' => t('No statistics available.'),
|
2009-07-29 06:39:35 +00:00
|
|
|
);
|
|
|
|
$build['statistics_pager'] = array('#theme' => 'pager');
|
|
|
|
return $build;
|
2007-08-23 16:34:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-02 19:41:40 +00:00
|
|
|
throw new NotFoundHttpException();
|
2007-08-23 16:34:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
/**
|
|
|
|
* Page callback: Displays statistics for a user.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* A render array containing user statistics. If information for the user was
|
2012-06-02 19:41:40 +00:00
|
|
|
* not found, this will throw a NotFoundHttpException.
|
2012-04-19 15:17:35 +00:00
|
|
|
*
|
|
|
|
* @see statistics_menu()
|
|
|
|
*/
|
2007-08-23 16:34:44 +00:00
|
|
|
function statistics_user_tracker() {
|
2009-03-14 23:01:38 +00:00
|
|
|
if ($account = user_load(arg(1))) {
|
2007-08-23 16:34:44 +00:00
|
|
|
|
|
|
|
$header = array(
|
2012-10-09 19:49:07 +00:00
|
|
|
array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
|
|
|
|
array('data' => t('Page'), 'field' => 'path'),
|
|
|
|
t('Operations'),
|
|
|
|
);
|
2012-06-05 05:42:19 +00:00
|
|
|
$query = db_select('accesslog', 'a', array('target' => 'slave'))
|
|
|
|
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
2012-06-08 12:26:56 +00:00
|
|
|
->extend('Drupal\Core\Database\Query\TableSortExtender');
|
2009-04-13 10:40:13 +00:00
|
|
|
$query
|
|
|
|
->fields('a', array('aid', 'timestamp', 'path', 'title'))
|
|
|
|
->condition('uid', $account->uid)
|
|
|
|
->limit(30)
|
2009-05-22 11:33:18 +00:00
|
|
|
->orderByHeader($header);
|
2007-08-23 16:34:44 +00:00
|
|
|
|
2009-04-13 10:40:13 +00:00
|
|
|
$result = $query->execute();
|
2007-08-23 16:34:44 +00:00
|
|
|
$rows = array();
|
2009-04-13 10:40:13 +00:00
|
|
|
foreach ($result as $log) {
|
2012-10-09 19:49:07 +00:00
|
|
|
$row = array();
|
|
|
|
$row[] = array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap'));
|
|
|
|
$row[] = _statistics_format_item($log->title, $log->path);
|
|
|
|
$links = array();
|
|
|
|
$links['details'] = array(
|
|
|
|
'title' => t('details'),
|
|
|
|
'href' => "admin/reports/access/$log->aid",
|
|
|
|
);
|
|
|
|
$row[] = array(
|
|
|
|
'data' => array(
|
|
|
|
'#type' => 'operations',
|
|
|
|
'#links' => $links,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$rows[] = $row;
|
2007-08-23 16:34:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 02:18:26 +00:00
|
|
|
drupal_set_title(user_format_name($account));
|
2009-07-29 06:39:35 +00:00
|
|
|
$build['statistics_table'] = array(
|
2009-10-29 07:17:22 +00:00
|
|
|
'#theme' => 'table',
|
|
|
|
'#header' => $header,
|
2009-12-02 14:56:32 +00:00
|
|
|
'#rows' => $rows,
|
|
|
|
'#empty' => t('No statistics available.'),
|
2009-07-29 06:39:35 +00:00
|
|
|
);
|
|
|
|
$build['statistics_pager'] = array('#theme' => 'pager');
|
|
|
|
return $build;
|
2007-08-23 16:34:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-02 19:41:40 +00:00
|
|
|
throw new NotFoundHttpException();
|
2007-08-23 16:34:44 +00:00
|
|
|
}
|
|
|
|
}
|