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