2004-04-18 23:20:53 +00:00
|
|
|
<?PHP //$Id$
|
|
|
|
|
2004-11-23 18:53:34 +00:00
|
|
|
class block_calendar_upcoming extends block_base {
|
2004-10-19 21:04:28 +00:00
|
|
|
function init() {
|
2004-04-18 23:20:53 +00:00
|
|
|
$this->title = get_string('upcomingevents', 'calendar');
|
2008-03-03 11:43:32 +00:00
|
|
|
$this->version = 2007101509;
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
function get_content() {
|
2006-05-29 08:17:57 +00:00
|
|
|
global $USER, $CFG, $SESSION, $COURSE;
|
2005-06-10 10:05:30 +00:00
|
|
|
$cal_m = optional_param( 'cal_m', 0, PARAM_INT );
|
|
|
|
$cal_y = optional_param( 'cal_y', 0, PARAM_INT );
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
require_once($CFG->dirroot.'/calendar/lib.php');
|
|
|
|
|
2004-08-11 09:00:53 +00:00
|
|
|
if ($this->content !== NULL) {
|
2004-04-18 23:20:53 +00:00
|
|
|
return $this->content;
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
// Reset the session variables
|
|
|
|
calendar_session_vars($COURSE);
|
2004-10-19 21:04:28 +00:00
|
|
|
$this->content = new stdClass;
|
2004-04-18 23:20:53 +00:00
|
|
|
$this->content->text = '';
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (empty($this->instance)) { // Overrides: use no course at all
|
2004-09-07 10:31:18 +00:00
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
$courseshown = false;
|
2004-05-20 15:16:42 +00:00
|
|
|
$filtercourse = array();
|
2004-08-11 09:00:53 +00:00
|
|
|
$this->content->footer = '';
|
2004-09-07 10:31:18 +00:00
|
|
|
|
2004-08-11 09:00:53 +00:00
|
|
|
} else {
|
2006-05-29 08:17:57 +00:00
|
|
|
$courseshown = $COURSE->id;
|
2004-08-11 09:00:53 +00:00
|
|
|
$this->content->footer = '<br /><a href="'.$CFG->wwwroot.
|
2004-10-19 21:04:28 +00:00
|
|
|
'/calendar/view.php?view=upcoming&course='.$courseshown.'">'.
|
2004-08-11 09:00:53 +00:00
|
|
|
get_string('gotocalendar', 'calendar').'</a>...';
|
2006-09-12 08:28:36 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $courseshown);
|
|
|
|
if (has_capability('moodle/calendar:manageentries', $context) ||
|
|
|
|
has_capability('moodle/calendar:manageownentries', $context)) {
|
|
|
|
$this->content->footer .= '<br /><a href="'.$CFG->wwwroot.
|
|
|
|
'/calendar/event.php?action=new&course='.$courseshown.'">'.
|
|
|
|
get_string('newevent', 'calendar').'</a>...';
|
|
|
|
}
|
2004-10-19 21:04:28 +00:00
|
|
|
if ($courseshown == SITEID) {
|
2004-09-19 22:25:21 +00:00
|
|
|
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
|
|
|
|
// the list of courses it will be grabbing events from.
|
2008-01-24 20:33:50 +00:00
|
|
|
$filtercourse = NULL;
|
|
|
|
$groupeventsfrom = NULL;
|
2008-04-17 19:19:55 +00:00
|
|
|
$SESSION->cal_courses_shown = calendar_get_default_courses(true);
|
|
|
|
calendar_set_referring_course(0);
|
2004-09-30 08:35:55 +00:00
|
|
|
} else {
|
2004-09-07 10:31:18 +00:00
|
|
|
// Forcibly filter events to include only those from the particular course we are in.
|
2008-01-24 20:33:50 +00:00
|
|
|
$filtercourse = array($courseshown => $COURSE);
|
|
|
|
$groupeventsfrom = array($courseshown => 1);
|
2004-09-07 10:31:18 +00:00
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We 'll need this later
|
|
|
|
calendar_set_referring_course($courseshown);
|
|
|
|
|
|
|
|
// Be VERY careful with the format for default courses arguments!
|
|
|
|
// Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
|
2004-09-30 08:35:55 +00:00
|
|
|
$events = calendar_get_upcoming($courses, $group, $user,
|
|
|
|
get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS),
|
|
|
|
get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($this->instance)) {
|
2004-09-30 08:35:55 +00:00
|
|
|
$this->content->text = calendar_get_sideblock_upcoming($events,
|
2004-10-19 21:04:28 +00:00
|
|
|
'view.php?view=day&course='.$courseshown.'&');
|
2004-09-30 08:35:55 +00:00
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2004-09-30 08:35:55 +00:00
|
|
|
if (empty($this->content->text)) {
|
2005-04-22 21:13:37 +00:00
|
|
|
$this->content->text = '<div class="post">'.
|
2004-09-30 08:35:55 +00:00
|
|
|
get_string('noupcomingevents', 'calendar').'</div>';
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|