From b42fcb9cda4dafdb9db86770f54965b3fb2fc7ab Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 28 Dec 2010 23:10:05 -0800 Subject: Use db::expr instead of "new Database_Expression". Resolves #1560. --- modules/tag/helpers/tag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 14d27c94..bcd3b0c0 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -118,7 +118,7 @@ class tag_Core { static function clear_all($item) { db::build() ->update("tags") - ->set("count", new Database_Expression("`count` - 1")) + ->set("count", db::expr("`count` - 1")) ->where("count", ">", 0) ->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id)) ->execute(); -- cgit v1.2.3 From 2e5d4a59b119fecce4f647eaa49565b024678cf9 Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Tue, 4 Jan 2011 19:52:25 -0700 Subject: Display an item's tags in the info block. --- modules/tag/helpers/tag_event.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 829089c4..78fe7058 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -147,4 +147,20 @@ class tag_event_Core { } } } + + static function info_block_metadata($block, $item) { + $tags = array(); + foreach (tag::item_tags($item) as $tag) { + $tags[] = "name}") . "\">$tag->name"; + } + if (count($tags)) { + $info = $block->content->metadata; + $info["tags"] = array( + "label" => t("Tags:"), + "value" => implode(", ", $tags) + ); + $block->content->metadata = $info; + } + } + } -- cgit v1.2.3 From 06d94065ce0919f34151da05b32642a95397044f Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Thu, 6 Jan 2011 21:03:19 -0700 Subject: Updates per Bharat's pull request review. Renamed info_block_metadata event to info_block_get_metadata. --- modules/info/helpers/info_block.php | 2 +- modules/info/views/info_block.html.php | 4 ++-- modules/tag/helpers/tag_event.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/info/helpers/info_block.php b/modules/info/helpers/info_block.php index 5841ec6f..9596bc41 100644 --- a/modules/info/helpers/info_block.php +++ b/modules/info/helpers/info_block.php @@ -71,7 +71,7 @@ class info_block_Core { } $block->content->metadata = $info; - module::event("info_block_metadata", $block, $theme->item); + module::event("info_block_get_metadata", $block, $theme->item); } break; } diff --git a/modules/info/views/info_block.html.php b/modules/info/views/info_block.html.php index 7c162767..b296fa1d 100644 --- a/modules/info/views/info_block.html.php +++ b/modules/info/views/info_block.html.php @@ -1,8 +1,8 @@ diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 78fe7058..6b8de723 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -148,12 +148,12 @@ class tag_event_Core { } } - static function info_block_metadata($block, $item) { + static function info_block_get_metadata($block, $item) { $tags = array(); foreach (tag::item_tags($item) as $tag) { - $tags[] = "name}") . "\">$tag->name"; + $tags[] = "name}") . "\">{$tag->name}"; } - if (count($tags)) { + if ($tags) { $info = $block->content->metadata; $info["tags"] = array( "label" => t("Tags:"), -- cgit v1.2.3 From 4756db435c1b934137f0ca2f169f74ab509ab72f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 7 Jan 2011 20:09:27 -0800 Subject: Minor style cleanup --- modules/info/helpers/info_block.php | 3 ++- modules/tag/helpers/tag_event.php | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/info/helpers/info_block.php b/modules/info/helpers/info_block.php index 9596bc41..74c92510 100644 --- a/modules/info/helpers/info_block.php +++ b/modules/info/helpers/info_block.php @@ -60,7 +60,8 @@ class info_block_Core { if ($theme->item->owner->url) { $info["owner"] = array( "label" => t("Owner:"), - "value" => "item->owner->url}\">" . html::clean($display_name) . "" + "value" => "item->owner->url}\">" . + html::clean($display_name) . "" ); } else { $info["owner"] = array( diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 6b8de723..baf8b1ae 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -156,11 +156,10 @@ class tag_event_Core { if ($tags) { $info = $block->content->metadata; $info["tags"] = array( - "label" => t("Tags:"), - "value" => implode(", ", $tags) + "label" => t("Tags:"), + "value" => implode(", ", $tags) ); $block->content->metadata = $info; } } - } -- cgit v1.2.3 From 966dee8628293f78fbf9431281709ceba011d3c2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 7 Jan 2011 23:38:08 -0800 Subject: Move tag count management into the model. Fixes #1586. --- modules/tag/helpers/tag.php | 2 -- modules/tag/models/tag.php | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index bcd3b0c0..7d5c643a 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -36,11 +36,9 @@ class tag_Core { $tag = ORM::factory("tag")->where("name", "=", $tag_name)->find(); if (!$tag->loaded()) { $tag->name = $tag_name; - $tag->count = 0; } $tag->add($item); - $tag->count++; return $tag->save(); } diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index c038f6d1..25df87e0 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -20,6 +20,15 @@ class Tag_Model_Core extends ORM { protected $has_and_belongs_to_many = array("items"); + public function __construct($id=null) { + parent::__construct($id); + + if (!$this->loaded()) { + // Set reasonable defaults + $this->count = 0; + } + } + /** * Return all viewable items associated with this tag. * @param integer $limit number of rows to limit result to @@ -69,11 +78,12 @@ class Tag_Model_Core extends ORM { $related_item_ids[$row->item_id] = 1; } + $added = array_diff($this->changed_relations["items"], $this->object_relations["items"]); + $removed = array_diff($this->object_relations["items"], $this->changed_relations["items"]); if (isset($this->changed_relations["items"])) { - $changed = array_merge( - array_diff($this->changed_relations["items"], $this->object_relations["items"]), - array_diff($this->object_relations["items"], $this->changed_relations["items"])); + $changed = array_merge($added, $removed); } + $this->count = count($this->object_relations["items"]) + count($added) - count($removed); $result = parent::save(); -- cgit v1.2.3