From be39156fd89b2b35c6c611e58e1339bf3eb34c85 Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 3 Sep 2024 18:53:45 +0200 Subject: [PATCH] fix backport not used by get_instance --- .../backport/backport_cm_completion_details.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/classes/local/backport/backport_cm_completion_details.php b/classes/local/backport/backport_cm_completion_details.php index 06eaaef..61c2b4f 100644 --- a/classes/local/backport/backport_cm_completion_details.php +++ b/classes/local/backport/backport_cm_completion_details.php @@ -3,6 +3,7 @@ namespace local_adler\local\backport; +use cm_info; use core_completion\cm_completion_details as core_cm_completion_details; if (get_config('moodle', 'version') < 2023100900) { @@ -48,6 +49,22 @@ public function is_overall_complete(): bool { return in_array($this->get_overall_completion(), $completionstates); } + + /** + * From Moodle 4.4 to make backports work, as otherwise the baseclass is returned by this method. + * + * Generates an instance of this class. + * + * @param cm_info $cminfo The course module info instance. + * @param int $userid The user ID that we're fetching completion details for. + * @param bool $returndetails Whether to return completion details or not. + * @return core_cm_completion_details + */ + public static function get_instance(cm_info $cminfo, int $userid, bool $returndetails = true): core_cm_completion_details { + $course = $cminfo->get_course(); + $completioninfo = new \completion_info($course); + return new self($completioninfo, $cminfo, $userid, $returndetails); + } } } else { class backport_cm_completion_details extends core_cm_completion_details {