From 0e93575f4f23d94b139b6039f4acd1171c10b7ec Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 8 Nov 2024 14:15:51 +1100 Subject: [PATCH 1/2] issue #34: make sure only active grading definition is returned --- locallib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locallib.php b/locallib.php index a512544..c6ac381 100755 --- a/locallib.php +++ b/locallib.php @@ -45,7 +45,7 @@ function get_grading_definition(int $assignid): \stdClass { JOIN {course_modules} cm ON cm.instance = assign.id JOIN {context} ctx ON ctx.instanceid = cm.id JOIN {grading_areas} ga ON ctx.id=ga.contextid - JOIN {grading_definitions} gdef ON ga.id = gdef.areaid + JOIN {grading_definitions} gdef ON (ga.id = gdef.areaid AND ga.activemethod = gdef.method) WHERE assign.id = :assignid"; $definition = $DB->get_record_sql($sql, ['assignid' => $assignid]); return $definition; From 9f6a3ff865a5f517e8b005ef366f2d488e3da721 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 8 Nov 2024 14:28:37 +1100 Subject: [PATCH 2/2] issue #33: display report link only for configured grading methods --- lib.php | 8 ++++++-- locallib.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib.php b/lib.php index 1b9a493..383796d 100755 --- a/lib.php +++ b/lib.php @@ -27,6 +27,8 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot.'/grade/grading/lib.php'); +require_once($CFG->dirroot . '/report/advancedgrading/locallib.php'); + global $PAGE; /** * Add an item to the dropdown when viewing the assignment @@ -36,8 +38,10 @@ * @return void */ function report_advancedgrading_extend_navigation_module(navigation_node $navigation, cm_info $cm) { - $context = \context_module::instance($cm->id); - if ($cm->modname == 'assign' && has_capability('moodle/grade:edit', $context)) { + $context = $cm->context; + $assignid = $cm->instance; + + if ($cm->modname == 'assign' && has_capability('moodle/grade:edit', $context) && !empty(get_grading_definition($assignid))) { $gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions'); switch ($gradingmanager->get_active_method()) { case 'rubric_ranges': diff --git a/locallib.php b/locallib.php index c6ac381..99313dc 100755 --- a/locallib.php +++ b/locallib.php @@ -36,9 +36,9 @@ * Get the structure of this grading definition * * @param int $assignid - * @return \stdClass + * @return false|\stdClass */ -function get_grading_definition(int $assignid): \stdClass { +function get_grading_definition(int $assignid) { global $DB; $sql = "SELECT gdef.id AS definitionid, ga.activemethod, gdef.name AS definition FROM {assign} assign