MDL-71775 block_calendar_month: add footer options

This commit is contained in:
Simey Lameze 2021-07-13 14:14:33 +08:00
parent c357779722
commit f58750c2a5
8 changed files with 143 additions and 36 deletions

View File

@ -61,6 +61,13 @@ class block_calendar_month extends block_base {
$this->content->text .= $renderer->event_filter();
}
$options = [
'showexportlink' => false,
'showfullcalendarlink' => true
];
list($footerdata, $footertemplate) = calendar_get_footer_options($calendar, $options);
$this->content->footer .= $renderer->render_from_template($footertemplate, $footerdata);
return $this->content;
}
}

View File

@ -53,17 +53,33 @@ class footer_options_exporter extends exporter {
*/
protected $token;
/**
* @var bool $showexportlink Whether the export link should be displayed or not.
*/
protected $showexportlink;
/**
* @var bool $showfullcalendarlink Whether the full calendar link should be displayed or not.
*/
protected $showfullcalendarlink;
/**
* Constructor for month_exporter.
*
* @param \calendar_information $calendar The calendar being represented
* @param int $userid The user id
* @param string $token The user sha1 token.
* @param array $options Display options for the footer. If an option is not set, a default value will be provided.
* It consists of:
* - showexportlink - bool - Whether to show the export link or not. Defaults to true.
* - showfullcalendarlink - bool - Whether to show the full calendar link or not. Defaults to false.
*/
public function __construct(\calendar_information $calendar, $userid, $token) {
public function __construct(\calendar_information $calendar, $userid, $token, array $options = []) {
$this->calendar = $calendar;
$this->userid = $userid;
$this->token = $token;
$this->showexportlink = $options['showexportlink'] ?? true;
$this->showfullcalendarlink = $options['showfullcalendarlink'] ?? false;
}
/**
@ -115,11 +131,28 @@ class footer_options_exporter extends exporter {
global $CFG;
$values = new stdClass();
$values->footerlinks = [];
if ($this->showfullcalendarlink) {
$values->footerlinks[] = (object)[
'url' => $this->get_calendar_url(),
'linkname' => get_string('fullcalendar', 'calendar'),
];
}
if (!empty($CFG->enablecalendarexport)) {
$values->exportcalendarlink = $this->get_export_calendar_link();
if ($this->showexportlink) {
$values->footerlinks[] = (object)[
'url' => $this->get_export_calendar_link(),
'linkname' => get_string('exportcalendar', 'calendar'),
];
}
if ($managesubscriptionlink = $this->get_manage_subscriptions_link()) {
$values->managesubscriptionlink = $managesubscriptionlink;
$values->footerlinks[] = (object)[
'url' => $managesubscriptionlink,
'linkname' => get_string('managesubscriptions', 'calendar'),
];
}
}
@ -132,14 +165,39 @@ class footer_options_exporter extends exporter {
* @return array
*/
public static function define_other_properties() {
return array(
'exportcalendarlink' => [
'type' => PARAM_URL
],
'managesubscriptionlink' => [
return [
'footerlinks' => [
'type' => [
'url' => [
'type' => PARAM_URL,
'default' => null,
],
);
'linkname' => [
'type' => PARAM_TEXT,
],
],
'multiple' => true,
'optional' => true,
],
];
}
/**
* Build the calendar URL.
*
* @return string The calendar URL.
*/
public function get_calendar_url() {
$url = new moodle_url('/calendar/view.php', [
'view' => 'month',
'time' => $this->calendar->time,
]);
if ($this->calendar->course && SITEID !== $this->calendar->course->id) {
$url->param('course', $this->calendar->course->id);
} else if ($this->calendar->categoryid) {
$url->param('category', $this->calendar->categoryid);
}
return $url->out(false);
}
}

View File

@ -3679,16 +3679,21 @@ function calendar_get_timestamp($d, $m, $y, $time = 0) {
* Get the calendar footer options.
*
* @param calendar_information $calendar The calendar information object.
* @param array $options Display options for the footer. If an option is not set, a default value will be provided.
* It consists of:
* - showexportlink - bool - Whether to show the export link or not. Defaults to true.
* - showfullcalendarlink - bool - Whether to show the full calendar link or not. Defaults to false.
*
* @return array The data for template and template name.
*/
function calendar_get_footer_options($calendar) {
function calendar_get_footer_options($calendar, array $options = []) {
global $CFG, $USER, $PAGE;
// Generate hash for iCal link.
$authtoken = calendar_get_export_token($USER);
$renderer = $PAGE->get_renderer('core_calendar');
$footer = new \core_calendar\external\footer_options_exporter($calendar, $USER->id, $authtoken);
$footer = new \core_calendar\external\footer_options_exporter($calendar, $USER->id, $authtoken, $options);
$data = $footer->export($renderer);
$template = 'core_calendar/footer_options';

View File

@ -21,19 +21,22 @@
Example context (json):
{
"exportcalendarlink": "http://abc.com/calendar/export.php?course=1",
"managesubscriptionlink": "http://abc.com/calendar/managesubscriptions.php?course=1"
"footerlinks": [
{
"url": "calendar/view.php?view=month",
"linkname": "Full calendar"
},
{
"url": "calendar/managesubscriptions.php",
"linkname": "Manage subcriptions"
}
]
}
}}
<div class="bottom">
{{#exportcalendarlink}}
<span class="export-link">
<a href="{{.}}" title={{#quote}}{{#str}}exportcalendar, calendar{{/str}}{{/quote}}>{{#str}}exportcalendar, calendar{{/str}}</a>
{{#footerlinks}}
<span class="footer-link">
<a href="{{url}}">{{linkname}}</a>
</span>
{{/exportcalendarlink}}
{{#managesubscriptionlink}}
<span class="export-link">
<a href="{{.}}" title={{#quote}}{{#str}}managesubscriptions, calendar{{/str}}{{/quote}}>{{#str}}managesubscriptions, calendar{{/str}}</a>
</span>
{{/managesubscriptionlink}}
{{/footerlinks}}
</div>

View File

@ -145,6 +145,7 @@ $string['exportcalendar'] = 'Export calendar';
$string['forcecalendartype'] = 'Force calendar';
$string['fri'] = 'Fri';
$string['friday'] = 'Friday';
$string['fullcalendar'] = 'Full calendar';
$string['generateurlbutton'] = 'Get calendar URL';
$string['gotoactivity'] = 'Go to activity';
$string['gotocalendar'] = 'Go to calendar';

View File

@ -61,6 +61,17 @@ $calendarEventColor: #0d5ca1 !default;
}
}
@mixin footer-links {
span.footer-link:after {
content: "\2022";
color: $blue;
}
span.footer-link:last-child:after {
content: none;
}
}
// Calendar restyling.
.path-calendar {
.calendartable {
@ -122,14 +133,7 @@ $calendarEventColor: #0d5ca1 !default;
text-align: left;
padding: 20px 0 0 20px;
span.export-link:after {
content: "\2022";
color: $blue;
}
span.export-link:last-child:after {
content: none;
}
@include footer-links;
}
.heightcontainer {
@ -311,6 +315,15 @@ $calendarEventColor: #0d5ca1 !default;
// Block minicalendar.
.block {
.bottom {
// This adds a border on the top side of the footer container so we won't have to add a <hr> element in the footer_options template.
border-top: $border-width solid $card-border-color;
margin-top: map-get($spacers, 3);
padding-top: map-get($spacers, 2);
@include footer-links;
}
.minicalendar {
max-width: 280px;
margin: 0 auto;

View File

@ -12908,10 +12908,10 @@ input[disabled] {
.path-calendar .maincalendar .bottom {
text-align: left;
padding: 20px 0 0 20px; }
.path-calendar .maincalendar .bottom span.export-link:after {
.path-calendar .maincalendar .bottom span.footer-link:after {
content: "\2022";
color: #0f6fc5; }
.path-calendar .maincalendar .bottom span.export-link:last-child:after {
.path-calendar .maincalendar .bottom span.footer-link:last-child:after {
content: none; }
.path-calendar .maincalendar .heightcontainer {
height: 100%;
@ -13011,6 +13011,16 @@ input[disabled] {
#page-calendar-export .indent {
padding-left: 20px; }
.block .bottom {
border-top: 1px solid rgba(0, 0, 0, 0.125);
margin-top: 1rem;
padding-top: 0.5rem; }
.block .bottom span.footer-link:after {
content: "\2022";
color: #0f6fc5; }
.block .bottom span.footer-link:last-child:after {
content: none; }
.block .minicalendar {
max-width: 280px;
margin: 0 auto;

View File

@ -13130,10 +13130,10 @@ input[disabled] {
.path-calendar .maincalendar .bottom {
text-align: left;
padding: 20px 0 0 20px; }
.path-calendar .maincalendar .bottom span.export-link:after {
.path-calendar .maincalendar .bottom span.footer-link:after {
content: "\2022";
color: #0f6fc5; }
.path-calendar .maincalendar .bottom span.export-link:last-child:after {
.path-calendar .maincalendar .bottom span.footer-link:last-child:after {
content: none; }
.path-calendar .maincalendar .heightcontainer {
height: 100%;
@ -13233,6 +13233,16 @@ input[disabled] {
#page-calendar-export .indent {
padding-left: 20px; }
.block .bottom {
border-top: 1px solid rgba(0, 0, 0, 0.125);
margin-top: 1rem;
padding-top: 0.5rem; }
.block .bottom span.footer-link:after {
content: "\2022";
color: #0f6fc5; }
.block .bottom span.footer-link:last-child:after {
content: none; }
.block .minicalendar {
max-width: 280px;
margin: 0 auto;