diff --git a/classes/allocations_table.php b/classes/allocations_table.php index 6418a037..116ef573 100644 --- a/classes/allocations_table.php +++ b/classes/allocations_table.php @@ -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(); } /** @@ -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); @@ -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; @@ -157,6 +166,27 @@ 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. @@ -164,6 +194,9 @@ public function build_table_by_sql() { 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. diff --git a/locallib.php b/locallib.php index a4147ea9..2aa2a822 100644 --- a/locallib.php +++ b/locallib.php @@ -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 */ diff --git a/styles.css b/styles.css index 772b70e2..16438ea1 100644 --- a/styles.css +++ b/styles.css @@ -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; }