MDL-14679 converted some get/set_field()

This commit is contained in:
skodak
2008-06-02 21:39:23 +00:00
parent 1829e015e6
commit a5d424df7c
31 changed files with 70 additions and 60 deletions
+1 -1
View File
@@ -520,7 +520,7 @@ class problem_000011 extends problem_base {
function solution() {
global $CFG;
if (optional_param('resetsesserrorcounter', 0, PARAM_BOOL)) {
if (get_field('config', 'name', 'name', 'session_error_counter')) {
if ($DB->get_field('config', 'name', array('name'=>'session_error_counter'))) {
delete_records('config', 'name', 'session_error_counter');
}
return 'Error counter was cleared.';
+1 -1
View File
@@ -590,7 +590,7 @@
}
/// If no recently cron run
$lastcron = get_field_sql('SELECT max(lastcron) FROM ' . $CFG->prefix . 'modules');
$lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
if (time() - $lastcron > 3600 * 24) {
$strinstallation = get_string('installation', 'install');
$helpbutton = helpbutton('install', $strinstallation, 'moodle', true, false, '', true);
+2 -2
View File
@@ -38,11 +38,11 @@
$hosts = $enrolment->list_remote_servers();
foreach ($hosts as $host) {
$coursesurl = "$CFG->wwwroot/$CFG->admin/mnet/enr_courses.php?host={$host->id}&sesskey={$USER->sesskey}";
$coursecount = get_field_sql("SELECT count(id) FROM {$CFG->prefix}mnet_enrol_course WHERE hostid={$host->id}");
$coursecount = $DB->get_field_sql("SELECT COUNT(id) FROM {mnet_enrol_course} WHERE hostid=?", array($host->id));
if (empty($coursecount)) {
$coursecount = '?';
}
$enrolcount = get_field_sql("SELECT count(id) FROM {$CFG->prefix}mnet_enrol_assignments WHERE hostid={$host->id}");
$enrolcount = $DB->get_field_sql("SELECT COUNT(id) FROM {mnet_enrol_assignments} WHERE hostid=?", array($host->id));
echo '<tr>'
. "<td><a href=\"{$coursesurl}\">{$host->name}</a></td>"
+1 -1
View File
@@ -87,7 +87,7 @@ if (($form = data_submitted()) && confirm_sesskey()) {
}
unset($temp_wwwroot);
$mnet_peer->set_applicationid($form->applicationid);
$application = get_field('mnet_application', 'name', 'id', $form->applicationid);
$application = $DB->get_field('mnet_application', 'name', array('id'=>$form->applicationid));
$mnet_peer->bootstrap($form->wwwroot, null, $application);
}
+2 -2
View File
@@ -63,7 +63,7 @@
echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strnext</font></td></tr>";
foreach ($courses as $course) {
/// Get the course shortname
$coursename = get_field ("course","fullname","id",$course->courseid);
$coursename = $DB->get_field ("course", "fullname", array("id"=>$course->courseid));
if ($coursename) {
echo "<tr>";
echo "<td nowrap=\"nowrap\"><font size=\"2\"><a href=\"index.php?courseid=$course->courseid\">".$coursename."</a></font></td>";
@@ -90,7 +90,7 @@
} else {
print_heading($backuplogdetailed);
$coursename = get_field("course","fullname","id","$courseid");
$coursename = $DB->get_field("course", "fullname", array("id"=>"$courseid"));
print_heading("$strcourse: $coursename");
print_simple_box_start('center');
+4 -4
View File
@@ -28,9 +28,9 @@
$tableprefix = $CFG->prefix.'stats_';
$earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
$earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
$earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'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();
@@ -101,7 +101,7 @@
foreach ($courses as $c) {
$a = array();
$a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.get_field('course','shortname','id',$c->courseid).'</a>';
$a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>';
$a[] = $c->line1;
if (isset($c->line2)) {
+1 -1
View File
@@ -47,7 +47,7 @@
}
foreach ($courses as $c) {
$graph->x_data[] = get_field('course','shortname','id',$c->courseid);
$graph->x_data[] = $DB->get_field('course', 'shortname', array('id'=>$c->courseid));
$graph->y_data['bar1'][] = $c->{$param->graphline};
}
$graph->y_order = array('bar1');
+1 -1
View File
@@ -454,7 +454,7 @@
}
foreach ($assignableroles as $roleid => $rolename) {
$description = format_string(get_field('role', 'description', 'id', $roleid));
$description = format_string($DB->get_field('role', 'description', array('id'=>$roleid)));
$row = array('<a href="'.$baseurl.'&amp;roleid='.$roleid.'">'.$rolename.'</a>',$description, $rolehodlercount[$roleid]);
if ($showroleholders) {
$row[] = $rolehodlernames[$roleid];
+1 -1
View File
@@ -386,7 +386,7 @@
// reset a role sitewide...
mark_context_dirty($sitecontext->path);
$rolename = get_field('role', 'name', 'id', $roleid);
$rolename = $DB->get_field('role', 'name', array('id'=>$roleid));
add_to_log(SITEID, 'role', 'reset', 'admin/roles/manage.php?roleid='.$roleid.'&action=reset', $rolename, '', $USER->id);
redirect('manage.php?action=view&amp;roleid='.$roleid);
+1 -1
View File
@@ -200,7 +200,7 @@
foreach ($overridableroles as $roleid => $rolename) {
$countusers = 0;
$overridecount = $DB->count_records_select('role_capabilities', "roleid = ? AND contextid = ?", array($roleid, $context->id));
$description = format_string(get_field('role', 'description', 'id', $roleid));
$description = format_string($DB->get_field('role', 'description', array('id'=>$roleid)));
$table->data[] = array('<a href="'.$baseurl.'&amp;roleid='.$roleid.'">'.$rolename.'</a>', $description, $overridecount);
}
+1 -1
View File
@@ -129,7 +129,7 @@ if ($formdata = $mform->get_data(false)) {
continue;
}
if (my_save_profile_image($user->id, $zipdir.'/'.$item)) {
set_field('user', 'picture', 1, 'id', $user->id);
$DB->set_field('user', 'picture', 1, array('id'=>$user->id));
$usersupdated++;
notify(get_string('uploadpicture_userupdated', 'admin', $user->username));
} else {
+1 -1
View File
@@ -936,7 +936,7 @@ class test extends XMLDBAction {
$tests['update record '. $textlen . ' cc. (text) and ' . $imglen . ' bytes (binary)'] = $test;
}
/// 50th test. set_field with TEXT contents
/// 50th test. $DB->set_field with TEXT contents
if ($test->status) {
$test = new stdClass;
$test->status = false;
+2 -2
View File
@@ -240,7 +240,7 @@ class auth_plugin_mnet extends auth_plugin_base {
* @return array The local user record.
*/
function confirm_mnet_session($token, $remotewwwroot) {
global $CFG, $MNET, $SESSION;
global $CFG, $MNET, $SESSION, $DB;
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
// verify the remote host is configured locally before attempting RPC call
@@ -425,7 +425,7 @@ class auth_plugin_mnet extends auth_plugin_base {
$extra = get_records_sql($sql);
$keys = array_keys($courses);
$defaultrolename = get_field('role', 'shortname', 'id', $CFG->defaultcourseroleid);
$defaultrolename = $DB->get_field('role', 'shortname', array('id'=>$CFG->defaultcourseroleid));
foreach ($keys AS $id) {
if ($courses[$id]->visible == 0) {
unset($courses[$id]);
+7 -3
View File
@@ -728,13 +728,15 @@ class block_base {
* @todo finish documenting this function
*/
function instance_config_save($data,$pinned=false) {
$data = stripslashes_recursive($data);
global $DB;
$data = $data;
$this->config = $data;
$table = 'block_instance';
if (!empty($pinned)) {
$table = 'block_pinned';
}
return set_field($table, 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id);
return $DB->set_field($table, 'configdata', base64_encode(serialize($data)), array('id'=>$this->instance->id));
}
/**
@@ -743,11 +745,13 @@ class block_base {
* @todo finish documenting this function
*/
function instance_config_commit($pinned=false) {
global $DB;
$table = 'block_instance';
if (!empty($pinned)) {
$table = 'block_pinned';
}
return set_field($table, 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id);
return $DB->set_field($table, 'configdata', base64_encode(serialize($this->config)), array('id'=>$this->instance->id));
}
/**
+1 -1
View File
@@ -70,7 +70,7 @@ class block_section_links extends block_base {
}
if (!empty($USER->id)) {
$display = get_field('course_display', 'display', 'course', $this->instance->pageid, 'userid', $USER->id);
$display = $DB->get_field('course_display', 'display', array('course'=>$this->instance->pageid, 'userid'=>$USER->id));
}
if (!empty($display)) {
$link = $CFG->wwwroot.'/course/view.php?id='.$this->instance->pageid.'&amp;'.$sectionname.'=';
+1 -1
View File
@@ -100,7 +100,7 @@
break;
case 'group':
$group = groups_get_group($id, false);
$info = $group->name; //TODO: get_field('groups', 'name', 'id', $id)
$info = $group->name; //TODO: $DB->get_field('groups', 'name', array('id'=>$id))
break;
default:
$info = '';
+5 -5
View File
@@ -133,7 +133,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
$count = $count->max + 100;
begin_sql();
foreach ($courses as $course) {
set_field('course', 'sortorder', $count, 'id', $course->id);
$DB->set_field('course', 'sortorder', $count, array('id'=>$course->id));
$count++;
}
commit_sql();
@@ -226,7 +226,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
$visible = 1;
}
if ($category) {
if (! set_field("course_categories", "visible", $visible, "id", $category->id)) {
if (! $DB->set_field("course_categories", "visible", $visible, array("id"=>$category->id))) {
notify("Could not update that category!");
}
}
@@ -259,9 +259,9 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
if ($swapcourse and $movecourse) { // Renumber everything for robustness
begin_sql();
if (!( set_field("course", "sortorder", $max, "id", $swapcourse->id)
&& set_field("course", "sortorder", $swapcourse->sortorder, "id", $movecourse->id)
&& set_field("course", "sortorder", $movecourse->sortorder, "id", $swapcourse->id)
if (!( $DB->set_field("course", "sortorder", $max, aray("id"=>$swapcourse->id))
&& $DB->set_field("course", "sortorder", $swapcourse->sortorder, array("id"=>$movecourse->id))
&& $DB->set_field("course", "sortorder", $movecourse->sortorder, array("id"=>$swapcourse->id))
)) {
notify("Could not update that course!");
}
+2 -2
View File
@@ -82,7 +82,7 @@
}
if (has_capability('moodle/course:create', $sysctx)) { // Print link to create a new course
/// Get the 1st available category
$options = array('category' => get_field('course_categories', 'id', 'parent', '0'));
$options = array('category' => $DB->get_field('course_categories', 'id', array('parent'=>'0')));
print_single_button('edit.php', $options, get_string('addnewcourse'), 'get');
}
if (has_capability('moodle/site:approvecourse', $sysctx) and !empty($CFG->enablecourserequests)) {
@@ -292,7 +292,7 @@
if (has_capability('moodle/course:create', $sysctx)) {
// print create course link to first category
$options = array();
$options = array('category' => get_field('course_categories', 'id', 'parent', '0'));
$options = array('category' => $DB->get_field('course_categories', 'id', array('parent'=>'0')));
print_single_button('edit.php', $options, get_string('addnewcourse'), 'get');
}
}
+5 -5
View File
@@ -1026,7 +1026,7 @@ function get_array_of_activities($courseid) {
}
}
if (!isset($mod[$seq]->name)) {
$mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
$mod[$seq]->name = urlencode($DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance)));
}
}
}
@@ -2205,22 +2205,22 @@ function add_mod_to_section($mod, $beforemod=NULL) {
function set_coursemodule_groupmode($id, $groupmode) {
global $DB;
return set_field("course_modules", "groupmode", $groupmode, array("id"=>$id));
return $DB->set_field("course_modules", "groupmode", $groupmode, array("id"=>$id));
}
function set_coursemodule_groupingid($id, $groupingid) {
global $DB;
return set_field("course_modules", "groupingid", $groupingid, array("id"=>$id));
return $DB->set_field("course_modules", "groupingid", $groupingid, array("id"=>$id));
}
function set_coursemodule_groupmembersonly($id, $groupmembersonly) {
global $DB;
return set_field("course_modules", "groupmembersonly", $groupmembersonly, array("id"=>$id));
return $DB->set_field("course_modules", "groupmembersonly", $groupmembersonly, array("id"=>$id));
}
function set_coursemodule_idnumber($id, $idnumber) {
global $DB;
return set_field("course_modules", "idnumber", $idnumber, array("id"=>$id));
return $DB->set_field("course_modules", "idnumber", $idnumber, array("id"=>$id));
}
/**
* $prevstateoverrides = true will set the visibility of the course module
+1 -1
View File
@@ -31,7 +31,7 @@
print_heading(format_string($course->fullname));
if (!$logstart = get_field_sql("SELECT MIN(time) FROM {$CFG->prefix}log")) {
if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
print_error('logfilenotavailable');
}
+4 -4
View File
@@ -30,7 +30,7 @@
function report_stats_timeoptions($mode) {
global $CFG;
global $CFG, $DB;
$tableprefix = $CFG->prefix.'stats_';
@@ -38,9 +38,9 @@
$tableprefix = $CFG->prefix.'stats_user_';
}
$earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
$earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
$earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'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();
+1 -1
View File
@@ -104,7 +104,7 @@
print_heading(format_string($course->shortname).' - '.get_string('statsreport'.$report)
.((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : '')
.((!empty($roleid)) ? ' '.get_field('role','name','id',$roleid) : ''));
.((!empty($roleid)) ? ' '.$DB->get_field('role','name', array('id'=>$roleid)) : ''));
if (empty($CFG->gdversion)) {
+5 -3
View File
@@ -69,6 +69,8 @@ var $imsroles = array(
* For example, IMS role '01' is 'Learner', so may map to 'student' in Moodle.
*/
function determine_default_rolemapping($imscode) {
global $DB;
switch($imscode) {
case '01':
case '04':
@@ -89,7 +91,7 @@ function determine_default_rolemapping($imscode) {
default:
return 0; // Zero for no match
}
return get_field('role', 'id', 'shortname', $shortname);
return $DB->get_field('role', 'id', array('shortname'=>$shortname));
}
@@ -469,7 +471,7 @@ function process_group_tag($tagcontents){
/* -----------Course aliasing is DEACTIVATED until a more general method is in place---------------
// Second, look in the course alias table to see if the code should be translated to something else
if($aliases = get_field('enrol_coursealias', 'toids', 'fromid', $group->coursecode)){
if($aliases = $DB->get_field('enrol_coursealias', 'toids', array('fromid'=>$group->coursecode))){
$this->log_line("Found alias of course code: Translated $group->coursecode to $aliases");
// Alias is allowed to be a comma-separated list, so let's split it
$group->coursecode = explode(',', $aliases);
@@ -561,7 +563,7 @@ function process_group_tag($tagcontents){
$this->log_line('Failed to create course '.$coursecode.' in Moodle');
}
}
}elseif($recstatus==3 && ($courseid = get_field('course', 'id', 'idnumber', $coursecode))){
}elseif($recstatus==3 && ($courseid = $DB->get_field('course', 'id', array('idnumber'=>$coursecode)))){
// If course does exist, but recstatus==3 (delete), then set the course as hidden
$DB->set_field('course', 'visible', '0', array('id'=>$courseid));
}
+1 -1
View File
@@ -1055,7 +1055,7 @@ function stats_get_parameters($time,$report,$courseid,$mode,$roleid=0) {
case STATS_REPORT_ACTIVITYBYROLE;
$param->fields = 'stat1 AS line1, stat2 AS line2';
$param->stattype = 'activity';
$rolename = get_field('role','name','id',$roleid);
$rolename = $DB->get_field('role','name', array('id'=>$roleid));
$param->line1 = $rolename . get_string('statsreads');
$param->line2 = $rolename . get_string('statswrites');
if ($courseid == SITEID) {
+2 -2
View File
@@ -62,7 +62,7 @@ if ($p_secret !== false) {
// Clear secret so that it can not be used again
$user->secret = '';
if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
if (!$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id))) {
print_error('Error resetting user secret string');
}
@@ -114,7 +114,7 @@ if ($mform->is_cancelled()) {
// set 'secret' string
$user->secret = random_string(15);
if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
if (!$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id))) {
print_error('error setting user secret string');
}
+5 -3
View File
@@ -93,6 +93,8 @@ class mnet_environment {
}
function get_keypair() {
global $DB;
// We don't generate keys on install/upgrade because we want the USER
// record to have an email address, city and country already.
if (!empty($_SESSION['upgraderunning'])) return true;
@@ -100,7 +102,7 @@ class mnet_environment {
if (!empty($this->keypair)) return true;
$this->keypair = array();
$keypair = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl');
$keypair = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl'));
if (!empty($keypair)) {
// Explode/Implode is faster than Unserialize/Serialize
@@ -114,7 +116,7 @@ class mnet_environment {
// Key generation/rotation
// 1. Archive the current key (if there is one).
$result = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl_history');
$result = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl_history'));
if(empty($result)) {
set_config('openssl_history', serialize(array()), 'mnet');
$openssl_history = array();
@@ -129,7 +131,7 @@ class mnet_environment {
// 2. How many old keys do we want to keep? Use array_slice to get
// rid of any we don't want
$openssl_generations = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl_generations');
$openssl_generations = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl_generations'));
if(empty($openssl_generations)) {
set_config('openssl_generations', 3, 'mnet');
$openssl_generations = 3;
+2 -2
View File
@@ -289,10 +289,10 @@ function mnet_encrypt_message($message, $remote_certificate) {
* @return string The signature over that text
*/
function mnet_get_keypair() {
global $CFG;
global $CFG, $DB;;
static $keypair = null;
if (!is_null($keypair)) return $keypair;
if ($result = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl')) {
if ($result = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl'))) {
list($keypair['certificate'], $keypair['keypair_PEM']) = explode('@@@@@@@@', $result);
$keypair['privatekey'] = openssl_pkey_get_private($keypair['keypair_PEM']);
$keypair['publickey'] = openssl_pkey_get_public($keypair['certificate']);
+3 -3
View File
@@ -20,14 +20,14 @@ function useredit_update_user_preference($usernew) {
}
function useredit_update_picture(&$usernew, &$userform) {
global $CFG;
global $CFG, $DB;
if (isset($usernew->deletepicture) and $usernew->deletepicture) {
$location = make_user_directory($usernew->id, true);
@remove_dir($location);
set_field('user', 'picture', 0, 'id', $usernew->id);
$DB->set_field('user', 'picture', 0, array('id'=>$usernew->id));
} else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) {
set_field('user', 'picture', 1, 'id', $usernew->id);
$DB->set_field('user', 'picture', 1, array('id'=>$usernew->id));
}
}
+3 -1
View File
@@ -78,7 +78,9 @@ class user_filter_globalrole extends user_filter_type {
* @return string active filter label
*/
function get_label($data) {
$rolename = get_field('role', 'name', 'id', $data['value']);
global $DB;
$rolename = $DB->get_field('role', 'name', array('id'=>$data['value']));
$a = new object();
$a->label = $this->_label;
+1 -1
View File
@@ -13,7 +13,7 @@
if ($agree and confirm_sesskey()) { // User has agreed
if (!isguestuser()) { // Don't remember guests
if (!set_field('user', 'policyagreed', 1, 'id', $USER->id)) {
if (!$DB->set_field('user', 'policyagreed', 1, array('id'=>$USER->id))) {
print_error('Could not save your agreement');
}
}
+2 -2
View File
@@ -246,11 +246,11 @@
if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
if (!empty($enable)) { /// Recieved a parameter to enable the email address
set_field('user', 'emailstop', 0, 'id', $user->id);
$DB->set_field('user', 'emailstop', 0, array('id'=>$user->id));
$user->emailstop = 0;
}
if (!empty($disable)) { /// Recieved a parameter to disable the email address
set_field('user', 'emailstop', 1, 'id', $user->id);
$DB->set_field('user', 'emailstop', 1, array('id'=>$user->id));
$user->emailstop = 1;
}
}