]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10995 eliminated some get course record calls - reused $COURSE instead
authorskodak <skodak>
Sun, 26 Aug 2007 08:24:50 +0000 (08:24 +0000)
committerskodak <skodak>
Sun, 26 Aug 2007 08:24:50 +0000 (08:24 +0000)
blocks/admin/block_admin.php
blocks/section_links/block_section_links.php
calendar/lib.php
lib/pagelib.php

index f0fd74489f10d5cf8383429dd32e8932e6cca76e..0d8a59f0db8edf1827d44c31dd677eebd8185819 100644 (file)
@@ -8,7 +8,7 @@ class block_admin extends block_list {
 
     function get_content() {
 
-        global $CFG, $USER, $SITE;
+        global $CFG, $USER, $SITE, $COURSE;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -27,13 +27,13 @@ class block_admin extends block_list {
 
         if (!empty($this->instance->pageid)) {
             $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
-        }
-
-        if (empty($context)) {
+            if ($COURSE->id == $this->instance->pageid) {
+                $course = $COURSE;
+            } else {
+                $course = get_record('course', 'id', $this->instance->pageid);
+            }
+        } else {
             $context = get_context_instance(CONTEXT_SYSTEM);
-        }
-
-        if (!$course = get_record('course', 'id', $this->instance->pageid)) {
             $course = $SITE;
         }
 
index 0403226854297f930820d7cf83a7b6b88b097f0d..494619be885f156a8b5ee808d66e3015533e6ec4 100644 (file)
@@ -26,7 +26,7 @@ class block_section_links extends block_base {
     }
 
     function get_content() {
-        global $CFG, $USER;
+        global $CFG, $USER, $COURSE;
 
         $highlight = 0;
 
@@ -42,7 +42,11 @@ class block_section_links extends block_base {
             return $this->content;
         }
 
-        $course = get_record('course', 'id', $this->instance->pageid);
+        if ($this->instance->pageid == $COURSE->id) {
+            $course = $COURSE;
+        } else {
+            $course = get_record('course', 'id', $this->instance->pageid);
+        }
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
         if ($course->format == 'weeks' or $course->format == 'weekscss') {
index 796cf92b4605096986773e62d1fca3e998185780..7c17f5948a5e5261190ea0162558461c4092852b 100644 (file)
@@ -1154,8 +1154,13 @@ function calendar_get_module_cached(&$coursecache, $modulename, $instance) {
 }
 
 function calendar_get_course_cached(&$coursecache, $courseid) {
-    if(!isset($coursecache[$courseid])) {
-        $coursecache[$courseid] = get_record('course', 'id', $courseid);
+    global $COURSE;
+    if (!isset($coursecache[$courseid])) {
+        if ($courseid == $COURSE->id) {
+            $coursecache[$courseid] = $COURSE;
+        } else {
+            $coursecache[$courseid] = get_record('course', 'id', $courseid);
+        }
     }
     return $coursecache[$courseid];
 }
index f30a3ded36b8af8a6d36fdb0858d09323522cea2..747c2ae72410093a5439fee797d6b59fd74efab2 100644 (file)
@@ -328,13 +328,19 @@ class page_course extends page_base {
     // in init_quick() and instead deferred here. Of course this function had better recognize
     // $this->full_init_done to prevent wasteful multiple-time data retrieval.
     function init_full() {
+        global $COURSE;
         if($this->full_init_done) {
             return;
         }
         if (empty($this->id)) {
             $this->id = 0; // avoid db errors
         }
-        $this->courserecord = get_record('course', 'id', $this->id);
+        if ($this->id == $COURSE->id) {
+            $this->courserecord = $COURSE;
+        } else {
+            $this->courserecord = get_record('course', 'id', $this->id);
+        }
+
         if(empty($this->courserecord) && !defined('ADMIN_STICKYBLOCKS')) {
             error('Cannot fully initialize page: invalid course id '. $this->id);
         }