Merge branch 'MDL-59927-33-enfix' of git://github.com/mudrd8mz/moodle into MOODLE_33_...
[moodle.git] / calendar / renderer.php
blob03a84d7c8a51552f1b3ac85fb2a732e49e8397ea
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
18 /**
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
23 * @package calendar
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
30 /**
31 * The primary renderer for the calendar.
33 class core_calendar_renderer extends plugin_renderer_base {
35 /**
36 * Starts the standard layout for the page
38 * @return string
40 public function start_layout() {
41 return html_writer::start_tag('div', array('class'=>'maincalendar'));
44 /**
45 * Creates the remainder of the layout
47 * @return string
49 public function complete_layout() {
50 return html_writer::end_tag('div');
53 /**
54 * Produces the content for the filters block (pretend block)
56 * @param int $courseid
57 * @param int $day
58 * @param int $month
59 * @param int $year
60 * @param int $view
61 * @param int $courses
62 * @return string
64 public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) {
65 $returnurl = $this->page->url;
66 $returnurl->param('course', $courseid);
67 return html_writer::tag('div', calendar_filter_controls($returnurl),
68 array('class' => 'calendar_filters filters'));
71 /**
72 * Produces the content for the three months block (pretend block)
74 * This includes the previous month, the current month, and the next month
76 * @param calendar_information $calendar
77 * @return string
79 public function fake_block_threemonths(calendar_information $calendar) {
80 // Get the calendar type we are using.
81 $calendartype = \core_calendar\type_factory::get_calendar_instance();
83 $date = $calendartype->timestamp_to_date_array($calendar->time);
85 $prevmonth = calendar_sub_month($date['mon'], $date['year']);
86 $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], 1);
87 $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day'],
88 $prevmonthtime['hour'], $prevmonthtime['minute']);
90 $nextmonth = calendar_add_month($date['mon'], $date['year']);
91 $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], 1);
92 $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day'],
93 $nextmonthtime['hour'], $nextmonthtime['minute']);
95 $content = html_writer::start_tag('div', array('class' => 'minicalendarblock'));
96 $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users,
97 false, false, 'display', $calendar->courseid, $prevmonthtime);
98 $content .= html_writer::end_tag('div');
99 $content .= html_writer::start_tag('div', array('class' => 'minicalendarblock'));
100 $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users,
101 false, false, 'display', $calendar->courseid, $calendar->time);
102 $content .= html_writer::end_tag('div');
103 $content .= html_writer::start_tag('div', array('class' => 'minicalendarblock'));
104 $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users,
105 false, false, 'display', $calendar->courseid, $nextmonthtime);
106 $content .= html_writer::end_tag('div');
107 return $content;
111 * Adds a pretent calendar block
113 * @param block_contents $bc
114 * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
116 public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) {
117 $this->page->blocks->add_fake_block($bc, $pos);
121 * Creates a button to add a new event
123 * @param int $courseid
124 * @param int $day
125 * @param int $month
126 * @param int $year
127 * @param int $time the unixtime, used for multiple calendar support. The values $day,
128 * $month and $year are kept for backwards compatibility.
129 * @return string
131 protected function add_event_button($courseid, $day = null, $month = null, $year = null, $time = null) {
132 // If a day, month and year were passed then convert it to a timestamp. If these were passed
133 // then we can assume the day, month and year are passed as Gregorian, as no where in core
134 // should we be passing these values rather than the time. This is done for BC.
135 if (!empty($day) && !empty($month) && !empty($year)) {
136 if (checkdate($month, $day, $year)) {
137 $time = make_timestamp($year, $month, $day);
138 } else {
139 $time = time();
141 } else if (empty($time)) {
142 $time = time();
145 $output = html_writer::start_tag('div', array('class'=>'buttons'));
146 $output .= html_writer::start_tag('form', array('action' => CALENDAR_URL . 'event.php', 'method' => 'get'));
147 $output .= html_writer::start_tag('div');
148 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name' => 'action', 'value' => 'new'));
149 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name' => 'course', 'value' => $courseid));
150 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name' => 'time', 'value' => $time));
151 $attributes = array('type' => 'submit', 'value' => get_string('newevent', 'calendar'), 'class' => 'btn btn-secondary');
152 $output .= html_writer::empty_tag('input', $attributes);
153 $output .= html_writer::end_tag('div');
154 $output .= html_writer::end_tag('form');
155 $output .= html_writer::end_tag('div');
156 return $output;
160 * Displays the calendar for a single day
162 * @param calendar_information $calendar
163 * @return string
165 public function show_day(calendar_information $calendar, moodle_url $returnurl = null) {
167 if ($returnurl === null) {
168 $returnurl = $this->page->url;
171 $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users,
172 1, 100, $calendar->timestamp_today());
174 $output = html_writer::start_tag('div', array('class'=>'header'));
175 $output .= $this->course_filter_selector($returnurl, get_string('dayviewfor', 'calendar'));
176 if (calendar_user_can_add_event($calendar->course)) {
177 $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
179 $output .= html_writer::end_tag('div');
180 // Controls
181 $output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid,
182 'time' => $calendar->time)), array('class' => 'controls'));
184 if (empty($events)) {
185 // There is nothing to display today.
186 $output .= html_writer::span(get_string('daywithnoevents', 'calendar'), 'calendar-information calendar-no-results');
187 } else {
188 $output .= html_writer::start_tag('div', array('class' => 'eventlist'));
189 $underway = array();
190 // First, print details about events that start today
191 foreach ($events as $event) {
192 $event = new calendar_event($event);
193 $event->calendarcourseid = $calendar->courseid;
194 if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now
195 $event->time = calendar_format_event_time($event, time(), null, false,
196 $calendar->timestamp_today());
197 $output .= $this->event($event);
198 } else { // Save this for later
199 $underway[] = $event;
203 // Then, show a list of all events that just span this day
204 if (!empty($underway)) {
205 $output .= html_writer::span(get_string('spanningevents', 'calendar'),
206 'calendar-information calendar-span-multiple-days');
207 foreach ($underway as $event) {
208 $event->time = calendar_format_event_time($event, time(), null, false,
209 $calendar->timestamp_today());
210 $output .= $this->event($event);
214 $output .= html_writer::end_tag('div');
217 return $output;
221 * Displays an event
223 * @param calendar_event $event
224 * @param bool $showactions
225 * @return string
227 public function event(calendar_event $event, $showactions=true) {
228 global $CFG;
230 $event = calendar_add_event_metadata($event);
231 $context = $event->context;
232 $output = '';
234 $output .= $this->output->box_start('card-header clearfix');
235 if (calendar_edit_event_allowed($event) && $showactions) {
236 if (empty($event->cmid)) {
237 $editlink = new moodle_url(CALENDAR_URL.'event.php', array('action' => 'edit', 'id' => $event->id));
238 $deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id' => $event->id));
239 if (!empty($event->calendarcourseid)) {
240 $editlink->param('course', $event->calendarcourseid);
241 $deletelink->param('course', $event->calendarcourseid);
243 } else {
244 $params = array('update' => $event->cmid, 'return' => true, 'sesskey' => sesskey());
245 $editlink = new moodle_url('/course/mod.php', $params);
246 $deletelink = null;
249 $commands = html_writer::start_tag('div', array('class' => 'commands pull-xs-right'));
250 $commands .= html_writer::start_tag('a', array('href' => $editlink));
251 $str = get_string('tt_editevent', 'calendar');
252 $commands .= $this->output->pix_icon('t/edit', $str);
253 $commands .= html_writer::end_tag('a');
254 if ($deletelink != null) {
255 $commands .= html_writer::start_tag('a', array('href' => $deletelink));
256 $str = get_string('tt_deleteevent', 'calendar');
257 $commands .= $this->output->pix_icon('t/delete', $str);
258 $commands .= html_writer::end_tag('a');
260 $commands .= html_writer::end_tag('div');
261 $output .= $commands;
263 if (!empty($event->icon)) {
264 $output .= $event->icon;
265 } else {
266 $output .= $this->output->spacer(array('height' => 16, 'width' => 16));
269 if (!empty($event->referer)) {
270 $output .= $this->output->heading($event->referer, 3, array('class' => 'referer'));
271 } else {
272 $output .= $this->output->heading(
273 format_string($event->name, false, array('context' => $context)),
275 array('class' => 'name d-inline-block')
278 // Show subscription source if needed.
279 if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
280 if (!empty($event->subscription->url)) {
281 $source = html_writer::link($event->subscription->url, get_string('subsource', 'calendar', $event->subscription));
282 } else {
283 // File based ical.
284 $source = get_string('subsource', 'calendar', $event->subscription);
286 $output .= html_writer::tag('div', $source, array('class' => 'subscription'));
288 if (!empty($event->courselink)) {
289 $output .= html_writer::tag('div', $event->courselink, array('class' => 'course'));
291 if (!empty($event->time)) {
292 $output .= html_writer::tag('span', $event->time, array('class' => 'date pull-xs-right m-r-1'));
293 } else {
294 $attrs = array('class' => 'date pull-xs-right m-r-1');
295 $output .= html_writer::tag('span', calendar_time_representation($event->timestart), $attrs);
298 if (!empty($event->actionurl)) {
299 $output .= html_writer::tag('div', html_writer::link(new moodle_url($event->actionurl), $event->actionname));
302 $output .= $this->output->box_end();
303 $eventdetailshtml = '';
304 $eventdetailsclasses = '';
306 $eventdetailshtml .= format_text($event->description, $event->format, array('context' => $context));
307 $eventdetailsclasses .= 'description card-block';
308 if (isset($event->cssclass)) {
309 $eventdetailsclasses .= ' '.$event->cssclass;
312 if (!empty($eventdetailshtml)) {
313 $output .= html_writer::tag('div', $eventdetailshtml, array('class' => $eventdetailsclasses));
316 $eventhtml = html_writer::tag('div', $output, array('class' => 'card'));
317 return html_writer::tag('div', $eventhtml, array('class' => 'event', 'id' => 'event_' . $event->id));
321 * Displays a month in detail
323 * @param calendar_information $calendar
324 * @param moodle_url $returnurl the url to return to
325 * @return string
327 public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) {
328 global $CFG;
330 if (empty($returnurl)) {
331 $returnurl = $this->page->url;
334 // Get the calendar type we are using.
335 $calendartype = \core_calendar\type_factory::get_calendar_instance();
337 // Store the display settings.
338 $display = new stdClass;
339 $display->thismonth = false;
341 // Get the specified date in the calendar type being used.
342 $date = $calendartype->timestamp_to_date_array($calendar->time);
343 $thisdate = $calendartype->timestamp_to_date_array(time());
344 if ($date['mon'] == $thisdate['mon'] && $date['year'] == $thisdate['year']) {
345 $display->thismonth = true;
346 $date = $thisdate;
347 $calendar->time = time();
350 // Get Gregorian date for the start of the month.
351 $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1);
352 // Store the gregorian date values to be used later.
353 list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'],
354 $gregoriandate['hour'], $gregoriandate['minute']);
356 // Get the starting week day for this month.
357 $startwday = dayofweek(1, $date['mon'], $date['year']);
358 // Get the days in a week.
359 $daynames = calendar_get_days();
360 // Store the number of days in a week.
361 $numberofdaysinweek = $calendartype->get_num_weekdays();
363 $display->minwday = calendar_get_starting_weekday();
364 $display->maxwday = $display->minwday + ($numberofdaysinweek - 1);
365 $display->maxdays = calendar_days_in_month($date['mon'], $date['year']);
367 // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates.
368 $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0);
369 $display->tend = $display->tstart + ($display->maxdays * DAYSECS) - 1;
371 // Align the starting weekday to fall in our display range
372 // This is simple, not foolproof.
373 if ($startwday < $display->minwday) {
374 $startwday += $numberofdaysinweek;
377 // Get events from database
378 $events = calendar_get_legacy_events($display->tstart, $display->tend, $calendar->users, $calendar->groups,
379 $calendar->courses);
380 if (!empty($events)) {
381 foreach($events as $eventid => $event) {
382 $event = new calendar_event($event);
383 if (!empty($event->modulename)) {
384 $instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
385 if (empty($instances[$event->instance]->uservisible)) {
386 unset($events[$eventid]);
392 // Extract information: events vs. time
393 calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday,
394 $typesbyday, $calendar->courses);
396 $output = html_writer::start_tag('div', array('class'=>'header'));
397 $output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar'));
398 if (calendar_user_can_add_event($calendar->course)) {
399 $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
401 $output .= html_writer::end_tag('div', array('class'=>'header'));
402 // Controls
403 $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid,
404 'time' => $calendar->time)), array('class' => 'controls'));
406 $table = new html_table();
407 $table->attributes = array('class'=>'calendarmonth calendartable');
408 $table->summary = get_string('calendarheading', 'calendar', userdate($calendar->time, get_string('strftimemonthyear')));
409 $table->data = array();
411 // Get the day names as the header.
412 $header = array();
413 for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
414 $header[] = $daynames[$i % $numberofdaysinweek]['shortname'];
416 $table->head = $header;
418 // For the table display. $week is the row; $dayweek is the column.
419 $week = 1;
420 $dayweek = $startwday;
422 $row = new html_table_row(array());
424 // Paddding (the first week may have blank days in the beginning)
425 for($i = $display->minwday; $i < $startwday; ++$i) {
426 $cell = new html_table_cell('&nbsp;');
427 $cell->attributes = array('class'=>'nottoday dayblank');
428 $row->cells[] = $cell;
431 // Now display all the calendar
432 $weekend = CALENDAR_DEFAULT_WEEKEND;
433 if (isset($CFG->calendar_weekend)) {
434 $weekend = intval($CFG->calendar_weekend);
437 $daytime = strtotime('-1 day', $display->tstart);
438 for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
439 $daytime = strtotime('+1 day', $daytime);
440 if($dayweek > $display->maxwday) {
441 // We need to change week (table row)
442 $table->data[] = $row;
443 $row = new html_table_row(array());
444 $dayweek = $display->minwday;
445 ++$week;
448 // Reset vars
449 $cell = new html_table_cell();
450 $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php',
451 array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime);
453 $cellclasses = array();
455 if ($weekend & (1 << ($dayweek % $numberofdaysinweek))) {
456 // Weekend. This is true no matter what the exact range is.
457 $cellclasses[] = 'weekend';
460 // Special visual fx if an event is defined
461 if (isset($eventsbyday[$day])) {
462 if(count($eventsbyday[$day]) == 1) {
463 $title = get_string('oneevent', 'calendar');
464 } else {
465 $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
467 $cell->text = html_writer::tag('div', html_writer::link($dayhref, $day, array('title'=>$title)), array('class'=>'day'));
468 } else {
469 $cell->text = html_writer::tag('div', $day, array('class'=>'day'));
472 // Special visual fx if an event spans many days
473 $durationclass = false;
474 if (isset($typesbyday[$day]['durationglobal'])) {
475 $durationclass = 'duration_global';
476 } else if (isset($typesbyday[$day]['durationcourse'])) {
477 $durationclass = 'duration_course';
478 } else if (isset($typesbyday[$day]['durationgroup'])) {
479 $durationclass = 'duration_group';
480 } else if (isset($typesbyday[$day]['durationuser'])) {
481 $durationclass = 'duration_user';
483 if ($durationclass) {
484 $cellclasses[] = 'duration';
485 $cellclasses[] = $durationclass;
488 // Special visual fx for today
489 if ($display->thismonth && $day == $date['mday']) {
490 $cellclasses[] = 'day today';
491 } else {
492 $cellclasses[] = 'day nottoday';
494 $cell->attributes = array('class'=>join(' ',$cellclasses));
496 if (isset($eventsbyday[$day])) {
497 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-new'));
498 foreach($eventsbyday[$day] as $eventindex) {
499 // If event has a class set then add it to the event <li> tag
500 $attributes = array();
501 if (!empty($events[$eventindex]->class)) {
502 $attributes['class'] = $events[$eventindex]->class;
504 $dayhref->set_anchor('event_'.$events[$eventindex]->id);
505 $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true));
506 $cell->text .= html_writer::tag('li', $link, $attributes);
508 $cell->text .= html_writer::end_tag('ul');
510 if (isset($durationbyday[$day])) {
511 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway'));
512 foreach($durationbyday[$day] as $eventindex) {
513 $cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway'));
515 $cell->text .= html_writer::end_tag('ul');
517 $row->cells[] = $cell;
520 // Paddding (the last week may have blank days at the end)
521 for($i = $dayweek; $i <= $display->maxwday; ++$i) {
522 $cell = new html_table_cell('&nbsp;');
523 $cell->attributes = array('class'=>'nottoday dayblank');
524 $row->cells[] = $cell;
526 $table->data[] = $row;
527 $output .= html_writer::table($table);
529 return $output;
533 * Displays upcoming events
535 * @param calendar_information $calendar
536 * @param int $futuredays
537 * @param int $maxevents
538 * @return string
540 public function show_upcoming_events(calendar_information $calendar, $futuredays, $maxevents, moodle_url $returnurl = null) {
542 if ($returnurl === null) {
543 $returnurl = $this->page->url;
546 $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users,
547 $futuredays, $maxevents);
549 $output = html_writer::start_tag('div', array('class'=>'header'));
550 $output .= $this->course_filter_selector($returnurl, get_string('upcomingeventsfor', 'calendar'));
551 if (calendar_user_can_add_event($calendar->course)) {
552 $output .= $this->add_event_button($calendar->course->id);
554 $output .= html_writer::end_tag('div');
556 if ($events) {
557 $output .= html_writer::start_tag('div', array('class' => 'eventlist'));
558 foreach ($events as $event) {
559 // Convert to calendar_event object so that we transform description accordingly.
560 $event = new calendar_event($event);
561 $event->calendarcourseid = $calendar->courseid;
562 $output .= $this->event($event);
564 $output .= html_writer::end_tag('div');
565 } else {
566 $output .= html_writer::span(get_string('noupcomingevents', 'calendar'), 'calendar-information calendar-no-results');
569 return $output;
573 * Displays a course filter selector
575 * @param moodle_url $returnurl The URL that the user should be taken too upon selecting a course.
576 * @param string $label The label to use for the course select.
577 * @return string
579 protected function course_filter_selector(moodle_url $returnurl, $label=null) {
580 global $USER, $SESSION, $CFG;
582 if (!isloggedin() or isguestuser()) {
583 return '';
586 if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) {
587 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
588 } else {
589 $courses = enrol_get_my_courses();
592 unset($courses[SITEID]);
594 $courseoptions = array();
595 $courseoptions[SITEID] = get_string('fulllistofcourses');
596 foreach ($courses as $course) {
597 $coursecontext = context_course::instance($course->id);
598 $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext));
601 if ($this->page->course->id !== SITEID) {
602 $selected = $this->page->course->id;
603 } else {
604 $selected = '';
606 $courseurl = new moodle_url($returnurl);
607 $courseurl->remove_params('course');
608 $select = new single_select($courseurl, 'course', $courseoptions, $selected, null);
609 $select->class = 'm-r-1';
610 if ($label !== null) {
611 $select->set_label($label);
612 } else {
613 $select->set_label(get_string('listofcourses'), array('class' => 'accesshide'));
615 return $this->output->render($select);
619 * Renders a table containing information about calendar subscriptions.
621 * @param int $courseid
622 * @param array $subscriptions
623 * @param string $importresults
624 * @return string
626 public function subscription_details($courseid, $subscriptions, $importresults = '') {
627 $table = new html_table();
628 $table->head = array(
629 get_string('colcalendar', 'calendar'),
630 get_string('collastupdated', 'calendar'),
631 get_string('eventkind', 'calendar'),
632 get_string('colpoll', 'calendar'),
633 get_string('colactions', 'calendar')
635 $table->align = array('left', 'left', 'left', 'center');
636 $table->width = '100%';
637 $table->data = array();
639 if (empty($subscriptions)) {
640 $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar'));
641 $cell->colspan = 5;
642 $table->data[] = new html_table_row(array($cell));
644 $strnever = new lang_string('never', 'calendar');
645 foreach ($subscriptions as $sub) {
646 $label = $sub->name;
647 if (!empty($sub->url)) {
648 $label = html_writer::link($sub->url, $label);
650 if (empty($sub->lastupdated)) {
651 $lastupdated = $strnever->out();
652 } else {
653 $lastupdated = userdate($sub->lastupdated, get_string('strftimedatetimeshort', 'langconfig'));
656 $cell = new html_table_cell($this->subscription_action_form($sub, $courseid));
657 $cell->colspan = 2;
658 $type = $sub->eventtype . 'events';
660 $table->data[] = new html_table_row(array(
661 new html_table_cell($label),
662 new html_table_cell($lastupdated),
663 new html_table_cell(get_string($type, 'calendar')),
664 $cell
668 $out = $this->output->box_start('generalbox calendarsubs');
670 $out .= $importresults;
671 $out .= html_writer::table($table);
672 $out .= $this->output->box_end();
673 return $out;
677 * Creates a form to perform actions on a given subscription.
679 * @param stdClass $subscription
680 * @param int $courseid
681 * @return string
683 protected function subscription_action_form($subscription, $courseid) {
684 // Assemble form for the subscription row.
685 $html = html_writer::start_tag('form', array('action' => new moodle_url('/calendar/managesubscriptions.php'), 'method' => 'post'));
686 if (empty($subscription->url)) {
687 // Don't update an iCal file, which has no URL.
688 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'pollinterval', 'value' => '0'));
689 } else {
690 // Assemble pollinterval control.
691 $html .= html_writer::start_tag('div', array('style' => 'float:left;'));
692 $html .= html_writer::start_tag('select', array('name' => 'pollinterval', 'class' => 'custom-select'));
693 foreach (calendar_get_pollinterval_choices() as $k => $v) {
694 $attributes = array();
695 if ($k == $subscription->pollinterval) {
696 $attributes['selected'] = 'selected';
698 $attributes['value'] = $k;
699 $html .= html_writer::tag('option', $v, $attributes);
701 $html .= html_writer::end_tag('select');
702 $html .= html_writer::end_tag('div');
704 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
705 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'course', 'value' => $courseid));
706 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $subscription->id));
707 $html .= html_writer::start_tag('div', array('class' => 'btn-group pull-right'));
708 if (!empty($subscription->url)) {
709 $html .= html_writer::tag('button', get_string('update'), array('type' => 'submit', 'name' => 'action',
710 'class' => 'btn btn-secondary',
711 'value' => CALENDAR_SUBSCRIPTION_UPDATE));
713 $html .= html_writer::tag('button', get_string('remove'), array('type' => 'submit', 'name' => 'action',
714 'class' => 'btn btn-secondary',
715 'value' => CALENDAR_SUBSCRIPTION_REMOVE));
716 $html .= html_writer::end_tag('div');
717 $html .= html_writer::end_tag('form');
718 return $html;