From 081ce9f6ca07b834fd31d3d340990504dd68f821 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 14 Nov 2009 14:25:39 -0800 Subject: Normalize pagination so that pager.html.php can handle pagination for both albums and movies. Kohana's paginator is not quite sufficient for this, so create our own pagination logic in Theme_View with only the stuff we need. Clearly document the variables available in pager.html so that themers know how to use it. Fixes ticket #626. --- modules/gallery/controllers/albums.php | 2 + modules/gallery/libraries/Theme_View.php | 48 ++++++++++++++--- themes/wind/views/movie.html.php | 24 +-------- themes/wind/views/pager.html.php | 88 +++++++++++++++++++++++--------- themes/wind/views/photo.html.php | 22 +------- 5 files changed, 108 insertions(+), 76 deletions(-) diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index a430b14d..4e37649c 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -65,6 +65,8 @@ class Albums_Controller extends Items_Controller { } $template = new Theme_View("page.html", "album"); + $template->set_global("page", $page); + $template->set_global("max_pages", $max_pages); $template->set_global("page_size", $page_size); $template->set_global("item", $album); $template->set_global("children", $album->viewable()->children($page_size, $offset)); diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 7e6a0b2e..5e8bc728 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -135,16 +135,48 @@ class Theme_View_Core extends Gallery_View { return $menu->render(); } + /** + * Set up the data and render a pager. + * + * See themes/wind/views/pager.html for documentation on the variables generated here. + */ public function pager() { - if ($this->children_count) { - $this->pagination = new Pagination(); - $this->pagination->initialize( - array("query_string" => "page", - "total_items" => $this->children_count, - "items_per_page" => $this->page_size, - "style" => "classic")); - return $this->pagination->render(); + $v = new View("pager.html"); + $v->page_type = $this->page_type; + $v->first_page_url = null; + $v->previous_page_url = null; + $v->next_page_url = null; + $v->last_page_url = null; + + if ($this->page_type == "album") { + $v->page = $this->page; + $v->max_pages = $this->max_pages; + $v->total = $this->children_count; + if ($this->page != 1) { + $v->first_page_url = $this->item->url(); + $v->previous_page_url = $this->item->url("page=" . ($this->page - 1)); + } + + if ($this->page != $this->max_pages) { + $v->next_page_url = $this->item->url("page=" . ($this->page + 1)); + $v->last_page_url = $this->item->url("page={$this->max_pages}"); + } + + $v->first_visible_position = ($this->page - 1) * $this->page_size + 1; + $v->last_visible_position = $this->page * $this->page_size; + } else { + $v->position = $this->position; + $v->total = $this->sibling_count; + if ($v->previous_page = $this->previous_item) { + $v->previous_page_url = $this->previous_item->url(); + } + + if ($v->next_page = $this->next_item) { + $v->next_page_url = $this->next_item->url(); + } } + + return $v; } /** diff --git a/themes/wind/views/movie.html.php b/themes/wind/views/movie.html.php index d91ffbc5..a44b891a 100644 --- a/themes/wind/views/movie.html.php +++ b/themes/wind/views/movie.html.php @@ -2,33 +2,13 @@
photo_top() ?> - + pager() ?>
movie_img(array("class" => "g-movie", "id" => "g-movie-id-{$item->id}")) ?> context_menu($item, "#g-movie-id-{$item->id}") ?>
- +

title) ?>

description)) ?>
diff --git a/themes/wind/views/pager.html.php b/themes/wind/views/pager.html.php index 1dfe7eac..51d52021 100644 --- a/themes/wind/views/pager.html.php +++ b/themes/wind/views/pager.html.php @@ -1,44 +1,82 @@ - + +
    - $current_first_item, - "to_number" => $current_last_item, - "count" => $total_items)) ?>
  • - - - - - - + + + + + + + + - - + + +
  • -
  • + +
  • + + $first_visible_position, + "to_number" => $last_visible_position, + "count" => $total)) ?> + + $position, "total" => $total)) ?> + +
  • +
  • - - + + - - - - - - + + + + + + + + +
diff --git a/themes/wind/views/photo.html.php b/themes/wind/views/photo.html.php index e17dcdb3..091fd7c5 100644 --- a/themes/wind/views/photo.html.php +++ b/themes/wind/views/photo.html.php @@ -15,27 +15,7 @@
photo_top() ?> -
    -
  • - - - - - - - -
  • -
  • $position, "total" => $sibling_count)) ?>
  • -
  • - - - - - - - -
  • -
+ pager() ?>
resize_top($item) ?> -- cgit v1.2.3