]> git.mjollnir.org Git - moodle.git/commitdiff
Updated to use new Roles System. Plus some fixes.
authorvyshane <vyshane>
Wed, 16 Aug 2006 08:54:07 +0000 (08:54 +0000)
committervyshane <vyshane>
Wed, 16 Aug 2006 08:54:07 +0000 (08:54 +0000)
blocks/moodleblock.class.php
blocks/online_users/block_online_users.php
blocks/participants/block_participants.php
blocks/quiz_results/block_quiz_results.php
blocks/social_activities/block_social_activities.php

index 3503cf7aa649d4a94234263a975edbe6a3a40300..9ff1a0b819692d11221ab8734c5e87da43677fe0 100644 (file)
@@ -718,7 +718,10 @@ class block_nuke extends block_base {
                         $oldvals['admin'] = $GLOBALS['admin'];
                     }
 
+                    // isteacher() will eventually be deprecated and blocks
+                    // should define their own capabilities.
                     $GLOBALS['admin'] = isteacher($this->course->id);
+                    
                     @include($dir.$file);
 
                     foreach($oldvals as $key => $val) {
@@ -739,4 +742,4 @@ class block_nuke extends block_base {
     }
 }
 
-?>
+?>
\ No newline at end of file
index 7eb84ffda0b933de4f959729212e8449010a5b15..8807fe94634c0c283ca4cfba357be7f516c54dc5 100644 (file)
@@ -1,5 +1,10 @@
 <?PHP //$Id$
 
