2010-06-22 04:03:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file contains the renderers for the calendar within Moodle
|
|
|
|
*
|
|
|
|
* @copyright 2010 Sam Hemelryk
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
* @package calendar
|
|
|
|
*/
|
|
|
|
|
2012-10-15 16:31:12 +08:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
|
|
|
|
2010-06-22 04:03:44 +00:00
|
|
|
/**
|
|
|
|
* The primary renderer for the calendar.
|
|
|
|
*/
|
|
|
|
class core_calendar_renderer extends plugin_renderer_base {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the standard layout for the page
|
2010-09-17 11:49:11 +00:00
|
|
|
*
|
2010-06-22 04:03:44 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function start_layout() {
|
2017-07-10 10:10:54 +08:00
|
|
|
return html_writer::start_tag('div', ['data-region' => 'calendar', 'class' => 'maincalendar']);
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the remainder of the layout
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function complete_layout() {
|
|
|
|
return html_writer::end_tag('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Produces the content for the three months block (pretend block)
|
|
|
|
*
|
|
|
|
* This includes the previous month, the current month, and the next month
|
|
|
|
*
|
2021-11-19 03:12:09 +08:00
|
|
|
* @deprecated since 4.0 MDL-72810.
|
|
|
|
* @todo MDL-73117 This will be deleted in Moodle 4.4.
|
|
|
|
*
|
2010-06-22 04:03:44 +00:00
|
|
|
* @param calendar_information $calendar
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function fake_block_threemonths(calendar_information $calendar) {
|
2021-11-19 03:12:09 +08:00
|
|
|
debugging('This method is no longer used as the three month calendar block has been removed', DEBUG_DEVELOPER);
|
|
|
|
|
2013-09-16 17:30:59 +08:00
|
|
|
// Get the calendar type we are using.
|
|
|
|
$calendartype = \core_calendar\type_factory::get_calendar_instance();
|
2017-09-10 13:21:33 +08:00
|
|
|
$time = $calendartype->timestamp_to_date_array($calendar->time);
|
2010-06-22 04:03:44 +00:00
|
|
|
|
2017-09-10 13:21:33 +08:00
|
|
|
$current = $calendar->time;
|
2017-10-31 08:51:46 +08:00
|
|
|
$prevmonthyear = $calendartype->get_prev_month($time['year'], $time['mon']);
|
2017-09-10 13:21:33 +08:00
|
|
|
$prev = $calendartype->convert_to_timestamp(
|
2017-10-31 08:51:46 +08:00
|
|
|
$prevmonthyear[1],
|
|
|
|
$prevmonthyear[0],
|
|
|
|
1
|
2017-09-10 13:21:33 +08:00
|
|
|
);
|
2017-10-31 08:51:46 +08:00
|
|
|
$nextmonthyear = $calendartype->get_next_month($time['year'], $time['mon']);
|
2017-09-10 13:21:33 +08:00
|
|
|
$next = $calendartype->convert_to_timestamp(
|
2017-10-31 08:51:46 +08:00
|
|
|
$nextmonthyear[1],
|
|
|
|
$nextmonthyear[0],
|
|
|
|
1
|
2017-09-10 13:21:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
$content = '';
|
|
|
|
|
|
|
|
// Previous.
|
|
|
|
$calendar->set_time($prev);
|
2017-11-24 07:02:11 +00:00
|
|
|
list($previousmonth, ) = calendar_get_view($calendar, 'minithree', false, true);
|
2017-09-10 13:21:33 +08:00
|
|
|
|
|
|
|
// Current month.
|
|
|
|
$calendar->set_time($current);
|
2017-11-24 07:02:11 +00:00
|
|
|
list($currentmonth, ) = calendar_get_view($calendar, 'minithree', false, true);
|
2017-09-10 13:21:33 +08:00
|
|
|
|
|
|
|
// Next month.
|
|
|
|
$calendar->set_time($next);
|
2017-11-24 07:02:11 +00:00
|
|
|
list($nextmonth, ) = calendar_get_view($calendar, 'minithree', false, true);
|
2017-09-10 13:21:33 +08:00
|
|
|
|
|
|
|
// Reset the time back.
|
|
|
|
$calendar->set_time($current);
|
|
|
|
|
|
|
|
$data = (object) [
|
|
|
|
'previousmonth' => $previousmonth,
|
|
|
|
'currentmonth' => $currentmonth,
|
|
|
|
'nextmonth' => $nextmonth,
|
|
|
|
];
|
|
|
|
|
|
|
|
$template = 'core_calendar/calendar_threemonth';
|
|
|
|
$content .= $this->render_from_template($template, $data);
|
2010-06-22 04:03:44 +00:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a pretent calendar block
|
|
|
|
*
|
|
|
|
* @param block_contents $bc
|
|
|
|
* @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
|
|
|
|
*/
|
|
|
|
public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) {
|
2010-12-13 13:23:49 +00:00
|
|
|
$this->page->blocks->add_fake_block($bc, $pos);
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-18 12:47:37 +08:00
|
|
|
* Creates a button to add a new event.
|
2010-06-22 04:03:44 +00:00
|
|
|
*
|
|
|
|
* @param int $courseid
|
2017-09-18 12:47:37 +08:00
|
|
|
* @param int $unused1
|
|
|
|
* @param int $unused2
|
|
|
|
* @param int $unused3
|
|
|
|
* @param int $unused4
|
2010-06-22 04:03:44 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2017-09-18 12:47:37 +08:00
|
|
|
public function add_event_button($courseid, $unused1 = null, $unused2 = null, $unused3 = null, $unused4 = null) {
|
|
|
|
$data = [
|
|
|
|
'contextid' => (\context_course::instance($courseid))->id,
|
2017-07-24 08:01:14 +00:00
|
|
|
];
|
2017-09-18 12:47:37 +08:00
|
|
|
return $this->render_from_template('core_calendar/add_event_button', $data);
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays an event
|
|
|
|
*
|
2020-04-29 22:22:10 +02:00
|
|
|
* @deprecated since 3.9
|
|
|
|
*
|
2017-03-29 13:33:11 +08:00
|
|
|
* @param calendar_event $event
|
2010-06-22 04:03:44 +00:00
|
|
|
* @param bool $showactions
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-03-29 13:33:11 +08:00
|
|
|
public function event(calendar_event $event, $showactions=true) {
|
2013-01-17 11:11:15 +08:00
|
|
|
global $CFG;
|
2020-04-29 22:22:10 +02:00
|
|
|
debugging('This function is no longer used', DEBUG_DEVELOPER);
|
2013-01-17 11:11:15 +08:00
|
|
|
|
2017-03-30 12:18:32 +08:00
|
|
|
$event = calendar_add_event_metadata($event);
|
2013-11-19 08:33:04 -05:00
|
|
|
$context = $event->context;
|
2014-06-25 16:33:12 +12:00
|
|
|
$output = '';
|
2010-06-22 04:03:44 +00:00
|
|
|
|
2016-11-09 22:17:14 +08:00
|
|
|
$output .= $this->output->box_start('card-header clearfix');
|
2017-03-30 12:18:32 +08:00
|
|
|
if (calendar_edit_event_allowed($event) && $showactions) {
|
2017-08-09 14:48:06 +08:00
|
|
|
if (calendar_delete_event_allowed($event)) {
|
2016-11-22 11:57:38 +08:00
|
|
|
$editlink = new moodle_url(CALENDAR_URL.'event.php', array('action' => 'edit', 'id' => $event->id));
|
|
|
|
$deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id' => $event->id));
|
2016-11-09 22:17:14 +08:00
|
|
|
if (!empty($event->calendarcourseid)) {
|
|
|
|
$editlink->param('course', $event->calendarcourseid);
|
|
|
|
$deletelink->param('course', $event->calendarcourseid);
|
|
|
|
}
|
|
|
|
} else {
|
2016-11-22 11:57:38 +08:00
|
|
|
$params = array('update' => $event->cmid, 'return' => true, 'sesskey' => sesskey());
|
|
|
|
$editlink = new moodle_url('/course/mod.php', $params);
|
2016-11-09 22:17:14 +08:00
|
|
|
$deletelink = null;
|
|
|
|
}
|
|
|
|
|
2019-07-01 13:06:06 +02:00
|
|
|
$commands = html_writer::start_tag('div', array('class' => 'commands float-sm-right'));
|
2016-11-22 11:57:38 +08:00
|
|
|
$commands .= html_writer::start_tag('a', array('href' => $editlink));
|
2016-11-09 22:17:14 +08:00
|
|
|
$str = get_string('tt_editevent', 'calendar');
|
2017-01-19 16:20:27 +08:00
|
|
|
$commands .= $this->output->pix_icon('t/edit', $str);
|
2016-11-09 22:17:14 +08:00
|
|
|
$commands .= html_writer::end_tag('a');
|
|
|
|
if ($deletelink != null) {
|
2016-11-22 11:57:38 +08:00
|
|
|
$commands .= html_writer::start_tag('a', array('href' => $deletelink));
|
2016-11-09 22:17:14 +08:00
|
|
|
$str = get_string('tt_deleteevent', 'calendar');
|
2017-01-19 16:20:27 +08:00
|
|
|
$commands .= $this->output->pix_icon('t/delete', $str);
|
2016-11-09 22:17:14 +08:00
|
|
|
$commands .= html_writer::end_tag('a');
|
|
|
|
}
|
|
|
|
$commands .= html_writer::end_tag('div');
|
|
|
|
$output .= $commands;
|
|
|
|
}
|
2010-06-22 04:03:44 +00:00
|
|
|
if (!empty($event->icon)) {
|
2014-06-25 16:33:12 +12:00
|
|
|
$output .= $event->icon;
|
2010-06-22 04:03:44 +00:00
|
|
|
} else {
|
2014-06-25 16:33:12 +12:00
|
|
|
$output .= $this->output->spacer(array('height' => 16, 'width' => 16));
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($event->referer)) {
|
2014-06-25 16:33:12 +12:00
|
|
|
$output .= $this->output->heading($event->referer, 3, array('class' => 'referer'));
|
2010-06-22 04:03:44 +00:00
|
|
|
} else {
|
2014-06-25 16:33:12 +12:00
|
|
|
$output .= $this->output->heading(
|
|
|
|
format_string($event->name, false, array('context' => $context)),
|
|
|
|
3,
|
2016-11-09 22:17:14 +08:00
|
|
|
array('class' => 'name d-inline-block')
|
2014-06-25 16:33:12 +12:00
|
|
|
);
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
2013-01-17 11:11:15 +08:00
|
|
|
// Show subscription source if needed.
|
|
|
|
if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
|
|
|
|
if (!empty($event->subscription->url)) {
|
2017-09-12 10:47:01 +08:00
|
|
|
$source = html_writer::link($event->subscription->url,
|
|
|
|
get_string('subscriptionsource', 'calendar', $event->subscription->name));
|
2013-01-17 11:11:15 +08:00
|
|
|
} else {
|
|
|
|
// File based ical.
|
2017-09-12 10:47:01 +08:00
|
|
|
$source = get_string('subscriptionsource', 'calendar', $event->subscription->name);
|
2013-01-17 11:11:15 +08:00
|
|
|
}
|
2014-06-25 16:33:12 +12:00
|
|
|
$output .= html_writer::tag('div', $source, array('class' => 'subscription'));
|
2012-12-27 15:06:37 +08:00
|
|
|
}
|
2017-04-04 14:32:35 +08:00
|
|
|
if (!empty($event->courselink)) {
|
2017-08-17 14:41:18 +08:00
|
|
|
$output .= html_writer::tag('div', $event->courselink);
|
2017-04-04 14:32:35 +08:00
|
|
|
}
|
2010-06-22 04:03:44 +00:00
|
|
|
if (!empty($event->time)) {
|
2019-07-01 13:06:06 +02:00
|
|
|
$output .= html_writer::tag('span', $event->time, array('class' => 'date float-sm-right mr-1'));
|
2010-06-22 04:03:44 +00:00
|
|
|
} else {
|
2019-07-01 13:06:06 +02:00
|
|
|
$attrs = array('class' => 'date float-sm-right mr-1');
|
2017-03-30 12:18:32 +08:00
|
|
|
$output .= html_writer::tag('span', calendar_time_representation($event->timestart), $attrs);
|
2016-11-09 22:17:14 +08:00
|
|
|
}
|
2017-04-04 14:32:35 +08:00
|
|
|
|
|
|
|
if (!empty($event->actionurl)) {
|
2017-08-17 14:41:18 +08:00
|
|
|
$actionlink = html_writer::link(new moodle_url($event->actionurl), $event->actionname);
|
|
|
|
$output .= html_writer::tag('div', $actionlink, ['class' => 'action']);
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 22:17:14 +08:00
|
|
|
$output .= $this->output->box_end();
|
2014-06-25 16:33:12 +12:00
|
|
|
$eventdetailshtml = '';
|
|
|
|
$eventdetailsclasses = '';
|
2010-06-22 04:03:44 +00:00
|
|
|
|
2014-06-25 16:33:12 +12:00
|
|
|
$eventdetailshtml .= format_text($event->description, $event->format, array('context' => $context));
|
2016-11-09 22:17:14 +08:00
|
|
|
$eventdetailsclasses .= 'description card-block';
|
2010-06-22 04:03:44 +00:00
|
|
|
if (isset($event->cssclass)) {
|
2014-06-25 16:33:12 +12:00
|
|
|
$eventdetailsclasses .= ' '.$event->cssclass;
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 22:17:14 +08:00
|
|
|
if (!empty($eventdetailshtml)) {
|
|
|
|
$output .= html_writer::tag('div', $eventdetailshtml, array('class' => $eventdetailsclasses));
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
2016-11-09 22:17:14 +08:00
|
|
|
|
|
|
|
$eventhtml = html_writer::tag('div', $output, array('class' => 'card'));
|
|
|
|
return html_writer::tag('div', $eventhtml, array('class' => 'event', 'id' => 'event_' . $event->id));
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a course filter selector
|
|
|
|
*
|
2014-01-30 09:39:11 +13:00
|
|
|
* @param moodle_url $returnurl The URL that the user should be taken too upon selecting a course.
|
|
|
|
* @param string $label The label to use for the course select.
|
2017-10-20 15:13:41 +08:00
|
|
|
* @param int $courseid The id of the course to be selected.
|
2021-07-20 01:52:25 +08:00
|
|
|
* @param int|null $calendarinstanceid The instance ID of the calendar we're generating this course filter for.
|
2010-06-22 04:03:44 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2021-07-20 01:52:25 +08:00
|
|
|
public function course_filter_selector(moodle_url $returnurl, $label = null, $courseid = null, int $calendarinstanceid = null) {
|
2017-11-27 07:13:19 +00:00
|
|
|
global $CFG, $DB;
|
2010-06-22 04:03:44 +00:00
|
|
|
|
|
|
|
if (!isloggedin() or isguestuser()) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-11-27 07:13:19 +00:00
|
|
|
$contextrecords = [];
|
2017-10-26 14:21:29 +08:00
|
|
|
$courses = calendar_get_default_courses($courseid, 'id, shortname');
|
2010-06-22 04:03:44 +00:00
|
|
|
|
2017-11-27 07:13:19 +00:00
|
|
|
if (!empty($courses) && count($courses) > CONTEXT_CACHE_MAX_SIZE) {
|
|
|
|
// We need to pull the context records from the DB to preload them
|
|
|
|
// below. The calendar_get_default_courses code will actually preload
|
|
|
|
// the contexts itself however the context cache is capped to a certain
|
|
|
|
// amount before it starts recycling. Unfortunately that starts to happen
|
|
|
|
// quite a bit if a user has access to a large number of courses (e.g. admin).
|
|
|
|
// So in order to avoid hitting the DB for each context as we loop below we
|
|
|
|
// can load all of the context records and add them to the cache just in time.
|
|
|
|
$courseids = array_map(function($c) {
|
|
|
|
return $c->id;
|
|
|
|
}, $courses);
|
|
|
|
list($insql, $params) = $DB->get_in_or_equal($courseids);
|
|
|
|
$contextsql = "SELECT ctx.instanceid, " . context_helper::get_preload_record_columns_sql('ctx') .
|
|
|
|
" FROM {context} ctx WHERE ctx.contextlevel = ? AND ctx.instanceid $insql";
|
|
|
|
array_unshift($params, CONTEXT_COURSE);
|
|
|
|
$contextrecords = $DB->get_records_sql($contextsql, $params);
|
|
|
|
}
|
|
|
|
|
2010-06-22 04:03:44 +00:00
|
|
|
unset($courses[SITEID]);
|
|
|
|
|
|
|
|
$courseoptions = array();
|
|
|
|
$courseoptions[SITEID] = get_string('fulllistofcourses');
|
|
|
|
foreach ($courses as $course) {
|
2017-11-27 07:13:19 +00:00
|
|
|
if (isset($contextrecords[$course->id])) {
|
|
|
|
context_helper::preload_from_record($contextrecords[$course->id]);
|
|
|
|
}
|
2012-07-23 16:22:36 +08:00
|
|
|
$coursecontext = context_course::instance($course->id);
|
2011-09-07 11:46:28 +12:00
|
|
|
$courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext));
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 15:13:41 +08:00
|
|
|
if ($courseid) {
|
|
|
|
$selected = $courseid;
|
|
|
|
} else if ($this->page->course->id !== SITEID) {
|
2011-06-29 14:50:38 +08:00
|
|
|
$selected = $this->page->course->id;
|
2010-06-22 04:03:44 +00:00
|
|
|
} else {
|
|
|
|
$selected = '';
|
|
|
|
}
|
2014-01-30 09:39:11 +13:00
|
|
|
$courseurl = new moodle_url($returnurl);
|
|
|
|
$courseurl->remove_params('course');
|
2017-09-04 09:03:50 +08:00
|
|
|
|
2020-02-21 19:42:06 +11:00
|
|
|
$labelattributes = [];
|
|
|
|
if (empty($label)) {
|
2017-09-04 09:03:50 +08:00
|
|
|
$label = get_string('listofcourses');
|
2020-02-21 19:42:06 +11:00
|
|
|
$labelattributes['class'] = 'sr-only';
|
2010-08-30 04:11:42 +00:00
|
|
|
}
|
2017-09-04 09:03:50 +08:00
|
|
|
|
2021-07-20 01:52:25 +08:00
|
|
|
$filterid = 'calendar-course-filter';
|
|
|
|
if ($calendarinstanceid) {
|
|
|
|
$filterid .= "-$calendarinstanceid";
|
|
|
|
}
|
|
|
|
$select = html_writer::label($label, $filterid, false, $labelattributes);
|
2019-06-06 14:08:43 +08:00
|
|
|
$select .= html_writer::select($courseoptions, 'course', $selected, false,
|
2021-07-20 01:52:25 +08:00
|
|
|
['class' => 'cal_courses_flt ml-1 mr-auto', 'id' => $filterid]);
|
2017-09-04 09:03:50 +08:00
|
|
|
|
|
|
|
return $select;
|
2010-06-22 04:03:44 +00:00
|
|
|
}
|
2012-10-15 16:31:12 +08:00
|
|
|
|
2021-07-07 14:53:01 +07:00
|
|
|
/**
|
|
|
|
* Render the subscriptions header
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function render_subscriptions_header(): string {
|
|
|
|
$importcalendarbutton = new single_button(new moodle_url('/calendar/import.php', calendar_get_export_import_link_params()),
|
|
|
|
get_string('importcalendar', 'calendar'), 'get', true);
|
|
|
|
$importcalendarbutton->class .= ' float-sm-right float-right';
|
|
|
|
$exportcalendarbutton = new single_button(new moodle_url('/calendar/export.php', calendar_get_export_import_link_params()),
|
|
|
|
get_string('exportcalendar', 'calendar'), 'get', true);
|
|
|
|
$exportcalendarbutton->class .= ' float-sm-right float-right';
|
|
|
|
$output = $this->output->heading(get_string('managesubscriptions', 'calendar'));
|
|
|
|
$output .= html_writer::start_div('header d-flex flex-wrap mt-5');
|
2021-08-30 18:13:30 +08:00
|
|
|
$headerattr = [
|
|
|
|
'class' => 'mr-auto',
|
|
|
|
'aria-describedby' => 'subscription_details_table',
|
|
|
|
];
|
|
|
|
$output .= html_writer::tag('h3', get_string('yoursubscriptions', 'calendar'), $headerattr);
|
2021-07-07 14:53:01 +07:00
|
|
|
$output .= $this->output->render($importcalendarbutton);
|
|
|
|
$output .= $this->output->render($exportcalendarbutton);
|
|
|
|
$output .= html_writer::end_div();
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the subscriptions blank state appearance
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function render_no_calendar_subscriptions(): string {
|
|
|
|
$output = html_writer::start_div('mt-5');
|
|
|
|
$importlink = html_writer::link((new moodle_url('/calendar/import.php', calendar_get_export_import_link_params()))->out(),
|
|
|
|
get_string('importcalendarexternal', 'calendar'));
|
|
|
|
$output .= get_string('nocalendarsubscriptions', 'calendar', $importlink);
|
|
|
|
$output .= html_writer::end_div();
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2012-10-15 16:31:12 +08:00
|
|
|
/**
|
|
|
|
* Renders a table containing information about calendar subscriptions.
|
|
|
|
*
|
2017-10-06 09:05:41 +08:00
|
|
|
* @param int $unused
|
2012-10-15 16:31:12 +08:00
|
|
|
* @param array $subscriptions
|
2021-07-07 14:53:01 +07:00
|
|
|
* @param string $unused2
|
2012-10-15 16:31:12 +08:00
|
|
|
* @return string
|
|
|
|
*/
|
2021-07-07 14:53:01 +07:00
|
|
|
public function subscription_details($unused, $subscriptions, $unused2 = '') {
|
2012-10-15 16:31:12 +08:00
|
|
|
$table = new html_table();
|
|
|
|
$table->head = array(
|
|
|
|
get_string('colcalendar', 'calendar'),
|
|
|
|
get_string('collastupdated', 'calendar'),
|
2012-12-28 11:35:02 +08:00
|
|
|
get_string('eventkind', 'calendar'),
|
2012-10-15 16:31:12 +08:00
|
|
|
get_string('colpoll', 'calendar'),
|
|
|
|
get_string('colactions', 'calendar')
|
|
|
|
);
|
|
|
|
$table->data = array();
|
2021-07-07 14:53:01 +07:00
|
|
|
$table->id = 'subscription_details_table';
|
2012-10-15 16:31:12 +08:00
|
|
|
|
|
|
|
if (empty($subscriptions)) {
|
|
|
|
$cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar'));
|
2015-06-18 13:21:33 +01:00
|
|
|
$cell->colspan = 5;
|
2012-10-15 16:31:12 +08:00
|
|
|
$table->data[] = new html_table_row(array($cell));
|
|
|
|
}
|
|
|
|
$strnever = new lang_string('never', 'calendar');
|
|
|
|
foreach ($subscriptions as $sub) {
|
|
|
|
$label = $sub->name;
|
|
|
|
if (!empty($sub->url)) {
|
|
|
|
$label = html_writer::link($sub->url, $label);
|
|
|
|
}
|
|
|
|
if (empty($sub->lastupdated)) {
|
|
|
|
$lastupdated = $strnever->out();
|
|
|
|
} else {
|
|
|
|
$lastupdated = userdate($sub->lastupdated, get_string('strftimedatetimeshort', 'langconfig'));
|
|
|
|
}
|
|
|
|
|
2012-12-28 11:35:02 +08:00
|
|
|
$type = $sub->eventtype . 'events';
|
2021-08-01 21:18:51 +07:00
|
|
|
$calendarname = new html_table_cell($label);
|
|
|
|
$calendarname->header = true;
|
2012-10-15 16:31:12 +08:00
|
|
|
|
2021-08-01 21:18:51 +07:00
|
|
|
$tablerow = new html_table_row(array(
|
|
|
|
$calendarname,
|
2012-10-15 16:31:12 +08:00
|
|
|
new html_table_cell($lastupdated),
|
2012-12-28 11:35:02 +08:00
|
|
|
new html_table_cell(get_string($type, 'calendar')),
|
2021-07-07 14:53:01 +07:00
|
|
|
new html_table_cell($this->render_subscription_update_interval($sub)),
|
2021-08-01 21:18:51 +07:00
|
|
|
new html_table_cell($this->subscription_action_links())
|
2012-10-15 16:31:12 +08:00
|
|
|
));
|
2021-08-01 21:18:51 +07:00
|
|
|
$tablerow->attributes += [
|
|
|
|
'data-subid' => $sub->id,
|
|
|
|
'data-subname' => $sub->name
|
|
|
|
];
|
|
|
|
$table->data[] = $tablerow;
|
2012-10-15 16:31:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$out = $this->output->box_start('generalbox calendarsubs');
|
|
|
|
|
|
|
|
$out .= html_writer::table($table);
|
|
|
|
$out .= $this->output->box_end();
|
2021-08-01 21:18:51 +07:00
|
|
|
|
|
|
|
$this->page->requires->js_call_amd('core_calendar/manage_subscriptions', 'init');
|
2012-10-15 16:31:12 +08:00
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-07 14:53:01 +07:00
|
|
|
* Render subscription update interval form.
|
2012-10-15 16:31:12 +08:00
|
|
|
*
|
|
|
|
* @param stdClass $subscription
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-07-07 14:53:01 +07:00
|
|
|
protected function render_subscription_update_interval(stdClass $subscription): string {
|
2012-10-15 16:31:12 +08:00
|
|
|
if (empty($subscription->url)) {
|
2021-08-01 21:18:51 +07:00
|
|
|
return '';
|
2012-10-15 16:31:12 +08:00
|
|
|
}
|
2021-07-07 14:53:01 +07:00
|
|
|
|
2021-08-01 21:18:51 +07:00
|
|
|
$tmpl = new \core_calendar\output\refreshintervalcollection($subscription);
|
|
|
|
return $this->output->render_from_template('core/inplace_editable', $tmpl->export_for_template($this->output));
|
2021-07-07 14:53:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form to perform actions on a given subscription.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-08-01 21:18:51 +07:00
|
|
|
protected function subscription_action_links(): string {
|
|
|
|
$html = html_writer::start_tag('div', array('class' => 'btn-group float-left'));
|
|
|
|
$html .= html_writer::span(html_writer::link('#', get_string('delete'),
|
|
|
|
['data-action' => 'delete-subscription']), '');
|
2012-10-15 16:31:12 +08:00
|
|
|
$html .= html_writer::end_tag('div');
|
|
|
|
return $html;
|
|
|
|
}
|
2017-09-01 14:58:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the event filter region.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function event_filter() {
|
|
|
|
$data = [
|
|
|
|
'eventtypes' => calendar_get_filter_types(),
|
|
|
|
];
|
|
|
|
return $this->render_from_template('core_calendar/event_filter', $data);
|
|
|
|
}
|
2021-08-01 21:18:51 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the calendar import result.
|
|
|
|
*
|
|
|
|
* @param array $result Import result
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function render_import_result(array $result): ?string {
|
|
|
|
$data = [
|
|
|
|
'eventsimported' => $result['eventsimported'],
|
|
|
|
'eventsskipped' => $result['eventsskipped'],
|
|
|
|
'eventsupdated' => $result['eventsupdated'],
|
|
|
|
'eventsdeleted' => $result['eventsdeleted'],
|
|
|
|
'haserror' => $result['haserror'],
|
|
|
|
'errors' => $result['errors']
|
|
|
|
];
|
|
|
|
|
|
|
|
return $this->render_from_template('core_calendar/subscription_update_result', $data);
|
|
|
|
}
|
2014-01-02 11:27:23 +08:00
|
|
|
}
|