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 * IMSCP 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_imscp_external extends external_api {
43 * Returns description of method parameters
45 * @return external_function_parameters
48 public static function view_imscp_parameters() {
49 return new external_function_parameters(
51 'imscpid' => new external_value(PARAM_INT, 'imscp instance id')
57 * Simulate the imscp/view.php web interface page: trigger events, completion, etc...
59 * @param int $imscpid the imscp instance id
60 * @return array of warnings and status result
62 * @throws moodle_exception
64 public static function view_imscp($imscpid) {
66 require_once($CFG->dirroot . "/mod/imscp/lib.php");
68 $params = self::validate_parameters(self::view_imscp_parameters(),
74 // Request and permission validation.
75 $imscp = $DB->get_record('imscp', array('id' => $params['imscpid']), '*', MUST_EXIST);
76 list($course, $cm) = get_course_and_cm_from_instance($imscp, 'imscp');
78 $context = context_module::instance($cm->id);
79 self::validate_context($context);
81 require_capability('mod/imscp:view', $context);
83 // Call the imscp/lib API.
84 imscp_view($imscp, $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_imscp_returns() {
99 return new external_single_structure(
101 'status' => new external_value(PARAM_BOOL, 'status: true if success'),
102 'warnings' => new external_warnings()