MDL-24955 improved detection of available self enrol plugins

This commit is contained in:
Petr Skoda
2010-11-10 02:14:27 +00:00
parent 5882506d53
commit 45ff8a80d3
2 changed files with 28 additions and 14 deletions
+27
View File
@@ -768,6 +768,33 @@ function enrol_try_internal_enrol($courseid, $userid, $roleid = null, $timestart
return true;
}
/**
* 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') {
// blacklist known temporary guest plugins
continue;
}
if ($plugins[$instance->enrol]->show_enrolme_link($instance)) {
$result = true;
break;
}
}
return $result;
}
/**
* All enrol plugins should be based on this class,
* this is also the main source of documentation.
+1 -14
View File
@@ -111,20 +111,7 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
if (!isguestuser()) {
if (!is_enrolled($coursecontext)) {
//note: this is a bloody hack, make sure there is at least one enrol
// plugin that allows them to self enrol...
$enrolinstances = enrol_get_instances($course->id, true);
$somethingprobablyusefulforselfenrol = false;
foreach($enrolinstances as $instance) {
if ($instance->enrol === 'self' or $instance->enrol === 'paypal') {
$somethingprobablyusefulforselfenrol = true;
break;
}
}
unset($enrolinstances);
if ($somethingprobablyusefulforselfenrol) {
if (enrol_selfenrol_available($course->id)) {
$SESSION->wantsurl = $FULLME;
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol'));