From b42e47fb4afe240c11251806399f6b5cd21cd2e5 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Tue, 2 May 2023 13:28:49 +0800 Subject: [PATCH] MDL-78066 enrol_lti: fix deep linking error in multiple grade items case If an activity, like workshop or forum, has multiple grade items, declarative binding of the grade item (line item) isn't supported. Instead of throwing an exception, handle the case more elegantly and just omit the 'add to gradebook' option for these activities. --- .../published_resource_repository.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/enrol/lti/classes/local/ltiadvantage/repository/published_resource_repository.php b/enrol/lti/classes/local/ltiadvantage/repository/published_resource_repository.php index ddf6a2e7e58..497ffdbdb36 100644 --- a/enrol/lti/classes/local/ltiadvantage/repository/published_resource_repository.php +++ b/enrol/lti/classes/local/ltiadvantage/repository/published_resource_repository.php @@ -96,19 +96,20 @@ class published_resource_repository { $resource->supportsgrades = false; $resource->grademax = null; - // Only activities with GRADE_TYPE_VALUE are valid. + // Only activities having a single grade item of GRADE_TYPE_VALUE are eligible for declarative binding. if (plugin_supports('mod', $mod->modname, FEATURE_GRADE_HAS_GRADE)) { - $gradeitem = \grade_item::fetch([ - 'courseid' => $resource->courseid, - 'itemtype' => 'mod', - 'itemmodule' => $mod->modname, - 'iteminstance' => $mod->instance - ]); - if ($gradeitem && $gradeitem->gradetype == GRADE_TYPE_VALUE) { - $gradinginfo = grade_get_grades($resource->courseid, 'mod', $mod->modname, - $mod->instance); - $resource->supportsgrades = true; - $resource->grademax = (int) $gradinginfo->items[0]->grademax; + $gradinginfo = grade_get_grades($resource->courseid, 'mod', $mod->modname, $mod->instance); + if (count($gradinginfo->items) == 1) { + $gradeitem = \grade_item::fetch([ + 'courseid' => $resource->courseid, + 'itemtype' => 'mod', + 'itemmodule' => $mod->modname, + 'iteminstance' => $mod->instance + ]); + if ($gradeitem && $gradeitem->gradetype == GRADE_TYPE_VALUE) { + $resource->supportsgrades = true; + $resource->grademax = (int)$gradinginfo->items[0]->grademax; + } } } $availableresources[] = $resource;