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_section 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
25namespace core\output;
26defined('MOODLE_INTERNAL') || die();
27
28use lang_string;
29use renderer_base;
30use renderable;
31use stdClass;
32use templatable;
33
34/**
35 * The chooser_section renderable class.
36 *
37 * @package    core
38 * @copyright  2016 Frédéric Massart - FMCorz.net
39 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 */
41class chooser_section implements renderable, templatable {
42
43    /** @var string $id An identifier for the section. */
44    public $id;
45    /** @var lang_string $label The label of the section. */
46    public $label;
47    /** @var chooser_item[] $items The items in this section. */
48    public $items;
49
50    /**
51     * Constructor.
52     *
53     * @param string $id An identifier for the section.
54     * @param lang_string $label The label of the section.
55     * @param chooser_item[] $items The items in this section.
56     */
57    public function __construct($id, lang_string $label, array $items) {
58        $this->id = $id;
59        $this->label = $label;
60        $this->items = $items;
61    }
62
63    /**
64     * Export for template.
65     *
66     * @param renderer_base The renderer.
67     * @return stdClass
68     */
69    public function export_for_template(renderer_base $output) {
70        $data = new stdClass();
71        $data->id = $this->id;
72        $data->label = (string) $this->label;
73        $data->items = array_map(function($item) use ($output) {
74            return $item->export_for_template($output);
75        }, array_values($this->items));
76        return $data;
77    }
78
79}
80