2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Course overview block
20 * @package block_course_overview
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 require_once($CFG->dirroot
.'/blocks/course_overview/locallib.php');
27 * Course overview block
29 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class block_course_overview
extends block_base
{
34 * If this is passed as mynumber then showallcourses, irrespective of limit by user.
36 const SHOW_ALL_COURSES
= -2;
39 * Block initialization
41 public function init() {
42 $this->title
= get_string('pluginname', 'block_course_overview');
46 * Return contents of course_overview block
48 * @return stdClass contents of block
50 public function get_content() {
51 global $USER, $CFG, $DB;
52 require_once($CFG->dirroot
.'/user/profile/lib.php');
54 if($this->content
!== NULL) {
55 return $this->content
;
58 $config = get_config('block_course_overview');
60 $this->content
= new stdClass();
61 $this->content
->text
= '';
62 $this->content
->footer
= '';
66 $updatemynumber = optional_param('mynumber', -1, PARAM_INT
);
67 if ($updatemynumber >= 0) {
68 block_course_overview_update_mynumber($updatemynumber);
71 profile_load_custom_fields($USER);
73 $showallcourses = ($updatemynumber === self
::SHOW_ALL_COURSES
);
74 list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses($showallcourses);
75 $overviews = block_course_overview_get_overviews($sitecourses);
77 $renderer = $this->page
->get_renderer('block_course_overview');
78 if (!empty($config->showwelcomearea
)) {
79 require_once($CFG->dirroot
.'/message/lib.php');
80 $msgcount = message_count_unread_messages();
81 $this->content
->text
= $renderer->welcome_area($msgcount);
84 // Number of sites to display.
85 if ($this->page
->user_is_editing() && empty($config->forcedefaultmaxcourses
)) {
86 $this->content
->text
.= $renderer->editing_bar_head($totalcourses);
89 if (empty($sortedcourses)) {
90 $this->content
->text
.= get_string('nocourses','my');
92 // For each course, build category cache.
93 $this->content
->text
.= $renderer->course_overview($sortedcourses, $overviews);
94 $this->content
->text
.= $renderer->hidden_courses($totalcourses - count($sortedcourses));
97 return $this->content
;
101 * Allow the block to have a configuration page
105 public function has_config() {
110 * Locations where block can be displayed
114 public function applicable_formats() {
115 return array('my' => true);
119 * Sets block header to be hidden or visible
121 * @return bool if true then header will be visible.
123 public function hide_header() {
124 // Hide header if welcome area is show.
125 $config = get_config('block_course_overview');
126 return !empty($config->showwelcomearea
);