]> git.mjollnir.org Git - moodle.git/commitdiff
Refining the way that blocks work: now you don't have to know anything
authordefacer <defacer>
Tue, 1 Feb 2005 06:24:28 +0000 (06:24 +0000)
committerdefacer <defacer>
Tue, 1 Feb 2005 06:24:28 +0000 (06:24 +0000)
about what editing the blocks adds to your URL. blocklib will take care
of that internally.

course/view.php
lib/blocklib.php

index 759b63747287e145687e45fc1acac7d5ffa1130e..b77102b3143fc1c9ce68f5d6656dc89c8586c03c 100644 (file)
@@ -9,8 +9,6 @@
     $id          = optional_param('id', 0, PARAM_INT);
     $name        = optional_param('name');
     $blockaction = optional_param('blockaction');
-    $instanceid  = optional_param('instanceid', 0, PARAM_INT);
-    $blockid     = optional_param('blockid',    0, PARAM_INT);
 
     if (empty($id) && empty($name)) {
         error("Must specify course id or short name");
             set_section_visible($course->id, $show, '1');
         }
 
-        if (!empty($blockaction) && confirm_sesskey()) {
-            if (!empty($blockid)) {
-                blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
-
-            }
-            else if (!empty($instanceid)) {
-                $instance = blocks_find_instance($instanceid, $pageblocks);
-                blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
-            }
+        if (!empty($blockaction)) {
+            blocks_execute_url_action($PAGE, $pageblocks);
             // This re-query could be eliminated by judicious programming in blocks_execute_action(),
             // but I 'm not sure if it's worth the complexity increase...
             $pageblocks = blocks_get_by_page($PAGE);
index 3938d9b7166622716d384e600bf53bebe4ad536e..ea0201bb929b69e69fa6e81c2c37e8c1ea28bcdc 100644 (file)
@@ -478,6 +478,27 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
     redirect($page->url_get_full());
 }
 
+// You can use this to get the blocks to respond to URL actions without much hassle
+function blocks_execute_url_action(&$PAGE, &$pageblocks) {
+    $blockaction = optional_param('blockaction');
+
+    if (empty($blockaction) || !confirm_sesskey()) {
+        return;
+    }
+
+    $instanceid  = optional_param('instanceid', 0, PARAM_INT);
+    $blockid     = optional_param('blockid',    0, PARAM_INT);
+    
+    if (!empty($blockid)) {
+        blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid);
+
+    }
+    else if (!empty($instanceid)) {
+        $instance = blocks_find_instance($instanceid, $pageblocks);
+        blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
+    }
+}
+
 // This shouldn't be used externally at all, it's here for use by blocks_execute_action()
 // in order to reduce code repetition.
 function blocks_execute_repositioning(&$instance, $newpos, $newweight) {