diff --git a/mod/data/db/upgrade.php b/mod/data/db/upgrade.php
index af524e3e87e..f82f8d79714 100644
--- a/mod/data/db/upgrade.php
+++ b/mod/data/db/upgrade.php
@@ -41,7 +41,7 @@ function xmldb_data_upgrade($oldversion=0) {
if ($result && $oldversion < 2007101513) {
// Upgrade all the data->notification currently being
// NULL to 0
- $sql = "UPDATE {$CFG->prefix}data SET notification=0 WHERE notification IS NULL";
+ $sql = "UPDATE {data} SET notification=0 WHERE notification IS NULL";
$result = $DB->execute($sql);
$table = new xmldb_table('data');
diff --git a/mod/data/preset.php b/mod/data/preset.php
index ac57b89c08d..29fe961ab17 100644
--- a/mod/data/preset.php
+++ b/mod/data/preset.php
@@ -27,17 +27,17 @@ if ($id) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record('course', 'id', $cm->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}
- if (! $data = get_record('data', 'id', $cm->instance)) {
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
print_error('invalidid', 'data');
}
} else if ($d) {
- if (! $data = get_record('data', 'id', $d)) {
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('invalidid', 'data');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
@@ -175,7 +175,7 @@ switch ($action) {
$strimportsuccess = get_string('importsuccess', 'data');
$straddentries = get_string('addentries', 'data');
$strtodatabase = get_string('todatabase', 'data');
- if (!get_records('data_records', 'dataid', $data->id)) {
+ if (!$DB->get_records('data_records', array('dataid'=>$data->id))) {
notify("$strimportsuccess $straddentries $strtodatabase", 'notifysuccess');
} else {
notify("$strimportsuccess", 'notifysuccess');
@@ -345,7 +345,7 @@ $i = 0;
foreach ($presets as $id => $preset) {
$screenshot = '';
if (!empty($preset->userid)) {
- $user = get_record('user', 'id', $preset->userid);
+ $user = $DB->get_record('user', array('id'=>$preset->userid));
$desc = $preset->name.' ('.fullname($user, true).')';
} else {
$desc = $preset->name;
diff --git a/mod/data/preset_class.php b/mod/data/preset_class.php
index 89a4852b092..8d73098f317 100644
--- a/mod/data/preset_class.php
+++ b/mod/data/preset_class.php
@@ -100,8 +100,9 @@ class Data_Preset
/**
* Constructor
*/
- function Data_Preset($shortname = null, $data_id = null, $directory = null, $user_id = null)
- {
+ function Data_Preset($shortname = null, $data_id = null, $directory = null, $user_id = null) {
+ global $DB;
+
$this->shortname = $shortname;
$this->user_id = $user_id;
@@ -112,7 +113,7 @@ class Data_Preset
}
if (!empty($data_id)) {
- if (!$this->data = get_record('data', 'id', $data_id)) {
+ if (!$this->data = $DB->get_record('data', array('id'=>$data_id))) {
print_error('wrongdataid','data');
} else {
$this->listtemplate = $this->data->listtemplate;
@@ -127,7 +128,7 @@ class Data_Preset
}
}
- /*
+ /**
* Returns the best name to show for a preset
* If the shortname has spaces in it, replace them with underscores.
* Convert the name to lower case.
@@ -233,7 +234,8 @@ class Data_Preset
* @return string The path/name of the resulting zip file if successful.
*/
function export() {
- global $CFG;
+ global $CFG, $DB;
+
$this->directory = $CFG->dataroot.'/temp';
// write all templates, but not the xml yet
@@ -245,7 +247,7 @@ class Data_Preset
}
/* All the display data is now done. Now assemble preset.xml */
- $fields = get_records('data_fields', 'dataid', $this->data->id);
+ $fields = $DB->get_records('data_fields', array('dataid'=>$this->data->id));
$presetfile = fopen($this->directory.'/preset.xml', 'w');
$presetxml = "\n\n";
@@ -313,7 +315,8 @@ class Data_Preset
* TODO document
*/
function load_from_file($directory = null) {
- global $CFG;
+ global $CFG, $DB;
+
if (empty($directory) && empty($this->directory)) {
$this->directory = $this->get_path();
}
@@ -363,7 +366,7 @@ class Data_Preset
/* Now we look at the current structure (if any) to work out whether we need to clear db
or save the data */
$currentfields = array();
- $currentfields = get_records('data_fields', 'dataid', $this->data->id);
+ $currentfields = $DB->get_records('data_fields', array('dataid'=>$this->data->id));
$currentfields = array_merge($currentfields);
return array($settings, $fields, $currentfields);
}
@@ -499,11 +502,11 @@ class Data_Preset
$id = $currentfield->id;
// Why delete existing data records and related comments/ratings ??
/*
- if ($content = get_records('data_content', 'fieldid', $id)) {
+ if ($content = $DB->get_records('data_content', array('fieldid'=>$id))) {
foreach ($content as $item) {
- delete_records('data_ratings', 'recordid', $item->recordid);
- delete_records('data_comments', 'recordid', $item->recordid);
- delete_records('data_records', 'id', $item->recordid);
+ $DB->delete_records('data_ratings', array('recordid'=>$item->recordid));
+ $DB->delete_records('data_comments', array('recordid'=>$item->recordid));
+ $DB->delete_records('data_records', array('id'=>$item->recordid));
}
}
*/
@@ -538,13 +541,11 @@ class Data_Preset
// ACTION METHODS //
////////////////////
- function action_base($params)
- {
+ function action_base($params) {
return null;
}
- function action_confirmdelete($params)
- {
+ function action_confirmdelete($params) {
global $CFG, $USER;
$html = '';
$course = $params['course'];
@@ -587,9 +588,9 @@ class Data_Preset
exit();
}
- function action_delete($params)
- {
+ function action_delete($params) {
global $CFG, $USER;
+
$course = $params['course'];
$shortname = $params['shortname'];
@@ -623,8 +624,7 @@ class Data_Preset
notify("$shortname $strdeleted", 'notifysuccess');
}
- function action_importpreset($params)
- {
+ function action_importpreset($params) {
$course = $params['course'];
if (!data_submitted() or !confirm_sesskey()) {
print_error('invalidrequest');
@@ -641,8 +641,7 @@ class Data_Preset
exit();
}
- function action_importzip($params)
- {
+ function action_importzip($params) {
global $CFG, $USER;
$course = $params['course'];
if (!data_submitted() or !confirm_sesskey()) {
@@ -667,8 +666,9 @@ class Data_Preset
exit();
}
- function action_finishimport($params)
- {
+ function action_finishimport($params) {
+ global $DB;
+
if (!data_submitted() or !confirm_sesskey()) {
print_error('invalidrequest');
}
@@ -679,15 +679,14 @@ class Data_Preset
$strimportsuccess = get_string('importsuccess', 'data');
$straddentries = get_string('addentries', 'data');
$strtodatabase = get_string('todatabase', 'data');
- if (!get_records('data_records', 'dataid', $this->data->id)) {
+ if (!$DB->get_records('data_records', array('dataid'=>$this->data->id))) {
notify('$strimportsuccess $straddentries $strtodatabase", 'notifysuccess');
} else {
notify("$strimportsuccess", 'notifysuccess');
}
}
- function action_export($params)
- {
+ function action_export($params) {
global $CFG, $USER;
$course = $params['course'];
$html = '';
@@ -720,8 +719,7 @@ class Data_Preset
/**
* First stage of saving a Preset: ask for a name
*/
- function action_save1($params)
- {
+ function action_save1($params) {
$html = '';
$sesskey = sesskey();
$course = $params['course'];
@@ -751,8 +749,7 @@ class Data_Preset
* Second stage of saving a preset: If the given name already exists,
* suggest to use a different name or offer to overwrite the existing preset.
*/
- function action_save2($params)
- {
+ function action_save2($params) {
$course = $params['course'];
$this->data = $params['data'];
@@ -798,8 +795,7 @@ class Data_Preset
/**
* Third stage of saving a preset, overwrites an existing preset with the new one.
*/
- function action_save3($params)
- {
+ function action_save3($params) {
global $CFG, $USER;
if (!data_submitted() or !confirm_sesskey()) {
print_error('invalidrequest');
diff --git a/mod/data/preset_new.php b/mod/data/preset_new.php
index ed7a0459ed9..a5132f74512 100755
--- a/mod/data/preset_new.php
+++ b/mod/data/preset_new.php
@@ -28,17 +28,17 @@ if ($id) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record('course', 'id', $cm->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}
- if (! $data = get_record('data', 'id', $cm->instance)) {
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
print_error('invalidid', 'data');
}
} else if ($d) {
- if (! $data = get_record('data', 'id', $d)) {
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
print_error('invalidid', 'data');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
@@ -139,7 +139,7 @@ $i = 0;
foreach ($presets as $id => $preset) {
$screenshot = '';
if (!empty($preset->user_id)) {
- $user = get_record('user', 'id', $preset->user_id);
+ $user = $DB->get_record('user', array('id'=>$preset->user_id));
$desc = $preset->name.' ('.fullname($user, true).')';
} else {
$desc = $preset->name;
diff --git a/mod/data/rate.php b/mod/data/rate.php
index d4b38ad6df4..eff04e9f60a 100755
--- a/mod/data/rate.php
+++ b/mod/data/rate.php
@@ -4,11 +4,11 @@
$dataid = required_param('dataid', PARAM_INT); // The forum the rated posts are from
- if (!$data = get_record('data', 'id', $dataid)) {
+ if (!$data = $DB->get_record('data', array('id'=>$dataid))) {
print_error('invalidid', 'data');
}
- if (!$course = get_record('course', 'id', $data->course)) {
+ if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('invalidcourseid');
}
@@ -40,7 +40,7 @@
continue;
}
- if (!$record = get_record('data_records', 'id', $recordid)) {
+ if (!$record = $DB->get_record('data_records', array('id'=>$recordid))) {
print_error('invalidid', 'data');
}
@@ -56,14 +56,14 @@
$count++;
- if ($oldrating = get_record('data_ratings', 'userid', $USER->id, 'recordid', $record->id)) {
+ if ($oldrating = $DB->get_record('data_ratings', array('userid'=>$USER->id, 'recordid'=>$record->id))) {
if ($rating == -999) {
- delete_records('data_ratings', 'userid', $oldrating->userid, 'recordid', $oldrating->recordid);
+ $DB->delete_records('data_ratings', array('userid'=>$oldrating->userid, 'recordid'=>$oldrating->recordid));
data_update_grades($data, $record->userid);
} else if ($rating != $oldrating->rating) {
$oldrating->rating = $rating;
- if (! update_record('data_ratings', $oldrating)) {
+ if (!$DB->update_record('data_ratings', $oldrating)) {
print_error('cannotupdaterate', 'data', '', array($record->id, $rating));
}
data_update_grades($data, $record->userid);
@@ -75,7 +75,7 @@
$newrating->userid = $USER->id;
$newrating->recordid = $record->id;
$newrating->rating = $rating;
- if (! insert_record('data_ratings', $newrating)) {
+ if (! $DB->insert_record('data_ratings', $newrating)) {
print_error('cannotinsertrate', 'data', '', array($record->id, $rating));
}
data_update_grades($data, $record->userid);
diff --git a/mod/data/report.php b/mod/data/report.php
index 75e7af88847..d73a006bacd 100755
--- a/mod/data/report.php
+++ b/mod/data/report.php
@@ -8,15 +8,15 @@
$id = required_param('id', PARAM_INT);
$sort = optional_param('sort', '', PARAM_ALPHA);
- if (!$record = get_record('data_records', 'id', $id)) {
+ if (!$record = $DB->get_record('data_records', array('id'=>$id))) {
print_error('invalidrecord', 'data');
}
- if (!$data = get_record('data', 'id', $record->dataid)) {
+ if (!$data = $DB->get_record('data', array('id'=>$record->dataid))) {
print_error('invalidid', 'data');
}
- if (!$course = get_record('course', 'id', $data->course)) {
+ if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
print_error('coursemisconf');
}
diff --git a/mod/data/rsslib.php b/mod/data/rsslib.php
index 675c7b40eef..7f735407904 100644
--- a/mod/data/rsslib.php
+++ b/mod/data/rsslib.php
@@ -7,7 +7,7 @@
function data_rss_feeds() {
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -22,14 +22,14 @@
// It's working so we start...
else {
// Iterate over all data.
- if ($datas = get_records('data')) {
+ if ($datas = $DB->get_records('data')) {
foreach ($datas as $data) {
if ($data->rssarticles > 0) {
// Get the first field in the list (a hack for now until we have a selector)
- if (!$firstfield = get_record_sql('SELECT id,name from '.$CFG->prefix.'data_fields WHERE dataid = '.$data->id.' ORDER by id', true)) {
+ if (!$firstfield = $DB->get_record_sql('SELECT id,name FROM {data_fields} WHERE dataid = ? ORDER by id', array($data->id), true)) {
continue;
}
@@ -37,13 +37,13 @@
// Get the data_records out.
$approved = ($data->approval) ? ' AND dr.approved = 1 ' : ' ';
- $sql = 'SELECT dr.*, u.firstname, u.lastname ' .
- "FROM {$CFG->prefix}data_records dr, {$CFG->prefix}user u " .
- "WHERE dr.dataid = {$data->id} " .$approved.
- ' AND dr.userid = u.id '.
- 'ORDER BY dr.timecreated DESC';
+ $sql = "SELECT dr.*, u.firstname, u.lastname
+ FROM {data_records} dr, {user} u
+ WHERE dr.dataid = ? $approved
+ AND dr.userid = u.id
+ ORDER BY dr.timecreated DESC";
- if (!$records = get_records_sql($sql, 0, $data->rssarticles)) {
+ if (!$records = $DB->get_records_sql($sql, array($data->id), 0, $data->rssarticles)) {
continue;
}
@@ -72,8 +72,8 @@
if (!empty($data->rsstitletemplate)) {
$item->title = data_print_template('rsstitletemplate', $recordarray, $data, '', 0, true);
} else { // else we guess
- $item->title = strip_tags(get_field('data_content', 'content',
- 'fieldid', $firstfield->id, 'recordid', $record->id));
+ $item->title = strip_tags($DB->get_field('data_content', 'content',
+ array('fieldid'=>$firstfield->id, 'recordid'=>$record->id)));
}
$item->description = data_print_template('rsstemplate', $recordarray, $data, '', 0, true);
$item->pubdate = $record->timecreated;
@@ -81,7 +81,7 @@
array_push($items, $item);
}
- $course = get_record('course', 'id', $data->course);
+ $course = $DB->get_record('course', array('id'=>$data->course));
// First all rss feeds common headers.
$header = rss_standard_header($course->shortname.': '.format_string($data->name,true),
diff --git a/mod/data/templates.php b/mod/data/templates.php
index 2ec039c7661..86c24c0e2e0 100755
--- a/mod/data/templates.php
+++ b/mod/data/templates.php
@@ -34,18 +34,18 @@
if (! $cm = get_coursemodule_from_id('data', $id)) {
error('Course Module ID was incorrect');
}
- if (! $course = get_record('course', 'id', $cm->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
error('Course is misconfigured');
}
- if (! $data = get_record('data', 'id', $cm->instance)) {
+ if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) {
error('Course module is incorrect');
}
} else {
- if (! $data = get_record('data', 'id', $d)) {
+ if (! $data = $DB->get_record('data', array('id'=>$d))) {
error('Data ID is incorrect');
}
- if (! $course = get_record('course', 'id', $data->course)) {
+ if (! $course = $DB->get_record('course', array('id'=>$data->course))) {
error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
@@ -58,7 +58,7 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:managetemplates', $context);
- if (!count_records('data_fields','dataid',$data->id)) { // Brand new database!
+ if (!$DB->count_records('data_fields', array('dataid'=>$data->id))) { // Brand new database!
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
}
@@ -144,7 +144,7 @@
// Check for multiple tags, only need to check for add template.
if ($mode != 'addtemplate' or data_tags_check($data->id, $newtemplate->{$mode})) {
- if (update_record('data', $newtemplate)) {
+ if ($DB->update_record('data', $newtemplate)) {
notify(get_string('templatesaved', 'data'), 'notifysuccess');
}
}
@@ -172,7 +172,7 @@
if (!$resettemplate) {
// Only reload if we are not resetting the template to default.
- $data = get_record('data', 'id', $d);
+ $data = $DB->get_record('data', array('id'=>$d));
}
print_simple_box_start('center','80%');
echo '';
@@ -202,7 +202,7 @@
echo '