Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show users that unenrolled prior to the allocation in a seperate row #199

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions classes/allocations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,42 @@ public function build_table_by_sql() {
$noallocation->choicetitle = get_string(
'allocations_table_noallocation',
ratingallocate_MOD_NAME);
$enrolled_user_ids = array_map(function($x) {return $x->id;},
$this->ratingallocate->get_raters_in_course());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of $this->ratingallocate->get_raters_in_course(), you could use $users


foreach ($userwithrating as $userid => $user) {
// Ignore users that were not allocated due to them unenrolling from the course.
if (!in_array($userid, $enrolled_user_ids)) {
continue;
}
if (object_property_exists($noallocation, 'users')) {
$noallocation->users .= ', ';
} else {
$noallocation->users = '';
}
$noallocation->users .= $this->get_user_link($user);
unset($userwithrating[$userid]);
}
$data []= $noallocation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no unallocated users, $noallocation->users will be undefined. You could put all userlinks for noallocation in an array, and set $noallocation->users = implode(', ', $noallocationusers) afterwards (or do it the same way as around line 151).
Same goes for $unenrolled.

It looks like the problem has already existed before this PR, but it seems a good opportunity to fix it :)

}
// If there are useres, which rated but unenrolled prior to the allocation, add them to a special row.
if (count($userwithrating) > 0 AND ($this->currpage + 1) * $this->pagesize >= $this->totalrows) {
$unenrolled = new \stdClass();
$unenrolled->choicetitle = get_string(
'allocations_table_unenrolled',
ratingallocate_MOD_NAME);

foreach ($userwithrating as $userid => $user) {
if (object_property_exists($unenrolled, 'users')) {
$unenrolled->users .= ', ';
} else {
$unenrolled->users = '';
}
$unenrolled->users .= $this->get_user_link($user);
unset($userwithrating[$userid]);
}
$data []= $unenrolled;
}
}

// Finally, add all data to the table.
Expand Down
1 change: 1 addition & 0 deletions lang/en/ratingallocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
$string['allocations_table_choice'] = 'Choice';
$string['allocations_table_users'] = 'Users';
$string['allocations_table_noallocation'] = 'No Allocation';
$string['allocations_table_unenrolled'] = 'Users that unenrolled prior to the allocation';
$string['start_distribution_explanation'] = ' An algorithm will automatically try to fairly allocate the users according to their given ratings.';
$string['distribution_table'] = 'Distribution Table';
$string['download_problem_mps_format'] = 'Download Equation (mps/txt)';
Expand Down