summaryrefslogtreecommitdiff
path: root/modules/tag
diff options
context:
space:
mode:
Diffstat (limited to 'modules/tag')
-rw-r--r--modules/tag/controllers/tag.php12
-rw-r--r--modules/tag/helpers/tag.php2
-rw-r--r--modules/tag/helpers/tag_event.php15
-rw-r--r--modules/tag/models/tag.php16
-rw-r--r--modules/tag/views/tag_block.html.php2
5 files changed, 35 insertions, 12 deletions
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));
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/helpers/tag_event.php b/modules/tag/helpers/tag_event.php
index 829089c4..baf8b1ae 100644
--- a/modules/tag/helpers/tag_event.php
+++ b/modules/tag/helpers/tag_event.php
@@ -147,4 +147,19 @@ class tag_event_Core {
}
}
}
+
+ static function info_block_get_metadata($block, $item) {
+ $tags = array();
+ foreach (tag::item_tags($item) as $tag) {
+ $tags[] = "<a href=\"" . url::site("tag/{$tag->name}") . "\">{$tag->name}</a>";
+ }
+ if ($tags) {
+ $info = $block->content->metadata;
+ $info["tags"] = array(
+ "label" => t("Tags:"),
+ "value" => implode(", ", $tags)
+ );
+ $block->content->metadata = $info;
+ }
+ }
}
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();
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 @@
});
});
</script>
-<div id="g-tag-cloud" ref="<?= url::site("tags") ?>">
+<div id="g-tag-cloud">
<?= $cloud ?>
</div>
<?= $form ?>