Merge branch 'MDL-53170_master' of git://github.com/dmonllao/moodle
[moodle.git] / mod / folder / classes / external.php
blobc547800047896a12f3183df59a0cabae6b13c0af
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.
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/>.
17 /**
18 * folder external API
20 * @package mod_folder
21 * @category external
22 * @copyright 2015 Juan Leyva <juan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * @since Moodle 3.0
27 defined('MOODLE_INTERNAL') || die;
29 require_once("$CFG->libdir/externallib.php");
31 /**
32 * folder external functions
34 * @package mod_folder
35 * @category external
36 * @copyright 2015 Juan Leyva <juan@moodle.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 * @since Moodle 3.0
40 class mod_folder_external extends external_api {
42 /**
43 * Returns description of method parameters
45 * @return external_function_parameters
46 * @since Moodle 3.0
48 public static function view_folder_parameters() {
49 return new external_function_parameters(
50 array(
51 'folderid' => new external_value(PARAM_INT, 'folder instance id')
56 /**
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
61 * @since Moodle 3.0
62 * @throws moodle_exception
64 public static function view_folder($folderid) {
65 global $DB, $CFG;
66 require_once($CFG->dirroot . "/mod/folder/lib.php");
68 $params = self::validate_parameters(self::view_folder_parameters(),
69 array(
70 'folderid' => $folderid
71 ));
72 $warnings = array();
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);
86 $result = array();
87 $result['status'] = true;
88 $result['warnings'] = $warnings;
89 return $result;
92 /**
93 * Returns description of method result value
95 * @return external_description
96 * @since Moodle 3.0
98 public static function view_folder_returns() {
99 return new external_single_structure(
100 array(
101 'status' => new external_value(PARAM_BOOL, 'status: true if success'),
102 'warnings' => new external_warnings()