Fix for bug 1662:
authordefacer <defacer>
Sun, 22 Aug 2004 16:54:48 +0000 (16:54 +0000)
committerdefacer <defacer>
Sun, 22 Aug 2004 16:54:48 +0000 (16:54 +0000)
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.

14 files changed:
blocks/admin/block_admin.php
blocks/calendar_month/block_calendar_month.php
blocks/calendar_upcoming/block_calendar_upcoming.php
blocks/course_list/block_course_list.php
blocks/course_summary/block_course_summary.php
blocks/login/block_login.php
blocks/moodleblock.class.php
blocks/news_items/block_news_items.php
blocks/online_users/block_online_users.php
blocks/section_links/block_section_links.php
blocks/site_main_menu/block_site_main_menu.php
blocks/social_activities/block_social_activities.php
course/view.php
index.php

index 87a836485ccfff1d0afb92b5cfec9741cf1f59c9..13a7b543b8765fafee6a4ef2254cffdbd77c6ddd 100644 (file)
@@ -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) {
index 46d771563a5e58a5c3a69e84f1cca493573b8003..aa04c241e96590cf05a112f8569435aeef09d193 100644 (file)
@@ -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']);
index c1ed2ae726ff37314071031a6198929e436d1174..07ca412105c3c6d2011e2d7f9289aaffc8564bad 100644 (file)
@@ -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']);
index e9b9054ab9d477a7bb6ca041b2452642a46b6489..f25b7f8a5642719b39dd95eccfb47f34cf77f357 100644 (file)
@@ -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;
 
index 40d21b0cf1d43bd52408e6ace15c67c8c8336c8e..a65774c329f9189d24ea2079c0e7633f538923fe 100644 (file)
@@ -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;
 
index 89d8b543001f8be72c2cda37cfdb2b4d54d0c9c6..6e54061c6702deb2c720e5d0a52903d946c951dc 100644 (file)
@@ -9,7 +9,7 @@ class CourseBlock_login extends MoodleBlock {
     }
 
     function applicable_formats() {
-        return COURSE_FORMAT_SITE;
+        return array('site' => true);
     }
 
     function get_content () {
index 5063445aae4d43af90eb3f621e63328aff1ea0b6..e85e5635866a47e6c67058abcde620036ffc4ac5 100644 (file)
@@ -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
index c9c81e2ac2a96b4e5c94c3ab0112ab37bc914665..be9190a80c9aa3b189c3b98cab496e9e8bfecaf6 100644 (file)
@@ -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;
 
index dfb720be2f11900c743d9e4a1d47f1738349e440..da7cf35cdd72ac28bafcfed508f8c2dc1bbfa119 100644 (file)
@@ -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() {
index 71dd045fb14649b35c047db6bcd1d858cb748b3f..a6f08a8639a4eb965bede579ce714004feddab97 100644 (file)
@@ -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() {
index 50b182ec0f150fd8ddba0af454ff01e2e6dbe849..f501f6bc6e544ef36bc97528e76b0aa1b33b42d0 100644 (file)
@@ -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() {
index 8190b58bf8bae5f9065ad0d67f7cd32b10063398..e769e1b836dc38a1fdcab35ec685476e86d0095e 100644 (file)
@@ -9,7 +9,7 @@ class CourseBlock_social_activities extends MoodleBlock {
     }
 
     function applicable_formats() {
-        return COURSE_FORMAT_SOCIAL;
+        return array('social' => true);
     }
 
     function get_content() {
index 18c3c42e782b01103fa3badeca80498935b0b4c4..61d51dcc366efc50ba5db866a9a35f16889d2cba 100644 (file)
         $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.
 
                 // 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;
                     }
index c1e5cefe8fe481f2437cff5b37c0f72dd1bdd77a..38d69e6b1aa132c2969fe96e00e940282f2ec709 100644 (file)
--- 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.
 
                 // 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;
                     }