From 2b0d60ec78415b925b6a49d810667f6d6c10bcf3 Mon Sep 17 00:00:00 2001 From: defacer Date: Sun, 22 Aug 2004 16:54:48 +0000 Subject: [PATCH] Fix for bug 1662: Changed the way applicable formats for blocks are handled. The changes are short codewise, but to grasp all the implications read the forum discussion at the relevant URL. --- blocks/admin/block_admin.php | 4 ---- .../calendar_month/block_calendar_month.php | 4 ---- .../block_calendar_upcoming.php | 4 ---- blocks/course_list/block_course_list.php | 4 ---- .../course_summary/block_course_summary.php | 4 ---- blocks/login/block_login.php | 2 +- blocks/moodleblock.class.php | 8 ++++--- blocks/news_items/block_news_items.php | 4 ---- blocks/online_users/block_online_users.php | 4 ---- blocks/section_links/block_section_links.php | 2 +- .../site_main_menu/block_site_main_menu.php | 2 +- .../block_social_activities.php | 2 +- course/view.php | 23 ++++++------------- index.php | 10 +++++--- 14 files changed, 23 insertions(+), 54 deletions(-) diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php index 87a836485c..13a7b543b8 100644 --- a/blocks/admin/block_admin.php +++ b/blocks/admin/block_admin.php @@ -8,10 +8,6 @@ class CourseBlock_admin extends MoodleBlock { $this->version = 2004081200; } - function applicable_formats() { - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - } - function get_content() { if($this->content !== NULL) { diff --git a/blocks/calendar_month/block_calendar_month.php b/blocks/calendar_month/block_calendar_month.php index 46d771563a..aa04c241e9 100644 --- a/blocks/calendar_month/block_calendar_month.php +++ b/blocks/calendar_month/block_calendar_month.php @@ -8,10 +8,6 @@ class CourseBlock_calendar_month extends MoodleBlock { $this->version = 2004081200; } - function applicable_formats() { - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - } - function get_content() { global $USER, $CFG, $SESSION; optional_variable($_GET['cal_m']); diff --git a/blocks/calendar_upcoming/block_calendar_upcoming.php b/blocks/calendar_upcoming/block_calendar_upcoming.php index c1ed2ae726..07ca412105 100644 --- a/blocks/calendar_upcoming/block_calendar_upcoming.php +++ b/blocks/calendar_upcoming/block_calendar_upcoming.php @@ -8,10 +8,6 @@ class CourseBlock_calendar_upcoming extends MoodleBlock { $this->version = 2004052600; } - function applicable_formats() { - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - } - function get_content() { global $USER, $CFG, $SESSION; optional_variable($_GET['cal_m']); diff --git a/blocks/course_list/block_course_list.php b/blocks/course_list/block_course_list.php index e9b9054ab9..f25b7f8a56 100644 --- a/blocks/course_list/block_course_list.php +++ b/blocks/course_list/block_course_list.php @@ -27,10 +27,6 @@ class CourseBlock_course_list extends MoodleBlock { return true; } - function applicable_formats() { - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - } - function get_content() { global $THEME, $CFG, $USER; diff --git a/blocks/course_summary/block_course_summary.php b/blocks/course_summary/block_course_summary.php index 40d21b0cf1..a65774c329 100644 --- a/blocks/course_summary/block_course_summary.php +++ b/blocks/course_summary/block_course_summary.php @@ -12,10 +12,6 @@ class CourseBlock_course_summary extends MoodleBlock { $this->version = 2004052600; } - function applicable_formats() { - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - } - function get_content() { global $CFG, $THEME; diff --git a/blocks/login/block_login.php b/blocks/login/block_login.php index 89d8b54300..6e54061c67 100644 --- a/blocks/login/block_login.php +++ b/blocks/login/block_login.php @@ -9,7 +9,7 @@ class CourseBlock_login extends MoodleBlock { } function applicable_formats() { - return COURSE_FORMAT_SITE; + return array('site' => true); } function get_content () { diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index 5063445aae..e85e563586 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -204,11 +204,13 @@ class MoodleBlock { $errors[] = 'version_not_set'; $correct = false; } - $allformats = COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - if(!($this->applicable_formats() & $allformats)) { + + $formats = $this->applicable_formats(); + if(empty($formats) || array_sum($formats) === 0) { $errors[] = 'no_course_formats'; $correct = false; } + $width = $this->preferred_width(); if(!is_int($width) || $width <= 0) { $errors[] = 'invalid_width'; @@ -230,7 +232,7 @@ class MoodleBlock { } function applicable_formats() { // Default case: the block can be used in all course types - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; + return array('all' => true); } function preferred_width() { // Default case: the block wants to be 180 pixels wide diff --git a/blocks/news_items/block_news_items.php b/blocks/news_items/block_news_items.php index c9c81e2ac2..be9190a80c 100644 --- a/blocks/news_items/block_news_items.php +++ b/blocks/news_items/block_news_items.php @@ -8,10 +8,6 @@ class CourseBlock_news_items extends MoodleBlock { $this->version = 2004052600; } - function applicable_formats() { - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - } - function get_content() { global $CFG; diff --git a/blocks/online_users/block_online_users.php b/blocks/online_users/block_online_users.php index dfb720be2f..da7cf35cdd 100644 --- a/blocks/online_users/block_online_users.php +++ b/blocks/online_users/block_online_users.php @@ -8,10 +8,6 @@ class CourseBlock_online_users extends MoodleBlock { $this->version = 2004052700; } - function applicable_formats() { - return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE; - } - function has_config() {return true;} function print_config() { diff --git a/blocks/section_links/block_section_links.php b/blocks/section_links/block_section_links.php index 71dd045fb1..a6f08a8639 100644 --- a/blocks/section_links/block_section_links.php +++ b/blocks/section_links/block_section_links.php @@ -20,7 +20,7 @@ class CourseBlock_section_links extends MoodleBlock { } function applicable_formats() { - return (COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS); + return (array('weeks' => true, 'topics' => true)); } function get_content() { diff --git a/blocks/site_main_menu/block_site_main_menu.php b/blocks/site_main_menu/block_site_main_menu.php index 50b182ec0f..f501f6bc6e 100644 --- a/blocks/site_main_menu/block_site_main_menu.php +++ b/blocks/site_main_menu/block_site_main_menu.php @@ -9,7 +9,7 @@ class CourseBlock_site_main_menu extends MoodleBlock { } function applicable_formats() { - return COURSE_FORMAT_SITE; + return array('site' => true); } function get_content() { diff --git a/blocks/social_activities/block_social_activities.php b/blocks/social_activities/block_social_activities.php index 8190b58bf8..e769e1b836 100644 --- a/blocks/social_activities/block_social_activities.php +++ b/blocks/social_activities/block_social_activities.php @@ -9,7 +9,7 @@ class CourseBlock_social_activities extends MoodleBlock { } function applicable_formats() { - return COURSE_FORMAT_SOCIAL; + return array('social' => true); } function get_content() { diff --git a/course/view.php b/course/view.php index 18c3c42e78..61d51dcc36 100644 --- a/course/view.php +++ b/course/view.php @@ -33,21 +33,6 @@ $course->format = 'weeks'; // Default format is weeks } - // Can't avoid this... :( - 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 = 0; - } - // Doing this now so we can pass the results to block_action() // and dodge the overhead of doing the same work twice. @@ -118,7 +103,13 @@ // 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, 'applicable_formats') & $courseformat) { + $formats = block_method_result($recblock->name, 'applicable_formats'); + + if( isset($formats[$course->format]) ? $formats[$course->format] : !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. + // Add it to the missing blocks $missingblocks[] = $recblock->id; } diff --git a/index.php b/index.php index c1e5cefe8f..38d69e6b1a 100644 --- a/index.php +++ b/index.php @@ -57,8 +57,6 @@ $editing = isediting($site->id); - $courseformat = COURSE_FORMAT_SITE; - // Doing this now so we can pass the results to block_action() // and dodge the overhead of doing the same work twice. @@ -105,7 +103,13 @@ // 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, 'applicable_formats') & $courseformat) { + $formats = block_method_result($recblock->name, 'applicable_formats'); + + if( isset($formats['site']) ? $formats['site'] : !empty($formats['all'])) { + // Translation: if the 'site' 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. + // Add it to the missing blocks $missingblocks[] = $recblock->id; } -- 2.39.5