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 mod_quiz\external;
18
 
19
use core_external\external_api;
20
use core_external\external_function_parameters;
21
use core_external\external_multiple_structure;
22
use core_external\external_single_structure;
23
use core_external\external_value;
24
use mod_quiz\quiz_settings;
25
 
26
/**
27
 * Webservice for deleting quiz overrides.
28
 *
29
 * @package   mod_quiz
30
 * @copyright 2024 Matthew Hilton <matthewhilton@catalyst-au.net>
31
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class delete_overrides extends external_api {
34
    /**
35
     * Defines parameters
36
     *
37
     * @return external_function_parameters
38
     */
39
    public static function execute_parameters(): external_function_parameters {
40
        return new external_function_parameters([
41
            // This must be nested in a single structure, because the ids structure does not play nicely at the top level.
42
            'data' => new external_single_structure([
43
                'quizid' => new external_value(PARAM_INT, "ID of quiz to delete overrides in"),
44
                'ids' => new external_multiple_structure(new external_value(PARAM_INT, 'ID of override to delete')),
45
            ]),
46
        ]);
47
    }
48
 
49
    /**
50
     * Executes webservice function, deleting given overrides.
51
     *
52
     * @param array $params array of override parameters
53
     * @return array with ids key, which contains the ids of the overrides successfully deleted.
54
     */
55
    public static function execute($params): array {
56
        $params = self::validate_parameters(self::execute_parameters(), ['data' => $params])['data'];
57
 
58
        $quizsettings = quiz_settings::create($params['quizid']);
59
        $manager = $quizsettings->get_override_manager();
60
        self::validate_context($manager->context);
61
        $manager->require_manage_capability();
62
        $manager->delete_overrides_by_id($params['ids']);
63
 
64
        return ['ids' => $params['ids']];
65
    }
66
 
67
    /**
68
     * Defines return type
69
     *
70
     * @return external_single_structure
71
     */
72
    public static function execute_returns(): external_single_structure {
73
        return new external_single_structure([
74
            'ids' => new external_multiple_structure(new external_value(PARAM_INT, 'ID of deleted override')),
75
        ]);
76
    }
77
}