Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
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 * Contains class mod_h5pactivity\output\result\sequencing 19 * 20 * @package mod_h5pactivity 21 * @copyright 2020 Ferran Recio 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace mod_h5pactivity\output\result; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 use mod_h5pactivity\output\result; 30 use renderer_base; 31 32 /** 33 * Class to display H5P sequencing result. 34 * 35 * @copyright 2020 Ferran Recio 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class sequencing extends result { 39 40 /** 41 * Return the options data structure. 42 * 43 * @return array of options 44 */ 45 protected function export_options(): ?array { 46 47 $correctpattern = reset($this->correctpattern); 48 49 $additionals = $this->additionals; 50 51 $response = $this->response; 52 53 if (isset($additionals->choices)) { 54 $choices = $this->get_descriptions($additionals->choices); 55 } else { 56 $choices = []; 57 } 58 59 $options = []; 60 $num = 1; 61 foreach ($correctpattern as $key => $pattern) { 62 if (!isset($choices[$pattern])) { 63 continue; 64 } 65 $option = (object)[ 66 'id' => 'true', 67 'description' => get_string('result_sequencing_position', 'mod_h5pactivity', $num), 68 'correctanswer' => $this->get_answer(parent::TEXT, $choices[$pattern]->description), 69 'correctanswerid' => 'item_'.$key, 70 ]; 71 if (isset($response[$key])) { 72 $answerstate = ($response[$key] == $option->correctanswerid) ? parent::PASS : parent::FAIL; 73 } else { 74 $answerstate = parent::FAIL; 75 } 76 $option->useranswer = $this->get_answer($answerstate); 77 78 $options[$key] = $option; 79 $num ++; 80 } 81 return $options; 82 } 83 84 /** 85 * Return a label for result user options/choices. 86 * 87 * @return string to use in options table 88 */ 89 protected function get_optionslabel(): string { 90 return get_string('result_sequencing_choice', 'mod_h5pactivity'); 91 } 92 93 /** 94 * Return a label for result user correct answer. 95 * 96 * @return string to use in options table 97 */ 98 protected function get_correctlabel(): string { 99 return get_string('result_sequencing_answer', 'mod_h5pactivity'); 100 } 101 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body