mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-75441 mod_forum: Show add new post button to guest users
This commit is contained in:
parent
40a89d8a9a
commit
31d84aaa2c
8 changed files with 456 additions and 6 deletions
|
@ -231,7 +231,7 @@ class enrol_self_plugin extends enrol_plugin {
|
|||
* @return bool|string true if successful, else error message or false.
|
||||
*/
|
||||
public function can_self_enrol(stdClass $instance, $checkuserenrolment = true) {
|
||||
global $CFG, $DB, $OUTPUT, $USER;
|
||||
global $DB, $OUTPUT, $USER;
|
||||
|
||||
if ($checkuserenrolment) {
|
||||
if (isguestuser()) {
|
||||
|
@ -244,8 +244,10 @@ class enrol_self_plugin extends enrol_plugin {
|
|||
}
|
||||
}
|
||||
|
||||
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
||||
return get_string('canntenrol', 'enrol_self');
|
||||
// Check if self enrolment is available right now for users.
|
||||
$result = $this->is_self_enrol_available($instance);
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Check if user has the capability to enrol in this context.
|
||||
|
@ -253,6 +255,23 @@ class enrol_self_plugin extends enrol_plugin {
|
|||
return get_string('canntenrol', 'enrol_self');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
||||
return get_string('canntenrol', 'enrol_self');
|
||||
}
|
||||
|
||||
if ($instance->enrolstartdate != 0 and $instance->enrolstartdate > time()) {
|
||||
return get_string('canntenrolearly', 'enrol_self', userdate($instance->enrolstartdate));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue