Skip to content

Commit

Permalink
MDL-15106 towards data mod dml conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 5, 2008
1 parent b13746a commit a656d95
Show file tree
Hide file tree
Showing 26 changed files with 190 additions and 162 deletions.
34 changes: 17 additions & 17 deletions mod/data/backuplib.php
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -312,7 +314,6 @@ function backup_data_records($bf,$preferences,$dataid){
}

function backup_data_files($bf,$preferences) {

global $CFG;

$status = true;
Expand All @@ -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
Expand Down Expand Up @@ -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,"/");
Expand Down
16 changes: 8 additions & 8 deletions mod/data/comment.php
Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mod/data/css.php
Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions mod/data/edit.php
Expand Up @@ -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)) {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions mod/data/export.php
Expand Up @@ -8,15 +8,15 @@
$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');
}

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

Expand All @@ -33,7 +33,7 @@
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);
Expand Down Expand Up @@ -85,12 +85,12 @@
}
}

$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])) {
Expand Down

0 comments on commit a656d95

Please sign in to comment.