Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/course_overview/block_course_overview.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require_once($CFG->dirroot.'/lib/weblib.php');
00028 require_once($CFG->dirroot . '/lib/formslib.php');
00029 
00030 class block_course_overview extends block_base {
00034     public function init() {
00035         $this->title   = get_string('pluginname', 'block_course_overview');
00036     }
00037 
00043     public function get_content() {
00044         global $USER, $CFG;
00045         if($this->content !== NULL) {
00046             return $this->content;
00047         }
00048 
00049         $this->content = new stdClass();
00050         $this->content->text = '';
00051         $this->content->footer = '';
00052 
00053         $content = array();
00054 
00055         // limits the number of courses showing up
00056         $courses_limit = 21;
00057         // FIXME: this should be a block setting, rather than a global setting
00058         if (isset($CFG->mycoursesperpage)) {
00059             $courses_limit = $CFG->mycoursesperpage;
00060         }
00061 
00062         $morecourses = false;
00063         if ($courses_limit > 0) {
00064             $courses_limit = $courses_limit + 1;
00065         }
00066 
00067         $courses = enrol_get_my_courses('id, shortname, modinfo', 'visible DESC,sortorder ASC', $courses_limit);
00068         $site = get_site();
00069         $course = $site; //just in case we need the old global $course hack
00070 
00071         if (is_enabled_auth('mnet')) {
00072             $remote_courses = get_my_remotecourses();
00073         }
00074         if (empty($remote_courses)) {
00075             $remote_courses = array();
00076         }
00077 
00078         if (($courses_limit > 0) && (count($courses)+count($remote_courses) >= $courses_limit)) {
00079             // get rid of any remote courses that are above the limit
00080             $remote_courses = array_slice($remote_courses, 0, $courses_limit - count($courses), true);
00081             if (count($courses) >= $courses_limit) {
00082                 //remove the 'marker' course that we retrieve just to see if we have more than $courses_limit
00083                 array_pop($courses);
00084             }
00085             $morecourses = true;
00086         }
00087 
00088 
00089         if (array_key_exists($site->id,$courses)) {
00090             unset($courses[$site->id]);
00091         }
00092 
00093         foreach ($courses as $c) {
00094             if (isset($USER->lastcourseaccess[$c->id])) {
00095                 $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
00096             } else {
00097                 $courses[$c->id]->lastaccess = 0;
00098             }
00099         }
00100 
00101         if (empty($courses) && empty($remote_courses)) {
00102             $content[] = get_string('nocourses','my');
00103         } else {
00104             ob_start();
00105 
00106             require_once $CFG->dirroot."/course/lib.php";
00107             print_overview($courses, $remote_courses);
00108 
00109             $content[] = ob_get_contents();
00110             ob_end_clean();
00111         }
00112 
00113         // if more than 20 courses
00114         if ($morecourses) {
00115             $content[] = '<br />...';
00116         }
00117 
00118         $this->content->text = implode($content);
00119 
00120         return $this->content;
00121     }
00122 
00128     public function has_config() {
00129         return false;
00130     }
00131 
00137     public function applicable_formats() {
00138         return array('my-index'=>true);
00139     }
00140 }
00141 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations