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.
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'));