3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * This file contains the renderers for the calendar within Moodle
21 * @copyright 2010 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 * The primary renderer for the calendar.
29 class core_calendar_renderer
extends plugin_renderer_base
{
32 * Creates a basic export form
34 * @param bool $allowthisweek
35 * @param bool $allownextweek
36 * @param bool $allownextmonth
38 * @param string $authtoken
41 public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $userid, $authtoken) {
43 $output = html_writer
::tag('div', get_string('export', 'calendar'), array('class'=>'header'));
44 $output .= html_writer
::start_tag('fieldset');
45 $output .= html_writer
::tag('legend', get_string('commontasks', 'calendar'));
46 $output .= html_writer
::start_tag('form', array('action'=>new moodle_url('/calendar/export_execute.php'), 'method'=>'get'));
48 $output .= html_writer
::tag('div', get_string('iwanttoexport', 'calendar'));
50 $output .= html_writer
::start_tag('div', array('class'=>'indent'));
51 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_all', 'value'=>'all', 'checked'=>'checked'));
52 $output .= html_writer
::tag('label', get_string('eventsall', 'calendar'), array('for'=>'pw_all'));
53 $output .= html_writer
::empty_tag('br');
54 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_course', 'value'=>'courses'));
55 $output .= html_writer
::tag('label', get_string('eventsrelatedtocourses', 'calendar'), array('for'=>'pw_course'));
56 $output .= html_writer
::empty_tag('br');
57 $output .= html_writer
::end_tag('div');
59 $output .= html_writer
::tag('div', get_string('for', 'calendar').':');
61 $output .= html_writer
::start_tag('div', array('class'=>'indent'));
63 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknow', 'value'=>'weeknow', 'checked'=>'checked'));
64 $output .= html_writer
::tag('label', get_string('weekthis', 'calendar'), array('for'=>'pt_wknow'));
65 $output .= html_writer
::empty_tag('br');
68 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknext', 'value'=>'weeknext'));
69 $output .= html_writer
::tag('label', get_string('weeknext', 'calendar'), array('for'=>'pt_wknext'));
70 $output .= html_writer
::empty_tag('br');
72 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnow', 'value'=>'monthnow'));
73 $output .= html_writer
::tag('label', get_string('monththis', 'calendar'), array('for'=>'pt_monnow'));
74 $output .= html_writer
::empty_tag('br');
75 if ($allownextmonth) {
76 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnext', 'value'=>'monthnext'));
77 $output .= html_writer
::tag('label', get_string('monthnext', 'calendar'), array('for'=>'pt_monnext'));
78 $output .= html_writer
::empty_tag('br');
80 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_recupc', 'value'=>'recentupcoming'));
81 $output .= html_writer
::tag('label', get_string('recentupcoming', 'calendar'), array('for'=>'pt_recupc'));
82 $output .= html_writer
::empty_tag('br');
83 $output .= html_writer
::end_tag('div');
85 $output .= html_writer
::start_tag('div', array('class'=>'rightalign'));
86 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>''));
87 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>''));
88 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>''));
89 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'userid', 'value'=>$userid));
90 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken));
92 $output .= html_writer
::empty_tag('input', array('type'=>'submit', 'name' => 'generateurl', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
93 $output .= html_writer
::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar')));
95 $output .= html_writer
::end_tag('div');
97 $output .= html_writer
::end_tag('form');
98 $output .= html_writer
::end_tag('fieldset');
100 $output .= html_writer
::start_tag('div', array('id'=>'urlbox', 'style'=>'display:none;'));
101 $output .= html_writer
::tag('p', get_string('urlforical', 'calendar'));
102 $output .= html_writer
::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;'));
103 $output .= html_writer
::end_tag('div');
109 * Starts the standard layout for the page
113 public function start_layout() {
114 return html_writer
::start_tag('div', array('class'=>'maincalendar'));
118 * Creates the remainder of the layout
122 public function complete_layout() {
123 return html_writer
::end_tag('div');
127 * Produces the content for the filters block (pretend block)
129 * @param int $courseid
134 * @param int $courses
137 public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) {
138 $returnurl = $this->page
->url
;
139 $returnurl->param('course', $courseid);
140 return html_writer
::tag('div', calendar_filter_controls($returnurl), array('class'=>'calendar_filters filters'));
144 * Produces the content for the three months block (pretend block)
146 * This includes the previous month, the current month, and the next month
148 * @param calendar_information $calendar
151 public function fake_block_threemonths(calendar_information
$calendar) {
153 list($prevmon, $prevyr) = calendar_sub_month($calendar->month
, $calendar->year
);
154 list($nextmon, $nextyr) = calendar_add_month($calendar->month
, $calendar->year
);
156 $content = html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
157 $content .= calendar_top_controls('display', array('id' => $calendar->courseid
, 'm' => $prevmon, 'y' => $prevyr));
158 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $prevmon, $prevyr);
159 $content .= html_writer
::end_tag('div');
160 $content .= html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
161 $content .= calendar_top_controls('display', array('id' => $calendar->courseid
, 'm' => $calendar->month
, 'y' => $calendar->year
));
162 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $calendar->month
, $calendar->year
);
163 $content .= html_writer
::end_tag('div');
164 $content .= html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
165 $content .= calendar_top_controls('display', array('id' => $calendar->courseid
, 'm' => $nextmon, 'y' => $nextyr));
166 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $nextmon, $nextyr);
167 $content .= html_writer
::end_tag('div');
172 * Adds a pretent calendar block
174 * @param block_contents $bc
175 * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
177 public function add_pretend_calendar_block(block_contents
$bc, $pos=BLOCK_POS_RIGHT
) {
178 $this->page
->blocks
->add_fake_block($bc, $pos);
182 * Creates a button to add a new event
184 * @param int $courseid
190 protected function add_event_button($courseid, $day=null, $month=null, $year=null) {
191 $output = html_writer
::start_tag('div', array('class'=>'buttons'));
192 $output .= html_writer
::start_tag('form', array('action'=>CALENDAR_URL
.'event.php', 'method'=>'get'));
193 $output .= html_writer
::start_tag('div');
194 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new'));
195 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid));
197 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day));
199 if ($month !== null) {
200 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month));
202 if ($year !== null) {
203 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year));
205 $output .= html_writer
::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar')));
206 $output .= html_writer
::end_tag('div');
207 $output .= html_writer
::end_tag('form');
208 $output .= html_writer
::end_tag('div');
213 * Displays the calendar for a single day
215 * @param calendar_information $calendar
218 public function show_day(calendar_information
$calendar, moodle_url
$returnurl = null) {
220 if ($returnurl === null) {
221 $returnurl = $this->page
->url
;
224 $calendar->checkdate();
225 $events = calendar_get_upcoming($calendar->courses
, $calendar->groups
, $calendar->users
, 1, 100, $calendar->timestamp_today());
227 $output = html_writer
::start_tag('div', array('class'=>'header'));
228 if (calendar_user_can_add_event($calendar->course
)) {
229 $output .= $this->add_event_button($calendar->course
->id
, $calendar->day
, $calendar->month
, $calendar->year
);
231 //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump'));
232 $output .= $this->course_filter_selector($returnurl, get_string('dayview', 'calendar'));
233 $output .= html_writer
::end_tag('div');
235 $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'));
237 if (empty($events)) {
238 // There is nothing to display today.
239 $output .= $this->output
->heading(get_string('daywithnoevents', 'calendar'), 3);
241 $output .= html_writer
::start_tag('div', array('class'=>'eventlist'));
243 // First, print details about events that start today
244 foreach ($events as $event) {
245 $event = new calendar_event($event);
246 $event->calendarcourseid
= $calendar->courseid
;
247 if ($event->timestart
>= $calendar->timestamp_today() && $event->timestart
<= $calendar->timestamp_tomorrow()-1) { // Print it now
248 $event->time
= calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
249 $output .= $this->event($event);
250 } else { // Save this for later
251 $underway[] = $event;
255 // Then, show a list of all events that just span this day
256 if (!empty($underway)) {
257 $output .= $this->output
->heading(get_string('spanningevents', 'calendar'), 3);
258 foreach ($underway as $event) {
259 $event->time
= calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
260 $output .= $this->event($event);
264 $output .= html_writer
::end_tag('div');
273 * @param calendar_event $event
274 * @param bool $showactions
277 public function event(calendar_event
$event, $showactions=true) {
278 $event = calendar_add_event_metadata($event);
280 $anchor = html_writer
::tag('a', '', array('name'=>'event_'.$event->id
));
282 $table = new html_table();
283 $table->attributes
= array('class'=>'event', 'cellspacing'=>'0');
284 $table->data
= array(
285 0 => new html_table_row(),
286 1 => new html_table_row(),
289 if (!empty($event->icon
)) {
290 $table->data
[0]->cells
[0] = new html_table_cell($anchor.$event->icon
);
292 $table->data
[0]->cells
[0] = new html_table_cell($anchor.$this->output
->spacer(array('height'=>16, 'width'=>16, 'br'=>true)));
294 $table->data
[0]->cells
[0]->attributes
['class'] .= ' picture';
296 $table->data
[0]->cells
[1] = new html_table_cell();
297 $table->data
[0]->cells
[1]->attributes
['class'] .= ' topic';
298 if (!empty($event->referer
)) {
299 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->referer
, array('class'=>'referer'));
301 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->name
, array('class'=>'name'));
303 if (!empty($event->courselink
)) {
304 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->courselink
, array('class'=>'course'));
306 if (!empty($event->time
)) {
307 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('span', $event->time
, array('class'=>'date'));
309 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('span', calendar_time_representation($event->timestart
), array('class'=>'date'));
312 $table->data
[1]->cells
[0] = new html_table_cell(' ');
313 $table->data
[1]->cells
[0]->attributes
['class'] .= 'side';
315 $table->data
[1]->cells
[1] = new html_table_cell($event->description
);
316 $table->data
[1]->cells
[1]->attributes
['class'] .= ' description';
317 if (isset($event->cssclass
)) {
318 $table->data
[1]->cells
[1]->attributes
['class'] .= ' '.$event->cssclass
;
321 if (calendar_edit_event_allowed($event) && $showactions) {
322 if (empty($event->cmid
)) {
323 $editlink = new moodle_url(CALENDAR_URL
.'event.php', array('action'=>'edit', 'id'=>$event->id
));
324 $deletelink = new moodle_url(CALENDAR_URL
.'delete.php', array('id'=>$event->id
));
325 if (!empty($event->calendarcourseid
)) {
326 $editlink->param('course', $event->calendarcourseid
);
327 $deletelink->param('course', $event->calendarcourseid
);
330 $editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid
, 'return'=>true, 'sesskey'=>sesskey()));
334 $commands = html_writer
::start_tag('div', array('class'=>'commands'));
335 $commands .= html_writer
::start_tag('a', array('href'=>$editlink));
336 $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')));
337 $commands .= html_writer
::end_tag('a');
338 if ($deletelink != null) {
339 $commands .= html_writer
::start_tag('a', array('href'=>$deletelink));
340 $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')));
341 $commands .= html_writer
::end_tag('a');
343 $commands .= html_writer
::end_tag('div');
344 $table->data
[1]->cells
[1]->text
.= $commands;
346 return html_writer
::table($table);
350 * Displays a month in detail
352 * @param calendar_information $calendar
355 public function show_month_detailed(calendar_information
$calendar, moodle_url
$returnurl = null) {
358 if (empty($returnurl)) {
359 $returnurl = $this->page
->url
;
362 $date = usergetdate(time());
364 $display = new stdClass
;
365 $display->minwday
= get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
366 $display->maxwday
= $display->minwday +
6;
367 $display->thismonth
= ($date['mon'] == $calendar->month
);
368 $display->maxdays
= calendar_days_in_month($calendar->month
, $calendar->year
);
371 if (get_user_timezone_offset() < 99) {
372 // We 'll keep these values as GMT here, and offset them when the time comes to query the db
373 $display->tstart
= gmmktime(0, 0, 0, $calendar->month
, 1, $calendar->year
); // This is GMT
374 $display->tend
= gmmktime(23, 59, 59, $calendar->month
, $display->maxdays
, $calendar->year
); // GMT
375 $startwday = gmdate('w', $display->tstart
); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
377 // no timezone info specified
378 $display->tstart
= mktime(0, 0, 0, $calendar->month
, 1, $calendar->year
);
379 $display->tend
= mktime(23, 59, 59, $calendar->month
, $display->maxdays
, $calendar->year
);
380 $startwday = date('w', $display->tstart
); // $display->tstart not necessarily GMT, so use date()
383 // Align the starting weekday to fall in our display range
384 if ($startwday < $display->minwday
) {
388 // Get events from database
389 $events = calendar_get_events(usertime($display->tstart
), usertime($display->tend
), $calendar->users
, $calendar->groups
, $calendar->courses
);
390 if (!empty($events)) {
391 foreach($events as $eventid => $event) {
392 $event = new calendar_event($event);
393 if (!empty($event->modulename
)) {
394 $cm = get_coursemodule_from_instance($event->modulename
, $event->instance
);
395 if (!groups_course_module_visible($cm)) {
396 unset($events[$eventid]);
402 // Extract information: events vs. time
403 calendar_events_by_day($events, $calendar->month
, $calendar->year
, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses
);
405 $output = html_writer
::start_tag('div', array('class'=>'header'));
406 if (calendar_user_can_add_event($calendar->course
)) {
407 $output .= $this->add_event_button($calendar->course
->id
, null, $calendar->month
, $calendar->year
);
409 $output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector($returnurl);
410 $output .= html_writer
::end_tag('div', array('class'=>'header'));
412 $output .= html_writer
::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid
, 'm' => $calendar->month
, 'y' => $calendar->year
)), array('class'=>'controls'));
414 $days = calendar_get_days();
416 $table = new html_table();
417 $table->attributes
= array('class'=>'calendarmonth calendartable');
418 $time = make_timestamp($calendar->year
, $calendar->month
);
419 $table->summary
= get_string('calendarheading', 'calendar', userdate($time, get_string('strftimemonthyear')));
420 $table->data
= array();
422 $header = new html_table_row();
423 $header->attributes
= array('class'=>'weekdays');
424 $header->cells
= array();
425 for($i = $display->minwday
; $i <= $display->maxwday
; ++
$i) {
426 // This uses the % operator to get the correct weekday no matter what shift we have
427 // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
428 $cell = new html_table_cell(get_string($days[$i %
7], 'calendar'));
429 $cell->header
= true;
430 $header->cells
[] = $cell;
433 // For the table display. $week is the row; $dayweek is the column.
435 $dayweek = $startwday;
437 // Create an array of all the week days.
438 $wdays = array(0 => '<strong>'. get_string('sunday', 'calendar'). '</strong>',
439 1 => '<strong>'. get_string('monday', 'calendar'). '</strong>',
440 2 => '<strong>'. get_string('tuesday', 'calendar'). '</strong>',
441 3 => '<strong>'. get_string('wednesday', 'calendar'). '</strong>',
442 4 => '<strong>'. get_string('thursday', 'calendar'). '</strong>',
443 5 => '<strong>'. get_string('friday', 'calendar'). '</strong>',
444 6 => '<strong>'. get_string('saturday', 'calendar'). '</strong>');
446 // Loop only if the day offset is greater than 0.
447 // This loop involves shifting the days around until the desired start day
448 // is at the start of the array.
450 while ($display->minwday
> $daycount++
) {
451 $wdays_end = array_shift($wdays);
452 array_push($wdays, $wdays_end);
455 // Now we set the (modified) array to the table header to be displayed.
456 $table->head
= $wdays;
458 $row = new html_table_row(array());
460 // Paddding (the first week may have blank days in the beginning)
461 for($i = $display->minwday
; $i < $startwday; ++
$i) {
462 $cell = new html_table_cell(' ');
463 $cell->attributes
= array('class'=>'nottoday');
464 $row->cells
[] = $cell;
467 // Now display all the calendar
468 $weekend = CALENDAR_DEFAULT_WEEKEND
;
469 if (isset($CFG->calendar_weekend
)) {
470 $weekend = intval($CFG->calendar_weekend
);
473 for ($calendar->day
= 1; $calendar->day
<= $display->maxdays
; ++
$calendar->day
, ++
$dayweek) {
474 if($dayweek > $display->maxwday
) {
475 // We need to change week (table row)
476 $table->data
[] = $row;
477 $row = new html_table_row(array());
478 $dayweek = $display->minwday
;
483 $cell = new html_table_cell();
484 $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL
.'view.php', array('view'=>'day', 'course'=>$calendar->courseid
)), $calendar->day
, $calendar->month
, $calendar->year
);
486 $cellclasses = array();
488 if ($weekend & (1 << ($dayweek %
7))) {
489 // Weekend. This is true no matter what the exact range is.
490 $cellclasses[] = 'weekend';
493 // Special visual fx if an event is defined
494 if (isset($eventsbyday[$calendar->day
])) {
495 if(count($eventsbyday[$calendar->day
]) == 1) {
496 $title = get_string('oneevent', 'calendar');
498 $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day
]));
500 $cell->text
= html_writer
::tag('div', html_writer
::link($dayhref, $calendar->day
, array('title'=>$title)), array('class'=>'day'));
502 $cell->text
= html_writer
::tag('div', $calendar->day
, array('class'=>'day'));
505 // Special visual fx if an event spans many days
506 $durationclass = false;
507 if (isset($typesbyday[$calendar->day
]['durationglobal'])) {
508 $durationclass = 'duration_global';
509 } else if (isset($typesbyday[$calendar->day
]['durationcourse'])) {
510 $durationclass = 'duration_course';
511 } else if (isset($typesbyday[$calendar->day
]['durationgroup'])) {
512 $durationclass = 'duration_group';
513 } else if (isset($typesbyday[$calendar->day
]['durationuser'])) {
514 $durationclass = 'duration_user';
516 if ($durationclass) {
517 $cellclasses[] = 'duration';
518 $cellclasses[] = $durationclass;
521 // Special visual fx for today
522 if($display->thismonth
&& $calendar->day
== $calendar->day
) {
523 $cellclasses[] = 'today';
525 $cellclasses[] = 'nottoday';
527 $cell->attributes
= array('class'=>join(' ',$cellclasses));
529 if (isset($eventsbyday[$calendar->day
])) {
530 $cell->text
.= html_writer
::start_tag('ul', array('class'=>'events-new'));
531 foreach($eventsbyday[$calendar->day
] as $eventindex) {
532 // If event has a class set then add it to the event <li> tag
533 $attributes = array();
534 if (!empty($events[$eventindex]->class)) {
535 $attributes['class'] = $events[$eventindex]->class;
537 $dayhref->set_anchor('event_'.$events[$eventindex]->id
);
538 $link = html_writer
::link($dayhref, format_string($events[$eventindex]->name
, true));
539 $cell->text
.= html_writer
::tag('li', $link, $attributes);
541 $cell->text
.= html_writer
::end_tag('ul');
543 if (isset($durationbyday[$calendar->day
])) {
544 $cell->text
.= html_writer
::start_tag('ul', array('class'=>'events-underway'));
545 foreach($durationbyday[$calendar->day
] as $eventindex) {
546 $cell->text
.= html_writer
::tag('li', '['.format_string($events[$eventindex]->name
,true).']', array('class'=>'events-underway'));
548 $cell->text
.= html_writer
::end_tag('ul');
550 $row->cells
[] = $cell;
553 // Paddding (the last week may have blank days at the end)
554 for($i = $dayweek; $i <= $display->maxwday
; ++
$i) {
555 $cell = new html_table_cell(' ');
556 $cell->attributes
= array('class'=>'nottoday');
557 $row->cells
[] = $cell;
559 $table->data
[] = $row;
560 $output .= html_writer
::table($table);
562 // OK, now for the filtering display
563 $output .= $this->filter_selection_table($calendar);
568 * Displays a filter selection table
570 * @param calendar_information $calendar
573 protected function filter_selection_table(calendar_information
$calendar, moodle_url
$returnurl = null) {
576 if ($returnurl === null) {
577 $returnurl = $this->page
->url
;
580 $output = html_writer
::start_tag('div', array('class'=>'filters'));
581 $output .= html_writer
::start_tag('table');
582 $output .= html_writer
::start_tag('tr');
585 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var' => 'showglobal', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
586 $strglobalevents = get_string('globalevents', 'calendar');
587 if (calendar_show_event_type(CALENDAR_EVENT_GLOBAL
)) {
588 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;'));
589 $output .= html_writer
::tag('td', html_writer
::tag('strong', $strglobalevents).' '.get_string('shown', 'calendar').' ('.html_writer
::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$strglobalevents.'</span>').')');
591 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
592 $output .= html_writer
::tag('td', html_writer
::tag('strong', $strglobalevents).' '.get_string('hidden', 'calendar').' ('.html_writer
::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$strglobalevents.'</span>').')');
596 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showcourses', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
597 $strcourseevents = get_string('courseevents', 'calendar');
598 if (calendar_show_event_type(CALENDAR_EVENT_COURSE
)) {
599 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;'));
600 $output .= html_writer
::tag('td', html_writer
::tag('strong', $strcourseevents).' '.get_string('shown', 'calendar').' ('.html_writer
::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$strcourseevents.'</span>').')');
602 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
603 $output .= html_writer
::tag('td', html_writer
::tag('strong', $strcourseevents).' '.get_string('hidden', 'calendar').' ('.html_writer
::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$strcourseevents.'</span>').')');
605 $output .= html_writer
::end_tag('tr');
607 if(isloggedin() && !isguestuser()) {
608 $output .= html_writer
::start_tag('tr');
610 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showgroups', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
611 $strgroupevents = get_string('groupevents', 'calendar');
612 if (calendar_show_event_type(CALENDAR_EVENT_GROUP
)) {
613 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;'));
614 $output .= html_writer
::tag('td', html_writer
::tag('strong', $strgroupevents).' '.get_string('shown', 'calendar').' ('.html_writer
::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$strgroupevents.'</span>').')');
616 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
617 $output .= html_writer
::tag('td', html_writer
::tag('strong', $strgroupevents).' '.get_string('hidden', 'calendar').' ('.html_writer
::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$strgroupevents.'</span>').')');
620 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showuser', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
621 $struserevents = get_string('userevents', 'calendar');
622 if (calendar_show_event_type(CALENDAR_EVENT_USER
)) {
623 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;'));
624 $output .= html_writer
::tag('td', html_writer
::tag('strong', $struserevents).' '.get_string('shown', 'calendar').' ('.html_writer
::link($link, get_string('clickhide', 'calendar').'<span class="accesshide">'.$struserevents.'</span>').')');
626 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
627 $output .= html_writer
::tag('td', html_writer
::tag('strong', $struserevents).' '.get_string('hidden', 'calendar').' ('.html_writer
::link($link, get_string('clickshow', 'calendar').'<span class="accesshide">'.$struserevents.'</span>').')');
629 $output .= html_writer
::end_tag('tr');
631 $output .= html_writer
::end_tag('table');
632 $output .= html_writer
::end_tag('div');
637 * Displays upcoming events
639 * @param calendar_information $calendar
640 * @param int $futuredays
641 * @param int $maxevents
644 public function show_upcoming_events(calendar_information
$calendar, $futuredays, $maxevents, moodle_url
$returnurl = null) {
646 if ($returnurl === null) {
647 $returnurl = $this->page
->url
;
650 $events = calendar_get_upcoming($calendar->courses
, $calendar->groups
, $calendar->users
, $futuredays, $maxevents);
652 $output = html_writer
::start_tag('div', array('class'=>'header'));
653 if (calendar_user_can_add_event($calendar->course
)) {
654 $output .= $this->add_event_button($calendar->course
->id
);
656 $output .= html_writer
::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump'));
657 $output .= $this->course_filter_selector($returnurl);
658 $output .= html_writer
::end_tag('div');
661 $output .= html_writer
::start_tag('div', array('class'=>'eventlist'));
662 foreach ($events as $event) {
663 // Convert to calendar_event object so that we transform description
665 $event = new calendar_event($event);
666 $event->calendarcourseid
= $calendar->courseid
;
667 $output .= $this->event($event);
669 $output .= html_writer
::end_tag('div');
671 $output .= $this->output
->heading(get_string('noupcomingevents', 'calendar'));
678 * Displays a course filter selector
680 * @param array $getvars
683 protected function course_filter_selector(moodle_url
$returnurl, $label=null) {
684 global $USER, $SESSION, $CFG;
686 if (!isloggedin() or isguestuser()) {
690 if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM
)) && !empty($CFG->calendar_adminseesall
)) {
691 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
693 $courses = enrol_get_my_courses();
696 unset($courses[SITEID
]);
698 $courseoptions = array();
699 $courseoptions[SITEID
] = get_string('fulllistofcourses');
700 foreach ($courses as $course) {
701 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
702 $courseoptions[$course->id
] = format_string($course->shortname
, true, array('context' => $coursecontext));
705 if ($this->page
->course
->id
!== SITEID
) {
706 $selected = $this->page
->course
->id
;
710 $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);
711 $select->class = 'cal_courses_flt';
712 if ($label !== null) {
713 $select->label
= $label;
715 return $this->output
->render($select);