From 29f83769d14db7be009fee99127d15a7661a5336 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 31 May 2008 14:35:58 +0000 Subject: [PATCH] MDL-14679 towards reports and stats conversion --- admin/report/backups/index.php | 19 +++++---- admin/report/courseoverview/index.php | 15 +++---- admin/report/courseoverview/reportsgraph.php | 13 +++--- admin/report/stats/index.php | 4 +- course/report/log/graph.php | 4 +- course/report/log/index.php | 6 +-- course/report/log/lib.php | 26 ++++++------ course/report/log/live.php | 2 +- course/report/outline/index.php | 12 +++--- course/report/participation/index.php | 42 +++++++++++--------- course/report/stats/graph.php | 7 ++-- course/report/stats/index.php | 4 +- course/report/stats/report.php | 6 ++- lib/dml/moodle_database.php | 14 +++++++ lib/dml/postgres7_adodb_moodle_database.php | 4 ++ lib/statslib.php | 33 +++++++-------- 16 files changed, 117 insertions(+), 94 deletions(-) diff --git a/admin/report/backups/index.php b/admin/report/backups/index.php index a332670fc0..a4f52946d5 100644 --- a/admin/report/backups/index.php +++ b/admin/report/backups/index.php @@ -49,7 +49,7 @@ print_heading($backuploglaststatus); print_simple_box_start('center'); /// Now, get every record from backup_courses - $courses = get_records("backup_courses"); + $courses = $DB->get_records("backup_courses"); if (!$courses) { notify(get_string('nologsfound')); @@ -96,10 +96,10 @@ print_simple_box_start('center'); /// First, me get all the distinct backups for that course in backup_log - $executions = get_records_sql("SELECT DISTINCT laststarttime,laststarttime - FROM {$CFG->prefix}backup_log - WHERE courseid = '$courseid' - ORDER BY laststarttime DESC"); + $executions = $DB->get_records_sql("SELECT DISTINCT laststarttime,laststarttime + FROM {backup_log} + WHERE courseid = ? + ORDER BY laststarttime DESC", array($courseid)); /// Iterate over backup executions if (!$executions) { @@ -112,11 +112,10 @@ print_simple_box("
".userdate($execution->laststarttime)."
", "center"); echo ""; echo ""; - $logs = get_records_sql("SELECT * - FROM {$CFG->prefix}backup_log - WHERE courseid = '$courseid' AND - laststarttime = '$execution->laststarttime' - ORDER BY id"); + $logs = $DB->get_records_sql("SELECT * + FROM {backup_log} + WHERE courseid = ? AND laststarttime = ? + ORDER BY id", array($courseid, $execution->laststarttime)); if ($logs) { foreach ($logs as $log) { echo ""; diff --git a/admin/report/courseoverview/index.php b/admin/report/courseoverview/index.php index 3977d3ab96..fbb922b588 100644 --- a/admin/report/courseoverview/index.php +++ b/admin/report/courseoverview/index.php @@ -68,15 +68,16 @@ if (!empty($param->sql)) { $sql = $param->sql; } else { - $sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table - ." WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0" - ." GROUP BY courseid " - .$param->extras - ." ORDER BY ".$param->orderby; + $sql = "SELECT courseid,".$param->fields." + FROM {".'stats_'.$param->table."} + WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0 + GROUP BY courseid + $param->extras + ORDER BY $param->orderby"; } - error_log($sql); + //error_log($sql); - $courses = get_records_sql($sql, 0, $numcourses); + $courses = $DB->get_records_sql($sql, $pram->params, 0, $numcourses); if (empty($courses)) { notify(get_string('statsnodata'));echo '';echo '

after notify

