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 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace core_reportbuilder\external\filters;
|
|
|
20 |
|
|
|
21 |
use core_external\external_api;
|
|
|
22 |
use core_external\external_value;
|
|
|
23 |
use core_external\external_function_parameters;
|
|
|
24 |
use core_reportbuilder\manager;
|
|
|
25 |
use core_reportbuilder\permission;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* External method for setting report filter values
|
|
|
29 |
*
|
|
|
30 |
* @package core_reportbuilder
|
|
|
31 |
* @copyright 2022 Paul Holden <paulh@moodle.com>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class set extends external_api {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* External method parameters
|
|
|
38 |
*
|
|
|
39 |
* @return external_function_parameters
|
|
|
40 |
*/
|
|
|
41 |
public static function execute_parameters(): external_function_parameters {
|
|
|
42 |
return new external_function_parameters([
|
|
|
43 |
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
|
|
44 |
'parameters' => new external_value(PARAM_RAW, 'JSON encoded report parameters', VALUE_DEFAULT, ''),
|
|
|
45 |
'values' => new external_value(PARAM_RAW, 'JSON encoded filter values'),
|
|
|
46 |
]);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* External method execution
|
|
|
51 |
*
|
|
|
52 |
* @param int $reportid
|
|
|
53 |
* @param string $parameters
|
|
|
54 |
* @param string $values
|
|
|
55 |
* @return bool
|
|
|
56 |
*/
|
|
|
57 |
public static function execute(int $reportid, string $parameters, string $values): bool {
|
|
|
58 |
[
|
|
|
59 |
'reportid' => $reportid,
|
|
|
60 |
'parameters' => $parameters,
|
|
|
61 |
'values' => $values,
|
|
|
62 |
] = self::validate_parameters(self::execute_parameters(), [
|
|
|
63 |
'reportid' => $reportid,
|
|
|
64 |
'parameters' => $parameters,
|
|
|
65 |
'values' => $values,
|
|
|
66 |
]);
|
|
|
67 |
|
|
|
68 |
$report = manager::get_report_from_id($reportid, (array) json_decode($parameters));
|
|
|
69 |
self::validate_context($report->get_context());
|
|
|
70 |
|
|
|
71 |
// System report permission is implicitly handled, we need to make sure custom report can be viewed.
|
|
|
72 |
$persistent = $report->get_report_persistent();
|
|
|
73 |
if ($persistent->get('type') === $report::TYPE_CUSTOM_REPORT) {
|
|
|
74 |
permission::require_can_view_report($persistent);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
return $report->set_filter_values((array) json_decode($values));
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* External method return value
|
|
|
82 |
*
|
|
|
83 |
* @return external_value
|
|
|
84 |
*/
|
|
|
85 |
public static function execute_returns(): external_value {
|
|
|
86 |
return new external_value(PARAM_BOOL, 'Success');
|
|
|
87 |
}
|
|
|
88 |
}
|