Clean tag creation

This commit is contained in:
Tim Almdal
2008-11-26 06:37:12 +00:00
parent 18ce4a4c1f
commit de56a33c9c
4 changed files with 16 additions and 32 deletions

View File

@@ -77,8 +77,8 @@ class Test_Controller extends Controller {
}
$installer_class = "{$module->name}_installer";
Kohana::log("debug", "$installer_class");
if (method_exists($installer_class, "uninstall")) {
Kohana::log("debug", "method uninstall exists");
call_user_func_array(array($installer_class, "uninstall"), array());
}
}

View File

@@ -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;
}

View File

@@ -58,8 +58,8 @@ class Tag_Test extends Unit_Test_Case {
array("id" => "3", "name" => "tag2", "count" => 6, "class" => 4),
array("id" => "4", "name" => "tag3", "count" => 5, "class" => 3),
array("id" => "5", "name" => "tag4", "count" => 4, "class" => 2),
array("id" => "6", "name" => "tag5", "count" => 3, "class" => 1),
array("id" => "7", "name" => "tag6", "count" => 2, "class" => 0),
array("id" => "6", "name" => "tag5", "count" => 3, "class" => 2),
array("id" => "7", "name" => "tag6", "count" => 2, "class" => 1),
array("id" => "8", "name" => "tag7", "count" => 1, "class" => 0)
);
$this->assert_equal($expected_tag_list, $tag_list, "incorrect non filtered tag list");

View File

@@ -57,7 +57,7 @@ class group_Core {
if ($group->loaded) {
// Drop the view column for this group in the items table.
Database::instance()->query("ALTER TABLE `items` DROP `view_{$group->id}`");
// Database::instance()->query("ALTER TABLE `items` DROP `view_{$group->id}`");
$group->delete();
}
}