MDL-70818 mod_workshop: cache workshop times in modinfo for performance

This commit is contained in:
Shamim Rezaie
2021-04-23 13:46:28 +10:00
parent 2ad16d8d9e
commit 0b64b10eb9
+44
View File
@@ -2209,3 +2209,47 @@ function mod_workshop_get_path_from_pluginfile(string $filearea, array $args) :
'filepath' => $filepath,
];
}
/**
* Add a get_coursemodule_info function in case any feedback type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info|false An object on information that the courses will know about (most noticeably, an icon).
*/
function workshop_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, name, intro, introformat, submissionstart, submissionend, assessmentstart, assessmentend';
if (!$workshop = $DB->get_record('workshop', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
$result->name = $workshop->name;
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$result->content = format_module_intro('workshop', $workshop, $coursemodule->id, false);
}
// Populate some other values that can be used in calendar or on dashboard.
if ($workshop->submissionstart) {
$result->customdata['submissionstart'] = $workshop->submissionstart;
}
if ($workshop->submissionend) {
$result->customdata['submissionend'] = $workshop->submissionend;
}
if ($workshop->assessmentstart) {
$result->customdata['assessmentstart'] = $workshop->assessmentstart;
}
if ($workshop->assessmentend) {
$result->customdata['assessmentend'] = $workshop->assessmentend;
}
return $result;
}