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
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
31 * The primary renderer for the calendar.
33 class core_calendar_renderer
extends plugin_renderer_base
{
36 * Creates a basic export form
38 * @param bool $allowthisweek
39 * @param bool $allownextweek
40 * @param bool $allownextmonth
42 * @param string $authtoken
45 public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $userid, $authtoken) {
48 $output = html_writer
::tag('div', get_string('export', 'calendar'), array('class'=>'header'));
49 $output .= html_writer
::start_tag('fieldset');
50 $output .= html_writer
::tag('legend', get_string('commontasks', 'calendar'));
51 $output .= html_writer
::start_tag('form', array('action'=>new moodle_url('/calendar/export_execute.php'), 'method'=>'get'));
53 $output .= html_writer
::tag('div', get_string('iwanttoexport', 'calendar'));
55 $output .= html_writer
::start_tag('div', array('class'=>'indent'));
56 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_all', 'value'=>'all', 'checked'=>'checked'));
57 $output .= html_writer
::tag('label', get_string('eventsall', 'calendar'), array('for'=>'pw_all'));
58 $output .= html_writer
::empty_tag('br');
59 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_course', 'value'=>'courses'));
60 $output .= html_writer
::tag('label', get_string('eventsrelatedtocourses', 'calendar'), array('for'=>'pw_course'));
61 $output .= html_writer
::empty_tag('br');
62 $output .= html_writer
::end_tag('div');
64 $output .= html_writer
::tag('div', get_string('for', 'calendar').':');
66 $output .= html_writer
::start_tag('div', array('class'=>'indent'));
68 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknow', 'value'=>'weeknow', 'checked'=>'checked'));
69 $output .= html_writer
::tag('label', get_string('weekthis', 'calendar'), array('for'=>'pt_wknow'));
70 $output .= html_writer
::empty_tag('br');
73 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknext', 'value'=>'weeknext'));
74 $output .= html_writer
::tag('label', get_string('weeknext', 'calendar'), array('for'=>'pt_wknext'));
75 $output .= html_writer
::empty_tag('br');
77 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnow', 'value'=>'monthnow'));
78 $output .= html_writer
::tag('label', get_string('monththis', 'calendar'), array('for'=>'pt_monnow'));
79 $output .= html_writer
::empty_tag('br');
80 if ($allownextmonth) {
81 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnext', 'value'=>'monthnext'));
82 $output .= html_writer
::tag('label', get_string('monthnext', 'calendar'), array('for'=>'pt_monnext'));
83 $output .= html_writer
::empty_tag('br');
85 $output .= html_writer
::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_recupc', 'value'=>'recentupcoming'));
86 $output .= html_writer
::tag('label', get_string('recentupcoming', 'calendar'), array('for'=>'pt_recupc'));
87 $output .= html_writer
::empty_tag('br');
89 if ($CFG->calendar_customexport
) {
92 $time = $now - $CFG->calendar_exportlookback
* DAYSECS
;
93 $a->timestart
= userdate($time, get_string('strftimedatefullshort', 'langconfig'));
94 $time = $now +
$CFG->calendar_exportlookahead
* DAYSECS
;
95 $a->timeend
= userdate($time, get_string('strftimedatefullshort', 'langconfig'));
96 $output .= html_writer
::empty_tag('input', array('type' => 'radio', 'name' => 'preset_time', 'id' => 'pt_custom', 'value' => 'custom'));
97 $output .= html_writer
::tag('label', get_string('customexport', 'calendar', $a), array('for' => 'pt_custom'));
98 $output .= html_writer
::empty_tag('br');
101 $output .= html_writer
::end_tag('div');
102 $output .= html_writer
::start_tag('div', array('class'=>'rightalign'));
103 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>''));
104 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>''));
105 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>''));
106 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'userid', 'value'=>$userid));
107 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken));
109 $output .= html_writer
::empty_tag('input', array('type'=>'submit', 'name' => 'generateurl', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
110 $output .= html_writer
::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar')));
112 $output .= html_writer
::end_tag('div');
114 $output .= html_writer
::end_tag('form');
115 $output .= html_writer
::end_tag('fieldset');
117 $output .= html_writer
::start_tag('div', array('id'=>'urlbox', 'style'=>'display:none;'));
118 $output .= html_writer
::tag('p', get_string('urlforical', 'calendar'));
119 $output .= html_writer
::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;'));
120 $output .= html_writer
::end_tag('div');
126 * Starts the standard layout for the page
130 public function start_layout() {
131 return html_writer
::start_tag('div', array('class'=>'maincalendar'));
135 * Creates the remainder of the layout
139 public function complete_layout() {
140 return html_writer
::end_tag('div');
144 * Produces the content for the filters block (pretend block)
146 * @param int $courseid
151 * @param int $courses
154 public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) {
155 $returnurl = $this->page
->url
;
156 $returnurl->param('course', $courseid);
157 return html_writer
::tag('div', calendar_filter_controls($returnurl), array('class'=>'calendar_filters filters'));
161 * Produces the content for the three months block (pretend block)
163 * This includes the previous month, the current month, and the next month
165 * @param calendar_information $calendar
168 public function fake_block_threemonths(calendar_information
$calendar) {
170 list($prevmon, $prevyr) = calendar_sub_month($calendar->month
, $calendar->year
);
171 list($nextmon, $nextyr) = calendar_add_month($calendar->month
, $calendar->year
);
173 $content = html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
174 $content .= calendar_get_mini( $calendar->courses
, $calendar->groups
, $calendar->users
, $prevmon, $prevyr, 'display', $calendar->courseid
);
175 $content .= html_writer
::end_tag('div');
176 $content .= html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
177 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $calendar->month
, $calendar->year
, 'display', $calendar->courseid
);
178 $content .= html_writer
::end_tag('div');
179 $content .= html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
180 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $nextmon, $nextyr, 'display', $calendar->courseid
);
181 $content .= html_writer
::end_tag('div');
186 * Adds a pretent calendar block
188 * @param block_contents $bc
189 * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
191 public function add_pretend_calendar_block(block_contents
$bc, $pos=BLOCK_POS_RIGHT
) {
192 $this->page
->blocks
->add_fake_block($bc, $pos);
196 * Creates a button to add a new event
198 * @param int $courseid
204 protected function add_event_button($courseid, $day=null, $month=null, $year=null) {
205 $output = html_writer
::start_tag('div', array('class'=>'buttons'));
206 $output .= html_writer
::start_tag('form', array('action'=>CALENDAR_URL
.'event.php', 'method'=>'get'));
207 $output .= html_writer
::start_tag('div');
208 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new'));
209 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid));
211 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day));
213 if ($month !== null) {
214 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month));
216 if ($year !== null) {
217 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year));
219 $output .= html_writer
::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar')));
220 $output .= html_writer
::end_tag('div');
221 $output .= html_writer
::end_tag('form');
222 $output .= html_writer
::end_tag('div');
227 * Displays the calendar for a single day
229 * @param calendar_information $calendar
232 public function show_day(calendar_information
$calendar, moodle_url
$returnurl = null) {
234 if ($returnurl === null) {
235 $returnurl = $this->page
->url
;
238 $calendar->checkdate();
239 $events = calendar_get_upcoming($calendar->courses
, $calendar->groups
, $calendar->users
, 1, 100, $calendar->timestamp_today());
241 $output = html_writer
::start_tag('div', array('class'=>'header'));
242 if (calendar_user_can_add_event($calendar->course
)) {
243 $output .= $this->add_event_button($calendar->course
->id
, $calendar->day
, $calendar->month
, $calendar->year
);
245 //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump'));
246 $output .= $this->course_filter_selector($returnurl, get_string('dayview', 'calendar'));
247 $output .= html_writer
::end_tag('div');
249 $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'));
251 if (empty($events)) {
252 // There is nothing to display today.
253 $output .= $this->output
->heading(get_string('daywithnoevents', 'calendar'), 3);
255 $output .= html_writer
::start_tag('div', array('class'=>'eventlist'));
257 // First, print details about events that start today
258 foreach ($events as $event) {
259 $event = new calendar_event($event);
260 $event->calendarcourseid
= $calendar->courseid
;
261 if ($event->timestart
>= $calendar->timestamp_today() && $event->timestart
<= $calendar->timestamp_tomorrow()-1) { // Print it now
262 $event->time
= calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
263 $output .= $this->event($event);
264 } else { // Save this for later
265 $underway[] = $event;
269 // Then, show a list of all events that just span this day
270 if (!empty($underway)) {
271 $output .= $this->output
->heading(get_string('spanningevents', 'calendar'), 3);
272 foreach ($underway as $event) {
273 $event->time
= calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
274 $output .= $this->event($event);
278 $output .= html_writer
::end_tag('div');
287 * @param calendar_event $event
288 * @param bool $showactions
291 public function event(calendar_event
$event, $showactions=true) {
294 $event = calendar_add_event_metadata($event);
296 $anchor = html_writer
::tag('a', '', array('name'=>'event_'.$event->id
));
298 $table = new html_table();
299 $table->attributes
= array('class'=>'event', 'cellspacing'=>'0');
300 $table->data
= array(
301 0 => new html_table_row(),
302 1 => new html_table_row(),
305 if (!empty($event->icon
)) {
306 $table->data
[0]->cells
[0] = new html_table_cell($anchor.$event->icon
);
308 $table->data
[0]->cells
[0] = new html_table_cell($anchor.$this->output
->spacer(array('height'=>16, 'width'=>16, 'br'=>true)));
310 $table->data
[0]->cells
[0]->attributes
['class'] .= ' picture';
312 $table->data
[0]->cells
[1] = new html_table_cell();
313 $table->data
[0]->cells
[1]->attributes
['class'] .= ' topic';
314 if (!empty($event->referer
)) {
315 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->referer
, array('class'=>'referer'));
317 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->name
, array('class'=>'name'));
319 if (!empty($event->courselink
)) {
320 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->courselink
, array('class'=>'course'));
322 // Show subscription source if needed.
323 if (!empty($event->subscription
) && $CFG->calendar_showicalsource
) {
324 if (!empty($event->subscription
->url
)) {
325 $source = html_writer
::link($event->subscription
->url
, get_string('subsource', 'calendar', $event->subscription
));
328 $source = get_string('subsource', 'calendar', $event->subscription
);
330 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $source, array('class' => 'subscription'));
332 if (!empty($event->time
)) {
333 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('span', $event->time
, array('class'=>'date'));
335 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('span', calendar_time_representation($event->timestart
), array('class'=>'date'));
338 $table->data
[1]->cells
[0] = new html_table_cell(' ');
339 $table->data
[1]->cells
[0]->attributes
['class'] .= 'side';
341 $table->data
[1]->cells
[1] = new html_table_cell($event->description
);
342 $table->data
[1]->cells
[1]->attributes
['class'] .= ' description';
343 if (isset($event->cssclass
)) {
344 $table->data
[1]->cells
[1]->attributes
['class'] .= ' '.$event->cssclass
;
347 if (calendar_edit_event_allowed($event) && $showactions) {
348 if (empty($event->cmid
)) {
349 $editlink = new moodle_url(CALENDAR_URL
.'event.php', array('action'=>'edit', 'id'=>$event->id
));
350 $deletelink = new moodle_url(CALENDAR_URL
.'delete.php', array('id'=>$event->id
));
351 if (!empty($event->calendarcourseid
)) {
352 $editlink->param('course', $event->calendarcourseid
);
353 $deletelink->param('course', $event->calendarcourseid
);
356 $editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid
, 'return'=>true, 'sesskey'=>sesskey()));
360 $commands = html_writer
::start_tag('div', array('class'=>'commands'));
361 $commands .= html_writer
::start_tag('a', array('href'=>$editlink));
362 $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')));
363 $commands .= html_writer
::end_tag('a');
364 if ($deletelink != null) {
365 $commands .= html_writer
::start_tag('a', array('href'=>$deletelink));
366 $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')));
367 $commands .= html_writer
::end_tag('a');
369 $commands .= html_writer
::end_tag('div');
370 $table->data
[1]->cells
[1]->text
.= $commands;
372 return html_writer
::table($table);
376 * Displays a month in detail
378 * @param calendar_information $calendar
381 public function show_month_detailed(calendar_information
$calendar, moodle_url
$returnurl = null) {
384 if (empty($returnurl)) {
385 $returnurl = $this->page
->url
;
388 $date = usergetdate(time());
390 $display = new stdClass
;
391 $display->minwday
= get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
392 $display->maxwday
= $display->minwday +
6;
393 $display->thismonth
= ($date['mon'] == $calendar->month
);
394 $display->maxdays
= calendar_days_in_month($calendar->month
, $calendar->year
);
397 if (get_user_timezone_offset() < 99) {
398 // We 'll keep these values as GMT here, and offset them when the time comes to query the db
399 $display->tstart
= gmmktime(0, 0, 0, $calendar->month
, 1, $calendar->year
); // This is GMT
400 $display->tend
= gmmktime(23, 59, 59, $calendar->month
, $display->maxdays
, $calendar->year
); // GMT
401 $startwday = gmdate('w', $display->tstart
); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
403 // no timezone info specified
404 $display->tstart
= mktime(0, 0, 0, $calendar->month
, 1, $calendar->year
);
405 $display->tend
= mktime(23, 59, 59, $calendar->month
, $display->maxdays
, $calendar->year
);
406 $startwday = date('w', $display->tstart
); // $display->tstart not necessarily GMT, so use date()
409 // Align the starting weekday to fall in our display range
410 if ($startwday < $display->minwday
) {
414 // Get events from database
415 $events = calendar_get_events(usertime($display->tstart
), usertime($display->tend
), $calendar->users
, $calendar->groups
, $calendar->courses
);
416 if (!empty($events)) {
417 foreach($events as $eventid => $event) {
418 $event = new calendar_event($event);
419 if (!empty($event->modulename
)) {
420 $cm = get_coursemodule_from_instance($event->modulename
, $event->instance
);
421 if (!groups_course_module_visible($cm)) {
422 unset($events[$eventid]);
428 // Extract information: events vs. time
429 calendar_events_by_day($events, $calendar->month
, $calendar->year
, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses
);
431 $output = html_writer
::start_tag('div', array('class'=>'header'));
432 if (calendar_user_can_add_event($calendar->course
)) {
433 $output .= $this->add_event_button($calendar->course
->id
, null, $calendar->month
, $calendar->year
);
435 $output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector($returnurl);
436 $output .= html_writer
::end_tag('div', array('class'=>'header'));
438 $output .= html_writer
::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid
, 'm' => $calendar->month
, 'y' => $calendar->year
)), array('class'=>'controls'));
440 $days = calendar_get_days();
442 $table = new html_table();
443 $table->attributes
= array('class'=>'calendarmonth calendartable');
444 $time = make_timestamp($calendar->year
, $calendar->month
);
445 $table->summary
= get_string('calendarheading', 'calendar', userdate($time, get_string('strftimemonthyear')));
446 $table->data
= array();
448 $header = new html_table_row();
449 $header->attributes
= array('class'=>'weekdays');
450 $header->cells
= array();
451 for($i = $display->minwday
; $i <= $display->maxwday
; ++
$i) {
452 // This uses the % operator to get the correct weekday no matter what shift we have
453 // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
454 $cell = new html_table_cell(get_string($days[$i %
7], 'calendar'));
455 $cell->header
= true;
456 $header->cells
[] = $cell;
459 // For the table display. $week is the row; $dayweek is the column.
461 $dayweek = $startwday;
463 // Create an array of all the week days.
464 $wdays = array(0 => '<strong>'. get_string('sun', 'calendar'). '</strong>',
465 1 => '<strong>'. get_string('mon', 'calendar'). '</strong>',
466 2 => '<strong>'. get_string('tue', 'calendar'). '</strong>',
467 3 => '<strong>'. get_string('wed', 'calendar'). '</strong>',
468 4 => '<strong>'. get_string('thu', 'calendar'). '</strong>',
469 5 => '<strong>'. get_string('fri', 'calendar'). '</strong>',
470 6 => '<strong>'. get_string('sat', 'calendar'). '</strong>');
472 // Loop only if the day offset is greater than 0.
473 // This loop involves shifting the days around until the desired start day
474 // is at the start of the array.
476 while ($display->minwday
> $daycount++
) {
477 $wdays_end = array_shift($wdays);
478 array_push($wdays, $wdays_end);
481 // Now we set the (modified) array to the table header to be displayed.
482 $table->head
= $wdays;
484 $row = new html_table_row(array());
486 // Paddding (the first week may have blank days in the beginning)
487 for($i = $display->minwday
; $i < $startwday; ++
$i) {
488 $cell = new html_table_cell(' ');
489 $cell->attributes
= array('class'=>'nottoday dayblank');
490 $row->cells
[] = $cell;
493 // Now display all the calendar
494 $weekend = CALENDAR_DEFAULT_WEEKEND
;
495 if (isset($CFG->calendar_weekend
)) {
496 $weekend = intval($CFG->calendar_weekend
);
499 for ($calendar->day
= 1; $calendar->day
<= $display->maxdays
; ++
$calendar->day
, ++
$dayweek) {
500 if($dayweek > $display->maxwday
) {
501 // We need to change week (table row)
502 $table->data
[] = $row;
503 $row = new html_table_row(array());
504 $dayweek = $display->minwday
;
509 $cell = new html_table_cell();
510 $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL
.'view.php', array('view'=>'day', 'course'=>$calendar->courseid
)), $calendar->day
, $calendar->month
, $calendar->year
);
512 $cellclasses = array();
514 if ($weekend & (1 << ($dayweek %
7))) {
515 // Weekend. This is true no matter what the exact range is.
516 $cellclasses[] = 'weekend';
519 // Special visual fx if an event is defined
520 if (isset($eventsbyday[$calendar->day
])) {
521 if(count($eventsbyday[$calendar->day
]) == 1) {
522 $title = get_string('oneevent', 'calendar');
524 $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day
]));
526 $cell->text
= html_writer
::tag('div', html_writer
::link($dayhref, $calendar->day
, array('title'=>$title)), array('class'=>'day'));
528 $cell->text
= html_writer
::tag('div', $calendar->day
, array('class'=>'day'));
531 // Special visual fx if an event spans many days
532 $durationclass = false;
533 if (isset($typesbyday[$calendar->day
]['durationglobal'])) {
534 $durationclass = 'duration_global';
535 } else if (isset($typesbyday[$calendar->day
]['durationcourse'])) {
536 $durationclass = 'duration_course';
537 } else if (isset($typesbyday[$calendar->day
]['durationgroup'])) {
538 $durationclass = 'duration_group';
539 } else if (isset($typesbyday[$calendar->day
]['durationuser'])) {
540 $durationclass = 'duration_user';
542 if ($durationclass) {
543 $cellclasses[] = 'duration';
544 $cellclasses[] = $durationclass;
547 // Special visual fx for today
548 if ($display->thismonth
&& $calendar->day
== $date['mday']) {
549 $cellclasses[] = 'day today';
551 $cellclasses[] = 'day nottoday';
553 $cell->attributes
= array('class'=>join(' ',$cellclasses));
555 if (isset($eventsbyday[$calendar->day
])) {
556 $cell->text
.= html_writer
::start_tag('ul', array('class'=>'events-new'));
557 foreach($eventsbyday[$calendar->day
] as $eventindex) {
558 // If event has a class set then add it to the event <li> tag
559 $attributes = array();
560 if (!empty($events[$eventindex]->class)) {
561 $attributes['class'] = $events[$eventindex]->class;
563 $dayhref->set_anchor('event_'.$events[$eventindex]->id
);
564 $link = html_writer
::link($dayhref, format_string($events[$eventindex]->name
, true));
565 $cell->text
.= html_writer
::tag('li', $link, $attributes);
567 $cell->text
.= html_writer
::end_tag('ul');
569 if (isset($durationbyday[$calendar->day
])) {
570 $cell->text
.= html_writer
::start_tag('ul', array('class'=>'events-underway'));
571 foreach($durationbyday[$calendar->day
] as $eventindex) {
572 $cell->text
.= html_writer
::tag('li', '['.format_string($events[$eventindex]->name
,true).']', array('class'=>'events-underway'));
574 $cell->text
.= html_writer
::end_tag('ul');
576 $row->cells
[] = $cell;
579 // Paddding (the last week may have blank days at the end)
580 for($i = $dayweek; $i <= $display->maxwday
; ++
$i) {
581 $cell = new html_table_cell(' ');
582 $cell->attributes
= array('class'=>'nottoday dayblank');
583 $row->cells
[] = $cell;
585 $table->data
[] = $row;
586 $output .= html_writer
::table($table);
592 * Displays a filter selection table
594 * @param calendar_information $calendar
596 * @deprecated since Moodle 2.4 MDL-32309
597 * @see calendar_filter_controls()
599 protected function filter_selection_table(calendar_information
$calendar, moodle_url
$returnurl = null) {
601 debugging('Method core_calendar_renderer::filter_selection_table() is deprecated, please use '.
602 'calendar_filter_controls() instead', DEBUG_DEVELOPER
);
604 if ($returnurl === null) {
605 $returnurl = $this->page
->url
;
608 $output = html_writer
::start_tag('div', array('class'=>'filters'));
609 $output .= html_writer
::start_tag('table');
610 $output .= html_writer
::start_tag('tr');
613 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var' => 'showglobal', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
614 $strglobalevents = get_string('globalevents', 'calendar');
615 if (calendar_show_event_type(CALENDAR_EVENT_GLOBAL
)) {
616 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;'));
617 $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>').')');
619 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
620 $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>').')');
624 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showcourses', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
625 $strcourseevents = get_string('courseevents', 'calendar');
626 if (calendar_show_event_type(CALENDAR_EVENT_COURSE
)) {
627 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;'));
628 $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>').')');
630 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
631 $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>').')');
633 $output .= html_writer
::end_tag('tr');
635 if(isloggedin() && !isguestuser()) {
636 $output .= html_writer
::start_tag('tr');
638 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showgroups', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
639 $strgroupevents = get_string('groupevents', 'calendar');
640 if (calendar_show_event_type(CALENDAR_EVENT_GROUP
)) {
641 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;'));
642 $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>').')');
644 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
645 $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>').')');
648 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showuser', 'return' => base64_encode($returnurl->out(false)), 'sesskey'=>sesskey()));
649 $struserevents = get_string('userevents', 'calendar');
650 if (calendar_show_event_type(CALENDAR_EVENT_USER
)) {
651 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;'));
652 $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>').')');
654 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
655 $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>').')');
657 $output .= html_writer
::end_tag('tr');
659 $output .= html_writer
::end_tag('table');
660 $output .= html_writer
::end_tag('div');
665 * Displays upcoming events
667 * @param calendar_information $calendar
668 * @param int $futuredays
669 * @param int $maxevents
672 public function show_upcoming_events(calendar_information
$calendar, $futuredays, $maxevents, moodle_url
$returnurl = null) {
674 if ($returnurl === null) {
675 $returnurl = $this->page
->url
;
678 $events = calendar_get_upcoming($calendar->courses
, $calendar->groups
, $calendar->users
, $futuredays, $maxevents);
680 $output = html_writer
::start_tag('div', array('class'=>'header'));
681 if (calendar_user_can_add_event($calendar->course
)) {
682 $output .= $this->add_event_button($calendar->course
->id
);
684 $output .= html_writer
::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump'));
685 $output .= $this->course_filter_selector($returnurl);
686 $output .= html_writer
::end_tag('div');
689 $output .= html_writer
::start_tag('div', array('class'=>'eventlist'));
690 foreach ($events as $event) {
691 // Convert to calendar_event object so that we transform description
693 $event = new calendar_event($event);
694 $event->calendarcourseid
= $calendar->courseid
;
695 $output .= $this->event($event);
697 $output .= html_writer
::end_tag('div');
699 $output .= $this->output
->heading(get_string('noupcomingevents', 'calendar'));
706 * Displays a course filter selector
708 * @param array $getvars
711 protected function course_filter_selector(moodle_url
$returnurl, $label=null) {
712 global $USER, $SESSION, $CFG;
714 if (!isloggedin() or isguestuser()) {
718 if (has_capability('moodle/calendar:manageentries', context_system
::instance()) && !empty($CFG->calendar_adminseesall
)) {
719 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
721 $courses = enrol_get_my_courses();
724 unset($courses[SITEID
]);
726 $courseoptions = array();
727 $courseoptions[SITEID
] = get_string('fulllistofcourses');
728 foreach ($courses as $course) {
729 $coursecontext = context_course
::instance($course->id
);
730 $courseoptions[$course->id
] = format_string($course->shortname
, true, array('context' => $coursecontext));
733 if ($this->page
->course
->id
!== SITEID
) {
734 $selected = $this->page
->course
->id
;
738 $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);
739 $select->class = 'cal_courses_flt';
740 if ($label !== null) {
741 $select->set_label($label);
743 $select->set_label(get_string('listofcourses'), array('class' => 'accesshide'));
745 return $this->output
->render($select);
749 * Renders a table containing information about calendar subscriptions.
751 * @param int $courseid
752 * @param array $subscriptions
753 * @param string $importresults
756 public function subscription_details($courseid, $subscriptions, $importresults = '') {
757 $table = new html_table();
758 $table->head
= array(
759 get_string('colcalendar', 'calendar'),
760 get_string('collastupdated', 'calendar'),
761 get_string('eventkind', 'calendar'),
762 get_string('colpoll', 'calendar'),
763 get_string('colactions', 'calendar')
765 $table->align
= array('left', 'left', 'left', 'center');
766 $table->width
= '100%';
767 $table->data
= array();
769 if (empty($subscriptions)) {
770 $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar'));
772 $table->data
[] = new html_table_row(array($cell));
774 $strnever = new lang_string('never', 'calendar');
775 foreach ($subscriptions as $sub) {
777 if (!empty($sub->url
)) {
778 $label = html_writer
::link($sub->url
, $label);
780 if (empty($sub->lastupdated
)) {
781 $lastupdated = $strnever->out();
783 $lastupdated = userdate($sub->lastupdated
, get_string('strftimedatetimeshort', 'langconfig'));
786 $cell = new html_table_cell($this->subscription_action_form($sub, $courseid));
788 $type = $sub->eventtype
. 'events';
790 $table->data
[] = new html_table_row(array(
791 new html_table_cell($label),
792 new html_table_cell($lastupdated),
793 new html_table_cell(get_string($type, 'calendar')),
798 $out = $this->output
->box_start('generalbox calendarsubs');
800 $out .= $importresults;
801 $out .= html_writer
::table($table);
802 $out .= $this->output
->box_end();
807 * Creates a form to perform actions on a given subscription.
809 * @param stdClass $subscription
810 * @param int $courseid
813 protected function subscription_action_form($subscription, $courseid) {
814 // Assemble form for the subscription row.
815 $html = html_writer
::start_tag('form', array('action' => new moodle_url('/calendar/managesubscriptions.php'), 'method' => 'post'));
816 if (empty($subscription->url
)) {
817 // Don't update an iCal file, which has no URL.
818 $html .= html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'pollinterval', 'value' => '0'));
820 // Assemble pollinterval control.
821 $html .= html_writer
::start_tag('div', array('style' => 'float:left;'));
822 $html .= html_writer
::start_tag('select', array('name' => 'pollinterval'));
823 foreach (calendar_get_pollinterval_choices() as $k => $v) {
824 $attributes = array();
825 if ($k == $subscription->pollinterval
) {
826 $attributes['selected'] = 'selected';
828 $attributes['value'] = $k;
829 $html .= html_writer
::tag('option', $v, $attributes);
831 $html .= html_writer
::end_tag('select');
832 $html .= html_writer
::end_tag('div');
834 $html .= html_writer
::start_tag('div', array('style' => 'float:right;'));
835 $html .= html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
836 $html .= html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'course', 'value' => $courseid));
837 $html .= html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $subscription->id
));
838 if (!empty($subscription->url
)) {
839 $html .= html_writer
::empty_tag('input', array('type' => 'submit', 'name' => 'action', 'value' => get_string('update')));
841 $html .= html_writer
::empty_tag('input', array('type' => 'submit', 'name' => 'action', 'value' => get_string('remove')));
842 $html .= html_writer
::end_tag('div');
843 $html .= html_writer
::end_tag('form');