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
@@ -0,0 +1,37 @@
<?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/>.
/**
* The form to confirm the intention to bulk delete users enrolments.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->dirroot/enrol/bulkchange_forms.php");
/**
* The form to confirm the intention to bulk delete users enrolments.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_self_deleteselectedusers_form extends enrol_bulk_enrolment_confirm_form {
}
@@ -0,0 +1,98 @@
<?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/>.
/**
* A bulk operation for the self enrolment plugin to delete selected users enrolments.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* A bulk operation for the self enrolment plugin to delete selected users enrolments.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_self_deleteselectedusers_operation extends enrol_bulk_enrolment_operation {
/**
* Returns the title to display for this bulk operation.
*
* @return string
*/
public function get_identifier() {
return 'deleteselectedusers';
}
/**
* Returns the identifier for this bulk operation. This is the key used when the plugin
* returns an array containing all of the bulk operations it supports.
*
* @return string
*/
public function get_title() {
return get_string('deleteselectedusers', 'enrol_self');
}
/**
* Returns a enrol_bulk_enrolment_operation extension form to be used
* in collecting required information for this operation to be processed.
*
* @param string|moodle_url|null $defaultaction
* @param mixed $defaultcustomdata
* @return enrol_self_deleteselectedusers_form
*/
public function get_form($defaultaction = null, $defaultcustomdata = null) {
if (!array($defaultcustomdata)) {
$defaultcustomdata = array();
}
$defaultcustomdata['title'] = $this->get_title();
$defaultcustomdata['message'] = get_string('confirmbulkdeleteenrolment', 'enrol_self');
$defaultcustomdata['button'] = get_string('unenrolusers', 'enrol_self');
return new enrol_self_deleteselectedusers_form($defaultaction, $defaultcustomdata);
}
/**
* Processes the bulk operation request for the given userids with the provided properties.
*
* @param course_enrolment_manager $manager
* @param array $users
* @param stdClass $properties The data returned by the form.
*/
public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
if (!has_capability("enrol/self:unenrol", $manager->get_context())) {
return false;
}
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$plugin = $enrolment->enrolmentplugin;
$instance = $enrolment->enrolmentinstance;
if ($plugin->allow_unenrol_user($instance, $enrolment)) {
$plugin->unenrol_user($instance, $user->id);
}
}
}
return true;
}
}
@@ -0,0 +1,37 @@
<?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/>.
/**
* The form to collect required information when bulk editing users enrolments.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->dirroot/enrol/bulkchange_forms.php");
/**
* The form to collect required information when bulk editing users enrolments.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_self_editselectedusers_form extends enrol_bulk_enrolment_change_form {
}
@@ -0,0 +1,161 @@
<?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/>.
/**
* A bulk operation for the manual enrolment plugin to edit selected users.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* A bulk operation for the manual enrolment plugin to edit selected users.
*
* @package enrol_self
* @copyright 2018 Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_self_editselectedusers_operation extends enrol_bulk_enrolment_operation {
/**
* Returns the title to display for this bulk operation.
*
* @return string
*/
public function get_title() {
return get_string('editselectedusers', 'enrol_self');
}
/**
* Returns the identifier for this bulk operation. This is the key used when the plugin
* returns an array containing all of the bulk operations it supports.
*/
public function get_identifier() {
return 'editselectedusers';
}
/**
* Processes the bulk operation request for the given userids with the provided properties.
*
* @param course_enrolment_manager $manager
* @param array $users
* @param stdClass $properties The data returned by the form.
*/
public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
global $DB, $USER;
if (!has_capability("enrol/self:manage", $manager->get_context())) {
return false;
}
// Get all of the user enrolment id's.
$ueids = array();
$instances = array();
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$ueids[] = $enrolment->id;
if (!array_key_exists($enrolment->id, $instances)) {
$instances[$enrolment->id] = $enrolment;
}
}
}
// Check that each instance is manageable by the current user.
foreach ($instances as $instance) {
if (!$this->plugin->allow_manage($instance)) {
return false;
}
}
// Collect the known properties.
$status = $properties->status;
$timestart = $properties->timestart;
$timeend = $properties->timeend;
list($ueidsql, $params) = $DB->get_in_or_equal($ueids, SQL_PARAMS_NAMED);
$updatesql = array();
if ($status == ENROL_USER_ACTIVE || $status == ENROL_USER_SUSPENDED) {
$updatesql[] = 'status = :status';
$params['status'] = (int)$status;
}
if (!empty($timestart)) {
$updatesql[] = 'timestart = :timestart';
$params['timestart'] = (int)$timestart;
}
if (!empty($timeend)) {
$updatesql[] = 'timeend = :timeend';
$params['timeend'] = (int)$timeend;
}
if (empty($updatesql)) {
return true;
}
// Update the modifierid.
$updatesql[] = 'modifierid = :modifierid';
$params['modifierid'] = (int)$USER->id;
// Update the time modified.
$updatesql[] = 'timemodified = :timemodified';
$params['timemodified'] = time();
// Build the SQL statement.
$updatesql = join(', ', $updatesql);
$sql = "UPDATE {user_enrolments}
SET $updatesql
WHERE id $ueidsql";
if ($DB->execute($sql, $params)) {
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$enrolment->courseid = $enrolment->enrolmentinstance->courseid;
$enrolment->enrol = 'self';
// Trigger event.
$event = \core\event\user_enrolment_updated::create(
array(
'objectid' => $enrolment->id,
'courseid' => $enrolment->courseid,
'context' => context_course::instance($enrolment->courseid),
'relateduserid' => $user->id,
'other' => array('enrol' => 'self')
)
);
$event->trigger();
}
}
// Delete cached course contacts for this course because they may be affected.
cache::make('core', 'coursecontacts')->delete($manager->get_context()->instanceid);
return true;
}
return false;
}
/**
* Returns a enrol_bulk_enrolment_operation extension form to be used
* in collecting required information for this operation to be processed.
*
* @param string|moodle_url|null $defaultaction
* @param mixed $defaultcustomdata
* @return enrol_self_editselectedusers_form
*/
public function get_form($defaultaction = null, $defaultcustomdata = null) {
return new enrol_self_editselectedusers_form($defaultaction, $defaultcustomdata);
}
}
+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/>.
/**
* Empty enrol_self form.
*
* Useful to mimic valid enrol instances UI when the enrolment instance is not available.
*
* @package enrol_self
* @copyright 2015 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
class enrol_self_empty_form extends moodleform {
/**
* Form definition.
* @return void
*/
public function definition() {
$this->_form->addElement('header', 'selfheader', $this->_customdata->header);
$this->_form->addElement('static', 'info', '', $this->_customdata->info);
}
}
+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_self.
*
* @package enrol_self
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_self\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for enrol_self 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';
}
}
@@ -0,0 +1,58 @@
<?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/>.
/**
* Send expiry notifications task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_self\task;
defined('MOODLE_INTERNAL') || die();
/**
* Send expiry notifications task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send_expiry_notifications extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('sendexpirynotificationstask', 'enrol_self');
}
/**
* Run task for sending expiry notifications.
*/
public function execute() {
$enrol = enrol_get_plugin('self');
$trace = new \text_progress_trace();
$enrol->send_expiry_notifications($trace);
}
}
@@ -0,0 +1,58 @@
<?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/>.
/**
* Sync enrolments task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_self\task;
defined('MOODLE_INTERNAL') || die();
/**
* Sync enrolments task.
*
* @package enrol_self
* @author Farhan Karmali <farhan6318@gmail.com>
* @copyright Farhan Karmali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sync_enrolments extends \core\task\scheduled_task {
/**
* Name for this task.
*
* @return string
*/
public function get_name() {
return get_string('syncenrolmentstask', 'enrol_self');
}
/**
* Run task for syncing enrolments.
*/
public function execute() {
$enrol = enrol_get_plugin('self');
$trace = new \text_progress_trace();
$enrol->sync($trace);
}
}
@@ -0,0 +1,46 @@
<?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_self;
/**
* Hook callbacks to get the enrolment information.
*
* @package enrol_self
* @copyright 2024 Huong Nguyen <huongnv13@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_enrolment_callbacks {
/**
* Callback for the user_enrolment hook.
*
* @param \core_enrol\hook\after_user_enrolled $hook
*/
public static function send_course_welcome_message(\core_enrol\hook\after_user_enrolled $hook): void {
$instance = $hook->get_enrolinstance();
// Send welcome message.
if ($instance->enrol == 'self' && $instance->customint4 && $instance->customint4 !== ENROL_DO_NOT_SEND_EMAIL) {
$plugin = enrol_get_plugin($instance->enrol);
$plugin->send_course_welcome_message_to_user(
instance: $instance,
userid: $hook->get_userid(),
sendoption: $instance->customint4,
message: $instance->customtext1,
);
}
}
}