2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
22 * @copyright 2015 Juan Leyva <juan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die;
29 require_once("$CFG->libdir/externallib.php");
32 * folder external functions
36 * @copyright 2015 Juan Leyva <juan@moodle.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class mod_folder_external
extends external_api
{
43 * Returns description of method parameters
45 * @return external_function_parameters
48 public static function view_folder_parameters() {
49 return new external_function_parameters(
51 'folderid' => new external_value(PARAM_INT
, 'folder instance id')
57 * Simulate the folder/view.php web interface page: trigger events, completion, etc...
59 * @param int $folderid the folder instance id
60 * @return array of warnings and status result
62 * @throws moodle_exception
64 public static function view_folder($folderid) {
66 require_once($CFG->dirroot
. "/mod/folder/lib.php");
68 $params = self
::validate_parameters(self
::view_folder_parameters(),
70 'folderid' => $folderid
74 // Request and permission validation.
75 $folder = $DB->get_record('folder', array('id' => $params['folderid']), '*', MUST_EXIST
);
76 list($course, $cm) = get_course_and_cm_from_instance($folder, 'folder');
78 $context = context_module
::instance($cm->id
);
79 self
::validate_context($context);
81 require_capability('mod/folder:view', $context);
83 // Call the page/lib API.
84 folder_view($folder, $course, $cm, $context);
87 $result['status'] = true;
88 $result['warnings'] = $warnings;
93 * Returns description of method result value
95 * @return external_description
98 public static function view_folder_returns() {
99 return new external_single_structure(
101 'status' => new external_value(PARAM_BOOL
, 'status: true if success'),
102 'warnings' => new external_warnings()