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
namespace qbank_viewquestiontext\output;
18
 
19
use core_question\local\bank\view;
20
use qbank_viewquestiontext\question_text_row;
21
use renderer_base;
22
 
23
/**
24
 * Question text format selector.
25
 *
26
 * @package   qbank_viewquestiontext
27
 * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
28
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
29
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class question_text_format implements \renderable, \templatable {
32
    /**
33
     * @var int Question text is off.
34
     */
35
    const OFF = 0;
36
 
37
    /**
38
     * @var int Question text is displayed in plain text mode.
39
     */
40
    const PLAIN = 1;
41
 
42
    /**
43
     * @var int Question text is displayed fully rendered.
44
     */
45
    const FULL = 2;
46
 
47
    /** @var int|mixed The current display preference value. */
48
    protected int $preference;
49
 
50
    /**
51
     * @var \moodle_url The return URL for redirecting back to the current question bank page.
52
     */
53
    protected \moodle_url $returnurl;
54
 
55
    /**
56
     * Store the returnurl and the current preference value.
57
     *
58
     * @param view $qbank
59
     * @throws \moodle_exception
60
     */
61
    public function __construct(view $qbank) {
62
        $row = new question_text_row($qbank);
63
        $this->returnurl = new \moodle_url($qbank->returnurl);
64
        $this->preference = question_get_display_preference($row->get_preference_key(), 0, PARAM_INT, new \moodle_url(''));
65
    }
66
 
67
    public function export_for_template(renderer_base $output): array {
68
        return [
69
            'formaction' => new \moodle_url('/question/bank/viewquestiontext/save.php'),
70
            'sesskey' => sesskey(),
71
            'returnurl' => $this->returnurl->out(false),
72
            'options' => [
73
                (object)[
74
                    'label' => get_string('showquestiontext_off', 'question'),
75
                    'value' => self::OFF,
76
                    'selected' => $this->preference === self::OFF,
77
                ],
78
                (object)[
79
                    'label' => get_string('showquestiontext_plain', 'question'),
80
                    'value' => self::PLAIN,
81
                    'selected' => $this->preference === self::PLAIN,
82
                ],
83
                (object)[
84
                    'label' => get_string('showquestiontext_full', 'question'),
85
                    'value' => self::FULL,
86
                    'selected' => $this->preference === self::FULL,
87
                ],
88
            ],
89
            'label' => get_string('showquestiontext', 'core_question'),
90
        ];
91
    }
92
}