diff --git a/admin/report/courseoverview/index.php b/admin/report/courseoverview/index.php index 74c6d2400ce..da91b6109c6 100644 --- a/admin/report/courseoverview/index.php +++ b/admin/report/courseoverview/index.php @@ -27,9 +27,9 @@ $reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED); - $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_daily} ORDER BY timeend'); - $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_weekly} ORDER BY timeend'); - $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_monthly} ORDER BY timeend'); + $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}'); + $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}'); + $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}'); if (empty($earliestday)) $earliestday = time(); if (empty($earliestweek)) $earliestweek = time(); diff --git a/course/report/stats/index.php b/course/report/stats/index.php index adca0117e76..6af3bc74a62 100644 --- a/course/report/stats/index.php +++ b/course/report/stats/index.php @@ -37,9 +37,14 @@ require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('coursereport/stats:view', $context); + $PAGE->set_url(new moodle_url('/course/report/stats/index.php', array('course' => $course->id, + 'report' => $report, + 'time' => $time, + 'mode' => $mode, + 'userid' => $userid))); + add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id); stats_check_uptodate($course->id); @@ -52,10 +57,8 @@ $PAGE->set_title("$course->shortname: $strstats"); $PAGE->set_heading($course->fullname); - //$PAGE->set_headingmenu(); - $PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id))); - $PAGE->navbar->add($strstats); - $PAGE->headingmenu(report_stats_mode_menu($course, $mode, $time, "$CFG->wwwroot/course/report/stats/index.php")); + $PAGE->set_pagelayout('report'); + $PAGE->set_headingmenu(report_stats_mode_menu($course, $mode, $time, "$CFG->wwwroot/course/report/stats/index.php")); echo $OUTPUT->header(); } diff --git a/course/report/stats/lib.php b/course/report/stats/lib.php index 095d13cded2..ed31e78cc9a 100644 --- a/course/report/stats/lib.php +++ b/course/report/stats/lib.php @@ -46,7 +46,7 @@ function report_stats_mode_menu($course, $mode, $time, $url) { $popupurl = $url."?course=$course->id&time=$time"; $select = new single_select(new moodle_url($popupurl), 'mode', $options, $mode, null); $select->formid = 'switchmode'; - echo $OUTPUT->render($select); + return $OUTPUT->render($select); } @@ -54,13 +54,13 @@ function report_stats_timeoptions($mode) { global $CFG, $DB; if ($mode == STATS_MODE_DETAILED) { - $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend'); - $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend'); - $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend'); + $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_daily}'); + $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_weekly}'); + $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_monthly}'); } else { - $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_daily} ORDER BY timeend'); - $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_weekly} ORDER BY timeend'); - $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_monthly} ORDER BY timeend'); + $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}'); + $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}'); + $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}'); } @@ -86,8 +86,8 @@ function stats_report_extend_navigation($navigation, $course, $context) { global $CFG, $OUTPUT; if (has_capability('coursereport/stats:view', $context)) { if (!empty($CFG->enablestats)) { - $url = new moodle_url('/course/report/stats/index.php', array('id'=>$course->id)); + $url = new moodle_url('/course/report/stats/index.php', array('course'=>$course->id)); $navigation->add(get_string('stats'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); } } -} \ No newline at end of file +} diff --git a/course/report/stats/report.php b/course/report/stats/report.php index 65962dd5967..e13f06423b6 100644 --- a/course/report/stats/report.php +++ b/course/report/stats/report.php @@ -98,7 +98,7 @@ .' ORDER BY timeend DESC'; } - $stats = $DB->get_records_sql($sql, $params); + $stats = $DB->get_records_sql($sql); if (empty($stats)) { echo $OUTPUT->notification(get_string('statsnodata')); diff --git a/lib/statslib.php b/lib/statslib.php index b52a7c482d0..8a499176ffd 100644 --- a/lib/statslib.php +++ b/lib/statslib.php @@ -854,13 +854,13 @@ function stats_get_start_from($str) { global $CFG, $DB; // are there any data in stats table? Should not be... - if ($timeend = $DB->get_field_sql('SELECT timeend FROM {stats_'.$str.'} ORDER BY timeend DESC')) { + if ($timeend = $DB->get_field_sql('SELECT MAX(timeend) FROM {stats_'.$str.'}')) { return $timeend; } // decide what to do based on our config setting (either all or none or a timestamp) switch ($CFG->statsfirstrun) { case 'all': - if ($firstlog = $DB->get_field_sql('SELECT time FROM {log} ORDER BY time ASC')) { + if ($firstlog = $DB->get_field_sql('SELECT MIN(time) FROM {log}')) { return $firstlog; } default: @@ -1333,8 +1333,8 @@ function stats_get_report_options($courseid,$mode) { case STATS_MODE_GENERAL: $reportoptions[STATS_REPORT_ACTIVITY] = get_string('statsreport'.STATS_REPORT_ACTIVITY); if ($courseid != SITEID && $context = get_context_instance(CONTEXT_COURSE, $courseid)) { - $sql = 'SELECT r.id,r.name FROM {role} r JOIN {stats_daily} s ON s.roleid = r.id WHERE s.courseid = '.$courseid; - if ($roles = $DB->get_records_sql($sql)) { + $sql = 'SELECT r.id, r.name FROM {role} r JOIN {stats_daily} s ON s.roleid = r.id WHERE s.courseid = :courseid GROUP BY s.roleid'; + if ($roles = $DB->get_records_sql($sql, array('courseid' => $courseid))) { foreach ($roles as $role) { $reportoptions[STATS_REPORT_ACTIVITYBYROLE.$role->id] = get_string('statsreport'.STATS_REPORT_ACTIVITYBYROLE). ' '.$role->name; }