$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.
This commit is contained in:
moodler 2006-09-17 09:22:33 +00:00
parent b29ab53d31
commit 88af238ccb
4 changed files with 53 additions and 8 deletions

View File

@ -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));

View File

@ -51,6 +51,9 @@
if(!isset($form->restrictmodules)) {
$form->restrictmodules = 0;
}
if(!isset($form->defaultrole)) {
$form->defaultrole = 0; // Use site default
}
?>
<form method="post" action="edit.php" name="form">
<table cellpadding="9" cellspacing="0" >
@ -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"));
?></td>
</tr>
<tr valign="top">
<td align="right"><?php print_string("defaultrole") ?>:</td>
<td><?php
$roles = get_assignable_roles($context);
asort($roles);
$choices = array();
if ($form->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"));
?></td>
</tr>
<tr valign="top">
<td align="right"><?php print_string("enrollable") ?>:</td>
<td><?php

View File

@ -15,11 +15,11 @@
$focus = "";
if ($id) {
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect");
if (! $course = get_record('course', 'id', $id)) {
error('Course ID was incorrect');
}
$context = get_context_instance(CONTEXT_COURSE, $id);
$context = get_context_instance(CONTEXT_COURSE, $course->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) {

View File

@ -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