}
public function rewind() {
+ //TODO - this does not work in Oracle :-(
+ error('Implement rewind in oracle by doing query again');
$this->rs->MoveFirst();
}
$users = optional_param('userid', array(), PARAM_INT); // array of user id
$contents = optional_param('contents', array(), PARAM_RAW); // array of user notes
$states = optional_param('states', array(), PARAM_ALPHA); // array of notes states
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}
$note->courseid = $id;
$note->format = FORMAT_PLAIN;
foreach ($users as $k => $v) {
- if(!$user = get_record('user', 'id', $v) || empty($contents[$k])) {
+ if(!$user = $DB->get_record('user', array('id'=>$v)) || empty($contents[$k])) {
continue;
}
$note->id = 0;
}
foreach ($users as $k => $v) {
- if(!$user = get_record('user', 'id', $v)) {
+ if(!$user = $DB->get_record('user', array('id'=>$v))) {
continue;
}
$checkbox = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], '', '', '0', true);
$id = required_param('id', PARAM_INT); // course id
$users = optional_param('userid', array(), PARAM_INT); // array of user id
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}
foreach ($form->userid as $k => $v) {
// find all roles this student have in this course
- if ($students = get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
- FROM {$CFG->prefix}role_assignments ra
- WHERE userid = $v
- AND contextid = $context->id")) {
+ if ($students = $DB->get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
+ FROM {role_assignments} ra
+ WHERE userid = ?
+ AND contextid = ?", array($v, $context->id))) {
// enrol these users again, with time extension
// not that this is not necessarily a student role
foreach ($students as $student) {
foreach ($_POST as $k => $v) {
if (preg_match('/^user(\d+)$/',$k,$m)) {
- if (!($user = get_record_sql("SELECT * FROM {$CFG->prefix}user u
- INNER JOIN {$CFG->prefix}role_assignments ra ON u.id=ra.userid
- WHERE u.id={$m[1]} AND ra.contextid = $context->id"))) {
+ if (!($user = $DB->get_record_sql("SELECT *
+ FROM {user} u
+ JOIN {role_assignments} ra ON u.id=ra.userid
+ WHERE u.id=? AND ra.contextid = ?", array($m[1], $context->id)))) {
continue;
}
$userbasemenu = $basemenu;
$content = optional_param('content', '', PARAM_RAW); // note content
$state = optional_param('state', '', PARAM_ALPHA); // note publish state
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}
$note->content = $content;
$note->publishstate = $state;
foreach ($users as $k => $v) {
- if(!$user = get_record('user', 'id', $v)) {
+ if(!$user = $DB->get_record('user', array('id'=>$v))) {
continue;
}
$note->id = 0;
$userlist = array();
foreach ($users as $k => $v) {
- if(!$user = get_record('user', 'id', $v)) {
+ if (!$user = $DB->get_record('user', array('id'=>$v))) {
continue;
}
echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';
$id = required_param('id', PARAM_INT); // course id
$users = optional_param('userid', array(), PARAM_INT); // array of user id
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}
foreach ($form->userid as $k => $v) {
// find all roles this student have in this course
- if ($students = get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
- FROM {$CFG->prefix}role_assignments ra
- WHERE userid = $v
- AND contextid = $context->id")) {
+ if ($students = $DB->get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
+ FROM {role_assignments} ra
+ WHERE userid = ?
+ AND contextid = ?", array($v, $context->id))) {
// enrol these users again, with time extension
// not that this is not necessarily a student role
foreach ($students as $student) {
foreach ($_POST as $k => $v) {
if (preg_match('/^user(\d+)$/',$k,$m)) {
- if (!($user = get_record_sql("SELECT * FROM {$CFG->prefix}user u
- INNER JOIN {$CFG->prefix}role_assignments ra ON u.id=ra.userid
- WHERE u.id={$m[1]} AND ra.contextid = $context->id"))) {
+ if (!($user = $DB->get_record_sql("SELECT *
+ FROM {user} u
+ JOIN {role_assignments} ra ON u.id=ra.userid
+ WHERE u.id=? AND ra.contextid = ?", array($m[1], $context->id)))) {
continue;
}
if ($user->timestart) {
if (! $context = get_context_instance_by_id($contextid)) {
error("Context ID is incorrect");
}
- if (! $course = get_record('course', 'id', $context->instanceid)) {
+ if (! $course = $DB->get_record('course', array('id'=>$context->instanceid))) {
error("Course ID is incorrect");
}
} else {
- if (! $course = get_record('course', 'id', $courseid)) {
+ if (! $course = $DB->get_record('course', array('id'=>$courseid))) {
error("Course ID is incorrect");
}
if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
// get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
// we need to make it diferently for normal courses and site course
if ($context->id != $frontpagectx->id) {
- $minlastaccess = get_field_sql('SELECT min(timeaccess)
- FROM '.$CFG->prefix.'user_lastaccess
- WHERE courseid = '.$course->id.'
- AND timeaccess != 0');
- $lastaccess0exists = record_exists('user_lastaccess', 'courseid', $course->id, 'timeaccess', 0);
+ $minlastaccess = $DB->get_field_sql('SELECT min(timeaccess)
+ FROM {user_lastaccess}
+ WHERE courseid = ?
+ AND timeaccess != 0', array($course->id));
+ $lastaccess0exists = $DB->record_exists('user_lastaccess', array('courseid'=>$course->id, 'timeaccess'=>0));
} else {
- $minlastaccess = get_field_sql('SELECT min(lastaccess)
- FROM '.$CFG->prefix.'user
- WHERE lastaccess != 0');
- $lastaccess0exists = record_exists('user','lastaccess',0);
+ $minlastaccess = $DB->get_field_sql('SELECT min(lastaccess)
+ FROM {user}
+ WHERE lastaccess != 0');
+ $lastaccess0exists = $DB->record_exists('user', array('lastaccess'=>0));
}
$now = usergetmidnight(time());
));
$table->setup();
-
+ $params = array();
// we are looking for all users with this role assigned in this context or higher
if ($usercontexts = get_parent_contexts($context)) {
$listofcontexts = '('.implode(',', $usercontexts).')';
$listofcontexts = '('.$sitecontext->id.')'; // must be site
}
if ($roleid > 0) {
- $selectrole = " AND r.roleid = $roleid ";
+ $selectrole = " AND r.roleid = :roleid ";
+ $params['roleid'] = $roleid;
} else {
$selectrole = " ";
}
}
if ($context->id != $frontpagectx->id or $roleid >= 0) {
- $from = "FROM {$CFG->prefix}user u
- LEFT OUTER JOIN {$CFG->prefix}context ctx
- ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
- JOIN {$CFG->prefix}role_assignments r
- ON u.id=r.userid
- LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul
- ON (r.userid=ul.userid and ul.courseid = $course->id) ";
+ $from = "FROM {user} u
+ LEFT OUTER JOIN {context} ctx
+ ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
+ JOIN {role_assignments} r
+ ON u.id=r.userid
+ LEFT OUTER JOIN {user_lastaccess} ul
+ ON (r.userid=ul.userid and ul.courseid = :courseid) ";
+ $params['courseid'] = $course->id;
} else {
// on frontpage and we want all registered users
- $from = "FROM {$CFG->prefix}user u
- LEFT OUTER JOIN {$CFG->prefix}context ctx
- ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") ";
+ $from = "FROM {user} u
+ LEFT OUTER JOIN {context} ctx
+ ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") ";
}
$hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';
if ($context->id != $frontpagectx->id) {
$where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
- AND u.deleted = 0 $selectrole
- AND (ul.courseid = $course->id OR ul.courseid IS NULL)
- AND u.username != 'guest'
- $adminroles
- $hiddensql ";
+ AND u.deleted = 0 $selectrole
+ AND (ul.courseid = $course->id OR ul.courseid IS NULL)
+ AND u.username != 'guest'
+ $adminroles
+ $hiddensql ";
$where .= get_course_lastaccess_sql($accesssince);
} else {
if ($roleid >= 0) {
$where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
- AND u.deleted = 0 $selectrole
- AND u.username != 'guest'";
- $where .= get_user_lastaccess_sql($accesssince);
+ AND u.deleted = 0 $selectrole
+ AND u.username != 'guest'";
+ $where .= get_user_lastaccess_sql($accesssince);
} else {
$where = "WHERE u.deleted = 0
AND u.username != 'guest'";
$wheresearch = '';
if (!empty($search)) {
- $LIKE = sql_ilike();
- $fullname = sql_fullname('u.firstname','u.lastname');
- $wheresearch .= ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\' OR idnumber '.$LIKE.' \'%'.$search.'%\') ';
-
+ $LIKE = $DB->sql_ilike();
+ $fullname = $DB->sql_fullname('u.firstname','u.lastname');
+ $wheresearch .= " AND ($fullname $LIKE :search1 OR email $LIKE :search2 OR idnumber $LIKE :search3) ";
+ $params['search1'] = "%$search%";
+ $params['search2'] = "%$search%";
+ $params['search3'] = "%$search%";
}
if ($currentgroup) { // Displaying a group by choice
// FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
- $from .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
- $where .= ' AND gm.groupid = '.$currentgroup;
+ $from .= 'LEFT JOIN {groups_members} gm ON u.id = gm.userid ';
+ $where .= ' AND gm.groupid = :currentgroup';
+ $params['curentgroup'] = $currentgroup;
}
- $totalcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where); // Each user could have > 1 role
+ $totalcount = $DB->count_records_sql("SELECT COUNT(distinct u.id) $from $where", $params); // Each user could have > 1 role
if ($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where();
}
}
- $matchcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where.$wheresearch);
+ $matchcount = $DB->count_records_sql("SELECT COUNT(distinct u.id) $from $where $wheresearch", $params);
$table->initialbars(true);
$table->pagesize($perpage, $matchcount);
- $userlist = get_recordset_sql($select.$from.$where.$wheresearch.$sort,
+ $userlist = $DB->get_recordset_sql("$select $from $where $wheresearch $sort", $params,
$table->get_page_start(), $table->get_page_size());
//
if ($mode===MODE_ENROLDETAILS) {
$userids = array();
- while ($user = rs_fetch_next_record($userlist)) {
+ foreach ($userlist as $user) {
$userids[] = $user->id;
}
$userlist_extra = get_participants_extra($userids, $avoidroles, $course, $context);
// Only Oracle cannot seek backwards
// and must re-query...
- if ($userlist->canSeek === true) {
- $userlist->MoveFirst();
- } else {
- $userlist = get_recordset_sql($select.$from.$where.$wheresearch.$sort,
- $table->get_page_start(), $table->get_page_size());
- }
+ $userlist->rewind();
}
if ($context->id == $frontpagectx->id) {
$strallsiteusers = get_string('allsiteusers', 'role');
if ($CFG->defaultfrontpageroleid) {
- if ($fprole = get_record('role', 'id', $CFG->defaultfrontpageroleid)) {
+ if ($fprole = $DB->get_record('role', array('id'=>$CFG->defaultfrontpageroleid))) {
$fprole = role_get_name($fprole, $frontpagectx);
$strallsiteusers = "$strallsiteusers ($fprole)";
}
}
if ($roleid > 0) {
- if (!$currentrole = get_record('role','id',$roleid)) {
+ if (!$currentrole = $DB->get_record('role', array('id'=>$roleid))) {
error('That role does not exist');
}
$a->number = $totalcount;
if ($matchcount > 0) {
$usersprinted = array();
- while ($user = rs_fetch_next_record($userlist)) {
+ foreach ($userlist as $user) {
if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
continue;
}
}
$usersprinted = array();
- while ($user = rs_fetch_next_record($userlist)) {
+ foreach ($userlist as $user) {
if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
continue;
}
print_footer($course);
if ($userlist) {
- rs_close($userlist);
+ $userlist->close();
}
}
function get_participants_extra ($userids, $avoidroles, $course, $context) {
-
- global $CFG;
+ global $CFG, $DB;
if (count($userids) === 0 || count($avoidroles) === 0) {
return array();
}
+ $params = array();
+
$userids = implode(',', $userids);
// turn the path into a list of context ids
}
if (!empty($CFG->enablegroupings)) {
- $gpjoin = "LEFT OUTER JOIN {$CFG->prefix}groupings_groups gpg
- ON gpg.groupid=g.id
- LEFT OUTER JOIN {$CFG->prefix}groupings gp
- ON (gp.courseid={$course->id} AND gp.id=gpg.groupingid)";
+ $gpjoin = "LEFT OUTER JOIN {groupings_groups} gpg
+ ON gpg.groupid=g.id
+ LEFT OUTER JOIN {groupings} gp
+ ON (gp.courseid={$course->id} AND gp.id=gpg.groupingid)";
$gpselect = ',gp.id AS gpid, gp.name AS gpname ';
} else {
$gpjoin = '';
ra.enrol AS enrolplugin,
g.id AS gid, g.name AS gname
$gpselect
- FROM {$CFG->prefix}role_assignments ra
- JOIN {$CFG->prefix}context ctx
- ON (ra.contextid=ctx.id)
- LEFT OUTER JOIN {$CFG->prefix}course_categories cc
- ON (ctx.contextlevel=40 AND ctx.instanceid=cc.id)
+ FROM {role_assignments} ra
+ JOIN {context} ctx
+ ON (ra.contextid=ctx.id)
+ LEFT JOIN {course_categories} cc
+ ON (ctx.contextlevel=40 AND ctx.instanceid=cc.id)
/* only if groups active */
- LEFT OUTER JOIN {$CFG->prefix}groups_members gm
- ON (ra.userid=gm.userid)
- LEFT OUTER JOIN {$CFG->prefix}groups g
- ON (gm.groupid=g.id AND g.courseid={$course->id})
+ LEFT JOIN {groups_members} gm
+ ON (ra.userid=gm.userid)
+ LEFT JOIN {groups} g
+ ON (gm.groupid=g.id AND g.courseid={$course->id})
/* and if groupings is enabled... */
$gpjoin
- WHERE ra.userid IN ( $userids )
- AND ra.contextid in ( $contextids )
- $avoidrolescond
+ WHERE ra.userid IN ( $userids )
+ AND ra.contextid in ( $contextids )
+ $avoidrolescond
- ORDER BY ra.userid, ctx.depth DESC";
+ ORDER BY ra.userid, ctx.depth DESC";
- $rs = get_recordset_sql($sql);
+ $rs = $DB->get_recordset_sql($sql, $params);
$extra = array();
// Data structure -
// and modifierid (with an outer join to mdl_user!
//
- while ($rec = rs_fetch_next_record($rs)) {
+ foreach ($rs as $rec) {
$userid = $rec->userid;
// Prime an initial user rec...
}
}
+ $rs->close();
return $extra;
}
$format = optional_param('format',FORMAT_MOODLE,PARAM_INT);
$deluser = optional_param('deluser',0,PARAM_INT);
- if (!$course = get_record('course','id',$id)) {
+ if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("Invalid course id");
}
foreach ($_POST as $k => $v) {
if (preg_match('/^(user|teacher)(\d+)$/',$k,$m)) {
if (!array_key_exists($m[2],$SESSION->emailto[$id])) {
- if ($user = get_record_select('user','id = '.$m[2],'id,firstname,lastname,idnumber,email,emailstop,mailformat,lastaccess')) {
+ if ($user = $DB->get_record_select('user', "id = ?", array($m[2]), 'id,firstname,lastname,idnumber,email,emailstop,mailformat,lastaccess')) {
$SESSION->emailto[$id][$m[2]] = $user;
$SESSION->emailto[$id][$m[2]]->teacher = ($m[1] == 'teacher');
$count++;
if ($count) {
if ($count == 1) {
- $heading = get_string('addedrecip','moodle',$count);
+ $heading = get_string('addedrecip','moodle',$count);
} else {
$heading = get_string('addedrecips','moodle',$count);
}
}
if (($filtertype == 'site' && $filterselect) || ($filtertype=='user' && $filterselect)) {
- $user = get_record('user','id',$filterselect);
+ $user = $DB->get_record('user', array('id'=>$filterselect));
}
$inactive = NULL;
**************************************/
} else if ($filtertype == 'course' && $filterselect) {
- $course = get_record('course','id',$filterselect);
+ $course = $DB->get_record('course', array('id'=>$filterselect));
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
print_heading(format_string($course->fullname));
**************************************/
} else {
if (isset($userid)) {
- $user = get_record('user','id', $userid);
+ $user = $DB->get_record('user', array('id'=>$userid));
}
print_heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
$id = $USER->id;
}
- if (! $user = get_record("user", "id", $id) ) {
+ if (! $user = $DB->get_record("user", array("id"=>$id))) {
print_error("No such user in this course");
}
- if (! $course = get_record("course", "id", $course) ) {
+ if (! $course = $DB->get_record("course", array("id"=>$course))) {
print_error("No such course id");
}
if (!empty($CFG->forcelogin) || $course->id != SITEID) {
// do not force parents to enrol
- if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
+ if (!$DB->get_record('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id))) {
require_login($course->id);
}
}
if ($course->id != SITEID) {
$user->lastaccess = false;
- if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id, 'courseid', $course->id)) {
+ if ($lastaccess = $DB->get_record('user_lastaccess', array('userid'=>$user->id, 'courseid'=>$course->id))) {
$user->lastaccess = $lastaccess->timeaccess;
}
}
if (is_mnet_remote_user($user)) {
$sql = "
- SELECT DISTINCT
- h.id,
- h.name,
- h.wwwroot,
- a.name as application,
- a.display_name
- FROM
- {$CFG->prefix}mnet_host h,
- {$CFG->prefix}mnet_application a
- WHERE
- h.id = '{$user->mnethostid}' AND
- h.applicationid = a.id
- ORDER BY
- a.display_name,
- h.name";
-
- $remotehost = get_record_sql($sql);
+ SELECT DISTINCT h.id, h.name, h.wwwroot,
+ a.name as application, a.display_name
+ FROM {mnet_host} h, {mnet_application} a
+ WHERE h.id = ? AND h.applicationid = a.id
+ ORDER BY a.display_name, h.name";
+
+ $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
echo '<p class="errorboxcontent">'.get_string('remote'.$remotehost->application.'user')." <br />\n";
if ($USER->id == $user->id) {