MDL-15106 towards data mod dml conversion

This commit is contained in:
skodak
2008-06-05 19:26:57 +00:00
parent b13746a483
commit a656d95103
26 changed files with 190 additions and 162 deletions
+17 -17
View File
@@ -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,"/");
+8 -8
View File
@@ -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
+1 -1
View File
@@ -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);
+12 -12
View File
@@ -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) {
+5 -5
View File
@@ -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])) {
+12 -12
View File
@@ -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 '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<label for="defaultsort">'.get_string('defaultsortfield','data').'</label>';
echo '<select id="defaultsort" name="defaultsort">';
if ($fields = get_records('data_fields','dataid',$data->id)) {
if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
echo '<optgroup label="'.get_string('fields', 'data').'">';
foreach ($fields as $field) {
if ($data->defaultsort == $field->id) {
+9 -6
View File
@@ -31,12 +31,12 @@ class data_field_checkbox extends data_field_base {
}
function display_add_field($recordid=0) {
global $CFG;
global $CFG, $DB;
$content = array();
if ($recordid) {
$content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
$content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$content = explode('##', $content);
}
@@ -87,22 +87,25 @@ class data_field_checkbox extends data_field_base {
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new object();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_checkbox_content($value);
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
return $DB->update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
return $DB->insert_record('data_content', $content);
}
}
function display_browse_field($recordid, $template) {
global $DB;
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$contentArr = array();
if (!empty($content->content)) {
$contentArr = explode('##', $content->content);
+8 -7
View File
@@ -39,9 +39,10 @@ class data_field_date extends data_field_base {
}
function display_add_field($recordid=0) {
global $DB;
if ($recordid) {
$content = (int) get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
$content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
} else {
$content = time();
}
@@ -81,6 +82,7 @@ class data_field_date extends data_field_base {
}
function update_content($recordid, $value, $name='') {
global $DB;
$names = explode('_',$name);
$name = $names[2]; // day month or year
@@ -94,20 +96,19 @@ class data_field_date extends data_field_base {
$content->recordid = $recordid;
$content->content = make_timestamp($this->year, $this->month, $this->day, 12, 0, 0, 0, false);
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
return $DB->update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
return $DB->insert_record('data_content', $content);
}
}
}
function display_browse_field($recordid, $template) {
global $CFG, $DB;
global $CFG;
if ($content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid)){
if ($content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
return userdate($content, get_string('strftimedate'), 0);
}
}
+11 -9
View File
@@ -30,9 +30,9 @@ class data_field_file extends data_field_base {
}
function display_add_field($recordid=0) {
global $CFG;
global $CFG, $DB;
if ($recordid){
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$contents[0] = $content->content;
$contents[1] = $content->content1;
} else {
@@ -87,8 +87,9 @@ class data_field_file extends data_field_base {
}
function display_browse_field($recordid, $template) {
global $CFG;
if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
global $CFG, $DB;
if (!$content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
return false;
}
$width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
@@ -109,13 +110,14 @@ class data_field_file extends data_field_base {
// content: "a##b" where a is the file name, b is the display name
function update_content($recordid, $value, $name) {
global $CFG;
if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
global $CFG, $DB;
if (!$oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
// Quickly make one now!
$oldcontent = new object;
$oldcontent->fieldid = $this->field->id;
$oldcontent->recordid = $recordid;
if ($oldcontent->id = insert_record('data_content', $oldcontent)) {
if ($oldcontent->id = $DB->insert_record('data_content', $oldcontent)) {
print_error('cannotinsertempty', 'data');
}
}
@@ -137,7 +139,7 @@ class data_field_file extends data_field_base {
if ($um->process_file_uploads($dir)) {
$newfile_name = $um->get_new_filename();
$content->content = $newfile_name;
update_record('data_content',$content);
$DB->update_record('data_content',$content);
}
}
break;
@@ -145,7 +147,7 @@ class data_field_file extends data_field_base {
case 'filename':
// only changing alt tag
$content->content1 = clean_param($value, PARAM_NOTAGS);
update_record('data_content', $content);
$DB->update_record('data_content', $content);
break;
default:
+1 -1
View File
@@ -12,7 +12,7 @@
<?php echo get_string('maxsize', 'data'); ?></label></td>
<td class="c1">
<?php
$course->maxbytes = get_field('course', 'maxbytes', 'id', $this->data->course);
$course->maxbytes = $DB->get_field('course', 'maxbytes', array('id'=>$this->data->course));
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
choose_from_menu($choices, 'param3', $this->field->param3, '', '', 0, false, false, 0, 'param3');
?>
+11 -7
View File
@@ -48,11 +48,12 @@ class data_field_latlong extends data_field_base {
}
function display_add_field($recordid=0) {
global $CFG;
global $CFG, $DB;
$lat = '';
$long = '';
if ($recordid) {
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$lat = $content->content;
$long = $content->content1;
}
@@ -95,8 +96,9 @@ class data_field_latlong extends data_field_base {
}
function display_browse_field($recordid, $template) {
global $CFG;
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
global $CFG, $DB;
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$lat = empty($content->content)? '':$content->content;
$long = empty($content->content1)? '':$content->content1;
if (empty($lat) or empty($long)) {
@@ -153,6 +155,8 @@ class data_field_latlong extends data_field_base {
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
@@ -169,11 +173,11 @@ class data_field_latlong extends data_field_base {
default:
break;
}
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
return $DB->update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
return $DB->insert_record('data_content', $content);
}
}
+11 -11
View File
@@ -13,38 +13,38 @@ $rid = optional_param('rid', 0, PARAM_INT); //record id
if ($rid) {
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)) {
print_error('invalidcoursemodule');
}
if (! $field = get_record('data_fields', 'id', $fieldid)) {
if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) {
print_error('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
print_error('invalidfieldtype', 'data');
}
if (! $content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $rid)) {
if (! $content = $DB->get_record('data_content', array('fieldid'=>$fieldid, 'recordid'=>$rid))) {
print_error('nofieldcontent', 'data');
}
} else { // We must have $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)) {
print_error('invalidcoursemodule');
}
if (! $field = get_record('data_fields', 'id', $fieldid)) {
if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) {
print_error('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
@@ -65,7 +65,7 @@ if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities'
/// 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
}
}
@@ -88,7 +88,7 @@ if($rid) { // List one single item
echo data_latlong_kml_placemark($pm);
} else { // List all items in turn
$contents = get_records('data_content', 'fieldid', $fieldid);
$contents = $DB->get_records('data_content', array('fieldid'=>$fieldid));
echo '<Document>';
@@ -147,7 +147,7 @@ function data_latlong_kml_get_item_name($content, $field) {
$name = '';
if($field->param2 > 0) {
$name = htmlspecialchars(get_field('data_content', 'content', 'fieldid', $field->param2, 'recordid', $content->recordid));
$name = htmlspecialchars($DB->get_field('data_content', 'content', array('fieldid'=>$field->param2, 'recordid'=>$content->recordid)));
}elseif($field->param2 == -2) {
$name = $content->content . ', ' . $content->content1;
}
+1 -1
View File
@@ -29,7 +29,7 @@
<option value="-2"<?php if($this->field->param2==-2) echo ' selected="selected"' ?>><?php echo get_string('latitude', 'data').'/'.get_string('longitude', 'data') ?></option>
<?php
// Fetch all "suitable" other fields that exist for this database
$textfields = get_records_select('data_fields', 'dataid='.$this->data->id.' AND type="text"');
$textfields = $DB->get_records_select('data_fields', array('dataid'=>$this->data->id, 'type'=>'text'));
echo '<optgroup label="'.get_string('latlongotherfields', 'data').':">';
if(sizeof($textfields)>0) {
foreach($textfields as $textfield) {
+6 -5
View File
@@ -31,9 +31,10 @@ class data_field_menu extends data_field_base {
}
function display_add_field($recordid=0) {
global $DB;
if ($recordid){
$content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
$content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$content = trim($content);
} else {
$content = '';
@@ -58,13 +59,13 @@ class data_field_menu extends data_field_base {
}
function display_search_field($content = '') {
global $CFG;
global $CFG, $DB;
$usedoptions = array();
$sql = "SELECT DISTINCT content
FROM {$CFG->prefix}data_content
WHERE fieldid={$this->field->id} AND content IS NOT NULL";
if ($used = get_records_sql($sql)) {
FROM {data_content}
WHERE fieldid=: AND content IS NOT NULL";
if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
foreach ($used as $data) {
$value = $data->content;
if ($value === '') {
+15 -11
View File
@@ -32,9 +32,10 @@ class data_field_multimenu extends data_field_base {
function display_add_field($recordid=0) {
global $DB;
if ($recordid){
$content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
$content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$content = explode('##', $content);
} else {
$content = array();
@@ -63,7 +64,7 @@ class data_field_multimenu extends data_field_base {
}
function display_search_field($value = '') {
global $CFG;
global $CFG, $DB;
if (is_array($value)){
$content = $value['selected'];
@@ -80,9 +81,9 @@ class data_field_multimenu extends data_field_base {
// display only used options
$usedoptions = array();
$sql = "SELECT DISTINCT content
FROM {$CFG->prefix}data_content
WHERE fieldid={$this->field->id} AND content IS NOT NULL";
if ($used = get_records_sql($sql)) {
FROM {data_content}
WHERE fieldid=? AND content IS NOT NULL";
if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
foreach ($used as $data) {
$valuestr = $data->content;
if ($valuestr === '') {
@@ -104,7 +105,7 @@ class data_field_multimenu extends data_field_base {
$found = true;
$str .= '<option value="' . s($option) . '"';
if (in_array(addslashes($option), $content)) {
if (in_array($option, $content)) {
// Selected by user.
$str .= ' selected = "selected"';
}
@@ -160,16 +161,18 @@ class data_field_multimenu extends data_field_base {
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_multimenu_content($value);
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
return $DB->update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
return $DB->insert_record('data_content', $content);
}
}
@@ -185,7 +188,7 @@ class data_field_multimenu extends data_field_base {
if ($key === 'xxx') {
continue;
}
if (!in_array(stripslashes($val), $options)) {
if (!in_array($val, $options)) {
continue;
}
$vals[] = $val;
@@ -200,8 +203,9 @@ class data_field_multimenu extends data_field_base {
function display_browse_field($recordid, $template) {
global $DB;
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
if (empty($content->content)) {
return false;
}
+8 -4
View File
@@ -30,6 +30,8 @@ class data_field_number extends data_field_base {
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
@@ -39,16 +41,18 @@ class data_field_number extends data_field_base {
} else {
$content->content = null;
}
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
return $DB->update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
return $DB->insert_record('data_content', $content);
}
}
function display_browse_field($recordid, $template) {
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
global $DB;
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
if (strlen($content->content) < 1) {
return false;
}
+14 -8
View File
@@ -35,12 +35,13 @@ class data_field_picture extends data_field_file {
}
function display_add_field($recordid=0) {
global $CFG;
global $CFG, $DB;
$filepath = '';
$filename = '';
$description = '';
if ($recordid) {
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$filename = $content->content;
$description = $content->content1;
}
@@ -79,8 +80,9 @@ class data_field_picture extends data_field_file {
}
function display_browse_field($recordid, $template) {
global $CFG;
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
global $CFG, $DB;
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
if (isset($content->content)) {
$contents[0] = $content->content;
$contents[1] = $content->content1;
@@ -118,9 +120,11 @@ class data_field_picture extends data_field_file {
}
function update_field() {
global $DB;
// Get the old field data so that we can check whether the thumbnail dimensions have changed
$oldfield = get_record('data_fields', 'id', $this->field->id);
if (!update_record('data_fields', $this->field)) {
$oldfield = $DB->get_record('data_fields', array('id'=>$this->field->id));
if (!$DB->update_record('data_fields', $this->field)) {
notify('updating of new field failed!');
return false;
}
@@ -128,7 +132,7 @@ class data_field_picture extends data_field_file {
// Have the thumbnail dimensions changed?
if ($oldfield && ($oldfield->param4 != $this->field->param4 || $oldfield->param5 != $this->field->param5)) {
// Check through all existing records and update the thumbnail
if ($contents = get_records('data_content', 'fieldid', $this->field->id)) {
if ($contents = $DB->get_records('data_content', array('fieldid'=>$this->field->id))) {
if (count($contents) > 20) {
notify(get_string('resizingimages', 'data'), 'notifysuccess');
echo "\n\n";
@@ -146,8 +150,10 @@ class data_field_picture extends data_field_file {
}
function update_content($recordid, $value, $name) {
global $DB;
parent::update_content($recordid, $value, $name);
$content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid);
$content = $DB->get_record('data_content',array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
$this->update_thumbnail($content);
// Regenerate the thumbnail
}
+1 -1
View File
@@ -44,7 +44,7 @@
<?php echo get_string('maxsize', 'data'); ?></label></td>
<td class="c1">
<?php
$course->maxbytes = get_field('course', 'maxbytes', 'id', $this->data->course);
$course->maxbytes = $DB->get_field('course', 'maxbytes', array('id'=>$this->data->course));
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
choose_from_menu($choices, 'param3', $this->field->param3, '', '', 0, false, false, 0, 'param3');
?>
+2 -2
View File
@@ -32,10 +32,10 @@ class data_field_radiobutton extends data_field_base {
function display_add_field($recordid=0) {
global $CFG;
global $CFG, $DB;
if ($recordid){
$content = trim(get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid));
$content = trim($DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)));
} else {
$content = '';
}
+7 -5
View File
@@ -32,13 +32,13 @@ class data_field_textarea extends data_field_base {
function display_add_field($recordid=0) {
global $CFG;
global $CFG, $DB;
$text = '';
$format = 0;
if ($recordid){
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$text = $content->content;
$format = $content->content1;
}
@@ -96,6 +96,8 @@ class data_field_textarea extends data_field_base {
function update_content($recordid, $value, $name='') {
global $DB;
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
@@ -107,11 +109,11 @@ class data_field_textarea extends data_field_base {
$content->content = clean_param($value, PARAM_CLEAN);
}
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
return $DB->update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
return $DB->insert_record('data_content', $content);
}
}
}
+11 -6
View File
@@ -30,11 +30,12 @@ class data_field_url extends data_field_base {
}
function display_add_field($recordid=0) {
global $CFG;
global $CFG, $DB;
$url = '';
$text = '';
if ($recordid) {
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$url = $content->content;
$text = $content->content1;
}
@@ -67,7 +68,9 @@ class data_field_url extends data_field_base {
}
function display_browse_field($recordid, $template) {
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
global $DB;
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$url = empty($content->content)? '':$content->content;
$text = empty($content->content1)? '':$content->content1;
if (empty($url) or ($url == 'http://')) {
@@ -93,6 +96,8 @@ class data_field_url extends data_field_base {
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
@@ -110,11 +115,11 @@ class data_field_url extends data_field_base {
break;
}
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
return $DB->update_record('data_content', $content);
} else {
return insert_record('data_content', $content);
return $DB->insert_record('data_content', $content);
}
}
+7 -7
View File
@@ -7,7 +7,7 @@
// Modified for data module by Vy-Shane SF.
function data_filter($courseid, $text) {
global $CFG;
global $CFG, $DB;
static $nothingtodo;
static $contentlist;
@@ -29,11 +29,11 @@
'dr.id AS recordid, ' .
'dc.content AS content, ' .
'd.id AS dataid ' .
'FROM '.$CFG->prefix.'data d, ' .
$CFG->prefix.'data_fields df, ' .
$CFG->prefix.'data_records dr, ' .
$CFG->prefix.'data_content dc ' .
"WHERE (d.course = '$courseid' or d.course = '".SITEID."')" .
'FROM {data} d, ' .
'{data_fields} df, ' .
'{data_records} dr, ' .
'{data_content} dc ' .
"WHERE (d.course = ? or d.course = '".SITEID."')" .
'AND d.id = df.dataid ' .
'AND df.id = dc.fieldid ' .
'AND d.id = dr.dataid ' .
@@ -41,7 +41,7 @@
"AND df.type = 'text' " .
'AND df.param1 = 1';
if (!$datacontents = get_records_sql($sql)) {
if (!$datacontents = $DB->get_records_sql($sql, array($courseid))) {
return $text;
}
+8 -9
View File
@@ -38,18 +38,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)) {
@@ -108,14 +108,14 @@
foreach ($records as $record) {
if ($recordid = data_add_record($data, 0)) { // add instance to data_record
$fields = get_records('data_fields', 'dataid', $data->id, '', 'name, id, type');
$fields = $DB->get_records('data_fields', array('dataid'=>$data->id), '', 'name, id, type');
// Insert new data_content fields with NULL contents:
foreach ($fields as $field) {
$content = new object();
$content->recordid = $recordid;
$content->fieldid = $field->id;
if (! insert_record('data_content', $content)) {
if (! $DB->insert_record('data_content', $content)) {
print_error('cannotinsertrecord', '', '', $recordid);
}
}
@@ -137,7 +137,6 @@
$replacements[] = '&gt;';
$value = preg_replace($patterns, $replacements, $value);
}
$value = addslashes($value);
// for now, only for "latlong" and "url" fields, but that should better be looked up from
// $CFG->dirroot . '/mod/data/field/' . $field->type . '/field.class.php'
// once there is stored how many contents the field can have.
@@ -148,9 +147,9 @@
} else {
$content->content = $value;
}
$oldcontent = get_record('data_content', 'fieldid', $field->id, 'recordid', $recordid);
$oldcontent = $DB->get_record('data_content', array('fieldid'=>$field->id, 'recordid'=>$recordid));
$content->id = $oldcontent->id;
if (! update_record('data_content', $content)) {
if (! $DB->update_record('data_content', $content)) {
print_error('cannotupdaterecord', '', '', $recordid);
}
}
+2 -5
View File
@@ -100,13 +100,10 @@
// TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
$numrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
'data_records r WHERE r.dataid ='.$data->id);
$numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
if ($data->approval == 1) {
$numunapprovedrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
'data_records r WHERE r.dataid ='.$data->id.
' AND r.approved <> 1');
$numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
} else {
$numunapprovedrecords = '-';
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -177,7 +177,7 @@ class data_field_base { // Base class for Database Field Types (see field/*/
// Print the relevant form element to define the attributes for this field
// viewable by teachers only.
function display_edit_field() {
global $CFG;
global $CFG, $DB;
if (empty($this->field)) { // No field has been defined yet, try and make one
$this->define_default_field();