Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]
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 * Guest enrolment method external API 19 * 20 * @package enrol_guest 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.1 25 */ 26 27 use core_external\external_api; 28 use core_external\external_description; 29 use core_external\external_function_parameters; 30 use core_external\external_single_structure; 31 use core_external\external_value; 32 use core_external\external_warnings; 33 34 defined('MOODLE_INTERNAL') || die; 35 36 require_once($CFG->libdir . '/enrollib.php'); 37 38 /** 39 * Guest enrolment method external API 40 * 41 * @package enrol_guest 42 * @category external 43 * @copyright 2015 Juan Leyva <juan@moodle.com> 44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 45 * @since Moodle 3.1 46 */ 47 class enrol_guest_external extends external_api { 48 49 /** 50 * Returns description of get_instance_info() parameters. 51 * 52 * @return external_function_parameters 53 * @since Moodle 3.1 54 */ 55 public static function get_instance_info_parameters() { 56 return new external_function_parameters( 57 array('instanceid' => new external_value(PARAM_INT, 'Instance id of guest enrolment plugin.')) 58 ); 59 } 60 61 /** 62 * Return guest enrolment instance information. 63 * 64 * @param int $instanceid instance id of guest enrolment plugin. 65 * @return array warnings and instance information. 66 * @since Moodle 3.1 67 */ 68 public static function get_instance_info($instanceid) { 69 global $DB; 70 71 $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid)); 72 $warnings = array(); 73 74 // Retrieve guest enrolment plugin. 75 $enrolplugin = enrol_get_plugin('guest'); 76 if (empty($enrolplugin)) { 77 throw new moodle_exception('invaliddata', 'error'); 78 } 79 80 self::validate_context(context_system::instance()); 81 $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST); 82 83 $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST); 84 if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) { 85 throw new moodle_exception('coursehidden'); 86 } 87 88 $instanceinfo = $enrolplugin->get_enrol_info($enrolinstance); 89 // Specific instance information. 90 $instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired; 91 92 unset($instanceinfo->requiredparam); 93 94 $result = array(); 95 $result['instanceinfo'] = $instanceinfo; 96 $result['warnings'] = $warnings; 97 return $result; 98 } 99 100 /** 101 * Returns description of get_instance_info() result value. 102 * 103 * @return external_description 104 * @since Moodle 3.1 105 */ 106 public static function get_instance_info_returns() { 107 return new external_single_structure( 108 array( 109 'instanceinfo' => new external_single_structure( 110 array( 111 'id' => new external_value(PARAM_INT, 'Id of course enrolment instance'), 112 'courseid' => new external_value(PARAM_INT, 'Id of course'), 113 'type' => new external_value(PARAM_PLUGIN, 'Type of enrolment plugin'), 114 'name' => new external_value(PARAM_RAW, 'Name of enrolment plugin'), 115 'status' => new external_value(PARAM_BOOL, 'Is the enrolment enabled?'), 116 'passwordrequired' => new external_value(PARAM_BOOL, 'Is a password required?'), 117 ) 118 ), 119 'warnings' => new external_warnings() 120 ) 121 ); 122 } 123 124 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body