Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * The chooser_item renderable.
19
 *
20
 * @package    core
21
 * @copyright  2016 Frédéric Massart - FMCorz.net
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace core\output;
26
 
1441 ariadna 27
use core\exception\coding_exception;
28
use core\context;
1 efrain 29
use stdClass;
30
 
31
/**
32
 * The chooser_item renderable class.
33
 *
34
 * @package    core
35
 * @copyright  2016 Frédéric Massart - FMCorz.net
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class chooser_item implements renderable, templatable {
39
    /** @var string An identifier for the item. */
40
    public $id;
41
    /** @var string The label of this item. */
42
    public $label;
43
    /** @var string The value this item represents. */
44
    public $value;
45
    /** @var pix_icon The icon for this item. */
46
    public $icon;
47
    /** @var string The item description. */
48
    public $description;
49
    /** @var context The relevant context. */
50
    public $context;
51
 
52
    /**
53
     * Constructor.
54
     */
1441 ariadna 55
    public function __construct($id, $label, $value, pix_icon $icon, $description = null, ?context $context = null) {
1 efrain 56
        $this->id = $id;
57
        $this->label = $label;
58
        $this->value = $value;
59
        $this->icon = $icon;
60
        $this->description = $description;
61
 
62
        if (!empty($description) && empty($context)) {
63
            throw new coding_exception('The context must be passed when there is a description.');
64
        }
65
        $this->context = $context;
66
    }
67
 
68
    /**
69
     * Export for template.
70
     *
71
     * @param renderer_base  The renderer.
72
     * @return stdClass
73
     */
74
    public function export_for_template(renderer_base $output) {
75
        $data = new stdClass();
76
        $data->id = $this->id;
77
        $data->label = $this->label;
78
        $data->value = $this->value;
79
        $data->icon = $this->icon->export_for_template($output);
80
 
81
        $options = new stdClass();
82
        $options->trusted = false;
83
        $options->noclean = false;
84
        $options->filter = false;
85
        $options->para = true;
86
        $options->newlines = false;
87
        $options->overflowdiv = false;
88
 
89
        $data->description = '';
90
        if (!empty($this->description)) {
1441 ariadna 91
            [$data->description] = \core_external\util::format_text(
92
                (string) $this->description,
93
                FORMAT_MARKDOWN,
94
                $this->context->id,
95
                null,
96
                null,
97
                null,
98
                $options
99
            );
1 efrain 100
        }
101
 
102
        return $data;
103
    }
104
}