diff options
Diffstat (limited to 'modules/image_block/helpers/image_block_block.php')
-rw-r--r-- | modules/image_block/helpers/image_block_block.php | 20 |
1 files changed, 14 insertions, 6 deletions
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; } |