]> git.mjollnir.org Git - moodle.git/commitdiff
Add a very useful feature to block_base to make instance config even more
authordefacer <defacer>
Tue, 1 Feb 2005 06:51:00 +0000 (06:51 +0000)
committerdefacer <defacer>
Tue, 1 Feb 2005 06:51:00 +0000 (06:51 +0000)
convenient to use. And take advantage of it to make the block run faster.

blocks/moodleblock.class.php
blocks/quiz_results/block_quiz_results.php

index 82170ae9ff0bde2b4db215a73f0c5bcf91b648b3..205d68048d61f40801c7302bcf36bd099e5c72f9 100644 (file)
@@ -539,6 +539,15 @@ class block_base {
         return set_field('block_instance', 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id);
     }
 
+    /**
+     * Replace the instance's configuration data with those currently in $this->config;
+     * @return boolean
+     * @todo finish documenting this function
+     */
+    function instance_config_commit() {
+        return set_field('block_instance', 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id);
+    }
+
 }
 
 /**
index eb32eb87f594fbd17eb96a43a9c34729ff418075..1b85cfdb6445539d98c9deba759dbd8b7de44261 100644 (file)
@@ -34,9 +34,15 @@ class block_quiz_results extends block_base {
         else {
             // Assuming we are displayed in the quiz view page
             $quizid    = $this->instance->pageid;
-            $modrecord = get_record('modules', 'name', 'quiz');
-            $cmrecord  = get_record('course_modules', 'module', $modrecord->id, 'instance', $quizid);
-            $courseid = $cmrecord->course;
+
+            // A trick to take advantage of instance config and save queries
+            if(empty($this->config->courseid)) {
+                $modrecord = get_record('modules', 'name', 'quiz');
+                $cmrecord  = get_record('course_modules', 'module', $modrecord->id, 'instance', $quizid);
+                $this->config->courseid = intval($cmrecord->course);
+                $this->instance_config_commit();
+            }
+            $courseid = $this->config->courseid;
         }
 
         if(empty($quizid)) {