diff options
Diffstat (limited to 'modules/tag/helpers')
| -rw-r--r-- | modules/tag/helpers/tag.php | 34 | ||||
| -rw-r--r-- | modules/tag/helpers/tag_block.php | 12 |
2 files changed, 16 insertions, 30 deletions
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 8057379b..0ca86dc8 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class tag_Core { - public static $NUMBER_OF_BUCKETS = 7; - /** * Associate a tag with an item. Create the tag if it doesn't already exist. * @@ -51,36 +49,14 @@ class tag_Core { } /** - * Assign a css class to the tags based on frequency of use. This code is based on the code - * from: http://www.hawkee.com/snippet/1485/ + * Return the N most popular tags. * - * @return array List of tags each entry has the following format: - * array("id" => "tag_id", "name" => "tag_name", "count" => "frequency", - * "class" => "bucket") + * @return ORM_Iterator of Tag_Model in descending tag count order */ - public static function load_buckets() { - $tag_list = array(); - $tags = ORM::factory("tag") + public static function popular_tags($count) { + return ORM::factory("tag") ->orderby("count", "DESC") - ->limit(30) + ->limit($count) ->find_all(); - if ($tags->count() > 0) { - $max_count = $tags[0]->count; - foreach($tags as $key => $tag) { - // Set the tag to the current class - $size = (int)(($tag->count / $max_count) * (self::$NUMBER_OF_BUCKETS - 1)); - $tag_list[$key] = array("id" => $tag->id, "name" => $tag->name, "count" => $tag->count, - "class" => "$size"); - } - usort($tag_list, array("tag", "alphasort")); - } - return $tag_list; - } - - public static function alphasort($tag1, $tag2) { - if ($tag1["name"] == $tag2["name"]) { - return 0; - } - return $tag1["name"] < $tag2["name"] ? -1 : 1; } } diff --git a/modules/tag/helpers/tag_block.php b/modules/tag/helpers/tag_block.php index 629008b6..4b74c4d7 100644 --- a/modules/tag/helpers/tag_block.php +++ b/modules/tag/helpers/tag_block.php @@ -24,7 +24,17 @@ class tag_block_Core { $block->id = "gTag"; $block->title = _("Tags"); $block->content = new View("tag_block.html"); - $block->content->tag_list = tag::load_buckets(); + + $tags = tag::popular_tags(30)->as_array(); + $block->content->max_count = $tags[0]->count; + + usort($tags, array("tag_block", "sort_by_name")); + $block->content->tags = $tags; + return $block; } + + public static function sort_by_name($tag1, $tag2) { + return strcmp($tag1->name, $tag2->name); + } }
\ No newline at end of file |
