Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/blog_recent/block_blog_recent.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 defined('MOODLE_INTERNAL') || die();
00027 
00032 class block_blog_recent extends block_base {
00033 
00034     function init() {
00035         $this->title = get_string('pluginname', 'block_blog_recent');
00036         $this->content_type = BLOCK_TYPE_TEXT;
00037     }
00038 
00039     function applicable_formats() {
00040         return array('all' => true, 'my' => false, 'tag' => false);
00041     }
00042 
00043     function instance_allow_config() {
00044         return true;
00045     }
00046 
00047     function get_content() {
00048         global $CFG;
00049 
00050         if ($this->content !== NULL) {
00051             return $this->content;
00052         }
00053 
00054         // verify blog is enabled
00055         if (empty($CFG->bloglevel)) {
00056             $this->content = new stdClass();
00057             $this->content->text = '';
00058             if ($this->page->user_is_editing()) {
00059                 $this->content->text = get_string('blogdisable', 'blog');
00060             }
00061             return $this->content;
00062 
00063         } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
00064             $this->content = new stdClass();
00065             $this->content->text = '';
00066             return $this->content;
00067         }
00068 
00069         require_once($CFG->dirroot .'/blog/lib.php');
00070         require_once($CFG->dirroot .'/blog/locallib.php');
00071 
00072         if (empty($this->config->recentbloginterval)) {
00073             $this->config->recentbloginterval = 8400;
00074         }
00075 
00076         if (empty($this->config->numberofrecentblogentries)) {
00077             $this->config->numberofrecentblogentries = 4;
00078         }
00079 
00080         $this->content = new stdClass();
00081         $this->content->footer = '';
00082 
00083         $context = $this->page->context;
00084 
00085         $filter = array();
00086         if ($context->contextlevel == CONTEXT_MODULE) {
00087             $filter['module'] = $context->instanceid;
00088             $a = new stdClass;
00089             $a->type = get_string('modulename', $this->page->cm->modname);
00090             $strview = get_string('viewallmodentries', 'blog', $a);
00091         } else if ($context->contextlevel == CONTEXT_COURSE) {
00092             $filter['course'] = $context->instanceid;
00093             $a = new stdClass;
00094             $a->type = get_string('course');
00095             $strview = get_string('viewblogentries', 'blog', $a);
00096         } else {
00097             $strview = get_string('viewsiteentries', 'blog');
00098         }
00099         $filter['since'] = $this->config->recentbloginterval;
00100 
00101         $bloglisting = new blog_listing($filter);
00102         $entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4);
00103         $url = new moodle_url('/blog/index.php', $filter);
00104 
00105         if (!empty($entries)) {
00106             $entrieslist = array();
00107             $viewblogurl = new moodle_url('/blog/index.php');
00108 
00109             foreach ($entries as $entryid => $entry) {
00110                 $viewblogurl->param('entryid', $entryid);
00111                 $entrylink = html_writer::link($viewblogurl, shorten_text($entry->subject));
00112                 $entrieslist[] = $entrylink;
00113             }
00114 
00115             $this->content->text .= html_writer::alist($entrieslist, array('class'=>'list'));
00116             $viewallentrieslink = html_writer::link($url, $strview);
00117             $this->content->text .= $viewallentrieslink;
00118         } else {
00119             $this->content->text .= get_string('norecentblogentries', 'block_blog_recent');
00120         }
00121     }
00122 }
 All Data Structures Namespaces Files Functions Variables Enumerations