summaryrefslogtreecommitdiff
path: root/modules/tag/helpers
diff options
context:
space:
mode:
authorChad Kieffer <ckieffer@gmail.com>2009-07-20 18:29:57 -0600
committerChad Kieffer <ckieffer@gmail.com>2009-07-20 18:29:57 -0600
commit8a4fb5017ba76f6556252a43f43a15ef05eddae1 (patch)
treec04190b619de5c17283756efd55613c289696651 /modules/tag/helpers
parentae22abcdf64e10dc9f96357fbd74b3efd918d4c1 (diff)
parentfb7d99740d9868938ec21449d57b9b3fe991f513 (diff)
Merge branch 'master' of git@github.com:gallery/gallery3
Diffstat (limited to 'modules/tag/helpers')
-rw-r--r--modules/tag/helpers/tag.php20
-rw-r--r--modules/tag/helpers/tag_event.php24
2 files changed, 38 insertions, 6 deletions
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index ab5ee303..1fb2e940 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -127,4 +127,24 @@ class tag_Core {
$group->submit("")->value(t("Delete Tag"));
return $form;
}
+
+ /**
+ * Delete all tags associated with an item
+ */
+ static function clear_all($item) {
+ $db = Database::instance();
+ $db->query("UPDATE {tags} SET `count` = `count` - 1 WHERE `count` > 0 " .
+ "AND `id` IN (SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)");
+ $db->delete("items_tags", array("item_id" => "$item->id"));
+ }
+
+ /**
+ * Get rid of any tags that have no associated items.
+ */
+ static function compact() {
+ // @todo There's a potential race condition here which we can solve by adding a lock around
+ // this and all the cases where we create/update tags. I'm loathe to do that since it's an
+ // extremely rare case.
+ Database::instance() ->delete("tags", array("count" => 0));
+ }
} \ No newline at end of file
diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php
index 0164f556..d13d1340 100644
--- a/modules/tag/helpers/tag_event.php
+++ b/modules/tag/helpers/tag_event.php
@@ -60,11 +60,23 @@ class tag_event_Core {
}
static function item_deleted($item) {
- $db = Database::instance();
- $db->query("UPDATE {tags} SET `count` = `count` - 1 WHERE `count` > 0 " .
- "AND `id` IN (SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)");
- $db->query("DELETE FROM {tags} WHERE `count` = 0 AND `id` IN (" .
- "SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)");
- $db->delete("items_tags", array("item_id" => "$item->id"));
+ tag::clear_all($item);
+ tag::compact();
+ }
+
+ static function item_edit_form($item, $form) {
+ $tag_value = implode("; ", tag::item_tags($item));
+ $form->edit_item->input("tags")->label(t("Tags (separate by , or ;)"))
+ ->value($tag_value);
+ }
+
+ static function item_edit_form_completed($item, $form) {
+ tag::clear_all($item);
+ foreach (preg_split("/[,;]/", $form->edit_item->tags->value) as $tag_name) {
+ if ($tag_name) {
+ tag::add($item, $tag_name);
+ }
+ }
+ tag::compact();
}
}