first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+124
View File
@@ -0,0 +1,124 @@
<?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;
use core_external\external_description;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/enrollib.php');
/**
* 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
*/
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()
)
);
}
}
+127
View File
@@ -0,0 +1,127 @@
<?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/>.
namespace enrol_guest\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use context_system;
use moodle_exception;
use core_text;
use stdClass;
/**
* This is the external method validating a guest password.
*
* @package enrol_guest
* @since Moodle 4.3
* @copyright 2023 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class validate_password extends external_api {
/**
* Webservice parameters.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters(
[
'instanceid' => new external_value(PARAM_INT, 'instance id of guest enrolment plugin'),
'password' => new external_value(PARAM_RAW, 'the course password'),
]
);
}
/**
* Perform password validation.
*
* If password is correct: keep it as user preference.
* If password is not correct: remove existing user preference (if any)
*
* @throws moodle_exception
* @param int $instanceid instance id of guest enrolment plugin
* @param string $password the course password
* @return stdClass validation result info
*/
public static function execute(int $instanceid, string $password): stdClass {
global $CFG, $DB;
require_once($CFG->libdir . '/enrollib.php');
$params = external_api::validate_parameters(self::execute_parameters(), [
'instanceid' => $instanceid,
'password' => $password,
]);
$warnings = [];
$validated = false;
$hint = '';
// 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',
['id' => $params['instanceid'], 'status' => ENROL_INSTANCE_ENABLED], '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $enrolinstance->courseid], '*', MUST_EXIST);
if (!\core_course_category::can_view_course_info($course) && !can_access_course($course)) {
throw new moodle_exception('coursehidden');
}
if ($enrolinstance->password) {
if ($params['password'] === $enrolinstance->password) {
$validated = true;
set_user_preference('enrol_guest_ws_password_' . $enrolinstance->id, $params['password']);
} else {
// Always unset in case there was something stored.
unset_user_preference('enrol_guest_ws_password_' . $enrolinstance->id);
if ($enrolplugin->get_config('showhint')) {
$hint = core_text::substr($enrolinstance->password, 0, 1);
$hint = get_string('passwordinvalidhint', 'enrol_guest', $hint);
}
}
}
$result = (object)[
'validated' => $validated,
'hint' => $hint,
'warnings' => $warnings,
];
return $result;
}
/**
* Describes the return information.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'validated' => new external_value(PARAM_BOOL, 'Whether the password was successfully validated'),
'hint' => new external_value(PARAM_RAW, 'Password hint (if enabled)', VALUE_OPTIONAL),
'warnings' => new external_warnings(),
]);
}
}
+41
View File
@@ -0,0 +1,41 @@
<?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/>.
/**
* Privacy Subsystem implementation for enrol_guest.
*
* @package enrol_guest
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_guest\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for enrol_guest implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}