MDL-1322 calendar: Add course short name in calendar event

* Add the course's short name for a course event in order to let the
user know immediately which course an event belongs to. Particularly
helpful for activity events.
This commit is contained in:
Jun Pataleta 2017-06-23 14:11:49 +08:00
parent f4a2d69631
commit 390098fa64
3 changed files with 26 additions and 1 deletions

View File

@ -1457,6 +1457,15 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
$name = format_string($event->name, true);
}
}
// Include course's shortname into the event name, if applicable.
if (!empty($event->courseid) && $event->courseid !== SITEID) {
$course = get_course($event->courseid);
$eventnameparams = (object)[
'name' => $name,
'course' => format_string($course->shortname, true, array('context' => $event->context))
];
$name = get_string('eventnameandcourse', 'calendar', $eventnameparams);
}
$popupcontent .= \html_writer::link($dayhref, $name);
$popupcontent .= \html_writer::end_tag('div');
}

View File

@ -502,7 +502,22 @@ class core_calendar_renderer extends plugin_renderer_base {
$attributes['class'] = $events[$eventindex]->class;
}
$dayhref->set_anchor('event_'.$events[$eventindex]->id);
$link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true));
$eventcontext = $events[$eventindex]->context;
$eventformatopts = array('context' => $eventcontext);
// Get event name.
$eventname = format_string($events[$eventindex]->name, true, $eventformatopts);
// Include course's shortname into the event name, if applicable.
$courseid = $events[$eventindex]->courseid;
if (!empty($courseid) && $courseid !== SITEID) {
$course = get_course($courseid);
$eventnameparams = (object)[
'name' => $eventname,
'course' => format_string($course->shortname, true, $eventformatopts)
];
$eventname = get_string('eventnameandcourse', 'calendar', $eventnameparams);
}
$link = html_writer::link($dayhref, $eventname);
$cell->text .= html_writer::tag('li', $link, $attributes);
}
$cell->text .= html_writer::end_tag('ul');

View File

@ -93,6 +93,7 @@ $string['eventendtime'] = 'End time';
$string['eventinstanttime'] = 'Time';
$string['eventkind'] = 'Type of event';
$string['eventname'] = 'Event title';
$string['eventnameandcourse'] = '{$a->course}: {$a->name}';
$string['eventnone'] = 'No events';
$string['eventrepeat'] = 'Repeats';
$string['eventsall'] = 'All events';