'; diff --git a/admin/report/courseoverview/reportsgraph.php b/admin/report/courseoverview/reportsgraph.php index a0c71c0faa..c81bb19068 100644 --- a/admin/report/courseoverview/reportsgraph.php +++ b/admin/report/courseoverview/reportsgraph.php @@ -19,14 +19,15 @@ if (!empty($param->sql)) { $sql = $param->sql; } else { - $sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table - ." WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0" - ." GROUP BY courseid " - .$param->extras - ." ORDER BY ".$param->orderby; + $sql = "SELECT courseid, $param->fields + FROM {".'stats_'.$param->table."} + WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0 + GROUP BY courseid + $param->extras + ORDER BY $param->orderby"; } - $courses = get_records_sql($sql, 0, $numcourses); + $courses = $DB->get_records_sql($sql, $pram->$prams, 0, $numcourses); if (empty($courses)) { print_error('statsnodata', 'error', $CFG->wwwroot.'/'.$CFG->admin.'/report/course/index.php'); diff --git a/admin/report/stats/index.php b/admin/report/stats/index.php index 0d857c3284..86ce469ff0 100644 --- a/admin/report/stats/index.php +++ b/admin/report/stats/index.php @@ -31,12 +31,12 @@ redirect($CFG->wwwroot.'/'.$CFG->admin.'/report/stats/index.php?time='.$time, '', 3); } - if (!$course = get_record("course","id",$courseid)) { + if (!$course = $DB->get_record("course", array("id"=>$courseid))) { print_error('invalidcourse', 'error'); } if (!empty($userid)) { - if (!$user = get_record('user','id',$userid)) { + if (!$user = $DB->get_record('user', array('id'=>$userid))) { print_error('invaliduser', 'error'); } } diff --git a/course/report/log/graph.php b/course/report/log/graph.php index c1f414f199..11b4ba84a3 100644 --- a/course/report/log/graph.php +++ b/course/report/log/graph.php @@ -10,7 +10,7 @@ $user = optional_param('user', 0, PARAM_INT); // Student ID $date = optional_param('date', 0, PARAM_INT); // A time of a day (in GMT) - if (! $course = get_record("course", "id", $id)) { + if (! $course = $DB->get_record("course", array("id"=>$id))) { print_error('invalidcourseid'); } @@ -23,7 +23,7 @@ } if ($user) { - if (! $user = get_record("user", "id", $user)) { + if (! $user = $DB->get_record("user", array("id"=>$user))) { print_error("nousers"); } } diff --git a/course/report/log/index.php b/course/report/log/index.php index 7cfd457b76..601cd4044b 100644 --- a/course/report/log/index.php +++ b/course/report/log/index.php @@ -34,11 +34,11 @@ $logformat = optional_param('logformat', 'showashtml', PARAM_ALPHA); if ($hostid == $CFG->mnet_localhost_id) { - if (!$course = get_record('course', 'id', $id) ) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('That\'s an invalid course id'.$id); } } else { - $course_stub = array_pop(get_records_select('mnet_log', " hostid='$hostid' AND course='$id' ", '', '*', '', '1')); + $course_stub = $DB->get_record('mnet_log', array('hostid'=>$hostid, 'course'=>$id), '*', true); $course->id = $id; $course->shortname = $course_stub->coursename; $course->fullname = $course_stub->coursename; @@ -65,7 +65,7 @@ $dateinfo = get_string('alldays'); if ($user) { - if (!$u = get_record('user', 'id', $user) ) { + if (!$u = $DB->get_record('user', array('id'=>$user))) { print_error('That\'s an invalid user!'); } $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context)); diff --git a/course/report/log/lib.php b/course/report/log/lib.php index d4c1773889..82297081cf 100644 --- a/course/report/log/lib.php +++ b/course/report/log/lib.php @@ -9,12 +9,12 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select $mnet_peer = new mnet_peer(); $mnet_peer->set_id($hostid); - $sql = "select distinct course, hostid, coursename from {$CFG->prefix}mnet_log"; - $courses = get_records_sql($sql); + $sql = "SELECT DISTINCT course, hostid, coursename FROM {mnet_log}"; + $courses = $DB->get_records_sql($sql); $remotecoursecount = count($courses); // first check to see if we can override showcourses and showusers - $numcourses = $remotecoursecount + count_records_select("course", "", "COUNT(id)"); + $numcourses = $remotecoursecount + $DB->count_records('course'); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { $showcourses = 1; } @@ -75,14 +75,14 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select h.id, h.name from - {$CFG->prefix}mnet_host h, - {$CFG->prefix}mnet_log l + {mnet_host} h, + {mnet_log} l where h.id = l.hostid order by h.name"; - if ($hosts = get_records_sql($sql)) { + if ($hosts = $DB->get_records_sql($sql)) { foreach($hosts as $host) { $hostarray[$host->id] = $host->name; } @@ -96,7 +96,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select $sites = array(); if ($CFG->mnet_localhost_id == $hostid) { if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { - if ($ccc = get_records("course", "", "", "fullname","id,fullname,category")) { + if ($ccc = $DB->get_records("course", null, "fullname","id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->id == SITEID) { $sites["$hostid/$cc->id"] = format_string($cc->fullname).' ('.get_string('site').')'; @@ -108,8 +108,8 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select } } else { if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { - $sql = "select distinct course, coursename from {$CFG->prefix}mnet_log where hostid = '$hostid'"; - if ($ccc = get_records_sql($sql)) { + $sql = "SELECT DISTINCT course, coursename FROM {mnet_log} where hostid = ?"; + if ($ccc = $DB->get_records_sql($sql, array($hostid))) { foreach ($ccc as $cc) { if (1 == $cc->course) { // TODO: this might be wrong - site course may have another id $sites["$hostid/$cc->course"] = $cc->coursename.' ('.get_string('site').')'; @@ -247,7 +247,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select else { $users = array(); if (!empty($selecteduser)) { - $user = get_record('user','id',$selecteduser); + $user = $DB->get_record('user', array('id'=>$selecteduser)); $users[$selecteduser] = fullname($user); } else { @@ -278,7 +278,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' global $USER, $CFG, $DB; // first check to see if we can override showcourses and showusers - $numcourses = count_records_select("course", "", "COUNT(id)"); + $numcourses = $DB->count_records("course"); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { $showcourses = 1; } @@ -326,7 +326,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' } if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { - if ($ccc = get_records("course", "", "", "fullname","id,fullname,category")) { + if ($ccc = $DB->get_records("course", null, "fullname", "id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->category) { $courses["$cc->id"] = format_string($cc->fullname); @@ -459,7 +459,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' else { $users = array(); if (!empty($selecteduser)) { - $user = get_record('user','id',$selecteduser); + $user = $DB->get_record('user', array('id'=>$selecteduser)); $users[$selecteduser] = fullname($user); } else { diff --git a/course/report/log/live.php b/course/report/log/live.php index 859efe0fde..370b6a6d8a 100644 --- a/course/report/log/live.php +++ b/course/report/log/live.php @@ -7,7 +7,7 @@ $id = required_param('id', PARAM_INT); $page = optional_param('page', 0, PARAM_INT); // which page to show - if (! $course = get_record("course", "id", $id) ) { + if (! $course = $DB->get_record("course", array("id"=>$id))) { print_error('invalidcourseid'); } diff --git a/course/report/outline/index.php b/course/report/outline/index.php index 27c2a2e9a0..b05a990ab9 100644 --- a/course/report/outline/index.php +++ b/course/report/outline/index.php @@ -7,7 +7,7 @@ $id = required_param('id',PARAM_INT); // course id - if (!$course = get_record('course', 'id', $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } @@ -46,12 +46,12 @@ $modinfo = get_fast_modinfo($course); $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime - FROM {$CFG->prefix}course_modules cm - JOIN {$CFG->prefix}modules m ON m.id = cm.module - JOIN {$CFG->prefix}log l ON l.cmid = cm.id - WHERE cm.course = $course->id AND l.action LIKE 'view%' AND m.visible = 1 + FROM {course_modules} cm + JOIN {modules} m ON m.id = cm.module + JOIN {log} l ON l.cmid = cm.id + WHERE cm.course = ? AND l.action LIKE 'view%' AND m.visible = 1 GROUP BY cm.id"; - $views = get_records_sql($sql); + $views = $DB->get_records_sql($sql, array($course->id)); $ri = 0; $prevsecctionnum = 0; diff --git a/course/report/participation/index.php b/course/report/participation/index.php index 9e24ac23c5..54fc6dc938 100644 --- a/course/report/participation/index.php +++ b/course/report/participation/index.php @@ -18,11 +18,11 @@ $action = ''; // default to all (don't restrict) } - if (!$course = get_record('course', 'id', $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourse'); } - if ($roleid != 0 and !$role = get_record('role', 'id', $roleid)) { + if ($roleid != 0 and !$role = $DB->get_record('role', array('id'=>$roleid))) { print_error('invalidrole'); } @@ -55,7 +55,7 @@ $modinfo = get_fast_modinfo($course); - $modules = get_records_select('modules', "visible = 1 AND name <> 'label'", 'name ASC'); + $modules = $DB->get_records_select('modules', "visible = 1 AND name <> 'label'", null, 'name ASC'); $instanceoptions = array(); foreach ($modules as $module) { @@ -71,7 +71,7 @@ $timeoptions = array(); // get minimum log time for this course - $minlog = get_field_sql('SELECT min(time) FROM '.$CFG->prefix.'log WHERE course = '.$course->id); + $minlog = $DB->get_field_sql('SELECT min(time) FROM {log} WHERE course = ?', array($course->id)); $now = usergetmidnight(time()); @@ -139,7 +139,7 @@ $postfun = $cm->modname.'_get_post_actions'; if (!function_exists($viewfun) || !function_exists($postfun)) { - error(get_string('modulemissingcode','error',$cm->modname), $baseurl); + print_error('modulemissingcode', 'error', $baseurl, $cm->modname); } $viewnames = $viewfun(); @@ -170,26 +170,32 @@ switch ($action) { case 'view': - $actionsql = 'l.action IN (\''.implode('\',\'', $viewnames).'\' )'; + $actions = $viewnames; break; case 'post': - $actionsql = 'l.action IN (\''.implode('\',\'', $postnames).'\' )'; + $actions = $postnames; break; default: // some modules have stuff we want to hide, ie mail blocked etc so do actually need to limit here. - $actionsql = 'l.action IN (\''.implode('\',\'', array_merge($viewnames, $postnames)).'\' )'; + $actions = array_merge($viewnames, $postnames); } + list($actionsql, $params) = $DB->get_in_or_equal($actions, SQL_PARAMS_NAMED, 'action0'); + $actionsql = "l.action $actionsql"; + $relatedcontexts = get_related_contexts_string($context); $sql = "SELECT ra.userid, u.firstname, u.lastname, u.idnumber, COUNT(l.action) AS count - FROM {$CFG->prefix}role_assignments ra - JOIN {$CFG->prefix}user u ON u.id = ra.userid - LEFT OUTER JOIN {$CFG->prefix}log l ON l.userid = ra.userid - WHERE ra.contextid $relatedcontexts AND ra.roleid = $roleid AND + FROM {role_assignments} ra + JOIN {user} u ON u.id = ra.userid + LEFT JOIN {log} l ON l.userid = ra.userid + WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid AND (l.id IS NULL OR - (l.cmid = $instanceid AND l.time > $timefrom AND $actionsql) + (l.cmid = :instanceid AND l.time > :timefrom AND $actionsql) )"; + $params['roleid'] = $roleid; + $params['instanceid'] = $instanceid; + $params['timefrom'] = $timefrom; if ($table->get_sql_where()) { $sql .= ' AND '.$table->get_sql_where(); //initial bar @@ -205,15 +211,15 @@ FROM {$CFG->prefix}role_assignments ra JOIN {$CFG->prefix}user u ON u.id = ra.userid LEFT OUTER JOIN {$CFG->prefix}log l ON l.userid = ra.userid - WHERE ra.contextid $relatedcontexts AND ra.roleid = $roleid AND + WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid AND (l.id IS NULL OR - (l.cmid = $instanceid AND l.time > $timefrom AND $actionsql) + (l.cmid = :instanceid AND l.time > :timefrom AND $actionsql) )"; - $totalcount = count_records_sql($countsql); + $totalcount = $DB->count_records_sql($countsql, $params); if ($table->get_sql_where()) { - $matchcount = count_records_sql($countsql.' AND '.$table->get_sql_where()); + $matchcount = $DB->count_records_sql($countsql.' AND '.$table->get_sql_where(), $params); } else { $matchcount = $totalcount; } @@ -225,7 +231,7 @@ $table->initialbars($totalcount > $perpage); $table->pagesize($perpage, $matchcount); - if (!$users = get_records_sql($sql, $table->get_page_start(), $table->get_page_size())) { + if (!$users = $DB->get_records_sql($sql, $params, $table->get_page_start(), $table->get_page_size())) { $users = array(); // tablelib will handle saying 'Nothing to display' for us. } diff --git a/course/report/stats/graph.php b/course/report/stats/graph.php index 732116e91c..f3a402fb38 100644 --- a/course/report/stats/graph.php +++ b/course/report/stats/graph.php @@ -11,12 +11,12 @@ $userid = optional_param('userid', 0, PARAM_INT); $roleid = optional_param('roleid',0,PARAM_INT); - if (!$course = get_record("course","id",$courseid)) { + if (!$course = $DB->get_record("course", array("id"=>$courseid))) { print_error("invalidcourseid"); } if (!empty($userid)) { - if (!$user = get_record('user','id',$userid)) { + if (!$user = $DB->get_record('user', array('id'=>$userid))) { print_error("nousers"); } } @@ -36,6 +36,7 @@ $param->table = 'user_'.$param->table; } + // TODO: cleanup this ugly mess! $sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields .' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE ' .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') @@ -46,7 +47,7 @@ .' '.$param->extras .' ORDER BY timeend DESC'; - $stats = get_records_sql($sql); + $stats = $DB->get_records_sql($sql, $param->params); $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); diff --git a/course/report/stats/index.php b/course/report/stats/index.php index 3f12f58f88..99a4a603a6 100644 --- a/course/report/stats/index.php +++ b/course/report/stats/index.php @@ -28,12 +28,12 @@ redirect($CFG->wwwroot.'/'.$CFG->admin.'/report/stats/index.php?time='.$time); } - if (!$course = get_record("course","id",$courseid)) { + if (!$course = $DB->get_record("course", array("id"=>$courseid))) { print_error("invalidcourseid"); } if (!empty($userid)) { - if (!$user = get_record('user','id',$userid)) { + if (!$user = $DB->get_record('user', array('id'=>$userid))) { print_error("nousers"); } } diff --git a/course/report/stats/report.php b/course/report/stats/report.php index f85a32a967..c2255bc8e3 100644 --- a/course/report/stats/report.php +++ b/course/report/stats/report.php @@ -22,6 +22,7 @@ if ($mode == STATS_MODE_DETAILED) { $param = stats_get_parameters($time,null,$course->id,$mode); // we only care about the table and the time string (if we have time) + //TODO: lceanup this ugly mess $sql = 'SELECT DISTINCT s.userid, u.firstname, u.lastname, u.idnumber FROM '.$CFG->prefix.'stats_user_'.$param->table.' s JOIN '.$CFG->prefix.'user u ON u.id = s.userid @@ -30,7 +31,7 @@ . ((!empty($time)) ? ' AND timeend >= '.$param->timeafter : '') .' ORDER BY u.lastname, u.firstname ASC'; - if (!$us = get_records_sql($sql)) { + if (!$us = $DB->get_records_sql($sql, $param->params)) { print_error('nousers'); } @@ -80,6 +81,7 @@ if (!empty($param->sql)) { $sql = $param->sql; } else { + //TODO: lceanup this ugly mess $sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields .' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE ' .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') @@ -91,7 +93,7 @@ .' ORDER BY timeend DESC'; } - $stats = get_records_sql($sql); + $stats = $DB->get_records_sql($sql, $params); if (empty($stats)) { notify(get_string('statsnodata')); diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index f7bb9c4b6f..d729279863 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -1112,6 +1112,20 @@ abstract class moodle_database { return ' ' . $fieldname . ' '; } + /** + * Returns the SQL to be used in order to CAST one CHAR column to REAL number. + * + * Be aware that the CHAR column you're trying to cast contains really + * numbers or the RDBMS will throw an error! + * + * @param string fieldname the name of the field to be casted + * @param boolean text to specify if the original column is one TEXT (CLOB) column (true). Defaults to false. + * @return string the piece of SQL code to be used in your statement. + */ + public function sql_cast_char2real($fieldname, $text=false) { + return ' ' . $fieldname . ' '; + } + /** * Returns the SQL text to be used to compare one TEXT (clob) column with * one varchar column, because some RDBMS doesn't support such direct diff --git a/lib/dml/postgres7_adodb_moodle_database.php b/lib/dml/postgres7_adodb_moodle_database.php index 7d190705ca..08e40d1375 100644 --- a/lib/dml/postgres7_adodb_moodle_database.php +++ b/lib/dml/postgres7_adodb_moodle_database.php @@ -425,6 +425,10 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database { return ' CAST(' . $fieldname . ' AS INT) '; } + public function sql_cast_char2real($fieldname, $text=false) { + return " $fieldname::real "; + } + /** * Does this driver suppoer regex syntax when searching */ diff --git a/lib/statslib.php b/lib/statslib.php index 2b848ea104..d5955ad87d 100644 --- a/lib/statslib.php +++ b/lib/statslib.php @@ -977,9 +977,10 @@ function stats_clean_old() { } function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) { - global $CFG,$db; + global $CFG, $DB; $param = new object(); + $params->params = array(); if ($time < 10) { // dailies // number of days to go back = 7* time @@ -997,12 +998,6 @@ function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) { $param->extras = ''; - // compatibility - if we're in postgres, cast to real for some reports. - $real = ''; - if ($CFG->dbfamily == 'postgres') { - $real = '::real'; - } - switch ($report) { // ******************** STATS_MODE_GENERAL ******************** // case STATS_REPORT_LOGINS: @@ -1017,33 +1012,33 @@ function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) { break; case STATS_REPORT_READS: - $param->fields = sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, stat1 as line1'; + $param->fields = $DB->sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, stat1 as line1'; $param->fieldscomplete = true; // set this to true to avoid anything adding stuff to the list and breaking complex queries. $param->aggregategroupby = 'roleid'; $param->stattype = 'activity'; $param->crosstab = true; $param->extras = 'GROUP BY timeend,roleid,stat1'; if ($courseid == SITEID) { - $param->fields = sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, sum(stat1) as line1'; + $param->fields = $DB->sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, sum(stat1) as line1'; $param->extras = 'GROUP BY timeend,roleid'; } break; case STATS_REPORT_WRITES: - $param->fields = sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, stat2 as line1'; + $param->fields = $DB->sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, stat2 as line1'; $param->fieldscomplete = true; // set this to true to avoid anything adding stuff to the list and breaking complex queries. $param->aggregategroupby = 'roleid'; $param->stattype = 'activity'; $param->crosstab = true; $param->extras = 'GROUP BY timeend,roleid,stat2'; if ($courseid == SITEID) { - $param->fields = sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, sum(stat2) as line1'; + $param->fields = $DB->sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, sum(stat2) as line1'; $param->extras = 'GROUP BY timeend,roleid'; } break; case STATS_REPORT_ACTIVITY: - $param->fields = sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, sum(stat1+stat2) as line1'; + $param->fields = $DB->sql_concat('timeend','roleid').' AS uniqueid, timeend, roleid, sum(stat1+stat2) as line1'; $param->fieldscomplete = true; // set this to true to avoid anything adding stuff to the list and breaking complex queries. $param->aggregategroupby = 'roleid'; $param->stattype = 'activity'; @@ -1112,13 +1107,13 @@ function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) { activity.all_activity / enrolments.highest_enrolments as line3 FROM ( SELECT courseid, (stat1+stat2) AS all_activity - FROM '.$CFG->prefix.'stats_'.$param->table.' + FROM {stats_'.$param->table.'} WHERE stattype=\'activity\' AND timeend >= '.$param->timeafter.' AND roleid = 0 ) activity INNER JOIN ( SELECT courseid, max(stat1) AS highest_enrolments - FROM '.$CFG->prefix.'stats_'.$param->table.' + FROM {stats_'.$param->table.'} WHERE stattype=\'enrolments\' AND timeend >= '.$param->timeafter.' AND stat1 > '.$threshold.' GROUP BY courseid ) enrolments @@ -1140,8 +1135,8 @@ function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) { ceil(avg(active_enrolments)) as line2, avg(proportion_active) AS line3 FROM ( SELECT courseid, timeend, stat2 as active_enrolments, - stat1 as all_enrolments, stat2'.$real.'/stat1'.$real.' as proportion_active - FROM '.$CFG->prefix.'stats_'.$param->table.' + stat1 as all_enrolments, '.$DB->sql_cast_char2real('stat2').'/'.$DB->sql_cast_char2real('stat1').' AS proportion_active + FROM {stats_'.$param->table.'} WHERE stattype=\'enrolments\' AND roleid = 0 AND stat1 > '.$threshold.' ) aq WHERE timeend >= '.$param->timeafter.' @@ -1160,8 +1155,8 @@ function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) { avg(proportion_active) AS line3 FROM ( SELECT courseid, timeend, stat1 as views, stat2 AS posts, - stat2'.$real.'/stat1'.$real.' as proportion_active - FROM '.$CFG->prefix.'stats_'.$param->table.' + '.$DB->sql_cast_char2real('stat2').'/'.$DB->sql_cast_char2real('stat1').' as proportion_active + FROM {stats_'.$param->table.'} WHERE stattype=\'activity\' AND roleid = 0 AND stat1 > 0 ) aq WHERE timeend >= '.$param->timeafter.' @@ -1181,7 +1176,7 @@ function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) { } */ //TODO must add the SITEID reports to the rest of the reports. - return $param; + return array($sql, $params); } function stats_get_view_actions() { -- 2.39.5