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\external;
18
 
19
use context_system;
20
use core_external\external_api;
21
use core_external\external_function_parameters;
22
use core_external\external_value;
23
use qbank_columnsortorder\column_manager;
24
 
25
/**
26
 * External function for saving column sizes.
27
 *
28
 * @package   qbank_columnsortorder
29
 * @copyright 2023 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 set_column_size extends external_api {
34
    /**
35
     * Returns description of method parameters.
36
     *
37
     * @return external_function_parameters
38
     */
39
    public static function execute_parameters(): external_function_parameters {
40
        return new external_function_parameters([
41
            'sizes' => new external_value(
42
                PARAM_TEXT,
43
                'Size for each column, as a JSON string representing [column => size]',
44
                VALUE_DEFAULT,
45
                null,
46
            ),
47
            'global' => new external_value(
48
                PARAM_BOOL,
49
                'Set global config setting, rather than user preference',
50
                VALUE_DEFAULT,
51
                false
52
            ),
53
        ]);
54
    }
55
 
56
    /**
57
     * Returns description of method result value.
58
     */
59
    public static function execute_returns(): void {
60
    }
61
 
62
    /**
63
     * Set sizes for columns
64
     * Save against user preference if component is specified
65
     *
66
     * @param ?string $sizes json string representing [column => size]. Null value clears the setting.
67
     * @param bool $global Set global config setting, rather than user preference
68
     */
69
    public static function execute(?string $sizes, bool $global = false): void {
70
        [
71
            'sizes' => $sizes,
72
            'global' => $global,
73
        ] = self::validate_parameters(
74
            self::execute_parameters(),
75
            [
76
                'sizes' => $sizes,
77
                'global' => $global,
78
            ]
79
        );
80
 
81
        $context = context_system::instance();
82
        self::validate_context($context);
83
        if ($global) {
84
            require_capability('moodle/site:config', $context);
85
        }
86
 
87
        column_manager::set_column_size($sizes, $global);
88
    }
89
}