]> git.mjollnir.org Git - moodle.git/commitdiff
fix for MDL-8966, customizable role names
authortoyomoyo <toyomoyo>
Thu, 22 Mar 2007 08:11:30 +0000 (08:11 +0000)
committertoyomoyo <toyomoyo>
Thu, 22 Mar 2007 08:11:30 +0000 (08:11 +0000)
course/edit.php
course/edit_form.php
course/lib.php
lib/accesslib.php
user/index.php

index 98b31adea1e90aabad7c7ea9a20099fb9f6516e0..8e0b8da3d27a21a8d147a54a17736cb06f5ec17a 100644 (file)
@@ -218,6 +218,41 @@ function update_course($data) {
         $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
         blocks_remove_inappropriate($page);
 
+        // put custom role names into db
+        $context = get_context_instance(CONTEXT_COURSE, $course->id);
+        
+        foreach ($data as $dname => $dvalue) {
+          
+            // is this the right param?
+            $dvalue = clean_param($dvalue, PARAM_NOTAGS);
+
+            if (!strstr($dname, 'role_')) {
+                continue;
+            }  
+            
+            $dt = explode('_', $dname);
+            $roleid = $dt[1];
+            // make up our mind whether we want to delete, update or insert
+            
+            if (empty($dvalue)) {
+                
+                delete_records('role_names', 'contextid', $context->id, 'roleid', $roleid);
+            
+            } else if ($t = get_record('role_names', 'contextid', $context->id, 'roleid', $roleid)) {
+                
+                $t->text = $dvalue;
+                update_record('role_names', $t);    
+                       
+            } else {
+                
+                $t->contextid = $context->id;
+                $t->roleid = $roleid;
+                $t->text = $dvalue;
+                insert_record('role_names', $t);  
+            }
+            
+        }
+
         redirect($CFG->wwwroot."/course/view.php?id=$course->id");
 
     } else {
index 6a5d1d2c883bc097458c1ca178c365d9b77da9fc..cd71c8aea1b954f62950e73c5ace9fd976baa8c9 100644 (file)
@@ -336,6 +336,21 @@ class course_edit_form extends moodleform {
         }
         $mform->setType('restrictmodules', PARAM_INT);
 
+/// customizable role names in this course
+//--------------------------------------------------------------------------------
+        $mform->addElement('header','', get_string('roles'));
+
+        if ($roles = get_records('role')) {
+            foreach ($roles as $role) {
+                $mform->addElement('text', 'role_'.$role->id, $role->name);
+                if ($coursecontext) {
+                    if ($rolename = get_record('role_names', 'roleid', $role->id, 'contextid', $coursecontext->id)) {
+                        $mform->setDefault('role_'.$role->id, $rolename->text); 
+                    }  
+                }
+            }
+        }
+
 //--------------------------------------------------------------------------------
         $this->add_action_buttons();
 //--------------------------------------------------------------------------------
index af2fc1caa9eec1d3c81eb41ed9691cf9a64eb48a..3b393056a28393eb5e5602cc67a362a7c5ed881b 100644 (file)
@@ -1801,7 +1801,7 @@ function print_course($course) {
             if ($users = get_role_users($roleid, $context, true, '', 'u.lastname ASC', true)) {
                 foreach ($users as $teacher) {
                     $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context)); 
-                    $namesarray[] = format_string($role->name).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
+                    $namesarray[] = role_get_name($role, $context).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
                                     $teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
                 }
             }          
index c57551b10ccea6b6dd7b98dcd601cce65360b9c2..09e849eef4756b98a5f344b8ccbd848887bb0897 100755 (executable)
@@ -3881,4 +3881,16 @@ function build_context_rel() {
     
     $db->debug = $savedb;
 }
+
+
+// gets the custom name of the role in course
+// TODO: proper documentation
+function role_get_name($role, $context) {
+    
+    if ($r = get_record('role_names','roleid', $role->id,'contextid', $context->id)) {
+        return format_string($r->text);  
+    } else {
+        return format_string($role->name);
+    }
+}
 ?>
index 88917dee5d1c4cf6c94cd12f760950da555dd320..3bcc2a25d9a4c6e369b6cc1a93eedd53340f26e8 100644 (file)
@@ -61,7 +61,7 @@
                 unset($roles[$role->id]);
                 continue;
             }
-            $rolenames[$role->id] = strip_tags(format_string($role->name));   // Used in menus etc later on
+            $rolenames[$role->id] = strip_tags(role_get_name($role, $context));   // Used in menus etc later on
         }
     }
 
             error('That role does not exist');
         }
         $a->number = $totalcount;
-        $a->role = $currentrole->name;
+        $a->role = role_get_name($currentrole, $context);
         $heading = get_string('xuserswiththerole', 'role', $a);
         if (user_can_assign($context, $roleid)) {
             $heading .= ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?roleid='.$roleid.'&amp;contextid='.$context->id.'">';