Skip to content

Commit

Permalink
show correct usercount in summary row of ratings_and_allocations_table
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe committed Aug 1, 2024
1 parent 89fbca3 commit dc23117
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
22 changes: 6 additions & 16 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1577,12 +1577,16 @@ public function get_ratings_for_rateable_choices_for_raters_without_alloc() {
* @throws dml_exception
*/
public function get_choices_with_allocationcount() {
$raters = array_map(function($rater) {
return $rater->id;
}, $this->get_raters_in_course());
$sql = 'SELECT c.*, al.usercount
FROM {ratingallocate_choices} c
LEFT JOIN (
SELECT choiceid, count( userid ) AS usercount
FROM {ratingallocate_allocations}
WHERE ratingallocateid =:ratingallocateid1
AND userid IN ( ' . implode(',', $raters) . ' )
GROUP BY choiceid
) AS al ON c.id = al.choiceid
WHERE c.ratingallocateid =:ratingallocateid and c.active = :active';
Expand All @@ -1600,33 +1604,19 @@ public function get_choices_with_allocationcount() {
* @return array all allocation objects that belong this ratingallocate
*/
public function get_allocations() {
$query = 'SELECT al.userid, al.*, r.rating
FROM {ratingallocate_allocations} al
LEFT JOIN {ratingallocate_choices} c ON al.choiceid = c.id
LEFT JOIN {ratingallocate_ratings} r ON al.choiceid = r.choiceid AND al.userid = r.userid
WHERE al.ratingallocateid = :ratingallocateid AND c.active = 1';
$records = $this->db->get_records_sql($query, [
'ratingallocateid' => $this->ratingallocateid,
]);
return $records;
}

/**
* Returns the allocation for each ENROLLED user. The keys of the returned array contain the userids.
* @return array all allocation objects that belong this ratingallocate
*/
public function get_valid_allocations() {
$raters = array_map(function($rater) {
return $rater->id;
}, $this->get_raters_in_course());

$query = 'SELECT al.userid, al.*, r.rating
FROM {ratingallocate_allocations} al
LEFT JOIN {ratingallocate_choices} c ON al.choiceid = c.id
LEFT JOIN {ratingallocate_ratings} r ON al.choiceid = r.choiceid AND al.userid = r.userid
WHERE al.ratingallocateid = :ratingallocateid AND c.active = 1
AND al.userid IN ( ' . implode(',', $raters) . ' )';
$records = $this->db->get_records_sql($query, [
'ratingallocateid' => $this->ratingallocateid,
'ratingallocateid' => $this->ratingallocateid,
]);
return $records;
}
Expand Down
2 changes: 1 addition & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public function statistics_table_for_ratingallocate(ratingallocate $ratingalloca
// Count the number of allocations with a specific rating.
$distributiondata = [];

$memberships = $ratingallocate->get_valid_allocations();
$memberships = $ratingallocate->get_allocations();

foreach ($memberships as $id => $membership) {
$rating = $membership->rating;
Expand Down

0 comments on commit dc23117

Please sign in to comment.