new test for diagnosing of Postgresql 9.0 problems with BLOBS
[moodle.git] / question / backuplib.php
1 <?php
3     //This function backups question_numerical_units from different question types
4     function question_backup_numerical_units($bf,$preferences,$question,$level=7) {
5         global $CFG, $DB;
7         $status = true;
9         $numerical_units = $DB->get_records("question_numerical_units", array("question"=>$question), "id");
10         //If there are numericals_units
11         if ($numerical_units) {
12             $status = $status && fwrite ($bf,start_tag("NUMERICAL_UNITS",$level,true));
13             //Iterate over each numerical_unit
14             foreach ($numerical_units as $numerical_unit) {
15                 $status = $status && fwrite ($bf,start_tag("NUMERICAL_UNIT",$level+1,true));
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
20                 $status = $status && fwrite ($bf,end_tag("NUMERICAL_UNIT",$level+1,true));
21             }
22             $status = $status && fwrite ($bf,end_tag("NUMERICAL_UNITS",$level,true));
23         }
25         return $status;
27     }
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;
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         }
49         return $status;
51     }
53     //This function backups dataset_definitions (via question_datasets) from different question types
54     function question_backup_datasets($bf,$preferences,$question,$level=7) {
55         global $CFG, $DB;
57         $status = true;
59         //First, we get the used datasets for this question
60         $question_datasets = $DB->get_records("question_datasets", array("question"=>$question), "id");
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
68                 if ($def = $DB->get_record("question_dataset_definitions", array("id"=>$question_dataset->datasetdefinition))) {;
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
77                     $status = $status && question_backup_dataset_items($bf,$preferences,$def->id,$level+2);
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         }
85         return $status;
87     }
89     //This function backups datases_items from dataset_definitions
90     function question_backup_dataset_items($bf,$preferences,$datasetdefinition,$level=9) {
91         global $CFG, $DB;
93         $status = true;
95         //First, we get the datasets_items for this dataset_definition
96         $dataset_items = $DB->get_records("question_dataset_items", array("definition"=>$datasetdefinition), "id");
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
104                 fwrite ($bf,full_tag("NUMBER",$level+2,false,$dataset_item->itemnumber));
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         }
112         return $status;
114     }