Skip to content

Commit

Permalink
Add a very useful feature to block_base to make instance config even …
Browse files Browse the repository at this point in the history
…more

convenient to use. And take advantage of it to make the block run faster.
  • Loading branch information
defacer committed Feb 1, 2005
1 parent bf94f83 commit 0144a0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ function instance_config_save($data) {
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);
}

}

/**
Expand Down
12 changes: 9 additions & 3 deletions blocks/quiz_results/block_quiz_results.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ function get_content() {
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)) {
Expand Down

0 comments on commit 0144a0a

Please sign in to comment.