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 block_accessreview\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 tool_brickfield\manager;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Web service to fetch module data.
|
|
|
28 |
*
|
|
|
29 |
* @package block_accessreview
|
|
|
30 |
* @copyright 2020 onward Brickfield Education Labs Ltd, https://www.brickfield.ie
|
|
|
31 |
* @author 2020 Max Larkin <max@brickfieldlabs.ie>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class get_module_data extends external_api {
|
|
|
35 |
/**
|
|
|
36 |
* Describes the parameters.
|
|
|
37 |
*
|
|
|
38 |
* @return external_function_parameters
|
|
|
39 |
*/
|
|
|
40 |
public static function execute_parameters() {
|
|
|
41 |
return new external_function_parameters([
|
|
|
42 |
'courseid' => new external_value(PARAM_INT, 'The course id to obtain results for.', VALUE_REQUIRED),
|
|
|
43 |
]);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Execute the service.
|
|
|
48 |
*
|
|
|
49 |
* @param int $courseid
|
|
|
50 |
* @return array
|
|
|
51 |
*/
|
|
|
52 |
public static function execute(int $courseid) {
|
|
|
53 |
[
|
|
|
54 |
'courseid' => $courseid,
|
|
|
55 |
] = self::validate_parameters(self::execute_parameters(), [
|
|
|
56 |
'courseid' => $courseid,
|
|
|
57 |
]);
|
|
|
58 |
|
|
|
59 |
$context = \context_course::instance($courseid);
|
|
|
60 |
self::validate_context($context);
|
|
|
61 |
|
|
|
62 |
require_capability('block/accessreview:view', $context);
|
|
|
63 |
|
|
|
64 |
return array_values(manager::get_cm_summary_for_course($courseid));
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Describes the return structure of the service..
|
|
|
69 |
*
|
|
|
70 |
* @return external_multiple_structure
|
|
|
71 |
*/
|
|
|
72 |
public static function execute_returns() {
|
|
|
73 |
return new external_multiple_structure(
|
|
|
74 |
new external_single_structure(
|
|
|
75 |
[
|
|
|
76 |
'cmid' => new external_value(PARAM_INT, 'ID'),
|
|
|
77 |
'numerrors' => new external_value(PARAM_INT, 'Number of errors.'),
|
|
|
78 |
'numchecks' => new external_value(PARAM_INT, 'Number of checks.'),
|
|
|
79 |
]
|
|
|
80 |
)
|
|
|
81 |
);
|
|
|
82 |
}
|
|
|
83 |
}
|