Skip to content

Commit

Permalink
modify allocations_table for teamvote
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe committed Sep 19, 2024
1 parent ba2786a commit fb56992
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
33 changes: 33 additions & 0 deletions classes/allocations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function __construct($ratingallocate) {
$download = optional_param('download', '', PARAM_ALPHA);
$this->is_downloading($download, $ratingallocate->ratingallocate->name . '-allocations', 'allocations');
}
// If teamvote is enabled, show allocation of teams.
$this->showteams = (bool) $this->ratingallocate->get_teamvote_groups();
}

/**
Expand Down Expand Up @@ -106,6 +108,12 @@ public function setup_table() {
$this->no_sorting('users');
}

if ($this->showteams) {
$columns[] = 'teams';
$headers[] = get_string('teams', 'mod_ratingallocate');
$this->no_sorting('teams');
}

$this->define_columns($columns);
$this->define_headers($headers);

Expand Down Expand Up @@ -142,6 +150,7 @@ public function build_table_by_sql() {
$allocations = $this->ratingallocate->get_allocations();

$users = $this->ratingallocate->get_raters_in_course();
$listedteams = [];

foreach ($allocations as $allocation) {
$userid = $allocation->userid;
Expand All @@ -157,13 +166,37 @@ public function build_table_by_sql() {
}
unset($userwithrating[$userid]);
}
if ($this->showteams) {

$teamids = $this->ratingallocate->get_teamids_for_allocation($allocation->id);
if (array_key_exists($allocation->choiceid, $data)) {
foreach ($teamids as $teamid) {
$teamname = groups_get_group_name($teamid);
if (!in_array($teamname, $listedteams)) {
if (object_property_exists($data[$allocation->choiceid], 'teams')) {
$data[$allocation->choiceid]->teams .= ', ';
} else {
$data[$allocation->choiceid]->teams = '';
}

$data[$allocation->choiceid]->teams .= $teamname;
$listedteams[] = $teamname;
}

}

}
}
}

// Enrich data with empty string for choices with no allocation.
foreach ($data as $row) {
if (!property_exists($row, 'users')) {
$row->users = '';
}
if ($this->showteams && !property_exists($row, 'teams')) {
$row->teams = '';
}
}

// If there are users, which rated but were not allocated, add them to a special row.
Expand Down
14 changes: 14 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,20 @@ public function get_allocations() {
return $records;
}

public function get_teamids_for_allocation($allocationid) {
$sql = 'SELECT r.groupid
FROM {ratingallocate_allocations} al
LEFT JOIN {ratingallocate_choices} c ON al.choiceid = c.id
LEFT JOIN {ratingallocate_ratings} r
ON al.userid = r.userid AND al.choiceid = r.choiceid
WHERE al.ratingallocateid = :ratingallocateid AND c.active = 1 AND al.id = :allocationid';
$teamids = $this->db->get_fieldset_sql($sql, [
'ratingallocateid' => $this->ratingallocateid,
'allocationid' => $allocationid,
]);
return $teamids;
}

/**
* Removes all allocations for choices in $ratingallocateid
*/
Expand Down
7 changes: 7 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
font-weight: bold;
}

.ratingallocate_ratings_table tbody td:first-child,
.ratingallocate_ratings_table.includeteams tbody td:nth-child(2) {
background-color: #fff;
z-index: 1;
font-weight: bold;
}

.ratingallocate_ratings_table_container .no-overflow {
overflow: unset;
}

0 comments on commit fb56992

Please sign in to comment.