diff options
Diffstat (limited to 'modules/tag')
-rw-r--r-- | modules/tag/controllers/tag.php | 16 | ||||
-rw-r--r-- | modules/tag/helpers/tag.php | 4 | ||||
-rw-r--r-- | modules/tag/helpers/tag_event.php | 15 | ||||
-rw-r--r-- | modules/tag/models/tag.php | 16 | ||||
-rw-r--r-- | modules/tag/views/tag_block.html.php | 4 |
5 files changed, 39 insertions, 16 deletions
diff --git a/modules/tag/controllers/tag.php b/modules/tag/controllers/tag.php index 0e924f3d..47110540 100644 --- a/modules/tag/controllers/tag.php +++ b/modules/tag/controllers/tag.php @@ -29,18 +29,18 @@ class Tag_Controller extends Controller { // Make sure that the page references a valid offset if ($page < 1) { - url::redirect($album->abs_url()); + url::redirect(url::merge(array("page" => 1))); } else if ($page > $max_pages) { - url::redirect($album->abs_url("page=$max_pages")); + url::redirect(url::merge(array("page" => $max_pages))); } $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 14d27c94..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(); } @@ -118,7 +116,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(); 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 44a4c904..06620ae2 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 @@ -70,11 +79,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 cc204c72..a6536361 100644 --- a/modules/tag/views/tag_block.html.php +++ b/modules/tag/views/tag_block.html.php @@ -8,7 +8,7 @@ multiple: true, multipleSeparator: ',', cacheLength: 1, - selectFirst: false, + selectFirst: false } ); $("#g-add-tag-form").ajaxForm({ @@ -22,7 +22,7 @@ }); }); </script> -<div id="g-tag-cloud" ref="<?= url::site("tags") ?>"> +<div id="g-tag-cloud"> <?= $cloud ?> </div> <?= $form ?> |