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
 * Provides the {@link core_form\external} class.
19
 *
20
 * @package     core_form
21
 * @category    external
22
 * @copyright   2017 David Mudrák <david@moodle.com>
23
 * @copyright   2016 Jonathon Fowler <fowlerj@usq.edu.au>
24
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
namespace core_form;
28
 
29
use core_external\external_api;
30
use core_external\external_function_parameters;
31
use core_external\external_multiple_structure;
32
use core_external\external_single_structure;
33
use core_external\external_value;
34
 
35
/**
36
 * Implements the external functions provided by the core_form subsystem.
37
 *
38
 * @copyright 2017 David Mudrak <david@moodle.com>
39
 * @copyright 2016 Jonathon Fowler <fowlerj@usq.edu.au>
40
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
42
class external extends external_api {
43
 
44
    /**
45
     * Describes the input paramaters of the get_filetypes_browser_data external function.
46
     *
47
     * @return \core_external\external_description
48
     */
49
    public static function get_filetypes_browser_data_parameters() {
50
        return new external_function_parameters([
51
            'onlytypes' => new external_value(PARAM_RAW, 'Limit the browser to the given groups and extensions', VALUE_DEFAULT, ''),
52
            'allowall' => new external_value(PARAM_BOOL, 'Allows to select All file types, does not apply with onlytypes are set.',
53
                VALUE_DEFAULT, true),
54
            'current' => new external_value(PARAM_RAW, 'Current types that should be selected.', VALUE_DEFAULT, ''),
55
        ]);
56
    }
57
 
58
    /**
59
     * Implements the get_filetypes_browser_data external function.
60
     *
61
     * @param string $onlytypes Allow selection from these file types only; for example 'web_image'.
62
     * @param bool $allowall Allow to select 'All file types'. Does not apply if onlytypes is set.
63
     * @param string $current Current values that should be selected.
64
     * @return object
65
     */
66
    public static function get_filetypes_browser_data($onlytypes, $allowall, $current) {
67
 
68
        $params = self::validate_parameters(self::get_filetypes_browser_data_parameters(),
69
            compact('onlytypes', 'allowall', 'current'));
70
 
71
        $util = new filetypes_util();
72
 
73
        return ['groups' => $util->data_for_browser($params['onlytypes'], $params['allowall'], $params['current'])];
74
    }
75
 
76
    /**
77
     * Describes the output of the get_filetypes_browser_data external function.
78
     *
79
     * @return \core_external\external_description
80
     */
81
    public static function get_filetypes_browser_data_returns() {
82
 
83
        $type = new external_single_structure([
84
            'key' => new external_value(PARAM_RAW, 'The file type identifier'),
85
            'name' => new external_value(PARAM_RAW, 'The file type name'),
86
            'selected' => new external_value(PARAM_BOOL, 'Should it be marked as selected'),
87
            'ext' => new external_value(PARAM_RAW, 'The file extension associated with the file type'),
88
        ]);
89
 
90
        $group = new external_single_structure([
91
            'key' => new external_value(PARAM_RAW, 'The file type group identifier'),
92
            'name' => new external_value(PARAM_RAW, 'The file type group name'),
93
            'selectable' => new external_value(PARAM_BOOL, 'Can it be marked as selected'),
94
            'selected' => new external_value(PARAM_BOOL, 'Should it be marked as selected'),
95
            'ext' => new external_value(PARAM_RAW, 'The list of file extensions associated with the group'),
96
            'expanded' => new external_value(PARAM_BOOL, 'Should the group start as expanded or collapsed'),
97
            'types' => new external_multiple_structure($type, 'List of file types in the group'),
98
        ]);
99
 
100
        return new external_single_structure([
101
            'groups' => new external_multiple_structure($group, 'List of file type groups'),
102
        ]);
103
    }
104
}