diff options
Diffstat (limited to 'modules/image_block/helpers/image_block_block.php')
-rw-r--r-- | modules/image_block/helpers/image_block_block.php | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php index f591e8d1..185df850 100644 --- a/modules/image_block/helpers/image_block_block.php +++ b/modules/image_block/helpers/image_block_block.php @@ -26,34 +26,13 @@ class image_block_block_Core { $block = ""; switch ($block_id) { case "random_image": - $block = new Block(); - $block->css_id = "g-image-block"; - $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) - ->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 { - $block = ""; + $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current(); + if ($item && $item->loaded()) { + $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; } break; } |