diff options
author | Bharat Mediratta <bharat@menalto.com> | 2012-10-08 14:45:10 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2012-10-08 14:45:10 -0700 |
commit | e81bb34327a026b787cdd5eee5335deed12471e7 (patch) | |
tree | 1322ae00b122b1f408b6470466ff6f8f3e05377c /modules/tag | |
parent | 8fc9e903747e11e64fad2ab88e3ad51e6f3ed785 (diff) |
Fix the delete function on item_tags and tag_items collections to
remove all tags from an item, or remove all items from a tag as
appropriate (ie, empty the collection). Fixes #1902.
Diffstat (limited to 'modules/tag')
-rw-r--r-- | modules/tag/helpers/item_tags_rest.php | 7 | ||||
-rw-r--r-- | modules/tag/helpers/tag.php | 23 | ||||
-rw-r--r-- | modules/tag/helpers/tag_items_rest.php | 6 |
3 files changed, 29 insertions, 7 deletions
diff --git a/modules/tag/helpers/item_tags_rest.php b/modules/tag/helpers/item_tags_rest.php index 31f9050c..98666338 100644 --- a/modules/tag/helpers/item_tags_rest.php +++ b/modules/tag/helpers/item_tags_rest.php @@ -44,10 +44,11 @@ class item_tags_rest_Core { } static function delete($request) { - list ($tag, $item) = rest::resolve($request->url); + $item = rest::resolve($request->url); access::required("edit", $item); - $tag->remove($item); - $tag->save(); + + // Deleting this collection means removing all tags associated with the item. + tag::clear_all($item); } static function resolve($id) { diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 70d9e545..0eccb3ed 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -90,6 +90,17 @@ class tag_Core { ->find_all(); } + /** + * Return all the items for a given tag. + * @return array + */ + static function tag_items($tag) { + return ORM::factory("item") + ->join("items_tags", "items_tags.item_id", "items.id", "left") + ->where("items_tags.tag_id", "=", $tag->id) + ->find_all(); + } + static function get_add_form($item) { $form = new Forge("tags/create/{$item->id}", "", "post", array("id" => "g-add-tag-form", "class" => "g-short-form")); $label = $item->is_album() ? @@ -128,6 +139,18 @@ class tag_Core { } /** + * Remove all items from a tag + */ + static function remove_items($tag) { + db::build() + ->delete("items_tags") + ->where("tag_id", "=", $tag->id) + ->execute(); + $tag->count = 0; + $tag->save(); + } + + /** * Get rid of any tags that have no associated items. */ static function compact() { diff --git a/modules/tag/helpers/tag_items_rest.php b/modules/tag/helpers/tag_items_rest.php index 106e3904..ec565cbb 100644 --- a/modules/tag/helpers/tag_items_rest.php +++ b/modules/tag/helpers/tag_items_rest.php @@ -50,10 +50,8 @@ class tag_items_rest_Core { } static function delete($request) { - list ($tag, $item) = rest::resolve($request->url); - access::required("edit", $item); - $tag->remove($item); - $tag->save(); + $tag = rest::resolve($request->url); + $tag->remove_items(); } static function resolve($id) { |