MDL-30340 Block stickiness computation improvements
authorDavid Mudrak <david@moodle.com>
Sat, 3 Dec 2011 13:11:26 +0000 (14:11 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Sat, 3 Dec 2011 15:57:21 +0000 (16:57 +0100)
This is an attempt to clean up and fix the computation of the block
stickiness. At first, the page pattern can't be ignored because the user
may want to currently try to limit the page pattern. Second, the
site-index pattern can be forced only if the user selected 'Front page
only' as the page context.

lib/blocklib.php

index b39badb..a25b5d4 100644 (file)
@@ -1235,20 +1235,26 @@ class block_manager {
                 // Explicitly set the context
                 $bi->parentcontextid = $parentcontext->id;
 
-                // If the context type is > 0 then we'll explicitly set the block as sticky, otherwise not
-                $bi->showinsubcontexts = (int)(!empty($data->bui_contexts));
+                // Should the block be sticky
+                if ($data->bui_contexts == BUI_CONTEXTS_ENTIRE_SITE or $data->bui_contexts == BUI_CONTEXTS_FRONTPAGE_SUBS) {
+                    $bi->showinsubcontexts = true;
+                } else {
+                    $bi->showinsubcontexts = false;
+                }
 
                 // If the block wants to be system-wide, then explicitly set that
                 if ($data->bui_contexts == BUI_CONTEXTS_ENTIRE_SITE) {   // Only possible on a frontpage or system page
                     $bi->parentcontextid = $systemcontext->id;
-                    $bi->showinsubcontexts = BUI_CONTEXTS_CURRENT_SUBS; //show in current and sub contexts
-                    $bi->pagetypepattern = '*';
 
                 } else { // The block doesn't want to be system-wide, so let's ensure that
                     if ($parentcontext->id == $systemcontext->id) {  // We need to move it to the front page
                         $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
                         $bi->parentcontextid = $frontpagecontext->id;
-                        $bi->pagetypepattern = 'site-index';
+                        if ($data->bui_contexts == BUI_CONTEXTS_FRONTPAGE_ONLY) {
+                            // If the front page only is specified, the page type setting is ignored
+                            // as explicitely set to site-index
+                            $bi->pagetypepattern = 'site-index';
+                        }
                     }
                 }
             }