Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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\reports;
20
 
21
use core_external\external_api;
22
use core_external\external_value;
23
use core_external\external_function_parameters;
24
use core_reportbuilder\permission;
25
use core_reportbuilder\local\helpers\report;
26
use core_reportbuilder\local\models\report as report_model;
27
 
28
/**
29
 * External method for deleting reports
30
 *
31
 * @package     core_reportbuilder
32
 * @copyright   2021 Paul Holden <paulh@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
     * External method parameters
39
     *
40
     * @return external_function_parameters
41
     */
42
    public static function execute_parameters(): external_function_parameters {
43
        return new external_function_parameters([
44
            'reportid' => new external_value(PARAM_INT, 'Report ID'),
45
        ]);
46
    }
47
 
48
    /**
49
     * External method execution
50
     *
51
     * @param int $reportid
52
     * @return bool
53
     */
54
    public static function execute(int $reportid): bool {
55
        [
56
            'reportid' => $reportid,
57
        ] = self::validate_parameters(self::execute_parameters(), [
58
            'reportid' => $reportid,
59
        ]);
60
 
61
        // Load the report model for deletion. Note we don't use the manager class because it validates the report source,
62
        // and we want user to be able to delete report, even if it's no longer associated with a valid source.
63
        $report = new report_model($reportid);
64
 
65
        self::validate_context($report->get_context());
66
        permission::require_can_edit_report($report);
67
 
68
        return report::delete_report($reportid);
69
    }
70
 
71
    /**
72
     * External method return value
73
     *
74
     * @return external_value
75
     */
76
    public static function execute_returns(): external_value {
77
        return new external_value(PARAM_BOOL, 'Success');
78
    }
79
}