From 2d19fa0d5f1aa9f45d4fc8fc6d99562098a7507a Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Mon, 8 Mar 2021 15:15:24 +1100 Subject: [PATCH] MDL-70818 mod_workshop: cache workshop times in modinfo for performance --- mod/workshop/lib.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 8140dcfa1e4..a6d0273a935 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -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; +} -- 2.11.4.GIT