Merge branch 'MDL-58490-master' of git://github.com/lameze/moodle
[moodle.git] / blocks / calendar_month / block_calendar_month.php
CommitLineData
4ca6cfbf 1<?php
ec126f62
MN
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
0f3fe4b6 16
ec126f62
MN
17/**
18 * Handles displaying the calendar block.
19 *
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
23 */
e89d741a 24class block_calendar_month extends block_base {
ec126f62
MN
25
26 /**
27 * Initialise the block.
28 */
29 public function init() {
58aac666 30 $this->title = get_string('pluginname', 'block_calendar_month');
89adb174 31 }
32
ec126f62
MN
33 /**
34 * Return the content of this block.
35 *
36 * @return stdClass the content
37 */
38 public function get_content() {
39 global $CFG;
40
41 $calm = optional_param('cal_m', 0, PARAM_INT);
42 $caly = optional_param('cal_y', 0, PARAM_INT);
da304137 43 $time = optional_param('time', 0, PARAM_INT);
0f3fe4b6 44
45 require_once($CFG->dirroot.'/calendar/lib.php');
4ca6cfbf 46
ec126f62 47 if ($this->content !== null) {
0f3fe4b6 48 return $this->content;
49 }
4ca6cfbf 50
da304137
MN
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)) {
57 $time = time();
58 }
59
9b4b78fd 60 $this->content = new stdClass;
0f3fe4b6 61 $this->content->text = '';
62 $this->content->footer = '';
63
4ca6cfbf 64 // [pj] To me it looks like this if would never be needed, but Penny added it
13f64465 65 // when committing the /my/ stuff. Reminder to discuss and learn what it's about.
66 // It definitely needs SOME comment here!
797cedc7
SH
67 $courseid = $this->page->course->id;
68 $issite = ($courseid == SITEID);
13f64465 69
797cedc7 70 if ($issite) {
13f64465 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.
23a29de7 73 $filtercourse = calendar_get_default_courses();
dd97c328 74 } else {
13f64465 75 // Forcibly filter events to include only those from the particular course we are in.
797cedc7 76 $filtercourse = array($courseid => $this->page->course);
02d5eba3 77 }
458eb0d1 78
23a29de7 79 list($courses, $group, $user) = calendar_set_filters($filtercourse);
797cedc7 80 if ($issite) {
ec126f62 81 // For the front page.
23a29de7 82 $this->content->text .= calendar_get_mini($courses, $group, $user, false, false,
12cbce0a 83 'frontpage', $courseid, $time);
ec126f62 84 // No filters for now.
1a2ea6f4 85 } else {
ec126f62 86 // For any other course.
23a29de7 87 $this->content->text .= calendar_get_mini($courses, $group, $user, false, false,
12cbce0a 88 'course', $courseid, $time);
6284362d 89 $this->content->text .= '<h3 class="eventskey">'.get_string('eventskey', 'calendar').'</h3>';
12cbce0a 90 $this->content->text .= '<div class="filters calendar_filters">' .
23a29de7 91 calendar_filter_controls($this->page->url) . '</div>';
02d5eba3 92 }
0f3fe4b6 93
94 return $this->content;
95 }
96}
97
4ca6cfbf 98