diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-01-08 11:48:44 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-01-08 11:48:44 -0800 |
commit | 2d8843ba4d780b8a9c3662f78d17ca29ebb1c8df (patch) | |
tree | ca064bf58dd1258bcc3b85970b514e72d9ac5637 /modules/image_block/helpers | |
parent | a2f5ace4931d4c4d812cd9af1eb3a104bc112b96 (diff) |
use item::random() to get the random item.
Diffstat (limited to 'modules/image_block/helpers')
-rw-r--r-- | modules/image_block/helpers/image_block_block.php | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php index f591e8d1..5f2bbcb7 100644 --- a/modules/image_block/helpers/image_block_block.php +++ b/modules/image_block/helpers/image_block_block.php @@ -30,29 +30,9 @@ class image_block_block_Core { $block->css_id = "g-image-block"; $block->title = t("Random image"); $block->content = new View("image_block_block.html"); + $block->content->items = item::random(array(array("type", "!=", "album"))); - $random = ((float)mt_rand()) / (float)mt_getrandmax(); - - $items = ORM::factory("item") - ->viewable() - ->where("type", "!=", "album") - ->where("rand_key", "<", $random) - ->order_by(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) - ->order_by(array("rand_key" => "DESC")) - ->find_all(1); - } - - if ($items->count() > 0) { - $block->content->item = $items->current(); - } else { + if ($block->content->items->count() == 0) { $block = ""; } break; |