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 * Handles displaying the calendar block.
20 * @package block_calendar_month
21 * @copyright 2004 Eloy Lafuente (stronk7) {@link http://stronk7.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 class block_calendar_month
extends block_base
{
27 * Initialise the block.
29 public function init() {
30 $this->title
= get_string('pluginname', 'block_calendar_month');
34 * Return the content of this block.
36 * @return stdClass the content
38 public function get_content() {
41 $calm = optional_param('cal_m', 0, PARAM_INT
);
42 $caly = optional_param('cal_y', 0, PARAM_INT
);
43 $time = optional_param('time', 0, PARAM_INT
);
45 require_once($CFG->dirroot
.'/calendar/lib.php');
47 if ($this->content
!== null) {
48 return $this->content
;
51 // If a day, month and year were passed then convert it to a timestamp. If these were passed then we can assume
52 // the day, month and year are passed as Gregorian, as no where in core should we be passing these values rather
53 // than the time. This is done for BC.
54 if (!empty($calm) && (!empty($caly))) {
55 $time = make_timestamp($caly, $calm, 1);
56 } else if (empty($time)) {
60 $this->content
= new stdClass
;
61 $this->content
->text
= '';
62 $this->content
->footer
= '';
64 // [pj] To me it looks like this if would never be needed, but Penny added it
65 // when committing the /my/ stuff. Reminder to discuss and learn what it's about.
66 // It definitely needs SOME comment here!
67 $courseid = $this->page
->course
->id
;
68 $issite = ($courseid == SITEID
);
71 // Being displayed at site level. This will cause the filter to fall back to auto-detecting
72 // the list of courses it will be grabbing events from.
73 $filtercourse = calendar_get_default_courses();
75 // Forcibly filter events to include only those from the particular course we are in.
76 $filtercourse = array($courseid => $this->page
->course
);
79 list($courses, $group, $user) = calendar_set_filters($filtercourse);
81 // For the front page.
82 $this->content
->text
.= calendar_get_mini($courses, $group, $user, false, false, 'frontpage', $courseid, $time);
83 // No filters for now.
85 // For any other course.
86 $this->content
->text
.= calendar_get_mini($courses, $group, $user, false, false, 'course', $courseid, $time);
87 $this->content
->text
.= '<h3 class="eventskey">'.get_string('eventskey', 'calendar').'</h3>';
88 $this->content
->text
.= '<div class="filters calendar_filters">'.calendar_filter_controls($this->page
->url
).'</div>';
91 return $this->content
;