MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
<?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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This library includes the basic parts of enrol api.
|
|
|
|
* It is available on each page.
|
|
|
|
*
|
2010-07-25 13:35:05 +00:00
|
|
|
* @package core
|
|
|
|
* @subpackage enrol
|
|
|
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
|
2010-07-25 13:35:05 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
/** Course enrol instance enabled. (used in enrol->status) */
|
|
|
|
define('ENROL_INSTANCE_ENABLED', 0);
|
|
|
|
|
|
|
|
/** Course enrol instance disabled, user may enter course if other enrol instance enabled. (used in enrol->status)*/
|
|
|
|
define('ENROL_INSTANCE_DISABLED', 1);
|
|
|
|
|
|
|
|
/** User is active participant (used in user_enrolments->status)*/
|
|
|
|
define('ENROL_USER_ACTIVE', 0);
|
|
|
|
|
|
|
|
/** User participation in course is suspended (used in user_enrolments->status) */
|
|
|
|
define('ENROL_USER_SUSPENDED', 1);
|
|
|
|
|
2011-11-05 12:12:48 +01:00
|
|
|
/** @deprecated - enrol caching was reworked, use ENROL_MAX_TIMESTAMP instead */
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
define('ENROL_REQUIRE_LOGIN_CACHE_PERIOD', 1800);
|
|
|
|
|
2011-11-05 12:12:48 +01:00
|
|
|
/** The timestamp indicating forever */
|
|
|
|
define('ENROL_MAX_TIMESTAMP', 2147483647);
|
|
|
|
|
2010-07-08 10:57:23 +00:00
|
|
|
/** When user disappears from external source, the enrolment is completely removed */
|
|
|
|
define('ENROL_EXT_REMOVED_UNENROL', 0);
|
|
|
|
|
|
|
|
/** When user disappears from external source, the enrolment is kept as is - one way sync */
|
|
|
|
define('ENROL_EXT_REMOVED_KEEP', 1);
|
|
|
|
|
2012-08-31 14:15:04 +02:00
|
|
|
/** @deprecated since 2.4 not used any more, migrate plugin to new restore methods */
|
2010-09-21 10:42:19 +00:00
|
|
|
define('ENROL_RESTORE_TYPE', 'enrolrestore');
|
|
|
|
|
2010-07-08 10:57:23 +00:00
|
|
|
/**
|
|
|
|
* When user disappears from external source, user enrolment is suspended, roles are kept as is.
|
|
|
|
* In some cases user needs a role with some capability to be visible in UI - suc has in gradebook,
|
|
|
|
* assignments, etc.
|
|
|
|
*/
|
|
|
|
define('ENROL_EXT_REMOVED_SUSPEND', 2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When user disappears from external source, the enrolment is suspended and roles assigned
|
|
|
|
* by enrol instance are removed. Please note that user may "disappear" from gradebook and other areas.
|
|
|
|
* */
|
|
|
|
define('ENROL_EXT_REMOVED_SUSPENDNOROLES', 3);
|
|
|
|
|
2016-10-26 09:34:44 +08:00
|
|
|
/**
|
|
|
|
* Do not send email.
|
|
|
|
*/
|
|
|
|
define('ENROL_DO_NOT_SEND_EMAIL', 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send email from course contact.
|
|
|
|
*/
|
|
|
|
define('ENROL_SEND_EMAIL_FROM_COURSE_CONTACT', 1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send email from enrolment key holder.
|
|
|
|
*/
|
|
|
|
define('ENROL_SEND_EMAIL_FROM_KEY_HOLDER', 2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send email from no reply address.
|
|
|
|
*/
|
|
|
|
define('ENROL_SEND_EMAIL_FROM_NOREPLY', 3);
|
|
|
|
|
2017-07-18 11:55:31 +08:00
|
|
|
/** Edit enrolment action. */
|
|
|
|
define('ENROL_ACTION_EDIT', 'editenrolment');
|
|
|
|
|
|
|
|
/** Unenrol action. */
|
|
|
|
define('ENROL_ACTION_UNENROL', 'unenrol');
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Returns instances of enrol plugins
|
2011-11-05 12:12:48 +01:00
|
|
|
* @param bool $enabled return enabled only
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @return array of enrol plugins name=>instance
|
|
|
|
*/
|
|
|
|
function enrol_get_plugins($enabled) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
if ($enabled) {
|
|
|
|
// sorted by enabled plugin order
|
|
|
|
$enabled = explode(',', $CFG->enrol_plugins_enabled);
|
|
|
|
$plugins = array();
|
|
|
|
foreach ($enabled as $plugin) {
|
|
|
|
$plugins[$plugin] = "$CFG->dirroot/enrol/$plugin";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// sorted alphabetically
|
2013-07-16 22:36:11 +02:00
|
|
|
$plugins = core_component::get_plugin_list('enrol');
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
ksort($plugins);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($plugins as $plugin=>$location) {
|
|
|
|
$class = "enrol_{$plugin}_plugin";
|
|
|
|
if (!class_exists($class)) {
|
2014-03-13 09:16:01 +00:00
|
|
|
if (!file_exists("$location/lib.php")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
include_once("$location/lib.php");
|
|
|
|
if (!class_exists($class)) {
|
|
|
|
continue;
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$result[$plugin] = new $class();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns instance of enrol plugin
|
|
|
|
* @param string $name name of enrol plugin ('manual', 'guest', ...)
|
2024-02-05 15:20:28 +00:00
|
|
|
* @return ?enrol_plugin
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
function enrol_get_plugin($name) {
|
|
|
|
global $CFG;
|
|
|
|
|
2011-09-24 15:07:27 +02:00
|
|
|
$name = clean_param($name, PARAM_PLUGIN);
|
|
|
|
|
|
|
|
if (empty($name)) {
|
|
|
|
// ignore malformed or missing plugin names completely
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$location = "$CFG->dirroot/enrol/$name";
|
|
|
|
|
|
|
|
$class = "enrol_{$name}_plugin";
|
|
|
|
if (!class_exists($class)) {
|
2016-11-15 12:22:54 +00:00
|
|
|
if (!file_exists("$location/lib.php")) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
include_once("$location/lib.php");
|
|
|
|
if (!class_exists($class)) {
|
|
|
|
return null;
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new $class();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns enrolment instances in given course.
|
|
|
|
* @param int $courseid
|
|
|
|
* @param bool $enabled
|
|
|
|
* @return array of enrol instances
|
|
|
|
*/
|
|
|
|
function enrol_get_instances($courseid, $enabled) {
|
|
|
|
global $DB, $CFG;
|
|
|
|
|
|
|
|
if (!$enabled) {
|
|
|
|
return $DB->get_records('enrol', array('courseid'=>$courseid), 'sortorder,id');
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $DB->get_records('enrol', array('courseid'=>$courseid, 'status'=>ENROL_INSTANCE_ENABLED), 'sortorder,id');
|
|
|
|
|
2010-06-21 22:01:11 +00:00
|
|
|
$enabled = explode(',', $CFG->enrol_plugins_enabled);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
foreach ($result as $key=>$instance) {
|
|
|
|
if (!in_array($instance->enrol, $enabled)) {
|
|
|
|
unset($result[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!file_exists("$CFG->dirroot/enrol/$instance->enrol/lib.php")) {
|
|
|
|
// broken plugin
|
|
|
|
unset($result[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a given plugin is in the list of enabled enrolment plugins.
|
|
|
|
*
|
|
|
|
* @param string $enrol Enrolment plugin name
|
|
|
|
* @return boolean Whether the plugin is enabled
|
|
|
|
*/
|
|
|
|
function enrol_is_enabled($enrol) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (empty($CFG->enrol_plugins_enabled)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return in_array($enrol, explode(',', $CFG->enrol_plugins_enabled));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check all the login enrolment information for the given user object
|
|
|
|
* by querying the enrolment plugins
|
2011-10-14 12:48:00 +02:00
|
|
|
* This function may be very slow, use only once after log-in or login-as.
|
|
|
|
*
|
2021-12-22 11:54:42 +11:00
|
|
|
* @param stdClass $user User object.
|
|
|
|
* @param bool $ignoreintervalcheck Force to ignore checking configured sync intervals.
|
|
|
|
*
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-12-22 11:54:42 +11:00
|
|
|
function enrol_check_plugins($user, bool $ignoreintervalcheck = true) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (empty($user->id) or isguestuser($user)) {
|
|
|
|
// shortcut - there is no enrolment work for guests and not-logged-in users
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-09 19:59:19 +02:00
|
|
|
// originally there was a broken admin test, but accidentally it was non-functional in 2.2,
|
|
|
|
// which proved it was actually not necessary.
|
2010-07-10 18:53:52 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
static $inprogress = array(); // To prevent this function being called more than once in an invocation
|
|
|
|
|
|
|
|
if (!empty($inprogress[$user->id])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-22 11:54:42 +11:00
|
|
|
$syncinterval = isset($CFG->enrolments_sync_interval) ? (int)$CFG->enrolments_sync_interval : HOURSECS;
|
|
|
|
$needintervalchecking = !$ignoreintervalcheck && !empty($syncinterval);
|
|
|
|
|
|
|
|
if ($needintervalchecking) {
|
|
|
|
$lastsync = get_user_preferences('last_time_enrolments_synced', 0, $user);
|
|
|
|
if (time() - $lastsync < $syncinterval) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$inprogress[$user->id] = true; // Set the flag
|
|
|
|
|
|
|
|
$enabled = enrol_get_plugins(true);
|
|
|
|
|
|
|
|
foreach($enabled as $enrol) {
|
|
|
|
$enrol->sync_user_enrolments($user);
|
|
|
|
}
|
|
|
|
|
2021-12-22 11:54:42 +11:00
|
|
|
if ($needintervalchecking) {
|
|
|
|
set_user_preference('last_time_enrolments_synced', time(), $user);
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
unset($inprogress[$user->id]); // Unset the flag
|
|
|
|
}
|
|
|
|
|
2011-03-12 19:04:26 +01:00
|
|
|
/**
|
|
|
|
* Do these two students share any course?
|
|
|
|
*
|
|
|
|
* The courses has to be visible and enrolments has to be active,
|
|
|
|
* timestart and timeend restrictions are ignored.
|
|
|
|
*
|
2011-10-03 11:23:30 +13:00
|
|
|
* This function calls {@see enrol_get_shared_courses()} setting checkexistsonly
|
|
|
|
* to true.
|
|
|
|
*
|
2011-03-12 19:04:26 +01:00
|
|
|
* @param stdClass|int $user1
|
|
|
|
* @param stdClass|int $user2
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function enrol_sharing_course($user1, $user2) {
|
2011-10-03 11:23:30 +13:00
|
|
|
return enrol_get_shared_courses($user1, $user2, false, true);
|
2011-03-12 19:04:26 +01:00
|
|
|
}
|
|
|
|
|
2011-09-08 16:17:12 +12:00
|
|
|
/**
|
|
|
|
* Returns any courses shared by the two users
|
|
|
|
*
|
|
|
|
* The courses has to be visible and enrolments has to be active,
|
|
|
|
* timestart and timeend restrictions are ignored.
|
|
|
|
*
|
2011-10-03 11:23:30 +13:00
|
|
|
* @global moodle_database $DB
|
2011-09-08 16:17:12 +12:00
|
|
|
* @param stdClass|int $user1
|
|
|
|
* @param stdClass|int $user2
|
2011-10-03 11:23:30 +13:00
|
|
|
* @param bool $preloadcontexts If set to true contexts for the returned courses
|
|
|
|
* will be preloaded.
|
|
|
|
* @param bool $checkexistsonly If set to true then this function will return true
|
|
|
|
* if the users share any courses and false if not.
|
|
|
|
* @return array|bool An array of courses that both users are enrolled in OR if
|
|
|
|
* $checkexistsonly set returns true if the users share any courses
|
|
|
|
* and false if not.
|
2011-09-08 16:17:12 +12:00
|
|
|
*/
|
2011-10-03 11:23:30 +13:00
|
|
|
function enrol_get_shared_courses($user1, $user2, $preloadcontexts = false, $checkexistsonly = false) {
|
2011-09-08 16:17:12 +12:00
|
|
|
global $DB, $CFG;
|
|
|
|
|
2012-04-09 19:03:45 +02:00
|
|
|
$user1 = isset($user1->id) ? $user1->id : $user1;
|
|
|
|
$user2 = isset($user2->id) ? $user2->id : $user2;
|
2011-09-08 16:17:12 +12:00
|
|
|
|
|
|
|
if (empty($user1) or empty($user2)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$plugins = explode(',', $CFG->enrol_plugins_enabled)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-18 13:28:08 +02:00
|
|
|
list($plugins1, $params1) = $DB->get_in_or_equal($plugins, SQL_PARAMS_NAMED, 'ee1');
|
|
|
|
list($plugins2, $params2) = $DB->get_in_or_equal($plugins, SQL_PARAMS_NAMED, 'ee2');
|
|
|
|
$params = array_merge($params1, $params2);
|
|
|
|
$params['enabled1'] = ENROL_INSTANCE_ENABLED;
|
|
|
|
$params['enabled2'] = ENROL_INSTANCE_ENABLED;
|
2011-09-08 16:17:12 +12:00
|
|
|
$params['active1'] = ENROL_USER_ACTIVE;
|
|
|
|
$params['active2'] = ENROL_USER_ACTIVE;
|
|
|
|
$params['user1'] = $user1;
|
|
|
|
$params['user2'] = $user2;
|
|
|
|
|
|
|
|
$ctxselect = '';
|
|
|
|
$ctxjoin = '';
|
|
|
|
if ($preloadcontexts) {
|
2013-07-05 13:02:00 +08:00
|
|
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
|
|
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
|
|
|
$params['contextlevel'] = CONTEXT_COURSE;
|
2011-09-08 16:17:12 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT c.* $ctxselect
|
|
|
|
FROM {course} c
|
|
|
|
JOIN (
|
|
|
|
SELECT DISTINCT c.id
|
2017-04-18 13:28:08 +02:00
|
|
|
FROM {course} c
|
|
|
|
JOIN {enrol} e1 ON (c.id = e1.courseid AND e1.status = :enabled1 AND e1.enrol $plugins1)
|
|
|
|
JOIN {user_enrolments} ue1 ON (ue1.enrolid = e1.id AND ue1.status = :active1 AND ue1.userid = :user1)
|
|
|
|
JOIN {enrol} e2 ON (c.id = e2.courseid AND e2.status = :enabled2 AND e2.enrol $plugins2)
|
|
|
|
JOIN {user_enrolments} ue2 ON (ue2.enrolid = e2.id AND ue2.status = :active2 AND ue2.userid = :user2)
|
|
|
|
WHERE c.visible = 1
|
2011-09-08 16:17:12 +12:00
|
|
|
) ec ON ec.id = c.id
|
|
|
|
$ctxjoin";
|
|
|
|
|
2011-10-03 11:23:30 +13:00
|
|
|
if ($checkexistsonly) {
|
|
|
|
return $DB->record_exists_sql($sql, $params);
|
|
|
|
} else {
|
|
|
|
$courses = $DB->get_records_sql($sql, $params);
|
|
|
|
if ($preloadcontexts) {
|
2013-08-14 17:30:00 +08:00
|
|
|
array_map('context_helper::preload_from_record', $courses);
|
2011-10-03 11:23:30 +13:00
|
|
|
}
|
|
|
|
return $courses;
|
|
|
|
}
|
2011-09-08 16:17:12 +12:00
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* This function adds necessary enrol plugins UI into the course edit form.
|
|
|
|
*
|
|
|
|
* @param MoodleQuickForm $mform
|
|
|
|
* @param object $data course edit form data
|
|
|
|
* @param object $context context of existing course or parent category if course does not exist
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function enrol_course_edit_form(MoodleQuickForm $mform, $data, $context) {
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
if (!empty($data->id)) {
|
|
|
|
$instances = enrol_get_instances($data->id, false);
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$plugin = $plugins[$instance->enrol];
|
|
|
|
$plugin->course_edit_form($instance, $mform, $data, $context);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach ($plugins as $plugin) {
|
|
|
|
$plugin->course_edit_form(NULL, $mform, $data, $context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate course edit form data
|
|
|
|
*
|
|
|
|
* @param array $data raw form data
|
|
|
|
* @param object $context context of existing course or parent category if course does not exist
|
|
|
|
* @return array errors array
|
|
|
|
*/
|
|
|
|
function enrol_course_edit_validation(array $data, $context) {
|
|
|
|
$errors = array();
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
|
|
|
|
if (!empty($data['id'])) {
|
|
|
|
$instances = enrol_get_instances($data['id'], false);
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$plugin = $plugins[$instance->enrol];
|
|
|
|
$errors = array_merge($errors, $plugin->course_edit_validation($instance, $data, $context));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach ($plugins as $plugin) {
|
|
|
|
$errors = array_merge($errors, $plugin->course_edit_validation(NULL, $data, $context));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update enrol instances after course edit form submission
|
|
|
|
* @param bool $inserted true means new course added, false course already existed
|
|
|
|
* @param object $course
|
|
|
|
* @param object $data form data
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function enrol_course_updated($inserted, $course, $data) {
|
|
|
|
global $DB, $CFG;
|
|
|
|
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
|
|
|
|
foreach ($plugins as $plugin) {
|
|
|
|
$plugin->course_updated($inserted, $course, $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add navigation nodes
|
|
|
|
* @param navigation_node $coursenode
|
|
|
|
* @param object $course
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function enrol_add_course_navigation(navigation_node $coursenode, $course) {
|
2010-09-18 11:32:28 +00:00
|
|
|
global $CFG;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2012-07-25 16:25:55 +08:00
|
|
|
$coursecontext = context_course::instance($course->id);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
$instances = enrol_get_instances($course->id, true);
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
|
|
|
|
// we do not want to break all course pages if there is some borked enrol plugin, right?
|
|
|
|
foreach ($instances as $k=>$instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
unset($instances[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-12 06:18:08 +00:00
|
|
|
$usersnode = $coursenode->add(get_string('users'), null, navigation_node::TYPE_CONTAINER, null, 'users');
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2021-11-01 14:33:59 +08:00
|
|
|
// List all participants - allows assigning roles, groups, etc.
|
|
|
|
// Have this available even in the site context as the page is still accessible from the frontpage.
|
|
|
|
if (has_capability('moodle/course:enrolreview', $coursecontext)) {
|
|
|
|
$url = new moodle_url('/user/index.php', array('id' => $course->id));
|
|
|
|
$usersnode->add(get_string('enrolledusers', 'enrol'), $url, navigation_node::TYPE_SETTING,
|
|
|
|
null, 'review', new pix_icon('i/enrolusers', ''));
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2021-11-01 14:33:59 +08:00
|
|
|
if ($course->id != SITEID) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
// manage enrol plugin instances
|
|
|
|
if (has_capability('moodle/course:enrolconfig', $coursecontext) or has_capability('moodle/course:enrolreview', $coursecontext)) {
|
|
|
|
$url = new moodle_url('/enrol/instances.php', array('id'=>$course->id));
|
|
|
|
} else {
|
|
|
|
$url = NULL;
|
|
|
|
}
|
2010-07-12 06:18:08 +00:00
|
|
|
$instancesnode = $usersnode->add(get_string('enrolmentinstances', 'enrol'), $url, navigation_node::TYPE_SETTING, null, 'manageinstances');
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
// each instance decides how to configure itself or how many other nav items are exposed
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$plugins[$instance->enrol]->add_course_navigation($instancesnode, $instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$url) {
|
|
|
|
$instancesnode->trim_if_empty();
|
|
|
|
}
|
2023-05-04 16:14:41 +02:00
|
|
|
|
|
|
|
if (has_capability('moodle/course:renameroles', $coursecontext)) {
|
|
|
|
$url = new moodle_url('/enrol/renameroles.php', array('id' => $course->id));
|
|
|
|
$instancesnode->add(
|
|
|
|
get_string('rolerenaming'),
|
|
|
|
$url,
|
|
|
|
navigation_node::TYPE_SETTING,
|
|
|
|
null,
|
|
|
|
'renameroles'
|
|
|
|
);
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Manage groups in this course or even frontpage
|
|
|
|
if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $coursecontext)) {
|
|
|
|
$url = new moodle_url('/group/index.php', array('id'=>$course->id));
|
|
|
|
$usersnode->add(get_string('groups'), $url, navigation_node::TYPE_SETTING, null, 'groups', new pix_icon('i/group', ''));
|
|
|
|
}
|
|
|
|
|
2023-05-04 16:14:41 +02:00
|
|
|
if (has_any_capability(
|
|
|
|
[ 'moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:review'],
|
|
|
|
$coursecontext
|
|
|
|
)) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
// Override roles
|
|
|
|
if (has_capability('moodle/role:review', $coursecontext)) {
|
|
|
|
$url = new moodle_url('/admin/roles/permissions.php', array('contextid'=>$coursecontext->id));
|
|
|
|
} else {
|
|
|
|
$url = NULL;
|
|
|
|
}
|
2010-07-12 06:18:08 +00:00
|
|
|
$permissionsnode = $usersnode->add(get_string('permissions', 'role'), $url, navigation_node::TYPE_SETTING, null, 'override');
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
// Add assign or override roles if allowed
|
|
|
|
if ($course->id == SITEID or (!empty($CFG->adminsassignrolesincourse) and is_siteadmin())) {
|
|
|
|
if (has_capability('moodle/role:assign', $coursecontext)) {
|
|
|
|
$url = new moodle_url('/admin/roles/assign.php', array('contextid'=>$coursecontext->id));
|
2012-11-13 16:48:50 +08:00
|
|
|
$permissionsnode->add(get_string('assignedroles', 'role'), $url, navigation_node::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', ''));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check role permissions
|
2015-10-29 10:43:23 +05:30
|
|
|
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override'), $coursecontext)) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$url = new moodle_url('/admin/roles/check.php', array('contextid'=>$coursecontext->id));
|
2010-07-12 06:18:08 +00:00
|
|
|
$permissionsnode->add(get_string('checkpermissions', 'role'), $url, navigation_node::TYPE_SETTING, null, 'permissions', new pix_icon('i/checkpermissions', ''));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
2023-05-04 16:14:41 +02:00
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
// Deal somehow with users that are not enrolled but still got a role somehow
|
|
|
|
if ($course->id != SITEID) {
|
|
|
|
//TODO, create some new UI for role assignments at course level
|
2014-03-26 10:17:23 -04:00
|
|
|
if (has_capability('moodle/course:reviewotherusers', $coursecontext)) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$url = new moodle_url('/enrol/otherusers.php', array('id'=>$course->id));
|
2012-11-13 16:48:50 +08:00
|
|
|
$usersnode->add(get_string('notenrolledusers', 'enrol'), $url, navigation_node::TYPE_SETTING, null, 'otherusers', new pix_icon('i/assignroles', ''));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// just in case nothing was actually added
|
|
|
|
$usersnode->trim_if_empty();
|
|
|
|
|
|
|
|
if ($course->id != SITEID) {
|
2012-03-10 09:40:42 +01:00
|
|
|
if (isguestuser() or !isloggedin()) {
|
2012-03-12 16:47:28 +01:00
|
|
|
// guest account can not be enrolled - no links for them
|
2012-03-10 09:40:42 +01:00
|
|
|
} else if (is_enrolled($coursecontext)) {
|
2012-03-12 16:47:28 +01:00
|
|
|
// unenrol link if possible
|
2010-07-13 17:04:17 +00:00
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$plugin = $plugins[$instance->enrol];
|
|
|
|
if ($unenrollink = $plugin->get_unenrolself_link($instance)) {
|
2023-02-10 11:10:15 +11:00
|
|
|
$coursenode->add(get_string('unenrolme', 'core_enrol'), $unenrollink,
|
|
|
|
navigation_node::TYPE_SETTING, null, 'unenrolself', new pix_icon('i/user', ''));
|
2022-03-21 13:46:42 +08:00
|
|
|
$coursenode->get('unenrolself')->set_force_into_more_menu(true);
|
2010-07-13 17:04:17 +00:00
|
|
|
break;
|
|
|
|
//TODO. deal with multiple unenrol links - not likely case, but still...
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
2010-07-13 17:04:17 +00:00
|
|
|
} else {
|
2012-03-12 16:47:28 +01:00
|
|
|
// enrol link if possible
|
2010-07-13 17:04:17 +00:00
|
|
|
if (is_viewing($coursecontext)) {
|
|
|
|
// better not show any enrol link, this is intended for managers and inspectors
|
|
|
|
} else {
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$plugin = $plugins[$instance->enrol];
|
|
|
|
if ($plugin->show_enrolme_link($instance)) {
|
|
|
|
$url = new moodle_url('/enrol/index.php', array('id'=>$course->id));
|
2011-09-07 11:46:28 +12:00
|
|
|
$shortname = format_string($course->shortname, true, array('context' => $coursecontext));
|
|
|
|
$coursenode->add(get_string('enrolme', 'core_enrol', $shortname), $url, navigation_node::TYPE_SETTING, null, 'enrolself', new pix_icon('i/user', ''));
|
2010-07-13 17:04:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns list of courses current $USER is enrolled in and can access
|
|
|
|
*
|
2017-12-05 21:53:55 +01:00
|
|
|
* The $fields param is a list of field names to ADD so name just the fields you really need,
|
|
|
|
* which will be added and uniq'd.
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*
|
2017-08-21 17:15:30 +01:00
|
|
|
* If $allaccessible is true, this will additionally return courses that the current user is not
|
|
|
|
* enrolled in, but can access because they are open to the user for other reasons (course view
|
|
|
|
* permission, currently viewing course as a guest, or course allows guest access without
|
|
|
|
* password).
|
|
|
|
*
|
2017-12-05 21:53:55 +01:00
|
|
|
* @param string|array $fields Extra fields to be returned (array or comma-separated list).
|
|
|
|
* @param string|null $sort Comma separated list of fields to sort by, defaults to respecting navsortmycoursessort.
|
2018-10-15 08:42:08 +02:00
|
|
|
* Allowed prefixes for sort fields are: "ul" for the user_lastaccess table, "c" for the courses table,
|
|
|
|
* "ue" for the user_enrolments table.
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @param int $limit max number of courses
|
2017-02-28 03:02:03 +00:00
|
|
|
* @param array $courseids the list of course ids to filter by
|
2017-08-21 17:15:30 +01:00
|
|
|
* @param bool $allaccessible Include courses user is not enrolled in, but can access
|
2018-08-27 16:43:56 +08:00
|
|
|
* @param int $offset Offset the result set by this number
|
2018-10-26 12:37:31 +08:00
|
|
|
* @param array $excludecourses IDs of hidden courses to exclude from search
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-10-26 12:37:31 +08:00
|
|
|
function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $courseids = [], $allaccessible = false,
|
|
|
|
$offset = 0, $excludecourses = []) {
|
2017-12-05 21:53:55 +01:00
|
|
|
global $DB, $USER, $CFG;
|
2017-11-22 16:13:03 +11:00
|
|
|
|
2021-05-10 17:20:05 +05:30
|
|
|
// Allowed prefixes and field names.
|
|
|
|
$allowedprefixesandfields = ['c' => array_keys($DB->get_columns('course')),
|
|
|
|
'ul' => array_keys($DB->get_columns('user_lastaccess')),
|
|
|
|
'ue' => array_keys($DB->get_columns('user_enrolments'))];
|
|
|
|
|
2019-09-02 14:17:40 +02:00
|
|
|
// Re-Arrange the course sorting according to the admin settings.
|
|
|
|
$sort = enrol_get_courses_sortingsql($sort);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2017-08-21 17:15:30 +01:00
|
|
|
// Guest account does not have any enrolled courses.
|
|
|
|
if (!$allaccessible && (isguestuser() or !isloggedin())) {
|
|
|
|
return array();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 20:41:53 +10:00
|
|
|
$basefields = [
|
|
|
|
'id', 'category', 'sortorder',
|
|
|
|
'shortname', 'fullname', 'idnumber',
|
|
|
|
'startdate', 'visible',
|
|
|
|
'groupmode', 'groupmodeforce', 'cacherev',
|
|
|
|
'showactivitydates', 'showcompletionconditions',
|
|
|
|
];
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
if (empty($fields)) {
|
|
|
|
$fields = $basefields;
|
|
|
|
} else if (is_string($fields)) {
|
|
|
|
// turn the fields from a string to an array
|
|
|
|
$fields = explode(',', $fields);
|
|
|
|
$fields = array_map('trim', $fields);
|
|
|
|
$fields = array_unique(array_merge($basefields, $fields));
|
|
|
|
} else if (is_array($fields)) {
|
|
|
|
$fields = array_unique(array_merge($basefields, $fields));
|
|
|
|
} else {
|
2017-12-05 21:59:04 +01:00
|
|
|
throw new coding_exception('Invalid $fields parameter in enrol_get_my_courses()');
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
if (in_array('*', $fields)) {
|
|
|
|
$fields = array('*');
|
|
|
|
}
|
|
|
|
|
|
|
|
$orderby = "";
|
|
|
|
$sort = trim($sort);
|
2018-10-15 08:42:08 +02:00
|
|
|
$sorttimeaccess = false;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if (!empty($sort)) {
|
|
|
|
$rawsorts = explode(',', $sort);
|
|
|
|
$sorts = array();
|
|
|
|
foreach ($rawsorts as $rawsort) {
|
|
|
|
$rawsort = trim($rawsort);
|
2021-05-10 17:20:05 +05:30
|
|
|
// Make sure that there are no more white spaces in sortparams after explode.
|
|
|
|
$sortparams = array_values(array_filter(explode(' ', $rawsort)));
|
|
|
|
// If more than 2 values present then throw coding_exception.
|
|
|
|
if (isset($sortparams[2])) {
|
|
|
|
throw new coding_exception('Invalid $sort parameter in enrol_get_my_courses()');
|
|
|
|
}
|
|
|
|
// Check the sort ordering if present, at the beginning.
|
|
|
|
if (isset($sortparams[1]) && (preg_match("/^(asc|desc)$/i", $sortparams[1]) === 0)) {
|
|
|
|
throw new coding_exception('Invalid sort direction in $sort parameter in enrol_get_my_courses()');
|
|
|
|
}
|
|
|
|
|
|
|
|
$sortfield = $sortparams[0];
|
|
|
|
$sortdirection = $sortparams[1] ?? 'asc';
|
|
|
|
if (strpos($sortfield, '.') !== false) {
|
|
|
|
$sortfieldparams = explode('.', $sortfield);
|
|
|
|
// Check if more than one dots present in the prefix field.
|
|
|
|
if (isset($sortfieldparams[2])) {
|
|
|
|
throw new coding_exception('Invalid $sort parameter in enrol_get_my_courses()');
|
2018-10-15 08:42:08 +02:00
|
|
|
}
|
2021-05-10 17:20:05 +05:30
|
|
|
list($prefix, $fieldname) = [$sortfieldparams[0], $sortfieldparams[1]];
|
|
|
|
// Check if the field name matches with the allowed prefix.
|
|
|
|
if (array_key_exists($prefix, $allowedprefixesandfields) &&
|
|
|
|
(in_array($fieldname, $allowedprefixesandfields[$prefix]))) {
|
|
|
|
if ($prefix === 'ul') {
|
|
|
|
$sorts[] = "COALESCE({$prefix}.{$fieldname}, 0) {$sortdirection}";
|
|
|
|
$sorttimeaccess = true;
|
|
|
|
} else {
|
|
|
|
// Check if the field name that matches with the prefix and just append to sorts.
|
|
|
|
$sorts[] = $rawsort;
|
|
|
|
}
|
2018-10-15 08:42:08 +02:00
|
|
|
} else {
|
|
|
|
throw new coding_exception('Invalid $sort parameter in enrol_get_my_courses()');
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-10 17:20:05 +05:30
|
|
|
// Check if the field name matches with $allowedprefixesandfields.
|
|
|
|
$found = false;
|
|
|
|
foreach (array_keys($allowedprefixesandfields) as $prefix) {
|
|
|
|
if (in_array($sortfield, $allowedprefixesandfields[$prefix])) {
|
|
|
|
if ($prefix === 'ul') {
|
|
|
|
$sorts[] = "COALESCE({$prefix}.{$sortfield}, 0) {$sortdirection}";
|
|
|
|
$sorttimeaccess = true;
|
|
|
|
} else {
|
|
|
|
$sorts[] = "{$prefix}.{$sortfield} {$sortdirection}";
|
|
|
|
}
|
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
// The param is not found in $allowedprefixesandfields.
|
|
|
|
throw new coding_exception('Invalid $sort parameter in enrol_get_my_courses()');
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-15 08:42:08 +02:00
|
|
|
$sort = implode(',', $sorts);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$orderby = "ORDER BY $sort";
|
|
|
|
}
|
|
|
|
|
MDL-75208 oracle: Amend a couple of queries to make Oracle happy
The changes introduced here are completely safe, just we stop
binding SITEID and, instead, embed it in the SQL.
Why? Because Oracle 21 has started to return non-sense results
when SITEID is bound.
After lots of tests, attempts, debugging... we have been unable
to find any logic to the need of this change and also, have been
unable to reproduce the problem with a standalone script that
pretty much runs the same queries that the ones changed here.
I'm sure that there is something, somewhere, but have failed
to find it, grrr.
Please read MDL-75208 and linked issues to find more information
about this problem, that is one of the biggest mysteries I've
seen recently. Maybe at the end there is a tiny detail that
explains it all, but it's really well hidden.
2022-07-13 23:44:16 +02:00
|
|
|
$wheres = ['c.id <> ' . SITEID];
|
|
|
|
$params = [];
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
if (isset($USER->loginascontext) and $USER->loginascontext->contextlevel == CONTEXT_COURSE) {
|
|
|
|
// list _only_ this course - anything else is asking for trouble...
|
|
|
|
$wheres[] = "courseid = :loginas";
|
|
|
|
$params['loginas'] = $USER->loginascontext->instanceid;
|
|
|
|
}
|
|
|
|
|
|
|
|
$coursefields = 'c.' .join(',c.', $fields);
|
2013-07-05 13:02:00 +08:00
|
|
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
|
|
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
|
|
|
$params['contextlevel'] = CONTEXT_COURSE;
|
2010-07-01 07:40:24 +00:00
|
|
|
$wheres = implode(" AND ", $wheres);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2018-10-15 08:42:08 +02:00
|
|
|
$timeaccessselect = "";
|
|
|
|
$timeaccessjoin = "";
|
|
|
|
|
2017-02-28 03:02:03 +00:00
|
|
|
if (!empty($courseids)) {
|
|
|
|
list($courseidssql, $courseidsparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
|
|
|
|
$wheres = sprintf("%s AND c.id %s", $wheres, $courseidssql);
|
2018-10-26 12:37:31 +08:00
|
|
|
$params = array_merge($params, $courseidsparams);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($excludecourses)) {
|
|
|
|
list($courseidssql, $courseidsparams) = $DB->get_in_or_equal($excludecourses, SQL_PARAMS_NAMED, 'param', false);
|
|
|
|
$wheres = sprintf("%s AND c.id %s", $wheres, $courseidssql);
|
2017-02-28 03:02:03 +00:00
|
|
|
$params = array_merge($params, $courseidsparams);
|
|
|
|
}
|
|
|
|
|
2017-08-21 17:15:30 +01:00
|
|
|
$courseidsql = "";
|
|
|
|
// Logged-in, non-guest users get their enrolled courses.
|
|
|
|
if (!isguestuser() && isloggedin()) {
|
|
|
|
$courseidsql .= "
|
|
|
|
SELECT DISTINCT e.courseid
|
|
|
|
FROM {enrol} e
|
2018-10-15 08:42:08 +02:00
|
|
|
JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid1)
|
2020-11-03 08:16:07 +00:00
|
|
|
WHERE ue.status = :active AND e.status = :enabled AND ue.timestart <= :now1
|
2017-08-21 17:15:30 +01:00
|
|
|
AND (ue.timeend = 0 OR ue.timeend > :now2)";
|
2018-10-15 08:42:08 +02:00
|
|
|
$params['userid1'] = $USER->id;
|
2017-08-21 17:15:30 +01:00
|
|
|
$params['active'] = ENROL_USER_ACTIVE;
|
|
|
|
$params['enabled'] = ENROL_INSTANCE_ENABLED;
|
2020-11-03 08:16:07 +00:00
|
|
|
$params['now1'] = $params['now2'] = time();
|
2018-10-15 08:42:08 +02:00
|
|
|
|
|
|
|
if ($sorttimeaccess) {
|
|
|
|
$params['userid2'] = $USER->id;
|
|
|
|
$timeaccessselect = ', ul.timeaccess as lastaccessed';
|
|
|
|
$timeaccessjoin = "LEFT JOIN {user_lastaccess} ul ON (ul.courseid = c.id AND ul.userid = :userid2)";
|
|
|
|
}
|
2017-08-21 17:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// When including non-enrolled but accessible courses...
|
|
|
|
if ($allaccessible) {
|
|
|
|
if (is_siteadmin()) {
|
|
|
|
// Site admins can access all courses.
|
|
|
|
$courseidsql = "SELECT DISTINCT c2.id AS courseid FROM {course} c2";
|
|
|
|
} else {
|
|
|
|
// If we used the enrolment as well, then this will be UNIONed.
|
|
|
|
if ($courseidsql) {
|
|
|
|
$courseidsql .= " UNION ";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Include courses with guest access and no password.
|
|
|
|
$courseidsql .= "
|
|
|
|
SELECT DISTINCT e.courseid
|
|
|
|
FROM {enrol} e
|
2017-09-21 19:27:59 +02:00
|
|
|
WHERE e.enrol = 'guest' AND e.password = :emptypass AND e.status = :enabled2";
|
|
|
|
$params['emptypass'] = '';
|
2017-08-21 17:15:30 +01:00
|
|
|
$params['enabled2'] = ENROL_INSTANCE_ENABLED;
|
|
|
|
|
|
|
|
// Include courses where the current user is currently using guest access (may include
|
|
|
|
// those which require a password).
|
|
|
|
$courseids = [];
|
|
|
|
$accessdata = get_user_accessdata($USER->id);
|
|
|
|
foreach ($accessdata['ra'] as $contextpath => $roles) {
|
|
|
|
if (array_key_exists($CFG->guestroleid, $roles)) {
|
|
|
|
// Work out the course id from context path.
|
|
|
|
$context = context::instance_by_id(preg_replace('~^.*/~', '', $contextpath));
|
|
|
|
if ($context instanceof context_course) {
|
|
|
|
$courseids[$context->instanceid] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Include courses where the current user has moodle/course:view capability.
|
|
|
|
$courses = get_user_capability_course('moodle/course:view', null, false);
|
|
|
|
if (!$courses) {
|
|
|
|
$courses = [];
|
|
|
|
}
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
$courseids[$course->id] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are any in either category, list them individually.
|
|
|
|
if ($courseids) {
|
|
|
|
list ($allowedsql, $allowedparams) = $DB->get_in_or_equal(
|
|
|
|
array_keys($courseids), SQL_PARAMS_NAMED);
|
|
|
|
$courseidsql .= "
|
|
|
|
UNION
|
|
|
|
SELECT DISTINCT c3.id AS courseid
|
|
|
|
FROM {course} c3
|
|
|
|
WHERE c3.id $allowedsql";
|
|
|
|
$params = array_merge($params, $allowedparams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: we can not use DISTINCT + text fields due to Oracle and MS limitations, that is why
|
|
|
|
// we have the subselect there.
|
2018-10-15 08:42:08 +02:00
|
|
|
$sql = "SELECT $coursefields $ccselect $timeaccessselect
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
FROM {course} c
|
2017-08-21 17:15:30 +01:00
|
|
|
JOIN ($courseidsql) en ON (en.courseid = c.id)
|
2018-10-15 08:42:08 +02:00
|
|
|
$timeaccessjoin
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$ccjoin
|
2010-07-01 07:40:24 +00:00
|
|
|
WHERE $wheres
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$orderby";
|
|
|
|
|
2018-08-27 16:43:56 +08:00
|
|
|
$courses = $DB->get_records_sql($sql, $params, $offset, $limit);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
// preload contexts and check visibility
|
|
|
|
foreach ($courses as $id=>$course) {
|
2013-07-05 11:48:36 +08:00
|
|
|
context_helper::preload_from_record($course);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if (!$course->visible) {
|
2012-07-25 16:25:55 +08:00
|
|
|
if (!$context = context_course::instance($id, IGNORE_MISSING)) {
|
2010-07-27 19:04:59 +00:00
|
|
|
unset($courses[$id]);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!has_capability('moodle/course:viewhiddencourses', $context)) {
|
2010-07-27 19:04:59 +00:00
|
|
|
unset($courses[$id]);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$courses[$id] = $course;
|
|
|
|
}
|
|
|
|
|
|
|
|
//wow! Is that really all? :-D
|
|
|
|
|
|
|
|
return $courses;
|
|
|
|
}
|
|
|
|
|
2010-08-18 09:02:05 +00:00
|
|
|
/**
|
|
|
|
* Returns course enrolment information icons.
|
|
|
|
*
|
|
|
|
* @param object $course
|
|
|
|
* @param array $instances enrol instances of this course, improves performance
|
|
|
|
* @return array of pix_icon
|
|
|
|
*/
|
|
|
|
function enrol_get_course_info_icons($course, array $instances = NULL) {
|
|
|
|
$icons = array();
|
|
|
|
if (is_null($instances)) {
|
|
|
|
$instances = enrol_get_instances($course->id, true);
|
|
|
|
}
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
foreach ($plugins as $name => $plugin) {
|
|
|
|
$pis = array();
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if ($instance->status != ENROL_INSTANCE_ENABLED or $instance->courseid != $course->id) {
|
|
|
|
debugging('Invalid instances parameter submitted in enrol_get_info_icons()');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($instance->enrol == $name) {
|
|
|
|
$pis[$instance->id] = $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($pis) {
|
|
|
|
$icons = array_merge($icons, $plugin->get_info_icons($pis));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $icons;
|
|
|
|
}
|
|
|
|
|
2019-09-02 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Returns SQL ORDER arguments which reflect the admin settings to sort my courses.
|
|
|
|
*
|
|
|
|
* @param string|null $sort SQL ORDER arguments which were originally requested (optionally).
|
|
|
|
* @return string SQL ORDER arguments.
|
|
|
|
*/
|
|
|
|
function enrol_get_courses_sortingsql($sort = null) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
// Prepare the visible SQL fragment as empty.
|
|
|
|
$visible = '';
|
|
|
|
// Only create a visible SQL fragment if the caller didn't already pass a sort order which contains the visible field.
|
|
|
|
if ($sort === null || strpos($sort, 'visible') === false) {
|
|
|
|
// If the admin did not explicitly want to have shown and hidden courses sorted as one list, we will sort hidden
|
|
|
|
// courses to the end of the course list.
|
|
|
|
if (!isset($CFG->navsortmycourseshiddenlast) || $CFG->navsortmycourseshiddenlast == true) {
|
|
|
|
$visible = 'visible DESC, ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only create a sortorder SQL fragment if the caller didn't already pass one.
|
|
|
|
if ($sort === null) {
|
|
|
|
// If the admin has configured a course sort order, we will use this.
|
|
|
|
if (!empty($CFG->navsortmycoursessort)) {
|
|
|
|
$sort = $CFG->navsortmycoursessort . ' ASC';
|
|
|
|
|
|
|
|
// Otherwise we will fall back to the sortorder sorting.
|
|
|
|
} else {
|
|
|
|
$sort = 'sortorder ASC';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $visible . $sort;
|
|
|
|
}
|
|
|
|
|
2010-08-18 09:02:05 +00:00
|
|
|
/**
|
|
|
|
* Returns course enrolment detailed information.
|
|
|
|
*
|
|
|
|
* @param object $course
|
|
|
|
* @return array of html fragments - can be used to construct lists
|
|
|
|
*/
|
|
|
|
function enrol_get_course_description_texts($course) {
|
|
|
|
$lines = array();
|
|
|
|
$instances = enrol_get_instances($course->id, true);
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
foreach ($instances as $instance) {
|
2010-09-18 11:35:22 +00:00
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
2010-08-18 09:02:05 +00:00
|
|
|
//weird
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-18 11:35:22 +00:00
|
|
|
$plugin = $plugins[$instance->enrol];
|
2010-08-18 09:02:05 +00:00
|
|
|
$text = $plugin->get_description_text($instance);
|
|
|
|
if ($text !== NULL) {
|
|
|
|
$lines[] = $text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $lines;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Returns list of courses user is enrolled into.
|
|
|
|
*
|
2017-12-05 21:53:55 +01:00
|
|
|
* Note: Use {@link enrol_get_all_users_courses()} if you need the list without any capability checks.
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*
|
2017-12-05 21:53:55 +01:00
|
|
|
* The $fields param is a list of field names to ADD so name just the fields you really need,
|
|
|
|
* which will be added and uniq'd.
|
|
|
|
*
|
|
|
|
* @param int $userid User whose courses are returned, defaults to the current user.
|
|
|
|
* @param bool $onlyactive Return only active enrolments in courses user may see.
|
|
|
|
* @param string|array $fields Extra fields to be returned (array or comma-separated list).
|
|
|
|
* @param string|null $sort Comma separated list of fields to sort by, defaults to respecting navsortmycoursessort.
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2017-12-05 21:53:55 +01:00
|
|
|
function enrol_get_users_courses($userid, $onlyactive = false, $fields = null, $sort = null) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
global $DB;
|
|
|
|
|
2012-04-02 16:11:13 +08:00
|
|
|
$courses = enrol_get_all_users_courses($userid, $onlyactive, $fields, $sort);
|
|
|
|
|
|
|
|
// preload contexts and check visibility
|
|
|
|
if ($onlyactive) {
|
|
|
|
foreach ($courses as $id=>$course) {
|
2013-07-05 11:48:36 +08:00
|
|
|
context_helper::preload_from_record($course);
|
2012-04-02 16:11:13 +08:00
|
|
|
if (!$course->visible) {
|
|
|
|
if (!$context = context_course::instance($id)) {
|
|
|
|
unset($courses[$id]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!has_capability('moodle/course:viewhiddencourses', $context, $userid)) {
|
|
|
|
unset($courses[$id]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $courses;
|
2019-03-18 11:20:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns list of roles per users into course.
|
|
|
|
*
|
|
|
|
* @param int $courseid Course id.
|
|
|
|
* @return array Array[$userid][$roleid] = role_assignment.
|
|
|
|
*/
|
2024-02-28 18:38:20 +01:00
|
|
|
function enrol_get_course_users_roles(int $courseid): array {
|
2019-03-18 11:20:08 +01:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$context = context_course::instance($courseid);
|
|
|
|
|
|
|
|
$roles = array();
|
|
|
|
|
|
|
|
$records = $DB->get_recordset('role_assignments', array('contextid' => $context->id));
|
|
|
|
foreach ($records as $record) {
|
|
|
|
if (isset($roles[$record->userid]) === false) {
|
|
|
|
$roles[$record->userid] = array();
|
|
|
|
}
|
|
|
|
$roles[$record->userid][$record->roleid] = $record;
|
|
|
|
}
|
|
|
|
$records->close();
|
2012-04-02 16:11:13 +08:00
|
|
|
|
2019-03-18 11:20:08 +01:00
|
|
|
return $roles;
|
2012-04-02 16:11:13 +08:00
|
|
|
}
|
|
|
|
|
2012-10-24 09:52:31 +08:00
|
|
|
/**
|
|
|
|
* Can user access at least one enrolled course?
|
|
|
|
*
|
|
|
|
* Cheat if necessary, but find out as fast as possible!
|
|
|
|
*
|
|
|
|
* @param int|stdClass $user null means use current user
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function enrol_user_sees_own_courses($user = null) {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if ($user === null) {
|
|
|
|
$user = $USER;
|
|
|
|
}
|
|
|
|
$userid = is_object($user) ? $user->id : $user;
|
|
|
|
|
|
|
|
// Guest account does not have any courses
|
|
|
|
if (isguestuser($userid) or empty($userid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's cheat here if this is the current user,
|
|
|
|
// if user accessed any course recently, then most probably
|
|
|
|
// we do not need to query the database at all.
|
|
|
|
if ($USER->id == $userid) {
|
|
|
|
if (!empty($USER->enrol['enrolled'])) {
|
|
|
|
foreach ($USER->enrol['enrolled'] as $until) {
|
|
|
|
if ($until > time()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now the slow way.
|
|
|
|
$courses = enrol_get_all_users_courses($userid, true);
|
|
|
|
foreach($courses as $course) {
|
|
|
|
if ($course->visible) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
context_helper::preload_from_record($course);
|
|
|
|
$context = context_course::instance($course->id);
|
|
|
|
if (has_capability('moodle/course:viewhiddencourses', $context, $user)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-02 16:11:13 +08:00
|
|
|
/**
|
2017-12-05 21:53:55 +01:00
|
|
|
* Returns list of courses user is enrolled into without performing any capability checks.
|
|
|
|
*
|
|
|
|
* The $fields param is a list of field names to ADD so name just the fields you really need,
|
|
|
|
* which will be added and uniq'd.
|
2012-04-02 16:11:13 +08:00
|
|
|
*
|
2017-12-05 21:53:55 +01:00
|
|
|
* @param int $userid User whose courses are returned, defaults to the current user.
|
|
|
|
* @param bool $onlyactive Return only active enrolments in courses user may see.
|
|
|
|
* @param string|array $fields Extra fields to be returned (array or comma-separated list).
|
|
|
|
* @param string|null $sort Comma separated list of fields to sort by, defaults to respecting navsortmycoursessort.
|
2012-04-02 16:11:13 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
2017-12-05 21:53:55 +01:00
|
|
|
function enrol_get_all_users_courses($userid, $onlyactive = false, $fields = null, $sort = null) {
|
2019-09-02 14:17:40 +02:00
|
|
|
global $DB;
|
2017-12-05 21:53:55 +01:00
|
|
|
|
2019-09-02 14:17:40 +02:00
|
|
|
// Re-Arrange the course sorting according to the admin settings.
|
|
|
|
$sort = enrol_get_courses_sortingsql($sort);
|
2012-04-02 16:11:13 +08:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
// Guest account does not have any courses
|
2010-06-22 06:26:39 +00:00
|
|
|
if (isguestuser($userid) or empty($userid)) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
return(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
$basefields = array('id', 'category', 'sortorder',
|
2012-04-02 16:11:13 +08:00
|
|
|
'shortname', 'fullname', 'idnumber',
|
|
|
|
'startdate', 'visible',
|
2016-05-05 15:15:58 +08:00
|
|
|
'defaultgroupingid',
|
2012-04-02 16:11:13 +08:00
|
|
|
'groupmode', 'groupmodeforce');
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
if (empty($fields)) {
|
|
|
|
$fields = $basefields;
|
|
|
|
} else if (is_string($fields)) {
|
|
|
|
// turn the fields from a string to an array
|
|
|
|
$fields = explode(',', $fields);
|
|
|
|
$fields = array_map('trim', $fields);
|
|
|
|
$fields = array_unique(array_merge($basefields, $fields));
|
|
|
|
} else if (is_array($fields)) {
|
|
|
|
$fields = array_unique(array_merge($basefields, $fields));
|
|
|
|
} else {
|
2017-12-05 21:59:04 +01:00
|
|
|
throw new coding_exception('Invalid $fields parameter in enrol_get_all_users_courses()');
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
if (in_array('*', $fields)) {
|
|
|
|
$fields = array('*');
|
|
|
|
}
|
|
|
|
|
|
|
|
$orderby = "";
|
|
|
|
$sort = trim($sort);
|
|
|
|
if (!empty($sort)) {
|
|
|
|
$rawsorts = explode(',', $sort);
|
|
|
|
$sorts = array();
|
|
|
|
foreach ($rawsorts as $rawsort) {
|
|
|
|
$rawsort = trim($rawsort);
|
|
|
|
if (strpos($rawsort, 'c.') === 0) {
|
|
|
|
$rawsort = substr($rawsort, 2);
|
|
|
|
}
|
|
|
|
$sorts[] = trim($rawsort);
|
|
|
|
}
|
|
|
|
$sort = 'c.'.implode(',c.', $sorts);
|
|
|
|
$orderby = "ORDER BY $sort";
|
|
|
|
}
|
|
|
|
|
MDL-75208 oracle: Amend a couple of queries to make Oracle happy
The changes introduced here are completely safe, just we stop
binding SITEID and, instead, embed it in the SQL.
Why? Because Oracle 21 has started to return non-sense results
when SITEID is bound.
After lots of tests, attempts, debugging... we have been unable
to find any logic to the need of this change and also, have been
unable to reproduce the problem with a standalone script that
pretty much runs the same queries that the ones changed here.
I'm sure that there is something, somewhere, but have failed
to find it, grrr.
Please read MDL-75208 and linked issues to find more information
about this problem, that is one of the biggest mysteries I've
seen recently. Maybe at the end there is a tiny detail that
explains it all, but it's really well hidden.
2022-07-13 23:44:16 +02:00
|
|
|
$params = [];
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
if ($onlyactive) {
|
2010-07-01 07:40:24 +00:00
|
|
|
$subwhere = "WHERE ue.status = :active AND e.status = :enabled AND ue.timestart < :now1 AND (ue.timeend = 0 OR ue.timeend > :now2)";
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$params['now1'] = round(time(), -2); // improves db caching
|
|
|
|
$params['now2'] = $params['now1'];
|
|
|
|
$params['active'] = ENROL_USER_ACTIVE;
|
|
|
|
$params['enabled'] = ENROL_INSTANCE_ENABLED;
|
2010-07-01 07:40:24 +00:00
|
|
|
} else {
|
|
|
|
$subwhere = "";
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$coursefields = 'c.' .join(',c.', $fields);
|
2013-07-05 13:02:00 +08:00
|
|
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
|
|
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
|
|
|
$params['contextlevel'] = CONTEXT_COURSE;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2010-07-01 07:40:24 +00:00
|
|
|
//note: we can not use DISTINCT + text fields due to Oracle and MS limitations, that is why we have the subselect there
|
|
|
|
$sql = "SELECT $coursefields $ccselect
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
FROM {course} c
|
2010-07-01 07:40:24 +00:00
|
|
|
JOIN (SELECT DISTINCT e.courseid
|
|
|
|
FROM {enrol} e
|
|
|
|
JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)
|
|
|
|
$subwhere
|
|
|
|
) en ON (en.courseid = c.id)
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$ccjoin
|
MDL-75208 oracle: Amend a couple of queries to make Oracle happy
The changes introduced here are completely safe, just we stop
binding SITEID and, instead, embed it in the SQL.
Why? Because Oracle 21 has started to return non-sense results
when SITEID is bound.
After lots of tests, attempts, debugging... we have been unable
to find any logic to the need of this change and also, have been
unable to reproduce the problem with a standalone script that
pretty much runs the same queries that the ones changed here.
I'm sure that there is something, somewhere, but have failed
to find it, grrr.
Please read MDL-75208 and linked issues to find more information
about this problem, that is one of the biggest mysteries I've
seen recently. Maybe at the end there is a tiny detail that
explains it all, but it's really well hidden.
2022-07-13 23:44:16 +02:00
|
|
|
WHERE c.id <> " . SITEID . "
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$orderby";
|
2010-06-22 06:26:39 +00:00
|
|
|
$params['userid'] = $userid;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
$courses = $DB->get_records_sql($sql, $params);
|
|
|
|
|
|
|
|
return $courses;
|
|
|
|
}
|
|
|
|
|
2012-04-02 16:11:13 +08:00
|
|
|
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Called when user is about to be deleted.
|
|
|
|
* @param object $user
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function enrol_user_delete($user) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
foreach ($plugins as $plugin) {
|
|
|
|
$plugin->user_delete($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
// force cleanup of all broken enrolments
|
|
|
|
$DB->delete_records('user_enrolments', array('userid'=>$user->id));
|
|
|
|
}
|
|
|
|
|
2010-09-19 13:09:48 +00:00
|
|
|
/**
|
|
|
|
* Called when course is about to be deleted.
|
2020-09-22 16:09:35 +08:00
|
|
|
* If a user id is passed, only enrolments that the user has permission to un-enrol will be removed,
|
|
|
|
* otherwise all enrolments in the course will be removed.
|
|
|
|
*
|
2011-11-05 12:12:48 +01:00
|
|
|
* @param stdClass $course
|
2020-09-22 16:09:35 +08:00
|
|
|
* @param int|null $userid
|
2010-09-19 13:09:48 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2020-09-22 16:09:35 +08:00
|
|
|
function enrol_course_delete($course, $userid = null) {
|
2010-09-19 13:09:48 +00:00
|
|
|
global $DB;
|
|
|
|
|
2020-09-22 16:09:35 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2010-09-19 13:09:48 +00:00
|
|
|
$instances = enrol_get_instances($course->id, false);
|
|
|
|
$plugins = enrol_get_plugins(true);
|
2020-09-22 16:09:35 +08:00
|
|
|
|
|
|
|
if ($userid) {
|
|
|
|
// If the user id is present, include only course enrolment instances which allow manual unenrolment and
|
|
|
|
// the given user have a capability to perform unenrolment.
|
|
|
|
$instances = array_filter($instances, function($instance) use ($userid, $plugins, $context) {
|
|
|
|
$unenrolcap = "enrol/{$instance->enrol}:unenrol";
|
|
|
|
return $plugins[$instance->enrol]->allow_unenrol($instance) &&
|
|
|
|
has_capability($unenrolcap, $context, $userid);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-09-19 13:09:48 +00:00
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if (isset($plugins[$instance->enrol])) {
|
|
|
|
$plugins[$instance->enrol]->delete_instance($instance);
|
|
|
|
}
|
|
|
|
// low level delete in case plugin did not do it
|
|
|
|
$DB->delete_records('role_assignments', array('itemid'=>$instance->id, 'component'=>'enrol_'.$instance->enrol));
|
|
|
|
$DB->delete_records('user_enrolments', array('enrolid'=>$instance->id));
|
|
|
|
$DB->delete_records('enrol', array('id'=>$instance->id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Try to enrol user via default internal auth plugin.
|
|
|
|
*
|
|
|
|
* For now this is always using the manual enrol plugin...
|
|
|
|
*
|
|
|
|
* @param $courseid
|
|
|
|
* @param $userid
|
|
|
|
* @param $roleid
|
|
|
|
* @param $timestart
|
|
|
|
* @param $timeend
|
|
|
|
* @return bool success
|
|
|
|
*/
|
|
|
|
function enrol_try_internal_enrol($courseid, $userid, $roleid = null, $timestart = 0, $timeend = 0) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
//note: this is hardcoded to manual plugin for now
|
|
|
|
|
|
|
|
if (!enrol_is_enabled('manual')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$enrol = enrol_get_plugin('manual')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!$instances = $DB->get_records('enrol', array('enrol'=>'manual', 'courseid'=>$courseid, 'status'=>ENROL_INSTANCE_ENABLED), 'sortorder,id ASC')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-01 12:12:59 +00:00
|
|
|
if ($roleid && !$DB->record_exists('role', ['id' => $roleid])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance = reset($instances);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$enrol->enrol_user($instance, $userid, $roleid, $timestart, $timeend);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-10 02:14:27 +00:00
|
|
|
/**
|
|
|
|
* Is there a chance users might self enrol
|
|
|
|
* @param int $courseid
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function enrol_selfenrol_available($courseid) {
|
|
|
|
$result = false;
|
|
|
|
|
|
|
|
$plugins = enrol_get_plugins(true);
|
|
|
|
$enrolinstances = enrol_get_instances($courseid, true);
|
|
|
|
foreach($enrolinstances as $instance) {
|
|
|
|
if (!isset($plugins[$instance->enrol])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($instance->enrol === 'guest') {
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-25 12:03:47 +01:00
|
|
|
if ((isguestuser() || !isloggedin()) &&
|
|
|
|
($plugins[$instance->enrol]->is_self_enrol_available($instance) === true)) {
|
|
|
|
$result = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($plugins[$instance->enrol]->show_enrolme_link($instance) === true) {
|
2010-11-10 02:14:27 +00:00
|
|
|
$result = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2011-11-05 12:12:48 +01:00
|
|
|
/**
|
|
|
|
* This function returns the end of current active user enrolment.
|
|
|
|
*
|
|
|
|
* It deals correctly with multiple overlapping user enrolments.
|
|
|
|
*
|
|
|
|
* @param int $courseid
|
|
|
|
* @param int $userid
|
|
|
|
* @return int|bool timestamp when active enrolment ends, false means no active enrolment now, 0 means never
|
|
|
|
*/
|
|
|
|
function enrol_get_enrolment_end($courseid, $userid) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$sql = "SELECT ue.*
|
|
|
|
FROM {user_enrolments} ue
|
|
|
|
JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)
|
|
|
|
JOIN {user} u ON u.id = ue.userid
|
|
|
|
WHERE ue.userid = :userid AND ue.status = :active AND e.status = :enabled AND u.deleted = 0";
|
|
|
|
$params = array('enabled'=>ENROL_INSTANCE_ENABLED, 'active'=>ENROL_USER_ACTIVE, 'userid'=>$userid, 'courseid'=>$courseid);
|
|
|
|
|
|
|
|
if (!$enrolments = $DB->get_records_sql($sql, $params)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$changes = array();
|
|
|
|
|
|
|
|
foreach ($enrolments as $ue) {
|
|
|
|
$start = (int)$ue->timestart;
|
|
|
|
$end = (int)$ue->timeend;
|
|
|
|
if ($end != 0 and $end < $start) {
|
|
|
|
debugging('Invalid enrolment start or end in user_enrolment id:'.$ue->id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isset($changes[$start])) {
|
|
|
|
$changes[$start] = $changes[$start] + 1;
|
|
|
|
} else {
|
|
|
|
$changes[$start] = 1;
|
|
|
|
}
|
|
|
|
if ($end === 0) {
|
|
|
|
// no end
|
|
|
|
} else if (isset($changes[$end])) {
|
|
|
|
$changes[$end] = $changes[$end] - 1;
|
|
|
|
} else {
|
|
|
|
$changes[$end] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// let's sort then enrolment starts&ends and go through them chronologically,
|
|
|
|
// looking for current status and the next future end of enrolment
|
|
|
|
ksort($changes);
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
$current = 0;
|
|
|
|
$present = null;
|
|
|
|
|
|
|
|
foreach ($changes as $time => $change) {
|
|
|
|
if ($time > $now) {
|
|
|
|
if ($present === null) {
|
|
|
|
// we have just went past current time
|
|
|
|
$present = $current;
|
|
|
|
if ($present < 1) {
|
|
|
|
// no enrolment active
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($present !== null) {
|
|
|
|
// we are already in the future - look for possible end
|
|
|
|
if ($current + $change < 1) {
|
|
|
|
return $time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$current += $change;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($current > 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-28 17:26:40 +02:00
|
|
|
/**
|
|
|
|
* Is current user accessing course via this enrolment method?
|
|
|
|
*
|
|
|
|
* This is intended for operations that are going to affect enrol instances.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance enrol instance
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function enrol_accessing_via_instance(stdClass $instance) {
|
|
|
|
global $DB, $USER;
|
|
|
|
|
|
|
|
if (empty($instance->id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_siteadmin()) {
|
|
|
|
// Admins may go anywhere.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id));
|
|
|
|
}
|
|
|
|
|
2016-08-30 10:58:29 +01:00
|
|
|
/**
|
|
|
|
* Returns true if user is enrolled (is participating) in course
|
|
|
|
* this is intended for students and teachers.
|
|
|
|
*
|
|
|
|
* Since 2.2 the result for active enrolments and current user are cached.
|
|
|
|
*
|
|
|
|
* @param context $context
|
|
|
|
* @param int|stdClass $user if null $USER is used, otherwise user object or id expected
|
|
|
|
* @param string $withcapability extra capability name
|
|
|
|
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function is_enrolled(context $context, $user = null, $withcapability = '', $onlyactive = false) {
|
|
|
|
global $USER, $DB;
|
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
// First find the course context.
|
2016-08-30 10:58:29 +01:00
|
|
|
$coursecontext = $context->get_course_context();
|
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
// Make sure there is a real user specified.
|
2016-08-30 10:58:29 +01:00
|
|
|
if ($user === null) {
|
|
|
|
$userid = isset($USER->id) ? $USER->id : 0;
|
|
|
|
} else {
|
|
|
|
$userid = is_object($user) ? $user->id : $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($userid)) {
|
2016-08-12 15:13:09 +01:00
|
|
|
// Not-logged-in!
|
2016-08-30 10:58:29 +01:00
|
|
|
return false;
|
|
|
|
} else if (isguestuser($userid)) {
|
2016-08-12 15:13:09 +01:00
|
|
|
// Guest account can not be enrolled anywhere.
|
2016-08-30 10:58:29 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
// Note everybody participates on frontpage, so for other contexts...
|
|
|
|
if ($coursecontext->instanceid != SITEID) {
|
|
|
|
// Try cached info first - the enrolled flag is set only when active enrolment present.
|
2016-08-30 10:58:29 +01:00
|
|
|
if ($USER->id == $userid) {
|
|
|
|
$coursecontext->reload_if_dirty();
|
|
|
|
if (isset($USER->enrol['enrolled'][$coursecontext->instanceid])) {
|
|
|
|
if ($USER->enrol['enrolled'][$coursecontext->instanceid] > time()) {
|
|
|
|
if ($withcapability and !has_capability($withcapability, $context, $userid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($onlyactive) {
|
2016-08-12 15:13:09 +01:00
|
|
|
// Look for active enrolments only.
|
2016-08-30 10:58:29 +01:00
|
|
|
$until = enrol_get_enrolment_end($coursecontext->instanceid, $userid);
|
|
|
|
|
|
|
|
if ($until === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($USER->id == $userid) {
|
|
|
|
if ($until == 0) {
|
|
|
|
$until = ENROL_MAX_TIMESTAMP;
|
|
|
|
}
|
|
|
|
$USER->enrol['enrolled'][$coursecontext->instanceid] = $until;
|
|
|
|
if (isset($USER->enrol['tempguest'][$coursecontext->instanceid])) {
|
|
|
|
unset($USER->enrol['tempguest'][$coursecontext->instanceid]);
|
|
|
|
remove_temp_course_roles($coursecontext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2016-08-12 15:13:09 +01:00
|
|
|
// Any enrolment is good for us here, even outdated, disabled or inactive.
|
2016-08-30 10:58:29 +01:00
|
|
|
$sql = "SELECT 'x'
|
|
|
|
FROM {user_enrolments} ue
|
|
|
|
JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)
|
|
|
|
JOIN {user} u ON u.id = ue.userid
|
|
|
|
WHERE ue.userid = :userid AND u.deleted = 0";
|
2016-08-12 15:13:09 +01:00
|
|
|
$params = array('userid' => $userid, 'courseid' => $coursecontext->instanceid);
|
2016-08-30 10:58:29 +01:00
|
|
|
if (!$DB->record_exists_sql($sql, $params)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($withcapability and !has_capability($withcapability, $context, $userid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
/**
|
|
|
|
* Returns an array of joins, wheres and params that will limit the group of
|
|
|
|
* users to only those enrolled and with given capability (if specified).
|
|
|
|
*
|
2017-01-05 14:34:41 +00:00
|
|
|
* Note this join will return duplicate rows for users who have been enrolled
|
|
|
|
* several times (e.g. as manual enrolment, and as self enrolment). You may
|
|
|
|
* need to use a SELECT DISTINCT in your query (see get_enrolled_sql for example).
|
|
|
|
*
|
2021-02-16 17:08:51 +01:00
|
|
|
* In case is guaranteed some of the joins never match any rows, the resulting
|
|
|
|
* join_sql->cannotmatchanyrows will be true. This happens when the capability
|
|
|
|
* is prohibited.
|
|
|
|
*
|
2016-08-12 15:13:09 +01:00
|
|
|
* @param context $context
|
|
|
|
* @param string $prefix optional, a prefix to the user id column
|
2016-08-19 17:21:19 +01:00
|
|
|
* @param string|array $capability optional, may include a capability name, or array of names.
|
|
|
|
* If an array is provided then this is the equivalent of a logical 'OR',
|
|
|
|
* i.e. the user needs to have one of these capabilities.
|
2024-02-05 15:20:28 +00:00
|
|
|
* @param int|array|null $groupids The groupids, 0 or [] means all groups and USERSWITHOUTGROUP no group
|
2016-08-12 15:13:09 +01:00
|
|
|
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
|
|
|
|
* @param bool $onlysuspended inverse of onlyactive, consider only suspended enrolments
|
2017-07-24 12:52:28 +08:00
|
|
|
* @param int $enrolid The enrolment ID. If not 0, only users enrolled using this enrolment method will be returned.
|
2021-02-16 17:08:51 +01:00
|
|
|
* @return \core\dml\sql_join Contains joins, wheres, params and cannotmatchanyrows
|
2016-08-12 15:13:09 +01:00
|
|
|
*/
|
2021-04-02 18:01:21 -07:00
|
|
|
function get_enrolled_with_capabilities_join(context $context, $prefix = '', $capability = '', $groupids = 0,
|
2017-07-24 12:52:28 +08:00
|
|
|
$onlyactive = false, $onlysuspended = false, $enrolid = 0) {
|
2016-08-12 15:13:09 +01:00
|
|
|
$uid = $prefix . 'u.id';
|
|
|
|
$joins = array();
|
|
|
|
$wheres = array();
|
2021-02-16 17:08:51 +01:00
|
|
|
$cannotmatchanyrows = false;
|
2016-08-12 15:13:09 +01:00
|
|
|
|
2017-07-24 12:52:28 +08:00
|
|
|
$enrolledjoin = get_enrolled_join($context, $uid, $onlyactive, $onlysuspended, $enrolid);
|
2016-08-12 15:13:09 +01:00
|
|
|
$joins[] = $enrolledjoin->joins;
|
|
|
|
$wheres[] = $enrolledjoin->wheres;
|
|
|
|
$params = $enrolledjoin->params;
|
2021-02-16 17:08:51 +01:00
|
|
|
$cannotmatchanyrows = $cannotmatchanyrows || $enrolledjoin->cannotmatchanyrows;
|
2016-08-12 15:13:09 +01:00
|
|
|
|
|
|
|
if (!empty($capability)) {
|
|
|
|
$capjoin = get_with_capability_join($context, $capability, $uid);
|
|
|
|
$joins[] = $capjoin->joins;
|
|
|
|
$wheres[] = $capjoin->wheres;
|
|
|
|
$params = array_merge($params, $capjoin->params);
|
2021-02-16 17:08:51 +01:00
|
|
|
$cannotmatchanyrows = $cannotmatchanyrows || $capjoin->cannotmatchanyrows;
|
2016-08-12 15:13:09 +01:00
|
|
|
}
|
|
|
|
|
2021-04-02 18:01:21 -07:00
|
|
|
if ($groupids) {
|
|
|
|
$groupjoin = groups_get_members_join($groupids, $uid, $context);
|
2016-08-12 15:13:09 +01:00
|
|
|
$joins[] = $groupjoin->joins;
|
|
|
|
$params = array_merge($params, $groupjoin->params);
|
2018-07-13 11:28:59 +02:00
|
|
|
if (!empty($groupjoin->wheres)) {
|
|
|
|
$wheres[] = $groupjoin->wheres;
|
|
|
|
}
|
2021-02-16 17:08:51 +01:00
|
|
|
$cannotmatchanyrows = $cannotmatchanyrows || $groupjoin->cannotmatchanyrows;
|
2016-08-12 15:13:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$joins = implode("\n", $joins);
|
|
|
|
$wheres[] = "{$prefix}u.deleted = 0";
|
|
|
|
$wheres = implode(" AND ", $wheres);
|
|
|
|
|
2021-02-16 17:08:51 +01:00
|
|
|
return new \core\dml\sql_join($joins, $wheres, $params, $cannotmatchanyrows);
|
2016-08-12 15:13:09 +01:00
|
|
|
}
|
|
|
|
|
2016-08-30 10:58:29 +01:00
|
|
|
/**
|
|
|
|
* Returns array with sql code and parameters returning all ids
|
|
|
|
* of users enrolled into course.
|
|
|
|
*
|
|
|
|
* This function is using 'eu[0-9]+_' prefix for table names and parameters.
|
|
|
|
*
|
|
|
|
* @param context $context
|
|
|
|
* @param string $withcapability
|
2024-02-05 15:20:28 +00:00
|
|
|
* @param int|array|null $groupids The groupids, 0 or [] means all groups and USERSWITHOUTGROUP no group
|
2016-08-30 10:58:29 +01:00
|
|
|
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
|
|
|
|
* @param bool $onlysuspended inverse of onlyactive, consider only suspended enrolments
|
2017-07-24 12:52:28 +08:00
|
|
|
* @param int $enrolid The enrolment ID. If not 0, only users enrolled using this enrolment method will be returned.
|
2016-08-30 10:58:29 +01:00
|
|
|
* @return array list($sql, $params)
|
|
|
|
*/
|
2021-04-02 18:01:21 -07:00
|
|
|
function get_enrolled_sql(context $context, $withcapability = '', $groupids = 0, $onlyactive = false, $onlysuspended = false,
|
2017-07-24 12:52:28 +08:00
|
|
|
$enrolid = 0) {
|
2016-08-30 10:58:29 +01:00
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
// Use unique prefix just in case somebody makes some SQL magic with the result.
|
2016-08-30 10:58:29 +01:00
|
|
|
static $i = 0;
|
|
|
|
$i++;
|
2016-08-12 15:13:09 +01:00
|
|
|
$prefix = 'eu' . $i . '_';
|
2016-08-30 10:58:29 +01:00
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
$capjoin = get_enrolled_with_capabilities_join(
|
2021-04-02 18:01:21 -07:00
|
|
|
$context, $prefix, $withcapability, $groupids, $onlyactive, $onlysuspended, $enrolid);
|
2016-08-12 15:13:09 +01:00
|
|
|
|
|
|
|
$sql = "SELECT DISTINCT {$prefix}u.id
|
|
|
|
FROM {user} {$prefix}u
|
|
|
|
$capjoin->joins
|
|
|
|
WHERE $capjoin->wheres";
|
|
|
|
|
|
|
|
return array($sql, $capjoin->params);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns array with sql joins and parameters returning all ids
|
|
|
|
* of users enrolled into course.
|
|
|
|
*
|
|
|
|
* This function is using 'ej[0-9]+_' prefix for table names and parameters.
|
|
|
|
*
|
|
|
|
* @throws coding_exception
|
|
|
|
*
|
|
|
|
* @param context $context
|
|
|
|
* @param string $useridcolumn User id column used the calling query, e.g. u.id
|
|
|
|
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
|
|
|
|
* @param bool $onlysuspended inverse of onlyactive, consider only suspended enrolments
|
2017-07-24 12:52:28 +08:00
|
|
|
* @param int $enrolid The enrolment ID. If not 0, only users enrolled using this enrolment method will be returned.
|
2016-08-12 15:13:09 +01:00
|
|
|
* @return \core\dml\sql_join Contains joins, wheres, params
|
|
|
|
*/
|
2017-07-24 12:52:28 +08:00
|
|
|
function get_enrolled_join(context $context, $useridcolumn, $onlyactive = false, $onlysuspended = false, $enrolid = 0) {
|
2016-08-12 15:13:09 +01:00
|
|
|
// Use unique prefix just in case somebody makes some SQL magic with the result.
|
|
|
|
static $i = 0;
|
|
|
|
$i++;
|
|
|
|
$prefix = 'ej' . $i . '_';
|
|
|
|
|
|
|
|
// First find the course context.
|
2016-08-30 10:58:29 +01:00
|
|
|
$coursecontext = $context->get_course_context();
|
|
|
|
|
|
|
|
$isfrontpage = ($coursecontext->instanceid == SITEID);
|
|
|
|
|
|
|
|
if ($onlyactive && $onlysuspended) {
|
|
|
|
throw new coding_exception("Both onlyactive and onlysuspended are set, this is probably not what you want!");
|
|
|
|
}
|
|
|
|
if ($isfrontpage && $onlysuspended) {
|
|
|
|
throw new coding_exception("onlysuspended is not supported on frontpage; please add your own early-exit!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$joins = array();
|
|
|
|
$wheres = array();
|
|
|
|
$params = array();
|
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
$wheres[] = "1 = 1"; // Prevent broken where clauses later on.
|
2016-08-30 10:58:29 +01:00
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
// Note all users are "enrolled" on the frontpage, but for others...
|
|
|
|
if (!$isfrontpage) {
|
2016-08-30 10:58:29 +01:00
|
|
|
$where1 = "{$prefix}ue.status = :{$prefix}active AND {$prefix}e.status = :{$prefix}enabled";
|
|
|
|
$where2 = "{$prefix}ue.timestart < :{$prefix}now1 AND ({$prefix}ue.timeend = 0 OR {$prefix}ue.timeend > :{$prefix}now2)";
|
2017-07-24 12:52:28 +08:00
|
|
|
|
|
|
|
$enrolconditions = array(
|
|
|
|
"{$prefix}e.id = {$prefix}ue.enrolid",
|
|
|
|
"{$prefix}e.courseid = :{$prefix}courseid",
|
|
|
|
);
|
|
|
|
if ($enrolid) {
|
|
|
|
$enrolconditions[] = "{$prefix}e.id = :{$prefix}enrolid";
|
|
|
|
$params[$prefix . 'enrolid'] = $enrolid;
|
|
|
|
}
|
|
|
|
$enrolconditionssql = implode(" AND ", $enrolconditions);
|
|
|
|
$ejoin = "JOIN {enrol} {$prefix}e ON ($enrolconditionssql)";
|
|
|
|
|
2016-08-30 10:58:29 +01:00
|
|
|
$params[$prefix.'courseid'] = $coursecontext->instanceid;
|
|
|
|
|
|
|
|
if (!$onlysuspended) {
|
2016-08-12 15:13:09 +01:00
|
|
|
$joins[] = "JOIN {user_enrolments} {$prefix}ue ON {$prefix}ue.userid = $useridcolumn";
|
2016-08-30 10:58:29 +01:00
|
|
|
$joins[] = $ejoin;
|
|
|
|
if ($onlyactive) {
|
|
|
|
$wheres[] = "$where1 AND $where2";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Suspended only where there is enrolment but ALL are suspended.
|
|
|
|
// Consider multiple enrols where one is not suspended or plain role_assign.
|
|
|
|
$enrolselect = "SELECT DISTINCT {$prefix}ue.userid FROM {user_enrolments} {$prefix}ue $ejoin WHERE $where1 AND $where2";
|
2016-08-12 15:13:09 +01:00
|
|
|
$joins[] = "JOIN {user_enrolments} {$prefix}ue1 ON {$prefix}ue1.userid = $useridcolumn";
|
2017-07-24 12:52:28 +08:00
|
|
|
$enrolconditions = array(
|
|
|
|
"{$prefix}e1.id = {$prefix}ue1.enrolid",
|
|
|
|
"{$prefix}e1.courseid = :{$prefix}_e1_courseid",
|
|
|
|
);
|
|
|
|
if ($enrolid) {
|
2017-10-03 11:31:45 +08:00
|
|
|
$enrolconditions[] = "{$prefix}e1.id = :{$prefix}e1_enrolid";
|
|
|
|
$params[$prefix . 'e1_enrolid'] = $enrolid;
|
2017-07-24 12:52:28 +08:00
|
|
|
}
|
|
|
|
$enrolconditionssql = implode(" AND ", $enrolconditions);
|
|
|
|
$joins[] = "JOIN {enrol} {$prefix}e1 ON ($enrolconditionssql)";
|
2016-08-30 10:58:29 +01:00
|
|
|
$params["{$prefix}_e1_courseid"] = $coursecontext->instanceid;
|
2016-08-12 15:13:09 +01:00
|
|
|
$wheres[] = "$useridcolumn NOT IN ($enrolselect)";
|
2016-08-30 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($onlyactive || $onlysuspended) {
|
2016-08-12 15:13:09 +01:00
|
|
|
$now = round(time(), -2); // Rounding helps caching in DB.
|
|
|
|
$params = array_merge($params, array($prefix . 'enabled' => ENROL_INSTANCE_ENABLED,
|
|
|
|
$prefix . 'active' => ENROL_USER_ACTIVE,
|
|
|
|
$prefix . 'now1' => $now, $prefix . 'now2' => $now));
|
2016-08-30 10:58:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$joins = implode("\n", $joins);
|
2016-08-12 15:13:09 +01:00
|
|
|
$wheres = implode(" AND ", $wheres);
|
2016-08-30 10:58:29 +01:00
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
return new \core\dml\sql_join($joins, $wheres, $params);
|
2016-08-30 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns list of users enrolled into course.
|
|
|
|
*
|
|
|
|
* @param context $context
|
|
|
|
* @param string $withcapability
|
2021-04-02 18:01:21 -07:00
|
|
|
* @param int|array $groupids The groupids, 0 or [] means all groups and USERSWITHOUTGROUP no group
|
2016-08-30 10:58:29 +01:00
|
|
|
* @param string $userfields requested user record fields
|
|
|
|
* @param string $orderby
|
|
|
|
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
|
|
|
|
* @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
|
|
|
|
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
|
|
|
|
* @return array of user records
|
|
|
|
*/
|
2021-04-02 18:01:21 -07:00
|
|
|
function get_enrolled_users(context $context, $withcapability = '', $groupids = 0, $userfields = 'u.*', $orderby = null,
|
2016-08-30 10:58:29 +01:00
|
|
|
$limitfrom = 0, $limitnum = 0, $onlyactive = false) {
|
|
|
|
global $DB;
|
|
|
|
|
2021-04-02 18:01:21 -07:00
|
|
|
list($esql, $params) = get_enrolled_sql($context, $withcapability, $groupids, $onlyactive);
|
2016-08-30 10:58:29 +01:00
|
|
|
$sql = "SELECT $userfields
|
|
|
|
FROM {user} u
|
|
|
|
JOIN ($esql) je ON je.id = u.id
|
|
|
|
WHERE u.deleted = 0";
|
|
|
|
|
|
|
|
if ($orderby) {
|
|
|
|
$sql = "$sql ORDER BY $orderby";
|
|
|
|
} else {
|
|
|
|
list($sort, $sortparams) = users_order_by_sql('u');
|
|
|
|
$sql = "$sql ORDER BY $sort";
|
|
|
|
$params = array_merge($params, $sortparams);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts list of users enrolled into course (as per above function)
|
|
|
|
*
|
|
|
|
* @param context $context
|
|
|
|
* @param string $withcapability
|
2021-04-02 18:01:21 -07:00
|
|
|
* @param int|array $groupids The groupids, 0 or [] means all groups and USERSWITHOUTGROUP no group
|
2016-08-30 10:58:29 +01:00
|
|
|
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
|
2021-11-23 23:24:11 +02:00
|
|
|
* @return int number of users enrolled into course
|
2016-08-30 10:58:29 +01:00
|
|
|
*/
|
2021-04-02 18:01:21 -07:00
|
|
|
function count_enrolled_users(context $context, $withcapability = '', $groupids = 0, $onlyactive = false) {
|
2016-08-30 10:58:29 +01:00
|
|
|
global $DB;
|
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
$capjoin = get_enrolled_with_capabilities_join(
|
2021-04-02 18:01:21 -07:00
|
|
|
$context, '', $withcapability, $groupids, $onlyactive);
|
2016-08-12 15:13:09 +01:00
|
|
|
|
2018-09-07 14:18:45 +01:00
|
|
|
$sql = "SELECT COUNT(DISTINCT u.id)
|
2016-08-30 10:58:29 +01:00
|
|
|
FROM {user} u
|
2016-08-12 15:13:09 +01:00
|
|
|
$capjoin->joins
|
|
|
|
WHERE $capjoin->wheres AND u.deleted = 0";
|
2016-08-30 10:58:29 +01:00
|
|
|
|
2016-08-12 15:13:09 +01:00
|
|
|
return $DB->count_records_sql($sql, $capjoin->params);
|
2016-08-30 10:58:29 +01:00
|
|
|
}
|
2011-11-05 12:12:48 +01:00
|
|
|
|
2016-10-26 09:34:44 +08:00
|
|
|
/**
|
|
|
|
* Send welcome email "from" options.
|
|
|
|
*
|
|
|
|
* @return array list of from options
|
|
|
|
*/
|
|
|
|
function enrol_send_welcome_email_options() {
|
|
|
|
return [
|
|
|
|
ENROL_DO_NOT_SEND_EMAIL => get_string('no'),
|
|
|
|
ENROL_SEND_EMAIL_FROM_COURSE_CONTACT => get_string('sendfromcoursecontact', 'enrol'),
|
|
|
|
ENROL_SEND_EMAIL_FROM_KEY_HOLDER => get_string('sendfromkeyholder', 'enrol'),
|
|
|
|
ENROL_SEND_EMAIL_FROM_NOREPLY => get_string('sendfromnoreply', 'enrol')
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-07-13 10:29:17 +08:00
|
|
|
/**
|
|
|
|
* Serve the user enrolment form as a fragment.
|
|
|
|
*
|
|
|
|
* @param array $args List of named arguments for the fragment loader.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function enrol_output_fragment_user_enrolment_form($args) {
|
|
|
|
global $CFG, $DB;
|
|
|
|
|
|
|
|
$args = (object) $args;
|
|
|
|
$context = $args->context;
|
|
|
|
require_capability('moodle/course:enrolreview', $context);
|
|
|
|
|
|
|
|
$ueid = $args->ueid;
|
|
|
|
$userenrolment = $DB->get_record('user_enrolments', ['id' => $ueid], '*', MUST_EXIST);
|
2017-10-16 17:55:34 +08:00
|
|
|
$instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
|
|
|
|
$plugin = enrol_get_plugin($instance->enrol);
|
2017-07-13 10:29:17 +08:00
|
|
|
$customdata = [
|
|
|
|
'ue' => $userenrolment,
|
|
|
|
'modal' => true,
|
2017-10-16 17:55:34 +08:00
|
|
|
'enrolinstancename' => $plugin->get_instance_name($instance)
|
2017-07-13 10:29:17 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
// Set the data if applicable.
|
|
|
|
$data = [];
|
|
|
|
if (isset($args->formdata)) {
|
|
|
|
$serialiseddata = json_decode($args->formdata);
|
|
|
|
parse_str($serialiseddata, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once("$CFG->dirroot/enrol/editenrolment_form.php");
|
|
|
|
$mform = new \enrol_user_enrolment_form(null, $customdata, 'post', '', null, true, $data);
|
|
|
|
|
|
|
|
if (!empty($data)) {
|
|
|
|
$mform->set_data($data);
|
|
|
|
$mform->is_validated();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $mform->render();
|
|
|
|
}
|
|
|
|
|
2017-06-09 12:53:41 +02:00
|
|
|
/**
|
|
|
|
* Returns the course where a user enrolment belong to.
|
|
|
|
*
|
|
|
|
* @param int $ueid user_enrolments id
|
|
|
|
* @return stdClass
|
|
|
|
*/
|
|
|
|
function enrol_get_course_by_user_enrolment_id($ueid) {
|
|
|
|
global $DB;
|
|
|
|
$sql = "SELECT c.* FROM {user_enrolments} ue
|
|
|
|
JOIN {enrol} e ON e.id = ue.enrolid
|
|
|
|
JOIN {course} c ON c.id = e.courseid
|
|
|
|
WHERE ue.id = :ueid";
|
|
|
|
return $DB->get_record_sql($sql, array('ueid' => $ueid));
|
|
|
|
}
|
|
|
|
|
2017-06-12 13:08:20 +02:00
|
|
|
/**
|
|
|
|
* Return all users enrolled in a course.
|
|
|
|
*
|
2017-06-13 07:12:48 +02:00
|
|
|
* @param int $courseid Course id or false if using $uefilter (user enrolment ids may belong to different courses)
|
2017-06-12 13:08:20 +02:00
|
|
|
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
|
2017-06-16 12:31:12 +02:00
|
|
|
* @param array $usersfilter Limit the results obtained to this list of user ids. $uefilter compatibility not guaranteed.
|
|
|
|
* @param array $uefilter Limit the results obtained to this list of user enrolment ids. $usersfilter compatibility not guaranteed.
|
2023-12-06 13:53:28 +07:00
|
|
|
* @param array $usergroups Limit the results of users to the ones that belong to one of the submitted group ids.
|
2017-06-16 12:31:12 +02:00
|
|
|
* @return stdClass[]
|
2017-06-12 13:08:20 +02:00
|
|
|
*/
|
2023-12-06 13:53:28 +07:00
|
|
|
function enrol_get_course_users($courseid = false, $onlyactive = false, $usersfilter = [], $uefilter = [],
|
|
|
|
$usergroups = []) {
|
2017-06-12 13:08:20 +02:00
|
|
|
global $DB;
|
|
|
|
|
2017-06-13 07:12:48 +02:00
|
|
|
if (!$courseid && !$usersfilter && !$uefilter) {
|
|
|
|
throw new \coding_exception('You should specify at least 1 filter: courseid, users or user enrolments');
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT ue.id AS ueid, ue.status AS uestatus, ue.enrolid AS ueenrolid, ue.timestart AS uetimestart,
|
|
|
|
ue.timeend AS uetimeend, ue.modifierid AS uemodifierid, ue.timecreated AS uetimecreated,
|
2019-07-05 10:05:33 +08:00
|
|
|
ue.timemodified AS uetimemodified, e.status AS estatus,
|
2017-06-13 07:12:48 +02:00
|
|
|
u.* FROM {user_enrolments} ue
|
2017-06-12 13:08:20 +02:00
|
|
|
JOIN {enrol} e ON e.id = ue.enrolid
|
|
|
|
JOIN {user} u ON ue.userid = u.id
|
2017-06-13 07:12:48 +02:00
|
|
|
WHERE ";
|
|
|
|
$params = array();
|
|
|
|
|
|
|
|
if ($courseid) {
|
|
|
|
$conditions[] = "e.courseid = :courseid";
|
|
|
|
$params['courseid'] = $courseid;
|
|
|
|
}
|
2017-06-12 13:08:20 +02:00
|
|
|
|
|
|
|
if ($onlyactive) {
|
2017-06-16 12:31:12 +02:00
|
|
|
$conditions[] = "ue.status = :active AND e.status = :enabled AND ue.timestart < :now1 AND " .
|
|
|
|
"(ue.timeend = 0 OR ue.timeend > :now2)";
|
|
|
|
// Improves db caching.
|
|
|
|
$params['now1'] = round(time(), -2);
|
2017-06-12 13:08:20 +02:00
|
|
|
$params['now2'] = $params['now1'];
|
|
|
|
$params['active'] = ENROL_USER_ACTIVE;
|
|
|
|
$params['enabled'] = ENROL_INSTANCE_ENABLED;
|
|
|
|
}
|
2017-06-13 07:12:48 +02:00
|
|
|
|
|
|
|
if ($usersfilter) {
|
|
|
|
list($usersql, $userparams) = $DB->get_in_or_equal($usersfilter, SQL_PARAMS_NAMED);
|
|
|
|
$conditions[] = "ue.userid $usersql";
|
|
|
|
$params = $params + $userparams;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($uefilter) {
|
2017-06-20 14:05:48 +02:00
|
|
|
list($uesql, $ueparams) = $DB->get_in_or_equal($uefilter, SQL_PARAMS_NAMED);
|
2017-06-13 07:12:48 +02:00
|
|
|
$conditions[] = "ue.id $uesql";
|
|
|
|
$params = $params + $ueparams;
|
|
|
|
}
|
|
|
|
|
2023-12-06 13:53:28 +07:00
|
|
|
// Only select enrolled users that belong to a specific group(s).
|
|
|
|
if (!empty($usergroups)) {
|
|
|
|
$usergroups = array_map(function ($item) { // Sanitize groupid to int to be save for sql.
|
|
|
|
return (int)$item;
|
|
|
|
}, $usergroups);
|
|
|
|
list($ugsql, $ugparams) = $DB->get_in_or_equal($usergroups, SQL_PARAMS_NAMED);
|
|
|
|
$conditions[] = 'ue.userid IN (SELECT userid FROM {groups_members} WHERE groupid ' . $ugsql . ')';
|
|
|
|
$params = $params + $ugparams;
|
|
|
|
}
|
|
|
|
|
2017-06-13 07:12:48 +02:00
|
|
|
return $DB->get_records_sql($sql . ' ' . implode(' AND ', $conditions), $params);
|
2017-06-12 13:08:20 +02:00
|
|
|
}
|
|
|
|
|
2019-06-13 14:49:20 +07:00
|
|
|
/**
|
|
|
|
* Get the list of options for the enrolment period dropdown
|
|
|
|
*
|
|
|
|
* @return array List of options for the enrolment period dropdown
|
|
|
|
*/
|
|
|
|
function enrol_get_period_list() {
|
|
|
|
$periodmenu = [];
|
|
|
|
$periodmenu[''] = get_string('unlimited');
|
|
|
|
for ($i = 1; $i <= 365; $i++) {
|
|
|
|
$seconds = $i * DAYSECS;
|
|
|
|
$periodmenu[$seconds] = get_string('numdays', '', $i);
|
|
|
|
}
|
|
|
|
return $periodmenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate duration base on start time and end time
|
|
|
|
*
|
|
|
|
* @param int $timestart Time start
|
|
|
|
* @param int $timeend Time end
|
|
|
|
* @return float|int Calculated duration
|
|
|
|
*/
|
|
|
|
function enrol_calculate_duration($timestart, $timeend) {
|
|
|
|
$duration = floor(($timeend - $timestart) / DAYSECS) * DAYSECS;
|
|
|
|
return $duration;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
2017-06-16 12:31:12 +02:00
|
|
|
* Enrolment plugins abstract class.
|
|
|
|
*
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* All enrol plugins should be based on this class,
|
|
|
|
* this is also the main source of documentation.
|
2017-06-16 12:31:12 +02:00
|
|
|
*
|
|
|
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
abstract class enrol_plugin {
|
|
|
|
protected $config = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns name of this enrol plugin
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_name() {
|
2010-08-18 09:02:05 +00:00
|
|
|
// second word in class is always enrol name, sorry, no fancy plugin names with _
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$words = explode('_', get_class($this));
|
|
|
|
return $words[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns localised name of enrol instance
|
|
|
|
*
|
|
|
|
* @param object $instance (null is accepted too)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_instance_name($instance) {
|
|
|
|
if (empty($instance->name)) {
|
|
|
|
$enrol = $this->get_name();
|
|
|
|
return get_string('pluginname', 'enrol_'.$enrol);
|
|
|
|
} else {
|
2012-07-25 16:25:55 +08:00
|
|
|
$context = context_course::instance($instance->courseid);
|
2010-08-11 17:15:52 +00:00
|
|
|
return format_string($instance->name, true, array('context'=>$context));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 09:02:05 +00:00
|
|
|
/**
|
|
|
|
* Returns optional enrolment information icons.
|
|
|
|
*
|
|
|
|
* This is used in course list for quick overview of enrolment options.
|
|
|
|
*
|
|
|
|
* We are not using single instance parameter because sometimes
|
|
|
|
* we might want to prevent icon repetition when multiple instances
|
|
|
|
* of one type exist. One instance may also produce several icons.
|
|
|
|
*
|
|
|
|
* @param array $instances all enrol instances of this type in one course
|
|
|
|
* @return array of pix_icon
|
|
|
|
*/
|
|
|
|
public function get_info_icons(array $instances) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns optional enrolment instance description text.
|
|
|
|
*
|
|
|
|
* This is used in detailed course information.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param object $instance
|
|
|
|
* @return string short html text
|
|
|
|
*/
|
|
|
|
public function get_description_text($instance) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Makes sure config is loaded and cached.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function load_config() {
|
|
|
|
if (!isset($this->config)) {
|
|
|
|
$name = $this->get_name();
|
2012-01-21 11:15:30 +01:00
|
|
|
$this->config = get_config("enrol_$name");
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns plugin config value
|
|
|
|
* @param string $name
|
|
|
|
* @param string $default value if config does not exist yet
|
|
|
|
* @return string value or default
|
|
|
|
*/
|
|
|
|
public function get_config($name, $default = NULL) {
|
|
|
|
$this->load_config();
|
|
|
|
return isset($this->config->$name) ? $this->config->$name : $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets plugin config value
|
|
|
|
* @param string $name name of config
|
|
|
|
* @param string $value string config value, null means delete
|
|
|
|
*/
|
|
|
|
public function set_config($name, $value) {
|
2010-07-07 17:56:24 +00:00
|
|
|
$pluginname = $this->get_name();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$this->load_config();
|
|
|
|
if ($value === NULL) {
|
|
|
|
unset($this->config->$name);
|
|
|
|
} else {
|
|
|
|
$this->config->$name = $value;
|
|
|
|
}
|
2010-07-07 17:56:24 +00:00
|
|
|
set_config($name, $value, "enrol_$pluginname");
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does this plugin assign protected roles are can they be manually removed?
|
|
|
|
* @return bool - false means anybody may tweak roles, it does not use itemid and component when assigning roles
|
|
|
|
*/
|
|
|
|
public function roles_protected() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:46:48 +00:00
|
|
|
/**
|
|
|
|
* Does this plugin allow manual enrolments?
|
|
|
|
*
|
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
* All plugins allowing this must implement 'enrol/xxx:enrol' capability
|
|
|
|
*
|
2011-12-28 16:55:30 +01:00
|
|
|
* @return bool - true means user with 'enrol/xxx:enrol' may enrol others freely, false means nobody may add more enrolments manually
|
2010-07-12 17:46:48 +00:00
|
|
|
*/
|
|
|
|
public function allow_enrol(stdClass $instance) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
2011-12-28 16:55:30 +01:00
|
|
|
* Does this plugin allow manual unenrolment of all users?
|
2010-07-12 17:46:48 +00:00
|
|
|
* All plugins allowing this must implement 'enrol/xxx:unenrol' capability
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*
|
2011-12-28 16:55:30 +01:00
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
* @return bool - true means user with 'enrol/xxx:unenrol' may unenrol others freely, false means nobody may touch user_enrolments
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
public function allow_unenrol(stdClass $instance) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-28 16:55:30 +01:00
|
|
|
/**
|
|
|
|
* Does this plugin allow manual unenrolment of a specific user?
|
|
|
|
* All plugins allowing this must implement 'enrol/xxx:unenrol' capability
|
|
|
|
*
|
|
|
|
* This is useful especially for synchronisation plugins that
|
|
|
|
* do suspend instead of full unenrolment.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
* @param stdClass $ue record from user_enrolments table, specifies user
|
|
|
|
*
|
|
|
|
* @return bool - true means user with 'enrol/xxx:unenrol' may unenrol this user, false means nobody may touch this user enrolment
|
|
|
|
*/
|
|
|
|
public function allow_unenrol_user(stdClass $instance, stdClass $ue) {
|
|
|
|
return $this->allow_unenrol($instance);
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Does this plugin allow manual changes in user_enrolments table?
|
|
|
|
*
|
2010-07-12 17:46:48 +00:00
|
|
|
* All plugins allowing this must implement 'enrol/xxx:manage' capability
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*
|
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
* @return bool - true means it is possible to change enrol period and status in user_enrolments table
|
|
|
|
*/
|
|
|
|
public function allow_manage(stdClass $instance) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:04:17 +00:00
|
|
|
/**
|
|
|
|
* Does this plugin support some way to user to self enrol?
|
|
|
|
*
|
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
*
|
|
|
|
* @return bool - true means show "Enrol me in this course" link in course UI
|
|
|
|
*/
|
|
|
|
public function show_enrolme_link(stdClass $instance) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-25 12:03:47 +01:00
|
|
|
/**
|
|
|
|
* Does this plugin support some way to self enrol?
|
|
|
|
* This function doesn't check user capabilities. Use can_self_enrol to check capabilities.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance enrolment instance
|
|
|
|
* @return bool - true means "Enrol me in this course" link could be available.
|
|
|
|
*/
|
|
|
|
public function is_self_enrol_available(stdClass $instance) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Attempt to automatically enrol current user in course without any interaction,
|
|
|
|
* calling code has to make sure the plugin and instance are active.
|
|
|
|
*
|
2010-11-11 03:37:56 +00:00
|
|
|
* This should return either a timestamp in the future or false.
|
|
|
|
*
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
* @return bool|int false means not enrolled, integer means timeend
|
|
|
|
*/
|
|
|
|
public function try_autoenrol(stdClass $instance) {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to automatically gain temporary guest access to course,
|
|
|
|
* calling code has to make sure the plugin and instance are active.
|
|
|
|
*
|
2010-11-11 03:37:56 +00:00
|
|
|
* This should return either a timestamp in the future or false.
|
|
|
|
*
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
* @return bool|int false means no guest access, integer means timeend
|
|
|
|
*/
|
|
|
|
public function try_guestaccess(stdClass $instance) {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enrol user into course via enrol instance.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $userid
|
|
|
|
* @param int $roleid optional role id
|
2010-07-13 20:58:17 +00:00
|
|
|
* @param int $timestart 0 means unknown
|
|
|
|
* @param int $timeend 0 means forever
|
2010-09-21 10:42:19 +00:00
|
|
|
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
|
2013-03-08 12:26:36 -08:00
|
|
|
* @param bool $recovergrades restore grade history
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2013-03-08 12:26:36 -08:00
|
|
|
public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
global $DB, $USER, $CFG; // CFG necessary!!!
|
|
|
|
|
|
|
|
if ($instance->courseid == SITEID) {
|
|
|
|
throw new coding_exception('invalid attempt to enrol into frontpage course!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
$courseid = $instance->courseid;
|
|
|
|
|
|
|
|
if ($instance->enrol !== $name) {
|
|
|
|
throw new coding_exception('invalid enrol instance!');
|
|
|
|
}
|
2012-07-25 16:25:55 +08:00
|
|
|
$context = context_course::instance($instance->courseid, MUST_EXIST);
|
2013-03-08 12:26:36 -08:00
|
|
|
if (!isset($recovergrades)) {
|
|
|
|
$recovergrades = $CFG->recovergradesdefault;
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
$inserted = false;
|
2011-10-23 20:02:31 +02:00
|
|
|
$updated = false;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if ($ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
|
2011-03-15 17:27:27 +08:00
|
|
|
//only update if timestart or timeend or status are different.
|
2011-03-21 14:02:50 +01:00
|
|
|
if ($ue->timestart != $timestart or $ue->timeend != $timeend or (!is_null($status) and $ue->status != $status)) {
|
2013-08-19 17:03:39 +08:00
|
|
|
$this->update_user_enrol($instance, $userid, $status, $timestart, $timeend);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-09-21 08:07:44 +00:00
|
|
|
$ue = new stdClass();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$ue->enrolid = $instance->id;
|
2011-03-21 14:02:50 +01:00
|
|
|
$ue->status = is_null($status) ? ENROL_USER_ACTIVE : $status;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$ue->userid = $userid;
|
|
|
|
$ue->timestart = $timestart;
|
|
|
|
$ue->timeend = $timeend;
|
2011-05-30 10:10:03 +08:00
|
|
|
$ue->modifierid = $USER->id;
|
2010-07-13 20:58:17 +00:00
|
|
|
$ue->timecreated = time();
|
|
|
|
$ue->timemodified = $ue->timecreated;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$ue->id = $DB->insert_record('user_enrolments', $ue);
|
|
|
|
|
|
|
|
$inserted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($inserted) {
|
2013-08-19 17:03:39 +08:00
|
|
|
// Trigger event.
|
|
|
|
$event = \core\event\user_enrolment_created::create(
|
|
|
|
array(
|
|
|
|
'objectid' => $ue->id,
|
|
|
|
'courseid' => $courseid,
|
|
|
|
'context' => $context,
|
|
|
|
'relateduserid' => $ue->userid,
|
|
|
|
'other' => array('enrol' => $name)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$event->trigger();
|
2015-08-14 12:28:09 +08:00
|
|
|
// Check if course contacts cache needs to be cleared.
|
2018-06-16 11:57:27 +08:00
|
|
|
core_course_category::user_enrolment_changed($courseid, $ue->userid,
|
2015-08-14 12:28:09 +08:00
|
|
|
$ue->status, $ue->timestart, $ue->timeend);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
2024-01-04 12:48:02 +11:00
|
|
|
// Dispatch the hook for post enrol user actions.
|
|
|
|
$hook = new \core_enrol\hook\after_user_enrolled(
|
|
|
|
enrolinstance: $instance,
|
|
|
|
userenrolmentinstance: $ue,
|
|
|
|
);
|
|
|
|
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
|
|
|
|
2011-10-28 14:57:42 +02:00
|
|
|
if ($roleid) {
|
2011-11-05 12:12:48 +01:00
|
|
|
// this must be done after the enrolment event so that the role_assigned event is triggered afterwards
|
2011-10-28 14:57:42 +02:00
|
|
|
if ($this->roles_protected()) {
|
|
|
|
role_assign($roleid, $userid, $context->id, 'enrol_'.$name, $instance->id);
|
|
|
|
} else {
|
|
|
|
role_assign($roleid, $userid, $context->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-08 12:26:36 -08:00
|
|
|
// Recover old grades if present.
|
|
|
|
if ($recovergrades) {
|
|
|
|
require_once("$CFG->libdir/gradelib.php");
|
|
|
|
grade_recover_history_grades($userid, $courseid);
|
|
|
|
}
|
|
|
|
|
2011-11-05 12:12:48 +01:00
|
|
|
// reset current user enrolment caching
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if ($userid == $USER->id) {
|
|
|
|
if (isset($USER->enrol['enrolled'][$courseid])) {
|
|
|
|
unset($USER->enrol['enrolled'][$courseid]);
|
|
|
|
}
|
|
|
|
if (isset($USER->enrol['tempguest'][$courseid])) {
|
|
|
|
unset($USER->enrol['tempguest'][$courseid]);
|
2011-10-14 12:48:00 +02:00
|
|
|
remove_temp_course_roles($context);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store user_enrolments changes and trigger event.
|
|
|
|
*
|
2011-10-23 20:02:31 +02:00
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $userid
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @param int $status
|
|
|
|
* @param int $timestart
|
|
|
|
* @param int $timeend
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function update_user_enrol(stdClass $instance, $userid, $status = NULL, $timestart = NULL, $timeend = NULL) {
|
2015-08-14 12:28:09 +08:00
|
|
|
global $DB, $USER, $CFG;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
|
|
|
|
if ($instance->enrol !== $name) {
|
|
|
|
throw new coding_exception('invalid enrol instance!');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
|
|
|
|
// weird, user not enrolled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$modified = false;
|
2023-03-08 13:39:53 +11:00
|
|
|
$statusmodified = false;
|
|
|
|
$timeendmodified = false;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if (isset($status) and $ue->status != $status) {
|
|
|
|
$ue->status = $status;
|
|
|
|
$modified = true;
|
2023-03-08 13:39:53 +11:00
|
|
|
$statusmodified = true;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
if (isset($timestart) and $ue->timestart != $timestart) {
|
|
|
|
$ue->timestart = $timestart;
|
|
|
|
$modified = true;
|
|
|
|
}
|
|
|
|
if (isset($timeend) and $ue->timeend != $timeend) {
|
|
|
|
$ue->timeend = $timeend;
|
|
|
|
$modified = true;
|
2023-03-08 13:39:53 +11:00
|
|
|
$timeendmodified = true;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$modified) {
|
|
|
|
// no change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-04 12:48:02 +11:00
|
|
|
// Dispatch the hook for pre user enrolment update actions.
|
2024-04-14 21:16:55 +08:00
|
|
|
$hook = new \core_enrol\hook\before_user_enrolment_updated(
|
2024-01-04 12:48:02 +11:00
|
|
|
enrolinstance: $instance,
|
|
|
|
userenrolmentinstance: $ue,
|
|
|
|
statusmodified: $statusmodified,
|
|
|
|
timeendmodified: $timeendmodified,
|
|
|
|
);
|
|
|
|
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
2023-03-08 13:39:53 +11:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$ue->modifierid = $USER->id;
|
2017-03-16 14:23:34 -03:00
|
|
|
$ue->timemodified = time();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$DB->update_record('user_enrolments', $ue);
|
2018-06-05 16:37:25 -04:00
|
|
|
|
|
|
|
// User enrolments have changed, so mark user as dirty.
|
|
|
|
mark_user_dirty($userid);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
2014-06-25 17:33:10 +09:30
|
|
|
// Invalidate core_access cache for get_suspended_userids.
|
2014-07-08 09:52:41 +12:00
|
|
|
cache_helper::invalidate_by_definition('core', 'suspended_userids', array(), array($instance->courseid));
|
2014-06-25 17:33:10 +09:30
|
|
|
|
2013-08-19 17:03:39 +08:00
|
|
|
// Trigger event.
|
|
|
|
$event = \core\event\user_enrolment_updated::create(
|
|
|
|
array(
|
|
|
|
'objectid' => $ue->id,
|
|
|
|
'courseid' => $instance->courseid,
|
|
|
|
'context' => context_course::instance($instance->courseid),
|
|
|
|
'relateduserid' => $ue->userid,
|
|
|
|
'other' => array('enrol' => $name)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$event->trigger();
|
2015-08-14 12:28:09 +08:00
|
|
|
|
2018-06-16 11:57:27 +08:00
|
|
|
core_course_category::user_enrolment_changed($instance->courseid, $ue->userid,
|
2015-08-14 12:28:09 +08:00
|
|
|
$ue->status, $ue->timestart, $ue->timeend);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unenrol user from course,
|
|
|
|
* the last unenrolment removes all remaining roles.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $userid
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function unenrol_user(stdClass $instance, $userid) {
|
|
|
|
global $CFG, $USER, $DB;
|
2012-09-26 17:13:42 +02:00
|
|
|
require_once("$CFG->dirroot/group/lib.php");
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
$courseid = $instance->courseid;
|
|
|
|
|
|
|
|
if ($instance->enrol !== $name) {
|
|
|
|
throw new coding_exception('invalid enrol instance!');
|
|
|
|
}
|
2012-07-25 16:25:55 +08:00
|
|
|
$context = context_course::instance($instance->courseid, MUST_EXIST);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
|
|
|
|
// weird, user not enrolled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-04 12:48:02 +11:00
|
|
|
// Dispatch the hook for pre user unenrolment actions.
|
2024-04-14 21:16:55 +08:00
|
|
|
$hook = new \core_enrol\hook\before_user_enrolment_removed(
|
2024-01-04 12:48:02 +11:00
|
|
|
enrolinstance: $instance,
|
|
|
|
userenrolmentinstance: $ue,
|
|
|
|
);
|
|
|
|
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
|
|
|
|
2012-09-26 17:13:42 +02:00
|
|
|
// Remove all users groups linked to this enrolment instance.
|
|
|
|
if ($gms = $DB->get_records('groups_members', array('userid'=>$userid, 'component'=>'enrol_'.$name, 'itemid'=>$instance->id))) {
|
|
|
|
foreach ($gms as $gm) {
|
|
|
|
groups_remove_member($gm->groupid, $gm->userid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
role_unassign_all(array('userid'=>$userid, 'contextid'=>$context->id, 'component'=>'enrol_'.$name, 'itemid'=>$instance->id));
|
|
|
|
$DB->delete_records('user_enrolments', array('id'=>$ue->id));
|
|
|
|
|
|
|
|
// add extra info and trigger event
|
|
|
|
$ue->courseid = $courseid;
|
|
|
|
$ue->enrol = $name;
|
|
|
|
|
|
|
|
$sql = "SELECT 'x'
|
|
|
|
FROM {user_enrolments} ue
|
|
|
|
JOIN {enrol} e ON (e.id = ue.enrolid)
|
2012-09-26 17:13:42 +02:00
|
|
|
WHERE ue.userid = :userid AND e.courseid = :courseid";
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if ($DB->record_exists_sql($sql, array('userid'=>$userid, 'courseid'=>$courseid))) {
|
|
|
|
$ue->lastenrol = false;
|
2012-09-26 17:13:42 +02:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
} else {
|
|
|
|
// the big cleanup IS necessary!
|
|
|
|
require_once("$CFG->libdir/gradelib.php");
|
|
|
|
|
|
|
|
// remove all remaining roles
|
|
|
|
role_unassign_all(array('userid'=>$userid, 'contextid'=>$context->id), true, false);
|
|
|
|
|
|
|
|
//clean up ALL invisible user data from course if this is the last enrolment - groups, grades, etc.
|
|
|
|
groups_delete_group_members($courseid, $userid);
|
|
|
|
|
|
|
|
grade_user_unenrol($courseid, $userid);
|
|
|
|
|
|
|
|
$DB->delete_records('user_lastaccess', array('userid'=>$userid, 'courseid'=>$courseid));
|
|
|
|
|
2010-07-23 18:39:47 +00:00
|
|
|
$ue->lastenrol = true; // means user not enrolled any more
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
2013-08-19 17:03:39 +08:00
|
|
|
// Trigger event.
|
|
|
|
$event = \core\event\user_enrolment_deleted::create(
|
|
|
|
array(
|
|
|
|
'courseid' => $courseid,
|
|
|
|
'context' => $context,
|
|
|
|
'relateduserid' => $ue->userid,
|
2013-10-02 10:45:28 +08:00
|
|
|
'objectid' => $ue->id,
|
2013-08-19 17:03:39 +08:00
|
|
|
'other' => array(
|
|
|
|
'userenrolment' => (array)$ue,
|
|
|
|
'enrol' => $name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$event->trigger();
|
2018-06-05 16:37:25 -04:00
|
|
|
// User enrolments have changed, so mark user as dirty.
|
|
|
|
mark_user_dirty($userid);
|
2011-11-05 12:12:48 +01:00
|
|
|
|
2015-08-14 12:28:09 +08:00
|
|
|
// Check if courrse contacts cache needs to be cleared.
|
2018-06-16 11:57:27 +08:00
|
|
|
core_course_category::user_enrolment_changed($courseid, $ue->userid, ENROL_USER_SUSPENDED);
|
2015-08-14 12:28:09 +08:00
|
|
|
|
2011-11-05 12:12:48 +01:00
|
|
|
// reset current user enrolment caching
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if ($userid == $USER->id) {
|
|
|
|
if (isset($USER->enrol['enrolled'][$courseid])) {
|
|
|
|
unset($USER->enrol['enrolled'][$courseid]);
|
|
|
|
}
|
|
|
|
if (isset($USER->enrol['tempguest'][$courseid])) {
|
|
|
|
unset($USER->enrol['tempguest'][$courseid]);
|
2011-10-14 12:48:00 +02:00
|
|
|
remove_temp_course_roles($context);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forces synchronisation of user enrolments.
|
|
|
|
*
|
|
|
|
* This is important especially for external enrol plugins,
|
|
|
|
* this function is called for all enabled enrol plugins
|
|
|
|
* right after every user login.
|
|
|
|
*
|
|
|
|
* @param object $user user record
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function sync_user_enrolments($user) {
|
|
|
|
// override if necessary
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:39:17 +08:00
|
|
|
/**
|
|
|
|
* This returns false for backwards compatibility, but it is really recommended.
|
|
|
|
*
|
|
|
|
* @since Moodle 3.1
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function use_standard_editing_ui() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether or not, given the current state, it is possible to add a new instance
|
|
|
|
* of this enrolment plugin to the course.
|
|
|
|
*
|
|
|
|
* Default implementation is just for backwards compatibility.
|
|
|
|
*
|
|
|
|
* @param int $courseid
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function can_add_instance($courseid) {
|
|
|
|
$link = $this->get_newinstance_link($courseid);
|
|
|
|
return !empty($link);
|
|
|
|
}
|
|
|
|
|
2016-02-29 13:53:29 +08:00
|
|
|
/**
|
|
|
|
* Return whether or not, given the current state, it is possible to edit an instance
|
|
|
|
* of this enrolment plugin in the course. Used by the standard editing UI
|
|
|
|
* to generate a link to the edit instance form if editing is allowed.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function can_edit_instance($instance) {
|
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
|
|
|
|
return has_capability('enrol/' . $instance->enrol . ':config', $context);
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Returns link to page which may be used to add new instance of enrolment plugin in course.
|
|
|
|
* @param int $courseid
|
2024-02-05 15:20:28 +00:00
|
|
|
* @return ?moodle_url page url
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
2010-07-31 20:02:56 +00:00
|
|
|
public function get_newinstance_link($courseid) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
// override for most plugins, check if instance already exists in cases only one instance is supported
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-16 16:39:18 -02:00
|
|
|
* @deprecated since Moodle 2.8 MDL-35864 - please use can_delete_instance() instead.
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
public function instance_deleteable($instance) {
|
2015-05-26 12:42:46 +05:30
|
|
|
throw new coding_exception('Function enrol_plugin::instance_deleteable() is deprecated, use
|
|
|
|
enrol_plugin::can_delete_instance() instead');
|
2013-12-16 16:39:18 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is it possible to delete enrol instance via standard UI?
|
|
|
|
*
|
2014-08-11 16:04:03 -03:00
|
|
|
* @param stdClass $instance
|
2013-12-16 16:39:18 -02:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function can_delete_instance($instance) {
|
|
|
|
return false;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 16:04:03 -03:00
|
|
|
/**
|
|
|
|
* Is it possible to hide/show enrol instance via standard UI?
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function can_hide_show_instance($instance) {
|
|
|
|
debugging("The enrolment plugin '".$this->get_name()."' should override the function can_hide_show_instance().", DEBUG_DEVELOPER);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Returns link to manual enrol UI if exists.
|
|
|
|
* Does the access control tests automatically.
|
|
|
|
*
|
|
|
|
* @param object $instance
|
2024-02-05 15:20:28 +00:00
|
|
|
* @return ?moodle_url
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
public function get_manual_enrol_link($instance) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns list of unenrol links for all enrol instances in course.
|
|
|
|
*
|
2023-02-28 13:13:42 +00:00
|
|
|
* @param stdClass $instance
|
2024-02-05 15:20:28 +00:00
|
|
|
* @return ?moodle_url or NULL if self unenrolment not supported
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
public function get_unenrolself_link($instance) {
|
|
|
|
global $USER, $CFG, $DB;
|
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
if ($instance->enrol !== $name) {
|
|
|
|
throw new coding_exception('invalid enrol instance!');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($instance->courseid == SITEID) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!enrol_is_enabled($name)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file_exists("$CFG->dirroot/enrol/$name/unenrolself.php")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-25 16:25:55 +08:00
|
|
|
$context = context_course::instance($instance->courseid, MUST_EXIST);
|
2010-07-13 17:04:17 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if (!has_capability("enrol/$name:unenrolself", $context)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$USER->id, 'status'=>ENROL_USER_ACTIVE))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-15 09:51:26 +08:00
|
|
|
return new moodle_url("/enrol/$name/unenrolself.php", array('enrolid'=>$instance->id));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds enrol instance UI to course edit form
|
|
|
|
*
|
|
|
|
* @param object $instance enrol instance or null if does not exist yet
|
|
|
|
* @param MoodleQuickForm $mform
|
|
|
|
* @param object $data
|
|
|
|
* @param object $context context of existing course or parent category if course does not exist
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function course_edit_form($instance, MoodleQuickForm $mform, $data, $context) {
|
|
|
|
// override - usually at least enable/disable switch, has to add own form header
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:39:17 +08:00
|
|
|
/**
|
|
|
|
* Adds form elements to add/edit instance form.
|
|
|
|
*
|
|
|
|
* @since Moodle 3.1
|
|
|
|
* @param object $instance enrol instance or null if does not exist yet
|
|
|
|
* @param MoodleQuickForm $mform
|
|
|
|
* @param context $context
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function edit_instance_form($instance, MoodleQuickForm $mform, $context) {
|
|
|
|
// Do nothing by default.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform custom validation of the data used to edit the instance.
|
|
|
|
*
|
|
|
|
* @since Moodle 3.1
|
|
|
|
* @param array $data array of ("fieldname"=>value) of submitted data
|
|
|
|
* @param array $files array of uploaded files "element_name"=>tmp_file_path
|
|
|
|
* @param object $instance The instance data loaded from the DB.
|
|
|
|
* @param context $context The context of the instance we are editing
|
|
|
|
* @return array of "element_name"=>"error_description" if there are errors,
|
|
|
|
* or an empty array if everything is OK.
|
|
|
|
*/
|
|
|
|
public function edit_instance_validation($data, $files, $instance, $context) {
|
|
|
|
// No errors by default.
|
|
|
|
debugging('enrol_plugin::edit_instance_validation() is missing. This plugin has no validation!', DEBUG_DEVELOPER);
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Validates course edit form data
|
|
|
|
*
|
|
|
|
* @param object $instance enrol instance or null if does not exist yet
|
|
|
|
* @param array $data
|
|
|
|
* @param object $context context of existing course or parent category if course does not exist
|
|
|
|
* @return array errors array
|
|
|
|
*/
|
|
|
|
public function course_edit_validation($instance, array $data, $context) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after updating/inserting course.
|
|
|
|
*
|
|
|
|
* @param bool $inserted true if course just inserted
|
|
|
|
* @param object $course
|
|
|
|
* @param object $data form data
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function course_updated($inserted, $course, $data) {
|
2010-07-31 12:13:38 +00:00
|
|
|
if ($inserted) {
|
|
|
|
if ($this->get_config('defaultenrol')) {
|
|
|
|
$this->add_default_instance($course);
|
|
|
|
}
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-31 12:13:38 +00:00
|
|
|
* Add new instance of enrol plugin.
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* @param object $course
|
|
|
|
* @param array instance fields
|
2010-07-31 12:20:23 +00:00
|
|
|
* @return int id of new instance, null if can not be created
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
public function add_instance($course, array $fields = NULL) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
if ($course->id == SITEID) {
|
|
|
|
throw new coding_exception('Invalid request to add enrol instance to frontpage.');
|
|
|
|
}
|
|
|
|
|
2010-09-21 08:07:44 +00:00
|
|
|
$instance = new stdClass();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$instance->enrol = $this->get_name();
|
|
|
|
$instance->status = ENROL_INSTANCE_ENABLED;
|
|
|
|
$instance->courseid = $course->id;
|
|
|
|
$instance->enrolstartdate = 0;
|
|
|
|
$instance->enrolenddate = 0;
|
|
|
|
$instance->timemodified = time();
|
|
|
|
$instance->timecreated = $instance->timemodified;
|
|
|
|
$instance->sortorder = $DB->get_field('enrol', 'COALESCE(MAX(sortorder), -1) + 1', array('courseid'=>$course->id));
|
|
|
|
|
|
|
|
$fields = (array)$fields;
|
|
|
|
unset($fields['enrol']);
|
|
|
|
unset($fields['courseid']);
|
|
|
|
unset($fields['sortorder']);
|
|
|
|
foreach($fields as $field=>$value) {
|
|
|
|
$instance->$field = $value;
|
|
|
|
}
|
|
|
|
|
2015-08-24 16:28:57 +08:00
|
|
|
$instance->id = $DB->insert_record('enrol', $instance);
|
|
|
|
|
|
|
|
\core\event\enrol_instance_created::create_from_record($instance)->trigger();
|
|
|
|
|
|
|
|
return $instance->id;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 15:39:17 +08:00
|
|
|
/**
|
|
|
|
* Update instance of enrol plugin.
|
|
|
|
*
|
|
|
|
* @since Moodle 3.1
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param stdClass $data modified instance fields
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function update_instance($instance, $data) {
|
|
|
|
global $DB;
|
|
|
|
$properties = array('status', 'name', 'password', 'customint1', 'customint2', 'customint3',
|
|
|
|
'customint4', 'customint5', 'customint6', 'customint7', 'customint8',
|
|
|
|
'customchar1', 'customchar2', 'customchar3', 'customdec1', 'customdec2',
|
|
|
|
'customtext1', 'customtext2', 'customtext3', 'customtext4', 'roleid',
|
|
|
|
'enrolperiod', 'expirynotify', 'notifyall', 'expirythreshold',
|
|
|
|
'enrolstartdate', 'enrolenddate', 'cost', 'currency');
|
|
|
|
|
|
|
|
foreach ($properties as $key) {
|
|
|
|
if (isset($data->$key)) {
|
|
|
|
$instance->$key = $data->$key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$instance->timemodified = time();
|
|
|
|
|
|
|
|
$update = $DB->update_record('enrol', $instance);
|
|
|
|
if ($update) {
|
|
|
|
\core\event\enrol_instance_updated::create_from_record($instance)->trigger();
|
|
|
|
}
|
|
|
|
return $update;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Add new instance of enrol plugin with default settings,
|
|
|
|
* called when adding new instance manually or when adding new course.
|
|
|
|
*
|
|
|
|
* Not all plugins support this.
|
|
|
|
*
|
|
|
|
* @param object $course
|
2024-02-05 15:20:28 +00:00
|
|
|
* @return ?int id of new instance or null if no default supported
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
public function add_default_instance($course) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-08-04 17:01:59 +08:00
|
|
|
/**
|
|
|
|
* Add new instance of enrol plugin with custom settings,
|
|
|
|
* called when adding new instance manually or when adding new course.
|
|
|
|
* Used for example on course upload.
|
|
|
|
*
|
|
|
|
* Not all plugins support this.
|
|
|
|
*
|
|
|
|
* @param stdClass $course Course object
|
|
|
|
* @param array|null $fields instance fields
|
|
|
|
* @return int|null id of new instance or null if not supported
|
|
|
|
*/
|
|
|
|
public function add_custom_instance(stdClass $course, ?array $fields = null): ?int {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if enrolment plugin is supported in csv course upload.
|
|
|
|
*
|
2024-01-31 11:29:33 +11:00
|
|
|
* If supported, plugins are also encouraged to override methods:
|
|
|
|
* {@see self::fill_enrol_custom_fields()}, {@see self::validate_plugin_data_context()}
|
|
|
|
*
|
2023-08-04 17:01:59 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function is_csv_upload_supported(): bool {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-18 17:02:16 +01:00
|
|
|
/**
|
|
|
|
* Update instance status
|
|
|
|
*
|
|
|
|
* Override when plugin needs to do some action when enabled or disabled.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $newstatus ENROL_INSTANCE_ENABLED, ENROL_INSTANCE_DISABLED
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function update_status($instance, $newstatus) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$instance->status = $newstatus;
|
|
|
|
$DB->update_record('enrol', $instance);
|
|
|
|
|
2024-01-04 12:48:02 +11:00
|
|
|
// Dispatch the hook for post enrol status update actions.
|
|
|
|
$hook = new \core_enrol\hook\after_enrol_instance_status_updated(
|
|
|
|
enrolinstance: $instance,
|
|
|
|
newstatus: $newstatus,
|
|
|
|
);
|
|
|
|
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
|
|
|
|
2011-12-18 17:02:16 +01:00
|
|
|
$context = context_course::instance($instance->courseid);
|
2015-08-24 16:28:57 +08:00
|
|
|
\core\event\enrol_instance_updated::create_from_record($instance)->trigger();
|
|
|
|
|
|
|
|
// Invalidate all enrol caches.
|
2011-12-18 17:02:16 +01:00
|
|
|
$context->mark_dirty();
|
|
|
|
}
|
|
|
|
|
2023-03-08 13:39:53 +11:00
|
|
|
/**
|
|
|
|
* Update instance members.
|
|
|
|
*
|
|
|
|
* Update communication room membership for an instance action being performed.
|
|
|
|
*
|
2024-01-04 12:48:02 +11:00
|
|
|
* @param int $enrolmentinstanceid ID of the enrolment instance
|
2023-03-08 13:39:53 +11:00
|
|
|
* @param string $action The update action being performed
|
2024-01-04 12:48:02 +11:00
|
|
|
* @param stdClass $course The course object
|
2023-03-08 13:39:53 +11:00
|
|
|
* @return void
|
2024-01-04 12:48:02 +11:00
|
|
|
* @deprecated Since Moodle 4.4.0.
|
|
|
|
* @see \core_communication\hook_listener::update_communication_memberships_for_enrol_status_change()
|
|
|
|
* @todo MDL-80491 Final deprecation in Moodle 4.8.
|
|
|
|
*
|
2023-03-08 13:39:53 +11:00
|
|
|
*/
|
2024-01-04 12:48:02 +11:00
|
|
|
public function update_communication(int $enrolmentinstanceid, string $action, stdClass $course): void {
|
|
|
|
debugging('Use of method update_communication is deprecated. This feature has been moved to
|
|
|
|
core_communication as a part of hooks api implementation so that plugins or core does not need to call this method anymore.
|
|
|
|
Method update_communication_memberships_for_enrol_status_change method in communication/classes/hook_listener.php
|
|
|
|
now handles all the operations related to this method using hooks callback recorded in lib/db/hooks.php.', DEBUG_DEVELOPER);
|
|
|
|
return;
|
2023-03-08 13:39:53 +11:00
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Delete course enrol plugin instance, unenrol all users.
|
|
|
|
* @param object $instance
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function delete_instance($instance) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
if ($instance->enrol !== $name) {
|
|
|
|
throw new coding_exception('invalid enrol instance!');
|
|
|
|
}
|
|
|
|
|
2024-01-04 12:48:02 +11:00
|
|
|
// Dispatch the hook for pre enrol instance delete actions.
|
2024-04-14 21:16:55 +08:00
|
|
|
$hook = new \core_enrol\hook\before_enrol_instance_deleted(
|
2024-01-04 12:48:02 +11:00
|
|
|
enrolinstance: $instance,
|
|
|
|
);
|
|
|
|
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
//first unenrol all users
|
|
|
|
$participants = $DB->get_recordset('user_enrolments', array('enrolid'=>$instance->id));
|
|
|
|
foreach ($participants as $participant) {
|
|
|
|
$this->unenrol_user($instance, $participant->userid);
|
|
|
|
}
|
|
|
|
$participants->close();
|
|
|
|
|
|
|
|
// now clean up all remainders that were not removed correctly
|
2017-11-23 23:15:27 +08:00
|
|
|
if ($gms = $DB->get_records('groups_members', array('itemid' => $instance->id, 'component' => 'enrol_' . $name))) {
|
|
|
|
foreach ($gms as $gm) {
|
|
|
|
groups_remove_member($gm->groupid, $gm->userid);
|
|
|
|
}
|
|
|
|
}
|
2012-10-06 19:22:07 +02:00
|
|
|
$DB->delete_records('role_assignments', array('itemid'=>$instance->id, 'component'=>'enrol_'.$name));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$DB->delete_records('user_enrolments', array('enrolid'=>$instance->id));
|
|
|
|
|
|
|
|
// finally drop the enrol row
|
|
|
|
$DB->delete_records('enrol', array('id'=>$instance->id));
|
2011-12-18 17:02:16 +01:00
|
|
|
|
|
|
|
$context = context_course::instance($instance->courseid);
|
2015-08-24 16:28:57 +08:00
|
|
|
\core\event\enrol_instance_deleted::create_from_record($instance)->trigger();
|
|
|
|
|
|
|
|
// Invalidate all enrol caches.
|
2011-12-18 17:02:16 +01:00
|
|
|
$context->mark_dirty();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates course enrol form, checks if form submitted
|
|
|
|
* and enrols user if necessary. It can also redirect.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @return string html text, usually a form in a text box
|
|
|
|
*/
|
|
|
|
public function enrol_page_hook(stdClass $instance) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:35:53 +08:00
|
|
|
/**
|
|
|
|
* Checks if user can self enrol.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance enrolment instance
|
2013-06-17 11:07:51 +08:00
|
|
|
* @param bool $checkuserenrolment if true will check if user enrolment is inactive.
|
|
|
|
* used by navigation to improve performance.
|
|
|
|
* @return bool|string true if successful, else error message or false
|
2013-06-14 15:35:53 +08:00
|
|
|
*/
|
2013-06-17 11:07:51 +08:00
|
|
|
public function can_self_enrol(stdClass $instance, $checkuserenrolment = true) {
|
2013-06-14 15:35:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return information for enrolment instance containing list of parameters required
|
|
|
|
* for enrolment, name of enrolment plugin etc.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance enrolment instance
|
2023-02-28 13:13:42 +00:00
|
|
|
* @return stdClass|null instance info.
|
2013-06-14 15:35:53 +08:00
|
|
|
*/
|
|
|
|
public function get_enrol_info(stdClass $instance) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
/**
|
|
|
|
* Adds navigation links into course admin block.
|
|
|
|
*
|
|
|
|
* By defaults looks for manage links only.
|
|
|
|
*
|
|
|
|
* @param navigation_node $instancesnode
|
2011-11-05 12:12:48 +01:00
|
|
|
* @param stdClass $instance
|
2010-07-31 09:58:36 +00:00
|
|
|
* @return void
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
|
|
|
public function add_course_navigation($instancesnode, stdClass $instance) {
|
2016-02-29 14:29:00 +08:00
|
|
|
if ($this->use_standard_editing_ui()) {
|
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
$cap = 'enrol/' . $instance->enrol . ':config';
|
|
|
|
if (has_capability($cap, $context)) {
|
|
|
|
$linkparams = array('courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol);
|
|
|
|
$managelink = new moodle_url('/enrol/editinstance.php', $linkparams);
|
|
|
|
$instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
|
|
|
|
}
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-31 09:58:36 +00:00
|
|
|
* Returns edit icons for the page with list of instances
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @return array
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
*/
|
2010-07-31 09:58:36 +00:00
|
|
|
public function get_action_icons(stdClass $instance) {
|
2016-02-29 13:53:29 +08:00
|
|
|
global $OUTPUT;
|
|
|
|
|
|
|
|
$icons = array();
|
|
|
|
if ($this->use_standard_editing_ui()) {
|
2022-11-16 13:41:53 +01:00
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
$cap = 'enrol/' . $instance->enrol . ':config';
|
|
|
|
if (has_capability($cap, $context)) {
|
|
|
|
$linkparams = array('courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol);
|
|
|
|
$editlink = new moodle_url("/enrol/editinstance.php", $linkparams);
|
|
|
|
$icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core',
|
|
|
|
array('class' => 'iconsmall')));
|
|
|
|
}
|
2016-02-29 13:53:29 +08:00
|
|
|
}
|
|
|
|
return $icons;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads version.php and determines if it is necessary
|
|
|
|
* to execute the cron job now.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function is_cron_required() {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
$versionfile = "$CFG->dirroot/enrol/$name/version.php";
|
2010-09-21 08:07:44 +00:00
|
|
|
$plugin = new stdClass();
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
include($versionfile);
|
|
|
|
if (empty($plugin->cron)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$lastexecuted = $this->get_config('lastcron', 0);
|
|
|
|
if ($lastexecuted + $plugin->cron < time()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for all enabled enrol plugins that returned true from is_cron_required().
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function cron() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when user is about to be deleted
|
|
|
|
* @param object $user
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function user_delete($user) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$sql = "SELECT e.*
|
|
|
|
FROM {enrol} e
|
2010-10-08 08:47:04 +00:00
|
|
|
JOIN {user_enrolments} ue ON (ue.enrolid = e.id)
|
|
|
|
WHERE e.enrol = :name AND ue.userid = :userid";
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$params = array('name'=>$this->get_name(), 'userid'=>$user->id);
|
|
|
|
|
2010-10-08 08:47:04 +00:00
|
|
|
$rs = $DB->get_recordset_sql($sql, $params);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
foreach($rs as $instance) {
|
|
|
|
$this->unenrol_user($instance, $user->id);
|
|
|
|
}
|
|
|
|
$rs->close();
|
|
|
|
}
|
|
|
|
|
2011-04-06 15:34:12 +08:00
|
|
|
/**
|
|
|
|
* Returns an enrol_user_button that takes the user to a page where they are able to
|
|
|
|
* enrol users into the managers course through this plugin.
|
|
|
|
*
|
|
|
|
* Optional: If the plugin supports manual enrolments it can choose to override this
|
|
|
|
* otherwise it shouldn't
|
|
|
|
*
|
|
|
|
* @param course_enrolment_manager $manager
|
|
|
|
* @return enrol_user_button|false
|
|
|
|
*/
|
|
|
|
public function get_manual_enrol_button(course_enrolment_manager $manager) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-07 12:20:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array of the user enrolment actions
|
|
|
|
*
|
|
|
|
* @param course_enrolment_manager $manager
|
|
|
|
* @param stdClass $ue
|
|
|
|
* @return array An array of user_enrolment_actions
|
|
|
|
*/
|
|
|
|
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
|
2017-08-23 15:17:49 +08:00
|
|
|
$actions = [];
|
|
|
|
$context = $manager->get_context();
|
|
|
|
$instance = $ue->enrolmentinstance;
|
|
|
|
$params = $manager->get_moodlepage()->url->params();
|
|
|
|
$params['ue'] = $ue->id;
|
|
|
|
|
|
|
|
// Edit enrolment action.
|
|
|
|
if ($this->allow_manage($instance) && has_capability("enrol/{$instance->enrol}:manage", $context)) {
|
|
|
|
$title = get_string('editenrolment', 'enrol');
|
|
|
|
$icon = new pix_icon('t/edit', $title);
|
|
|
|
$url = new moodle_url('/enrol/editenrolment.php', $params);
|
|
|
|
$actionparams = [
|
|
|
|
'class' => 'editenrollink',
|
|
|
|
'rel' => $ue->id,
|
|
|
|
'data-action' => ENROL_ACTION_EDIT
|
|
|
|
];
|
|
|
|
$actions[] = new user_enrolment_action($icon, $title, $url, $actionparams);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unenrol action.
|
|
|
|
if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/{$instance->enrol}:unenrol", $context)) {
|
|
|
|
$title = get_string('unenrol', 'enrol');
|
|
|
|
$icon = new pix_icon('t/delete', $title);
|
|
|
|
$url = new moodle_url('/enrol/unenroluser.php', $params);
|
|
|
|
$actionparams = [
|
|
|
|
'class' => 'unenrollink',
|
|
|
|
'rel' => $ue->id,
|
|
|
|
'data-action' => ENROL_ACTION_UNENROL
|
|
|
|
];
|
|
|
|
$actions[] = new user_enrolment_action($icon, $title, $url, $actionparams);
|
|
|
|
}
|
|
|
|
return $actions;
|
2011-04-07 12:20:38 +08:00
|
|
|
}
|
2011-04-20 16:52:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the plugin has one or more bulk operations that can be performed on
|
|
|
|
* user enrolments.
|
|
|
|
*
|
2012-03-18 18:37:24 +01:00
|
|
|
* @param course_enrolment_manager $manager
|
2011-04-20 16:52:33 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
2012-03-18 18:37:24 +01:00
|
|
|
public function has_bulk_operations(course_enrolment_manager $manager) {
|
2011-04-20 16:52:33 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of enrol_bulk_enrolment_operation objects that define
|
|
|
|
* the bulk actions that can be performed on user enrolments by the plugin.
|
|
|
|
*
|
2012-03-18 18:37:24 +01:00
|
|
|
* @param course_enrolment_manager $manager
|
2011-04-20 16:52:33 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
2012-03-18 18:37:24 +01:00
|
|
|
public function get_bulk_operations(course_enrolment_manager $manager) {
|
2011-04-20 16:52:33 +08:00
|
|
|
return array();
|
|
|
|
}
|
2012-08-31 14:15:04 +02:00
|
|
|
|
2013-01-26 14:55:11 +01:00
|
|
|
/**
|
|
|
|
* Do any enrolments need expiration processing.
|
|
|
|
*
|
|
|
|
* Plugins that want to call this functionality must implement 'expiredaction' config setting.
|
|
|
|
*
|
|
|
|
* @param progress_trace $trace
|
|
|
|
* @param int $courseid one course, empty mean all
|
|
|
|
* @return bool true if any data processed, false if not
|
|
|
|
*/
|
|
|
|
public function process_expirations(progress_trace $trace, $courseid = null) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
if (!enrol_is_enabled($name)) {
|
|
|
|
$trace->finished();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$processed = false;
|
|
|
|
$params = array();
|
|
|
|
$coursesql = "";
|
|
|
|
if ($courseid) {
|
|
|
|
$coursesql = "AND e.courseid = :courseid";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal with expired accounts.
|
|
|
|
$action = $this->get_config('expiredaction', ENROL_EXT_REMOVED_KEEP);
|
|
|
|
|
|
|
|
if ($action == ENROL_EXT_REMOVED_UNENROL) {
|
|
|
|
$instances = array();
|
|
|
|
$sql = "SELECT ue.*, e.courseid, c.id AS contextid
|
|
|
|
FROM {user_enrolments} ue
|
|
|
|
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = :enrol)
|
|
|
|
JOIN {context} c ON (c.instanceid = e.courseid AND c.contextlevel = :courselevel)
|
|
|
|
WHERE ue.timeend > 0 AND ue.timeend < :now $coursesql";
|
|
|
|
$params = array('now'=>time(), 'courselevel'=>CONTEXT_COURSE, 'enrol'=>$name, 'courseid'=>$courseid);
|
|
|
|
|
|
|
|
$rs = $DB->get_recordset_sql($sql, $params);
|
|
|
|
foreach ($rs as $ue) {
|
|
|
|
if (!$processed) {
|
|
|
|
$trace->output("Starting processing of enrol_$name expirations...");
|
|
|
|
$processed = true;
|
|
|
|
}
|
|
|
|
if (empty($instances[$ue->enrolid])) {
|
|
|
|
$instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
|
|
|
|
}
|
|
|
|
$instance = $instances[$ue->enrolid];
|
|
|
|
if (!$this->roles_protected()) {
|
|
|
|
// Let's just guess what extra roles are supposed to be removed.
|
|
|
|
if ($instance->roleid) {
|
|
|
|
role_unassign($instance->roleid, $ue->userid, $ue->contextid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The unenrol cleans up all subcontexts if this is the only course enrolment for this user.
|
|
|
|
$this->unenrol_user($instance, $ue->userid);
|
|
|
|
$trace->output("Unenrolling expired user $ue->userid from course $instance->courseid", 1);
|
|
|
|
}
|
|
|
|
$rs->close();
|
|
|
|
unset($instances);
|
|
|
|
|
|
|
|
} else if ($action == ENROL_EXT_REMOVED_SUSPENDNOROLES or $action == ENROL_EXT_REMOVED_SUSPEND) {
|
|
|
|
$instances = array();
|
|
|
|
$sql = "SELECT ue.*, e.courseid, c.id AS contextid
|
|
|
|
FROM {user_enrolments} ue
|
|
|
|
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = :enrol)
|
|
|
|
JOIN {context} c ON (c.instanceid = e.courseid AND c.contextlevel = :courselevel)
|
|
|
|
WHERE ue.timeend > 0 AND ue.timeend < :now
|
|
|
|
AND ue.status = :useractive $coursesql";
|
|
|
|
$params = array('now'=>time(), 'courselevel'=>CONTEXT_COURSE, 'useractive'=>ENROL_USER_ACTIVE, 'enrol'=>$name, 'courseid'=>$courseid);
|
|
|
|
$rs = $DB->get_recordset_sql($sql, $params);
|
|
|
|
foreach ($rs as $ue) {
|
|
|
|
if (!$processed) {
|
|
|
|
$trace->output("Starting processing of enrol_$name expirations...");
|
|
|
|
$processed = true;
|
|
|
|
}
|
|
|
|
if (empty($instances[$ue->enrolid])) {
|
|
|
|
$instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
|
|
|
|
}
|
|
|
|
$instance = $instances[$ue->enrolid];
|
|
|
|
|
|
|
|
if ($action == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
|
|
|
if (!$this->roles_protected()) {
|
|
|
|
// Let's just guess what roles should be removed.
|
|
|
|
$count = $DB->count_records('role_assignments', array('userid'=>$ue->userid, 'contextid'=>$ue->contextid));
|
|
|
|
if ($count == 1) {
|
|
|
|
role_unassign_all(array('userid'=>$ue->userid, 'contextid'=>$ue->contextid, 'component'=>'', 'itemid'=>0));
|
|
|
|
|
|
|
|
} else if ($count > 1 and $instance->roleid) {
|
|
|
|
role_unassign($instance->roleid, $ue->userid, $ue->contextid, '', 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// In any case remove all roles that belong to this instance and user.
|
|
|
|
role_unassign_all(array('userid'=>$ue->userid, 'contextid'=>$ue->contextid, 'component'=>'enrol_'.$name, 'itemid'=>$instance->id), true);
|
|
|
|
// Final cleanup of subcontexts if there are no more course roles.
|
|
|
|
if (0 == $DB->count_records('role_assignments', array('userid'=>$ue->userid, 'contextid'=>$ue->contextid))) {
|
|
|
|
role_unassign_all(array('userid'=>$ue->userid, 'contextid'=>$ue->contextid, 'component'=>'', 'itemid'=>0), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->update_user_enrol($instance, $ue->userid, ENROL_USER_SUSPENDED);
|
|
|
|
$trace->output("Suspending expired user $ue->userid in course $instance->courseid", 1);
|
|
|
|
}
|
|
|
|
$rs->close();
|
|
|
|
unset($instances);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// ENROL_EXT_REMOVED_KEEP means no changes.
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($processed) {
|
|
|
|
$trace->output("...finished processing of enrol_$name expirations");
|
|
|
|
} else {
|
|
|
|
$trace->output("No expired enrol_$name enrolments detected");
|
|
|
|
}
|
|
|
|
$trace->finished();
|
|
|
|
|
|
|
|
return $processed;
|
|
|
|
}
|
|
|
|
|
2012-10-13 22:23:35 +02:00
|
|
|
/**
|
|
|
|
* Send expiry notifications.
|
|
|
|
*
|
|
|
|
* Plugin that wants to have expiry notification MUST implement following:
|
|
|
|
* - expirynotifyhour plugin setting,
|
|
|
|
* - configuration options in instance edit form (expirynotify, notifyall and expirythreshold),
|
|
|
|
* - notification strings (expirymessageenrollersubject, expirymessageenrollerbody,
|
|
|
|
* expirymessageenrolledsubject and expirymessageenrolledbody),
|
|
|
|
* - expiry_notification provider in db/messages.php,
|
|
|
|
* - upgrade code that sets default thresholds for existing courses (should be 1 day),
|
|
|
|
* - something that calls this method, such as cron.
|
|
|
|
*
|
2012-12-25 15:44:35 +01:00
|
|
|
* @param progress_trace $trace (accepts bool for backwards compatibility only)
|
2012-10-13 22:23:35 +02:00
|
|
|
*/
|
2012-12-25 15:44:35 +01:00
|
|
|
public function send_expiry_notifications($trace) {
|
2019-08-19 16:30:09 +01:00
|
|
|
global $CFG;
|
2012-10-13 22:23:35 +02:00
|
|
|
|
2013-01-26 14:55:11 +01:00
|
|
|
$name = $this->get_name();
|
|
|
|
if (!enrol_is_enabled($name)) {
|
|
|
|
$trace->finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-13 22:23:35 +02:00
|
|
|
// Unfortunately this may take a long time, it should not be interrupted,
|
|
|
|
// otherwise users get duplicate notification.
|
|
|
|
|
2013-10-15 13:22:19 +01:00
|
|
|
core_php_time_limit::raise();
|
2012-10-13 22:23:35 +02:00
|
|
|
raise_memory_limit(MEMORY_HUGE);
|
|
|
|
|
|
|
|
|
|
|
|
$expirynotifylast = $this->get_config('expirynotifylast', 0);
|
|
|
|
$expirynotifyhour = $this->get_config('expirynotifyhour');
|
|
|
|
if (is_null($expirynotifyhour)) {
|
|
|
|
debugging("send_expiry_notifications() in $name enrolment plugin needs expirynotifyhour setting");
|
2012-12-25 15:44:35 +01:00
|
|
|
$trace->finished();
|
2012-10-13 22:23:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-25 15:44:35 +01:00
|
|
|
if (!($trace instanceof progress_trace)) {
|
|
|
|
$trace = $trace ? new text_progress_trace() : new null_progress_trace();
|
|
|
|
debugging('enrol_plugin::send_expiry_notifications() now expects progress_trace instance as parameter!', DEBUG_DEVELOPER);
|
|
|
|
}
|
|
|
|
|
2012-10-13 22:23:35 +02:00
|
|
|
$timenow = time();
|
|
|
|
$notifytime = usergetmidnight($timenow, $CFG->timezone) + ($expirynotifyhour * 3600);
|
|
|
|
|
|
|
|
if ($expirynotifylast > $notifytime) {
|
2012-12-25 15:44:35 +01:00
|
|
|
$trace->output($name.' enrolment expiry notifications were already sent today at '.userdate($expirynotifylast, '', $CFG->timezone).'.');
|
|
|
|
$trace->finished();
|
2012-10-13 22:23:35 +02:00
|
|
|
return;
|
2012-12-25 15:44:35 +01:00
|
|
|
|
2012-10-13 22:23:35 +02:00
|
|
|
} else if ($timenow < $notifytime) {
|
2012-12-25 15:44:35 +01:00
|
|
|
$trace->output($name.' enrolment expiry notifications will be sent at '.userdate($notifytime, '', $CFG->timezone).'.');
|
|
|
|
$trace->finished();
|
2012-10-13 22:23:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-25 15:44:35 +01:00
|
|
|
$trace->output('Processing '.$name.' enrolment expiration notifications...');
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
// Notify users responsible for enrolment once every day.
|
2019-08-19 16:30:09 +01:00
|
|
|
$this->fetch_users_and_notify_expiry($timenow, $name, $trace);
|
|
|
|
|
|
|
|
$trace->output('...notification processing finished.');
|
|
|
|
$trace->finished();
|
|
|
|
|
|
|
|
$this->set_config('expirynotifylast', $timenow);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify users about enrolment expiration.
|
|
|
|
*
|
|
|
|
* Retrieves enrolment data from the database and notifies users about their
|
|
|
|
* upcoming course enrolment expiration based on expiry thresholds and notification settings.
|
|
|
|
*
|
|
|
|
* @param int $timenow Current time.
|
|
|
|
* @param string $name Name of this enrol plugin.
|
|
|
|
* @param progress_trace $trace (accepts bool for backwards compatibility only).
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function fetch_users_and_notify_expiry(int $timenow, string $name, progress_trace $trace): void {
|
|
|
|
global $DB, $CFG;
|
|
|
|
|
2012-10-13 22:23:35 +02:00
|
|
|
$sql = "SELECT ue.*, e.expirynotify, e.notifyall, e.expirythreshold, e.courseid, c.fullname
|
|
|
|
FROM {user_enrolments} ue
|
|
|
|
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = :name AND e.expirynotify > 0 AND e.status = :enabled)
|
|
|
|
JOIN {course} c ON (c.id = e.courseid)
|
|
|
|
JOIN {user} u ON (u.id = ue.userid AND u.deleted = 0 AND u.suspended = 0)
|
|
|
|
WHERE ue.status = :active AND ue.timeend > 0 AND ue.timeend > :now1 AND ue.timeend < (e.expirythreshold + :now2)
|
|
|
|
ORDER BY ue.enrolid ASC, u.lastname ASC, u.firstname ASC, u.id ASC";
|
2019-08-19 16:30:09 +01:00
|
|
|
$params = [
|
|
|
|
'enabled' => ENROL_INSTANCE_ENABLED,
|
|
|
|
'active' => ENROL_USER_ACTIVE,
|
|
|
|
'now1' => $timenow,
|
|
|
|
'now2' => $timenow,
|
|
|
|
'name' => $name,
|
|
|
|
];
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
$rs = $DB->get_recordset_sql($sql, $params);
|
|
|
|
|
|
|
|
$lastenrollid = 0;
|
2019-08-19 16:30:09 +01:00
|
|
|
$users = [];
|
2012-10-13 22:23:35 +02:00
|
|
|
|
2019-08-19 16:30:09 +01:00
|
|
|
foreach ($rs as $ue) {
|
|
|
|
if ($lastenrollid && $lastenrollid != $ue->enrolid) {
|
2012-12-25 15:44:35 +01:00
|
|
|
$this->notify_expiry_enroller($lastenrollid, $users, $trace);
|
2019-08-19 16:30:09 +01:00
|
|
|
$users = [];
|
2012-10-13 22:23:35 +02:00
|
|
|
}
|
|
|
|
$lastenrollid = $ue->enrolid;
|
|
|
|
|
|
|
|
$enroller = $this->get_enroller($ue->enrolid);
|
|
|
|
$context = context_course::instance($ue->courseid);
|
|
|
|
|
2019-08-19 16:30:09 +01:00
|
|
|
$user = $DB->get_record('user', ['id' => $ue->userid]);
|
2012-10-13 22:23:35 +02:00
|
|
|
|
2019-08-19 16:30:09 +01:00
|
|
|
$users[] = [
|
|
|
|
'fullname' => fullname($user, has_capability('moodle/site:viewfullnames', $context, $enroller)),
|
|
|
|
'timeend' => $ue->timeend,
|
|
|
|
];
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
if (!$ue->notifyall) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($ue->timeend - $ue->expirythreshold + 86400 < $timenow) {
|
|
|
|
// Notify enrolled users only once at the start of the threshold.
|
2019-08-19 16:30:09 +01:00
|
|
|
$trace->output("user $ue->userid was already notified that enrolment in course $ue->courseid expires on ".
|
|
|
|
userdate($ue->timeend, '', $CFG->timezone), 1);
|
2012-10-13 22:23:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-12-25 15:44:35 +01:00
|
|
|
$this->notify_expiry_enrolled($user, $ue, $trace);
|
2012-10-13 22:23:35 +02:00
|
|
|
}
|
|
|
|
$rs->close();
|
|
|
|
|
2019-08-19 16:30:09 +01:00
|
|
|
if ($lastenrollid && $users) {
|
2012-12-25 15:44:35 +01:00
|
|
|
$this->notify_expiry_enroller($lastenrollid, $users, $trace);
|
2012-10-13 22:23:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the user who is responsible for enrolments for given instance.
|
|
|
|
*
|
|
|
|
* Override if plugin knows anybody better than admin.
|
|
|
|
*
|
|
|
|
* @param int $instanceid enrolment instance id
|
|
|
|
* @return stdClass user record
|
|
|
|
*/
|
|
|
|
protected function get_enroller($instanceid) {
|
|
|
|
return get_admin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify user about incoming expiration of their enrolment,
|
|
|
|
* it is called only if notification of enrolled users (aka students) is enabled in course.
|
|
|
|
*
|
|
|
|
* This is executed only once for each expiring enrolment right
|
|
|
|
* at the start of the expiration threshold.
|
|
|
|
*
|
|
|
|
* @param stdClass $user
|
|
|
|
* @param stdClass $ue
|
2012-12-25 15:44:35 +01:00
|
|
|
* @param progress_trace $trace
|
2012-10-13 22:23:35 +02:00
|
|
|
*/
|
2012-12-25 15:44:35 +01:00
|
|
|
protected function notify_expiry_enrolled($user, $ue, progress_trace $trace) {
|
2013-12-24 14:00:49 +01:00
|
|
|
global $CFG;
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
|
2013-12-24 14:00:49 +01:00
|
|
|
$oldforcelang = force_current_language($user->lang);
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
$enroller = $this->get_enroller($ue->enrolid);
|
|
|
|
$context = context_course::instance($ue->courseid);
|
|
|
|
|
2019-08-19 16:30:09 +01:00
|
|
|
$subject = get_string('expirymessageenrolledsubject', 'enrol_'.$name);
|
|
|
|
$body = $this->get_expiry_message_body($user, $ue, $name, $enroller, $context);
|
2012-10-13 22:23:35 +02:00
|
|
|
|
2019-08-19 16:30:09 +01:00
|
|
|
$coursename = format_string($ue->fullname, true, ['context' => $context]);
|
2012-10-13 22:23:35 +02:00
|
|
|
|
2016-07-20 12:40:34 +01:00
|
|
|
$message = new \core\message\message();
|
2016-10-31 14:13:13 -04:00
|
|
|
$message->courseid = $ue->courseid;
|
2012-10-13 22:23:35 +02:00
|
|
|
$message->notification = 1;
|
|
|
|
$message->component = 'enrol_'.$name;
|
|
|
|
$message->name = 'expiry_notification';
|
|
|
|
$message->userfrom = $enroller;
|
|
|
|
$message->userto = $user;
|
|
|
|
$message->subject = $subject;
|
|
|
|
$message->fullmessage = $body;
|
|
|
|
$message->fullmessageformat = FORMAT_MARKDOWN;
|
|
|
|
$message->fullmessagehtml = markdown_to_html($body);
|
|
|
|
$message->smallmessage = $subject;
|
2019-08-19 16:30:09 +01:00
|
|
|
$message->contexturlname = $coursename;
|
|
|
|
$message->contexturl = (string)new moodle_url('/course/view.php', ['id' => $ue->courseid]);
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
if (message_send($message)) {
|
2019-08-19 16:30:09 +01:00
|
|
|
$stringmessage = 'notifying user %s that enrolment in course %s expires on %s';
|
2012-10-13 22:23:35 +02:00
|
|
|
} else {
|
2019-08-19 16:30:09 +01:00
|
|
|
$stringmessage = 'error notifying user %s that enrolment in course %s expires on %s';
|
2012-10-13 22:23:35 +02:00
|
|
|
}
|
2019-08-19 16:30:09 +01:00
|
|
|
$outputmessage = sprintf($stringmessage, $ue->userid, $ue->courseid, userdate($ue->timeend, '', $CFG->timezone));
|
|
|
|
$trace->output($outputmessage, 1);
|
2012-10-13 22:23:35 +02:00
|
|
|
|
2013-12-24 14:00:49 +01:00
|
|
|
force_current_language($oldforcelang);
|
2012-10-13 22:23:35 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 16:30:09 +01:00
|
|
|
/**
|
|
|
|
* Generate subject and body messages for enrolment expiration notification.
|
|
|
|
*
|
|
|
|
* @param stdClass $user An object representing the user.
|
|
|
|
* @param stdClass $ue An object containing enrolment data.
|
|
|
|
* @param string $name Name of this enrol plugin.
|
|
|
|
* @param stdClass $enroller The user who is responsible for enrolments.
|
|
|
|
* @param context $context The context object.
|
|
|
|
* @return string Return the body message.
|
|
|
|
*/
|
|
|
|
protected function get_expiry_message_body(stdClass $user, stdClass $ue, string $name,
|
|
|
|
stdClass $enroller, context $context): string {
|
|
|
|
$a = new stdClass();
|
|
|
|
$a->course = format_string($ue->fullname, true, ['context' => $context]);
|
|
|
|
$a->user = fullname($user, true);
|
|
|
|
$a->timeend = userdate($ue->timeend, '', $user->timezone);
|
|
|
|
$a->enroller = fullname($enroller, has_capability('moodle/site:viewfullnames', $context, $user));
|
|
|
|
return get_string('expirymessageenrolledbody', 'enrol_'.$name, $a);
|
|
|
|
}
|
|
|
|
|
2012-10-13 22:23:35 +02:00
|
|
|
/**
|
|
|
|
* Notify person responsible for enrolments that some user enrolments will be expired soon,
|
|
|
|
* it is called only if notification of enrollers (aka teachers) is enabled in course.
|
|
|
|
*
|
|
|
|
* This is called repeatedly every day for each course if there are any pending expiration
|
|
|
|
* in the expiration threshold.
|
|
|
|
*
|
|
|
|
* @param int $eid
|
|
|
|
* @param array $users
|
2012-12-25 15:44:35 +01:00
|
|
|
* @param progress_trace $trace
|
2012-10-13 22:23:35 +02:00
|
|
|
*/
|
2012-12-25 15:44:35 +01:00
|
|
|
protected function notify_expiry_enroller($eid, $users, progress_trace $trace) {
|
2013-12-24 14:00:49 +01:00
|
|
|
global $DB;
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
$name = $this->get_name();
|
|
|
|
|
|
|
|
$instance = $DB->get_record('enrol', array('id'=>$eid, 'enrol'=>$name));
|
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
$course = $DB->get_record('course', array('id'=>$instance->courseid));
|
|
|
|
|
|
|
|
$enroller = $this->get_enroller($instance->id);
|
|
|
|
$admin = get_admin();
|
|
|
|
|
2013-12-24 14:00:49 +01:00
|
|
|
$oldforcelang = force_current_language($enroller->lang);
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
foreach($users as $key=>$info) {
|
|
|
|
$users[$key] = '* '.$info['fullname'].' - '.userdate($info['timeend'], '', $enroller->timezone);
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = new stdClass();
|
|
|
|
$a->course = format_string($course->fullname, true, array('context'=>$context));
|
|
|
|
$a->threshold = get_string('numdays', '', $instance->expirythreshold / (60*60*24));
|
|
|
|
$a->users = implode("\n", $users);
|
2017-07-24 10:10:34 +08:00
|
|
|
$a->extendurl = (string)new moodle_url('/user/index.php', array('id'=>$instance->courseid));
|
2012-10-13 22:23:35 +02:00
|
|
|
|
|
|
|
$subject = get_string('expirymessageenrollersubject', 'enrol_'.$name, $a);
|
|
|
|
$body = get_string('expirymessageenrollerbody', 'enrol_'.$name, $a);
|
|
|
|
|
2016-07-20 12:40:34 +01:00
|
|
|
$message = new \core\message\message();
|
2016-10-31 14:13:13 -04:00
|
|
|
$message->courseid = $course->id;
|
2012-10-13 22:23:35 +02:00
|
|
|
$message->notification = 1;
|
|
|
|
$message->component = 'enrol_'.$name;
|
|
|
|
$message->name = 'expiry_notification';
|
|
|
|
$message->userfrom = $admin;
|
|
|
|
$message->userto = $enroller;
|
|
|
|
$message->subject = $subject;
|
|
|
|
$message->fullmessage = $body;
|
|
|
|
$message->fullmessageformat = FORMAT_MARKDOWN;
|
|
|
|
$message->fullmessagehtml = markdown_to_html($body);
|
|
|
|
$message->smallmessage = $subject;
|
|
|
|
$message->contexturlname = $a->course;
|
|
|
|
$message->contexturl = $a->extendurl;
|
|
|
|
|
|
|
|
if (message_send($message)) {
|
2012-12-25 15:44:35 +01:00
|
|
|
$trace->output("notifying user $enroller->id about all expiring $name enrolments in course $instance->courseid", 1);
|
2012-10-13 22:23:35 +02:00
|
|
|
} else {
|
2012-12-25 15:44:35 +01:00
|
|
|
$trace->output("error notifying user $enroller->id about all expiring $name enrolments in course $instance->courseid", 1);
|
2012-10-13 22:23:35 +02:00
|
|
|
}
|
|
|
|
|
2013-12-24 14:00:49 +01:00
|
|
|
force_current_language($oldforcelang);
|
2012-10-13 22:23:35 +02:00
|
|
|
}
|
|
|
|
|
2014-09-18 23:35:27 -04:00
|
|
|
/**
|
|
|
|
* Backup execution step hook to annotate custom fields.
|
|
|
|
*
|
|
|
|
* @param backup_enrolments_execution_step $step
|
|
|
|
* @param stdClass $enrol
|
|
|
|
*/
|
|
|
|
public function backup_annotate_custom_fields(backup_enrolments_execution_step $step, stdClass $enrol) {
|
|
|
|
// Override as necessary to annotate custom fields in the enrol table.
|
|
|
|
}
|
|
|
|
|
2012-08-31 14:15:04 +02:00
|
|
|
/**
|
|
|
|
* Automatic enrol sync executed during restore.
|
|
|
|
* Useful for automatic sync by course->idnumber or course category.
|
|
|
|
* @param stdClass $course course record
|
|
|
|
*/
|
|
|
|
public function restore_sync_course($course) {
|
|
|
|
// Override if necessary.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore instance and map settings.
|
|
|
|
*
|
|
|
|
* @param restore_enrolments_structure_step $step
|
|
|
|
* @param stdClass $data
|
|
|
|
* @param stdClass $course
|
|
|
|
* @param int $oldid
|
|
|
|
*/
|
|
|
|
public function restore_instance(restore_enrolments_structure_step $step, stdClass $data, $course, $oldid) {
|
|
|
|
// Do not call this from overridden methods, restore and set new id there.
|
|
|
|
$step->set_mapping('enrol', $oldid, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore user enrolment.
|
|
|
|
*
|
|
|
|
* @param restore_enrolments_structure_step $step
|
|
|
|
* @param stdClass $data
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $oldinstancestatus
|
|
|
|
* @param int $userid
|
|
|
|
*/
|
|
|
|
public function restore_user_enrolment(restore_enrolments_structure_step $step, $data, $instance, $userid, $oldinstancestatus) {
|
|
|
|
// Override as necessary if plugin supports restore of enrolments.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore role assignment.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $roleid
|
|
|
|
* @param int $userid
|
|
|
|
* @param int $contextid
|
|
|
|
*/
|
|
|
|
public function restore_role_assignment($instance, $roleid, $userid, $contextid) {
|
|
|
|
// No role assignment by default, override if necessary.
|
|
|
|
}
|
2012-09-26 17:13:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore user group membership.
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $groupid
|
|
|
|
* @param int $userid
|
|
|
|
*/
|
|
|
|
public function restore_group_member($instance, $groupid, $userid) {
|
|
|
|
// Implement if you want to restore protected group memberships,
|
|
|
|
// usually this is not necessary because plugins should be able to recreate the memberships automatically.
|
|
|
|
}
|
2015-08-11 15:39:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns defaults for new instances.
|
|
|
|
* @since Moodle 3.1
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_instance_defaults() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate a list of parameter names and types.
|
|
|
|
* @since Moodle 3.1
|
|
|
|
*
|
|
|
|
* @param array $data array of ("fieldname"=>value) of submitted data
|
|
|
|
* @param array $rules array of ("fieldname"=>PARAM_X types - or "fieldname"=>array( list of valid options )
|
|
|
|
* @return array of "element_name"=>"error_description" if there are errors,
|
|
|
|
* or an empty array if everything is OK.
|
|
|
|
*/
|
|
|
|
public function validate_param_types($data, $rules) {
|
|
|
|
$errors = array();
|
|
|
|
$invalidstr = get_string('invaliddata', 'error');
|
|
|
|
foreach ($rules as $fieldname => $rule) {
|
2024-03-22 13:45:10 +01:00
|
|
|
if (!array_key_exists($fieldname, $data)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-11 15:39:17 +08:00
|
|
|
if (is_array($rule)) {
|
|
|
|
if (!in_array($data[$fieldname], $rule)) {
|
|
|
|
$errors[$fieldname] = $invalidstr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($data[$fieldname] != clean_param($data[$fieldname], $rule)) {
|
|
|
|
$errors[$fieldname] = $invalidstr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
2022-05-09 11:09:57 +06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill custom fields data for a given enrolment plugin.
|
|
|
|
*
|
2024-01-31 11:29:33 +11:00
|
|
|
* For example: resolve linked entities from the idnumbers (cohort, role, group, etc.)
|
|
|
|
* Also fill the default values that are not specified.
|
|
|
|
*
|
|
|
|
* @param array $enrolmentdata enrolment data received in CSV file in tool_uploadcourse
|
2022-05-09 11:09:57 +06:00
|
|
|
* @param int $courseid Course ID.
|
|
|
|
* @return array Updated enrolment data with custom fields info.
|
|
|
|
*/
|
2024-02-28 18:38:20 +01:00
|
|
|
public function fill_enrol_custom_fields(array $enrolmentdata, int $courseid): array {
|
2022-05-09 11:09:57 +06:00
|
|
|
return $enrolmentdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if data is valid for a given enrolment plugin
|
|
|
|
*
|
|
|
|
* @param array $enrolmentdata enrolment data to validate.
|
|
|
|
* @param int|null $courseid Course ID.
|
|
|
|
* @return array Errors
|
|
|
|
*/
|
2024-02-28 18:38:20 +01:00
|
|
|
public function validate_enrol_plugin_data(array $enrolmentdata, ?int $courseid = null): array {
|
2023-08-04 17:01:59 +08:00
|
|
|
$errors = [];
|
|
|
|
if (!$this->is_csv_upload_supported()) {
|
|
|
|
$errors['errorunsupportedmethod'] =
|
|
|
|
new lang_string('errorunsupportedmethod', 'tool_uploadcourse',
|
|
|
|
get_class($this));
|
2024-02-05 15:08:46 +08:00
|
|
|
} else {
|
|
|
|
$plugin = $this->get_name();
|
|
|
|
if (!enrol_is_enabled($plugin)) {
|
|
|
|
$pluginname = get_string('pluginname', 'enrol_' . $plugin);
|
|
|
|
$errors['plugindisabled'] = new lang_string('plugindisabled', 'enrol', $pluginname);
|
|
|
|
}
|
2023-08-04 17:01:59 +08:00
|
|
|
}
|
|
|
|
return $errors;
|
2022-05-09 11:09:57 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if plugin custom data is allowed in relevant context.
|
|
|
|
*
|
2024-01-31 11:29:33 +11:00
|
|
|
* This is called from the tool_uploadcourse if the plugin supports instance creation in
|
|
|
|
* upload course ({@see self::is_csv_upload_supported()})
|
|
|
|
*
|
2024-03-27 15:42:20 +08:00
|
|
|
* Override it if plugin can validate provided data in relevant context.
|
2024-01-31 11:29:33 +11:00
|
|
|
*
|
2022-05-09 11:09:57 +06:00
|
|
|
* @param array $enrolmentdata enrolment data to validate.
|
|
|
|
* @param int|null $courseid Course ID.
|
|
|
|
* @return lang_string|null Error
|
|
|
|
*/
|
2024-02-28 18:38:20 +01:00
|
|
|
public function validate_plugin_data_context(array $enrolmentdata, ?int $courseid = null): ?lang_string {
|
2022-05-09 11:09:57 +06:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-08-01 11:35:45 +08:00
|
|
|
/**
|
|
|
|
* Finds matching instances for a given course.
|
|
|
|
*
|
|
|
|
* @param array $enrolmentdata enrolment data.
|
|
|
|
* @param int $courseid Course ID.
|
|
|
|
* @return stdClass|null Matching instance
|
|
|
|
*/
|
2024-02-28 18:38:20 +01:00
|
|
|
public function find_instance(array $enrolmentdata, int $courseid): ?stdClass {
|
2023-08-01 11:35:45 +08:00
|
|
|
|
|
|
|
// By default, we assume we can't uniquely identify an instance so better not update any.
|
|
|
|
// Plugins can override this if they can uniquely identify an instance.
|
|
|
|
return null;
|
|
|
|
}
|
2024-01-15 15:14:50 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "from" contact which the message will be sent from.
|
|
|
|
*
|
|
|
|
* @param int $sendoption send email from constant ENROL_SEND_EMAIL_FROM_*
|
|
|
|
* @param context $context where the user will be fetched from.
|
|
|
|
* @return null|stdClass the contact user object.
|
|
|
|
*/
|
|
|
|
public function get_welcome_message_contact(
|
|
|
|
int $sendoption,
|
|
|
|
context $context,
|
|
|
|
): ?stdClass {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$acceptedsendoptions = [
|
|
|
|
ENROL_DO_NOT_SEND_EMAIL,
|
|
|
|
ENROL_SEND_EMAIL_FROM_COURSE_CONTACT,
|
|
|
|
ENROL_SEND_EMAIL_FROM_KEY_HOLDER,
|
|
|
|
ENROL_SEND_EMAIL_FROM_NOREPLY,
|
|
|
|
];
|
|
|
|
if (!in_array($sendoption, $acceptedsendoptions)) {
|
|
|
|
throw new coding_exception('Invalid send option');
|
|
|
|
}
|
|
|
|
if ($sendoption === ENROL_DO_NOT_SEND_EMAIL) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$contact = null;
|
|
|
|
// Send as the first user assigned as the course contact.
|
|
|
|
if ($sendoption === ENROL_SEND_EMAIL_FROM_COURSE_CONTACT) {
|
|
|
|
$rusers = [];
|
|
|
|
if (!empty($CFG->coursecontact)) {
|
|
|
|
$croles = explode(',', $CFG->coursecontact);
|
|
|
|
[$sort, $sortparams] = users_order_by_sql('u');
|
|
|
|
// We only use the first user.
|
|
|
|
$i = 0;
|
|
|
|
do {
|
|
|
|
$userfieldsapi = \core_user\fields::for_name();
|
|
|
|
$allnames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
|
|
|
|
$rusers = get_role_users($croles[$i], $context, true, 'u.id, u.confirmed, u.username, '. $allnames . ',
|
2024-01-16 09:14:44 +07:00
|
|
|
u.email, r.sortorder, ra.id AS raid', 'r.sortorder, ra.id ASC, ' . $sort, null, '', '', '', '', $sortparams);
|
2024-01-15 15:14:50 +07:00
|
|
|
$i++;
|
|
|
|
} while (empty($rusers) && !empty($croles[$i]));
|
|
|
|
}
|
|
|
|
if ($rusers) {
|
|
|
|
$contact = array_values($rusers)[0];
|
|
|
|
}
|
|
|
|
} else if ($sendoption === ENROL_SEND_EMAIL_FROM_KEY_HOLDER) {
|
|
|
|
// Send as the first user with enrol/self:holdkey capability assigned in the course.
|
|
|
|
[$sort] = users_order_by_sql('u');
|
|
|
|
$keyholders = get_users_by_capability($context, 'enrol/self:holdkey', 'u.*', $sort);
|
|
|
|
if (!empty($keyholders)) {
|
|
|
|
$contact = array_values($keyholders)[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sendoption === ENROL_SEND_EMAIL_FROM_NOREPLY) {
|
|
|
|
$contact = core_user::get_noreply_user();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $contact;
|
|
|
|
}
|
2024-01-16 09:14:44 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send course welcome message to user.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance Enrol instance.
|
|
|
|
* @param int $userid User ID.
|
|
|
|
* @param int $sendoption Send email from constant ENROL_SEND_EMAIL_FROM_*
|
|
|
|
* @param null|string $message Message to send to the user.
|
|
|
|
*/
|
|
|
|
public function send_course_welcome_message_to_user(
|
|
|
|
stdClass $instance,
|
|
|
|
int $userid,
|
|
|
|
int $sendoption,
|
|
|
|
?string $message = '',
|
|
|
|
): void {
|
|
|
|
global $DB;
|
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
$user = core_user::get_user($userid);
|
|
|
|
$course = get_course($instance->courseid);
|
|
|
|
$courserole = $DB->get_field(
|
|
|
|
table: 'role',
|
|
|
|
return: 'shortname',
|
|
|
|
conditions: ['id' => $instance->roleid],
|
|
|
|
);
|
|
|
|
|
|
|
|
$a = new stdClass();
|
2024-04-24 17:07:27 +01:00
|
|
|
$a->coursename = format_string($course->fullname, true, ['context' => $context, 'escape' => false]);
|
2024-01-16 09:14:44 +07:00
|
|
|
$a->profileurl = (new moodle_url(
|
|
|
|
url: '/user/view.php',
|
|
|
|
params: [
|
|
|
|
'id' => $user->id,
|
|
|
|
'course' => $instance->courseid,
|
|
|
|
],
|
|
|
|
))->out();
|
|
|
|
$a->fullname = fullname($user);
|
|
|
|
|
|
|
|
if ($message && trim($message) !== '') {
|
|
|
|
$placeholders = [
|
|
|
|
'{$a->coursename}',
|
|
|
|
'{$a->profileurl}',
|
|
|
|
'{$a->fullname}',
|
|
|
|
'{$a->email}',
|
|
|
|
'{$a->firstname}',
|
|
|
|
'{$a->lastname}',
|
|
|
|
'{$a->courserole}',
|
|
|
|
];
|
|
|
|
$values = [
|
|
|
|
$a->coursename,
|
|
|
|
$a->profileurl,
|
|
|
|
fullname($user),
|
|
|
|
$user->email,
|
|
|
|
$user->firstname,
|
|
|
|
$user->lastname,
|
|
|
|
$courserole,
|
|
|
|
];
|
|
|
|
$message = str_replace($placeholders, $values, $message);
|
|
|
|
if (strpos($message, '<') === false) {
|
|
|
|
// Plain text only.
|
|
|
|
$messagetext = $message;
|
|
|
|
$messagehtml = text_to_html($messagetext, null, false, true);
|
|
|
|
} else {
|
|
|
|
// This is most probably the tag/newline soup known as FORMAT_MOODLE.
|
|
|
|
$messagehtml = format_text($message, FORMAT_MOODLE,
|
|
|
|
['context' => $context, 'para' => false, 'newlines' => true, 'filter' => true]);
|
|
|
|
$messagetext = html_to_text($messagehtml);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$messagetext = get_string('customwelcomemessageplaceholder', 'core_enrol', $a);
|
|
|
|
$messagehtml = text_to_html($messagetext, null, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact = $this->get_welcome_message_contact(
|
|
|
|
sendoption: $sendoption,
|
|
|
|
context: $context,
|
|
|
|
);
|
|
|
|
if (!$contact) {
|
|
|
|
// Cannot find the contact to send the message from.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = new \core\message\message();
|
|
|
|
$message->courseid = $instance->courseid;
|
|
|
|
$message->component = 'moodle';
|
|
|
|
$message->name = 'enrolcoursewelcomemessage';
|
|
|
|
$message->userfrom = $contact;
|
|
|
|
$message->userto = $user;
|
2024-04-24 17:07:27 +01:00
|
|
|
$message->subject = get_string('welcometocourse', 'moodle', $a->coursename);
|
2024-01-16 09:14:44 +07:00
|
|
|
$message->fullmessage = $messagetext;
|
|
|
|
$message->fullmessageformat = FORMAT_MARKDOWN;
|
|
|
|
$message->fullmessagehtml = $messagehtml;
|
|
|
|
$message->notification = 1;
|
|
|
|
$message->contexturl = $a->profileurl;
|
|
|
|
$message->contexturlname = $course->fullname;
|
|
|
|
|
|
|
|
message_send($message);
|
|
|
|
}
|
2024-02-05 15:08:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates enrol plugin instance with provided data.
|
|
|
|
* @param int $courseid Course ID.
|
|
|
|
* @param array $enrolmentdata enrolment data.
|
|
|
|
* @param stdClass $instance Instance to update.
|
|
|
|
*
|
|
|
|
* @return stdClass updated instance
|
|
|
|
*/
|
|
|
|
public function update_enrol_plugin_data(int $courseid, array $enrolmentdata, stdClass $instance): stdClass {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
// Sort out the start, end and date.
|
|
|
|
$instance->enrolstartdate = (isset($enrolmentdata['startdate']) ? strtotime($enrolmentdata['startdate']) : 0);
|
|
|
|
$instance->enrolenddate = (isset($enrolmentdata['enddate']) ? strtotime($enrolmentdata['enddate']) : 0);
|
|
|
|
|
|
|
|
// Is the enrolment period set?
|
|
|
|
if (!empty($enrolmentdata['enrolperiod'])) {
|
|
|
|
if (preg_match('/^\d+$/', $enrolmentdata['enrolperiod'])) {
|
|
|
|
$enrolmentdata['enrolperiod'] = (int)$enrolmentdata['enrolperiod'];
|
|
|
|
} else {
|
|
|
|
// Try and convert period to seconds.
|
|
|
|
$enrolmentdata['enrolperiod'] = strtotime('1970-01-01 GMT + ' . $enrolmentdata['enrolperiod']);
|
|
|
|
}
|
|
|
|
$instance->enrolperiod = $enrolmentdata['enrolperiod'];
|
|
|
|
}
|
|
|
|
if ($instance->enrolstartdate > 0 && isset($enrolmentdata['enrolperiod'])) {
|
|
|
|
$instance->enrolenddate = $instance->enrolstartdate + $enrolmentdata['enrolperiod'];
|
|
|
|
}
|
|
|
|
if ($instance->enrolenddate > 0) {
|
|
|
|
$instance->enrolperiod = $instance->enrolenddate - $instance->enrolstartdate;
|
|
|
|
}
|
|
|
|
if ($instance->enrolenddate < $instance->enrolstartdate) {
|
|
|
|
$instance->enrolenddate = $instance->enrolstartdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort out the given role.
|
|
|
|
if (isset($enrolmentdata['role']) || isset($enrolmentdata['roleid'])) {
|
|
|
|
if (isset($enrolmentdata['role'])) {
|
|
|
|
$roleid = $DB->get_field('role', 'id', ['shortname' => $enrolmentdata['role']], MUST_EXIST);
|
|
|
|
} else {
|
|
|
|
$roleid = $enrolmentdata['roleid'];
|
|
|
|
}
|
|
|
|
$instance->roleid = $roleid;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort out custom instance name.
|
|
|
|
if (isset($enrolmentdata['name'])) {
|
|
|
|
$instance->name = $enrolmentdata['name'];
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
2011-09-08 16:17:12 +12:00
|
|
|
}
|