From a656d95103a097f6e88677f39a562ad974a89fea Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 5 Jun 2008 19:26:57 +0000 Subject: [PATCH] MDL-15106 towards data mod dml conversion --- mod/data/backuplib.php | 34 +++++++++++----------- mod/data/comment.php | 16 +++++----- mod/data/css.php | 2 +- mod/data/edit.php | 24 +++++++-------- mod/data/export.php | 10 +++---- mod/data/field.php | 24 +++++++-------- mod/data/field/checkbox/field.class.php | 15 ++++++---- mod/data/field/date/field.class.php | 15 +++++----- mod/data/field/file/field.class.php | 20 +++++++------ mod/data/field/file/mod.html | 2 +- mod/data/field/latlong/field.class.php | 18 +++++++----- mod/data/field/latlong/kml.php | 22 +++++++------- mod/data/field/latlong/mod.html | 2 +- mod/data/field/menu/field.class.php | 11 +++---- mod/data/field/multimenu/field.class.php | 26 ++++++++++------- mod/data/field/number/field.class.php | 12 +++++--- mod/data/field/picture/field.class.php | 22 +++++++++----- mod/data/field/picture/mod.html | 2 +- mod/data/field/radiobutton/field.class.php | 4 +-- mod/data/field/textarea/field.class.php | 12 ++++---- mod/data/field/url/field.class.php | 17 +++++++---- mod/data/filter.php | 14 ++++----- mod/data/import.php | 17 +++++------ mod/data/index.php | 7 ++--- mod/data/js.php | 2 +- mod/data/lib.php | 2 +- 26 files changed, 190 insertions(+), 162 deletions(-) diff --git a/mod/data/backuplib.php b/mod/data/backuplib.php index c8a1e1e108..3065e8bf89 100644 --- a/mod/data/backuplib.php +++ b/mod/data/backuplib.php @@ -37,12 +37,12 @@ //Return a content encoded to support interactivities linking. Every module function data_backup_mods($bf,$preferences) { - global $CFG; + global $CFG, $DB; $status = true; // iterate - if ($datas = get_records('data','course',$preferences->backup_course,"id")) { + if ($datas = $DB->get_records('data', array('course'=>$preferences->backup_course),"id")) { foreach ($datas as $data) { if (function_exists('backup_mod_selected')) { // Moodle 1.6 @@ -61,10 +61,10 @@ function data_backup_mods($bf,$preferences) { } function data_backup_one_mod($bf,$preferences,$data) { - global $CFG; + global $CFG, $DB; if (is_numeric($data)) { // backwards compatibility - $data = get_record('data','id',$data); + $data = $DB->get_record('data', array('id'=>$data)); } $instanceid = $data->id; @@ -125,10 +125,10 @@ function data_backup_one_mod($bf,$preferences,$data) { function backup_data_fields($bf,$preferences,$dataid){ - global $CFG; + global $CFG, $DB; $status = true; - $data_fields = get_records("data_fields","dataid",$dataid); + $data_fields = $DB->get_records("data_fields", array("dataid"=>$dataid)); //If there is submissions if ($data_fields) { @@ -165,10 +165,10 @@ function backup_data_fields($bf,$preferences,$dataid){ } function backup_data_content($bf,$preferences,$recordid){ - global $CFG; + global $CFG, $DB; $status = true; - $data_contents = get_records("data_content","recordid",$recordid); + $data_contents = $DB->get_records("data_content", array("recordid"=>$recordid)); //If there is submissions if ($data_contents) { @@ -197,9 +197,10 @@ function backup_data_content($bf,$preferences,$recordid){ } function backup_data_ratings($bf,$preferences,$recordid){ - global $CFG; + global $CFG, $DB; + $status = true; - $data_ratings = get_records("data_ratings","recordid",$recordid); + $data_ratings = $DB->get_records("data_ratings", array("recordid"=>$recordid)); //If there is submissions if ($data_ratings) { @@ -225,9 +226,10 @@ function backup_data_ratings($bf,$preferences,$recordid){ return $status; } function backup_data_comments($bf,$preferences,$recordid){ - global $CFG; + global $CFG, $DB; + $status = true; - $data_comments = get_records("data_comments","recordid",$recordid); + $data_comments = $DB->get_records("data_comments", array("recordid"=>$recordid)); //If there is submissions if ($data_comments) { @@ -275,11 +277,11 @@ function backup_data_files_instance($bf,$preferences,$instanceid) { } function backup_data_records($bf,$preferences,$dataid){ + global $CFG, $DB; - global $CFG; $status = true; - $data_records = get_records("data_records","dataid",$dataid); + $data_records = $DB->get_records("data_records", array("dataid"=>$dataid)); //If there is submissions if ($data_records) { //Write start tag @@ -312,7 +314,6 @@ function backup_data_records($bf,$preferences,$dataid){ } function backup_data_files($bf,$preferences) { - global $CFG; $status = true; @@ -333,8 +334,8 @@ function backup_data_files($bf,$preferences) { } function backup_data_file_instance($bf,$preferences,$instanceid) { - global $CFG; + $status = true; //First we check to moddata exists and create it as necessary @@ -396,7 +397,6 @@ function data_check_backup_mods($course,$user_data=false,$backup_unique_code,$in * @return string the content encoded */ function data_encode_content_links ($content,$preferences) { - global $CFG; $base = preg_quote($CFG->wwwroot,"/"); diff --git a/mod/data/comment.php b/mod/data/comment.php index bed2afe83f..b486812535 100755 --- a/mod/data/comment.php +++ b/mod/data/comment.php @@ -14,13 +14,13 @@ $confirm = optional_param('confirm','',PARAM_INT); - if (! $record = get_record('data_records', 'id', $rid)) { + if (! $record = $DB->get_record('data_records', array('id'=>$rid))) { 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'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { @@ -32,7 +32,7 @@ $context = get_context_instance(CONTEXT_MODULE, $cm->id); if ($commentid) { - if (! $comment = get_record('data_comments', 'id', $commentid)) { + if (! $comment = $DB->get_record('data_comments', array('id'=>$commentid))) { print_error('commentmisconf'); } if ($comment->recordid != $record->id) { @@ -68,7 +68,7 @@ switch ($mode) { case 'add': - if (!$formadata = $mform->get_data()) { + if (!$formadata = $mform->get_data(false)) { break; // something is wrong here, try again } @@ -78,7 +78,7 @@ $newcomment->modified = time(); $newcomment->content = $formadata->content; $newcomment->recordid = $formadata->rid; - if (insert_record('data_comments',$newcomment)) { + if ($DB->insert_record('data_comments',$newcomment)) { redirect('view.php?rid='.$record->id.'&page='.$page); } else { print_error('cannotsavecomment'); @@ -97,7 +97,7 @@ $updatedcomment->format = $formadata->format; $updatedcomment->modified = time(); - if (update_record('data_comments',$updatedcomment)) { + if ($DB->update_record('data_comments', $updatedcomment)) { redirect('view.php?rid='.$record->id.'&page='.$page); } else { print_error('cannotsavecomment'); @@ -106,7 +106,7 @@ case 'delete': //deletes single comment from db if ($confirm and confirm_sesskey() and $comment) { - delete_records('data_comments','id',$comment->id); + $DB->delete_records('data_comments', array('id'=>$comment->id)); redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentdeleted', 'data')); } else { //print confirm delete form diff --git a/mod/data/css.php b/mod/data/css.php index 00469ed2ed..393d9eacbe 100755 --- a/mod/data/css.php +++ b/mod/data/css.php @@ -29,7 +29,7 @@ $d = optional_param('d', 0, PARAM_INT); // database id - if ($data = get_record('data', 'id', $d)) { + if ($data = $DB->get_record('data', array('id'=>$d))) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT'); header('Cache-control: max_age = '. $lifetime); diff --git a/mod/data/edit.php b/mod/data/edit.php index b699caace0..25a4f3f512 100755 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -37,18 +37,18 @@ 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('invalidcoursemodule'); } } else { - 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)) { @@ -75,7 +75,7 @@ /// Can't use this if there are no fields 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 } } @@ -141,14 +141,14 @@ /// Process incoming data for adding/updating records - if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/edit.php') and confirm_sesskey()) { + if ($datarecord = data_submitted(false) and confirm_sesskey()) { $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel'); // strings to be ignored in input data if ($rid) { /// Update some records /// All student edits are marked unapproved by default - $record = get_record('data_records','id',$rid); + $record = $DB->get_record('data_records', array('id'=>$rid)); /// reset approved flag after student edit if (!has_capability('mod/data:approve', $context)) { @@ -157,7 +157,7 @@ $record->groupid = $currentgroup; $record->timemodified = time(); - update_record('data_records',$record); + $DB->update_record('data_records', $record); /// Update all content $field = NULL; @@ -216,11 +216,11 @@ if (!$emptyform && $recordid = data_add_record($data, $currentgroup)) { //add instance to data_record /// Insert a whole lot of empty records to make sure we have them - $fields = get_records('data_fields','dataid',$data->id); + $fields = $DB->get_records('data_fields', array('dataid'=>$data->id)); foreach ($fields as $field) { $content->recordid = $recordid; $content->fieldid = $field->id; - insert_record('data_content',$content); + $DB->insert_record('data_content',$content); } //for each field in the add form, add it to the data_content. @@ -268,7 +268,7 @@ * Regular expression replacement section * ******************************************/ if ($data->addtemplate){ - $possiblefields = get_records('data_fields','dataid',$data->id,'id'); + $possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id'); ///then we generate strings to replace foreach ($possiblefields as $eachfield){ @@ -340,7 +340,7 @@ /// Finish the page // Print the stuff that need to come after the form fields. - if (!$fields = get_records('data_fields', 'dataid', $data->id)) { + if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) { print_error('nofieldindatabase', 'data'); } foreach ($fields as $eachfield) { diff --git a/mod/data/export.php b/mod/data/export.php index 81283e10a1..a3e8fdba1b 100644 --- a/mod/data/export.php +++ b/mod/data/export.php @@ -8,7 +8,7 @@ require_once('export_form.php'); $d = required_param('d', PARAM_INT); // database ID -if (! $data = get_record('data', 'id', $d)) { +if (! $data = $DB->get_record('data', array('id'=>$d))) { print_error('wrongdataid', 'data'); } @@ -16,7 +16,7 @@ if (! $cm = get_coursemodule_from_instance('data', $data->id, $data->course)) { print_error('invalidcoursemodule'); } -if(! $course = get_record('course', 'id', $cm->course)) { +if(! $course = $DB->get_record('course', array('id'=>$cm->course))) { print_error('invalidcourseid', '', '', $cm->course); } @@ -33,7 +33,7 @@ require_login($course->id, false, $cm); require_capability('mod/data:managetemplates', $context); // get fields for this database -$fieldrecords = get_records('data_fields','dataid', $data->id, 'id'); +$fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id'); if(empty($fieldrecords)) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -85,12 +85,12 @@ foreach($fields as $key => $field) { } } -$datarecords = get_records('data_records', 'dataid', $data->id); +$datarecords = $DB->get_records('data_records', array('dataid'=>$data->id)); ksort($datarecords); $line = 1; foreach($datarecords as $record) { // get content indexed by fieldid - if( $content = get_records('data_content', 'recordid', $record->id, 'fieldid', 'fieldid, content, content1, content2, content3, content4') ) { + if( $content = $DB->get_records('data_content', array('recordid'=>$record->id), 'fieldid', 'fieldid, content, content1, content2, content3, content4') ) { foreach($fields as $field) { $contents = ''; if(isset($content[$field->field->id])) { diff --git a/mod/data/field.php b/mod/data/field.php index c041ce4e32..2a62ffacf5 100755 --- a/mod/data/field.php +++ b/mod/data/field.php @@ -44,18 +44,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)) { @@ -74,7 +74,7 @@ switch ($mode) { case 'add': ///add a new field - if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){ + if (confirm_sesskey() and $fieldinput = data_submitted(false)){ //$fieldinput->name = data_clean_field_name($fieldinput->name); @@ -96,7 +96,7 @@ $field->insert_field(); /// Update some templates - data_append_new_field_to_templates($data, stripslashes($fieldinput->name)); + data_append_new_field_to_templates($data, $fieldinput->name); add_to_log($course->id, 'data', 'fields add', "field.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id); @@ -108,7 +108,7 @@ case 'update': ///update a field - if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){ + if (confirm_sesskey() and $fieldinput = data_submitted(false)){ //$fieldinput->name = data_clean_field_name($fieldinput->name); @@ -168,7 +168,7 @@ $rec->id = $data->id; $rec->defaultsort = 0; $rec->defaultsortdir = 0; - if (!update_record('data', $rec)) { + if (!$DB->update_record('data', $rec)) { error('There was an error updating the database'); } } @@ -203,7 +203,7 @@ $rec->defaultsort = $defaultsort; $rec->defaultsortdir = $defaultsortdir; - if (update_record('data', $rec)) { + if ($DB->update_record('data', $rec)) { redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('changessaved'), 2); } else { error('There was an error updating the database'); @@ -250,7 +250,7 @@ data_print_header($course,$cm,$data,'fields'); - if (!record_exists('data_fields','dataid',$data->id)) { + if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { notify(get_string('nofieldindatabase','data')); // nothing in database notify(get_string('pleaseaddsome','data', 'preset.php?id='.$cm->id)); // link to presets @@ -260,7 +260,7 @@ $table->align = array('left','left','left', 'center'); $table->wrap = array(false,false,false,false); - if ($fff = get_records('data_fields','dataid',$data->id,'id')){ + if ($fff = $DB->get_records('data_fields', array('dataid'=>$data->id),'id')){ foreach ($fff as $ff) { $field = data_get_field($ff, $data); @@ -302,7 +302,7 @@ echo ''; echo ''; echo '