diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-11-14 14:25:39 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-11-14 14:25:39 -0800 |
commit | 081ce9f6ca07b834fd31d3d340990504dd68f821 (patch) | |
tree | bb6d8597bbedbf1327475b8c2ad4b63f0170f16d | |
parent | 100a66d861849ab0d78dca84b0b06c1af973752a (diff) |
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.
-rw-r--r-- | modules/gallery/controllers/albums.php | 2 | ||||
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 48 | ||||
-rw-r--r-- | themes/wind/views/movie.html.php | 24 | ||||
-rw-r--r-- | themes/wind/views/pager.html.php | 88 | ||||
-rw-r--r-- | 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 @@ <div id="g-item"> <?= $theme->photo_top() ?> - <ul class="g-pager ui-helper-clearfix"> - <li> - <? if ($previous_item): ?> - <a href="<?= $previous_item->url() ?>" class="g-button ui-icon-left ui-state-default ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-w"></span><?= t("Previous") ?></a> - <? else: ?> - <a class="g-button ui-icon-left ui-state-disabled ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-w"></span><?= t("Previous") ?></a> - <? endif; ?> - </li> - <li class="g-info"><?= t("%position of %total", array("position" => $position, "total" => $sibling_count)) ?></li> - <li class="g-text-right"> - <? if ($next_item): ?> - <a href="<?= $next_item->url() ?>" class="g-button ui-icon-right ui-state-default ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-e"></span><?= t("Next") ?></a> - <? else: ?> - <a class="g-button ui-icon-right ui-state-disabled ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-e"></span><?= t("Next") ?></a> - <? endif ?> - </li> - </ul> + <?= $theme->pager() ?> <div id="g-movie" class="ui-helper-clearfix"> <?= $item->movie_img(array("class" => "g-movie", "id" => "g-movie-id-{$item->id}")) ?> <?= $theme->context_menu($item, "#g-movie-id-{$item->id}") ?> </div> - + <div id="g-info"> <h1><?= html::purify($item->title) ?></h1> <div><?= nl2br(html::purify($item->description)) ?></div> 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 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<? // See http://docs.kohanaphp.com/libraries/pagination ?> +<? +// This is a generic paginator for album, photo and movie pages. Depending on the page type, +// there are different sets of variables available. With this data, you can make a paginator +// that lets you say "You're viewing photo 5 of 35", or "You're viewing photos 10 - 18 of 37" +// for album views. +// +// Available variables for all page types: +// $page_type - "album", "movie" or "photo" +// $previous_page_url - the url to the previous page, if there is one +// $next_page_url - the url to the next page, if there is one +// $total - the total number of photos in this album +// +// Available for the "album" page type: +// $page - what page number we're on +// $max_pages - the maximum page number +// $page_size - the page size +// $first_page_url - the url to the first page, or null if we're on the first page +// $last_page_url - the url to the last page, or null if we're on the last page +// $first_visible_position - the position number of the first visible photo on this page +// $last_visible_position - the position number of the last visible photo on this page +// +// Available for "photo" and "movie" page types: +// $position - the position number of this photo +?> + <ul class="g-pager ui-helper-clearfix"> - <? /* @todo This message isn't easily localizable */ - $from_to_msg = t2("Photo %from_number of %count", - "Photos %from_number - %to_number of %count", - $total_items, - array("from_number" => $current_first_item, - "to_number" => $current_last_item, - "count" => $total_items)) ?> <li class="g-first"> - <? if ($first_page): ?> - <a href="<?= str_replace('{page}', 1, $url) ?>" class="g-button ui-icon-left ui-state-default ui-corner-all"> - <span class="ui-icon ui-icon-seek-first"></span><?= t("First") ?></a> - <? else: ?> - <a class="g-button ui-icon-left ui-state-disabled ui-corner-all"> - <span class="ui-icon ui-icon-seek-first"></span><?= t("First") ?></a> + <? if ($page_type == "album"): ?> + <? if (isset($first_page_url)): ?> + <a href="<?= $first_page_url ?>" class="g-button ui-icon-left ui-state-default ui-corner-all"> + <span class="ui-icon ui-icon-seek-first"></span><?= t("First") ?></a> + <? else: ?> + <a class="g-button ui-icon-left ui-state-disabled ui-corner-all"> + <span class="ui-icon ui-icon-seek-first"></span><?= t("First") ?></a> + <? endif ?> <? endif ?> - <? if ($previous_page): ?> - <a href="<?= str_replace('{page}', $previous_page, $url) ?>" class="g-button ui-icon-left ui-state-default ui-corner-all"> + + <? if (isset($previous_page_url)): ?> + <a href="<?= $previous_page_url ?>" class="g-button ui-icon-left ui-state-default ui-corner-all"> <span class="ui-icon ui-icon-seek-prev"></span><?= t("Previous") ?></a> <? else: ?> <a class="g-button ui-icon-left ui-state-disabled ui-corner-all"> <span class="ui-icon ui-icon-seek-prev"></span><?= t("Previous") ?></a> <? endif ?> </li> - <li class="g-info"><?= $from_to_msg ?></li> + + <li class="g-info"> + <? if ($page_type == "album"): ?> + <?= /* @todo This message isn't easily localizable */ + /* @todo does this really need to be a t2? why not just skip the msg when there's 1 photo? */ + t2("Photo %from_number of %count", + "Photos %from_number - %to_number of %count", + $total, + array("from_number" => $first_visible_position, + "to_number" => $last_visible_position, + "count" => $total)) ?> + <? else: ?> + <?= t("%position of %total", array("position" => $position, "total" => $total)) ?> + <? endif ?> + </li> + <li class="g-text-right"> - <? if ($next_page): ?> - <a href="<?= str_replace('{page}', $next_page, $url) ?>" class="g-button ui-icon-right ui-state-default ui-corner-all"> + <? if (isset($next_page_url)): ?> + <a href="<?= $next_page_url ?>" class="g-button ui-icon-right ui-state-default ui-corner-all"> <span class="ui-icon ui-icon-seek-next"></span><?= t("Next") ?></a> <? else: ?> <a class="g-button ui-state-disabled ui-icon-right ui-corner-all"> <span class="ui-icon ui-icon-seek-next"></span><?= t("Next") ?></a> <? endif ?> - <? if ($last_page): ?> - <a href="<?= str_replace('{page}', $last_page, $url) ?>" class="g-button ui-icon-right ui-state-default ui-corner-all"> - <span class="ui-icon ui-icon-seek-end"></span><?= t("Last") ?></a> - <? else: ?> - <a class="g-button ui-state-disabled ui-icon-right ui-corner-all"> - <span class="ui-icon ui-icon-seek-end"></span><?= t("Last") ?></a> + + <? if ($page_type == "album"): ?> + <? if (isset($last_page_url)): ?> + <a href="<?= $last_page_url ?>" class="g-button ui-icon-right ui-state-default ui-corner-all"> + <span class="ui-icon ui-icon-seek-end"></span><?= t("Last") ?></a> + <? else: ?> + <a class="g-button ui-state-disabled ui-icon-right ui-corner-all"> + <span class="ui-icon ui-icon-seek-end"></span><?= t("Last") ?></a> + <? endif ?> <? endif ?> </li> </ul> 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 @@ <div id="g-item"> <?= $theme->photo_top() ?> - <ul class="g-pager ui-helper-clearfix"> - <li class="g-first"> - <? if ($previous_item): ?> - <a href="<?= $previous_item->url() ?>" class="g-button ui-icon-left ui-state-default ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-w"></span><?= t("previous") ?></a> - <? else: ?> - <a class="g-button ui-icon-left ui-state-disabled ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-w"></span><?= t("previous") ?></a> - <? endif; ?> - </li> - <li class="g-info"><?= t("%position of %total", array("position" => $position, "total" => $sibling_count)) ?></li> - <li class="g-text-right"> - <? if ($next_item): ?> - <a href="<?= $next_item->url() ?>" class="g-button ui-icon-right ui-state-default ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-e"></span><?= t("next") ?></a> - <? else: ?> - <a class="g-button ui-icon-right ui-state-disabled ui-corner-all"> - <span class="ui-icon ui-icon-triangle-1-e"></span><?= t("next") ?></a> - <? endif ?> - </li> - </ul> + <?= $theme->pager() ?> <div id="g-photo"> <?= $theme->resize_top($item) ?> |