. /** * Handles displaying the calendar upcoming events block. * * @package block_calendar_upcoming * @copyright 2004 Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class block_calendar_upcoming extends block_base { /** * Initialise the block. */ public function init() { $this->title = get_string('pluginname', 'block_calendar_upcoming'); } /** * Return the content of this block. * * @return stdClass the content */ public function get_content() { global $CFG; require_once($CFG->dirroot.'/calendar/lib.php'); if ($this->content !== null) { return $this->content; } $this->content = new stdClass; $this->content->text = ''; $filtercourse = array(); if (empty($this->instance)) { // Overrides: use no course at all. $courseshown = false; $this->content->footer = ''; } else { $courseshown = $this->page->course->id; $this->content->footer = '
'. get_string('gotocalendar', 'calendar').'...
'; $context = context_course::instance($courseshown); if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) { $this->content->footer .= '
'. get_string('newevent', 'calendar').'...
'; } if ($courseshown == SITEID) { // 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. $filtercourse = calendar_get_default_courses(); } else { // Forcibly filter events to include only those from the particular course we are in. $filtercourse = array($courseshown => $this->page->course); } } list($courses, $group, $user) = calendar_set_filters($filtercourse); $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD; if (isset($CFG->calendar_lookahead)) { $defaultlookahead = intval($CFG->calendar_lookahead); } $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead); $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS; if (isset($CFG->calendar_maxevents)) { $defaultmaxevents = intval($CFG->calendar_maxevents); } $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents); $events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents); if (!empty($this->instance)) { $link = 'view.php?view=day&course='.$courseshown.'&'; $showcourselink = ($this->page->course->id == SITEID); $this->content->text = calendar_get_block_upcoming($events, $link, $showcourselink); } if (empty($this->content->text)) { $this->content->text = '
'. get_string('noupcomingevents', 'calendar').'
'; } return $this->content; } }