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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Guest access plugin.
|
|
|
|
*
|
|
|
|
* This plugin does not add any entries into the user_enrolments table,
|
|
|
|
* the access control is granted on the fly via the tricks in require_login().
|
|
|
|
*
|
2013-04-27 13:41:32 +02:00
|
|
|
* @package enrol_guest
|
2010-07-31 20:22:29 +00: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
|
|
|
*/
|
|
|
|
|
2010-07-31 20:30:29 +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
|
|
|
|
2015-10-01 10:37:01 +01:00
|
|
|
/**
|
|
|
|
* Class enrol_guest_plugin
|
|
|
|
*
|
|
|
|
* @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
|
|
|
class enrol_guest_plugin extends enrol_plugin {
|
|
|
|
|
2010-09-20 07:49:30 +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
|
|
|
|
*/
|
2010-08-18 09:26:46 +00:00
|
|
|
public function get_info_icons(array $instances) {
|
2010-09-20 07:49:30 +00:00
|
|
|
foreach ($instances as $instance) {
|
2011-11-05 15:06:32 +01:00
|
|
|
if ($instance->password !== '') {
|
2013-12-03 09:45:14 +00:00
|
|
|
return array(new pix_icon('withpassword', get_string('guestaccess_withpassword', 'enrol_guest'), 'enrol_guest'));
|
2010-11-01 07:31:54 +00:00
|
|
|
} else {
|
2013-12-03 09:45:14 +00:00
|
|
|
return array(new pix_icon('withoutpassword', get_string('guestaccess_withoutpassword', 'enrol_guest'), 'enrol_guest'));
|
2010-09-20 07:49:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-18 09:26:46 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 10:37:01 +01:00
|
|
|
/**
|
|
|
|
* Enrol a user using a given enrolment instance.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @param int $userid
|
|
|
|
* @param null $roleid
|
|
|
|
* @param int $timestart
|
|
|
|
* @param int $timeend
|
|
|
|
* @param null $status
|
|
|
|
* @param null $recovergrades
|
|
|
|
*/
|
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
|
|
|
// no real enrolments here!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-01 10:37:01 +01:00
|
|
|
/**
|
|
|
|
* Enrol a user from a given enrolment instance.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
public function unenrol_user(stdClass $instance, $userid) {
|
|
|
|
// nothing to do, we never enrol here!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-01 10:37:01 +01:00
|
|
|
/**
|
|
|
|
* Sets up navigation entries.
|
|
|
|
*
|
|
|
|
* @param stdClass $instancesnode
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @return void
|
|
|
|
* @throws coding_exception
|
|
|
|
*/
|
|
|
|
public function add_course_navigation($instancesnode, stdClass $instance) {
|
|
|
|
if ($instance->enrol !== 'guest') {
|
|
|
|
throw new coding_exception('Invalid enrol instance type!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
if (has_capability('enrol/guest:config', $context)) {
|
|
|
|
$managelink = new moodle_url('/enrol/guest/edit.php', array('courseid' => $instance->courseid, 'id' => $instance->id));
|
|
|
|
$instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns edit icons for the page with list of instances
|
|
|
|
* @param stdClass $instance
|
|
|
|
* @return array
|
|
|
|
* @throws coding_exception
|
|
|
|
*/
|
|
|
|
public function get_action_icons(stdClass $instance) {
|
|
|
|
global $OUTPUT;
|
|
|
|
|
|
|
|
if ($instance->enrol !== 'guest') {
|
|
|
|
throw new coding_exception('invalid enrol instance!');
|
|
|
|
}
|
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
|
|
|
|
$icons = array();
|
|
|
|
|
|
|
|
if (has_capability('enrol/guest:config', $context)) {
|
|
|
|
$editlink = new moodle_url("/enrol/guest/edit.php", array('courseid' => $instance->courseid, 'id' => $instance->id));
|
|
|
|
$icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core',
|
|
|
|
array('class' => 'iconsmall')));
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Attempt to automatically gain temporary guest access to course,
|
|
|
|
* calling code has to make sure the plugin and instance are active.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance course enrol instance
|
|
|
|
* @return bool|int false means no guest access, integer means end of cached time
|
|
|
|
*/
|
|
|
|
public function try_guestaccess(stdClass $instance) {
|
|
|
|
global $USER, $CFG;
|
|
|
|
|
2011-11-05 15:06:32 +01:00
|
|
|
$allow = false;
|
|
|
|
|
|
|
|
if ($instance->password === '') {
|
|
|
|
$allow = true;
|
|
|
|
|
|
|
|
} else if (isset($USER->enrol_guest_passwords[$instance->id])) { // this is a hack, ideally we should not add stuff to $USER...
|
|
|
|
if ($USER->enrol_guest_passwords[$instance->id] === $instance->password) {
|
|
|
|
$allow = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($allow) {
|
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
|
|
|
// Temporarily assign them some guest role for this context
|
2012-07-23 16:08:41 +08:00
|
|
|
$context = context_course::instance($instance->courseid);
|
2011-10-14 12:48:00 +02:00
|
|
|
load_temp_course_role($context, $CFG->guestroleid);
|
2011-11-05 12:12:48 +01:00
|
|
|
return ENROL_MAX_TIMESTAMP;
|
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 false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns link to page which may be used to add new instance of enrolment plugin in course.
|
|
|
|
* @param int $courseid
|
|
|
|
* @return moodle_url page url
|
|
|
|
*/
|
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
|
|
|
global $DB;
|
|
|
|
|
2012-07-23 16:08:41 +08:00
|
|
|
$context = context_course::instance($courseid, MUST_EXIST);
|
2010-07-31 20:22:29 +00:00
|
|
|
|
|
|
|
if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/guest: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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($DB->record_exists('enrol', array('courseid'=>$courseid, 'enrol'=>'guest'))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 10:37:01 +01:00
|
|
|
return new moodle_url('/enrol/guest/edit.php', array('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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
global $CFG, $OUTPUT, $SESSION, $USER;
|
|
|
|
|
2011-11-05 15:06:32 +01:00
|
|
|
if ($instance->password === '') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($USER->enrol['tempguest'][$instance->courseid]) and $USER->enrol['tempguest'][$instance->courseid] > time()) {
|
|
|
|
// no need to show the guest access when user can already enter course as guest
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once("$CFG->dirroot/enrol/guest/locallib.php");
|
|
|
|
$form = new enrol_guest_enrol_form(NULL, $instance);
|
|
|
|
$instanceid = optional_param('instance', 0, PARAM_INT);
|
|
|
|
|
|
|
|
if ($instance->id == $instanceid) {
|
|
|
|
if ($data = $form->get_data()) {
|
|
|
|
// add guest role
|
2012-07-23 16:08:41 +08:00
|
|
|
$context = context_course::instance($instance->courseid);
|
2011-11-05 15:06:32 +01:00
|
|
|
$USER->enrol_guest_passwords[$instance->id] = $data->guestpassword; // this is a hack, ideally we should not add stuff to $USER...
|
|
|
|
if (isset($USER->enrol['tempguest'][$instance->courseid])) {
|
|
|
|
remove_temp_course_roles($context);
|
|
|
|
}
|
2011-10-14 12:48:00 +02:00
|
|
|
load_temp_course_role($context, $CFG->guestroleid);
|
2011-11-05 15:06:32 +01:00
|
|
|
$USER->enrol['tempguest'][$instance->courseid] = ENROL_MAX_TIMESTAMP;
|
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
|
|
|
|
|
|
|
// go to the originally requested page
|
|
|
|
if (!empty($SESSION->wantsurl)) {
|
|
|
|
$destination = $SESSION->wantsurl;
|
|
|
|
unset($SESSION->wantsurl);
|
|
|
|
} else {
|
|
|
|
$destination = "$CFG->wwwroot/course/view.php?id=$instance->courseid";
|
|
|
|
}
|
|
|
|
redirect($destination);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$form->display();
|
|
|
|
$output = ob_get_clean();
|
|
|
|
|
|
|
|
return $OUTPUT->box($output, 'generalbox');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
global $DB;
|
|
|
|
|
2013-07-21 11:55:37 +02:00
|
|
|
if ($inserted) {
|
|
|
|
if (isset($data->enrol_guest_status_0)) {
|
|
|
|
$fields = array('status'=>$data->enrol_guest_status_0);
|
|
|
|
if ($fields['status'] == ENROL_INSTANCE_ENABLED) {
|
|
|
|
$fields['password'] = $data->enrol_guest_password_0;
|
2011-10-11 09:21:23 +08:00
|
|
|
} else {
|
2013-07-21 11:55:37 +02:00
|
|
|
if ($this->get_config('requirepassword')) {
|
|
|
|
$fields['password'] = generate_password(20);
|
2011-10-11 09:21:23 +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
|
|
|
}
|
2013-07-21 11:55:37 +02:00
|
|
|
$this->add_instance($course, $fields);
|
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 {
|
2013-07-21 11:55:37 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2013-07-21 11:55:37 +02:00
|
|
|
$instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'enrol'=>'guest'));
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
$i = $instance->id;
|
|
|
|
|
|
|
|
if (isset($data->{'enrol_guest_status_'.$i})) {
|
|
|
|
$reset = ($instance->status != $data->{'enrol_guest_status_'.$i});
|
|
|
|
|
|
|
|
$instance->status = $data->{'enrol_guest_status_'.$i};
|
|
|
|
$instance->timemodified = time();
|
|
|
|
if ($instance->status == ENROL_INSTANCE_ENABLED) {
|
|
|
|
if ($instance->password !== $data->{'enrol_guest_password_'.$i}) {
|
|
|
|
$reset = true;
|
|
|
|
}
|
|
|
|
$instance->password = $data->{'enrol_guest_password_'.$i};
|
|
|
|
}
|
|
|
|
$DB->update_record('enrol', $instance);
|
2015-08-24 16:28:57 +08:00
|
|
|
\core\event\enrol_instance_updated::create_from_record($instance)->trigger();
|
2013-07-21 11:55:37 +02:00
|
|
|
|
|
|
|
if ($reset) {
|
|
|
|
$context = context_course::instance($course->id);
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-07 08:58:18 +01:00
|
|
|
/**
|
|
|
|
* Add new instance of enrol plugin.
|
|
|
|
* @param object $course
|
|
|
|
* @param array instance fields
|
|
|
|
* @return int id of new instance, null if can not be created
|
|
|
|
*/
|
|
|
|
public function add_instance($course, array $fields = NULL) {
|
|
|
|
$fields = (array)$fields;
|
|
|
|
|
|
|
|
if (!isset($fields['password'])) {
|
|
|
|
$fields['password'] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::add_instance($course, $fields);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* @param object $course
|
|
|
|
* @return int id of new instance
|
|
|
|
*/
|
|
|
|
public function add_default_instance($course) {
|
|
|
|
$fields = array('status'=>$this->get_config('status'));
|
|
|
|
|
|
|
|
if ($this->get_config('requirepassword')) {
|
|
|
|
$fields['password'] = generate_password(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->add_instance($course, $fields);
|
|
|
|
}
|
|
|
|
|
2012-08-31 14:15:04 +02:00
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
global $DB;
|
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-08-31 14:15:04 +02:00
|
|
|
if (!$DB->record_exists('enrol', array('courseid' => $data->courseid, 'enrol' => $this->get_name()))) {
|
|
|
|
$this->add_instance($course, (array)$data);
|
|
|
|
}
|
2010-09-21 10:42:19 +00:00
|
|
|
|
2012-08-31 14:15:04 +02:00
|
|
|
// No need to set mapping, we do not restore users or roles here.
|
|
|
|
$step->set_mapping('enrol', $oldid, 0);
|
2010-09-21 10:42:19 +00:00
|
|
|
}
|
2013-12-16 16:39:18 -02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is it possible to delete enrol instance via standard UI?
|
|
|
|
*
|
|
|
|
* @param object $instance
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function can_delete_instance($instance) {
|
|
|
|
$context = context_course::instance($instance->courseid);
|
|
|
|
return has_capability('enrol/guest:config', $context);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
$context = context_course::instance($instance->courseid);
|
2015-10-23 10:39:03 +08:00
|
|
|
if (!has_capability('enrol/guest:config', $context)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the instance is currently disabled, before it can be enabled, we must check whether the password meets the
|
|
|
|
// password policies.
|
|
|
|
if ($instance->status == ENROL_INSTANCE_DISABLED) {
|
|
|
|
if ($this->get_config('requirepassword')) {
|
|
|
|
if (empty($instance->password)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->get_config('usepasswordpolicy')) {
|
|
|
|
if (!check_password_policy($instance->password, $errmsg)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-08-11 16:04:03 -03:00
|
|
|
}
|
2015-10-01 10:37:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get default settings for enrol_guest.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_instance_defaults() {
|
|
|
|
$fields = array();
|
|
|
|
$fields['status'] = $this->get_config('status');
|
|
|
|
return $fields;
|
|
|
|
}
|
2015-11-17 10:59:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return information for enrolment instance containing list of parameters required
|
|
|
|
* for enrolment, name of enrolment plugin etc.
|
|
|
|
*
|
|
|
|
* @param stdClass $instance enrolment instance
|
|
|
|
* @return stdClass instance info.
|
|
|
|
* @since Moodle 3.1
|
|
|
|
*/
|
|
|
|
public function get_enrol_info(stdClass $instance) {
|
|
|
|
|
|
|
|
$instanceinfo = new stdClass();
|
|
|
|
$instanceinfo->id = $instance->id;
|
|
|
|
$instanceinfo->courseid = $instance->courseid;
|
|
|
|
$instanceinfo->type = $this->get_name();
|
|
|
|
$instanceinfo->name = $this->get_instance_name($instance);
|
|
|
|
$instanceinfo->status = $instance->status == ENROL_INSTANCE_ENABLED;
|
|
|
|
|
|
|
|
// Specifics enrolment method parameters.
|
|
|
|
$instanceinfo->requiredparam = new stdClass();
|
|
|
|
$instanceinfo->requiredparam->passwordrequired = !empty($instance->password);
|
|
|
|
|
|
|
|
// If the plugin is enabled, return the URL for obtaining more information.
|
|
|
|
if ($instanceinfo->status) {
|
|
|
|
$instanceinfo->wsfunction = 'enrol_guest_get_instance_info';
|
|
|
|
}
|
|
|
|
return $instanceinfo;
|
|
|
|
}
|
2010-09-21 10:42:19 +00:00
|
|
|
}
|