diff options
| author | Tim Almdal <tnalmdal@shaw.ca> | 2008-11-26 06:37:12 +0000 |
|---|---|---|
| committer | Tim Almdal <tnalmdal@shaw.ca> | 2008-11-26 06:37:12 +0000 |
| commit | de56a33c9c27cdf5abc0573fb1334fbbeb762048 (patch) | |
| tree | e8c7174bd8df5e5ec5a37738675d74645ae34381 /modules/tag/helpers | |
| parent | 18ce4a4c1fab25bd5d7be43c6761195dd60b5981 (diff) | |
Clean tag creation
Diffstat (limited to 'modules/tag/helpers')
| -rw-r--r-- | modules/tag/helpers/tag.php | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 2ff73e62..8057379b 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -19,7 +19,7 @@ */ class tag_Core { public static $NUMBER_OF_BUCKETS = 7; - + /** * Associate a tag with an item. Create the tag if it doesn't already exist. * @@ -55,45 +55,29 @@ class tag_Core { * from: http://www.hawkee.com/snippet/1485/ * * @return array List of tags each entry has the following format: - * array("id" => "tag_id", "name" => "tag_name", "count" => "frequency", - * "class" => "bucket") + * array("id" => "tag_id", "name" => "tag_name", "count" => "frequency", + * "class" => "bucket") */ public static function load_buckets() { $tag_list = array(); $tags = ORM::factory("tag") - ->orderby("count", "ASC") - ->find_all() - ->as_array(); - if (count($tags) > 0) { - $min_tags = count($tags) / self::$NUMBER_OF_BUCKETS; - $bucket_count = 0; - $bucket_items = 0; - $tags_set = 0; - + ->orderby("count", "DESC") + ->limit(30) + ->find_all(); + if ($tags->count() > 0) { + $max_count = $tags[0]->count; foreach($tags as $key => $tag) { - if (($bucket_items >= $min_tags) && $last_count != $tag->count && - $bucket_count < self::$NUMBER_OF_BUCKETS) { - $bucket_count++; - $bucket_items = 0; - - // Calculate a new minimum number if tags for the remaining classes. - $remaining_tags = count($tags) - $tags_set; - $min_tags = $remaining_tags / self::$NUMBER_OF_BUCKETS; - } - // Set the tag to the current class - $tag_list[$key] = array("id" => $tag->id, "name" => $tag->name, "count" => $tag->count, - "class" => "$bucket_count"); - $bucket_items++; - $tags_set++; - $last_count = $tag->count; + $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 function alphasort($tag1, $tag2) { + public static function alphasort($tag1, $tag2) { if ($tag1["name"] == $tag2["name"]) { return 0; } |
