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');
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)) {
$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 <a href='edit.php?d=$data->id'>$straddentries</a> $strtodatabase", 'notifysuccess');
} else {
notify("$strimportsuccess", 'notifysuccess');
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;
/**
* 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;
}
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;
}
}
- /*
+ /**
* 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.
* @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
}
/* 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 = "<preset>\n\n";
* TODO document
*/
function load_from_file($directory = null) {
- global $CFG;
+ global $CFG, $DB;
+
if (empty($directory) && empty($this->directory)) {
$this->directory = $this->get_path();
}
/* 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);
}
$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));
}
}
*/
// 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'];
exit();
}
- function action_delete($params)
- {
+ function action_delete($params) {
global $CFG, $USER;
+
$course = $params['course'];
$shortname = $params['shortname'];
notify("$shortname $strdeleted", 'notifysuccess');
}
- function action_importpreset($params)
- {
+ function action_importpreset($params) {
$course = $params['course'];
if (!data_submitted() or !confirm_sesskey()) {
print_error('invalidrequest');
exit();
}
- function action_importzip($params)
- {
+ function action_importzip($params) {
global $CFG, $USER;
$course = $params['course'];
if (!data_submitted() or !confirm_sesskey()) {
exit();
}
- function action_finishimport($params)
- {
+ function action_finishimport($params) {
+ global $DB;
+
if (!data_submitted() or !confirm_sesskey()) {
print_error('invalidrequest');
}
$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 <a href="edit.php?d=' . $this->data->id . "\">$straddentries</a> $strtodatabase", 'notifysuccess');
} else {
notify("$strimportsuccess", 'notifysuccess');
}
}
- function action_export($params)
- {
+ function action_export($params) {
global $CFG, $USER;
$course = $params['course'];
$html = '';
/**
* First stage of saving a Preset: ask for a name
*/
- function action_save1($params)
- {
+ function action_save1($params) {
$html = '';
$sesskey = sesskey();
$course = $params['course'];
* 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'];
/**
* 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');
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)) {
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;
$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');
}
continue;
}
- if (!$record = get_record('data_records', 'id', $recordid)) {
+ if (!$record = $DB->get_record('data_records', array('id'=>$recordid))) {
print_error('invalidid', 'data');
}
$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);
$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);
$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');
}
function data_rss_feeds() {
- global $CFG;
+ global $CFG, $DB;
$status = true;
// 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;
}
// 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;
}
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;
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),
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)) {
$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
}
// 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');
}
}
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 '<table cellpadding="4" cellspacing="0" border="0">';
echo '<select name="fields1[]" id="availabletags" size="12" onclick="insert_field_tags(this)">';
- $fields = get_records('data_fields', 'dataid', $data->id);
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id));
echo '<optgroup label="'.get_string('fields', 'data').'">';
foreach ($fields as $field) {
echo '<option value="[['.$field->name.']]" title="'.$field->description.'">'.$field->name.' - [['.$field->name.']]</option>';
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');
}
$record = NULL;
} else if ($rid) {
- if (! $record = get_record('data_records', 'id', $rid)) {
+ if (! $record = $DB->get_record('data_records', array('id'=>$rid))) {
error('Record ID is incorrect');
}
- if (! $data = get_record('data', 'id', $record->dataid)) {
+ if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) {
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)) {
error('Course Module ID was incorrect');
}
} else { // We must have $d
- 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)) {
/// If we have an empty Database then redirect because this page is useless without data
if (has_capability('mod/data:managetemplates', $context)) {
- if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database!
+ if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database!
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
}
}
if (!empty($advanced)) {
$search = '';
$vals = array();
- $fields = get_records('data_fields', 'dataid', $data->id);
+ $fields = $DB->get_records('data_fields', array('dataid'=>$data->id));
//Added to ammend paging error. This error would occur when attempting to go from one page of advanced
//search results to another. All fields were reset in the page transfer, and there was no way of determining
if ($delete && confirm_sesskey() && (has_capability('mod/data:manageentries', $context) or data_isowner($delete))) {
if ($confirm = optional_param('confirm',0,PARAM_INT)) {
- if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
+ if ($deleterecord = $DB->get_record('data_records', array('id'=>$delete))) { // Need to check this is valid
if ($deleterecord->dataid == $data->id) { // Must be from this database
- if ($contents = get_records('data_content','recordid', $deleterecord->id)) {
+ if ($contents = $DB->get_records('data_content', array('recordid'=>$deleterecord->id))) {
foreach ($contents as $content) { // Delete files or whatever else this field allows
if ($field = data_get_field_from_id($content->fieldid, $data)) { // Might not be there
$field->delete_content($content->recordid);
}
}
}
- delete_records('data_content','recordid', $deleterecord->id);
- delete_records('data_records','id', $deleterecord->id);
+ $DB->delete_records('data_content', array('recordid'=>$deleterecord->id));
+ $DB->delete_records('data_records', array('id'=>$deleterecord->id));
add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
}
} else { // Print a confirmation page
- if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
+ if ($deleterecord = $DB->get_record('data_records', array('id'=>$delete))) { // Need to check this is valid
if ($deleterecord->dataid == $data->id) { // Must be from this database
notice_yesno(get_string('confirmdeleterecord','data'),
'view.php?d='.$data->id.'&delete='.$delete.'&confirm=1&sesskey='.sesskey(),
$approvecap = has_capability('mod/data:approve', $context);
if ($approve && confirm_sesskey() && $approvecap) {
- if ($approverecord = get_record('data_records', 'id', $approve)) { // Need to check this is valid
+ if ($approverecord = $DB->get_record('data_records', array('id'=>$approve))) { // Need to check this is valid
if ($approverecord->dataid == $data->id) { // Must be from this database
$newrecord->id = $approverecord->id;
$newrecord->approved = 1;
- if (update_record('data_records', $newrecord)) {
+ if ($DB->update_record('data_records', $newrecord)) {
notify(get_string('recordapproved','data'), 'notifysuccess');
}
}