Skip to content

Commit

Permalink
statistics MDL-25822 multiple values in get_field_sql
Browse files Browse the repository at this point in the history
A variety of get_field_sql calls returning multiple values, switched
to using MIN/MAX selects.
  • Loading branch information
danpoltawski committed Dec 30, 2010
1 parent c63ebd4 commit 5b90396
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions admin/report/courseoverview/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions course/report/stats/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}');
}


Expand Down Expand Up @@ -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', ''));
}
}
}
}
4 changes: 2 additions & 2 deletions lib/statslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5b90396

Please sign in to comment.