From 3c523bcac6e902973c5891c02842254eaecd33a4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 21 Nov 2010 13:51:07 -0800 Subject: Create a module setting for the number of random images to show in the sidebar. Fixes #1499. --- modules/image_block/helpers/image_block_block.php | 20 ++++++++++----- .../image_block/helpers/image_block_installer.php | 29 ++++++++++++++++++++++ modules/image_block/module.info | 2 +- .../image_block/views/image_block_block.html.php | 2 ++ 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 modules/image_block/helpers/image_block_installer.php (limited to 'modules/image_block') diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php index da6e8782..0a53672c 100644 --- a/modules/image_block/helpers/image_block_block.php +++ b/modules/image_block/helpers/image_block_block.php @@ -29,16 +29,24 @@ class image_block_block_Core { // The random_query approach is flawed and doesn't always return a // result when there actually is one. Retry a *few* times. // @todo Consider another fallback if further optimizations are necessary. - $attempts = 0; - do { - $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current(); - } while (!$item && $attempts++ < 3); - if ($item && $item->loaded()) { + $image_count = module::get_var("image_block", "image_count"); + $items = array(); + for ($i = 0; $i < $image_count; $i++) { + $attempts = 0; + $item = null; + do { + $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current(); + } while (!$item && $attempts++ < 3); + if ($item) { + $items[] = $item; + } + } + if ($items) { $block = new Block(); $block->css_id = "g-image-block"; $block->title = t("Random image"); $block->content = new View("image_block_block.html"); - $block->content->item = $item; + $block->content->items = $items; } break; } diff --git a/modules/image_block/helpers/image_block_installer.php b/modules/image_block/helpers/image_block_installer.php new file mode 100644 index 00000000..895a7e5d --- /dev/null +++ b/modules/image_block/helpers/image_block_installer.php @@ -0,0 +1,29 @@ + +
thumb_img(array("class" => "g-thumbnail")) ?>
+ -- cgit v1.2.3 From cdf0f7f765a5bd5e0d5619d345bdc6aba069c555 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 29 Nov 2010 21:02:19 -0800 Subject: In 3c523bcac6e902973c5891c02842254eaecd33a4 (fix for #1499) I left out the install() function which should set the image_block module to version 2. Fix that here. --- modules/image_block/helpers/image_block_installer.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules/image_block') diff --git a/modules/image_block/helpers/image_block_installer.php b/modules/image_block/helpers/image_block_installer.php index 895a7e5d..e9967314 100644 --- a/modules/image_block/helpers/image_block_installer.php +++ b/modules/image_block/helpers/image_block_installer.php @@ -19,6 +19,10 @@ */ class image_block_installer { + static function install() { + module::set_version("image_block", $version = 2); + } + static function upgrade($version) { $db = Database::instance(); if ($version == 1) { -- cgit v1.2.3 From c3ef8921260db8e39b6d2a7b4708e3d19f35f8b5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 2 Dec 2010 08:32:59 -0800 Subject: Duh, set the image_block.image_count variable in the installer! This issue was introduced in cdf0f7f765a5bd5e0d5619d345bdc6aba069c555 which was a follow-on for 3c523bcac6e902973c5891c02842254eaecd33a4 which fixes #1499. --- modules/image_block/helpers/image_block_installer.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/image_block') diff --git a/modules/image_block/helpers/image_block_installer.php b/modules/image_block/helpers/image_block_installer.php index e9967314..62c38ba4 100644 --- a/modules/image_block/helpers/image_block_installer.php +++ b/modules/image_block/helpers/image_block_installer.php @@ -20,6 +20,7 @@ class image_block_installer { static function install() { + module::set_var("image_block", "image_count", "1"); module::set_version("image_block", $version = 2); } -- cgit v1.2.3