diff --git a/3.0/modules/tagsinalbum/helpers/tagsinalbum_block.php b/3.0/modules/tagsinalbum/helpers/tagsinalbum_block.php
index cb28053c..10ebfe97 100644
--- a/3.0/modules/tagsinalbum/helpers/tagsinalbum_block.php
+++ b/3.0/modules/tagsinalbum/helpers/tagsinalbum_block.php
@@ -29,12 +29,26 @@ class tagsinalbum_block_Core {
case "tagsinalbum":
if (($theme->item) && ($theme->item->is_album())) {
$item = $theme->item;
- $all_tags = ORM::factory("tag")
+
+ // Create an ORM query for finding one instance of each tag
+ // used by children in the current album.
+ $tags_model = ORM::factory("tag")
->join("items_tags", "items_tags.tag_id", "tags.id")
->join("items", "items.id", "items_tags.item_id", "LEFT")
->where("items.parent_id", "=", $item->id)
- ->order_by("tags.id", "ASC")
- ->find_all();
+ ->order_by("tags.name", "ASC")
+ ->group_by("tags.id");
+
+ // Limit $all_tags to the first X tags if max_display_tags is set,
+ // else populate it with all tags used by this album's children.
+ $all_tags = "";
+ if (module::get_var("tagsinalbum", "max_display_tags") > 0) {
+ $all_tags = $tags_model->find_all(module::get_var("tagsinalbum", "max_display_tags"));
+ } else {
+ $all_tags = $tags_model->find_all();
+ }
+
+ // If this album has children that are tagged, display those tags.
if (count($all_tags) > 0) {
$block = new Block();
$block->css_id = "g-tags-in-album-block";
diff --git a/3.0/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php b/3.0/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php
index 6c8b1dff..8d9e0910 100644
--- a/3.0/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php
+++ b/3.0/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php
@@ -1,33 +1,11 @@
- // Create an array to store the tag names and urls in.
- $display_tags = array();
-
- // Loop through all tags in the album, copying their
- // names and urls into the array and skipping duplicates.
- $last_tagid = "";
- foreach ($all_tags as $one_tag) {
- if ($last_tagid != $one_tag->id) {
- $tag = ORM::factory("tag", $one_tag->id);
- $display_tags[] = array(html::clean($tag->name), $tag->url());
- $last_tagid = $one_tag->id;
- }
- if (module::get_var("tagsinalbum", "max_display_tags") > 0) {
- if (count($display_tags) == module::get_var("tagsinalbum", "max_display_tags")) {
- break;
- }
- }
- }
-
- // Sort the array.
- asort($display_tags);
-
- // Print out the list of tags as clickable links.
+ // Loop through each tag in $all_tags, and display it as a link.
$not_first = 0;
- foreach ($display_tags as $one_tag) {
+ foreach ($all_tags as $one_tag) {
if ($not_first++ > 0) {
print ", ";
}
- print "" . $one_tag[0] . "";
+ print "url() . "\">" . html::clean($one_tag->name) . "";
}
?>
diff --git a/3.1/modules/tagsinalbum/helpers/tagsinalbum_block.php b/3.1/modules/tagsinalbum/helpers/tagsinalbum_block.php
index cb28053c..10ebfe97 100644
--- a/3.1/modules/tagsinalbum/helpers/tagsinalbum_block.php
+++ b/3.1/modules/tagsinalbum/helpers/tagsinalbum_block.php
@@ -29,12 +29,26 @@ class tagsinalbum_block_Core {
case "tagsinalbum":
if (($theme->item) && ($theme->item->is_album())) {
$item = $theme->item;
- $all_tags = ORM::factory("tag")
+
+ // Create an ORM query for finding one instance of each tag
+ // used by children in the current album.
+ $tags_model = ORM::factory("tag")
->join("items_tags", "items_tags.tag_id", "tags.id")
->join("items", "items.id", "items_tags.item_id", "LEFT")
->where("items.parent_id", "=", $item->id)
- ->order_by("tags.id", "ASC")
- ->find_all();
+ ->order_by("tags.name", "ASC")
+ ->group_by("tags.id");
+
+ // Limit $all_tags to the first X tags if max_display_tags is set,
+ // else populate it with all tags used by this album's children.
+ $all_tags = "";
+ if (module::get_var("tagsinalbum", "max_display_tags") > 0) {
+ $all_tags = $tags_model->find_all(module::get_var("tagsinalbum", "max_display_tags"));
+ } else {
+ $all_tags = $tags_model->find_all();
+ }
+
+ // If this album has children that are tagged, display those tags.
if (count($all_tags) > 0) {
$block = new Block();
$block->css_id = "g-tags-in-album-block";
diff --git a/3.1/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php b/3.1/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php
index 6c8b1dff..8d9e0910 100644
--- a/3.1/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php
+++ b/3.1/modules/tagsinalbum/views/tagsinalbum_sidebar.html.php
@@ -1,33 +1,11 @@
- // Create an array to store the tag names and urls in.
- $display_tags = array();
-
- // Loop through all tags in the album, copying their
- // names and urls into the array and skipping duplicates.
- $last_tagid = "";
- foreach ($all_tags as $one_tag) {
- if ($last_tagid != $one_tag->id) {
- $tag = ORM::factory("tag", $one_tag->id);
- $display_tags[] = array(html::clean($tag->name), $tag->url());
- $last_tagid = $one_tag->id;
- }
- if (module::get_var("tagsinalbum", "max_display_tags") > 0) {
- if (count($display_tags) == module::get_var("tagsinalbum", "max_display_tags")) {
- break;
- }
- }
- }
-
- // Sort the array.
- asort($display_tags);
-
- // Print out the list of tags as clickable links.
+ // Loop through each tag in $all_tags, and display it as a link.
$not_first = 0;
- foreach ($display_tags as $one_tag) {
+ foreach ($all_tags as $one_tag) {
if ($not_first++ > 0) {
print ", ";
}
- print "" . $one_tag[0] . "";
+ print "url() . "\">" . html::clean($one_tag->name) . "";
}
?>