Skip to content

Commit

Permalink
show correct usercount in allocation statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe committed Jul 30, 2024
1 parent 6085cb3 commit 89fbca3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,15 @@ public function handle_view() {
* @return int
*/
public function get_number_of_active_raters() {
$raters = array_map(function($rater) {
return $rater->id;
}, $this->get_raters_in_course());
$sql = 'SELECT COUNT(DISTINCT ra_ratings.userid) AS number
FROM {ratingallocate} ra INNER JOIN {ratingallocate_choices} ra_choices
ON ra.id = ra_choices.ratingallocateid INNER JOIN {ratingallocate_ratings} ra_ratings
ON ra_choices.id = ra_ratings.choiceid
WHERE ra.course = :courseid AND ra.id = :ratingallocateid';
WHERE ra.course = :courseid AND ra.id = :ratingallocateid
AND ra_ratings.userid IN ( ' . implode(',', $raters) . ' )';
$numberofratersfromdb = $this->db->get_field_sql($sql, [
'courseid' => $this->course->id, 'ratingallocateid' => $this->ratingallocateid]);
return (int) $numberofratersfromdb;
Expand Down Expand Up @@ -1607,6 +1611,26 @@ public function get_allocations() {
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,
]);
return $records;
}

/**
* Removes all allocations for choices in $ratingallocateid
*/
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_allocations();
$memberships = $ratingallocate->get_valid_allocations();

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

0 comments on commit 89fbca3

Please sign in to comment.