mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 10:26:17 +02:00
MDL-14489: Make the tag cloud "more extended" in size with small dataset (credits to Matt Gibson) (merge from 1.9)
This commit is contained in:
parent
94abd70c7d
commit
dae7b4f606
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user