Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

statistics MDL-25822 multiple values in get_field_sql

A variety of get_field_sql calls returning multiple values, switched
to using MIN/MAX selects.
  • Loading branch information...
commit 5b903967deaf035a93d2eb60b6ab15114db5caef 1 parent c63ebd4
@danpoltawski danpoltawski authored
View
6 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();
View
14 course/report/stats/lib.php
@@ -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}');
}
@@ -90,4 +90,4 @@ function stats_report_extend_navigation($navigation, $course, $context) {
$navigation->add(get_string('stats'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
}
-}
+}
View
4 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:
Please sign in to comment.
Something went wrong with that request. Please try again.