]> git.mjollnir.org Git - moodle.git/commitdiff
Adding hidden role assignment, currently used in course participants page and print_c...
authortoyomoyo <toyomoyo>
Wed, 15 Nov 2006 04:28:18 +0000 (04:28 +0000)
committertoyomoyo <toyomoyo>
Wed, 15 Nov 2006 04:28:18 +0000 (04:28 +0000)
Please test.

admin/roles/assign.html
admin/roles/assign.php
lang/en_utf8/moodle.php
lib/accesslib.php
user/index.php

index 8ee63e9a473983c5cf2824fe2f7ecf5705ac4164..620d77bcf71f69bf31b4c144de831e73f0391d50 100755 (executable)
@@ -31,6 +31,8 @@
 
           </select></td>
       <td valign="top">
+        <input type="checkbox" name="hidden" value="1" />
+        <img src="<?php echo $CFG->pixpath; ?>/t/hide.gif" alt="<?php print_string('hiddenassign') ?>" class="hide-show-image" />
         <br />
         <input name="add" type="submit" id="add" value="&larr;" />
         <br />
index b36bbf10078d558a4eaf87d89e28d688abe05905..d49cc3daed911c87a04327a37f23de97755f5832 100755 (executable)
@@ -19,7 +19,7 @@
     $timeend        = optional_param('timened', 0, PARAM_INT);
     $userid         = optional_param('userid', 0, PARAM_INT); // needed for user tabs
     $courseid       = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
-
+    
     $errors = array();
 
     $previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
index 8da55c08953a1dc9fb4779a7747732bec9c7c994..92288d1134c2a7dffede22c96d046569b68c8be7 100644 (file)
@@ -668,6 +668,7 @@ $string['helpsummaries'] = 'About these summaries';
 $string['helptext'] = 'How to write text';
 $string['helpwiki'] = 'How to write Wiki-like text';
 $string['helpwriting'] = 'Write carefully';
+$string['hiddenassign'] = 'Hidden assignment';
 $string['hiddensections'] = 'Hidden sections';
 $string['hiddensectionscollapsed'] = 'Hidden sections are shown in collapsed form';
 $string['hiddensectionsinvisible'] = 'Hidden sections are completely invisible';
index 9efcbad8bdedb534b702103e41f9923ce496cdff..1cba7edc8eedfb5ca40380c0adc6113b601d312c 100755 (executable)
@@ -2707,11 +2707,21 @@ function get_component_string($component, $contextlevel) {
 /**
  * Gets the list of roles assigned to this context and up (parents)
  * @param object $context
+ * @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_roles_used_in_context($context) {
+function get_roles_used_in_context($context, $view = false) {
 
     global $CFG;
+    
+    // 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 ';   
     $contextlist = get_related_contexts_string($context);
 
     $sql = "SELECT DISTINCT r.id,
@@ -2722,6 +2732,7 @@ function get_roles_used_in_context($context) {
                    {$CFG->prefix}role r
              WHERE r.id = ra.roleid
                AND ra.contextid $contextlist
+                   $hiddensql
           ORDER BY r.sortorder ASC";
 
     return get_records_sql($sql);
index 27d695dc513f2856ddeef64cccf9180efe6122fc..ef7361c4e58ff160714aa0aaa7bbf34a545ec4a6 100644 (file)
     }
 
 
-    if ($roles = get_roles_used_in_context($context)) {
+    if ($roles = get_roles_used_in_context($context, true)) {
         
         // We should exclude "admin" users (those with "doanything" at site level) because 
         // Otherwise they appear in every participant list
         $selectrole = " ";
     }
     $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
-        u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, ul.timeaccess AS lastaccess '; // s.lastaccess
+        u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, ul.timeaccess AS lastaccess, r.hidden '; // s.lastaccess
     //$select .= $course->enrolperiod?', s.timeend ':'';
     $from   = "FROM {$CFG->prefix}user u INNER JOIN
     {$CFG->prefix}role_assignments r on u.id=r.userid LEFT OUTER JOIN
     {$CFG->prefix}user_lastaccess ul on (r.userid=ul.userid and ul.courseid = $course->id)"; 
+    
+    $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';
+    
     // join on 2 conditions
     // otherwise we run into the problem of having records in ul table, but not relevant course
     // and user record is not pulled out
     $where  = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
         AND u.deleted = 0 $selectrole
         AND (ul.courseid = $course->id OR ul.courseid IS NULL)
-        AND u.username <> 'guest' ";
+        AND u.username <> 'guest' 
+        $hiddensql ";
         $where .= get_lastaccess_sql($accesssince);
 
     $wheresearch = '';
     } else {
         $countrysort = (strpos($sort, 'country') !== false);
         $timeformat = get_string('strftimedate');
+
+
         if (!empty($userlist))  {
             foreach ($userlist as $user) {
+                if ($user->hidden) {        
+                // if the assignment is hidden, display icon
+                    $hidden = "<img src=\"{$CFG->pixpath}/t/hide.gif\" alt=\"".get_string('hiddenassign')."\" class=\"hide-show-image\"/>";
+                } else {
+                    $hidden = '';  
+                }
+                
                 if ($user->lastaccess) {
                     $lastaccess = format_time(time() - $user->lastaccess, $datestring);
                 } else {
 
                 $data = array (
                         print_user_picture($user->id, $course->id, $user->picture, false, true),
-                        '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user).'</a></strong>');
+                        '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user).'</a></strong>'.$hidden);
                 if (!isset($hiddenfields['city'])) {
                     $data[] = $user->city;
                 }