Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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_managecategories\output;
18
 
19
use context;
20
use renderable;
21
use renderer_base;
22
use templatable;
23
use qbank_managecategories\question_categories;
24
 
25
/**
26
 * Output component for category page header.
27
 *
28
 * @package   qbank_managecategories
29
 * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
30
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
31
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class categories_header implements renderable, templatable {
34
    /**
35
     * Constructor.
36
     *
37
     * @param question_categories $categories Question categories for display.
38
     */
39
    public function __construct(
40
        /** @var question_categories $categories Question categories for display. */
41
        protected question_categories $categories,
42
    ) {
43
    }
44
 
45
    /**
46
     * Output template data for the heading of the category management page.
47
     *
48
     * @param renderer_base $output
49
     * @return array
50
     * @throws \coding_exception
51
     */
52
    public function export_for_template(renderer_base $output): array {
53
        $helpstringhead = $output->heading_with_help(
54
            get_string('editcategories', 'question'),
55
            'editcategories',
56
            'question',
57
        );
58
        $hascapability = has_capability(
59
            'moodle/question:managecategory',
60
            context::instance_by_id($this->categories->contextid),
61
        );
62
 
63
        $data = [
64
            'helpstringhead' => $helpstringhead,
65
            'showdescriptions' => [
66
                'id' => 'showdescriptions-toggle',
67
                'checked' => get_user_preferences('qbank_managecategories_showdescriptions'),
68
                'label' => get_string('showcategorydescription', 'qbank_managecategories'),
69
            ],
70
            'hascapability' => $hascapability,
71
            'contextid' => $this->categories->contextid,
72
            'cmid' => $this->categories->cmid,
73
            'courseid' => $this->categories->courseid,
74
        ];
75
        return $data;
76
    }
77
}