Skip to content

Instantly share code, notes, and snippets.

@grief-of-these-days
Created November 30, 2009 21:38
Show Gist options
  • Save grief-of-these-days/245773 to your computer and use it in GitHub Desktop.
Save grief-of-these-days/245773 to your computer and use it in GitHub Desktop.
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index 89a2703..7f058d8 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -63,13 +63,31 @@ class tag_Core {
}
/**
+ * Return the N most popular viewable tags.
+ *
+ * @return ORM_Iterator of Tag_Model in descending tag count order
+ */
+ static function popular_viewable_tags($count) {
+ // Using chainable item::viewable helper method.
+ return item::viewable (
+ ORM::factory("tag")
+ ->order_by("count", "DESC")
+ ->limit($count)
+ ->join("items_tags", "tags.id", "items_tags.tag_id", "inner")
+ ->join("items", "items.id", "items_tags.item_id", "inner")
+ )
+ ->group_by ("tags.id")
+ ->find_all();
+ }
+
+ /**
* Return a rendering of the cloud for the N most popular tags.
*
* @param integer $count the number of tags
* @return View
*/
static function cloud($count) {
- $tags = tag::popular_tags($count)->as_array();
+ $tags = tag::popular_viewable_tags($count)->as_array();
if ($tags) {
$cloud = new View("tag_cloud.html");
$cloud->max_count = $tags[0]->count;
@grief-of-these-days
Copy link
Author

This is the difference against the original tag.php, not the complete file.
Here is the complete tag.php with the applied changes: http://gist.github.com/624637 .

@pete2010
Copy link

Brilliant! You are a prince among men (princess among women?). You should put that out as a module - it seems pretty core to me.

Thanks for this contribution to Gallery - it has made my day (and my site).

Pete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment