mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-08-22 23:05:18 -04:00
use item::random() to get the random item.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user