Commit 109f669c authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add institution members graph


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 31426271
......@@ -33,13 +33,14 @@ $type = param_alpha('type');
switch ($type) {
case 'weekly':
case 'institutions':
$maxage = 3600;
header('Content-type: ' . 'image/png');
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
readfile(get_config('dataroot') . 'weekly.png');
readfile(get_config('dataroot') . $type . '.png');
exit;
}
......
......@@ -337,49 +337,17 @@ if ($institution || $add) {
}
else {
// Get a list of institutions
require_once(get_config('libroot') . 'institution.php');
if (!$USER->get('admin')) { // Filter the list for institutional admins
$where = '
WHERE ii.name IN (' . join(',', array_map('db_quote', $USER->get('admininstitutions'))) . ')';
$filter = $USER->get('admininstitutions');
$showdefault = false;
}
else {
$where = '';
$smarty->assign('siteadmin', true);
$defaultinstmembers = count_records_sql('
SELECT COUNT(u.id) FROM {usr} u LEFT OUTER JOIN {usr_institution} i ON u.id = i.usr
WHERE u.deleted = 0 AND i.usr IS NULL AND u.id != 0
');
}
$institutions = get_records_sql_assoc('
SELECT
ii.name,
ii.displayname,
ii.maxuseraccounts,
ii.suspended,
COALESCE(a.members, 0) AS members,
COALESCE(a.staff, 0) AS staff,
COALESCE(a.admins, 0) AS admins
FROM
{institution} ii
LEFT JOIN
(SELECT
i.name, i.displayname, i.maxuseraccounts,
COUNT(ui.usr) AS members, SUM(ui.staff) AS staff, SUM(ui.admin) AS admins
FROM
{institution} i
LEFT OUTER JOIN {usr_institution} ui ON (ui.institution = i.name)
LEFT OUTER JOIN {usr} u ON (u.id = ui.usr)
WHERE
(u.deleted = 0 OR u.id IS NULL)
GROUP BY
i.name, i.displayname, i.maxuseraccounts
) a ON (a.name = ii.name)' . $where . '
ORDER BY
ii.name = \'mahara\', ii.displayname', array());
if (isset($defaultinstmembers)) {
$institutions['mahara']->members = $defaultinstmembers;
$institutions['mahara']->staff = '';
$institutions['mahara']->admins = '';
$filter = false;
$showdefault = true;
}
$institutions = Institution::count_members($filter, $showdefault);
$smarty->assign('institutions', $institutions);
}
......
......@@ -437,6 +437,53 @@ class Institution {
public function isFull() {
return ($this->maxuseraccounts != '') && ($this->countMembers() >= $this->maxuseraccounts);
}
public static function count_members($filter, $showdefault) {
if ($filter) {
$where = '
WHERE ii.name IN (' . join(',', array_map('db_quote', $filter)) . ')';
}
else {
$where = '';
}
$institutions = get_records_sql_assoc('
SELECT
ii.name,
ii.displayname,
ii.maxuseraccounts,
ii.suspended,
COALESCE(a.members, 0) AS members,
COALESCE(a.staff, 0) AS staff,
COALESCE(a.admins, 0) AS admins
FROM
{institution} ii
LEFT JOIN
(SELECT
i.name, i.displayname, i.maxuseraccounts,
COUNT(ui.usr) AS members, SUM(ui.staff) AS staff, SUM(ui.admin) AS admins
FROM
{institution} i
LEFT OUTER JOIN {usr_institution} ui ON (ui.institution = i.name)
LEFT OUTER JOIN {usr} u ON (u.id = ui.usr)
WHERE
(u.deleted = 0 OR u.id IS NULL)
GROUP BY
i.name, i.displayname, i.maxuseraccounts
) a ON (a.name = ii.name)' . $where . '
ORDER BY
ii.name = \'mahara\', ii.displayname', array());
if ($showdefault) {
$defaultinstmembers = count_records_sql('
SELECT COUNT(u.id) FROM {usr} u LEFT OUTER JOIN {usr_institution} i ON u.id = i.usr
WHERE u.deleted = 0 AND i.usr IS NULL AND u.id != 0
');
$institutions['mahara']->members = $defaultinstmembers;
$institutions['mahara']->staff = '';
$institutions['mahara']->admins = '';
}
return $institutions;
}
}
function get_institution_selector($includedefault = true) {
......
......@@ -2432,6 +2432,8 @@ function cron_site_data_daily() {
unlink($viewlog . '.temp');
}
graph_site_data_daily();
}
function build_portfolio_search_html(&$data) {
......
......@@ -352,6 +352,10 @@ function user_statistics($limit, $offset, &$sitedata) {
display_size($maxquotaused->quotaused)
);
if (file_exists(get_config('dataroot') . 'institutions.png')) {
$data['institutions'] = get_config('wwwroot') . 'admin/thumb.php?type=institutions';
}
$smarty = smarty_core();
$smarty->assign('data', $data);
$data['summary'] = $smarty->fetch('admin/userstatssummary.tpl');
......@@ -702,4 +706,37 @@ function graph_site_data_weekly() {
$Graph->done(array('filename' => get_config('dataroot') . 'weekly.png'));
}
function graph_site_data_daily() {
// Bar graph of number of users in each institution
require_once(get_config('libroot') . 'institution.php');
$institutions = Institution::count_members(false, true);
if (count($institutions) > 1) {
$dataarray = array();
foreach ($institutions as &$i) {
$dataarray[$i->displayname] = $i->members;
}
arsort($dataarray);
require_once(get_config('libroot') . "pear/Image/Graph.php");
$Graph =& Image_Graph::factory('graph', array(300, 200));
$Font =& $Graph->addNew('font', 'Vera');
$Font->setSize(8);
$Graph->setFont($Font);
$Graph->add(
$Plotarea = Image_Graph::factory('plotarea')
);
$Dataset =& Image_Graph::factory('dataset', array($dataarray));
$Plot =& $Plotarea->addNew('bar', array(&$Dataset));
$Plot->setLineColor('gray');
$Plot->setFillColor('blue@0.2');
$Graph->done(array('filename' => get_config('dataroot') . 'institutions.png'));
}
// @todo: Pie graph of views broken down by view type.
}
?>
......@@ -5,6 +5,8 @@
<li>{$data.strmaxgroups}</li>
<li>{$data.strmaxquotaused}</li>
</ul>
{if $data.institutions}
<img src="{$data.institutions}" alt="" />
{/if}
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