mirror of
https://github.com/moodle/moodle.git
synced 2025-04-17 22:45:54 +02:00
Block now configurable.
This commit is contained in:
parent
4852ab889f
commit
b51434e751
@ -1,9 +1,13 @@
|
||||
<?PHP //$Id$
|
||||
|
||||
define('BLOGDEFAULTTIMEWITHIN', 90);
|
||||
define('BLOGDEFAULTNUMBEROFTAGS', 20);
|
||||
define('BLOGDEFAULTSORT', 'text');
|
||||
|
||||
class block_blog_tags extends block_base {
|
||||
function init() {
|
||||
$this->title = get_string('blogtags', 'blog');
|
||||
$this->version = 2006032000;
|
||||
$this->title = get_string('blogtags', 'blog');
|
||||
}
|
||||
|
||||
function instance_allow_multiple() {
|
||||
@ -14,16 +18,38 @@ class block_blog_tags extends block_base {
|
||||
return true;
|
||||
}
|
||||
|
||||
function applicable_formats() {
|
||||
return array('all' => true, 'my' => false);
|
||||
}
|
||||
|
||||
function instance_allow_config() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function specialization() {
|
||||
|
||||
// load userdefined title and make sure it's never empty
|
||||
if (empty($this->config->title)) {
|
||||
$this->title = get_string('blocktagstitle','blog');
|
||||
} else {
|
||||
$this->title = $this->config->title;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_content() {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$timewithin = time() - 7776000; // last 90 days
|
||||
$topentries = 20; // get the 20 most popular tags
|
||||
if (empty($this->config->timewithin)) {
|
||||
$this->config->timewithin = BLOGDEFAULTTIMEWITHIN;
|
||||
}
|
||||
if (empty($this->config->numberoftags)) {
|
||||
$this->config->numberoftags = BLOGDEFAULTNUMBEROFTAGS;
|
||||
}
|
||||
if (empty($this->config->sort)) {
|
||||
$this->config->sort = BLOGDEFAULTSORT;
|
||||
}
|
||||
|
||||
if ($this->content !== NULL) {
|
||||
return $this->content;
|
||||
@ -40,14 +66,16 @@ class block_blog_tags extends block_base {
|
||||
|
||||
|
||||
/// Get a list of tags
|
||||
|
||||
$timewithin = $this->config->timewithin * 24 * 60 * 60; /// convert to seconds
|
||||
|
||||
$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 .= "AND bt.timemodified > {$timewithin} ";
|
||||
$sql .= 'GROUP BY bt.tagid ';
|
||||
$sql .= 'ORDER BY ct DESC, t.text ASC ';
|
||||
$sql .= "LIMIT $topentries ";
|
||||
$sql .= "LIMIT {$this->config->numberoftags} ";
|
||||
|
||||
if ($tags = get_records_sql($sql)) {
|
||||
|
||||
@ -81,28 +109,74 @@ class block_blog_tags extends block_base {
|
||||
}
|
||||
|
||||
/// Now we sort the tag display order
|
||||
$CFG->tagsort = $this->config->sort;
|
||||
usort($etags, "blog_tags_sort");
|
||||
|
||||
/// Finally we create the output
|
||||
foreach ($etags as $tag) {
|
||||
$link = $CFG->wwwroot.'/blog/index.php?courseid='.
|
||||
$this->instance->pageid.'&filtertype=site&tagid='.$tag->id;
|
||||
$this->content->text .= '<a href="'.$link.'" class="'.
|
||||
$tag->class.'">'.$tag->text.'</a> ';
|
||||
$this->content->text .= '<a href="'.$link.'" '.
|
||||
'class="'.$tag->class.'" '.
|
||||
'title="'.get_string('numberofentries','blog',$tag->ct).'">'.
|
||||
$tag->text.'</a> ';
|
||||
}
|
||||
|
||||
}
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
function applicable_formats() {
|
||||
return array('all' => true, 'my' => false);
|
||||
function instance_config_print() {
|
||||
global $CFG;
|
||||
|
||||
/// set up the numberoftags select field
|
||||
$numberoftags = array();
|
||||
for($i=1;$i<=50;$i++) $numberoftags[$i] = $i;
|
||||
|
||||
//// set up the timewithin select field
|
||||
$timewithin = array();
|
||||
$timewithin[10] = get_string('numdays', '', 10);
|
||||
$timewithin[30] = get_string('numdays', '', 30);
|
||||
$timewithin[60] = get_string('numdays', '', 60);
|
||||
$timewithin[90] = get_string('numdays', '', 90);
|
||||
$timewithin[120] = get_string('numdays', '', 120);
|
||||
$timewithin[240] = get_string('numdays', '', 240);
|
||||
$timewithin[365] = get_string('numdays', '', 365);
|
||||
|
||||
/// set up sort select field
|
||||
$sort = array();
|
||||
$sort['text'] = get_string('tagtext', 'blog');
|
||||
$sort['id'] = get_string('tagdatelastused', 'blog');
|
||||
|
||||
|
||||
if (is_file($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html')) {
|
||||
print_simple_box_start('center', '', '', 5, 'blockconfigglobal');
|
||||
include($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html');
|
||||
print_simple_box_end();
|
||||
} else {
|
||||
notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function blog_tags_sort($a, $b) {
|
||||
return strcmp($a->text, $b->text);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
43
blocks/blog_tags/config_instance.html
Normal file
43
blocks/blog_tags/config_instance.html
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
if (empty($this->config->title)) {
|
||||
$this->config->title = get_string('blogtags', 'blog');
|
||||
}
|
||||
if (empty($this->config->timewithin)) {
|
||||
$this->config->timewithin = BLOGDEFAULTTIMEWITHIN;
|
||||
}
|
||||
if (empty($this->config->numberoftags)) {
|
||||
$this->config->numberoftags = BLOGDEFAULTNUMBEROFTAGS;
|
||||
}
|
||||
if (empty($this->config->sort)) {
|
||||
$this->config->sort = BLOGDEFAULTSORT;
|
||||
}
|
||||
?>
|
||||
|
||||
<table cellpadding="9" cellspacing="0">
|
||||
|
||||
<tr valign=top>
|
||||
<td align=right><?php print_string("blocktitle","blog") ?>:</td>
|
||||
<td><input type="text" name="title" size="50" value="<?php p($this->config->title) ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr valign=top>
|
||||
<td align=right><?php print_string("numberoftags","blog") ?>:</td>
|
||||
<td><?php choose_from_menu($numberoftags,"numberoftags",$this->config->numberoftags) ?></td>
|
||||
</tr>
|
||||
|
||||
<tr valign=top>
|
||||
<td align=right><?php print_string("timewithin","blog") ?>:</td>
|
||||
<td><?php choose_from_menu($timewithin,"timewithin",$this->config->timewithin) ?></td>
|
||||
</tr>
|
||||
|
||||
<tr valign=top>
|
||||
<td align=right><?php print_string("tagsort","blog") ?>:</td>
|
||||
<td><?php choose_from_menu($sort,"sort",$this->config->sort) ?></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="2" align="center"><input type="submit" value="<?php print_string("savechanges") ?>"></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user