Renamed $rid to $recordid in function call $field->update_content($rid,
[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() {
6479f657 5 $this->title = get_string('blogtags', 'blog');
f3ea6dfa 6 $this->version = 2006032000;
7 }
8
7d61cf65 9 function instance_allow_multiple() {
10 return true;
11 }
12
13 function has_config() {
14 return true;
15 }
16
17 function instance_allow_config() {
18 return true;
19 }
20
f3ea6dfa 21 function get_content() {
22
23 global $CFG;
24
25 $timewithin = time() - 7776000; // last 90 days
26 $topentries = 20; // get the 20 most popular tags
f3ea6dfa 27
28 if ($this->content !== NULL) {
29 return $this->content;
30 }
31
32 if (empty($this->instance)) {
33 $this->content = '';
34 return $this->content;
35 }
36
37 $this->content = new stdClass;
38 $this->content->text = '';
39 $this->content->footer = '';
40
41
42 /// Get a list of tags
43
44 $sql = 'SELECT t.*, COUNT(DISTINCT bt.id) as ct ';
45 $sql .= "FROM {$CFG->prefix}tags as t, {$CFG->prefix}blog_tag_instance as bt ";
46 $sql .= 'WHERE t.id = bt.tagid ';
47 $sql .= "AND bt.timemodified > $timewithin ";
48 $sql .= 'GROUP BY bt.tagid ';
49 $sql .= 'ORDER BY ct DESC, t.text ASC ';
50 $sql .= "LIMIT $topentries ";
51
7d61cf65 52 if ($tags = get_records_sql($sql)) {
53
54 $size = 20; $lasttagcount = -1; $sizecount = 1;
55 $etags = array();
56 foreach ($tags as $tag) {
57 $tag->class = "$tag->type s$size";
58 $etags[] = $tag;
f3ea6dfa 59
7d61cf65 60 /// Set the size class
61 if ($tag->ct != $lasttagcount) {
62 $size -= $sizecount;
63 $lasttagcount = $tag->ct;
64 $sizecount = 1;
65 } else {
66 $sizecount++;
67 }
68 }
69
70 usort($etags, "blog_tags_sort");
f3ea6dfa 71
7d61cf65 72 foreach ($etags as $tag) {
73 $link = $CFG->wwwroot.'/blog/index.php?filtertype=site&tagid='.$tag->id;
74 $this->content->text .= '<a href="'.$link.'" class="'.$tag->class.'">'.$tag->text.'</a> ';
f3ea6dfa 75 }
f3ea6dfa 76
7d61cf65 77 }
f3ea6dfa 78 return $this->content;
79 }
80
81 function applicable_formats() {
82 return array('all' => true, 'my' => false);
83 }
7d61cf65 84
85}
86
87function blog_tags_sort($a, $b) {
88 return strcmp($a->text, $b->text);
f3ea6dfa 89}
7d61cf65 90
f3ea6dfa 91?>