From: scyrma <scyrma> Date: Wed, 24 Sep 2008 08:07:15 +0000 (+0000) Subject: MDL-14489: Make the tag cloud "more extended" in size with small dataset (credits... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dae7b4f6061b1fb5a2321bcf6a753da5d9b505a9;p=moodle.git MDL-14489: Make the tag cloud "more extended" in size with small dataset (credits to Matt Gibson) (merge from 1.9) --- diff --git a/tag/locallib.php b/tag/locallib.php index a9775fc3c6..71597baad3 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -22,43 +22,33 @@ function tag_print_cloud($nr_of_tags=150, $return=false) { $can_manage_tags = has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM)); - if ( !$tagcloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag - FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid - WHERE ti.itemtype <> \'tag\' - GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype - ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) { - $tagcloud = array(); + if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag + FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid + WHERE ti.itemtype <> \'tag\' + GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype + ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) { + $tagsincloud = array(); } - $totaltags = count($tagcloud); - $currenttag = 0; - $size = 20; - $lasttagct = -1; + $tagkeys = array_keys($tagsincloud); + $firsttagkey = $tagkeys[0]; + $maxcount = $tagsincloud[$firsttagkey]->count; $etags = array(); - foreach ($tagcloud as $tag) { - - $currenttag++; - - if ($currenttag == 1) { - $lasttagct = $tag->count; - $size = 20; - } else if ($tag->count != $lasttagct) { - $lasttagct = $tag->count; - $size = 20 - ( (int)((($currenttag - 1) / $totaltags) * 20) ); - } + foreach ($tagsincloud as $tag) { + $size = (int) (( $tag->count / $maxcount) * 20); $tag->class = "$tag->tagtype s$size"; $etags[] = $tag; } - usort($etags, "tag_cloud_sort"); + usort($etags, "tag_cloud_sort"); $output = ''; $output .= "\n<ul class='tag_cloud inline-list'>\n"; foreach ($etags as $tag) { if ($tag->flag > 0 && $can_manage_tags) { - $tagname = '<span class="flagged-tag">'. tag_display_name($tag) .'</span>'; - } else { + $tagname = '<span class="flagged-tag">'. tag_display_name($tag) .'</span>'; + } else { $tagname = tag_display_name($tag); }