Files
moodle/blocks/course_overview/block_course_overview.php
T
Martin Dougiamas 03d9401e7d My Moodle MDL-19124 New version of My Moodle, User profiles and Course profiles, all with block support
Thanks very much to Remote Learner Canada, especially Hubert Chathi and Olav Jordan, for their work on the bulk of this code, and also Mike Churchward for supporting them.  I worked on it after that (actually simplified it by removing a feature temporarily: multiple pages) to bring it more to what I was imagining, and to provide a base to build on and get all the navigation perfect.

There's still work to do.  Some blocks don't quite work as expected, and some of the code still needs upgrading to bring it fully into line with 2.0.  We also could use a much better course overview block and better CSS styling of the profile pages.  But it's definitely more usable this it was, I think.
2010-05-04 13:04:35 +00:00

129 lines
3.5 KiB
PHP

<?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/>.
/**
* Course overview block
*
* Currently, just a copy-and-paste from the old My Moodle.
*
* @package blocks
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/lib/weblib.php');
require_once($CFG->dirroot . '/lib/formslib.php');
class block_course_overview extends block_base {
/**
* block initializations
*/
public function init() {
$this->title = get_string('pluginname', 'block_course_overview');
$this->version = 2010021100;
}
/**
* block contents
*
* @return object
*/
public function get_content() {
global $USER;
if($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
$content = array();
// limits the number of courses showing up
$courses_limit = 21;
// FIXME: this should be a block setting, rather than a global setting
if (isset($CFG->mycoursesperpage)) {
$courses_limit = $CFG->mycoursesperpage;
}
$morecourses = false;
if ($courses_limit > 0) {
$courses_limit = $courses_limit + 1;
}
$courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
$site = get_site();
$course = $site; //just in case we need the old global $course hack
if (($courses_limit > 0) && (count($courses) >= $courses_limit)) {
//remove the 'marker' course that we retrieve just to see if we have more than $courses_limit
array_pop($courses);
$morecourses = true;
}
if (array_key_exists($site->id,$courses)) {
unset($courses[$site->id]);
}
foreach ($courses as $c) {
if (isset($USER->lastcourseaccess[$c->id])) {
$courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
} else {
$courses[$c->id]->lastaccess = 0;
}
}
if (empty($courses)) {
$content[] = get_string('nocourses','my');
} else {
ob_start();
print_overview($courses);
$content[] = ob_get_contents();
ob_end_clean();
}
// if more than 20 courses
if ($morecourses) {
$content[] = '<br />...';
}
$this->content->text = implode($content);
return $this->content;
}
/**
* allow the block to have a configuration page
*
* @return boolean
*/
public function has_config() {
return false;
}
/**
* locations where block can be displayed
*
* @return array
*/
public function applicable_formats() {
return array('my-index'=>true);
}
}
?>