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
namespace core_blog\external;
18
 
19
use context_system;
20
use core_external\external_api;
21
use core_external\external_function_parameters;
22
use core_external\external_single_structure;
23
use core_external\external_value;
24
use core_external\external_warnings;
25
 
26
 
27
/**
28
 * External blog API implementation
29
 *
30
 * @package    core_blog
31
 * @copyright  2024 Juan Leyva <juan@moodle.com>
32
 * @category   external
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class get_access_information extends external_api {
36
 
37
    /**
38
     * Returns description of method parameters.
39
     *
40
     * @return external_function_parameters.
41
     * @since  Moodle 4.4
42
     */
43
    public static function execute_parameters(): external_function_parameters {
44
        return new external_function_parameters([]);
45
    }
46
 
47
    /**
48
     * Convenience function to retrieve some permissions information for the blogs system.
49
     *
50
     * @return array The access information
51
     * @since  Moodle 4.4
52
     */
53
    public static function execute(): array {
54
 
55
        $context = context_system::instance();
56
        self::validate_context($context);
57
 
58
        return [
59
            'canview' => has_capability('moodle/blog:view', $context),
60
            'cansearch' => has_capability('moodle/blog:search', $context),
61
            'canviewdrafts' => has_capability('moodle/blog:viewdrafts', $context),
62
            'cancreate' => has_capability('moodle/blog:create', $context),
63
            'canmanageentries' => has_capability('moodle/blog:manageentries', $context),
64
            'canmanageexternal' => has_capability('moodle/blog:manageexternal', $context),
65
            'warnings' => [],
66
        ];
67
    }
68
 
69
    /**
70
     * Returns description of method result value.
71
     *
72
     * @return external_single_structure.
73
     * @since  Moodle 4.4
74
     */
75
    public static function execute_returns(): external_single_structure {
76
 
77
        return new external_single_structure(
78
            [
79
                'canview' => new external_value(PARAM_BOOL, 'Whether the user can view blogs'),
80
                'cansearch' => new external_value(PARAM_BOOL, 'Whether the user can search blogs'),
81
                'canviewdrafts' => new external_value(PARAM_BOOL, 'Whether the user can view drafts'),
82
                'cancreate' => new external_value(PARAM_BOOL, 'Whether the user can create blog entries'),
83
                'canmanageentries' => new external_value(PARAM_BOOL, 'Whether the user can manage blog entries'),
84
                'canmanageexternal' => new external_value(PARAM_BOOL, 'Whether the user can manage external blogs'),
85
                'warnings' => new external_warnings(),
86
            ]
87
        );
88
    }
89
}