Differences Between: [Versions 400 and 402] [Versions 401 and 402]
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\audiences; 20 21 use core_reportbuilder\local\audiences\base; 22 use core_external\external_api; 23 use core_external\external_value; 24 use core_external\external_function_parameters; 25 use core_reportbuilder\manager; 26 use core_reportbuilder\permission; 27 28 /** 29 * External method for deleting a report audience 30 * 31 * @package core_reportbuilder 32 * @copyright 2021 David Matamoros <davidmc@moodle.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class delete extends external_api { 36 37 /** 38 * Describes the parameters for get_users_courses. 39 * 40 * @return external_function_parameters 41 */ 42 public static function execute_parameters(): external_function_parameters { 43 return new external_function_parameters( 44 [ 45 'reportid' => new external_value(PARAM_INT, 'Report id'), 46 'instanceid' => new external_value(PARAM_INT, 'Audience instance id'), 47 ] 48 ); 49 } 50 51 /** 52 * External function to delete a report audience instance. 53 * 54 * @param int $reportid 55 * @param int $instanceid 56 * @return bool 57 */ 58 public static function execute(int $reportid, int $instanceid): bool { 59 [ 60 'reportid' => $reportid, 61 'instanceid' => $instanceid, 62 ] = self::validate_parameters(self::execute_parameters(), [ 63 'reportid' => $reportid, 64 'instanceid' => $instanceid, 65 ]); 66 67 $report = manager::get_report_from_id($reportid); 68 69 self::validate_context($report->get_context()); 70 permission::require_can_edit_report($report->get_report_persistent()); 71 72 $baseinstance = base::instance($instanceid); 73 if ($baseinstance && $baseinstance->user_can_edit()) { 74 $persistent = $baseinstance->get_persistent(); 75 $persistent->delete(); 76 return true; 77 } 78 79 return false; 80 } 81 82 /** 83 * Describes the data returned from the external function. 84 * 85 * @return external_value 86 */ 87 public static function execute_returns(): external_value { 88 return new external_value(PARAM_BOOL, '', VALUE_REQUIRED); 89 } 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body