From 289fb8976c93de621bbcf7296a825d9af4c0d9e2 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 9 Aug 2024 11:12:13 +0200 Subject: [PATCH] fix computation of completionstatus for user --- classes/completion/custom_completion.php | 18 +++++++++--------- lib.php | 2 -- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index 554c1210..e477c750 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -46,22 +46,22 @@ public function get_state(string $rule): int { $this->validate_rule($rule); $userid = $this->userid; - $course = $this->cm->get_course(); $instance = $this->cm->instance; - if (!$ratingallocaterecord = $DB->get_record('ratingallocate', ['id' => $instance])) { + if (!$DB->get_record('ratingallocate', ['id' => $instance])) { throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $instance); } - $modinfo = get_fast_modinfo($course, $userid)->instances['ratingallocate'][$instance]; - $context = context_module::instance($modinfo->id); - - $ratingallocate = new \ratingallocate($ratingallocaterecord, $course, $this->cm, $context); - if ($rule == 'completionvote') { - $status = count($ratingallocate->get_rating_data_for_user($userid)) > 0; + $sql = "SELECT * FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c on r.choiceid=c.id " . + "WHERE r.userid= :userid AND c.ratingallocateid= :ratingallocateid AND c.active=1"; + $votesofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $instance]); + $status = count($votesofuser) > 0; } else if ($rule == 'completionallocation') { - $status = count($ratingallocate->get_allocations_for_user($userid)) > 0; + $sql = "SELECT * FROM {ratingallocate_allocations} a INNER JOIN {ratingallocate_choices} c + ON a.choiceid = c.id WHERE userid= :userid AND a.ratingallocateid= :ratingallocateid AND c.active=1"; + $allocationsofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $instance]); + $status = count($allocationsofuser) > 0; } return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE; diff --git a/lib.php b/lib.php index dbdcac74..6f8a56ea 100644 --- a/lib.php +++ b/lib.php @@ -72,8 +72,6 @@ function ratingallocate_supports($feature) { return true; case FEATURE_COMPLETION_HAS_RULES: return true; - case FEATURE_COMPLETION_HAS_RULES: - return true; default : return null; }