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_description;
|
|
|
21 |
use core_external\external_function_parameters;
|
|
|
22 |
use core_external\external_value;
|
|
|
23 |
use Exception;
|
|
|
24 |
use html_writer;
|
|
|
25 |
use mod_quiz\output\edit_grading_page;
|
|
|
26 |
use mod_quiz\quiz_attempt;
|
|
|
27 |
use mod_quiz\quiz_settings;
|
|
|
28 |
use moodle_exception;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Web service to get the data required o re-render the Quiz grading setup page.
|
|
|
32 |
*
|
|
|
33 |
* The use must have the 'mod/quiz:manage' capability.
|
|
|
34 |
*
|
|
|
35 |
* @package mod_quiz
|
|
|
36 |
* @copyright 2023 The Open University
|
|
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
38 |
*/
|
|
|
39 |
class get_edit_grading_page_data extends external_api {
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Declare the method parameters.
|
|
|
43 |
*
|
|
|
44 |
* @return external_function_parameters
|
|
|
45 |
*/
|
|
|
46 |
public static function execute_parameters(): external_function_parameters {
|
|
|
47 |
return new external_function_parameters([
|
|
|
48 |
'quizid' => new external_value(PARAM_INT, 'The quiz for which to return the data.'),
|
|
|
49 |
]);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Check a quiz attempt state, and return a confirmation message method implementation.
|
|
|
54 |
*
|
|
|
55 |
* @param int $quizid the quiz for which to return the data.
|
|
|
56 |
* @return string a suitable confirmation message (HTML), if the attempt is suitable to be reopened.
|
|
|
57 |
* @throws Exception an appropriate exception if the attempt cannot be reopened now.
|
|
|
58 |
*/
|
|
|
59 |
public static function execute(int $quizid): string {
|
|
|
60 |
global $PAGE;
|
|
|
61 |
|
|
|
62 |
[
|
|
|
63 |
'quizid' => $quizid,
|
|
|
64 |
] = self::validate_parameters(self::execute_parameters(), [
|
|
|
65 |
'quizid' => $quizid,
|
|
|
66 |
]);
|
|
|
67 |
|
|
|
68 |
// Check the request is valid.
|
|
|
69 |
$quizobj = quiz_settings::create($quizid);
|
|
|
70 |
require_capability('mod/quiz:manage', $quizobj->get_context());
|
|
|
71 |
self::validate_context($quizobj->get_context());
|
|
|
72 |
|
|
|
73 |
$structure = $quizobj->get_structure();
|
|
|
74 |
$editpage = new edit_grading_page($structure);
|
|
|
75 |
return json_encode($editpage->export_for_template($PAGE->get_renderer('core')));
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Define the webservice response.
|
|
|
80 |
*
|
|
|
81 |
* @return external_description
|
|
|
82 |
*/
|
|
|
83 |
public static function execute_returns(): external_description {
|
|
|
84 |
return new external_value(PARAM_RAW, 'JSON-encoded data required to render the mod_quiz/edit_grading_page template.');
|
|
|
85 |
}
|
|
|
86 |
}
|