Fix a possible race condition in the PaintWeb DML code.
[moodle/mihaisucan.git] / blocks / calendar_upcoming / block_calendar_upcoming.php
blobb47559593fd991fb0ecc19dfed5aa514a3945444
1 <?PHP //$Id$
3 class block_calendar_upcoming extends block_base {
4 function init() {
5 $this->title = get_string('upcomingevents', 'calendar');
6 $this->version = 2007101509;
9 function get_content() {
10 global $USER, $CFG, $SESSION, $COURSE;
11 $cal_m = optional_param( 'cal_m', 0, PARAM_INT );
12 $cal_y = optional_param( 'cal_y', 0, PARAM_INT );
14 require_once($CFG->dirroot.'/calendar/lib.php');
16 if ($this->content !== NULL) {
17 return $this->content;
19 // Reset the session variables
20 calendar_session_vars($COURSE);
21 $this->content = new stdClass;
22 $this->content->text = '';
24 if (empty($this->instance)) { // Overrides: use no course at all
26 $courseshown = false;
27 $filtercourse = array();
28 $this->content->footer = '';
30 } else {
31 $courseshown = $COURSE->id;
32 $this->content->footer = '<br /><a href="'.$CFG->wwwroot.
33 '/calendar/view.php?view=upcoming&amp;course='.$courseshown.'">'.
34 get_string('gotocalendar', 'calendar').'</a>...';
35 $context = get_context_instance(CONTEXT_COURSE, $courseshown);
36 if (has_capability('moodle/calendar:manageentries', $context) ||
37 has_capability('moodle/calendar:manageownentries', $context)) {
38 $this->content->footer .= '<br /><a href="'.$CFG->wwwroot.
39 '/calendar/event.php?action=new&amp;course='.$courseshown.'">'.
40 get_string('newevent', 'calendar').'</a>...';
42 if ($courseshown == SITEID) {
43 // Being displayed at site level. This will cause the filter to fall back to auto-detecting
44 // the list of courses it will be grabbing events from.
45 $filtercourse = NULL;
46 $groupeventsfrom = NULL;
47 $SESSION->cal_courses_shown = calendar_get_default_courses(true);
48 calendar_set_referring_course(0);
49 } else {
50 // Forcibly filter events to include only those from the particular course we are in.
51 $filtercourse = array($courseshown => $COURSE);
52 $groupeventsfrom = array($courseshown => 1);
56 // We 'll need this later
57 calendar_set_referring_course($courseshown);
59 // Be VERY careful with the format for default courses arguments!
60 // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
62 calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
63 $events = calendar_get_upcoming($courses, $group, $user,
64 get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS),
65 get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
67 if (!empty($this->instance)) {
68 $this->content->text = calendar_get_sideblock_upcoming($events,
69 'view.php?view=day&amp;course='.$courseshown.'&amp;');
72 if (empty($this->content->text)) {
73 $this->content->text = '<div class="post">'.
74 get_string('noupcomingevents', 'calendar').'</div>';
77 return $this->content;