Many small fixes to stats, including aggregate activity across all courses when querying for SITEID

This commit is contained in:
mjollnir_
2005-10-13 03:16:11 +00:00
parent f74a8cc6ce
commit 3a317277b6
4 changed files with 45 additions and 20 deletions
+10 -6
View File
@@ -91,9 +91,9 @@
if ($mode == STATS_MODE_DETAILED) {
if (!empty($time)) {
$param = stats_get_parameters($time,null); // we only care about the table and the time string.
$param = stats_get_parameters($time,null,$course->id); // we only care about the table and the time string.
$sql = 'SELECT DISTINCT s.userid,s.roleid,u.firstname,u.lastname,u.idnumber,u.nickname FROM '.$CFG->prefix.'stats_user_'.$param->table.' s JOIN '.$CFG->prefix.'user u ON u.id = s.userid '
.'WHERE courseid = '.$course->id.' AND timeend > '.$param->timeafter . ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '');
.'WHERE courseid = '.$course->id.' AND timeend >= '.$param->timeafter . ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '');
if (!isadmin()) {
$sql .= ' AND (s.roleid = 1 OR s.userid = '.$USER->id .")";
}
@@ -153,14 +153,18 @@
if ($report == STATS_REPORT_LOGINS && $course->id != SITEID) {
error("This type of report is only available for the site course");
}
$param = stats_get_parameters($time,$report);
$param = stats_get_parameters($time,$report,$course->id);
if ($mode == STATS_MODE_DETAILED) {
$param->table = 'user_'.$param->table;
}
$sql = 'SELECT timeend,'.$param->fields.',id FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE courseid = '.$course->id.((!empty($userid)) ? ' AND userid = '.$userid : '')
. ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '')
.' AND timeend > '.$param->timeafter
$sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
.((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
. ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
.' timeend >= '.$param->timeafter
.$param->extras
.' ORDER BY timeend DESC';
$stats = get_records_sql($sql);
if (empty($stats)) {
+7 -4
View File
@@ -26,15 +26,18 @@
stats_check_uptodate($course->id);
$param = stats_get_parameters($time,$report);
$param = stats_get_parameters($time,$report,$course->id);
if (!empty($userid)) {
$param->table = 'user_'.$param->table;
}
$sql = 'SELECT timeend,'.$param->fields.',id FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE courseid = '.$course->id.((!empty($userid)) ? ' AND userid = '.$userid : '')
. ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '')
.' AND timeend > '.$param->timeafter
$sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
. (($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
. ((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
. ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
.' timeend >= '.$param->timeafter
.$param->extras
.' ORDER BY timeend DESC';
$stats = get_records_sql($sql);
+16 -6
View File
@@ -107,20 +107,30 @@
}
// use the earliest.
$time = array_pop($timeoptions);
echo '<center><img src="'.$CFG->wwwroot.'/course/statsgraph.php?course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" /></center>';
$time = array_pop(array_keys($timeoptions));
$param = stats_get_parameters($time,STATS_REPORT_USER_VIEW);
$param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id);
$param->table = 'user_'.$param->table;
$sql = 'SELECT timeend,'.$param->fields.',id FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE courseid = '.$course->id.' AND userid = '.$user->id
$sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
.' userid = '.$user->id
.' AND stattype = \''.$param->stattype.'\''
.' AND timeend > '.$param->timeafter
.' AND timeend >= '.$param->timeafter
.$param->extras
.' ORDER BY timeend DESC';
$stats = get_records_sql($sql);
if (empty($stats)) {
error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
}
echo '<center><img src="'.$CFG->wwwroot.'/course/statsgraph.php?course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" /></center>';
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
$table = new object();
$table->align = array('left','center','center','center');
$param->table = str_replace('user_','',$param->table);
+12 -4
View File
@@ -464,24 +464,23 @@ function stats_clean_old() {
// don't delete monthlies
}
function stats_get_parameters($time,$report) {
function stats_get_parameters($time,$report,$courseid) {
if ($time < 10) { // dailies
// number of days to go back = 7* time
$param->limit = 7*$time;
$param->table = 'daily';
$param->timeafter = strtotime("-".($time*7)." days",stats_get_base_daily());
} elseif ($time < 20) { // weeklies
// number of weeks to go back = time - 10 * 4 (weeks) + base week
$param->limit = ($time - 10) * 4;
$param->table = 'weekly';
$param->timeafter = strtotime("-".(($time - 10)*4)." weeks",stats_get_base_weekly());
} else { // monthlies.
// number of months to go back = time - 20 * months + base month
$param->limit = $time - 20;
$param->table = 'monthly';
$param->timeafter = strtotime("-".($time - 20)." months",stats_get_base_monthly());
}
$param->extras = '';
switch ($report) {
case STATS_REPORT_LOGINS:
$param->fields = 'logins as line1,uniquelogins as line2';
@@ -537,6 +536,11 @@ function stats_get_parameters($time,$report) {
$param->stattype = 'activity';
break;
}
if ($courseid == SITEID) { // just aggregate all courses.
$param->fields = preg_replace('/([a-zA-Z0-9+_]*)\W+as\W+([a-zA-Z0-9_]*)/','sum($1) as $2',$param->fields);
$param->extras = ' GROUP BY timeend';
}
return $param;
}
@@ -751,6 +755,10 @@ function stats_get_report_options($courseid,$mode) {
function stats_fix_zeros($stats,$timeafter,$timestr,$line2=true,$line3=false) {
if (empty($stats)) {
return;
}
$timestr = str_replace('user_','',$timestr); // just in case.
$fun = 'stats_get_base_'.$timestr;