Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Guest enrolment method external API
 *
 * @package    enrol_guest
 * @category   external
 * @copyright  2015 Juan Leyva <juan@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @since      Moodle 3.1
 */

> use core_external\external_api; defined('MOODLE_INTERNAL') || die; > use core_external\external_description; > use core_external\external_function_parameters; require_once($CFG->libdir . '/externallib.php'); > use core_external\external_single_structure; require_once($CFG->libdir . '/enrollib.php'); > use core_external\external_value; > use core_external\external_warnings; /** >
< require_once($CFG->libdir . '/externallib.php');
* * @package enrol_guest * @category external * @copyright 2015 Juan Leyva <juan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 3.1 */ class enrol_guest_external extends external_api { /** * Returns description of get_instance_info() parameters. * * @return external_function_parameters * @since Moodle 3.1 */ public static function get_instance_info_parameters() { return new external_function_parameters( array('instanceid' => new external_value(PARAM_INT, 'Instance id of guest enrolment plugin.')) ); } /** * Return guest enrolment instance information. * * @param int $instanceid instance id of guest enrolment plugin. * @return array warnings and instance information. * @since Moodle 3.1 */ public static function get_instance_info($instanceid) { global $DB; $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid)); $warnings = array(); // Retrieve guest enrolment plugin. $enrolplugin = enrol_get_plugin('guest'); if (empty($enrolplugin)) { throw new moodle_exception('invaliddata', 'error'); } self::validate_context(context_system::instance()); $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST); if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) { throw new moodle_exception('coursehidden'); } $instanceinfo = $enrolplugin->get_enrol_info($enrolinstance); // Specific instance information. $instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired; unset($instanceinfo->requiredparam); $result = array(); $result['instanceinfo'] = $instanceinfo; $result['warnings'] = $warnings; return $result; } /** * Returns description of get_instance_info() result value. * * @return external_description * @since Moodle 3.1 */ public static function get_instance_info_returns() { return new external_single_structure( array( 'instanceinfo' => new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Id of course enrolment instance'), 'courseid' => new external_value(PARAM_INT, 'Id of course'), 'type' => new external_value(PARAM_PLUGIN, 'Type of enrolment plugin'), 'name' => new external_value(PARAM_RAW, 'Name of enrolment plugin'), 'status' => new external_value(PARAM_BOOL, 'Is the enrolment enabled?'), 'passwordrequired' => new external_value(PARAM_BOOL, 'Is a password required?'), ) ), 'warnings' => new external_warnings() ) ); } }