From 39a40e49a19f00baeeeefe375d67e915ccc7e09a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 29 Sep 2009 14:35:15 -0700 Subject: Refactor sidebar_blocks into a separate function and then call block_manager::get_html(site.sidebar). Convert image_block to use block management instead of theme::sidebar_blocks --- modules/image_block/helpers/image_block_block.php | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 modules/image_block/helpers/image_block_block.php (limited to 'modules/image_block/helpers/image_block_block.php') diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php new file mode 100644 index 00000000..f7aefc43 --- /dev/null +++ b/modules/image_block/helpers/image_block_block.php @@ -0,0 +1,63 @@ + t("Random Image")); + } + + static function get($block_id) { + $block = new Block(); + switch ($block_id) { + case "random_image": + $block = new Block(); + $block->css_id = "gImageBlock"; + $block->title = t("Random Image"); + $block->content = new View("image_block_block.html"); + + $random = ((float)mt_rand()) / (float)mt_getrandmax(); + + $items = ORM::factory("item") + ->viewable() + ->where("type !=", "album") + ->where("rand_key < ", $random) + ->orderby(array("rand_key" => "DESC")) + ->find_all(1); + + if ($items->count() == 0) { + // Try once more. If this fails, just ditch the block altogether + $items = ORM::factory("item") + ->viewable() + ->where("type !=", "album") + ->where("rand_key >= ", $random) + ->orderby(array("rand_key" => "DESC")) + ->find_all(1); + } + + if ($items->count() > 0) { + $block->content->item = $items->current(); + } else { + $block = ""; + } + break; + } + + return $block; + } +} -- cgit v1.2.3