mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-07-10 09:19:18 -04:00
Update to image_block based on bharat's feedback
1) move the rand_key column into core 2) don't do a max rand, just try to a get a random number less than the current random number if that doesn't successd look the other way
This commit is contained in:
@@ -19,11 +19,12 @@
|
||||
*/
|
||||
class image_block_theme_Core {
|
||||
static function sidebar_blocks($theme) {
|
||||
$result = ORM::factory("item")
|
||||
// Leave as a count so we can filter based on viewable items.
|
||||
$viewable_items = ORM::factory("item")
|
||||
->viewable()
|
||||
->select("COUNT(*) AS C")
|
||||
->find();
|
||||
if (empty($result->C)) {
|
||||
->find()->C;
|
||||
if (empty($viewable_items)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -32,18 +33,12 @@ class image_block_theme_Core {
|
||||
$block->title = t("Random Image");
|
||||
$block->content = new View("image_block_block.html");
|
||||
|
||||
$result = ORM::factory("item")
|
||||
->viewable()
|
||||
->select("MAX(rand_key) AS max_random")
|
||||
->find();
|
||||
|
||||
$max_rand = $result->max_random;
|
||||
$random = ((float)mt_rand()) / (float)mt_getrandmax();
|
||||
|
||||
$items = ORM::factory("item")
|
||||
->viewable()
|
||||
->where("type !=", "album")
|
||||
->where("rand_key < ", $max_rand * $random)
|
||||
->where("rand_key < ", $random)
|
||||
->orderby(array("rand_key" => "DESC"))
|
||||
->find_all(1);
|
||||
|
||||
@@ -51,10 +46,9 @@ class image_block_theme_Core {
|
||||
$items = ORM::factory("item")
|
||||
->viewable()
|
||||
->where("type !=", "album")
|
||||
->where("rand_key > ", $max_rand * $random)
|
||||
->where("rand_key >= ", $random)
|
||||
->orderby(array("rand_key" => "DESC"))
|
||||
->find_all(1);
|
||||
|
||||
}
|
||||
|
||||
$block->content->item = $items->current();
|
||||
|
||||
Reference in New Issue
Block a user