diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-11-14 16:17:19 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-11-14 16:17:19 -0800 |
commit | 846f365db9d3c1b61ed4bd68316bd5e7b80e56ec (patch) | |
tree | 8dde35e3e121c0e48f1dd67432b01e44e7b2bdcc | |
parent | 9fd6a6f9058a89e60f83c6f2e89ae9e994c9e53a (diff) |
Normalize tags a bit.
- Create Tag_Model::url() to mimic Item_Model::url()
- Use the same pagination logic as we do for viewing items
-rw-r--r-- | modules/tag/controllers/tags.php | 9 | ||||
-rw-r--r-- | modules/tag/models/tag.php | 14 | ||||
-rw-r--r-- | modules/tag/views/tag_cloud.html.php | 2 |
3 files changed, 22 insertions, 3 deletions
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 @@ <? foreach ($tags as $tag): ?> <li class="size<?=(int)(($tag->count / $max_count) * 7) ?>"> <span><?= $tag->count ?> photos are tagged with </span> - <a href="<?= url::site("tags/$tag->id") ?>"><?= html::clean($tag->name) ?></a> + <a href="<?= $tag->url() ?>"><?= html::clean($tag->name) ?></a> </li> <? endforeach ?> </ul> |