summaryrefslogtreecommitdiff
path: root/modules/tag/helpers
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2011-09-28 20:39:05 +0000
committerNathan Kinkade <nath@nkinka.de>2011-09-28 20:39:05 +0000
commit47456c0de8a408bca9b5a02a0fbc835ff1c01a68 (patch)
treedca2ead5e7159b28aa323465a363f81813f75acd /modules/tag/helpers
parentd8dffba94277c2179a59eb72d6927a5bdb879648 (diff)
parentdfbfe090168ee4ed44e2c8208e79d3fe40f90437 (diff)
Manually fixed a merge conflict after pulling.
Diffstat (limited to 'modules/tag/helpers')
-rw-r--r--modules/tag/helpers/tag.php19
1 files changed, 19 insertions, 0 deletions
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