]> git.mjollnir.org Git - moodle.git/commitdiff
$CFG->defaultcourseroleid defines a site default for the role given to
authormoodler <moodler>
Sun, 17 Sep 2006 09:22:33 +0000 (09:22 +0000)
committermoodler <moodler>
Sun, 17 Sep 2006 09:22:33 +0000 (09:22 +0000)
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
course/edit.html
course/edit.php
version.php

index 0c6b3816086151f0f39843ab439e9b4072c741f6..0c50cced7e61a8ab0f845a7f13837c97bf351725 100644 (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));
index 71bfcf3506ba52bc649ac3098ec1b145e6492e88..6cab9201939174bf1a6973df3dcc345eb36fb99c 100644 (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" >
             }
             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
index 91b6f2900142bcad054a6ad3622277a58ca49d20..2d1ff3dea041b2eb484a35b6d40066eccec57ed2 100644 (file)
     $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!");
 
         $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) {
index f8299175ff8eb5c6f05fd913b5053bc814ac6973..f01423f67055b414b168fe0e83b18a00180a42aa 100644 (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