Commit 57b46549 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1691910: Consolidating the admin and institution statistics pages



Making the admin/statistics.php obsolete and getting admin/users/statistics.php
to do the work.

The institution 'all' shows the site statistics

Sponsored by University of Sussex and Dublin City University

behatnotneeded

Change-Id: Ic2fb9d4ef355fdc5e5527c1ce776463d821c0c08
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 75f4fd25
...@@ -17,7 +17,7 @@ define('SECTION_PLUGINNAME', 'admin'); ...@@ -17,7 +17,7 @@ define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'index'); define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)).'/init.php'); require(dirname(dirname(__FILE__)).'/init.php');
require(get_config('libroot') . 'registration.php'); require(get_config('libroot') . 'statistics.php');
if (get_config('installed')) { if (get_config('installed')) {
define('TITLE', get_string('administration', 'admin')); define('TITLE', get_string('administration', 'admin'));
validate_theme(get_config('theme')); validate_theme(get_config('theme'));
...@@ -26,7 +26,6 @@ else { ...@@ -26,7 +26,6 @@ else {
define('TITLE', get_string('installation', 'admin')); define('TITLE', get_string('installation', 'admin'));
} }
require(get_config('libroot') . 'upgrade.php'); require(get_config('libroot') . 'upgrade.php');
require_once(get_config('libroot') . 'registration.php');
$upgrades = check_upgrades(); $upgrades = check_upgrades();
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('STAFF', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require(get_config('libroot') . 'registration.php');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$extradata = json_decode(param_variable('extradata'));
$type = param_alpha('type', 'users');
$subpages = array('users', 'groups', 'views', 'content', 'historical', 'institutions', 'logins');
if (!in_array($type, $subpages)) {
$type = 'users';
}
if ($type == 'historical') {
$field = (isset($extradata->field) ? $extradata->field : 'count_usr');
}
if ($type == 'institutions' || $type == 'logins') {
$sort = (isset($extradata->sort) ? $extradata->sort : 'displayname');
$sortdesc = (isset($extradata->sortdesc) ? $extradata->sortdesc : false);
$start = param_alphanumext('start', null);
$end = param_alphanumext('end', null);
}
switch ($type) {
case 'logins':
$data = institution_logins_statistics($limit, $offset, $sort, $sortdesc, $start, $end);
$data = $data['table'];
break;
case 'institutions':
$data = institution_comparison_stats_table($limit, $offset, $sort, $sortdesc);
break;
case 'historical':
$data = historical_stats_table($limit, $offset, $field);
break;
case 'content':
$data = content_stats_table($limit, $offset);
break;
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);
}
json_reply(false, (object) array('message' => false, 'data' => $data));
<?php
/**
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('STAFF', 1);
define('MENUITEM', 'adminhome/statistics');
require(dirname(dirname(__FILE__)).'/init.php');
require(get_config('libroot') . 'registration.php');
define('TITLE', get_string('sitestatistics', 'admin'));
$type = param_alpha('type', 'users');
$subpages = array('users', 'groups', 'views', 'content', 'historical', 'institutions', 'logins');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
if (!in_array($type, $subpages)) {
$type = 'users';
}
if ($type == 'historical') {
$field = param_alphanumext('field', 'count_usr');
}
if ($type == 'institutions' || $type == 'logins') {
$sort = param_alphanumext('sort', 'displayname');
$sortdesc = param_boolean('sortdesc');
$start = param_alphanumext('start', null);
$end = param_alphanumext('end', null);
}
$sitedata = site_statistics(true);
switch ($type) {
case 'logins':
$data = institution_logins_statistics($limit, $offset, $sort, $sortdesc, $start, $end);
break;
case 'institutions':
$data = institution_comparison_statistics($limit, $offset, $sort, $sortdesc);
break;
case 'historical':
$data = historical_statistics($limit, $offset, $field);
break;
case 'content':
$data = content_statistics($limit, $offset);
break;
case 'groups':
$data = group_statistics($limit, $offset);
break;
case 'views':
$data = view_statistics($limit, $offset);
break;
case 'users':
default:
$data = user_statistics($limit, $offset, $sitedata);
}
$js = <<< EOF
jQuery(function() {
{$data['table']['pagination_js']}
});
EOF;
$smarty = smarty(array('paginator','js/chartjs/Chart.min.js'));
setpageicon($smarty, 'icon-area-chart');
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('sitedata', $sitedata);
$smarty->assign('type', $type);
$smarty->assign('subpages', $subpages);
$smarty->assign('subpagedata', $data);
$smarty->display('admin/statistics.tpl');
...@@ -14,38 +14,33 @@ define('INSTITUTIONALSTAFF', 1); ...@@ -14,38 +14,33 @@ define('INSTITUTIONALSTAFF', 1);
define('JSON', 1); define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php'); require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require(get_config('libroot') . 'registration.php'); require(get_config('libroot') . 'statistics.php');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$extradata = json_decode(param_variable('extradata')); $extradata = json_decode(param_variable('extradata'));
$institution = (isset($extradata->institution) ? $extradata->institution : 'mahara'); $institution = param_alphanum('institution', null);
if (empty($institution)) {
$type = param_alpha('type', 'users'); if (isset($extradata->institution)) {
$subpages = array('users', 'views', 'content', 'historical'); $institution = $extradata->institution;
if (!in_array($type, $subpages)) { }
$type = 'users'; else if ($USER->get('admin') || $USER->get('staff')) {
} $institution = 'all';
}
if ($type == 'historical') { else {
$field = (isset($extradata->field) ? $extradata->field : 'count_members'); $institution = 'mahara';
}
} }
$institutiondata = institution_statistics($institution, true); $type = param_alpha('type', 'users');
$extraparams = new stdClass();
switch ($type) { $extraparams->type = $type;
case 'historical': $extraparams->offset = param_integer('offset', 0);
$data = institution_historical_stats_table($limit, $offset, $field, $institutiondata); $extraparams->limit = param_integer('limit', 10);
break; $extraparams->sort = isset($extradata->sort) ? $extradata->sort : 'displayname';
case 'content': $extraparams->sortdesc = isset($extradata->sortdesc) ? true : false;
$data = institution_content_stats_table($limit, $offset, $institutiondata); $extraparams->start = param_alphanumext('start', null);
break; $extraparams->end = param_alphanumext('end', null);
case 'views': $extraparams->field = isset($extradata->field) ? $extradata->field : (($institution == 'all') ? 'count_usr' : 'count_members');
$data = institution_view_stats_table($limit, $offset, $institutiondata);
break; list($subpages, $institutiondata, $subpagedata) = display_statistics($institution, $type, $extraparams);
case 'users':
default: json_reply(false, (object) array('message' => false, 'data' => $subpagedata['table']));
$data = institution_user_stats_table($limit, $offset, $institutiondata);
}
json_reply(false, (object) array('message' => false, 'data' => $data));
...@@ -14,7 +14,7 @@ define('INSTITUTIONALSTAFF', 1); ...@@ -14,7 +14,7 @@ define('INSTITUTIONALSTAFF', 1);
define('MENUITEM', 'manageinstitutions/statistics'); define('MENUITEM', 'manageinstitutions/statistics');
require(dirname(dirname(dirname(__FILE__))).'/init.php'); require(dirname(dirname(dirname(__FILE__))).'/init.php');
require(get_config('libroot') . 'registration.php'); require(get_config('libroot') . 'statistics.php');
require_once('institution.php'); require_once('institution.php');
if (!is_logged_in()) { if (!is_logged_in()) {
...@@ -31,7 +31,7 @@ if (!empty($institution)) { ...@@ -31,7 +31,7 @@ if (!empty($institution)) {
} }
if (!$notallowed) { if (!$notallowed) {
$institutionelement = get_institution_selector(true, false, true, get_config('staffstats')); $institutionelement = get_institution_selector(true, false, true, get_config('staffstats'), ($USER->get('admin') || $USER->get('staff')));
} }
if (empty($institutionelement) || $notallowed) { if (empty($institutionelement) || $notallowed) {
...@@ -47,6 +47,7 @@ if (!$institution || !$USER->can_edit_institution($institution, true)) { ...@@ -47,6 +47,7 @@ if (!$institution || !$USER->can_edit_institution($institution, true)) {
else if (!empty($institution)) { else if (!empty($institution)) {
$institutionelement['defaultvalue'] = $institution; $institutionelement['defaultvalue'] = $institution;
} }
$institutionselector = pieform(array( $institutionselector = pieform(array(
'name' => 'usertypeselect', 'name' => 'usertypeselect',
'class' => 'form-inline', 'class' => 'form-inline',
...@@ -55,42 +56,32 @@ $institutionselector = pieform(array( ...@@ -55,42 +56,32 @@ $institutionselector = pieform(array(
) )
)); ));
define('TITLE', get_string('institutionstatisticsfor', 'admin', get_field('institution', 'displayname', 'name', $institution))); $showall = ($institution == 'all') ? true : false;
if ($showall) {
$type = param_alpha('type', 'users'); define('TITLE', get_string('statisticsforallinstitutions', 'admin'));
$subpages = array('users', 'views', 'content', 'historical'); $icon = 'icon-area-chart';
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
if (!in_array($type, $subpages)) {
$type = 'users';
} }
else {
if ($type == 'historical') { define('TITLE', get_string('institutionstatisticsfor', 'admin', get_field('institution', 'displayname', 'name', $institution)));
$field = param_alphanumext('field', 'count_members'); $icon = 'icon-university';
} }
$institutiondata = institution_statistics($institution, true); $type = param_alpha('type', 'users');
$extraparams = new stdClass();
switch ($type) { $extraparams->type = $type;
case 'historical': $extraparams->offset = param_integer('offset', 0);
$data = institution_historical_statistics($limit, $offset, $field, $institutiondata); $extraparams->limit = param_integer('limit', 10);
break; $extraparams->sort = param_alphanumext('sort', 'displayname');
case 'content': $extraparams->sortdesc = param_boolean('sortdesc');
$data = institution_content_statistics($limit, $offset, $institutiondata); $extraparams->start = param_alphanumext('start', null);
break; $extraparams->end = param_alphanumext('end', null);
case 'views':
$data = institution_view_statistics($limit, $offset, $institutiondata); list($subpages, $institutiondata, $subpagedata) = display_statistics($institution, $type, $extraparams);
break;
case 'users':
default:
$data = institution_user_statistics($limit, $offset, $institutiondata);
}
$wwwroot = get_config('wwwroot'); $wwwroot = get_config('wwwroot');
$js = <<< EOF $js = <<< EOF
jQuery(function ($) { jQuery(function ($) {
{$data['table']['pagination_js']} {$subpagedata['table']['pagination_js']}
function reloadStats() { function reloadStats() {
window.location.href = '{$wwwroot}admin/users/statistics.php?institution='+$('#usertypeselect_institution').val() +'&type={$type}'; window.location.href = '{$wwwroot}admin/users/statistics.php?institution='+$('#usertypeselect_institution').val() +'&type={$type}';
...@@ -101,15 +92,14 @@ jQuery(function ($) { ...@@ -101,15 +92,14 @@ jQuery(function ($) {
EOF; EOF;
$smarty = smarty(array('paginator','js/chartjs/Chart.min.js')); $smarty = smarty(array('paginator','js/chartjs/Chart.min.js'));
setpageicon($smarty, 'icon-university'); setpageicon($smarty, $icon);
$smarty->assign('INLINEJAVASCRIPT', $js); $smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('institutiondata', $institutiondata); $smarty->assign('institutiondata', $institutiondata);
$smarty->assign('type', $type); $smarty->assign('type', $type);
$smarty->assign('subpages', $subpages); $smarty->assign('subpages', $subpages);
$smarty->assign('showall', ($showall ? '_all' : ''));
$smarty->assign('subpagedata', $data); $smarty->assign('subpagedata', $subpagedata);
$smarty->assign('institutionselector', $institutionselector); $smarty->assign('institutionselector', $institutionselector);
$smarty->display('admin/users/statistics.tpl'); $smarty->display('admin/users/statistics.tpl');
...@@ -20,8 +20,9 @@ if (!defined('CRON')) { ...@@ -20,8 +20,9 @@ if (!defined('CRON')) {
json_headers(); json_headers();
$validtypes = array('Line', 'Bar', 'Radar', 'PolarArea', 'Pie', 'Doughnut'); $validtypes = array('Line', 'Bar', 'Radar', 'PolarArea', 'Pie', 'Doughnut');
$type = ucfirst(param_alphanum('type', false)); $search_array = array_combine(array_map('strtolower', $validtypes), $validtypes);
if (!in_array($type, $validtypes)) { $type = strtolower(param_alphanum('type', false));
if (empty($search_array[$type])) {
json_reply('missingparameter', '\'' . $type . '\' is not a valid graph type'); json_reply('missingparameter', '\'' . $type . '\' is not a valid graph type');
} }
$graph = param_alphanumext('graph', null); $graph = param_alphanumext('graph', null);
...@@ -31,13 +32,13 @@ if (!defined('CRON')) { ...@@ -31,13 +32,13 @@ if (!defined('CRON')) {
$extradata = json_decode($extradata); $extradata = json_decode($extradata);
require_once(get_config('libroot') . 'graph.php'); require_once(get_config('libroot') . 'graph.php');
require_once(get_config('libroot') . 'registration.php'); require_once(get_config('libroot') . 'statistics.php');
if (!function_exists($graph) || !in_array($graph, allowed_graph_functions())) { if (!function_exists($graph) || !in_array($graph, allowed_graph_functions())) {
json_reply('invalidparameter', 'Cannot call graph function \'' . $graph . '\''); json_reply('invalidparameter', 'Cannot call graph function \'' . $graph . '\'');
} }
else { else {
$data = ($extradata) ? $graph($type, $extradata) : $graph($type); $data = ($extradata) ? $graph($search_array[$type], $extradata) : $graph($search_array[$type]);
if (empty($data)) { if (empty($data)) {
$data['empty'] = true; $data['empty'] = true;
json_reply(false, array('data' => $data)); json_reply(false, array('data' => $data));
......
...@@ -266,8 +266,7 @@ $string['reopensitedetail'] = 'Your site is closed. Site administrators may stay ...@@ -266,8 +266,7 @@ $string['reopensitedetail'] = 'Your site is closed. Site administrators may stay
// Statistics // Statistics
$string['siteinformation'] = 'Site information'; $string['siteinformation'] = 'Site information';
$string['viewfullsitestatistics'] = 'View full site statistics'; $string['viewfullsitestatistics'] = 'View full site statistics';
$string['sitestatistics'] = 'Site statistics'; $string['institutioncreated_all'] = 'Site installed';
$string['siteinstalled'] = 'Site installed';
$string['databasesize'] = 'Database size'; $string['databasesize'] = 'Database size';
$string['diskusage'] = 'Disk usage'; $string['diskusage'] = 'Disk usage';
$string['maharaversion'] = 'Mahara version'; $string['maharaversion'] = 'Mahara version';
...@@ -1307,3 +1306,5 @@ $string['cli_lang_branch'] = 'Mahara series version to fetch langpacks for serie ...@@ -1307,3 +1306,5 @@ $string['cli_lang_branch'] = 'Mahara series version to fetch langpacks for serie
$string['withselectedcontentexport'] = 'Re-queue items into the export queue'; $string['withselectedcontentexport'] = 'Re-queue items into the export queue';
$string['withselectedcontentdelete'] = 'Delete selected items from the export queue'; $string['withselectedcontentdelete'] = 'Delete selected items from the export queue';
$string['statisticsforallinstitutions'] = 'Statistics for all institutions';
\ No newline at end of file
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
<h3>Login statistics</h3> <h3>Login statistics</h3>
<p>By default you see the logins for the previous calendar month. If you view this page in April, you will see the results for March.</p> <p>By default you see the logins for the previous calendar month. If you view this page in April, you will see the results for March.</p>
<p>To alter the results time period you can add a <strong>'start'</strong> and an <strong>'end'</strong> option to the URL, e.g.</p> <p>To alter the results time period you can add a <strong>'start'</strong> and an <strong>'end'</strong> option to the URL, e.g.</p>
<p>'admin/statistics.php?type=logins&start=2015-01-01&end=2015-04-30'</p> <p>'admin/users/statistics.php?type=logins&start=2015-01-01&end=2015-04-30'</p>
<p>This will return the results for the 4-month period of 1 January to 30 April 2015.</p> <p>This will return the results for the 4-month period of 1 January to 30 April 2015.</p>
...@@ -5000,5 +5000,10 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -5000,5 +5000,10 @@ function xmldb_core_upgrade($oldversion=0) {
} }
} }
if ($oldversion < 2017052900) {
log_debug('Clear menu cache for removal of menu items');
clear_menu_cache();
}
return $status; return $status;
} }
...@@ -840,7 +840,18 @@ class Institution { ...@@ -840,7 +840,18 @@ class Institution {
} }
} }
function get_institution_selector($includedefault = true, $assumesiteadmin=false, $includesitestaff=false, $includeinstitutionstaff=false) { /**
* Returns an institution dropdown selector
*
* @param bool $includedefault To include the 'mahara' institution in list
* @param bool $assumesiteadmin To call this function like you had site admin privileges
* @param bool $includesitestaff To allow site staff to see dropdown like the site admin would
* @param bool $includeinstitutionstaff To allow institution staff to see dropdown like institution admin would
* @param bool $allselector To add an 'all' option to the dropdown where it makes sense, eg in institution statistics page
*
* @return null or array suitable for pieform element
*/
function get_institution_selector($includedefault = true, $assumesiteadmin=false, $includesitestaff=false, $includeinstitutionstaff=false, $allselector=false) {
global $USER; global $USER;
if (($assumesiteadmin || $USER->get('admin')) || ($includesitestaff && $USER->get('staff'))) { if (($assumesiteadmin || $USER->get('admin')) || ($includesitestaff && $USER->get('staff'))) {
...@@ -883,6 +894,9 @@ function get_institution_selector($includedefault = true, $assumesiteadmin=false ...@@ -883,6 +894,9 @@ function get_institution_selector($includedefault = true, $assumesiteadmin=false
} }
$options = array(); $options = array();
if ($allselector) {
$options['all'] = get_string('Allinstitutions', 'mahara');
}
foreach ($institutions as $i) { foreach ($institutions as $i) {
$options[$i->name] = $i->displayname; $options[$i->name] = $i->displayname;
} }
......
...@@ -4085,7 +4085,7 @@ function cron_institution_registration_data() { ...@@ -4085,7 +4085,7 @@ function cron_institution_registration_data() {
* Cronjob to save weekly site data locally * Cronjob to save weekly site data locally
*/ */
function cron_site_data_weekly() { function cron_site_data_weekly() {
require_once(get_config('libroot') . 'registration.php'); require_once(get_config('libroot') . 'statistics.php');
$current = site_data_current(); $current = site_data_current();
$time = db_format_timestamp(time()); $time = db_format_timestamp(time());
...@@ -4107,7 +4107,7 @@ function cron_site_data_weekly() { ...@@ -4107,7 +4107,7 @@ function cron_site_data_weekly() {
} }
function cron_site_data_daily() { function cron_site_data_daily() {
require_once(get_config('libroot') . 'registration.php'); require_once(get_config('libroot') . 'statistics.php');
$current = site_data_current(); $current = site_data_current();
$time = db_format_timestamp(time()); $time = db_format_timestamp(time());
...@@ -4191,7 +4191,7 @@ function cron_site_data_daily() { ...@@ -4191,7 +4191,7 @@ function cron_site_data_daily() {
} }
function cron_institution_data_weekly() { function cron_institution_data_weekly() {
require_once(get_config('libroot') . 'registration.php'); require_once(get_config('libroot') . 'statistics.php');
foreach (get_column('institution', 'name') as $institution) { foreach (get_column('institution', 'name') as $institution) {
$current = institution_data_current($institution); $current = institution_data_current($institution);
$time = db_format_timestamp(time()); $time = db_format_timestamp(time());
...@@ -4214,7 +4214,7 @@ function cron_institution_data_weekly() { ...@@ -4214,7 +4214,7 @@ function cron_institution_data_weekly() {
} }
function cron_institution_data_daily() { function cron_institution_data_daily() {
require_once(get_config('libroot') . 'registration.php'); require_once(get_config('libroot') . 'statistics.php');
foreach (get_column('institution', 'name') as $institution) { foreach (get_column('institution', 'name') as $institution) {
$current = institution_data_current($institution); $current = institution_data_current($institution);
$time = db_format_timestamp(time()); $time = db_format_timestamp(time());
......
This diff is collapsed.
This diff is collapsed.
...@@ -16,7 +16,7 @@ $config = new stdClass(); ...@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy // See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date. // For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2017052300; $config->version = 2017052900;
$config->series = '17.10'; $config->series = '17.10';
$config->release = '17.10dev'; $config->release = '17.10dev';
$config->minupgradefrom = 2012080604; $config->minupgradefrom = 2012080604;
......
...@@ -2301,12 +2301,6 @@ function admin_nav() { ...@@ -2301,12 +2301,6 @@ function admin_nav() {
'title' => get_string('register'), 'title' => get_string('register'),
'weight' => 20, 'weight' => 20,
), ),
'adminhome/statistics' => array(
'path' => 'adminhome/statistics',
'url' => 'admin/statistics.php',