Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/calendar_upcoming/block_calendar_upcoming.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class block_calendar_upcoming extends block_base {
00004     function init() {
00005         $this->title = get_string('pluginname', 'block_calendar_upcoming');
00006     }
00007 
00008     function get_content() {
00009         global $USER, $CFG, $SESSION;
00010         $cal_m = optional_param( 'cal_m', 0, PARAM_INT );
00011         $cal_y = optional_param( 'cal_y', 0, PARAM_INT );
00012 
00013         require_once($CFG->dirroot.'/calendar/lib.php');
00014 
00015         if ($this->content !== NULL) {
00016             return $this->content;
00017         }
00018         $this->content = new stdClass;
00019         $this->content->text = '';
00020 
00021         $filtercourse    = array();
00022         if (empty($this->instance)) { // Overrides: use no course at all
00023             $courseshown = false;
00024             $this->content->footer = '';
00025 
00026         } else {
00027             $courseshown = $this->page->course->id;
00028             $this->content->footer = '<div class="gotocal"><a href="'.$CFG->wwwroot.
00029                                      '/calendar/view.php?view=upcoming&amp;course='.$courseshown.'">'.
00030                                       get_string('gotocalendar', 'calendar').'</a>...</div>';
00031             $context = get_context_instance(CONTEXT_COURSE, $courseshown);
00032             if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) {
00033                 $this->content->footer .= '<div class="newevent"><a href="'.$CFG->wwwroot.
00034                                           '/calendar/event.php?action=new&amp;course='.$courseshown.'">'.
00035                                            get_string('newevent', 'calendar').'</a>...</div>';
00036             }
00037             if ($courseshown == SITEID) {
00038                 // Being displayed at site level. This will cause the filter to fall back to auto-detecting
00039                 // the list of courses it will be grabbing events from.
00040                 $filtercourse = calendar_get_default_courses();
00041             } else {
00042                 // Forcibly filter events to include only those from the particular course we are in.
00043                 $filtercourse = array($courseshown => $this->page->course);
00044             }
00045         }
00046 
00047         list($courses, $group, $user) = calendar_set_filters($filtercourse);
00048 
00049         $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
00050         if (isset($CFG->calendar_lookahead)) {
00051             $defaultlookahead = intval($CFG->calendar_lookahead);
00052         }
00053         $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
00054 
00055         $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
00056         if (isset($CFG->calendar_maxevents)) {
00057             $defaultmaxevents = intval($CFG->calendar_maxevents);
00058         }
00059         $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
00060         $events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents);
00061 
00062         if (!empty($this->instance)) {
00063             $this->content->text = calendar_get_block_upcoming($events, 'view.php?view=day&amp;course='.$courseshown.'&amp;');
00064         }
00065 
00066         if (empty($this->content->text)) {
00067             $this->content->text = '<div class="post">'. get_string('noupcomingevents', 'calendar').'</div>';
00068         }
00069 
00070         return $this->content;
00071     }
00072 }
00073 
00074 
 All Data Structures Namespaces Files Functions Variables Enumerations