From dc01eb84f28f8383b263d84e80fcfa3349396964 Mon Sep 17 00:00:00 2001 From: Nicolas Connault Date: Fri, 30 Oct 2009 07:27:33 +0000 Subject: [PATCH] MDL-19688 Recent blog entries block --- blocks/blog_recent/block_blog_recent.php | 106 ++++++++++++----------- blocks/blog_recent/edit_form.php | 59 +++++++++++++ lang/en_utf8/block_blog_recent.php | 5 ++ 3 files changed, 118 insertions(+), 52 deletions(-) create mode 100644 blocks/blog_recent/edit_form.php create mode 100644 lang/en_utf8/block_blog_recent.php diff --git a/blocks/blog_recent/block_blog_recent.php b/blocks/blog_recent/block_blog_recent.php index 9e895744a1..59f018a79d 100644 --- a/blocks/blog_recent/block_blog_recent.php +++ b/blocks/blog_recent/block_blog_recent.php @@ -40,73 +40,75 @@ class block_blog_recent extends block_base { $this->version = 2009070900; } + function applicable_formats() { + return array('all' => true, 'my' => false, 'tag' => false); + } + + function has_config() { + return true; + } + + function instance_allow_config() { + return true; + } + function get_content() { - global $CFG, $USER, $PAGE, $DB; + global $CFG, $USER, $PAGE, $DB, $OUTPUT; - $this->content = new stdClass(); - $this->content->footer = ''; + if (empty($this->config->recentbloginterval)) { + $this->config->recentbloginterval = 8400; + } - $tag = optional_param('tag', null, PARAM_NOTAGS); - $tagid = optional_param('tagid', null, PARAM_INT); - $entryid = optional_param('entryid', null, PARAM_INT); - $groupid = optional_param('groupid', null, PARAM_INT); - $search = optional_param('search', null, PARAM_RAW); - - //correct tagid if a text tag is provided as a param - if (!empty($tag)) { //text tag parameter takes precedence - if ($tagrec = $DB->get_record_sql("SELECT * FROM {tag} WHERE name LIKE ?", array($tag))) { - $tagid = $tagrec->id; - } else { - unset($tagid); - } + if (empty($this->config->numberofrecentblogentries)) { + $this->config->numberofrecentblogentries = 4; } - $context = $PAGE->get_context(); - - $strlevel = ''; - - switch ($context->contextlevel) { - case CONTEXT_COURSE: - $strlevel = ($context->instanceid == SITEID) ? '' : get_string('course'); - break; - case CONTEXT_MODULE: - $strlevel = print_context_name($context); - break; - case CONTEXT_USER: - $strlevel = get_string('user'); - break; + if (empty($CFG->bloglevel) || ($CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguestuser()))) { + $this->content->text = ''; + if ($this->page->user_is_editing()) { + $this->content->text = get_string('blogdisable', 'blog'); + } + return $this->content; } - $filters = array(); + $this->content = new stdClass(); + $this->content->footer = ''; - if (!empty($entryid)) { - $filters['entry'] = $entryid; - } + $context = $PAGE->get_context(); - if (!empty($groupid)) { - $filters['group'] = $groupid; - } + $blogheaders = blog_get_headers(); - if (!empty($tagid)) { - $filters['tag'] = $tagid; + // Remove entryid filter + if (!empty($blogheaders['filters']['entry'])) { + unset($blogheaders['filters']['entry']); + $blogheaders['url']->remove_params(array('entryid')); } - if (!empty($search)) { - $filters['search'] = $search; - } + $blogheaders['filters']['since'] = $this->config->recentbloginterval; - $blog_listing = new blog_listing($filters); - $entries = $blog_listing->get_entries(0, get_user_preferences('blogrecententriesnumber', 4)); + $bloglisting = new blog_listing($blogheaders['filters']); + $entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4); - $this->content->text = ''; + $this->content->text .= $OUTPUT->htmllist($entrieslist); + $strview = get_string('viewsiteentries', 'blog'); + if (!empty($blogheaders['strview'])) { + $strview = $blogheaders['strview']; + } + $viewallentrieslink = html_link::make($blogheaders['url'], $strview); + $this->content->text .= $OUTPUT->link($viewallentrieslink); + } else { + $this->content->text .= get_string('norecentblogentries', 'block_blog_recent'); + } } } diff --git a/blocks/blog_recent/edit_form.php b/blocks/blog_recent/edit_form.php new file mode 100644 index 0000000000..85f5ecd131 --- /dev/null +++ b/blocks/blog_recent/edit_form.php @@ -0,0 +1,59 @@ +. + +/** + * Form for editing tag block instances. + * + * @package moodlecore + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Form for editing tag block instances. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class block_blog_recent_edit_form extends block_edit_form { + protected function specific_definition($mform) { + // Fields for editing HTML block title and contents. + $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); + + $numberofentries = array(); + for ($i = 1; $i <= 20; $i++) { + $numberofentries[$i] = $i; + } + + $mform->addElement('select', 'config_numberofrecentblogentries', get_string('numentriestodisplay', 'block_blog_recent'), $numberofentries); + $mform->setDefault('config_numberofrecentblogentries', 4); + + + $intervals = array( + 7200 => get_string('numhours', '', 2), + 14400 => get_string('numhours', '', 4), + 21600 => get_string('numhours', '', 6), + 43200 => get_string('numhours', '', 12), + 86400 => get_string('numhours', '', 24), + 172800 => get_string('numdays', '', 2), + 604800 => get_string('numdays', '', 7) + ); + + $mform->addElement('select', 'config_recentbloginterval', get_string('recentinterval', 'block_blog_recent'), $intervals); + $mform->setDefault('config_recentbloginterval', 86400); + } +} diff --git a/lang/en_utf8/block_blog_recent.php b/lang/en_utf8/block_blog_recent.php new file mode 100644 index 0000000000..dc360522e2 --- /dev/null +++ b/lang/en_utf8/block_blog_recent.php @@ -0,0 +1,5 @@ +