Block for listing blog tags
[moodle.git] / blocks / blog_tags / block_blog_tags.php
CommitLineData
f3ea6dfa 1<?PHP //$Id$
2
3class block_blog_tags extends block_base {
4 function init() {
5 $this->title = get_string('blogtags');
6 $this->version = 2006032000;
7 }
8
9 function get_content() {
10
11 global $CFG;
12
13 $timewithin = time() - 7776000; // last 90 days
14 $topentries = 20; // get the 20 most popular tags
15
16
17 if ($this->content !== NULL) {
18 return $this->content;
19 }
20
21 if (empty($this->instance)) {
22 $this->content = '';
23 return $this->content;
24 }
25
26 $this->content = new stdClass;
27 $this->content->text = '';
28 $this->content->footer = '';
29
30
31 /// Get a list of tags
32
33 $sql = 'SELECT t.*, COUNT(DISTINCT bt.id) as ct ';
34 $sql .= "FROM {$CFG->prefix}tags as t, {$CFG->prefix}blog_tag_instance as bt ";
35 $sql .= 'WHERE t.id = bt.tagid ';
36 $sql .= "AND bt.timemodified > $timewithin ";
37 $sql .= 'GROUP BY bt.tagid ';
38 $sql .= 'ORDER BY ct DESC, t.text ASC ';
39 $sql .= "LIMIT $topentries ";
40
41 $tags = get_records_sql($sql) or array();
42
43 $size = 20; $lasttagcount = -1; $sizecount = 1;
44 foreach ($tags as $tag) {
45 $class = "$tag->type s$size";
46 $link = $CFG->wwwroot.'/blog/index.php?filtertype=site&tagid='.$tag->id;
47
48 $this->content->text .= '<a href="'.$link.'" class="'.$class.'">'.$tag->text.'</a> ';
49
50 /// Set the size class
51 if ($tag->ct != $lasttagcount) {
52 $size -= $sizecount;
53 $lasttagcount = $tag->ct;
54 $sizecount = 1;
55 } else {
56 $sizecount++;
57 }
58 }
59
60 return $this->content;
61 }
62
63 function applicable_formats() {
64 return array('all' => true, 'my' => false);
65 }
66}
67?>