summaryrefslogtreecommitdiff
path: root/modules/tag/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/tag/helpers')
-rw-r--r--modules/tag/helpers/tag.php40
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;
}