[ 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 * @package block_quiz_results 19 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 */ 22 23 defined('MOODLE_INTERNAL') || die(); 24 25 /** 26 * Specialised restore task for the quiz_results block 27 * (using execute_after_tasks for recoding of target quiz) 28 * 29 * TODO: Finish phpdocs 30 * 31 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class restore_quiz_results_block_task extends restore_block_task { 35 36 protected function define_my_settings() { 37 } 38 39 protected function define_my_steps() { 40 } 41 42 public function get_fileareas() { 43 return array(); // No associated fileareas 44 } 45 46 public function get_configdata_encoded_attributes() { 47 return array(); // No special handling of configdata 48 } 49 50 /** 51 * This function, executed after all the tasks in the plan 52 * have been executed, will perform the recode of the 53 * target quiz for the block. This must be done here 54 * and not in normal execution steps because the quiz 55 * can be restored after the block. 56 */ 57 public function after_restore() { 58 global $DB; 59 60 // Get the blockid. 61 $blockid = $this->get_blockid(); 62 63 // Extract block configdata and update it to point to the new quiz. 64 $configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid)); 65 $newconfigdata = ''; 66 67 // The block was configured. 68 if (!empty($configdata)) { 69 70 $config = unserialize(base64_decode($configdata)); 71 $config->activityparent = 'quiz'; 72 $config->activityparentid = 0; 73 $config->gradeformat = isset($config->gradeformat) ? $config->gradeformat : 1; 74 75 if (!empty($config->quizid) 76 && $quizmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'quiz', $config->quizid)) { 77 $config->activityparentid = $quizmap->newitemid; 78 } 79 80 // Set the decimal valuue as appropriate. 81 if ($config->gradeformat == 1) { 82 // This block is using percentages, do not display any decimal places. 83 $config->decimalpoints = 0; 84 } else { 85 // Get the decimal value from the corresponding quiz. 86 $config->decimalpoints = $DB->get_field('quiz', 'decimalpoints', array('id' => $config->activityparentid)); 87 } 88 89 // Get the grade_items record to set the activitygradeitemid. 90 $info = $DB->get_record('grade_items', 91 array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent)); 92 $config->activitygradeitemid = 0; 93 if ($info) { 94 $config->activitygradeitemid = $info->id; 95 } 96 97 unset($config->quizid); 98 $newconfigdata = base64_encode(serialize($config)); 99 } 100 101 // Update the configuration and convert the block. 102 $DB->set_field('block_instances', 'configdata', $newconfigdata, array('id' => $blockid)); 103 $DB->set_field('block_instances', 'blockname', 'activity_results', array('id' => $blockid)); 104 } 105 106 static public function define_decode_contents() { 107 return array(); 108 } 109 110 static public function define_decode_rules() { 111 return array(); 112 } 113 }
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 |