diff options
author | Nathan Kinkade <nkinkade@nkinka.de> | 2010-02-02 02:59:20 +0000 |
---|---|---|
committer | Nathan Kinkade <nkinkade@nkinka.de> | 2010-02-02 02:59:20 +0000 |
commit | 9d0927dda936756f1f5003813f437d714fe481f8 (patch) | |
tree | fe1b887345b37387ab0ddcfd78bf344f6150b6cc /modules/image_block/helpers/image_block_block.php | |
parent | a6f794c20dc3592bcaef17c622413c1b670a20d8 (diff) | |
parent | 43985ea2fb137aa7d532617271e37d7c20def3c5 (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
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; } |