Differences Between: [Versions 400 and 402] [Versions 400 and 403]
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 external_api; 22 use external_function_parameters; 23 use external_value; 24 use core_reportbuilder\manager; 25 use core_reportbuilder\permission; 26 use core_reportbuilder\local\helpers\user_filter_manager; 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 global $CFG; 31 require_once("{$CFG->libdir}/externallib.php"); 32 33 /** 34 * External method for resetting report filters 35 * 36 * @package core_reportbuilder 37 * @copyright 2021 Paul Holden <paulh@moodle.com> 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class reset extends external_api { 41 42 /** 43 * External method parameters 44 * 45 * @return external_function_parameters 46 */ 47 public static function execute_parameters(): external_function_parameters { 48 return new external_function_parameters([ 49 'reportid' => new external_value(PARAM_INT, 'Report ID'), 50 'parameters' => new external_value(PARAM_RAW, 'JSON encoded report parameters', VALUE_DEFAULT, ''), 51 ]); 52 } 53 54 /** 55 * External method execution 56 * 57 * @param int $reportid 58 * @param string $parameters JSON encoded parameters used to re-create the report, for instance for those reports that 59 * require parameters as part of their {@see \core_reportbuilder\system_report::can_view} implementation 60 * @return bool 61 */ 62 public static function execute(int $reportid, string $parameters = ''): bool { 63 [ 64 'reportid' => $reportid, 65 'parameters' => $parameters, 66 ] = self::validate_parameters(self::execute_parameters(), [ 67 'reportid' => $reportid, 68 'parameters' => $parameters, 69 ]); 70 71 $report = manager::get_report_from_id($reportid, (array) json_decode($parameters)); 72 self::validate_context($report->get_context()); 73 74 // System report permission is implicitly handled, we need to make sure custom report can be viewed. 75 $persistent = $report->get_report_persistent(); 76 if ($persistent->get('type') === $report::TYPE_CUSTOM_REPORT) { 77 permission::require_can_view_report($persistent); 78 } 79 80 return user_filter_manager::reset_all($reportid); 81 } 82 83 /** 84 * External method return value 85 * 86 * @return external_value 87 */ 88 public static function execute_returns(): external_value { 89 return new external_value(PARAM_BOOL, 'Success'); 90 } 91 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body