weekly release 3.3.7+
[moodle.git] / calendar / renderer.php
blob7ba62b074fcd6127e35ade869f6a59ea8b628142
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);
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 $actionlink = html_writer::link(new moodle_url($event->actionurl), $event->actionname);
300 $output .= html_writer::tag('div', $actionlink, ['class' => 'action']);
303 $output .= $this->output->box_end();
304 $eventdetailshtml = '';
305 $eventdetailsclasses = '';
307 $eventdetailshtml .= format_text($event->description, $event->format, array('context' => $context));
308 $eventdetailsclasses .= 'description card-block';
309 if (isset($event->cssclass)) {
310 $eventdetailsclasses .= ' '.$event->cssclass;
313 if (!empty($eventdetailshtml)) {
314 $output .= html_writer::tag('div', $eventdetailshtml, array('class' => $eventdetailsclasses));
317 $eventhtml = html_writer::tag('div', $output, array('class' => 'card'));
318 return html_writer::tag('div', $eventhtml, array('class' => 'event', 'id' => 'event_' . $event->id));
322 * Displays a month in detail
324 * @param calendar_information $calendar
325 * @param moodle_url $returnurl the url to return to
326 * @return string
328 public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) {
329 global $CFG;
331 if (empty($returnurl)) {
332 $returnurl = $this->page->url;
335 // Get the calendar type we are using.
336 $calendartype = \core_calendar\type_factory::get_calendar_instance();
338 // Store the display settings.
339 $display = new stdClass;
340 $display->thismonth = false;
342 // Get the specified date in the calendar type being used.
343 $date = $calendartype->timestamp_to_date_array($calendar->time);
344 $thisdate = $calendartype->timestamp_to_date_array(time());
345 if ($date['mon'] == $thisdate['mon'] && $date['year'] == $thisdate['year']) {
346 $display->thismonth = true;
347 $date = $thisdate;
348 $calendar->time = time();
351 // Get Gregorian date for the start of the month.
352 $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1);
353 // Store the gregorian date values to be used later.
354 list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'],
355 $gregoriandate['hour'], $gregoriandate['minute']);
357 // Get the starting week day for this month.
358 $startwday = dayofweek(1, $date['mon'], $date['year']);
359 // Get the days in a week.
360 $daynames = calendar_get_days();
361 // Store the number of days in a week.
362 $numberofdaysinweek = $calendartype->get_num_weekdays();
364 $display->minwday = calendar_get_starting_weekday();
365 $display->maxwday = $display->minwday + ($numberofdaysinweek - 1);
366 $display->maxdays = calendar_days_in_month($date['mon'], $date['year']);
368 // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates.
369 $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0);
370 $display->tend = $display->tstart + ($display->maxdays * DAYSECS) - 1;
372 // Align the starting weekday to fall in our display range
373 // This is simple, not foolproof.
374 if ($startwday < $display->minwday) {
375 $startwday += $numberofdaysinweek;
378 // Get events from database
379 $events = calendar_get_legacy_events($display->tstart, $display->tend, $calendar->users, $calendar->groups,
380 $calendar->courses);
381 if (!empty($events)) {
382 foreach($events as $eventid => $event) {
383 $event = new calendar_event($event);
384 if (!empty($event->modulename)) {
385 $instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
386 if (empty($instances[$event->instance]->uservisible)) {
387 unset($events[$eventid]);
393 // Extract information: events vs. time
394 calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday,
395 $typesbyday, $calendar->courses);
397 $output = html_writer::start_tag('div', array('class'=>'header'));
398 $output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar'));
399 if (calendar_user_can_add_event($calendar->course)) {
400 $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
402 $output .= html_writer::end_tag('div', array('class'=>'header'));
403 // Controls
404 $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid,
405 'time' => $calendar->time)), array('class' => 'controls'));
407 $table = new html_table();
408 $table->attributes = array('class'=>'calendarmonth calendartable');
409 $table->summary = get_string('calendarheading', 'calendar', userdate($calendar->time, get_string('strftimemonthyear')));
410 $table->data = array();
412 // Get the day names as the header.
413 $header = array();
414 for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
415 $header[] = $daynames[$i % $numberofdaysinweek]['shortname'];
417 $table->head = $header;
419 // For the table display. $week is the row; $dayweek is the column.
420 $week = 1;
421 $dayweek = $startwday;
423 $row = new html_table_row(array());
425 // Paddding (the first week may have blank days in the beginning)
426 for($i = $display->minwday; $i < $startwday; ++$i) {
427 $cell = new html_table_cell('&nbsp;');
428 $cell->attributes = array('class'=>'nottoday dayblank');
429 $row->cells[] = $cell;
432 // Now display all the calendar
433 $weekend = CALENDAR_DEFAULT_WEEKEND;
434 if (isset($CFG->calendar_weekend)) {
435 $weekend = intval($CFG->calendar_weekend);
438 $daytime = strtotime('-1 day', $display->tstart);
439 for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
440 $daytime = strtotime('+1 day', $daytime);
441 if($dayweek > $display->maxwday) {
442 // We need to change week (table row)
443 $table->data[] = $row;
444 $row = new html_table_row(array());
445 $dayweek = $display->minwday;
446 ++$week;
449 // Reset vars
450 $cell = new html_table_cell();
451 $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php',
452 array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime);
454 $cellclasses = array();
456 if ($weekend & (1 << ($dayweek % $numberofdaysinweek))) {
457 // Weekend. This is true no matter what the exact range is.
458 $cellclasses[] = 'weekend';
461 // Special visual fx if an event is defined
462 if (isset($eventsbyday[$day])) {
463 if(count($eventsbyday[$day]) == 1) {
464 $title = get_string('oneevent', 'calendar');
465 } else {
466 $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
468 $cell->text = html_writer::tag('div', html_writer::link($dayhref, $day, array('title'=>$title)), array('class'=>'day'));
469 } else {
470 $cell->text = html_writer::tag('div', $day, array('class'=>'day'));
473 // Special visual fx if an event spans many days
474 $durationclass = false;
475 if (isset($typesbyday[$day]['durationglobal'])) {
476 $durationclass = 'duration_global';
477 } else if (isset($typesbyday[$day]['durationcourse'])) {
478 $durationclass = 'duration_course';
479 } else if (isset($typesbyday[$day]['durationgroup'])) {
480 $durationclass = 'duration_group';
481 } else if (isset($typesbyday[$day]['durationuser'])) {
482 $durationclass = 'duration_user';
484 if ($durationclass) {
485 $cellclasses[] = 'duration';
486 $cellclasses[] = $durationclass;
489 // Special visual fx for today
490 if ($display->thismonth && $day == $date['mday']) {
491 $cellclasses[] = 'day today';
492 } else {
493 $cellclasses[] = 'day nottoday';
495 $cell->attributes = array('class'=>join(' ',$cellclasses));
497 if (isset($eventsbyday[$day])) {
498 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-new'));
499 foreach($eventsbyday[$day] as $eventindex) {
500 // If event has a class set then add it to the event <li> tag
501 $attributes = array();
502 if (!empty($events[$eventindex]->class)) {
503 $attributes['class'] = $events[$eventindex]->class;
505 $dayhref->set_anchor('event_'.$events[$eventindex]->id);
506 $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true));
507 $cell->text .= html_writer::tag('li', $link, $attributes);
509 $cell->text .= html_writer::end_tag('ul');
511 if (isset($durationbyday[$day])) {
512 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway'));
513 foreach($durationbyday[$day] as $eventindex) {
514 $cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway'));
516 $cell->text .= html_writer::end_tag('ul');
518 $row->cells[] = $cell;
521 // Paddding (the last week may have blank days at the end)
522 for($i = $dayweek; $i <= $display->maxwday; ++$i) {
523 $cell = new html_table_cell('&nbsp;');
524 $cell->attributes = array('class'=>'nottoday dayblank');
525 $row->cells[] = $cell;
527 $table->data[] = $row;
528 $output .= html_writer::table($table);
530 return $output;
534 * Displays upcoming events
536 * @param calendar_information $calendar
537 * @param int $futuredays
538 * @param int $maxevents
539 * @return string
541 public function show_upcoming_events(calendar_information $calendar, $futuredays, $maxevents, moodle_url $returnurl = null) {
543 if ($returnurl === null) {
544 $returnurl = $this->page->url;
547 $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users,
548 $futuredays, $maxevents);
550 $output = html_writer::start_tag('div', array('class'=>'header'));
551 $output .= $this->course_filter_selector($returnurl, get_string('upcomingeventsfor', 'calendar'));
552 if (calendar_user_can_add_event($calendar->course)) {
553 $output .= $this->add_event_button($calendar->course->id);
555 $output .= html_writer::end_tag('div');
557 if ($events) {
558 $output .= html_writer::start_tag('div', array('class' => 'eventlist'));
559 foreach ($events as $event) {
560 // Convert to calendar_event object so that we transform description accordingly.
561 $event = new calendar_event($event);
562 $event->calendarcourseid = $calendar->courseid;
563 $output .= $this->event($event);
565 $output .= html_writer::end_tag('div');
566 } else {
567 $output .= html_writer::span(get_string('noupcomingevents', 'calendar'), 'calendar-information calendar-no-results');
570 return $output;
574 * Displays a course filter selector
576 * @param moodle_url $returnurl The URL that the user should be taken too upon selecting a course.
577 * @param string $label The label to use for the course select.
578 * @return string
580 protected function course_filter_selector(moodle_url $returnurl, $label=null) {
581 global $USER, $SESSION, $CFG;
583 if (!isloggedin() or isguestuser()) {
584 return '';
587 if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) {
588 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
589 } else {
590 $courses = enrol_get_my_courses();
593 unset($courses[SITEID]);
595 $courseoptions = array();
596 $courseoptions[SITEID] = get_string('fulllistofcourses');
597 foreach ($courses as $course) {
598 $coursecontext = context_course::instance($course->id);
599 $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext));
602 if ($this->page->course->id !== SITEID) {
603 $selected = $this->page->course->id;
604 } else {
605 $selected = '';
607 $courseurl = new moodle_url($returnurl);
608 $courseurl->remove_params('course');
609 $select = new single_select($courseurl, 'course', $courseoptions, $selected, null);
610 $select->class = 'm-r-1';
611 if ($label !== null) {
612 $select->set_label($label);
613 } else {
614 $select->set_label(get_string('listofcourses'), array('class' => 'accesshide'));
616 return $this->output->render($select);
620 * Renders a table containing information about calendar subscriptions.
622 * @param int $courseid
623 * @param array $subscriptions
624 * @param string $importresults
625 * @return string
627 public function subscription_details($courseid, $subscriptions, $importresults = '') {
628 $table = new html_table();
629 $table->head = array(
630 get_string('colcalendar', 'calendar'),
631 get_string('collastupdated', 'calendar'),
632 get_string('eventkind', 'calendar'),
633 get_string('colpoll', 'calendar'),
634 get_string('colactions', 'calendar')
636 $table->align = array('left', 'left', 'left', 'center');
637 $table->width = '100%';
638 $table->data = array();
640 if (empty($subscriptions)) {
641 $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar'));
642 $cell->colspan = 5;
643 $table->data[] = new html_table_row(array($cell));
645 $strnever = new lang_string('never', 'calendar');
646 foreach ($subscriptions as $sub) {
647 $label = $sub->name;
648 if (!empty($sub->url)) {
649 $label = html_writer::link($sub->url, $label);
651 if (empty($sub->lastupdated)) {
652 $lastupdated = $strnever->out();
653 } else {
654 $lastupdated = userdate($sub->lastupdated, get_string('strftimedatetimeshort', 'langconfig'));
657 $cell = new html_table_cell($this->subscription_action_form($sub, $courseid));
658 $cell->colspan = 2;
659 $type = $sub->eventtype . 'events';
661 $table->data[] = new html_table_row(array(
662 new html_table_cell($label),
663 new html_table_cell($lastupdated),
664 new html_table_cell(get_string($type, 'calendar')),
665 $cell
669 $out = $this->output->box_start('generalbox calendarsubs');
671 $out .= $importresults;
672 $out .= html_writer::table($table);
673 $out .= $this->output->box_end();
674 return $out;
678 * Creates a form to perform actions on a given subscription.
680 * @param stdClass $subscription
681 * @param int $courseid
682 * @return string
684 protected function subscription_action_form($subscription, $courseid) {
685 // Assemble form for the subscription row.
686 $html = html_writer::start_tag('form', array('action' => new moodle_url('/calendar/managesubscriptions.php'), 'method' => 'post'));
687 if (empty($subscription->url)) {
688 // Don't update an iCal file, which has no URL.
689 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'pollinterval', 'value' => '0'));
690 } else {
691 // Assemble pollinterval control.
692 $html .= html_writer::start_tag('div', array('style' => 'float:left;'));
693 $html .= html_writer::start_tag('select', array('name' => 'pollinterval', 'class' => 'custom-select'));
694 foreach (calendar_get_pollinterval_choices() as $k => $v) {
695 $attributes = array();
696 if ($k == $subscription->pollinterval) {
697 $attributes['selected'] = 'selected';
699 $attributes['value'] = $k;
700 $html .= html_writer::tag('option', $v, $attributes);
702 $html .= html_writer::end_tag('select');
703 $html .= html_writer::end_tag('div');
705 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
706 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'course', 'value' => $courseid));
707 $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $subscription->id));
708 $html .= html_writer::start_tag('div', array('class' => 'btn-group pull-right'));
709 if (!empty($subscription->url)) {
710 $html .= html_writer::tag('button', get_string('update'), array('type' => 'submit', 'name' => 'action',
711 'class' => 'btn btn-secondary',
712 'value' => CALENDAR_SUBSCRIPTION_UPDATE));
714 $html .= html_writer::tag('button', get_string('remove'), array('type' => 'submit', 'name' => 'action',
715 'class' => 'btn btn-secondary',
716 'value' => CALENDAR_SUBSCRIPTION_REMOVE));
717 $html .= html_writer::end_tag('div');
718 $html .= html_writer::end_tag('form');
719 return $html;