3 class block_calendar_month
extends block_base
{
5 $this->title
= get_string('calendar', 'calendar');
6 $this->version
= 2007101509;
9 function preferred_width() {
13 function get_content() {
14 global $USER, $CFG, $SESSION, $COURSE;
15 $cal_m = optional_param( 'cal_m', 0, PARAM_INT
);
16 $cal_y = optional_param( 'cal_y', 0, PARAM_INT
);
18 require_once($CFG->dirroot
.'/calendar/lib.php');
20 if ($this->content
!== NULL) {
21 return $this->content
;
23 // Reset the session variables
24 calendar_session_vars($COURSE);
26 $this->content
= new stdClass
;
27 $this->content
->text
= '';
28 $this->content
->footer
= '';
30 // [pj] To me it looks like this if would never be needed, but Penny added it
31 // when committing the /my/ stuff. Reminder to discuss and learn what it's about.
32 // It definitely needs SOME comment here!
33 $courseshown = $COURSE->id
;
35 if ($courseshown == SITEID
) {
36 // Being displayed at site level. This will cause the filter to fall back to auto-detecting
37 // the list of courses it will be grabbing events from.
39 $groupeventsfrom = NULL;
40 $SESSION->cal_courses_shown
= calendar_get_default_courses(true);
41 calendar_set_referring_course(0);
44 // Forcibly filter events to include only those from the particular course we are in.
45 $filtercourse = array($courseshown => $COURSE);
46 $groupeventsfrom = array($courseshown => 1);
49 // We 'll need this later
50 calendar_set_referring_course($courseshown);
52 // MDL-9059, set to show this course when admins go into a course, then unset it.
53 if ($COURSE->id
!= SITEID
&& !isset($SESSION->cal_courses_shown
[$COURSE->id
]) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM
))) {
55 $SESSION->cal_courses_shown
[$COURSE->id
] = $COURSE;
58 // Be VERY careful with the format for default courses arguments!
59 // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
60 calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
61 if ($courseshown == SITEID
) {
63 $this->content
->text
.= calendar_overlib_html();
64 $this->content
->text
.= calendar_top_controls('frontpage', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y));
65 $this->content
->text
.= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
69 // For any other course
70 $this->content
->text
.= calendar_overlib_html();
71 $this->content
->text
.= calendar_top_controls('course', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y));
72 $this->content
->text
.= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
73 $this->content
->text
.= '<h3 class="eventskey">'.get_string('eventskey', 'calendar').'</h3>';
74 $this->content
->text
.= '<div class="filters">'.calendar_filter_controls('course', '', $COURSE).'</div>';
78 // MDL-9059, unset this so that it doesn't stay in session
79 if (!empty($courseset)) {
80 unset($SESSION->cal_courses_shown
[$COURSE->id
]);
83 return $this->content
;