if ($courses = get_courses($id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
// move it off the range
$count = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1
- FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id);
+ FROM {course} WHERE category=' . $category->id);
$count = $count->max + 100;
begin_sql();
foreach ($courses as $course) {
// TODO something like fix_course_sortorder() ?
// we are going to need to know the range
- $max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course_categories WHERE id=' . $category->id);
+ $max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM {course_categories} WHERE id=' . $category->id);
$max = $max->max + 100;
if (!empty($moveup)) {
}
$countsql = "SELECT COUNT(DISTINCT(ra.userid))
- 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
+ FROM {role_assignments} ra
+ JOIN {user} u ON u.id = ra.userid
+ LEFT OUTER 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)
// TODO: cleanup this ugly mess!
$sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
- .' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
+ .' FROM {stats_'.$param->table.'} WHERE '
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
.((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
function report_stats_timeoptions($mode) {
global $CFG, $DB;
- $tableprefix = $CFG->prefix.'stats_';
-
if ($mode == STATS_MODE_DETAILED) {
- $tableprefix = $CFG->prefix.'stats_user_';
+ $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');
+ } 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 timeend FROM {daily} ORDER BY timeend');
- $earliestweek = $DB->get_field_sql('SELECT timeend FROM {weekly} ORDER BY timeend');
- $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {monthly} ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = 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
+ FROM {stats_user_'.$param->table.'} s
+ JOIN {user} u ON u.id = s.userid
WHERE courseid = '.$course->id
. ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '')
. ((!empty($time)) ? ' AND timeend >= '.$param->timeafter : '')
global $CFG, $DB;
// NOTE: if $this->enrol_connect() succeeds you MUST remember to call
- // $this->enrol_disconnect() as it is doing some nasty vodoo with $CFG->prefix
+ // $this->enrol_disconnect() as it is doing some nasty vodoo with table prefix
$enroldb = $this->enrol_connect();
if (!$enroldb) {
error_log('[ENROL_DB] Could not make a connection');
/// DB Connect
/// NOTE: You MUST remember to disconnect
/// when you stop using it -- as this call will
-/// sometimes modify $CFG->prefix for the whole of Moodle!
+/// sometimes modify table prefix for the whole of Moodle!
function enrol_connect() {
global $CFG;
$DB->set_debug(true);
foreach ($columns as $column => $data) {
if (in_array($data->meta_type, array('C', 'X'))) { // Text stuff only
- $DB->execute("UPDATE {$CFG->prefix}$table SET $column = REPLACE($column, ?, ?)", array($search, $replace));
+ $DB->execute("UPDATE {".$table."} SET $column = REPLACE($column, ?, ?)", array($search, $replace));
}
}
$DB->set_debug(false);
// change course start data
$DB->set_field('course', 'startdate', $data->reset_start_date, array('id'=>$data->courseid));
// update all course and group events - do not move activity events
- $updatesql = "UPDATE {$CFG->prefix}event
+ $updatesql = "UPDATE {event}
SET timestart = timestart + ?
WHERE courseid=? AND instance=0";
$DB->execute($updatesql, array($data->timeshift, $data->courseid));
/// Get all the INFOs with more than notifyloginthreshold failures since lastnotifyfailure
/// and insert them into the cache_flags temp table
$sql = "SELECT info, count(*)
- FROM {$CFG->prefix}log
+ FROM {log}
WHERE module = 'login' AND action = 'error'
AND time > ?
GROUP BY info
// the tag has been deleted. This shouldn't happen, but if it did, using
// this query could help "clean it up". This causes bugs at this time.
//$tags = $DB->get_records_sql("SELECT ti.tagid, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering ".
- // "FROM {$CFG->prefix}tag_instance ti LEFT JOIN {$CFG->prefix}tag tg ON ti.tagid = tg.id ".
+ // "FROM {tag_instance} ti LEFT JOIN {tag} tg ON ti.tagid = tg.id ".
// "WHERE ti.itemtype = '{$record_type}' AND ti.itemid = '{$record_id}' {$type} ".
// "ORDER BY ti.ordering ASC");
}
$timenow = round(time(), 100);
$sql = "id IN (SELECT userid
- FROM {$CFG->prefix}role_assignments a
+ FROM {role_assignments} a
WHERE a.contextid=".SYSCONTEXTID." AND a.roleid=$value AND a.timestart<$timenow
AND (a.timeend=0 OR a.timeend>$timenow))";
return array($sql, array());