Skip to content

Commit 5df8598

Browse files
committed
delete use of _ratingallocate as suffix
1 parent f14fc2b commit 5df8598

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

classes/completion/custom_completion.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace mod_ratingallocate\completion;
2020

21+
use context_module;
2122
use core_completion\activity_custom_completion;
2223

2324
/**
@@ -41,25 +42,37 @@ class custom_completion extends activity_custom_completion {
4142
*/
4243
public function get_state(string $rule): int {
4344
global $DB;
44-
45+
$status = false;
4546
$this->validate_rule($rule);
4647

4748
$userid = $this->userid;
48-
$ratingallocateid = $this->cm->instance;
49+
$course = $this->cm->get_course();
50+
$instance = $this->cm->instance;
4951

50-
if (!$DB->get_record('ratingallocate', ['id' => $ratingallocateid])) {
51-
throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $ratingallocateid);
52+
if (!$ratingallocaterecord= $DB->get_record('ratingallocate', ['id' => $instance])) {
53+
throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $instance);
5254
}
5355

56+
$modinfo = get_fast_modinfo($course, $userid)->instances['ratingallocate'][$instance];
57+
$context = context_module::instance($modinfo->id);
58+
59+
$ratingallocate = new \ratingallocate($ratingallocaterecord, $course, $this->cm, $context);
60+
5461
if ($rule == 'completionvote') {
62+
$status = count($ratingallocate->get_rating_data_for_user($userid)) > 0;
63+
/*
5564
$sql = "SELECT * FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c on r.choiceid=c.id " .
5665
"WHERE r.userid= :userid AND c.ratingallocateid= :ratingallocateid";
5766
$votesofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]);
5867
$status = count($votesofuser) > 0;
68+
*/
5969
} else if ($rule == 'completionallocation') {
70+
$status = count($ratingallocate->get_allocations_for_user($userid)) > 0;
71+
/*
6072
$sql = "SELECT * FROM {ratingallocate_allocations} WHERE userid= :userid AND ratingallocateid= :ratingallocateid";
6173
$allocationsofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]);
6274
$status = count($allocationsofuser) > 0;
75+
*/
6376
}
6477

6578
return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;

locallib.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,6 @@ private function process_action_manual_allocation() {
750750
$completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id);
751751
}
752752
}
753-
$raters = $this->get_raters_in_course();
754-
$completion = new completion_info($this->course);
755-
if ($completion->is_enabled($this->coursemodule)) {
756-
foreach ($raters as $rater) {
757-
$completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id);
758-
}
759-
}
760753
}
761754
$output .= $OUTPUT->heading(get_string('manual_allocation', RATINGALLOCATE_MOD_NAME), 2);
762755

mod_form.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ public function add_completion_rules() {
358358
* @return string
359359
*/
360360
protected function get_suffixed_name(string $fieldname): string {
361-
// Replace _ratingallocate with $this->get_suffix() for Moodle 4.3 or later.
362-
return 'completion' . $fieldname . '_ratingallocate';
361+
// Counterintuitively don't use function get_suffix(), since data isn't saved correctly in DB otherwise.
362+
return 'completion' . $fieldname;
363363
}
364364

365365
/**
@@ -401,7 +401,7 @@ public function data_postprocessing($data) {
401401
parent::data_postprocessing($data);
402402
// Turn off completion settings if the checkboxes aren't ticked.
403403
if (!empty($data->completionunlocked)) {
404-
$completion = $data->{'completion_ratingallocate'};
404+
$completion = $data->completion;
405405
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
406406
if (empty($data->{$this->get_suffixed_name('vote')}) || !$autocompletion) {
407407
$data->{$this->get_suffixed_name('vote')} = 0;

0 commit comments

Comments
 (0)