move code up one directory
[atutor.git] / mods / _standard / tests / module_backup.php
1 <?php\r
2 \r
3 $sql = array();\r
4 \r
5 $sql['tests'] = 'SELECT test_id, title, format, start_date, end_date, randomize_order, num_questions, instructions, content_id, result_release, random, difficulty, num_takes, anonymous, out_of, guests, display, description, passscore, passpercent, passfeedback, failfeedback, show_guest_form FROM '.TABLE_PREFIX.'tests WHERE course_id=? ORDER BY test_id ASC';\r
6 \r
7 $sql['tests_questions_categories'] = 'SELECT category_id, title FROM '.TABLE_PREFIX.'tests_questions_categories WHERE course_id=?';\r
8 \r
9 $sql['tests_questions'] = 'SELECT question_id, category_id, type, feedback, question, choice_0, choice_1, choice_2, choice_3, choice_4, choice_5, choice_6, choice_7, choice_8, choice_9, answer_0, answer_1, answer_2, answer_3, answer_4, answer_5, answer_6, answer_7, answer_8, answer_9, option_0, option_1, option_2, option_3, option_4, option_5, option_6, option_7, option_8, option_9, properties, content_id FROM '.TABLE_PREFIX.'tests_questions WHERE course_id=?';\r
10 \r
11 $sql['tests_questions_assoc'] = 'SELECT TQ.test_id, question_id, weight, ordering, required FROM '.TABLE_PREFIX.'tests_questions_assoc TQ, '.TABLE_PREFIX.'tests T WHERE T.course_id=? AND T.test_id=TQ.test_id ORDER BY TQ.test_id';\r
12 \r
13 /* \r
14  * The content test association & content prerequisites cannot be put into the content/module_backup.php, because the $table_id_map does not include\r
15  * the test hash mapping until this is reached.\r
16  * And, for different content prerequisite type, the backup should be separated into different modules to \r
17  * find out the correct mapping id. For example, test prerequistes go into "tests" module backup, content \r
18  * prerequisites go into "content" module backup.\r
19  * @harris Sep 25, 08, cindy Nov 17, 2009\r
20  */\r
21 $sql['content_tests_assoc'] = 'SELECT cta.content_id, cta.test_id FROM '.TABLE_PREFIX.'content c, '.TABLE_PREFIX.'content_tests_assoc cta WHERE c.content_id = cta.content_id AND c.course_id = ? ORDER BY c.content_id';\r
22 \r
23 $sql['content_prerequisites'] = 'SELECT cp.content_id, cp.type, cp.item_id FROM '.TABLE_PREFIX.'content c, '.TABLE_PREFIX.'content_prerequisites cp WHERE c.content_id = cp.content_id AND c.course_id = ? ORDER BY c.content_id';\r
24 \r
25 function tests_convert($row, $course_id, $table_id_map, $version) {\r
26         $new_row = array();\r
27         $new_row[0]  = $row[0];\r
28         $new_row[1]  = $course_id;\r
29         $new_row[2]  = $row[1];\r
30         $new_row[3]  = $row[2];\r
31         $new_row[4]  = $row[3];\r
32         $new_row[5]  = $row[4];\r
33         $new_row[6]  = $row[5];\r
34         $new_row[7]  = $row[6];\r
35         $new_row[8]  = $row[7];\r
36         $new_row[9]  = 0;\r
37         $new_row[10] = $row[9]  ? $row[9]  : 0;\r
38         $new_row[11] = $row[10] ? $row[10] : 0;\r
39         $new_row[12] = $row[11] ? $row[11] : 0;\r
40         $new_row[13] = $row[12] ? $row[12] : 0;\r
41         $new_row[14] = $row[13] ? $row[13] : 0;\r
42         $new_row[15] = $row[14] ? $row[14] : 0;\r
43         $new_row[16] = $row[15] ? $row[15] : 0; // `guests`  added 1.5.4\r
44         $new_row[17] = $row[16] ? $row[16] : 0; // `display` added 1.5.6\r
45         $new_row[18]  = $row[17];\r
46         $new_row[19]  = $row[18];\r
47         $new_row[20]  = $row[19];\r
48         $new_row[21]  = $row[20];\r
49         $new_row[22]  = $row[21];\r
50         $new_row[23]  = $row[22];\r
51         return $new_row;\r
52 }\r
53 \r
54 function tests_questions_categories_convert($row, $course_id, $table_id_map, $version) {\r
55         $new_row = array();\r
56         $new_row[0] = $row[0];\r
57         $new_row[1] = $course_id;\r
58         $new_row[2] = $row[1];\r
59 \r
60         return $new_row;\r
61 }\r
62 \r
63 function tests_questions_convert($row, $course_id, $table_id_map, $version) {\r
64         $new_row = array();\r
65         $new_row[0]  = $row[0]; // question_id\r
66         $new_row[1]  = $table_id_map['tests_questions_categories'][$row[1]]; // category_id\r
67         $new_row[2]  = $course_id; // course_id, obviously\r
68         $new_row[3]  = $row[2];    // type\r
69         $new_row[4]  = $row[3];    // feedback\r
70         $new_row[5]  = $row[4];    // question\r
71         $new_row[6]  = $row[5];    // choice_0\r
72         $new_row[7]  = $row[6];    // choice_1\r
73         $new_row[8]  = $row[7];    // choice_2\r
74         $new_row[9]  = $row[8];    // choice_3\r
75         $new_row[10] = $row[9];    // choice_4\r
76         $new_row[11] = $row[10];   // choice_5\r
77         $new_row[12] = $row[11];   // choice_6\r
78         $new_row[13] = $row[12];   // choice_7\r
79         $new_row[14] = $row[13];   // choice_8\r
80         $new_row[15] = $row[14];   // choice_9\r
81         $new_row[16] = $row[15];   // answer_0\r
82         $new_row[17] = $row[16];   // answer_1\r
83         $new_row[18] = $row[17];   // answer_2\r
84         $new_row[19] = $row[18];   // answer_3\r
85         $new_row[20] = $row[19];   // answer_4\r
86         $new_row[21] = $row[20];   // answer_5\r
87         $new_row[22] = $row[21];   // answer_6\r
88         $new_row[23] = $row[22];   // answer_7\r
89         $new_row[24] = $row[23];   // answer_8\r
90         $new_row[25] = $row[24];   // answer_9\r
91         if (version_compare($version, '1.5.4', '<')) {\r
92                 // option_[0-9] were added in 1.5.4 before properties\r
93                 $new_row[26] = '';       // option_0\r
94                 $new_row[27] = '';       // option_1\r
95                 $new_row[28] = '';       // option_2\r
96                 $new_row[29] = '';       // option_3\r
97                 $new_row[30] = '';       // option_4\r
98                 $new_row[31] = '';       // option_5\r
99                 $new_row[32] = '';       // option_6\r
100                 $new_row[33] = '';       // option_7\r
101                 $new_row[34] = '';       // option_8\r
102                 $new_row[35] = '';       // option_9\r
103                 $new_row[36] = $row[25]; // properties\r
104                 $new_row[37] = $row[26]; // content_id\r
105         } else {\r
106                 $new_row[26] = $row[25]; // option_0\r
107                 $new_row[27] = $row[26]; // option_1\r
108                 $new_row[28] = $row[27]; // option_2\r
109                 $new_row[29] = $row[28]; // option_3\r
110                 $new_row[30] = $row[29]; // option_4\r
111                 $new_row[31] = $row[30]; // option_5\r
112                 $new_row[32] = $row[31]; // option_6\r
113                 $new_row[33] = $row[32]; // option_7\r
114                 $new_row[34] = $row[33]; // option_8\r
115                 $new_row[35] = $row[34]; // option_9\r
116                 $new_row[36] = $row[35]; // properties\r
117                 $new_row[37] = $row[36]; // content_id\r
118         }\r
119 \r
120         return $new_row;\r
121 }\r
122 \r
123 function tests_questions_assoc_convert($row, $course_id, $table_id_map, $version) {\r
124         $new_row = array();\r
125         $new_row[0] = $table_id_map['tests'][$row[0]];\r
126         $new_row[1] = $table_id_map['tests_questions'][$row[1]];\r
127         $new_row[2] = $row[2];\r
128         $new_row[3] = $row[3];\r
129         $new_row[4] = $row[4];\r
130 \r
131         return $new_row;\r
132 }\r
133 \r
134 \r
135 function content_tests_assoc_convert($row, $course_id, $table_id_map, $version) {\r
136         $new_row[0] = $table_id_map['content'][$row[0]];\r
137         $new_row[1] = $table_id_map['tests'][$row[1]];\r
138         return $new_row;\r
139 }\r
140 \r
141 function content_prerequisites_convert($row, $course_id, $table_id_map, $version) {\r
142         $new_row[0] = $table_id_map['content'][$row[0]];\r
143         $new_row[1] = $row[1];\r
144         $new_row[2] = $table_id_map['tests'][$row[2]];\r
145         return $new_row;\r
146 }\r
147 ?>