|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00033 function xmldb_quiz_statistics_upgrade($oldversion) { 00034 00035 global $DB; 00036 00037 $dbman = $DB->get_manager(); 00038 00039 // In Moodle 2.0, this table was incorrectly called quiz_report, which breaks 00040 // the moodle coding guidelines. In 2.1 it was renamed to quiz_reports. This 00041 // bit of code lets us handle all the various upgrade paths without problems. 00042 if ($dbman->table_exists('quiz_reports')) { 00043 $quizreportstablename = 'quiz_reports'; 00044 } else { 00045 $quizreportstablename = 'quiz_report'; 00046 } 00047 00048 //===== 1.9.0 upgrade line ======// 00049 00050 if ($oldversion < 2008072401) { 00051 //register cron to run every 5 hours. 00052 $DB->set_field($quizreportstablename, 'cron', HOURSECS*5, array('name'=>'statistics')); 00053 00054 // statistics savepoint reached 00055 upgrade_plugin_savepoint(true, 2008072401, 'quiz', 'statistics'); 00056 } 00057 00058 if ($oldversion < 2008072500) { 00059 00060 // Define field s to be added to quiz_question_statistics 00061 $table = new xmldb_table('quiz_question_statistics'); 00062 $field = new xmldb_field('s', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00063 XMLDB_NOTNULL, null, '0', 'subquestion'); 00064 00065 // Conditionally launch add field s 00066 if (!$dbman->field_exists($table, $field)) { 00067 $dbman->add_field($table, $field); 00068 } 00069 00070 // statistics savepoint reached 00071 upgrade_plugin_savepoint(true, 2008072500, 'quiz', 'statistics'); 00072 } 00073 00074 if ($oldversion < 2008072800) { 00075 00076 // Define field maxgrade to be added to quiz_question_statistics 00077 $table = new xmldb_table('quiz_question_statistics'); 00078 $field = new xmldb_field('maxgrade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00079 null, null, null, 'subquestions'); 00080 00081 // Conditionally launch add field maxgrade 00082 if (!$dbman->field_exists($table, $field)) { 00083 $dbman->add_field($table, $field); 00084 } 00085 00086 // statistics savepoint reached 00087 upgrade_plugin_savepoint(true, 2008072800, 'quiz', 'statistics'); 00088 } 00089 00090 if ($oldversion < 2008072801) { 00091 00092 // Define field positions to be added to quiz_question_statistics 00093 $table = new xmldb_table('quiz_question_statistics'); 00094 $field = new xmldb_field('positions', XMLDB_TYPE_TEXT, 'medium', null, 00095 null, null, null, 'maxgrade'); 00096 00097 // Conditionally launch add field positions 00098 if (!$dbman->field_exists($table, $field)) { 00099 $dbman->add_field($table, $field); 00100 } 00101 00102 // statistics savepoint reached 00103 upgrade_plugin_savepoint(true, 2008072801, 'quiz', 'statistics'); 00104 } 00105 00106 if ($oldversion < 2008081500) { 00107 // Changing type of field maxgrade on table quiz_question_statistics to number 00108 $table = new xmldb_table('quiz_question_statistics'); 00109 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '12, 7', null, 00110 null, null, null, 'subquestions'); 00111 00112 // Launch change of type for field maxgrade 00113 $dbman->change_field_type($table, $field); 00114 00115 // statistics savepoint reached 00116 upgrade_plugin_savepoint(true, 2008081500, 'quiz', 'statistics'); 00117 } 00118 00119 if ($oldversion < 2008082600) { 00120 00121 // Define table quiz_question_response_stats to be created 00122 $table = new xmldb_table('quiz_question_response_stats'); 00123 00124 // Adding fields to table quiz_question_response_stats 00125 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00126 XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 00127 $table->add_field('quizstatisticsid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00128 XMLDB_NOTNULL, null, null); 00129 $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00130 XMLDB_NOTNULL, null, null); 00131 $table->add_field('anssubqid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00132 null, null, null); 00133 $table->add_field('response', XMLDB_TYPE_TEXT, 'big', null, 00134 null, null, null); 00135 $table->add_field('rcount', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00136 null, null, null); 00137 $table->add_field('credit', XMLDB_TYPE_NUMBER, '15, 5', null, 00138 XMLDB_NOTNULL, null, null); 00139 00140 // Adding keys to table quiz_question_response_stats 00141 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 00142 00143 // Conditionally launch create table for quiz_question_response_stats 00144 if (!$dbman->table_exists($table)) { 00145 $dbman->create_table($table); 00146 } 00147 00148 // statistics savepoint reached 00149 upgrade_plugin_savepoint(true, 2008082600, 'quiz', 'statistics'); 00150 } 00151 00152 if ($oldversion < 2008090500) { 00153 //delete all cached results first 00154 $DB->delete_records('quiz_statistics'); 00155 $DB->delete_records('quiz_question_statistics'); 00156 $DB->delete_records('quiz_question_response_stats'); 00157 // Define field anssubqid to be dropped from quiz_question_response_stats 00158 $table = new xmldb_table('quiz_question_response_stats'); 00159 $field = new xmldb_field('anssubqid'); 00160 00161 // Conditionally launch drop field subqid 00162 if ($dbman->field_exists($table, $field)) { 00163 $dbman->drop_field($table, $field); 00164 } 00165 00166 // Define field subqid to be added to quiz_question_response_stats 00167 $field = new xmldb_field('subqid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00168 XMLDB_NOTNULL, null, null, 'questionid'); 00169 00170 // Conditionally launch add field subqid 00171 if (!$dbman->field_exists($table, $field)) { 00172 $dbman->add_field($table, $field); 00173 } 00174 00175 // Define field aid to be added to quiz_question_response_stats 00176 $field = new xmldb_field('aid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00177 XMLDB_NOTNULL, null, null, 'subqid'); 00178 00179 // Conditionally launch add field aid 00180 if (!$dbman->field_exists($table, $field)) { 00181 $dbman->add_field($table, $field); 00182 } 00183 00184 // statistics savepoint reached 00185 upgrade_plugin_savepoint(true, 2008090500, 'quiz', 'statistics'); 00186 } 00187 00188 if ($oldversion < 2008111000) { 00189 // Delete all cached results first 00190 $DB->delete_records('quiz_statistics'); 00191 $DB->delete_records('quiz_question_statistics'); 00192 $DB->delete_records('quiz_question_response_stats'); 00193 00194 // Define field anssubqid to be dropped from quiz_question_response_stats 00195 $table = new xmldb_table('quiz_question_statistics'); 00196 // Define field subqid to be added to quiz_question_response_stats 00197 $field = new xmldb_field('negcovar', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, 00198 XMLDB_NOTNULL, null, '0', 'effectiveweight'); 00199 00200 // Conditionally launch add field subqid 00201 if (!$dbman->field_exists($table, $field)) { 00202 $dbman->add_field($table, $field); 00203 } 00204 00205 // statistics savepoint reached 00206 upgrade_plugin_savepoint(true, 2008111000, 'quiz', 'statistics'); 00207 } 00208 00209 if ($oldversion < 2008112100) { 00210 $DB->set_field($quizreportstablename, 'capability', 'quizreport/statistics:view', 00211 array('name'=>'statistics')); 00212 00213 // statistics savepoint reached 00214 upgrade_plugin_savepoint(true, 2008112100, 'quiz', 'statistics'); 00215 } 00216 00217 if ($oldversion < 2008112101) { 00218 // Removed UNSIGNED from all NUMBER columns in the quiz_statistics table. 00219 $table = new xmldb_table('quiz_statistics'); 00220 00221 // Change of sign for field firstattemptsavg 00222 $field = new xmldb_field('firstattemptsavg', XMLDB_TYPE_NUMBER, '15, 5', null, 00223 null, null, null, 'allattemptscount'); 00224 $dbman->change_field_unsigned($table, $field); 00225 00226 // Change of sign for field allattemptsavg 00227 $field = new xmldb_field('allattemptsavg', XMLDB_TYPE_NUMBER, '15, 5', null, 00228 null, null, null, 'firstattemptsavg'); 00229 $dbman->change_field_unsigned($table, $field); 00230 00231 // Change of sign for field median 00232 $field = new xmldb_field('median', XMLDB_TYPE_NUMBER, '15, 5', null, 00233 null, null, null, 'allattemptsavg'); 00234 $dbman->change_field_unsigned($table, $field); 00235 00236 // Change of sign for field standarddeviation 00237 $field = new xmldb_field('standarddeviation', XMLDB_TYPE_NUMBER, '15, 5', null, 00238 null, null, null, 'median'); 00239 $dbman->change_field_unsigned($table, $field); 00240 00241 // Change of sign for field errorratio 00242 $field = new xmldb_field('errorratio', XMLDB_TYPE_NUMBER, '15, 10', null, 00243 null, null, null, 'cic'); 00244 $dbman->change_field_unsigned($table, $field); 00245 00246 // Change of sign for field standarderror 00247 $field = new xmldb_field('standarderror', XMLDB_TYPE_NUMBER, '15, 10', null, 00248 null, null, null, 'errorratio'); 00249 $dbman->change_field_unsigned($table, $field); 00250 00251 // statistics savepoint reached 00252 upgrade_plugin_savepoint(true, 2008112101, 'quiz', 'statistics'); 00253 } 00254 00255 if ($oldversion < 2008112102) { 00256 // Removed UNSIGNED from all NUMBER columns in the quiz_question_statistics table. 00257 $table = new xmldb_table('quiz_question_statistics'); 00258 00259 // Change of sign for field effectiveweight 00260 $field = new xmldb_field('effectiveweight', XMLDB_TYPE_NUMBER, '15, 5', null, 00261 null, null, null, 's'); 00262 $dbman->change_field_unsigned($table, $field); 00263 00264 // Change of sign for field sd 00265 $field = new xmldb_field('sd', XMLDB_TYPE_NUMBER, '15, 10', null, 00266 null, null, null, 'discriminativeefficiency'); 00267 $dbman->change_field_unsigned($table, $field); 00268 00269 // Change of sign for field facility 00270 $field = new xmldb_field('facility', XMLDB_TYPE_NUMBER, '15, 10', null, 00271 null, null, null, 'sd'); 00272 $dbman->change_field_unsigned($table, $field); 00273 00274 // Change of sign for field maxgrade 00275 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '12, 7', null, 00276 null, null, null, 'subquestions'); 00277 $dbman->change_field_unsigned($table, $field); 00278 00279 // statistics savepoint reached 00280 upgrade_plugin_savepoint(true, 2008112102, 'quiz', 'statistics'); 00281 } 00282 00283 if ($oldversion < 2008112103) { 00284 // Removed UNSIGNED from all NUMBER columns in the quiz_question_response_stats table. 00285 $table = new xmldb_table('quiz_question_response_stats'); 00286 00287 // Change of sign for field credit 00288 $field = new xmldb_field('credit', XMLDB_TYPE_NUMBER, '15, 5', null, 00289 XMLDB_NOTNULL, null, null, 'rcount'); 00290 $dbman->change_field_unsigned($table, $field); 00291 00292 // statistics savepoint reached 00293 upgrade_plugin_savepoint(true, 2008112103, 'quiz', 'statistics'); 00294 } 00295 00296 if ($oldversion < 2010031700) { 00297 00298 // Define field randomguessscore to be added to quiz_question_statistics 00299 $table = new xmldb_table('quiz_question_statistics'); 00300 $field = new xmldb_field('randomguessscore', XMLDB_TYPE_NUMBER, '12, 7', null, 00301 null, null, null, 'positions'); 00302 00303 // Conditionally launch add field randomguessscore 00304 if (!$dbman->field_exists($table, $field)) { 00305 $dbman->add_field($table, $field); 00306 } 00307 00308 // statistics savepoint reached 00309 upgrade_plugin_savepoint(true, 2010031700, 'quiz', 'statistics'); 00310 } 00311 00312 if ($oldversion < 2010032400) { 00313 00314 // Define field slot to be added to quiz_question_statistics 00315 $table = new xmldb_table('quiz_question_statistics'); 00316 $field = new xmldb_field('slot', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, 00317 null, null, 'questionid'); 00318 00319 // Conditionally launch add field slot 00320 if (!$dbman->field_exists($table, $field)) { 00321 $dbman->add_field($table, $field); 00322 } 00323 00324 // statistics savepoint reached 00325 upgrade_plugin_savepoint(true, 2010032400, 'quiz', 'statistics'); 00326 } 00327 00328 if ($oldversion < 2010032401) { 00329 00330 // Delete all cached data 00331 $DB->delete_records('quiz_question_response_stats'); 00332 $DB->delete_records('quiz_question_statistics'); 00333 $DB->delete_records('quiz_statistics'); 00334 00335 // Rename field maxgrade on table quiz_question_statistics to maxmark 00336 $table = new xmldb_table('quiz_question_statistics'); 00337 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, 00338 null, null, null, 'subquestions'); 00339 00340 // Launch rename field maxmark 00341 $dbman->rename_field($table, $field, 'maxmark'); 00342 00343 // statistics savepoint reached 00344 upgrade_plugin_savepoint(true, 2010032401, 'quiz', 'statistics'); 00345 } 00346 00347 if ($oldversion < 2010062200) { 00348 00349 // Changing nullability of field aid on table quiz_question_response_stats to null 00350 $table = new xmldb_table('quiz_question_response_stats'); 00351 $field = new xmldb_field('aid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, 00352 null, null, null, 'subqid'); 00353 00354 // Launch change of nullability for field aid 00355 $dbman->change_field_notnull($table, $field); 00356 00357 // statistics savepoint reached 00358 upgrade_plugin_savepoint(true, 2010062200, 'quiz', 'statistics'); 00359 } 00360 00361 if ($oldversion < 2010070301) { 00362 00363 // Changing type of field maxmark on table quiz_question_statistics to number 00364 $table = new xmldb_table('quiz_question_statistics'); 00365 $field = new xmldb_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, 00366 null, null, null, 'subquestions'); 00367 00368 // Launch change of type for field maxmark 00369 $dbman->change_field_type($table, $field); 00370 00371 // statistics savepoint reached 00372 upgrade_plugin_savepoint(true, 2010070301, 'quiz', 'statistics'); 00373 } 00374 00375 if ($oldversion < 2011021500) { 00376 $DB->set_field($quizreportstablename, 'capability', 'quiz/statistics:view', 00377 array('name' => 'statistics')); 00378 00379 // statistics savepoint reached 00380 upgrade_plugin_savepoint(true, 2011021500, 'quiz', 'statistics'); 00381 } 00382 00383 // Signed fixes - MDL-28032 00384 if ($oldversion < 2011062600) { 00385 00386 // Changing sign of field maxmark on table quiz_question_statistics to signed 00387 $table = new xmldb_table('quiz_question_statistics'); 00388 $field = new xmldb_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null, 00389 null, null, null, 'subquestions'); 00390 00391 // Launch change of sign for field maxmark 00392 $dbman->change_field_unsigned($table, $field); 00393 00394 // statistics savepoint reached 00395 upgrade_plugin_savepoint(true, 2011062600, 'quiz', 'statistics'); 00396 } 00397 00398 // Moodle v2.1.0 release upgrade line 00399 // Put any upgrade step following this 00400 00401 // Moodle v2.2.0 release upgrade line 00402 // Put any upgrade step following this 00403 00404 return true; 00405 } 00406