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_question\local\bank\column_base;
20
use qbank_columnsortorder\local\bank\column_action_remove;
21
use moodle_url;
22
use qbank_columnsortorder\column_manager;
23
use renderable;
24
use templatable;
25
 
26
/**
27
 * Renderable for the column sort admin UI.
28
 *
29
 * Displays a list of the currently enabled columns and allows them to be sorted, hidden, and resized.
30
 *
31
 * @package   qbank_columnsortorder
32
 * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
33
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class column_sort_ui implements renderable, templatable {
37
    /**
38
     * The minimum custom width for a column.
39
     *
40
     * This is based on the minimum possible width of the smallest core column (question type).
41
     * When viewed, the width will be resized to the minimum width of the column header, if too small.
42
     *
43
     * @var int
44
     */
45
    const MIN_COLUMN_WIDTH = 30;
46
 
47
    public function export_for_template(\renderer_base $output): array {
48
        $columnmanager = new column_manager(true);
49
        $enabledcolumns = $columnmanager->get_columns();
50
        $disabledcolumns = $columnmanager->get_disabled_columns();
51
        $columnsizes = $columnmanager->get_colsize_map();
52
        $qbank = $columnmanager->get_questionbank();
53
        $returnurl = new moodle_url('/question/bank/columnsortorder/sortcolumns.php');
54
        $params = [];
55
        $params['formaction'] = new moodle_url('/question/bank/columnsortorder/actions.php');
56
        $params['sesskey'] = sesskey();
57
        $params['disabled'] = $disabledcolumns;
58
        $params['contextid'] = \context_system::instance()->id;
59
        $params['minwidth'] = self::MIN_COLUMN_WIDTH;
60
        foreach ($enabledcolumns as $column) {
61
            if (in_array($column->id, $columnmanager->hiddencolumns) || array_key_exists($column->id, $disabledcolumns)) {
62
                continue;
63
            }
64
            $name = $column->name;
65
            $colname = get_string('qbankcolumnname', 'qbank_columnsortorder', $column->colname);
66
 
67
            $removeaction = new column_action_remove($qbank);
68
            $removeaction->set_global(true);
69
            $actionmenu = new \action_menu([
70
                $removeaction->get_action_menu_link($column->class::from_column_name($qbank, $column->colname)),
71
            ]);
72
            $params['names'][] = [
73
                'name' => $name,
74
                'colname' => $colname,
75
                'class' => $column->class,
76
                'width' => $columnsizes[$column->id] ?? null,
77
                'widthlabel' => get_string('width', 'qbank_columnsortorder', $name),
78
                'actionmenu' => $actionmenu->export_for_template($output),
79
                'columnid' => $column->id,
80
                'escapedid' => str_replace('\\', '__', $column->id),
81
            ];
82
        }
83
 
84
        $params['disabled'] = array_values($disabledcolumns);
85
        $params['columnsdisabled'] = !empty($params['disabled']);
86
        $addcolumn = new add_column($columnmanager, $returnurl);
87
        $params['addcolumn'] = $addcolumn->export_for_template($output);
88
        $resetcolums = new reset_columns($returnurl);
89
        $params['resetcolumns'] = $resetcolums->export_for_template($output);
90
        $params['extraclasses'] = 'pr-1';
91
        $urltoredirect = new moodle_url('/admin/settings.php', ['section' => 'manageqbanks']);
92
 
93
        $params['urltomanageqbanks'] = get_string('qbankgotomanageqbanks', 'qbank_columnsortorder', $urltoredirect->out());
94
        $params['previewurl'] = new moodle_url('/question/bank/columnsortorder/sortcolumns.php', [
95
            'preview' => true,
96
        ]);
97
        return $params;
98
    }
99
}