18
18
19
19
namespace mod_ratingallocate \completion ;
20
20
21
+ use context_module ;
21
22
use core_completion \activity_custom_completion ;
22
23
23
24
/**
@@ -41,25 +42,37 @@ class custom_completion extends activity_custom_completion {
41
42
*/
42
43
public function get_state (string $ rule ): int {
43
44
global $ DB ;
44
-
45
+ $ status = false ;
45
46
$ this ->validate_rule ($ rule );
46
47
47
48
$ userid = $ this ->userid ;
48
- $ ratingallocateid = $ this ->cm ->instance ;
49
+ $ course = $ this ->cm ->get_course ();
50
+ $ instance = $ this ->cm ->instance ;
49
51
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 );
52
54
}
53
55
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
+
54
61
if ($ rule == 'completionvote ' ) {
62
+ $ status = count ($ ratingallocate ->get_rating_data_for_user ($ userid )) > 0 ;
63
+ /*
55
64
$sql = "SELECT * FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c on r.choiceid=c.id " .
56
65
"WHERE r.userid= :userid AND c.ratingallocateid= :ratingallocateid";
57
66
$votesofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]);
58
67
$status = count($votesofuser) > 0;
68
+ */
59
69
} else if ($ rule == 'completionallocation ' ) {
70
+ $ status = count ($ ratingallocate ->get_allocations_for_user ($ userid )) > 0 ;
71
+ /*
60
72
$sql = "SELECT * FROM {ratingallocate_allocations} WHERE userid= :userid AND ratingallocateid= :ratingallocateid";
61
73
$allocationsofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]);
62
74
$status = count($allocationsofuser) > 0;
75
+ */
63
76
}
64
77
65
78
return $ status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE ;
0 commit comments