Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/calendar/renderer.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00029 class core_calendar_renderer extends plugin_renderer_base {
00030 
00041     public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $userid, $authtoken) {
00042 
00043         $output  = html_writer::tag('div', get_string('export', 'calendar'), array('class'=>'header'));
00044         $output .= html_writer::start_tag('fieldset');
00045         $output .= html_writer::tag('legend', get_string('commontasks', 'calendar'));
00046         $output .= html_writer::start_tag('form', array('action'=>new moodle_url('/calendar/export_execute.php'), 'method'=>'get'));
00047 
00048         $output .= html_writer::tag('div', get_string('iwanttoexport', 'calendar'));
00049 
00050         $output .= html_writer::start_tag('div', array('class'=>'indent'));
00051         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_all', 'value'=>'all', 'checked'=>'checked'));
00052         $output .= html_writer::tag('label', get_string('eventsall', 'calendar'), array('for'=>'pw_all'));
00053         $output .= html_writer::empty_tag('br');
00054         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_course', 'value'=>'courses'));
00055         $output .= html_writer::tag('label', get_string('eventsrelatedtocourses', 'calendar'), array('for'=>'pw_course'));
00056         $output .= html_writer::empty_tag('br');
00057         $output .= html_writer::end_tag('div');
00058 
00059         $output .= html_writer::tag('div', get_string('for', 'calendar').':');
00060 
00061         $output .= html_writer::start_tag('div', array('class'=>'indent'));
00062         if ($allowthisweek) {
00063             $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknow', 'value'=>'weeknow', 'checked'=>'checked'));
00064             $output .= html_writer::tag('label', get_string('weekthis', 'calendar'), array('for'=>'pt_wknow'));
00065             $output .= html_writer::empty_tag('br');
00066         }
00067         if ($allownextweek) {
00068             $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknext', 'value'=>'weeknext'));
00069             $output .= html_writer::tag('label', get_string('weeknext', 'calendar'), array('for'=>'pt_wknext'));
00070             $output .= html_writer::empty_tag('br');
00071         }
00072         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnow', 'value'=>'monthnow'));
00073         $output .= html_writer::tag('label', get_string('monththis', 'calendar'), array('for'=>'pt_monnow'));
00074         $output .= html_writer::empty_tag('br');
00075         if ($allownextmonth) {
00076             $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnext', 'value'=>'monthnext'));
00077             $output .= html_writer::tag('label', get_string('monthnext', 'calendar'), array('for'=>'pt_monnext'));
00078             $output .= html_writer::empty_tag('br');
00079         }
00080         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_recupc', 'value'=>'recentupcoming'));
00081         $output .= html_writer::tag('label', get_string('recentupcoming', 'calendar'), array('for'=>'pt_recupc'));
00082         $output .= html_writer::empty_tag('br');
00083         $output .= html_writer::end_tag('div');
00084 
00085         $output .= html_writer::start_tag('div', array('class'=>'rightalign'));
00086         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>''));
00087         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>''));
00088         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>''));
00089         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'userid', 'value'=>$userid));
00090         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken));
00091 
00092         $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name' => 'generateurl', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
00093         $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar')));
00094 
00095         $output .= html_writer::end_tag('div');
00096 
00097         $output .= html_writer::end_tag('form');
00098         $output .= html_writer::end_tag('fieldset');
00099 
00100         $output .= html_writer::start_tag('div', array('id'=>'urlbox', 'style'=>'display:none;'));
00101         $output .= html_writer::tag('p', get_string('urlforical', 'calendar'));
00102         $output .= html_writer::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;'));
00103         $output .= html_writer::end_tag('div');
00104 
00105         return $output;
00106     }
00107 
00113     public function start_layout() {
00114         return html_writer::start_tag('div', array('class'=>'maincalendar'));
00115     }
00116 
00122     public function complete_layout() {
00123         return html_writer::end_tag('div');
00124     }
00125 
00137     public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) {
00138         return html_writer::tag('div', calendar_filter_controls($this->page->url), array('class'=>'calendar_filters filters'));
00139     }
00140 
00149     public function fake_block_threemonths(calendar_information $calendar) {
00150 
00151         list($prevmon, $prevyr) = calendar_sub_month($calendar->month, $calendar->year);
00152         list($nextmon, $nextyr) = calendar_add_month($calendar->month, $calendar->year);
00153 
00154         $content  = html_writer::start_tag('div', array('class'=>'minicalendarblock'));
00155         $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $prevmon, 'y' => $prevyr));
00156         $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $prevmon, $prevyr);
00157         $content .= html_writer::end_tag('div');
00158         $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock'));
00159         $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year));
00160         $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $calendar->month, $calendar->year);
00161         $content .= html_writer::end_tag('div');
00162         $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock'));
00163         $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $nextmon, 'y' => $nextyr));
00164         $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $nextmon, $nextyr);
00165         $content .= html_writer::end_tag('div');
00166         return $content;
00167     }
00168 
00175     public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) {
00176         $this->page->blocks->add_fake_block($bc, $pos);
00177     }
00178 
00188     protected function add_event_button($courseid, $day=null, $month=null, $year=null) {
00189         $output = html_writer::start_tag('div', array('class'=>'buttons'));
00190         $output .= html_writer::start_tag('form', array('action'=>CALENDAR_URL.'event.php', 'method'=>'get'));
00191         $output .= html_writer::start_tag('div');
00192         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new'));
00193         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid));
00194         if ($day !== null) {
00195             $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day));
00196         }
00197         if ($month !== null) {
00198             $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month));
00199         }
00200         if ($year !== null) {
00201             $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year));
00202         }
00203         $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar')));
00204         $output .= html_writer::end_tag('div');
00205         $output .= html_writer::end_tag('form');
00206         $output .= html_writer::end_tag('div');
00207         return $output;
00208     }
00209 
00216     public function show_day(calendar_information $calendar, moodle_url $returnurl = null) {
00217 
00218         if ($returnurl === null) {
00219             $returnurl = $this->page->url;
00220         }
00221 
00222         $calendar->checkdate();
00223         $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today());
00224 
00225         $output  = html_writer::start_tag('div', array('class'=>'header'));
00226         if (calendar_user_can_add_event($calendar->course)) {
00227             $output .= $this->add_event_button($calendar->course->id, $calendar->day, $calendar->month, $calendar->year);
00228         }
00229         //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump'));
00230         $output .= $this->course_filter_selector($returnurl, get_string('dayview', 'calendar'));
00231         $output .= html_writer::end_tag('div');
00232         // Controls
00233         $output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'd' => $calendar->day, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls'));
00234 
00235         if (empty($events)) {
00236             // There is nothing to display today.
00237             $output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3);
00238         } else {
00239             $output .= html_writer::start_tag('div', array('class'=>'eventlist'));
00240             $underway = array();
00241             // First, print details about events that start today
00242             foreach ($events as $event) {
00243                 $event = new calendar_event($event);
00244                 $event->calendarcourseid = $calendar->courseid;
00245                 if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) {  // Print it now
00246                     $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
00247                     $output .= $this->event($event);
00248                 } else {                                                                 // Save this for later
00249                     $underway[] = $event;
00250                 }
00251             }
00252 
00253             // Then, show a list of all events that just span this day
00254             if (!empty($underway)) {
00255                 $output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3);
00256                 foreach ($underway as $event) {
00257                     $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
00258                     $output .= $this->event($event);
00259                 }
00260             }
00261 
00262             $output .= html_writer::end_tag('div');
00263         }
00264 
00265         return $output;
00266     }
00267 
00275     public function event(calendar_event $event, $showactions=true) {
00276         $event = calendar_add_event_metadata($event);
00277 
00278         $anchor  = html_writer::tag('a', '', array('name'=>'event_'.$event->id));
00279 
00280         $table = new html_table();
00281         $table->attributes = array('class'=>'event', 'cellspacing'=>'0');
00282         $table->data = array(
00283             0 => new html_table_row(),
00284             1 => new html_table_row(),
00285         );
00286 
00287         if (!empty($event->icon)) {
00288             $table->data[0]->cells[0] = new html_table_cell($anchor.$event->icon);
00289         } else {
00290             $table->data[0]->cells[0] = new html_table_cell($anchor.$this->output->spacer(array('height'=>16, 'width'=>16, 'br'=>true)));
00291         }
00292         $table->data[0]->cells[0]->attributes['class'] .= ' picture';
00293 
00294         $table->data[0]->cells[1] = new html_table_cell();
00295         $table->data[0]->cells[1]->attributes['class'] .= ' topic';
00296         if (!empty($event->referer)) {
00297             $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->referer, array('class'=>'referer'));
00298         } else {
00299             $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->name, array('class'=>'name'));
00300         }
00301         if (!empty($event->courselink)) {
00302             $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->courselink, array('class'=>'course'));
00303         }
00304         if (!empty($event->time)) {
00305             $table->data[0]->cells[1]->text .= html_writer::tag('span', $event->time, array('class'=>'date'));
00306         } else {
00307             $table->data[0]->cells[1]->text .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class'=>'date'));
00308         }
00309 
00310         $table->data[1]->cells[0] = new html_table_cell('&nbsp;');
00311         $table->data[1]->cells[0]->attributes['class'] .= 'side';
00312 
00313         $table->data[1]->cells[1] = new html_table_cell($event->description);
00314         $table->data[1]->cells[1]->attributes['class'] .= ' description';
00315         if (isset($event->cssclass)) {
00316             $table->data[1]->cells[1]->attributes['class'] .= ' '.$event->cssclass;
00317         }
00318 
00319         if (calendar_edit_event_allowed($event) && $showactions) {
00320             if (empty($event->cmid)) {
00321                 $editlink = new moodle_url(CALENDAR_URL.'event.php', array('action'=>'edit', 'id'=>$event->id));
00322                 $deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->id));
00323                 if (!empty($event->calendarcourseid)) {
00324                     $editlink->param('course', $event->calendarcourseid);
00325                     $deletelink->param('course', $event->calendarcourseid);
00326                 }
00327             } else {
00328                 $editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid, 'return'=>true, 'sesskey'=>sesskey()));
00329                 $deletelink = null;
00330             }
00331 
00332             $commands  = html_writer::start_tag('div', array('class'=>'commands'));
00333             $commands .= html_writer::start_tag('a', array('href'=>$editlink));
00334             $commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/edit'), 'alt'=>get_string('tt_editevent', 'calendar'), 'title'=>get_string('tt_editevent', 'calendar')));
00335             $commands .= html_writer::end_tag('a');
00336             if ($deletelink != null) {
00337                 $commands .= html_writer::start_tag('a', array('href'=>$deletelink));
00338                 $commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/delete'), 'alt'=>get_string('tt_deleteevent', 'calendar'), 'title'=>get_string('tt_deleteevent', 'calendar')));
00339                 $commands .= html_writer::end_tag('a');
00340             }
00341             $commands .= html_writer::end_tag('div');
00342             $table->data[1]->cells[1]->text .= $commands;
00343         }
00344         return html_writer::table($table);
00345     }
00346 
00353     public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl  = null) {
00354         global $CFG;
00355 
00356         if (empty($returnurl)) {
00357             $returnurl = $this->page->url;
00358         }
00359 
00360         $date = usergetdate(time());
00361 
00362         $display = new stdClass;
00363         $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
00364         $display->maxwday = $display->minwday + 6;
00365         $display->thismonth = ($date['mon'] == $calendar->month);
00366         $display->maxdays = calendar_days_in_month($calendar->month, $calendar->year);
00367 
00368         $startwday = 0;
00369         if (get_user_timezone_offset() < 99) {
00370             // We 'll keep these values as GMT here, and offset them when the time comes to query the db
00371             $display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT
00372             $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT
00373             $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
00374         } else {
00375             // no timezone info specified
00376             $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year);
00377             $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year);
00378             $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
00379         }
00380 
00381         // Align the starting weekday to fall in our display range
00382         if ($startwday < $display->minwday) {
00383             $startwday += 7;
00384         }
00385 
00386         // Get events from database
00387         $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses);
00388         if (!empty($events)) {
00389             foreach($events as $eventid => $event) {
00390                 $event = new calendar_event($event);
00391                 if (!empty($event->modulename)) {
00392                     $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
00393                     if (!groups_course_module_visible($cm)) {
00394                         unset($events[$eventid]);
00395                     }
00396                 }
00397             }
00398         }
00399 
00400         // Extract information: events vs. time
00401         calendar_events_by_day($events, $calendar->month, $calendar->year, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses);
00402 
00403         $output  = html_writer::start_tag('div', array('class'=>'header'));
00404         if (calendar_user_can_add_event($calendar->course)) {
00405             $output .= $this->add_event_button($calendar->course->id, null, $calendar->month, $calendar->year);
00406         }
00407         $output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector($returnurl);
00408         $output .= html_writer::end_tag('div', array('class'=>'header'));
00409         // Controls
00410         $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls'));
00411 
00412         $days = calendar_get_days();
00413 
00414         $table = new html_table();
00415         $table->attributes = array('class'=>'calendarmonth calendartable');
00416         $table->data = array();
00417 
00418         $header = new html_table_row();
00419         $header->attributes = array('class'=>'weekdays');
00420         $header->cells = array();
00421         for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
00422             // This uses the % operator to get the correct weekday no matter what shift we have
00423             // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
00424             $cell = new html_table_cell(get_string($days[$i % 7], 'calendar'));
00425             $cell->header = true;
00426             $header->cells[] = $cell;
00427         }
00428 
00429         // For the table display. $week is the row; $dayweek is the column.
00430         $week = 1;
00431         $dayweek = $startwday;
00432 
00433         // Create an array of all the week days.
00434         $wdays = array(0 => '<strong>'. get_string('sunday', 'calendar'). '</strong>',
00435                        1 => '<strong>'. get_string('monday', 'calendar'). '</strong>',
00436                        2 => '<strong>'. get_string('tuesday', 'calendar'). '</strong>',
00437                        3 => '<strong>'. get_string('wednesday', 'calendar'). '</strong>',
00438                        4 => '<strong>'. get_string('thursday', 'calendar'). '</strong>',
00439                        5 => '<strong>'. get_string('friday', 'calendar'). '</strong>',
00440                        6 => '<strong>'. get_string('saturday', 'calendar'). '</strong>');
00441 
00442         // Loop only if the day offset is greater than 0.
00443         // This loop involves shifting the days around until the desired start day
00444         // is at the start of the array.
00445         $daycount = 0;
00446         while ($display->minwday > $daycount++) {
00447             $wdays_end = array_shift($wdays);
00448             array_push($wdays, $wdays_end);
00449         }
00450 
00451         // Now we set the (modified) array to the table header to be displayed.
00452         $table->head = $wdays;
00453 
00454         $row = new html_table_row(array());
00455 
00456         // Paddding (the first week may have blank days in the beginning)
00457         for($i = $display->minwday; $i < $startwday; ++$i) {
00458             $cell = new html_table_cell('&nbsp;');
00459             $cell->attributes = array('class'=>'nottoday');
00460             $row->cells[] = $cell;
00461         }
00462 
00463         // Now display all the calendar
00464         $weekend = CALENDAR_DEFAULT_WEEKEND;
00465         if (isset($CFG->calendar_weekend)) {
00466             $weekend = intval($CFG->calendar_weekend);
00467         }
00468 
00469         for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) {
00470             if($dayweek > $display->maxwday) {
00471                 // We need to change week (table row)
00472                 $table->data[] = $row;
00473                 $row = new html_table_row(array());
00474                 $dayweek = $display->minwday;
00475                 ++$week;
00476             }
00477 
00478             // Reset vars
00479             $cell = new html_table_cell();
00480             $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL.'view.php', array('view'=>'day', 'course'=>$calendar->courseid)), $calendar->day, $calendar->month, $calendar->year);
00481 
00482             $cellclasses = array();
00483 
00484             if ($weekend & (1 << ($dayweek % 7))) {
00485                 // Weekend. This is true no matter what the exact range is.
00486                 $cellclasses[] = 'weekend';
00487             }
00488 
00489             // Special visual fx if an event is defined
00490             if (isset($eventsbyday[$calendar->day])) {
00491                 if(count($eventsbyday[$calendar->day]) == 1) {
00492                     $title = get_string('oneevent', 'calendar');
00493                 } else {
00494                     $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day]));
00495                 }
00496                 $cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title'=>$title)), array('class'=>'day'));
00497             } else {
00498                 $cell->text = html_writer::tag('div', $calendar->day, array('class'=>'day'));
00499             }
00500 
00501             // Special visual fx if an event spans many days
00502             $durationclass = false;
00503             if (isset($typesbyday[$calendar->day]['durationglobal'])) {
00504                 $durationclass = 'duration_global';
00505             } else if (isset($typesbyday[$calendar->day]['durationcourse'])) {
00506                 $durationclass = 'duration_course';
00507             } else if (isset($typesbyday[$calendar->day]['durationgroup'])) {
00508                 $durationclass = 'duration_group';
00509             } else if (isset($typesbyday[$calendar->day]['durationuser'])) {
00510                 $durationclass = 'duration_user';
00511             }
00512             if ($durationclass) {
00513                 $cellclasses[] = 'duration';
00514                 $cellclasses[] = $durationclass;
00515             }
00516 
00517             // Special visual fx for today
00518             if($display->thismonth && $calendar->day == $calendar->day) {
00519                 $cellclasses[] = 'today';
00520             } else {
00521                 $cellclasses[] = 'nottoday';
00522             }
00523             $cell->attributes = array('class'=>join(' ',$cellclasses));
00524 
00525             if (isset($eventsbyday[$calendar->day])) {
00526                 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-new'));
00527                 foreach($eventsbyday[$calendar->day] as $eventindex) {
00528                     // If event has a class set then add it to the event <li> tag
00529                     $attributes = array();
00530                     if (!empty($events[$eventindex]->class)) {
00531                         $attributes['class'] = $events[$eventindex]->class;
00532                     }
00533                     $dayhref->set_anchor('event_'.$events[$eventindex]->id);
00534                     $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true));
00535                     $cell->text .= html_writer::tag('li', $link, $attributes);
00536                 }
00537                 $cell->text .= html_writer::end_tag('ul');
00538             }
00539             if (isset($durationbyday[$calendar->day])) {
00540                 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway'));
00541                 foreach($durationbyday[$calendar->day] as $eventindex) {
00542                     $cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway'));
00543                 }
00544                 $cell->text .= html_writer::end_tag('ul');
00545             }
00546             $row->cells[] = $cell;
00547         }
00548 
00549         // Paddding (the last week may have blank days at the end)
00550         for($i = $dayweek; $i <= $display->maxwday; ++$i) {
00551             $cell = new html_table_cell('&nbsp;');
00552             $cell->attributes = array('class'=>'nottoday');
00553             $row->cells[] = $cell;
00554         }
00555         $table->data[] = $row;
00556         $output .= html_writer::table($table);
00557 
00558         // OK, now for the filtering display
00559         $output .= $this->filter_selection_table($calendar);
00560         return $output;
00561     }
00562 
00569     protected function filter_selection_table(calendar_information $calendar, moodle_url $returnurl = null) {
00570         global $SESSION;
00571 
00572         if ($returnurl === null) {
00573             $returnurl = $this->page->url;
00574         }
00575 
00576         $output  = html_writer::start_tag('div', array('class'=>'filters'));
00577         $output .= html_writer::start_tag('table');
00578         $output .= html_writer::start_tag('tr');
00579 
00580         // Global events
00581         $link = new moodle_url(CALENDAR_URL.'set.php', array('var' => 'showglobal', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
00582         if (calendar_show_event_type(CALENDAR_EVENT_GLOBAL)) {
00583             $output .= html_writer::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;'));
00584             $output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
00585         } else {
00586             $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
00587             $output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
00588         }
00589 
00590         // Course events
00591         $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showcourses', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
00592         if (calendar_show_event_type(CALENDAR_EVENT_COURSE)) {
00593             $output .= html_writer::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;'));
00594             $output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
00595         } else {
00596             $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
00597             $output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
00598         }
00599         $output .= html_writer::end_tag('tr');
00600 
00601         if(isloggedin() && !isguestuser()) {
00602             $output .= html_writer::start_tag('tr');
00603             // Group events
00604             $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showgroups', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
00605             if (calendar_show_event_type(CALENDAR_EVENT_GROUP)) {
00606                 $output .= html_writer::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;'));
00607                 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
00608             } else {
00609                 $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
00610                 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
00611             }
00612             // User events
00613             $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showuser', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
00614             if (calendar_show_event_type(CALENDAR_EVENT_USER)) {
00615                 $output .= html_writer::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;'));
00616                 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
00617             } else {
00618                 $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
00619                 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
00620             }
00621             $output .= html_writer::end_tag('tr');
00622         }
00623         $output .= html_writer::end_tag('table');
00624         $output .= html_writer::end_tag('div');
00625         return $output;
00626     }
00627 
00636     public function show_upcoming_events(calendar_information $calendar, $futuredays, $maxevents, moodle_url $returnurl = null) {
00637 
00638         if ($returnurl === null) {
00639             $returnurl = $this->page->url;
00640         }
00641 
00642         $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, $futuredays, $maxevents);
00643 
00644         $output  = html_writer::start_tag('div', array('class'=>'header'));
00645         if (calendar_user_can_add_event($calendar->course)) {
00646             $output .= $this->add_event_button($calendar->course->id);
00647         }
00648         $output .= html_writer::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump'));
00649         $output .= $this->course_filter_selector($returnurl);
00650         $output .= html_writer::end_tag('div');
00651 
00652         if ($events) {
00653             $output .= html_writer::start_tag('div', array('class'=>'eventlist'));
00654             foreach ($events as $event) {
00655                 // Convert to calendar_event object so that we transform description
00656                 // accordingly
00657                 $event = new calendar_event($event);
00658                 $event->calendarcourseid = $calendar->courseid;
00659                 $output .= $this->event($event);
00660             }
00661             $output .= html_writer::end_tag('div');
00662         } else {
00663             $output .= $this->output->heading(get_string('noupcomingevents', 'calendar'));
00664         }
00665 
00666         return $output;
00667     }
00668 
00675     protected function course_filter_selector(moodle_url $returnurl, $label=null) {
00676         global $USER, $SESSION, $CFG;
00677 
00678         if (!isloggedin() or isguestuser()) {
00679             return '';
00680         }
00681 
00682         if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
00683             $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
00684         } else {
00685             $courses = enrol_get_my_courses();
00686         }
00687 
00688         unset($courses[SITEID]);
00689 
00690         $courseoptions = array();
00691         $courseoptions[SITEID] = get_string('fulllistofcourses');
00692         foreach ($courses as $course) {
00693             $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00694             $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext));
00695         }
00696 
00697         if ($this->page->course->id !== SITEID) {
00698             $selected = $this->page->course->id;
00699         } else {
00700             $selected = '';
00701         }
00702         $select = new single_select(new moodle_url(CALENDAR_URL.'set.php', array('return' => base64_encode($returnurl->out(false)), 'var' => 'setcourse', 'sesskey'=>sesskey())), 'id', $courseoptions, $selected, null);
00703         $select->class = 'cal_courses_flt';
00704         if ($label !== null) {
00705             $select->label = $label;
00706         }
00707         return $this->output->render($select);
00708     }
00709 }
 All Data Structures Namespaces Files Functions Variables Enumerations