From ee6055eb89e2ce19061a6fa173dd55d6cd7b3948 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Tue, 23 Aug 2005 04:03:56 +0000 Subject: [PATCH] Fixing up the my moodle blocks to use blocks_setup instead of the old way. --- admin/mymoodle.php | 12 +----------- lib/blocklib.php | 21 ++++++++++++++++++--- my/index.php | 9 +-------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/admin/mymoodle.php b/admin/mymoodle.php index 7c0d9cadaba..3c8e1d3cac6 100644 --- a/admin/mymoodle.php +++ b/admin/mymoodle.php @@ -13,18 +13,8 @@ define('OVERRIDE_PAGE_TYPE',PAGE_MY_MOODLE); $PAGE = page_create_object(PAGE_MY_MOODLE,0); - - $blockaction = optional_param('blockaction'); - - $blocks = blocks_get_pinned($PAGE); - - if (!empty($blockaction)) { - blocks_execute_url_action($PAGE, $blocks,true); - // 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... - $blocks = blocks_get_pinned($PAGE); - } + $blocks = blocks_setup($PAGE,BLOCKS_PINNED_TRUE); $strtitle = get_string('pinblocks','my'); diff --git a/lib/blocklib.php b/lib/blocklib.php index 6b798ebaa79..1a73df240e1 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -11,6 +11,10 @@ define('BLOCK_CONFIGURE', 0x10); define('BLOCK_POS_LEFT', 'l'); define('BLOCK_POS_RIGHT', 'r'); +define('BLOCKS_PINNED_TRUE',0); +define('BLOCKS_PINNED_FALSE',1); +define('BLOCKS_PINNED_BOTH',2); + require_once($CFG->libdir.'/pagelib.php'); @@ -378,9 +382,20 @@ function blocks_find_instance($instanceid, $blocksarray) { } // Simple entry point for anyone that wants to use blocks -function blocks_setup(&$PAGE) { - $pageblocks = blocks_get_by_page($PAGE); - blocks_execute_url_action($PAGE, $pageblocks); +function blocks_setup(&$PAGE,$pinned=BLOCKS_PINNED_FALSE) { + switch ($pinned) { + case BLOCKS_PINNED_TRUE: + $pageblocks = blocks_get_pinned($PAGE); + break; + case BLOCKS_PINNED_BOTH: + $pageblocks = blocks_get_by_page_pinned($PAGE); + break; + case BLOCKS_PINNED_FALSE: + default: + $pageblocks = blocks_get_by_page($PAGE); + break; + } + blocks_execute_url_action($PAGE, $pageblocks,($pinned==BLOCKS_PINNED_TRUE)); return $pageblocks; } diff --git a/my/index.php b/my/index.php index 5f640466283..5f74feb82ad 100644 --- a/my/index.php +++ b/my/index.php @@ -13,14 +13,7 @@ $PAGE = page_create_instance($USER->id); - $pageblocks = blocks_get_by_page_pinned($PAGE); - 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_pinned($PAGE); - } - + $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH); if (!empty($edit) && $PAGE->user_allowed_editing()) { if ($edit == 'on') {