1
0

Clean up the code to work with K24 ORM changes, and update it to work

with paginator changes.  Also fix some minor style issues.
This commit is contained in:
Bharat Mediratta 2009-12-24 11:45:44 -08:00
parent 8658a609fd
commit 0cb6b9e58f

View File

@ -21,7 +21,7 @@ class latestupdates_Controller extends Controller {
public function albums($id) {
// Figure out how many items to display on each page.
$itemsPerPage = module::get_var("gallery", "page_size", 9);
$page_size = module::get_var("gallery", "page_size", 9);
// Figure out which page # the visitor is on and
// don't allow the visitor to go below page 1.
@ -31,33 +31,30 @@ class latestupdates_Controller extends Controller {
}
// First item to display.
$offset = ($page - 1) * $itemsPerPage;
$offset = ($page - 1) * $page_size;
$item = ORM::factory("item", $id);
// Determine the total number of items,
// for page numbering purposes.
$count = ORM::factory("item", $id)
$count = $item
->viewable()
->where("type", "!=", "album")
->order_by("created", "DESC")
->descendants()
->count();
->descendants_count(null, null, array(array("type", "!=", "album")));
// Figure out what the highest page number is.
$max_pages = ceil($count / $itemsPerPage);
$max_pages = ceil($count / $page_size);
// Don't let the visitor go past the last page.
if ($max_pages && $page > $max_pages) {
if ($max_pages && $page > $max_pages) {
url::redirect("latestupdates/albums/{$item->id}?page=$max_pages");
}
// Figure out which items to display on this page.
$children = ORM::factory("item", $id)
$children = $item
->viewable()
->where("type", "!=", "album")
->order_by("created", "DESC")
->limit($itemsPerPage)
->offset($offset)
->descendants();
->descendants($page_size, $offset);
// Set up the previous and next page buttons.
if ($page > 1) {
@ -70,9 +67,11 @@ class latestupdates_Controller extends Controller {
}
// Set up and display the actual page.
$template = new Theme_View("page.html", "other", "LatestUpdates");
$template = new Theme_View("page.html", "collection", "LatestUpdates");
$template->page_title = t("Gallery :: Latest Updates");
$template->set_global("page_size", $itemsPerPage);
$template->set_global("page", $page);
$template->set_global("page_size", $page_size);
$template->set_global("max_pages", $max_pages);
$template->set_global("children", $children);
$template->set_global("children_count", $count);
$template->content = new View("dynamic.html");
@ -82,7 +81,7 @@ class latestupdates_Controller extends Controller {
public function updates() {
// Figure out how many items to display on each page.
$itemsPerPage = module::get_var("gallery", "page_size", 9);
$page_size = module::get_var("gallery", "page_size", 9);
// Figure out which page # the visitor is on and
// don't allow the visitor to go below page 1.
@ -92,7 +91,7 @@ class latestupdates_Controller extends Controller {
}
// First item to display.
$offset = ($page - 1) * $itemsPerPage;
$offset = ($page - 1) * $page_size;
// Determine the total number of items,
// for page numbering purposes.
@ -103,7 +102,7 @@ class latestupdates_Controller extends Controller {
->count();
// Figure out what the highest page number is.
$max_pages = ceil($count / $itemsPerPage);
$max_pages = ceil($count / $page_size);
// Don't let the visitor go past the last page.
if ($max_pages && $page > $max_pages) {
@ -115,7 +114,7 @@ class latestupdates_Controller extends Controller {
->viewable()
->where("type", "!=", "album")
->order_by("created", "DESC")
->find_all($itemsPerPage, $offset);
->find_all($page_size, $offset);
// Set up the previous and next page buttons.
if ($page > 1) {
@ -128,9 +127,11 @@ class latestupdates_Controller extends Controller {
}
// Set up and display the actual page.
$template = new Theme_View("page.html", "other", "LatestUpdates");
$template = new Theme_View("page.html", "collection", "LatestUpdates");
$template->page_title = t("Gallery :: Latest Updates");
$template->set_global("page_size", $itemsPerPage);
$template->set_global("page", $page);
$template->set_global("page_size", $page_size);
$template->set_global("max_pages", $max_pages);
$template->set_global("children", $items);
$template->set_global("children_count", $count);
$template->content = new View ("dynamic.html");