Skip to content

Commit

Permalink
fix computation of completionstatus for user
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe committed Aug 9, 2024
1 parent e532301 commit 289fb89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 9 additions & 9 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 289fb89

Please sign in to comment.