Created
November 30, 2009 21:38
-
-
Save grief-of-these-days/245773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
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
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 .