$formats = $this->applicable_formats();
if (empty($formats) || array_sum($formats) === 0) {
- $errors[] = 'no_course_formats';
+ $errors[] = 'no_formats';
$correct = false;
}
* @todo finish documenting this function
*/
function applicable_formats() {
- // Default case: the block can be used in all course types and not in quizzes
- return array('all' => true, 'quiz' => false);
+ // Default case: the block can be used in all course types but not in activities
+ return array('all' => true, 'mod' => false);
}
}
function applicable_formats() {
- return (array('weeks' => true, 'topics' => true));
+ return (array('course-view-weeks' => true, 'course-view-topics' => true));
}
function get_content() {
}
function applicable_formats() {
- return array('social' => true);
+ return array('course-view-social' => true);
}
function get_content() {
if($block->visible && (!blocks_find_block($block->id, $pageblocks) || $block->multiple)) {
// And if it's applicable for display in this format...
$formats = block_method_result($block->name, 'applicable_formats');
- if(isset($formats[$pageformat]) ? $formats[$pageformat] : !empty($formats['all'])) {
- // Add it to the missing blocks
+ $accept = NULL;
+ foreach($formats as $format => $allowed) {
+ $thisformat = '^'.str_replace('*', '[^-]*', $format).'.*$';
+ if(ereg($thisformat, $pageformat)) {
+ $accept = $allowed;
+ break;
+ }
+ }
+ if($accept === NULL) {
+ // ...or in all pages...
+ $accept = !empty($formats['all']);
+ }
+ if(!empty($accept)) {
+ // ...add it to the missing blocks
$missingblocks[] = $block->id;
}
}
foreach($position as $instance) {
$block = blocks_get_record($instance->blockid);
$formats = block_method_result($block->name, 'applicable_formats');
- if(! (isset($formats[$pageformat]) ? $formats[$pageformat] : !empty($formats['all']))) {
- // Translation: if the course format is explicitly accepted/rejected, use
- // that setting. Otherwise, fallback to the 'all' format. The empty() test
- // uses the trick that empty() fails if 'all' is either !isset() or false.
-
- blocks_delete_instance($instance);
+ $accept = NULL;
+ foreach($formats as $format => $allowed) {
+ $thisformat = '^'.str_replace('*', '[^-]*', $format).'.*$';
+ if(ereg($thisformat, $pageformat)) {
+ $accept = $allowed;
+ break;
+ }
+ }
+ if($accept === NULL) {
+ $accept = !empty($formats['all']);
+ }
+ if(empty($accept)) {
+ blocks_delete_instance($instance);
}
}
}
return $this->id;
}
- // "Sensible default" case here. Don't trigger any error.
+ // "Sensible default" case here. Take it from the body id.
function get_format_name() {
- return NULL;
+ return $this->body_id;
}
// Returns $this->body_class
// the format_name might be that activity's name etc.
function get_format_name() {
$this->init_full();
- return $this->courserecord->format;
+ if($this->id == SITEID) {
+ return parent::get_format_name();
+ }
+ return $this->body_id.'-'.$this->courserecord->format;
}
// This should return a fully qualified path to the URL which is responsible for displaying us.
return PAGE_QUIZ_VIEW;
}
- // This is like the "category" of a page of this "type". For example, if the type is PAGE_COURSE_VIEW
- // the format_name is the actual name of the course format. If the type were PAGE_ACTIVITY_VIEW, then
- // the format_name might be that activity's name etc.
- function get_format_name() {
- return 'quiz';
- }
-
// This should return a fully qualified path to the URL which is responsible for displaying us.
function url_get_path() {
global $CFG;