]> git.mjollnir.org Git - moodle.git/commitdiff
fix for MDL-7595, adding coursemanager config variable to determine what roles are...
authortoyomoyo <toyomoyo>
Fri, 17 Nov 2006 08:57:50 +0000 (08:57 +0000)
committertoyomoyo <toyomoyo>
Fri, 17 Nov 2006 08:57:50 +0000 (08:57 +0000)
admin/settings/appearance.php
course/lib.php
lang/en_utf8/admin.php
lib/accesslib.php
lib/adminlib.php

index 789241c9361dfa25d3bc82ee407958c545a1a8a6..ae14f00ed7561d72d12712444425f84f6833bc3e 100644 (file)
@@ -123,6 +123,10 @@ $temp = new admin_settingpage('gradebook', get_string('gradebook', 'admin'));
 $temp->add(new admin_setting_special_gradebookroles());
 $ADMIN->add('appearance', $temp);
 
+// new CFG variable for coursemanager (what roles to display)
+$temp = new admin_settingpage('coursemanager', get_string('coursemanager', 'admin'));
+$temp->add(new admin_setting_special_coursemanager());
+$ADMIN->add('appearance', $temp);
 
 $ADMIN->add('appearance', new admin_externalpage('stickyblocks', get_string('stickyblocks', 'admin'), "$CFG->wwwroot/$CFG->admin/stickyblocks.php"));
 
