use item::random() to get the random item.

This commit is contained in:
Bharat Mediratta
2010-01-08 11:48:44 -08:00
parent a2f5ace493
commit 2d8843ba4d
@@ -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;