From 7d61cf659646a3426f7dacd554699281a4de5fa7 Mon Sep 17 00:00:00 2001 From: ikawhero Date: Wed, 22 Mar 2006 16:48:35 +0000 Subject: [PATCH] Added sorting - needs generalising. --- blocks/blog_tags/block_blog_tags.php | 56 ++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/blocks/blog_tags/block_blog_tags.php b/blocks/blog_tags/block_blog_tags.php index 7d856836b6..855787480d 100644 --- a/blocks/blog_tags/block_blog_tags.php +++ b/blocks/blog_tags/block_blog_tags.php @@ -6,13 +6,24 @@ class block_blog_tags extends block_base { $this->version = 2006032000; } + function instance_allow_multiple() { + return true; + } + + function has_config() { + return true; + } + + function instance_allow_config() { + return true; + } + function get_content() { global $CFG; $timewithin = time() - 7776000; // last 90 days $topentries = 20; // get the 20 most popular tags - if ($this->content !== NULL) { return $this->content; @@ -38,30 +49,43 @@ class block_blog_tags extends block_base { $sql .= 'ORDER BY ct DESC, t.text ASC '; $sql .= "LIMIT $topentries "; - $tags = get_records_sql($sql) or array(); + if ($tags = get_records_sql($sql)) { + + $size = 20; $lasttagcount = -1; $sizecount = 1; + $etags = array(); + foreach ($tags as $tag) { + $tag->class = "$tag->type s$size"; + $etags[] = $tag; - $size = 20; $lasttagcount = -1; $sizecount = 1; - foreach ($tags as $tag) { - $class = "$tag->type s$size"; - $link = $CFG->wwwroot.'/blog/index.php?filtertype=site&tagid='.$tag->id; + /// Set the size class + if ($tag->ct != $lasttagcount) { + $size -= $sizecount; + $lasttagcount = $tag->ct; + $sizecount = 1; + } else { + $sizecount++; + } + } + + usort($etags, "blog_tags_sort"); - $this->content->text .= ''.$tag->text.' '; - - /// Set the size class - if ($tag->ct != $lasttagcount) { - $size -= $sizecount; - $lasttagcount = $tag->ct; - $sizecount = 1; - } else { - $sizecount++; + foreach ($etags as $tag) { + $link = $CFG->wwwroot.'/blog/index.php?filtertype=site&tagid='.$tag->id; + $this->content->text .= ''.$tag->text.' '; } - } + } return $this->content; } function applicable_formats() { return array('all' => true, 'my' => false); } + +} + +function blog_tags_sort($a, $b) { + return strcmp($a->text, $b->text); } + ?> -- 2.39.5