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_columnsortorder\output;
18
 
19
use core_reportbuilder\local\models\column;
20
use qbank_columnsortorder\column_manager;
21
use moodle_url;
22
use renderer_base;
23
 
24
/**
25
 * Renderable for the "add column" dropdown list
26
 *
27
 * @package   qbank_columnsortorder
28
 * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
29
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class add_column implements \renderable, \templatable {
33
    /** @var column_manager The column manager for getting the list of hidden columns. */
34
    protected column_manager $columnmanager;
35
 
36
    /** @var moodle_url The current page URL to redirect back to. */
37
    protected moodle_url $returnurl;
38
 
39
    /** @var bool True if we are changing global config, false for user preferences. */
40
    protected bool $global;
41
 
42
    /**
43
     * Store arguments for generating template context.
44
     *
45
     * @param column_manager $columnmanager
46
     * @param moodle_url $returnurl
47
     * @param bool $global
48
     */
49
    public function __construct(column_manager $columnmanager, moodle_url $returnurl, bool $global = false) {
50
        $this->columnmanager = $columnmanager;
51
        $this->returnurl = $returnurl;
52
        $this->global = $global;
53
    }
54
 
55
    public function export_for_template(renderer_base $output): array {
56
        $hiddencolumns = [];
57
        foreach ($this->columnmanager->get_hidden_columns() as $class => $name) {
58
            $addurl = new moodle_url('/question/bank/columnsortorder/actions.php', [
59
                'action' => 'add',
60
                'global' => $this->global,
61
                'column' => $class,
62
                'sesskey' => sesskey(),
63
                'returnurl' => $this->returnurl,
64
            ]);
65
            $hiddencolumns[] = [
66
                'name' => $name,
67
                'addurl' => $addurl->out(false),
68
                'column' => $class,
69
                'addtext' => get_string('addcolumn', 'qbank_columnsortorder', $name),
70
            ];
71
        }
72
        return [
73
            'hashiddencolumns' => !empty($hiddencolumns),
74
            'hiddencolumns' => $hiddencolumns,
75
        ];
76
    }
77
}