mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ikawhero
committed
Mar 20, 2006
1 parent
9a8091a
commit f3ea6df
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?PHP //$Id$ | ||
|
||
class block_blog_tags extends block_base { | ||
function init() { | ||
$this->title = get_string('blogtags'); | ||
$this->version = 2006032000; | ||
} | ||
|
||
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; | ||
} | ||
|
||
if (empty($this->instance)) { | ||
$this->content = ''; | ||
return $this->content; | ||
} | ||
|
||
$this->content = new stdClass; | ||
$this->content->text = ''; | ||
$this->content->footer = ''; | ||
|
||
|
||
/// Get a list of tags | ||
|
||
$sql = 'SELECT t.*, COUNT(DISTINCT bt.id) as ct '; | ||
$sql .= "FROM {$CFG->prefix}tags as t, {$CFG->prefix}blog_tag_instance as bt "; | ||
$sql .= 'WHERE t.id = bt.tagid '; | ||
$sql .= "AND bt.timemodified > $timewithin "; | ||
$sql .= 'GROUP BY bt.tagid '; | ||
$sql .= 'ORDER BY ct DESC, t.text ASC '; | ||
$sql .= "LIMIT $topentries "; | ||
|
||
$tags = get_records_sql($sql) or array(); | ||
|
||
$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; | ||
|
||
$this->content->text .= '<a href="'.$link.'" class="'.$class.'">'.$tag->text.'</a> '; | ||
|
||
/// Set the size class | ||
if ($tag->ct != $lasttagcount) { | ||
$size -= $sizecount; | ||
$lasttagcount = $tag->ct; | ||
$sizecount = 1; | ||
} else { | ||
$sizecount++; | ||
} | ||
} | ||
|
||
return $this->content; | ||
} | ||
|
||
function applicable_formats() { | ||
return array('all' => true, 'my' => false); | ||
} | ||
} | ||
?> |