From f364e8a96b47f0e4f674c8b36317fc80184b219a Mon Sep 17 00:00:00 2001 From: Joe7 Date: Mon, 3 Jan 2011 20:28:54 +0100 Subject: Using array support introduced in 8295201adf948ea35f21f75801b7a8bf36c27569 --- modules/tag/controllers/tag.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules/tag') diff --git a/modules/tag/controllers/tag.php b/modules/tag/controllers/tag.php index 0e924f3d..7bfa7d58 100644 --- a/modules/tag/controllers/tag.php +++ b/modules/tag/controllers/tag.php @@ -35,12 +35,12 @@ class Tag_Controller extends Controller { } $template = new Theme_View("page.html", "collection", "tag"); - $template->set_global("page", $page); - $template->set_global("max_pages", $max_pages); - $template->set_global("page_size", $page_size); - $template->set_global("tag", $tag); - $template->set_global("children", $tag->items($page_size, $offset)); - $template->set_global("children_count", $children_count); + $template->set_global(array("page" => $page, + "max_pages" => $max_pages, + "page_size" => $page_size, + "tag" => $tag, + "children" => $tag->items($page_size, $offset), + "children_count" => $children_count)); $template->content = new View("dynamic.html"); $template->content->title = t("Tag: %tag_name", array("tag_name" => $tag->name)); -- 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') 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') 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') 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') 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 From 5e8d92552b1384d99d5fef56333deb7eb67a8f92 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Wed, 5 Jan 2011 23:05:23 +0100 Subject: Temporarily removed ref tag to get the page validated. (Was also pointing at a rather semi-finished looking page) --- modules/tag/views/tag_block.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/tag') diff --git a/modules/tag/views/tag_block.html.php b/modules/tag/views/tag_block.html.php index 813f24b5..a6536361 100644 --- a/modules/tag/views/tag_block.html.php +++ b/modules/tag/views/tag_block.html.php @@ -22,7 +22,7 @@ }); }); -
"> +
-- cgit v1.2.3