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
/**
18
 * Generate a new draft itemid for the current user.
19
 *
20
 * @package    core_files
21
 * @since      Moodle 3.11
22
 * @copyright  2020 Juan Leyva <juan@moodle.com>
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace core_files\external\get;
27
 
28
defined('MOODLE_INTERNAL') || die();
29
 
30
global $CFG;
31
require_once($CFG->libdir . '/filelib.php');
32
 
33
use core_external\external_api;
34
use core_external\external_function_parameters;
35
use core_external\external_single_structure;
36
use core_external\external_value;
37
use core_external\external_warnings;
38
use context_user;
39
 
40
/**
41
 * Generate a new draft itemid for the current user.
42
 *
43
 * @copyright  2020 Juan Leyva <juan@moodle.com>
44
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45
 */
46
class unused_draft extends external_api {
47
 
48
    /**
49
     * Describes the parameters for execute.
50
     *
51
     * @return external_function_parameters
52
     * @since Moodle 3.11
53
     */
54
    public static function execute_parameters(): external_function_parameters {
55
        return new external_function_parameters ([]);
56
    }
57
 
58
    /**
59
     * Generate a new draft itemid for the current user.
60
     *
61
     * @return array of information containing the draft item area and possible warnings.
62
     * @since Moodle 3.11
63
     */
64
    public static function execute(): array {
65
        global $USER;
66
 
67
        $usercontext = context_user::instance($USER->id);
68
        self::validate_context($usercontext);
69
 
70
        return [
71
            'component' => 'user',
72
            'contextid' => $usercontext->id,
73
            'userid' => $USER->id,
74
            'filearea' => 'draft',
75
            'itemid' => file_get_unused_draft_itemid(),
76
            'warnings' => [],
77
        ];
78
    }
79
 
80
    /**
81
     * Describes the execute return value.
82
     *
83
     * @return external_single_structure
84
     * @since Moodle 3.11
85
     */
86
    public static function execute_returns(): external_single_structure {
87
        return new external_single_structure(
88
            [
89
                'component' => new external_value(PARAM_COMPONENT, 'File area component.'),
90
                'contextid' => new external_value(PARAM_INT, 'File area context.'),
91
                'userid' => new external_value(PARAM_INT, 'File area user id.'),
92
                'filearea' => new external_value(PARAM_ALPHA, 'File area name.'),
93
                'itemid' => new external_value(PARAM_INT, 'File are item id.'),
94
                'warnings' => new external_warnings(),
95
            ]
96
        );
97
    }
98
}