コード例 #1
0
ファイル: registration.php プロジェクト: kienv/mahara
function institution_user_statistics($limit, $offset, &$institutiondata)
{
    $data = array();
    $data['institution'] = $institutiondata['institution'];
    $data['tableheadings'] = array(array('name' => get_string('date')), array('name' => get_string('Loggedin', 'admin'), 'class' => 'center'), array('name' => get_string('Joined', 'group'), 'class' => 'center'), array('name' => get_string('Total'), 'class' => 'center'));
    $data['table'] = institution_user_stats_table($limit, $offset, $institutiondata);
    $data['tabletitle'] = get_string('userstatstabletitle', 'admin');
    if (!$institutiondata['users']) {
        $data['strmaxfriends'] = get_string('statsnofriends', 'admin');
        $data['strmaxviews'] = get_string('statsnoviews', 'admin');
        $data['strmaxgroups'] = get_string('statsnogroups', 'admin');
        $data['strmaxquotaused'] = get_string('statsnoquota', 'admin');
        $smarty = smarty_core();
        $smarty->assign('data', $data);
        $data['summary'] = $smarty->fetch('admin/institutionuserstatssummary.tpl');
        return $data;
    }
    $maxfriends = get_records_sql_array("\n        SELECT u.id, u.firstname, u.lastname, u.preferredname, u.urlid, SUM(f.friends) AS friends\n        FROM {usr} u INNER JOIN (\n            SELECT DISTINCT(usr1) AS id, COUNT(usr1) AS friends\n            FROM {usr_friend}\n            GROUP BY usr1\n            UNION SELECT DISTINCT(usr2) AS id, COUNT(usr2) AS friends\n            FROM {usr_friend}\n            GROUP BY usr2\n        ) f ON u.id = f.id\n        WHERE u.id IN (" . join(',', array_fill(0, $institutiondata['users'], '?')) . ")\n        GROUP BY u.id, u.firstname, u.lastname, u.preferredname, u.urlid\n        ORDER BY friends DESC\n        LIMIT 1", $institutiondata['members']);
    $maxfriends = $maxfriends[0];
    $meanfriends = count_records_sql('SELECT COUNT(*) FROM
                (SELECT * FROM {usr_friend}
                    WHERE usr1 IN (' . join(',', array_fill(0, $institutiondata['users'], '?')) . ')
                UNION ALL SELECT * FROM {usr_friend}
                    WHERE usr2 IN (' . join(',', array_fill(0, $institutiondata['users'], '?')) . ')
                ) tmp', array_merge($institutiondata['members'], $institutiondata['members'])) / $institutiondata['users'];
    if ($maxfriends) {
        $data['strmaxfriends'] = get_string('statsmaxfriends1', 'admin', round($meanfriends, 1), profile_url($maxfriends), hsc(display_name($maxfriends, null, true)), $maxfriends->friends);
    } else {
        $data['strmaxfriends'] = get_string('statsnofriends', 'admin');
    }
    $maxviews = get_records_sql_array("\n        SELECT u.id, u.firstname, u.lastname, u.preferredname, u.urlid, COUNT(v.id) AS views\n        FROM {usr} u JOIN {view} v ON u.id = v.owner\n        WHERE \"owner\" IN (" . join(',', array_fill(0, $institutiondata['users'], '?')) . ")\n        GROUP BY u.id, u.firstname, u.lastname, u.preferredname, u.urlid\n        ORDER BY views DESC\n        LIMIT 1", $institutiondata['members']);
    $maxviews = $maxviews[0];
    if ($maxviews) {
        $data['strmaxviews'] = get_string('statsmaxviews1', 'admin', $institutiondata['viewsperuser'], profile_url($maxviews), hsc(display_name($maxviews, null, true)), $maxviews->views);
    } else {
        $data['strmaxviews'] = get_string('statsnoviews', 'admin');
    }
    $maxgroups = get_records_sql_array("\n        SELECT u.id, u.firstname, u.lastname, u.preferredname, u.urlid, COUNT(m.group) AS groups\n        FROM {usr} u JOIN {group_member} m ON u.id = m.member JOIN {group} g ON m.group = g.id\n        WHERE g.deleted = 0 AND u.id IN (" . join(',', array_fill(0, $institutiondata['users'], '?')) . ")\n        GROUP BY u.id, u.firstname, u.lastname, u.preferredname, u.urlid\n        ORDER BY groups DESC\n        LIMIT 1", $institutiondata['members']);
    $maxgroups = $maxgroups[0];
    if ($maxgroups) {
        $data['strmaxgroups'] = get_string('statsmaxgroups1', 'admin', $institutiondata['groupmemberaverage'], profile_url($maxgroups), hsc(display_name($maxgroups, null, true)), $maxgroups->groups);
    } else {
        $data['strmaxgroups'] = get_string('statsnogroups', 'admin');
    }
    $maxquotaused = get_records_sql_array("\n        SELECT id, firstname, lastname, preferredname, urlid, quotaused\n        FROM {usr}\n        WHERE id IN (" . join(',', array_fill(0, $institutiondata['users'], '?')) . ")\n        ORDER BY quotaused DESC\n        LIMIT 1", $institutiondata['members']);
    $maxquotaused = $maxquotaused[0];
    $avgquota = get_field_sql("\n        SELECT AVG(quotaused)\n        FROM {usr}\n        WHERE id IN (" . join(',', array_fill(0, $institutiondata['users'], '?')) . ")\n        ", $institutiondata['members']);
    $data['strmaxquotaused'] = get_string('statsmaxquotaused1', 'admin', display_size($avgquota), profile_url($maxquotaused), hsc(display_name($maxquotaused, null, true)), display_size($maxquotaused->quotaused));
    $smarty = smarty_core();
    $smarty->assign('data', $data);
    $data['summary'] = $smarty->fetch('admin/institutionuserstatssummary.tpl');
    return $data;
}
コード例 #2
0
define('JSON', 1);
require dirname(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'));
$institution = isset($extradata->institution) ? $extradata->institution : 'mahara';
$type = param_alpha('type', 'users');
$subpages = array('users', 'views', 'content', 'historical');
if (!in_array($type, $subpages)) {
    $type = 'users';
}
if ($type == 'historical') {
    $field = isset($extradata->field) ? $extradata->field : 'count_members';
}
$institutiondata = institution_statistics($institution, true);
switch ($type) {
    case 'historical':
        $data = institution_historical_stats_table($limit, $offset, $field, $institutiondata);
        break;
    case 'content':
        $data = institution_content_stats_table($limit, $offset, $institutiondata);
        break;
    case 'views':
        $data = institution_view_stats_table($limit, $offset, $institutiondata);
        break;
    case 'users':
    default:
        $data = institution_user_stats_table($limit, $offset, $institutiondata);
}
json_reply(false, (object) array('message' => false, 'data' => $data));