Commit f5d9ac96 authored by jun's avatar jun
Browse files

MDL-70821 course: Render activity information only when necessary

Render the activity information output component in the course homepage
only if either completion details or activity dates are to be displayed.
This can help reduce the number of files being included when loading the
course homepage (e.g. the activity information template for each
activity in the course homepage).
parent a5e6df51
......@@ -83,19 +83,34 @@ class cm_format implements renderable, templatable {
$displayoptions = $this->displayoptions;
$course = $mod->get_course();
$completiondetails = cm_completion_details::get_instance($mod, $USER->id, $course->showcompletionconditions);
// Fetch completion details.
$showcompletionconditions = $course->showcompletionconditions == COMPLETION_SHOW_CONDITIONS;
$completiondetails = cm_completion_details::get_instance($mod, $USER->id, $showcompletionconditions);
$ismanualcompletion = $completiondetails->has_completion() && !$completiondetails->is_automatic();
// Fetch activity dates.
$activitydates = [];
if ($course->showactivitydates) {
$activitydates = activity_dates::get_dates_for_module($mod, $USER->id);
}
$activityinfo = new activity_information($mod, $completiondetails, $activitydates);
$activityinfodata = null;
// Show the activity information if:
// - The course's showcompletionconditions setting is enabled; or
// - The activity tracks completion manually; or
// - There are activity dates to be shown.
if ($showcompletionconditions || $ismanualcompletion || $activitydates) {
$activityinfo = new activity_information($mod, $completiondetails, $activitydates);
$activityinfodata = $activityinfo->export_for_template($output);
}
$data = (object)[
'cmname' => $output->course_section_cm_name($mod, $displayoptions),
'afterlink' => $mod->afterlink,
'altcontent' => $output->course_section_cm_text($mod, $displayoptions),
'availability' => $output->course_section_cm_availability($mod, $displayoptions),
'url' => $mod->url,
'activityinfo' => $activityinfo->export_for_template($output),
'activityinfo' => $activityinfodata,
];
if (!empty($mod->indent)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment