Commit 2e53cfc1 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Initial view stats page


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 15f39474
......@@ -45,6 +45,9 @@ switch ($type) {
case 'groups':
$data = group_stats_table($limit, $offset);
break;
case 'views':
$data = view_stats_table($limit, $offset);
break;
case 'users':
default:
$data = user_stats_table($limit, $offset);
......
......@@ -49,6 +49,9 @@ switch ($type) {
case 'groups':
$data = group_statistics($limit, $offset);
break;
case 'views':
$data = view_statistics($limit, $offset);
break;
case 'users':
default:
$data = user_statistics($limit, $offset);
......
......@@ -437,4 +437,69 @@ function group_stats_table($limit, $offset) {
return $result;
}
function view_statistics($limit, $offset) {
$data = array();
$data['tableheadings'] = array(
'#',
get_string('view'),
get_string('Owner', 'view'),
get_string('visits'),
get_string('feedback', 'view'),
);
$data['table'] = view_stats_table($limit, $offset);
return $data;
}
function view_stats_table($limit, $offset) {
$count = count_records('view');
$pagination = build_pagination(array(
'id' => 'stats_pagination',
'url' => get_config('wwwroot') . 'admin/statistics.php?type=views',
'jsonscript' => 'admin/statistics.json.php',
'datatable' => 'statistics_table',
'count' => $count,
'limit' => $limit,
'offset' => $offset,
));
$result = array(
'tablerows' => '',
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
);
if ($count < 1) {
return $result;
}
$viewdata = get_records_sql_array(
"SELECT
v.id, v.title, v.owner, v.group, v.institution,
u.firstname, u.lastname,
COUNT(vf.*) AS comments
FROM {view} v
LEFT JOIN {view_feedback} vf ON v.id = vf.view
LEFT JOIN {usr} u ON v.owner = u.id
LEFT JOIN {group} g ON v.group = g.id
LEFT JOIN {institution} i ON v.institution = i.name
GROUP BY v.id, v.title, v.owner, v.group, v.institution,
u.firstname, u.lastname",
array(),
$offset,
$limit
);
foreach ($viewdata as &$v) {
$v->author = $v->owner ? display_name($v->owner) : null;
}
$smarty = smarty_core();
$smarty->assign('data', $viewdata);
$smarty->assign('offset', $offset);
$result['tablerows'] = $smarty->fetch('admin/viewstats.tpl');
return $result;
}
?>
\ No newline at end of file
{foreach from=$data item=item key=key}
<tr class="{cycle values='r0,r1'}">
<td>{$offset + $dwoo.foreach.default.iteration}</td>
<td><a href="{$WWWROOT}view/view.php?id={$item->id}">{$item->title}</a></td>
<td>{$item->author}</td>
<td></td>
<td>{$item->comments}</td>
</tr>
{/foreach}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment