]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10995 removing previous patch; testing a better one just now
authorskodak <skodak>
Sat, 25 Aug 2007 14:35:54 +0000 (14:35 +0000)
committerskodak <skodak>
Sat, 25 Aug 2007 14:35:54 +0000 (14:35 +0000)
lib/accesslib.php

index d27c7ca656784beba3669cec59b0e9eccb56d52b..de52ba2209bd892f14b9f4582dcd1c9a0bc8e07c 100755 (executable)
@@ -681,7 +681,7 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr
  */
 function capability_search($capability, $context, $capabilities, $switchroleactive=false) {
 
-    global $USER, $CFG, $COURSE;
+    global $USER, $CFG;
 
     if (!isset($context->id)) {
         return 0;
@@ -712,16 +712,9 @@ function capability_search($capability, $context, $capabilities, $switchroleacti
         break;
 
         case CONTEXT_COURSECAT: // Coursecat -> coursecat or site
-            static $categorycache = null; // caching of parent categories - these are never changing on one page
-            if (!isset($categorycache)) {
-                $categorycache = array();
-            }
-            if (!array_key_exists($context->instanceid, $categorycache)) {
-                $coursecat = get_record('course_categories','id',$context->instanceid);
-                $categorycache[$context->instanceid] = $coursecat->parent;
-            }
-            if (!empty($categorycache[$context->instanceid])) { // return parent value if it exists
-                $parentcontext = get_context_instance(CONTEXT_COURSECAT, $categorycache[$context->instanceid]);
+            $coursecat = get_record('course_categories','id',$context->instanceid);
+            if (!empty($coursecat->parent)) { // return parent value if it exists
+                $parentcontext = get_context_instance(CONTEXT_COURSECAT, $coursecat->parent);
             } else { // else return site value
                 $parentcontext = get_context_instance(CONTEXT_SYSTEM);
             }
@@ -731,11 +724,7 @@ function capability_search($capability, $context, $capabilities, $switchroleacti
         case CONTEXT_COURSE: // 1 to 1 to course cat
             if (empty($switchroleactive)) {
                 // find the course cat, and return its value
-                if ($context->instanceid == $COURSE->id) {
-                    $course = $COURSE; // reuse the global COURSE we already have ;-)
-                } else {
-                    $course = get_record('course','id',$context->instanceid);
-                }
+                $course = get_record('course','id',$context->instanceid);
                 if ($course->id == SITEID) {   // In 1.8 we've separated site course and system
                     $parentcontext = get_context_instance(CONTEXT_SYSTEM);
                 } else {