Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | 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 searching 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 get_overrides extends external_api {
34
    /**
35
     * Defines parameters for getting quiz overrides.
36
     *
37
     * @return external_function_parameters
38
     */
39
    public static function execute_parameters(): external_function_parameters {
40
        return new external_function_parameters([
41
            'quizid' => new external_value(PARAM_INT, 'ID of quiz to get overrides for'),
42
        ]);
43
    }
44
 
45
    /**
46
     * Executes webservice function, returning quiz overrides.
47
     *
48
     * @param int $quizid
49
     * @return array with overrides key which contains the overrides for the given quiz.
50
     */
51
    public static function execute($quizid): array {
52
        $params = self::validate_parameters(self::execute_parameters(), ['quizid' => $quizid]);
53
        $manager = quiz_settings::create($params['quizid'])->get_override_manager();
54
        self::validate_context($manager->context);
55
        $manager->require_read_capability();
56
        $overrides = $manager->get_all_overrides();
57
        return ['overrides' => $overrides];
58
    }
59
 
60
    /**
61
     * Defines return type
62
     *
63
     * @return external_single_structure
64
     */
65
    public static function execute_returns(): external_single_structure {
66
        $overridedatastructure = new external_single_structure([
67
            'id' => new external_value(PARAM_INT, 'Override ID'),
68
            'quiz' => new external_value(PARAM_INT, 'Quiz ID'),
69
            'userid' => new external_value(PARAM_INT, 'User ID', VALUE_DEFAULT, null),
70
            'groupid' => new external_value(PARAM_INT, 'Group ID', VALUE_DEFAULT, null),
71
            'timeopen' => new external_value(PARAM_INT, 'Override time open value', VALUE_DEFAULT, null),
72
            'timeclose' => new external_value(PARAM_INT, 'Override time close value', VALUE_DEFAULT, null),
73
            'timelimit' => new external_value(PARAM_INT, 'Override time limit value', VALUE_DEFAULT, null),
74
            'attempts' => new external_value(PARAM_INT, 'Override attempts value', VALUE_DEFAULT, null),
75
            'password' => new external_value(PARAM_TEXT, 'Override password', VALUE_DEFAULT, null),
76
        ]);
77
 
78
        return new external_single_structure([
79
            'overrides' => new external_multiple_structure($overridedatastructure),
80
        ]);
81
    }
82
}