From: scyrma Date: Wed, 27 Feb 2008 04:49:28 +0000 (+0000) Subject: MDL-13633 - This is a first step toward integrating all "tag blocks" together. (merge... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4e6d0c94c489a9c375f59892b1f3846a3bc7affe;p=moodle.git MDL-13633 - This is a first step toward integrating all "tag blocks" together. (merge from 1.9) --- diff --git a/tag/locallib.php b/tag/locallib.php index 0ceea95c86..e51431e6a3 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -18,68 +18,55 @@ * @param int $min_size minimum text size, in percentage * @param $return if true return html string */ -function tag_print_cloud($nr_of_tags=150, $shuffle=true, $max_size=180, $min_size=80, $return=false) { +function tag_print_cloud($nr_of_tags=150, $max_size=170, $min_size=70, $return=false) { global $CFG; + + $can_manage_tags = has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM)); - $query = 'SELECT tg.rawname, tg.id, tg.name, COUNT(ti.id) AS count, tg.flag '. + $tagcloud = get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag '. 'FROM '. $CFG->prefix .'tag_instance ti INNER JOIN '. $CFG->prefix .'tag tg ON tg.id = ti.tagid '. 'GROUP BY tg.id, tg.rawname, tg.name, tg.flag '. - 'ORDER BY count DESC'; + 'ORDER BY count DESC, tg.name ASC', 0, $nr_of_tags); - $tagcloud = get_records_sql($query, 0, $nr_of_tags); + $totaltags = count($tagcloud); + $currenttag = 0; + $size = 20; + $lasttagct = -1; - if ($shuffle) { - shuffle($tagcloud); - } else { - ksort($tagcloud); - } + $etags = array(); + foreach ($tagcloud as $tag) { - $count = array(); - foreach ($tagcloud as $key => $tag){ - if(!empty($tag->count)) { - $count[$key] = log10($tag->count); - } - else{ - $count[$key] = 0; - } - } + $currenttag++; - $max = max($count); - $min = min($count); + if ($currenttag == 1) { + $lasttagct = $tag->count; + $size = 20; + } else if ($tag->count != $lasttagct) { + $lasttagct = $tag->count; + $size = 20 - ( (int)((($currenttag - 1) / $totaltags) * 20) ); + } - $spread = $max - $min; - if (0 == $spread) { // we don't want to divide by zero - $spread = 1; + $tag->class = "$tag->tagtype s$size"; + $etags[] = $tag; } - $step = ($max_size - $min_size)/($spread); - - $systemcontext = get_context_instance(CONTEXT_SYSTEM); - $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext); - - //prints the tag cloud - $output = '\n"; if ($return) { return $output; @@ -88,6 +75,29 @@ function tag_print_cloud($nr_of_tags=150, $shuffle=true, $max_size=180, $min_siz } } +/** + * This function is used by print_tag_cloud, to usort() the tags in the cloud. + * See php.net/usort for the parameters documentation. This was originally in + * blocks/blog_tags/block_blog_tags.php, named blog_tags_sort(). + */ +function tag_cloud_sort($a, $b) { + global $CFG; + + if (empty($CFG->tagsort)) { + return 0; + } else { + $tagsort = $CFG->tagsort; + } + + if (is_numeric($a->$tagsort)) { + return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1; + } elseif (is_string($a->$tagsort)) { + return strcmp($a->$tagsort, $b->$tagsort); + } else { + return 0; + } +} + /** * Prints a box with the description of a tag and its related tags * diff --git a/theme/standard/styles_fonts.css b/theme/standard/styles_fonts.css index 7ebaf6a94d..92aeb01483 100644 --- a/theme/standard/styles_fonts.css +++ b/theme/standard/styles_fonts.css @@ -711,6 +711,79 @@ body#grade-index .grades .header { text-decoration: none; } +/*** + *** Tags + ***/ + +.tag_cloud .s20 { + font-size: 1.5em; + font-weight: bold; +} + +.tag_cloud .s19 { + font-size: 1.5em; +} + +.tag_cloud .s18 { + font-size: 1.4em; + font-weight: bold; +} + +.tag_cloud .s17 { + font-size: 1.4em; +} + +.tag_cloud .s16 { + font-size: 1.3em; + font-weight: bold; +} + +.tag_cloud .s15 { + font-size: 1.3em; +} + +.tag_cloud .s14 { + font-size: 1.2em; + font-weight: bold; +} + +.tag_cloud .s13 { + font-size: 1.2em; +} + +.tag_cloud .s12, +.tag_cloud .s11 { + font-size: 1.1em; + font-weight: bold; +} + +.tag_cloud .s10, +.tag_cloud .s9 { + font-size: 1.1em; +} + +.tag_cloud .s8, +.tag_cloud .s7 { + font-size: 1em; + font-weight: bold; +} + +.tag_cloud .s6, +.tag_cloud .s5 { + font-size: 1em; +} + +.tag_cloud .s4, +.tag_cloud .s3 { + font-size: 0.9em; + font-weight: bold; +} + +.tag_cloud .s2, +.tag_cloud .s1 { + font-size: 0.9em; +} + /*** *** User