From 846f365db9d3c1b61ed4bd68316bd5e7b80e56ec Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 14 Nov 2009 16:17:19 -0800 Subject: Normalize tags a bit. - Create Tag_Model::url() to mimic Item_Model::url() - Use the same pagination logic as we do for viewing items --- modules/tag/controllers/tags.php | 9 +++++++-- modules/tag/models/tag.php | 14 ++++++++++++++ modules/tag/views/tag_cloud.html.php | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 1bd6b3cc..c3b14fcc 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -25,13 +25,18 @@ class Tags_Controller extends REST_Controller { $page = (int) $this->input->get("page", "1"); $children_count = $tag->items_count(); $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))) { - Kohana::show_404(); + if ($page < 1) { + url::redirect($album->abs_url()); + } else if ($page > $max_pages) { + url::redirect($album->abs_url("page=$max_pages")); } $template = new Theme_View("page.html", "tag"); + $template->set_global("page", $page); + $template->set_global("max_pages", $max_pages); $template->set_global("page_size", $page_size); $template->set_global("tag", $tag); $template->set_global("children", $tag->items($page_size, $offset)); diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index d9488e1c..49512daa 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -102,4 +102,18 @@ class Tag_Model extends ORM { } return $result; } + + /** + * Return the server-relative url to this item, eg: + * /gallery3/index.php/tags/35 + * + * @param string $query the query string (eg "page=3") + */ + public function url($query=null) { + $url = url::site("tags/$this->id"); + if ($query) { + $url .= "?$query"; + } + return $url; + } } \ No newline at end of file diff --git a/modules/tag/views/tag_cloud.html.php b/modules/tag/views/tag_cloud.html.php index d6a0b5f8..de12bb49 100644 --- a/modules/tag/views/tag_cloud.html.php +++ b/modules/tag/views/tag_cloud.html.php @@ -3,7 +3,7 @@
  • count ?> photos are tagged with - id") ?>">name) ?> + name) ?>
  • -- cgit v1.2.3