1
0
mirror of https://github.com/moodle/moodle.git synced 2025-03-15 05:00:06 +01:00

MDL-19688 Recent blog entries block

This commit is contained in:
Nicolas Connault 2009-10-30 07:27:33 +00:00
parent 5a5cd650fc
commit dc01eb84f2
3 changed files with 123 additions and 57 deletions

@ -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;
if (empty($this->config->recentbloginterval)) {
$this->config->recentbloginterval = 8400;
}
if (empty($this->config->numberofrecentblogentries)) {
$this->config->numberofrecentblogentries = 4;
}
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;
}
$this->content = new stdClass();
$this->content->footer = '';
$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);
}
}
$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;
$blogheaders = blog_get_headers();
// Remove entryid filter
if (!empty($blogheaders['filters']['entry'])) {
unset($blogheaders['filters']['entry']);
$blogheaders['url']->remove_params(array('entryid'));
}
$filters = array();
$blogheaders['filters']['since'] = $this->config->recentbloginterval;
if (!empty($entryid)) {
$filters['entry'] = $entryid;
$bloglisting = new blog_listing($blogheaders['filters']);
$entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4);
if (!empty($entries)) {
$entrieslist = new html_list();
$entrieslist->add_class('list');
$viewblogurl = new moodle_url($CFG->wwwroot . '/blog/index.php');
foreach ($entries as $entryid => $entry) {
$viewblogurl->param('entryid', $entryid);
$entrylink = html_link::make($viewblogurl, shorten_text($entry->subject));
$entrieslist->add_item($OUTPUT->link($entrylink));
}
$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');
}
if (!empty($groupid)) {
$filters['group'] = $groupid;
}
if (!empty($tagid)) {
$filters['tag'] = $tagid;
}
if (!empty($search)) {
$filters['search'] = $search;
}
$blog_listing = new blog_listing($filters);
$entries = $blog_listing->get_entries(0, get_user_preferences('blogrecententriesnumber', 4));
$this->content->text = '<ul class="list">';
$viewblog_url = $CFG->wwwroot . '/blog/index.php?entryid=';
foreach ($entries as $entry_id => $entry) {
$this->content->text .= "<li><a href=\"$viewblog_url$entry_id\">".shorten_text($entry->subject)."</a></li>\n";
}
$this->content->text .= '<li>&nbsp;</li>';
$this->content->text .= '<li><a href="'.blog_get_context_url().'">'.get_string('viewallblogentries', 'blog', $strlevel).'</a></li>';
$this->content->text .= '</ul>';
}
}

@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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);
}
}

@ -0,0 +1,5 @@
<?php
$string['blockname'] = 'Recent blog entries';
$string['norecentblogentries'] = 'No recent entries';
$string['numentriestodisplay'] = 'Number of recent entries to display';
$string['recentinterval'] = 'Interval of time considered \"recent\"';