]> git.mjollnir.org Git - moodle.git/commitdiff
making hidden assignment work with multiple roles
authortoyomoyo <toyomoyo>
Thu, 16 Nov 2006 08:29:25 +0000 (08:29 +0000)
committertoyomoyo <toyomoyo>
Thu, 16 Nov 2006 08:29:25 +0000 (08:29 +0000)
course/lib.php
lib/accesslib.php

index 59ea351835daddc7773ea95b1a1f82aec3b8f089..b01f15e9736fb581e6fc80079991cce325ecc942 100644 (file)
@@ -1547,22 +1547,19 @@ function print_course($course, $width="100%") {
     echo '<td valign="top" width="50%" class="info">';
     echo '<b><a title="'.get_string('entercourse').'"'.
          $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
-         $course->fullname.'</a></b><br />';
-
+         $course->fullname.'</a></b><br />';   
+    
     if ($teachers = get_users_by_capability($context, 'moodle/course:update',
-                                            'u.*, ul.timeaccess as lastaccess, ra.hidden',
-                                            'r.sortorder ASC', '','','','', false)) {
-                                              
-        $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
+                                            'u.*, ul.timeaccess as lastaccess',
+                                            'r.sortorder ASC', '','','','', false, true)) {        
         $namesarray = array();
         foreach ($teachers as $teacher) {
-            if (!$teacher->hidden || $canseehidden) {
-                $roles = get_user_roles($context, $teacher->id, true, 'r.sortorder ASC');
+            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='.
-                                  $teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
-            }
+                                    $teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
+            }          
         }
         if ($namesarray) {
             echo "<ul class=\"teachers\">\n<li>";
index c440539683f04109c2cd77f860bb403eee57eb19..3dba6c35fb4dabb49b50707aef2341641574e881 100755 (executable)
@@ -2870,9 +2870,14 @@ function get_all_roles() {
  * allow_override tables
  * @param object $context
  * @param int $userid
+ * @param view - set to true when roles are pulled for display only
+ *               this is so that we can filter roles with no visible 
+ *               assignment, for example, you might want to "hide" all
+ *               course creators when browsing the course participants
+ *               list.
  * @return array
  */
-function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order='c.contextlevel DESC, r.sortorder ASC') {
+function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order='c.contextlevel DESC, r.sortorder ASC', $view=false) {
 
     global $USER, $CFG, $db;
 
@@ -2882,6 +2887,8 @@ 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 ';
 
     if ($checkparentcontexts && ($parents = get_parent_contexts($context))) {
         $contexts = ' ra.contextid IN ('.implode(',' , $parents).','.$context->id.')';
@@ -2896,7 +2903,7 @@ function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order='
                              WHERE ra.userid = '.$userid.
                            '   AND ra.roleid = r.id
                                AND ra.contextid = c.id
-                               AND '.$contexts.
+                               AND '.$contexts . $hiddensql .
                            ' ORDER BY '.$order);
 }
 
@@ -3012,9 +3019,14 @@ function get_default_course_role($course) {
  * @param $limitnum - number of records to fetch
  * @param $groups - single group or array of groups - group(s) user is in
  * @param $exceptions - list of users to exclude
+ * @param view - set to true when roles are pulled for display only
+ *               this is so that we can filter roles with no visible 
+ *               assignment, for example, you might want to "hide" all
+ *               course creators when browsing the course participants
+ *               list.
  */
 function get_users_by_capability($context, $capability, $fields='', $sort='',
-                                 $limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true) {
+                                 $limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true, $view=false) {
     global $CFG;
 
 /// Sorting out groups
@@ -3045,6 +3057,8 @@ 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 ';
 
 /// If context is a course, then construct sql for ul
     if ($context->contextlevel == CONTEXT_COURSE) {
@@ -3095,8 +3109,9 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
                   AND u.deleted = 0
                   AND ra.roleid in $roleids
                       $exceptionsql
-                      $groupsql";
-
+                      $groupsql
+                      $hiddensql";
+        
     return get_records_sql($select.$from.$where.$sortby, $limitfrom, $limitnum);
 }