From d02ae958668877a97aa0ad11004241e2851e4114 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 2 Jun 2011 22:18:08 -0700 Subject: [PATCH] When the display limit is specified, but there less than the display limit items, then use the item count as the display limit. 2nd attempt :-/ --- 3.0/modules/dynamic/controllers/dynamic.php | 18 ++++++++---------- 3.1/modules/dynamic/controllers/dynamic.php | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/3.0/modules/dynamic/controllers/dynamic.php b/3.0/modules/dynamic/controllers/dynamic.php index 7229b70d..10a7a6f5 100644 --- a/3.0/modules/dynamic/controllers/dynamic.php +++ b/3.0/modules/dynamic/controllers/dynamic.php @@ -31,18 +31,16 @@ class Dynamic_Controller extends Controller { $album_defn = unserialize(module::get_var("dynamic", $album)); $display_limit = $album_defn->limit; - if (empty($display_limit)) { - $children_count = ORM::factory("item") - ->viewable() - ->where("type", "!=", "album") - ->count_all(); - } else { - $children_count = $display_limit; + $children_count = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->count_all(); + if (!empty($display_limit)) { + $children_count = min($children_count, $display_limit); } - $offset = ($page-1) * $page_size; - - $max_pages = ceil($children_count / $page_size); + $offset = ($page - 1) * $page_size; + $max_pages = max(ceil($children_count / $page_size), 1); // Make sure that the page references a valid offset if ($page < 1 || ($children_count && $page > ceil($children_count / $page_size))) { diff --git a/3.1/modules/dynamic/controllers/dynamic.php b/3.1/modules/dynamic/controllers/dynamic.php index 7229b70d..10a7a6f5 100644 --- a/3.1/modules/dynamic/controllers/dynamic.php +++ b/3.1/modules/dynamic/controllers/dynamic.php @@ -31,18 +31,16 @@ class Dynamic_Controller extends Controller { $album_defn = unserialize(module::get_var("dynamic", $album)); $display_limit = $album_defn->limit; - if (empty($display_limit)) { - $children_count = ORM::factory("item") - ->viewable() - ->where("type", "!=", "album") - ->count_all(); - } else { - $children_count = $display_limit; + $children_count = ORM::factory("item") + ->viewable() + ->where("type", "!=", "album") + ->count_all(); + if (!empty($display_limit)) { + $children_count = min($children_count, $display_limit); } - $offset = ($page-1) * $page_size; - - $max_pages = ceil($children_count / $page_size); + $offset = ($page - 1) * $page_size; + $max_pages = max(ceil($children_count / $page_size), 1); // Make sure that the page references a valid offset if ($page < 1 || ($children_count && $page > ceil($children_count / $page_size))) {