+/**
+ * This block needs to be reworked.
+ * The new roles system does away with the concepts of rigid student and
+ * teacher roles.
+ */
 class block_online_users extends block_base {
     function init() {
         $this->title = get_string('blockname','block_online_users');
@@ -22,15 +27,20 @@ class block_online_users extends block_base {
         if (empty($this->instance)) {
             return $this->content;
         }
-    
+
         $timetoshowusers = 300; //Seconds default
         if (isset($CFG->block_online_users_timetosee)) {
             $timetoshowusers = $CFG->block_online_users_timetosee * 60;
         }
         $timefrom = time()-$timetoshowusers;
 
+        // Get context so we can check capabilities.
+        $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+
         //Calculate if we are in separate groups
-        $isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS && $COURSE->groupmodeforce && !isteacheredit($COURSE->id));
+        $isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS 
+                             && $COURSE->groupmodeforce
+                             && !has_capability('moodle/site:accessallgroups', $context));
 
         //Get the user current group
         $currentgroup = $isseparategroups ? get_current_group($COURSE->id) : NULL;
@@ -85,7 +95,9 @@ class block_online_users extends block_base {
                                           {$CFG->prefix}user_teachers s
                                           $groupmembers
                                      WHERE u.id = s.userid $courseselect $groupselect $timeselect ";
-
+        
+        // Now that we have the Roles System, how will we handle what
+        // used to be hidden teachers?
         if (!isteacher($COURSE->id)) {
             // Hide hidden teachers from students.
             $findteacherssql .= 'AND s.authority > 0 ';
@@ -131,4 +143,4 @@ class block_online_users extends block_base {
     }
 }
 
-?>
+?>
\ No newline at end of file
index 06921eb075b4c1b39150a7ef90de98dff28fbdbc..c54e9314357771c96b7cb962fbbc1dfc4dc7c668 100644 (file)
@@ -14,15 +14,17 @@ class block_participants extends block_list {
                if (empty($this->instance->pageid)) {
                        return '';  
                }
-                       
+               
+               $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+               
                // only 2 possible contexts, site or course
                if ($this->instance->pageid == SITEID) { // site context
-                       $context = get_context_instance(CONTEXT_SYSTEM, SITEID); 
+                       $currentcontext = $sitecontext;
                } else { // course context
-                       $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
+                       $currentcontext = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
                }
                
-               if (!has_capability('moodle/course:viewparticipants', $context)) {
+               if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
                        $this->context = '';
                        return $this->content;
                }
@@ -45,13 +47,14 @@ class block_participants extends block_list {
             $this->instance->pageid = SITEID;
         }
 
+        // $CFG->showsiteparticipantslist == 1  <-- this is deprecated.
         if ($this->instance->pageid != SITEID || 
             $CFG->showsiteparticipantslist > 1 || 
             ($CFG->showsiteparticipantslist == 1 && isteacherinanycourse()) || 
-            isteacher(SITEID)) {
+            has_capability('moodle/course:viewparticipants', $sitecontext)) {
 
             $this->content->items[] = '<a title="'.get_string('listofallpeople').'" href="'.
-                                      $CFG->wwwroot.'/user/index.php?contextid='.$context->id.'">'.get_string('participants').'</a>';
+                                      $CFG->wwwroot.'/user/index.php?contextid='.$currentcontext->id.'">'.get_string('participants').'</a>';
             $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="" />';
         }
 
@@ -66,4 +69,4 @@ class block_participants extends block_list {
 
 }
 
-?>
+?>
\ No newline at end of file
index ea92f77f43b2da94fafc5d4d4bdb8ef98960285f..c6e54093e7a90d5661f6862d8e09ce8bcf4b1b45 100644 (file)
@@ -51,6 +51,9 @@ class block_quiz_results extends block_base {
             $courseid = $this->config->courseid;
         }
 
+        $context = get_context_instance(CONTEXT_COURSE, $courseid);
+
+
         if(empty($quizid)) {
             $this->content->text = get_string('error_emptyquizid', 'block_quiz_results');
             return $this->content;
@@ -101,7 +104,7 @@ class block_quiz_results extends block_base {
             // The actual groupmode for the quiz is now known to be $groupmode
         }
 
-        if(isteacheredit($courseid) && $groupmode == SEPARATEGROUPS) {
+        if(has_capability('moodle/site:accessallgroups', $context) && $groupmode == SEPARATEGROUPS) {
             // We 'll make an exception in this case
             $groupmode = VISIBLEGROUPS;
         }
index c671c357cf8498aae3eb7e1e3ce1dede1afd6353..cd166a87efec73b9bf9a7e3e2c6a2e55952a49c2 100644 (file)
@@ -27,6 +27,7 @@ class block_social_activities extends block_list {
         }
 
         $course = get_record('course', 'id', $this->instance->pageid);
+        $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
         // To make our day, we start with an ugly hack
         global $sections, $mods, $modnames;
@@ -36,8 +37,8 @@ class block_social_activities extends block_list {
 
         $groupbuttons = $course->groupmode;
         $groupbuttonslink = (!$course->groupmodeforce);
-        $isteacher = isteacher($this->instance->pageid);
-        $isediting = isediting($this->instance->pageid);
+        $viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
+        $manageactivities = has_capability('moodle/course:manageactivities', $context);
         $ismoving = ismoving($this->instance->pageid);
         if ($ismoving) {
             $strmovehere = get_string('movehere');
@@ -61,7 +62,7 @@ class block_social_activities extends block_list {
                     continue;
                 }
                 $mod = $mods[$modnumber];
-                if ($isediting && !$ismoving) {
+                if ($manageactivities && !$ismoving) {
                     if ($groupbuttons) {
                         if (! $mod->groupmodelink = $groupbuttonslink) {
                             $mod->groupmode = $course->groupmode;
@@ -74,7 +75,7 @@ class block_social_activities extends block_list {
                 } else {
                     $editbuttons = '';
                 }
-                if ($mod->visible || $isteacher) {
+                if ($mod->visible || $viewhiddenactivities) {
                     if ($ismoving) {
                         if ($mod->id == $USER->activitycopy) {
                             continue;
@@ -115,7 +116,7 @@ class block_social_activities extends block_list {
             $this->content->icons[] = '';
         }
 
-        if ($isediting && $modnames) {
+        if ($manageactivities && $modnames) {
             $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
         } else {
             $this->content->footer = '';
@@ -125,4 +126,4 @@ class block_social_activities extends block_list {
     }
 }
 
-?>
+?>
\ No newline at end of file