3 class block_calendar_upcoming
extends block_base
{
5 $this->title
= get_string('pluginname', 'block_calendar_upcoming');
8 function get_content() {
9 global $USER, $CFG, $SESSION;
10 $cal_m = optional_param( 'cal_m', 0, PARAM_INT
);
11 $cal_y = optional_param( 'cal_y', 0, PARAM_INT
);
13 require_once($CFG->dirroot
.'/calendar/lib.php');
15 if ($this->content
!== NULL) {
16 return $this->content
;
18 $this->content
= new stdClass
;
19 $this->content
->text
= '';
21 $filtercourse = array();
22 if (empty($this->instance
)) { // Overrides: use no course at all
24 $this->content
->footer
= '';
27 $courseshown = $this->page
->course
->id
;
28 $this->content
->footer
= '<div class="gotocal"><a href="'.$CFG->wwwroot
.
29 '/calendar/view.php?view=upcoming&course='.$courseshown.'">'.
30 get_string('gotocalendar', 'calendar').'</a>...</div>';
31 $context = get_context_instance(CONTEXT_COURSE
, $courseshown);
32 if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) {
33 $this->content
->footer
.= '<div class="newevent"><a href="'.$CFG->wwwroot
.
34 '/calendar/event.php?action=new&course='.$courseshown.'">'.
35 get_string('newevent', 'calendar').'</a>...</div>';
37 if ($courseshown == SITEID
) {
38 // Being displayed at site level. This will cause the filter to fall back to auto-detecting
39 // the list of courses it will be grabbing events from.
40 $filtercourse = calendar_get_default_courses();
42 // Forcibly filter events to include only those from the particular course we are in.
43 $filtercourse = array($courseshown => $this->page
->course
);
47 list($courses, $group, $user) = calendar_set_filters($filtercourse);
49 $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD
;
50 if (isset($CFG->calendar_lookahead
)) {
51 $defaultlookahead = intval($CFG->calendar_lookahead
);
53 $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
55 $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS
;
56 if (isset($CFG->calendar_maxevents
)) {
57 $defaultmaxevents = intval($CFG->calendar_maxevents
);
59 $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
60 $events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents);
62 if (!empty($this->instance
)) {
63 $this->content
->text
= calendar_get_block_upcoming($events, 'view.php?view=day&course='.$courseshown.'&');
66 if (empty($this->content
->text
)) {
67 $this->content
->text
= '<div class="post">'. get_string('noupcomingevents', 'calendar').'</div>';
70 return $this->content
;