- blocklib.php:
- Add: define ('COURSE_FORMAT_ALL', 0xFF);
- Change 'block_method_result' as follows:
function block_method_result($blockname, $method, $parameters=null) {
if(($block = block_instance($blockname, null)) === false) {
return NULL;
}
return ($block->$method($parameters));
}
- moodleblock.class.php:
- Add: is_applicable_format($format), as follows:
function is_applicable_format($format) {
// Default case: the block can be used in all course types
return (($this->applicable_formats() == COURSE_FORMAT_ALL) || ($this->applicable_formats() == $format));
} - Change: applicable_formats(), as follows:
function applicable_formats() {
// Default case: the block can be used in all course types
return COURSE_FORMAT_ALL;
}
- Add: is_applicable_format($format), as follows:
- course/view.php:
- Change the default for $course->format switch statement, as follows:
switch($course->format) {
case 'weeks':
$courseformat = COURSE_FORMAT_WEEKS;
break;
case 'topics':
$courseformat = COURSE_FORMAT_TOPICS;
break;
case 'social':
$courseformat = COURSE_FORMAT_SOCIAL;
break;
default:
$courseformat = COURSE_FORMAT_ALL;
} - Change the missing_blocks code as follows:
blocks_used($allblocks, $recblocks);
if($editing && $recblocks) {
foreach($recblocks as $recblock) {
// If it's not hidden or displayed right now...
if(!in_array($recblock->id, $allblocks) && !in_array(-($recblock->id), $allblocks)) {
// And if it's applicable for display in this format...
if(block_method_result($recblock->name, 'is_applicable_format', $courseformat)) {
// Add it to the missing blocks
$missingblocks[] = $recblock->id;
}
}
}
}
- Change the default for $course->format switch statement, as follows:
This would allow us to add new course formats without having to edit the 'blocks' code, something I'm sure you're in favour of. Thoughts?
I've also logged this as a feature request in the bug tracker.
mike