source: moodle/trunk/fuentes/enrol/self/externallib.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 3 years ago

Ported code to xenial

File size: 3.6 KB
Line 
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 * Self enrol plugin external functions
19 *
20 * @package    enrol_self
21 * @copyright  2013 Rajesh Taneja <rajesh@moodle.com>
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27require_once("$CFG->libdir/externallib.php");
28
29/**
30 * Self enrolment external functions.
31 *
32 * @package   enrol_self
33 * @copyright 2012 Rajesh Taneja <rajesh@moodle.com>
34 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 * @since     Moodle 2.6
36 */
37class enrol_self_external extends external_api {
38
39    /**
40     * Returns description of get_instance_info() parameters.
41     *
42     * @return external_function_parameters
43     */
44    public static function get_instance_info_parameters() {
45        return new external_function_parameters(
46                array('instanceid' => new external_value(PARAM_INT, 'instance id of self enrolment plugin.'))
47            );
48    }
49
50    /**
51     * Return self-enrolment instance information.
52     *
53     * @param int $instanceid instance id of self enrolment plugin.
54     * @return array instance information.
55     */
56    public static function get_instance_info($instanceid) {
57        global $DB, $CFG;
58
59        require_once($CFG->libdir . '/enrollib.php');
60
61        $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid));
62
63        // Retrieve self enrolment plugin.
64        $enrolplugin = enrol_get_plugin('self');
65        if (empty($enrolplugin)) {
66            throw new moodle_exception('invaliddata', 'error');
67        }
68
69        $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
70        $coursecontext = context_course::instance($enrolinstance->courseid);
71        $categorycontext = $coursecontext->get_parent_context();
72        self::validate_context($categorycontext);
73
74        $instanceinfo = (array) $enrolplugin->get_enrol_info($enrolinstance);
75        if (isset($instanceinfo['requiredparam']->enrolpassword)) {
76            $instanceinfo['enrolpassword'] = $instanceinfo['requiredparam']->enrolpassword;
77        }
78        unset($instanceinfo->requiredparam);
79
80        return $instanceinfo;
81    }
82
83    /**
84     * Returns description of get_instance_info() result value.
85     *
86     * @return external_description
87     */
88    public static function get_instance_info_returns() {
89        return new external_single_structure(
90            array(
91                'id' => new external_value(PARAM_INT, 'id of course enrolment instance'),
92                'courseid' => new external_value(PARAM_INT, 'id of course'),
93                'type' => new external_value(PARAM_PLUGIN, 'type of enrolment plugin'),
94                'name' => new external_value(PARAM_RAW, 'name of enrolment plugin'),
95                'status' => new external_value(PARAM_RAW, 'status of enrolment plugin'),
96                'enrolpassword' => new external_value(PARAM_RAW, 'password required for enrolment', VALUE_OPTIONAL),
97            )
98        );
99    }
100}
Note: See TracBrowser for help on using the repository browser.