Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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' => $key,
70
            ];
71
            if (isset($response[$key])) {
72
                $responseid = str_replace('item_', '', $response[$key]);
73
                $answerstate = ($responseid == $option->correctanswerid) ? parent::PASS : parent::FAIL;
74
            } else {
75
                $answerstate = parent::FAIL;
76
            }
77
            $option->useranswer = $this->get_answer($answerstate);
78
 
79
            $options[$key] = $option;
80
            $num ++;
81
        }
82
        return $options;
83
    }
84
 
85
    /**
86
     * Return a label for result user options/choices.
87
     *
88
     * @return string to use in options table
89
     */
90
    protected function get_optionslabel(): string {
91
        return get_string('result_sequencing_choice', 'mod_h5pactivity');
92
    }
93
 
94
    /**
95
     * Return a label for result user correct answer.
96
     *
97
     * @return string to use in options table
98
     */
99
    protected function get_correctlabel(): string {
100
        return get_string('result_sequencing_answer', 'mod_h5pactivity');
101
    }
102
}