merged fix for MDL-9656, blocks parents can be system context
authortoyomoyo <toyomoyo>
Mon, 7 May 2007 03:24:22 +0000 (03:24 +0000)
committertoyomoyo <toyomoyo>
Mon, 7 May 2007 03:24:22 +0000 (03:24 +0000)
lib/accesslib.php

index 2906d531f4bb786bff0e02e6dd58bd3a4b4c9387..10020d1883c922806a98a09dd4c1bed6bd98b2f8 100755 (executable)
@@ -1344,7 +1344,11 @@ function capability_prohibits($capability, $context, $sum='', $array='') {
                 $prohibits[$capability][$context->id] = false;
                 return false;
             }
-            $parent = get_context_instance(CONTEXT_COURSE, $block->pageid); // needs check
+            if ($block->pagetype == 'course-view') {
+                $parent = get_context_instance(CONTEXT_COURSE, $block->pageid); // needs check
+            } else {
+                $parent = get_context_instance(CONTEXT_SYSTEM); 
+            }           
             $prohibits[$capability][$context->id] = capability_prohibits($capability, $parent);
             return $prohibits[$capability][$context->id];
         break;
@@ -2982,12 +2986,19 @@ function get_parent_contexts($context) {
             if (!$block = get_record('block_instance','id',$context->instanceid)) {
                 return array();
             }
-            if ($parent = get_context_instance(CONTEXT_COURSE, $block->pageid)) {
+            // fix for MDL-9656, block parents are not necessarily courses
+            if ($block->pagetype == 'course-view') {
+                $parent = get_context_instance(CONTEXT_COURSE, $block->pageid);
+            } else {
+                $parent = get_context_instance(CONTEXT_SYSTEM); 
+            }                       
+            
+            if ($parent) {
                 $res = array_merge(array($parent->id), get_parent_contexts($parent));
                 $pcontexts[$context->id] = $res;
                 return $res;
             } else {
-                return array();
+                return array();              
             }
         break;
 
@@ -3880,7 +3891,6 @@ function insert_context_rel($context, $deletechild=true, $deleteparent=true) {
     }  
 }
 
-
 /**
  * rebuild context_rel table without deleting
  */