[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file keeps track of upgrades to the quiz_results block 19 * 20 * Sometimes, changes between versions involve alterations to database structures 21 * and other major things that may break installations. 22 * 23 * The upgrade function in this file will attempt to perform all the necessary 24 * actions to upgrade your older installation to the current version. 25 * 26 * If there's something it cannot do itself, it will tell you what you need to do. 27 * 28 * The commands in here will all be database-neutral, using the methods of 29 * database_manager class 30 * 31 * Please do not forget to use upgrade_set_timeout() 32 * before any action that may take longer time to finish. 33 * 34 * @since Moodle 2.9 35 * @package block_quiz_results 36 * @copyright 2015 Stephen Bourget 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 40 /** 41 * Upgrade the quiz_results block 42 * @param int $oldversion 43 * @param object $block 44 */ 45 function xmldb_block_quiz_results_upgrade($oldversion, $block) { 46 global $DB, $CFG; 47 48 if ($oldversion < 2015022200) { 49 // Only migrate if the block_activity_results is installed. 50 if (is_dir($CFG->dirroot . '/blocks/activity_results')) { 51 52 // Migrate all instances of block_quiz_results to block_activity_results. 53 $records = $DB->get_records('block_instances', array('blockname' => 'quiz_results')); 54 foreach ($records as $record) { 55 $configdata = ''; 56 57 // The block was configured. 58 if (!empty($record->configdata)) { 59 60 $config = unserialize(base64_decode($record->configdata)); 61 $config->activityparent = 'quiz'; 62 $config->activityparentid = isset($config->quizid) ? $config->quizid : 0; 63 $config->gradeformat = isset($config->gradeformat) ? $config->gradeformat : 1; 64 65 // Set the decimal valuue as appropriate. 66 if ($config->gradeformat == 1) { 67 // This block is using percentages, do not display any decimal places. 68 $config->decimalpoints = 0; 69 } else { 70 // Get the decimal value from the corresponding quiz. 71 $config->decimalpoints = $DB->get_field('quiz', 'decimalpoints', array('id' => $config->activityparentid)); 72 } 73 74 // Get the grade_items record to set the activitygradeitemid. 75 $info = $DB->get_record('grade_items', 76 array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent)); 77 $config->activitygradeitemid = 0; 78 if ($info) { 79 $config->activitygradeitemid = $info->id; 80 } 81 82 unset($config->quizid); 83 $configdata = base64_encode(serialize($config)); 84 } 85 86 // Save the new configuration and update the record. 87 $record->configdata = $configdata; 88 $record->blockname = 'activity_results'; 89 $DB->update_record('block_instances', $record); 90 } 91 92 // Disable the Quiz_results block. 93 if ($block = $DB->get_record("block", array("name" => "quiz_results"))) { 94 $DB->set_field("block", "visible", "0", array("id" => $block->id)); 95 } 96 97 } 98 upgrade_block_savepoint(true, 2015022200, 'quiz_results'); 99 } 100 101 // Moodle v2.8.0 release upgrade line. 102 // Put any upgrade step following this. 103 104 // Moodle v2.9.0 release upgrade line. 105 // Put any upgrade step following this. 106 107 // Moodle v3.0.0 release upgrade line. 108 // Put any upgrade step following this. 109 110 // Moodle v3.1.0 release upgrade line. 111 // Put any upgrade step following this. 112 113 return true; 114 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |