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 qtype 19 * @subpackage calculated 20 * @copyright 2011 David Mudrak <david@moodle.com> 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 defined('MOODLE_INTERNAL') || die(); 25 26 /** 27 * Calculated question type conversion handler 28 */ 29 class moodle1_qtype_calculated_handler extends moodle1_qtype_handler { 30 31 /** 32 * @return array 33 */ 34 public function get_question_subpaths() { 35 return array( 36 'ANSWERS/ANSWER', 37 'CALCULATED', 38 'CALCULATED/NUMERICAL_UNITS/NUMERICAL_UNIT', 39 'CALCULATED/DATASET_DEFINITIONS/DATASET_DEFINITION', 40 'CALCULATED/DATASET_DEFINITIONS/DATASET_DEFINITION/DATASET_ITEMS/DATASET_ITEM' 41 ); 42 } 43 44 /** 45 * Appends the calculated specific information to the question 46 */ 47 public function process_question(array $data, array $raw) { 48 49 // Convert and write the answers first. 50 if (isset($data['answers'])) { 51 $this->write_answers($data['answers'], $this->pluginname); 52 } 53 54 // Convert and write the numerical units and numerical options. 55 if (isset($data['calculated'][0]['numerical_units'])) { 56 $numericalunits = $data['calculated'][0]['numerical_units']; 57 } else { 58 $numericalunits = array(); 59 } 60 $numericaloptions = $this->get_default_numerical_options( 61 $data['oldquestiontextformat'], $numericalunits); 62 63 $this->write_numerical_units($numericalunits); 64 $this->write_numerical_options($numericaloptions); 65 66 // Write dataset_definitions. 67 if (isset($data['calculated'][0]['dataset_definitions']['dataset_definition'])) { 68 $datasetdefinitions = $data['calculated'][0]['dataset_definitions']['dataset_definition']; 69 } else { 70 $datasetdefinitions = array(); 71 } 72 $this->write_dataset_definitions($datasetdefinitions); 73 74 // Write calculated_records. 75 $this->xmlwriter->begin_tag('calculated_records'); 76 foreach ($data['calculated'] as $calculatedrecord) { 77 $record = array( 78 'id' => $this->converter->get_nextid(), 79 'answer' => $calculatedrecord['answer'], 80 'tolerance' => $calculatedrecord['tolerance'], 81 'tolerancetype' => $calculatedrecord['tolerancetype'], 82 'correctanswerlength' => $calculatedrecord['correctanswerlength'], 83 'correctanswerformat' => $calculatedrecord['correctanswerformat'] 84 ); 85 $this->write_xml('calculated_record', $record, array('/calculated_record/id')); 86 } 87 $this->xmlwriter->end_tag('calculated_records'); 88 89 // Write calculated_options. 90 $options = array( 91 'calculate_option' => array( 92 'id' => $this->converter->get_nextid(), 93 'synchronize' => 0, 94 'single' => 0, 95 'shuffleanswers' => 0, 96 'correctfeedback' => null, 97 'correctfeedbackformat' => FORMAT_HTML, 98 'partiallycorrectfeedback' => null, 99 'partiallycorrectfeedbackformat' => FORMAT_HTML, 100 'incorrectfeedback' => null, 101 'incorrectfeedbackformat' => FORMAT_HTML, 102 'answernumbering' => 'abc' 103 ) 104 ); 105 $this->write_xml('calculated_options', $options, array('/calculated_options/calculate_option/id')); 106 } 107 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body