index b01f15e9736fb581e6fc80079991cce325ecc942..3869afa98dda3ed76c7b505145c08af8d7e28825 100644 (file)
@@ -1549,25 +1549,27 @@ function print_course($course, $width="100%") {
          $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
          $course->fullname.'</a></b><br />';   
     
-    if ($teachers = get_users_by_capability($context, 'moodle/course:update',
-                                            'u.*, ul.timeaccess as lastaccess',
-                                            'r.sortorder ASC', '','','','', false, true)) {        
-        $namesarray = array();
-        foreach ($teachers as $teacher) {
-            if ($roles = get_user_roles($context, $teacher->id, true, 'r.sortorder ASC', true)) {
-                $role = array_shift($roles);  // First one
-                $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
-                $namesarray[] = format_string($role->name).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
+    /// first find all roles that are supposed to be displayed
+    if ($managerroles = get_config('', 'coursemanager')) {
+        $coursemanagerroles = split(',', $managerroles->value);
+        foreach ($coursemanagerroles as $roleid) {
+            $role = get_record('role','id',$roleid);
+            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='.
                                     $teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
+                }
             }          
         }
-        if ($namesarray) {
+        
+        if (!empty($namesarray)) {
             echo "<ul class=\"teachers\">\n<li>";
             echo implode('</li><li>', $namesarray);
             echo "</li></ul>";
         }
     }
-
+    
     require_once("$CFG->dirroot/enrol/enrol.class.php");
     $enrol = enrolment_factory::factory($course->enrol);
     echo $enrol->get_access_icons($course);
index 771de2415729940a43131887924f5f3adadae2c1..44884d05c8a5ccc0b7b4562f9def907f7bec9b35 100644 (file)
@@ -57,6 +57,7 @@ $string['configclamactlikevirus'] = 'Treat files like viruses';
 $string['configclamdonothing'] = 'Treat files as OK';
 $string['configclamfailureonupload'] = 'If you have configured clam to scan uploaded files, but it is configured incorrectly or fails to run for some unknown reason, how should it behave?  If you choose \'Treat files like viruses\', they\'ll be moved into the quarantine area, or deleted. If you choose \'Treat files as OK\', the files will be moved to the desination directory like normal. Either way, admins will be alerted that clam has failed.  If you choose \'Treat files like viruses\' and for some reason clam fails to run (usually because you have entered an invalid pathtoclam), ALL files that are uploaded will be moved to the given quarantine area, or deleted. Be careful with this setting.';
 $string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts.  To force users to choose a country, just leave this unset.';
+$string['configcoursemanager'] = 'This setting allows you to control who appears on the course description. Users need to have at least one of these roles in a course to be shown on the course description for that course.';
 $string['configcoursesperpage'] = 'Enter the number of courses to be display per page in a course listing.';
 $string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions.  This is especially useful for large/busy sites or sites built on cluster of servers.  For most sites this should probably be left disabled so that the server disk is used instead.  Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M.';
 $string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed.  This is only useful for developers.';
@@ -179,6 +180,7 @@ $string['configzip'] = 'Indicate the location of your zip program (Unix only, op
 $string['confirmation'] = 'Confirmation';
 $string['confirminstall'] = 'You are about to install language pack ($a), are you sure?';
 $string['country'] = 'Default country';
+$string['coursemanager'] = 'Course managers';
 $string['coursemgmt'] = 'Add/edit courses';
 $string['courseoverview'] = 'Course overview';
 $string['courserequests'] = 'Course Requests';
index 3dba6c35fb4dabb49b50707aef2341641574e881..944b5bcc83f9fc48f698d5b028380f03cab60e44 100755 (executable)
@@ -2767,7 +2767,7 @@ function get_roles_used_in_context($context, $view = false) {
     // filter for roles with all hidden assignments
     // no need to return when only pulling roles for reviewing
     // e.g. participants page.
-    $hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 ';   
+    $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND ra.hidden = 0 ':'';   
     $contextlist = get_related_contexts_string($context);
 
     $sql = "SELECT DISTINCT r.id,
@@ -2888,7 +2888,7 @@ function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order='
         $userid = $USER->id;
     }
     // set up hidden sql
-    $hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 ';
+    $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND ra.hidden = 0 ':'';
 
     if ($checkparentcontexts && ($parents = get_parent_contexts($context))) {
         $contexts = ' ra.contextid IN ('.implode(',' , $parents).','.$context->id.')';
@@ -3058,7 +3058,7 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
 
     $sortby = $sort ? " ORDER BY $sort " : '';
 /// Set up hidden sql
-    $hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 ';
+    $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND ra.hidden = 0 ':'';
 
 /// If context is a course, then construct sql for ul
     if ($context->contextlevel == CONTEXT_COURSE) {
@@ -3122,7 +3122,7 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
  * @param bool parent if true, get list of users assigned in higher context too
  * @return array()
  */
-function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.lastname ASC') {
+function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.lastname ASC', $view=false) {
     global $CFG;
 
     if (empty($fields)) {
@@ -3132,6 +3132,8 @@ function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.l
                   'u.emailstop, u.lang, u.timezone';
     }
 
+    // whether this assignment is hidden
+    $hiddensql = ($view && !has_capability('moodle/role:viewhiddenassigns', $context))? ' AND r.hidden = 0 ':'';
     if ($parent) {
         if ($contexts = get_parent_contexts($context)) {
             $parentcontexts = ' OR r.contextid IN ('.implode(',', $contexts).')';
@@ -3153,6 +3155,7 @@ function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.l
                  {$CFG->prefix}user u
             WHERE (r.contextid = $context->id $parentcontexts)
             AND u.id = r.userid $roleselect
+            $hiddensql
             ORDER BY $sort
             ";                  // join now so that we can just use fullname() later
 
index 1766f8e861e8fb62e7a70771eee91e302c0039bd..0cf3b9fed61e7f3b1c7c9df6a29c6def7b6a04d8 100644 (file)
@@ -2376,6 +2376,79 @@ class admin_setting_special_gradebookroles extends admin_setting {
 
 }
 
+/*
+ * this is used in config->appearance->coursemanager
+ * (which roles to show on course decription page)
+ */
+class admin_setting_special_coursemanager extends admin_setting {
+
+    function admin_setting_special_coursemanager() {
+        $name = 'coursemanager';
+        $visiblename = get_string('coursemanager', 'admin');
+        $description = get_string('configcoursemanager', 'admin');
+        $default = array(3=>'1');    // The teahcer role in a default install
+        parent::admin_setting($name, $visiblename, $description, $default);
+    }
+
+    function get_setting() {
+
+        global $CFG;
+        if (!empty($CFG->{$this->name})) {
+            $result = explode(',', $CFG->{$this->name});
+            foreach ($result as $roleid) {
+                $array[$roleid] = 1;  
+            }
+            return $array;
+        } else {
+            return null;
+        }
+    }
+
+    function write_setting($data) {
+
+        if (!empty($data)) {
+            $str = '';
+            foreach ($data as $key => $value) {
+                if ($value) {
+                    $str .= $key.',';
+                }
+            }
+            return set_config($this->name, rtrim($str, ","))?'':get_string('errorsetting', 'admin') . $this->visiblename . '<br />';
+        } else {
+            return set_config($this->name, '')?'':get_string('errorsetting', 'admin') . $this->visiblename . '<br />';
+        }
+    }
+
+    function output_html() {
+
+        if ($this->get_setting() === NULL) {
+            $currentsetting = $this->defaultsetting;
+        } else {
+            $currentsetting = $this->get_setting();
+        }
+        // from to process which roles to display
+        if ($roles = get_records('role')) {
+            $return = '<div class="form-group">';
+            $first = true;
+            foreach ($roles as $roleid=>$role) {
+                if (is_array($currentsetting) && in_array($roleid, array_keys($currentsetting))) {
+                    $checked = 'checked="checked"';
+                } else {
+                    $checked = '';
+                }
+                if ($first) {
+                    $first = false;
+                } else {
+                    $return .= '<br />';
+                }
+                $return .= '<input type="checkbox" name="s_'.$this->name.'['.$roleid.']" value="1" '.$checked.'>&nbsp;'.$role->name;
+            }
+            $return .= '</div>';
+        }
+        return format_admin_setting($this->name, $this->visiblename, $return, $this->description);
+    }
+}
+
 class admin_setting_special_perfdebug extends admin_setting_configcheckbox {
 
     function admin_setting_special_perfdebug() {
@@ -2386,6 +2459,7 @@ class admin_setting_special_perfdebug extends admin_setting_configcheckbox {
     }
 
     function write_setting($data) {
+
         if ($data == '1') {
             return (set_config($this->name,15) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '<br />');
         } else {
@@ -2394,6 +2468,7 @@ class admin_setting_special_perfdebug extends admin_setting_configcheckbox {
     }
 
     function output_html() {
+
         if ($this->get_setting() === NULL) {
             $currentsetting = $this->defaultsetting;
         } else {