From 88af238ccbbf7b36c1439a0b69fc3556ce9107c6 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 17 Sep 2006 09:22:33 +0000 Subject: [PATCH] $CFG->defaultcourseroleid defines a site default for the role given to people who enrol in the course. $course->defaultrole defines the value for each course for what role should be used in the same case. Naturally it defaults to the site config (when it is zero). This role is retained even when the person editing the course settings doesn't actually have that role in their list of assignable rights (however they are prevented from actually switching to any such role themselves). Note that enrol plugins are free to ignore these values and use whatever roles they like. Generally, though, they should respect these settings. --- admin/settings/users.php | 15 ++++++++++++--- course/edit.html | 32 +++++++++++++++++++++++++++++++- course/edit.php | 12 +++++++++--- version.php | 2 +- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/admin/settings/users.php b/admin/settings/users.php index 0c6b381608..0c50cced7e 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -24,12 +24,21 @@ $temp = new admin_settingpage('userpolicies', get_string('userpolicies', 'admin' $context = get_context_instance(CONTEXT_SYSTEM, SITEID); if (!$guestrole = get_guest_role()) { - $guestrole->id = 999; + $guestrole->id = 0; } +if ($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) { + $studentrole = array_shift($studentroles); /// Take the first one +} else { + $studentrole->id = 0; +} +$assignableroles = get_assignable_roles($context); + $temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'), - get_string('confignotloggedinroleid', 'admin'), $guestrole->id, get_assignable_roles($context))); + get_string('confignotloggedinroleid', 'admin'), $guestrole->id, $assignableroles )); $temp->add(new admin_setting_configselect('defaultuserroleid', get_string('defaultuserroleid', 'admin'), - get_string('configdefaultuserroleid', 'admin'), $guestrole->id, get_assignable_roles($context))); + get_string('configdefaultuserroleid', 'admin'), $guestrole->id, $assignableroles)); +$temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'), + get_string('configdefaultcourseroleid', 'admin'), $studentrole->id, $assignableroles)); //$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0)); //$temp->add(new admin_setting_configcheckbox('allusersaresitestudents', get_string('allusersaresitestudents', 'admin'), get_string('configallusersaresitestudents','admin'), 1)); diff --git a/course/edit.html b/course/edit.html index 71bfcf3506..6cab920193 100644 --- a/course/edit.html +++ b/course/edit.html @@ -51,6 +51,9 @@ if(!isset($form->restrictmodules)) { $form->restrictmodules = 0; } + if(!isset($form->defaultrole)) { + $form->defaultrole = 0; // Use site default + } ?>
@@ -126,11 +129,38 @@ } asort($choices); $choices = array_flip($choices); - $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string("enrolname", "enrol_$CFG->enrol").')'), $choices); + $choices = array('' => get_string('sitedefault').' ('.get_string("enrolname", "enrol_$CFG->enrol").')') + $choices; choose_from_menu ($choices, "enrol", "$form->enrol", ""); helpbutton("courseenrolmentplugins", get_string("enrolmentplugins")); ?> + + + +
:defaultrole && !isset($roles[$form->defaultrole])) { // Existing setting is one we can't choose + if ($coursedefaultrole = get_record('role', 'id', $form->defaultrole)) { + $choices[-1] = get_string('currentrole', 'role').' ('.$coursedefaultrole->name.')'; + } else { + $choices[-1] = get_string('currentrole', 'role'); + } + } + + if ($sitedefaultrole = get_record('role', 'id', $CFG->defaultcourseroleid)) { + $choices[0] = get_string('sitedefault').' ('.$sitedefaultrole->name.')'; + } else { + $choices[0] = get_string('sitedefault'); + } + + $choices = $choices + $roles; + + choose_from_menu ($choices, 'defaultrole', $form->defaultrole, ''); + helpbutton("coursedefaultrole", get_string("defaultrole")); + ?>
: id); if (!has_capability('moodle/course:update', $context)) { error("You do not currently have editing privileges!"); @@ -74,6 +74,12 @@ $form->format = optional_param('format', 'social', PARAM_ALPHA); + $form->defaultrole = optional_param('defaultrole', 0, PARAM_INT); + if ($form->defaultrole == -1) { // Just leave it however it is + unset($form->defaultrole); + } + + validate_form($course, $form, $err); if (count($err) == 0) { diff --git a/version.php b/version.php index f8299175ff..f01423f670 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2006091700; // YYYYMMDD = date + $version = 2006091701; // YYYYMMDD = date // XY = increments within a single day $release = '1.7 dev'; // Human-friendly version name -- 2.39.5