summaryrefslogtreecommitdiff
path: root/modules/tag
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2011-08-11 22:11:24 -0700
committerTim Almdal <tnalmdal@shaw.ca>2011-08-11 22:11:24 -0700
commitc92d34a86b0515363f790056293cea2b0a738782 (patch)
tree9d5b794e434d26ef7ee50281b3ebee716e3327a5 /modules/tag
parenta5b1972bbe9676479886ca94bb23f09407a87561 (diff)
parent933a34986dbca248f388e8aa3c3aea4a6d71a94b (diff)
Merge branch 'displayContext' into display_context_compressed
Conflicts: modules/gallery/controllers/movies.php modules/gallery/controllers/photos.php modules/tag/controllers/tag.php
Diffstat (limited to 'modules/tag')
-rw-r--r--modules/tag/controllers/tag.php21
-rw-r--r--modules/tag/helpers/tag.php19
-rw-r--r--modules/tag/libraries/Tag_Display_Context.php49
-rw-r--r--modules/tag/models/tag.php38
4 files changed, 109 insertions, 18 deletions
diff --git a/modules/tag/controllers/tag.php b/modules/tag/controllers/tag.php
index 7786daa1..1628f0ac 100644
--- a/modules/tag/controllers/tag.php
+++ b/modules/tag/controllers/tag.php
@@ -22,7 +22,22 @@ class Tag_Controller extends Controller {
$tag_id = $function;
$tag = ORM::factory("tag")->where("id", "=", $tag_id)->find();
$page_size = module::get_var("gallery", "page_size", 9);
- $page = (int) Input::instance()->get("page", "1");
+
+ $input = Input::instance();
+ $show = $input->get("show");
+
+ if ($show) {
+ $child = ORM::factory("item", $show);
+ $index = tag::get_position($tag, $child);
+ if ($index) {
+ $page = ceil($index / $page_size);
+ $uri = "tag/$tag_id/" . urlencode($tag->name);
+ url::redirect($uri . ($page == 1 ? "" : "?page=$page"));
+ }
+ } else {
+ $page = (int) $input->get("page", "1");
+ }
+
$children_count = $tag->items_count();
$offset = ($page-1) * $page_size;
$max_pages = max(ceil($children_count / $page_size), 1);
@@ -35,6 +50,10 @@ class Tag_Controller extends Controller {
}
$root = item::root();
+ Display_Context::factory("tag")
+ ->set(array("tag" => $tag))
+ ->save();
+
$template = new Theme_View("page.html", "collection", "tag");
$template->set_global(
array("page" => $page,
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index c21104ee..83a00080 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -136,4 +136,23 @@ class tag_Core {
// extremely rare case.
db::build()->delete("tags")->where("count", "=", 0)->execute();
}
+
+ /**
+ * Find the position of the given item in the tag collection. The resulting
+ * value is 1-indexed, so the first child in the album is at position 1.
+ *
+ * @param Tag_Model $tag
+ * @param Item_Model $item
+ * @param array $where an array of arrays, each compatible with ORM::where()
+ */
+ static function get_position($tag, $item, $where=array()) {
+ return ORM::factory("item")
+ ->viewable()
+ ->join("items_tags", "items.id", "items_tags.item_id")
+ ->where("items_tags.tag_id", "=", $tag->id)
+ ->where("items.id", "<=", $item->id)
+ ->merge_where($where)
+ ->order_by("items.id")
+ ->count_all();
+ }
} \ No newline at end of file
diff --git a/modules/tag/libraries/Tag_Display_Context.php b/modules/tag/libraries/Tag_Display_Context.php
new file mode 100644
index 00000000..47c79088
--- /dev/null
+++ b/modules/tag/libraries/Tag_Display_Context.php
@@ -0,0 +1,49 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2011 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+class Tag_Display_Context_Core extends Display_Context {
+ protected function __construct() {
+ parent::__construct("tag");
+ }
+
+ function display_context($item) {
+ $tag = $this->get("tag");
+
+ $where = array(array("type", "!=", "album"));
+
+ $position = tag::get_position($tag, $item, $where);
+ if ($position > 1) {
+ list ($previous_item, $ignore, $next_item) = $tag->items(3, $position - 2, $where);
+ } else {
+ $previous_item = null;
+ list ($next_item) = $tag->items(1, $position, $where);
+ }
+
+ $root = item::root();
+ return array("position" =>$position,
+ "previous_item" => $previous_item,
+ "next_item" =>$next_item,
+ "sibling_count" => $tag->items_count($where),
+ "breadcrumbs" => array(
+ Breadcrumb::instance($root->title, $root->url())->set_first(),
+ Breadcrumb::instance($tag->name, $tag->url("show={$item->id}")),
+ Breadcrumb::instance($item->title, $item->url())->set_last()));
+ }
+}
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php
index bb79e707..a7150df8 100644
--- a/modules/tag/models/tag.php
+++ b/modules/tag/models/tag.php
@@ -33,35 +33,39 @@ class Tag_Model_Core extends ORM {
* Return all viewable items associated with this tag.
* @param integer $limit number of rows to limit result to
* @param integer $offset offset in result to start returning rows from
- * @param string $type the type of item (album, photo)
+ * @param string $where an array of arrays, each compatible with ORM::where()
* @return ORM_Iterator
*/
- public function items($limit=null, $offset=null, $type=null) {
- $model = ORM::factory("item")
+ public function items($limit=null, $offset=null, $where=array()) {
+ if (is_scalar($where)) {
+ // backwards compatibility
+ $where = array(array("items.type", "=", $where));
+ }
+ return ORM::factory("item")
->viewable()
->join("items_tags", "items.id", "items_tags.item_id")
- ->where("items_tags.tag_id", "=", $this->id);
- if ($type) {
- $model->where("items.type", "=", $type);
- }
- return $model->find_all($limit, $offset);
+ ->where("items_tags.tag_id", "=", $this->id)
+ ->merge_where($where)
+ ->order_by("items.id")
+ ->find_all($limit, $offset);
}
/**
* Return the count of all viewable items associated with this tag.
- * @param string $type the type of item (album, photo)
+ * @param string $where an array of arrays, each compatible with ORM::where()
* @return integer
*/
- public function items_count($type=null) {
- $model = ORM::factory("item")
+ public function items_count($where=array()) {
+ if (is_scalar($where)) {
+ // backwards compatibility
+ $where = array(array("items.type", "=", $where));
+ }
+ return $model = ORM::factory("item")
->viewable()
->join("items_tags", "items.id", "items_tags.item_id")
- ->where("items_tags.tag_id", "=", $this->id);
-
- if ($type) {
- $model->where("items.type", "=", $type);
- }
- return $model->count_all();
+ ->where("items_tags.tag_id", "=", $this->id)
+ ->merge_where($where)
+ ->count_all();
}
/**