Skip to content

Commit

Permalink
MDL-14679 converted some get/set_field()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 2, 2008
1 parent 1829e01 commit a5d424d
Show file tree
Hide file tree
Showing 31 changed files with 70 additions and 60 deletions.
2 changes: 1 addition & 1 deletion admin/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ function description() {
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.';
Expand Down
2 changes: 1 addition & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions admin/mnet/enr_hosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/peers.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
}
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);
}

Expand Down
4 changes: 2 additions & 2 deletions admin/report/backups/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>";
Expand All @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions admin/report/courseoverview/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion admin/report/courseoverview/reportsgraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/override.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion admin/uploadpicture.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
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 {
Expand Down
2 changes: 1 addition & 1 deletion admin/xmldb/actions/test/test.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ function invoke() {
$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;
Expand Down
4 changes: 2 additions & 2 deletions auth/mnet/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function start_jump_session($mnethostid, $wantsurl) {
* @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
Expand Down Expand Up @@ -425,7 +425,7 @@ function confirm_mnet_session($token, $remotewwwroot) {
$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]);
Expand Down
10 changes: 7 additions & 3 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,15 @@ function instance_config_print() {
* @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));
}

/**
Expand All @@ -743,11 +745,13 @@ function instance_config_save($data,$pinned=false) {
* @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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion blocks/section_links/block_section_links.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function get_content() {
}

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.'=';
Expand Down
2 changes: 1 addition & 1 deletion blog/rsslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function blog_generate_rss_feed($type, $id, $tagid=0) {
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 = '';
Expand Down
10 changes: 5 additions & 5 deletions course/editcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
$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();
Expand Down Expand Up @@ -226,7 +226,7 @@
$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!");
}
}
Expand Down Expand Up @@ -259,9 +259,9 @@
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!");
}
Expand Down
4 changes: 2 additions & 2 deletions course/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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');
}
}
Expand Down
10 changes: 5 additions & 5 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion course/report/outline/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
8 changes: 4 additions & 4 deletions course/report/stats/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ function report_stats_mode_menu($course, $mode, $time, $url) {


function report_stats_timeoptions($mode) {
global $CFG;
global $CFG, $DB;

$tableprefix = $CFG->prefix.'stats_';

if ($mode == STATS_MODE_DETAILED) {
$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();
Expand Down
2 changes: 1 addition & 1 deletion course/report/stats/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 5 additions & 3 deletions enrol/imsenterprise/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class enrolment_plugin_imsenterprise {
* 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':
Expand All @@ -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));
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/statslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions login/forgot_password.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

// 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');
}

Expand Down Expand Up @@ -114,7 +114,7 @@

// 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');
}

Expand Down
Loading

0 comments on commit a5d424d

Please sign in to comment.