new test for diagnosing of Postgresql 9.0 problems with BLOBS
[moodle.git] / question / backuplib.php
CommitLineData
aeb15530 1<?php
924ff16a 2
3 //This function backups question_numerical_units from different question types
fe1106f0 4 function question_backup_numerical_units($bf,$preferences,$question,$level=7) {
bae73624 5 global $CFG, $DB;
924ff16a 6
7 $status = true;
8
bae73624 9 $numerical_units = $DB->get_records("question_numerical_units", array("question"=>$question), "id");
924ff16a 10 //If there are numericals_units
11 if ($numerical_units) {
271e6dec 12 $status = $status && fwrite ($bf,start_tag("NUMERICAL_UNITS",$level,true));
924ff16a 13 //Iterate over each numerical_unit
14 foreach ($numerical_units as $numerical_unit) {
271e6dec 15 $status = $status && fwrite ($bf,start_tag("NUMERICAL_UNIT",$level+1,true));
924ff16a 16 //Print numerical_unit contents
17 fwrite ($bf,full_tag("MULTIPLIER",$level+2,false,$numerical_unit->multiplier));
18 fwrite ($bf,full_tag("UNIT",$level+2,false,$numerical_unit->unit));
19 //Now backup numerical_units
271e6dec 20 $status = $status && fwrite ($bf,end_tag("NUMERICAL_UNIT",$level+1,true));
924ff16a 21 }
271e6dec 22 $status = $status && fwrite ($bf,end_tag("NUMERICAL_UNITS",$level,true));
924ff16a 23 }
24
25 return $status;
26
27 }
28
03990aa6 29 //This function backups question_numerical_options from different question types
30 function question_backup_numerical_options($bf,$preferences,$question,$level=7) {
31 global $CFG, $DB;
32
33 $status = true;
34 $numerical_options = $DB->get_records("question_numerical_options",array("questionid" => $question),"id");
35 if ($numerical_options) {
36 //Iterate over each numerical_option
37 foreach ($numerical_options as $numerical_option) {
38 $status = $status && fwrite ($bf,start_tag("NUMERICAL_OPTIONS",$level,true));
39 //Print numerical_option contents
40 fwrite ($bf,full_tag("INSTRUCTIONS",$level+1,false,$numerical_option->instructions));
41 fwrite ($bf,full_tag("SHOWUNITS",$level+1,false,$numerical_option->showunits));
42 fwrite ($bf,full_tag("UNITSLEFT",$level+1,false,$numerical_option->unitsleft));
43 fwrite ($bf,full_tag("UNITGRADINGTYPE",$level+1,false,$numerical_option->unitgradingtype));
44 fwrite ($bf,full_tag("UNITPENALTY",$level+1,false,$numerical_option->unitpenalty));
45 $status = $status && fwrite ($bf,end_tag("NUMERICAL_OPTIONS",$level,true));
46 }
47 }
48
49 return $status;
50
51 }
52
924ff16a 53 //This function backups dataset_definitions (via question_datasets) from different question types
fe1106f0 54 function question_backup_datasets($bf,$preferences,$question,$level=7) {
bae73624 55 global $CFG, $DB;
924ff16a 56
57 $status = true;
58
59 //First, we get the used datasets for this question
bae73624 60 $question_datasets = $DB->get_records("question_datasets", array("question"=>$question), "id");
924ff16a 61 //If there are question_datasets
62 if ($question_datasets) {
63 $status = $status &&fwrite ($bf,start_tag("DATASET_DEFINITIONS",$level,true));
64 //Iterate over each question_dataset
65 foreach ($question_datasets as $question_dataset) {
66 $def = NULL;
67 //Get dataset_definition
bae73624 68 if ($def = $DB->get_record("question_dataset_definitions", array("id"=>$question_dataset->datasetdefinition))) {;
924ff16a 69 $status = $status &&fwrite ($bf,start_tag("DATASET_DEFINITION",$level+1,true));
70 //Print question_dataset contents
71 fwrite ($bf,full_tag("CATEGORY",$level+2,false,$def->category));
72 fwrite ($bf,full_tag("NAME",$level+2,false,$def->name));
73 fwrite ($bf,full_tag("TYPE",$level+2,false,$def->type));
74 fwrite ($bf,full_tag("OPTIONS",$level+2,false,$def->options));
75 fwrite ($bf,full_tag("ITEMCOUNT",$level+2,false,$def->itemcount));
76 //Now backup dataset_entries
271e6dec 77 $status = $status && question_backup_dataset_items($bf,$preferences,$def->id,$level+2);
924ff16a 78 //End dataset definition
79 $status = $status &&fwrite ($bf,end_tag("DATASET_DEFINITION",$level+1,true));
80 }
81 }
82 $status = $status &&fwrite ($bf,end_tag("DATASET_DEFINITIONS",$level,true));
83 }
84
85 return $status;
86
87 }
88
89 //This function backups datases_items from dataset_definitions
fe1106f0 90 function question_backup_dataset_items($bf,$preferences,$datasetdefinition,$level=9) {
bae73624 91 global $CFG, $DB;
924ff16a 92
93 $status = true;
94
95 //First, we get the datasets_items for this dataset_definition
bae73624 96 $dataset_items = $DB->get_records("question_dataset_items", array("definition"=>$datasetdefinition), "id");
924ff16a 97 //If there are dataset_items
98 if ($dataset_items) {
99 $status = $status &&fwrite ($bf,start_tag("DATASET_ITEMS",$level,true));
100 //Iterate over each dataset_item
101 foreach ($dataset_items as $dataset_item) {
102 $status = $status &&fwrite ($bf,start_tag("DATASET_ITEM",$level+1,true));
103 //Print question_dataset contents
717cfb0a 104 fwrite ($bf,full_tag("NUMBER",$level+2,false,$dataset_item->itemnumber));
924ff16a 105 fwrite ($bf,full_tag("VALUE",$level+2,false,$dataset_item->value));
106 //End dataset definition
107 $status = $status &&fwrite ($bf,end_tag("DATASET_ITEM",$level+1,true));
108 }
109 $status = $status &&fwrite ($bf,end_tag("DATASET_ITEMS",$level,true));
110 }
111
112 return $status;
113
114 }