From 05316577e8d0b1b892ad39c0bb2011c1e487c671 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Mon, 15 Apr 2024 09:12:10 +0200 Subject: [PATCH] modified ratings_and_allocations_table.php to include team of each user --- classes/ratings_and_allocations_table.php | 63 ++++++++++++++++++++--- form_manual_allocation.php | 4 -- locallib.php | 18 +++++++ mod_form.php | 4 +- styles.css | 11 ++-- 5 files changed, 83 insertions(+), 17 deletions(-) diff --git a/classes/ratings_and_allocations_table.php b/classes/ratings_and_allocations_table.php index d4de1ee6..71e4a780 100644 --- a/classes/ratings_and_allocations_table.php +++ b/classes/ratings_and_allocations_table.php @@ -189,7 +189,7 @@ public function setup_table($choices, $hidenorating = null, $showallocnecessary } if ($this->showteams) { $columns[] = 'teams'; - $headers[] = get_string('teams'); + $headers[] = get_string('teams', 'mod_ratingallocate'); } } @@ -222,19 +222,20 @@ public function setup_table($choices, $hidenorating = null, $showallocnecessary // Set additional table settings. if ($this->showteams) { - //$this->sortable(true, 'teams'); + $this->sortable(true, 'teams'); } else { - + $this->sortable(true, 'lastname'); } - $this->sortable(true, 'lastname'); + $tableclasses = 'ratingallocate_ratings_table'; if ($this->showgroups) { $tableclasses .= ' includegroups'; $this->no_sorting('groups'); } if ($this->showteams) { - $this->no_sorting('teams'); + $tableclasses .= ' includeteams'; } + $this->set_attribute('class', $tableclasses); $this->initialbars(true); @@ -352,7 +353,7 @@ function($groupid) use ($user) { } ); $teamname = array_map(function ($team) { - return $team->name; + return groups_get_group($team, 'name')->name; }, $teamofuser); // We should only have one team for each user, but we cant ensure that at this point. $row['teams'] = implode(';', $teamname); @@ -403,6 +404,10 @@ private function add_summary_row() { // In case we are showing groups, the second column is the group column and needs to be skipped in summary row. $row[] = ''; } + if ($this->showteams) { + // In case we are showing teams, the third (second) column is the teams column and needs to be skipped in summary row. + $row[] = ''; + } } foreach ($this->choicesum as $choiceid => $sum) { @@ -707,7 +712,45 @@ public function init_sql() { $userids = $this->filter_userids($userids); $sortfields = $this->get_sort_columns(); + + + // To do vardumps entfernen. var_dump($sortfields); + var_dump("
sortdata: "); + var_dump($this->sortdata); + var_dump("
sortorder: "); + var_dump($this->get_sort_order()); + + // If we have teamvote enabled, always order by team first, in order to always show users in their teams. + if ($this->showteams) { + + $sortdata = array([ + 'sortby' => 'teams', + 'sortorder' => SORT_ASC + ]); + + foreach (array_keys($sortfields) as $column) { + if (substr($column, 0, 5) != "teams") { + $sortdata[] =[ + 'sortby' => $column, + 'sortorder' => SORT_ASC + ]; + } + } + $this->set_sortdata($sortdata); + $this->set_sorting_preferences(); + + } + $sortfields = $this->get_sort_columns(); + + var_dump("
sortdata nach preferences: "); + var_dump($this->sortdata); + var_dump("
sortcolumns nach preferences: "); + var_dump($this->get_sort_columns()); + var_dump("
sortorder nach preferences: "); + var_dump($this->get_sort_order()); + + $fields = "u.*"; if ($userids) { $where = "u.id in (" . implode(",", $userids) . ")"; @@ -720,13 +763,19 @@ public function init_sql() { $params = array(); for ($i = 0; $i < count($sortfields); $i++) { $key = array_keys($sortfields)[$i]; + + // If sortfields contain 'teams', it is always on first position. if (substr($key, 0, 6) == "choice") { $id = substr($key, 7); $from .= " LEFT JOIN {ratingallocate_ratings} r$i ON u.id = r$i.userid AND r$i.choiceid = :choiceid$i "; $fields .= ", r$i.rating as $key"; $params["choiceid$i"] = $id; } else if (substr($key, 0, 5) == "teams") { - //$from .= + $fields .= ", gm.groupid as teams"; + $from .= " LEFT JOIN {groups_members} gm ON u.id=gm.userid LEFT JOIN {groupings_groups} gg ON gm.groupid=gg.groupid + LEFT JOIN {ratingallocate} r ON gg.groupingid=r.teamvotegroupingid"; + $where .= " AND r.id = :ratingallocateid"; + $params["ratingallocateid"] = $this->ratingallocate->get_ratingallocateid(); } } diff --git a/form_manual_allocation.php b/form_manual_allocation.php index c5f01237..62356a13 100644 --- a/form_manual_allocation.php +++ b/form_manual_allocation.php @@ -148,10 +148,6 @@ public function definition_after_data() { $mform->setDefault('filtergroup', $filter['groupselect']); $mform->getElement('filtergroup')->setSelected($filter['groupselect']); - if ($this->ratingallocate->get_teamvote_goups()) { - - } - $PAGE->requires->js_call_amd('mod_ratingallocate/radiobuttondeselect', 'init'); // The rest must be done through output buffering due to the way flextable works. diff --git a/locallib.php b/locallib.php index 2c9475b1..543d7042 100644 --- a/locallib.php +++ b/locallib.php @@ -1371,6 +1371,24 @@ public function delete_groups_for_usersnogroup($usergroups) { } + /** + * Returns the group in the teamvotegrouping this user is a member of. + * (Should return only one groupid, please only call if teamvote is enabled). + * + * @param $userid + * @return false|mixed The groupid + * @throws dml_exception + */ + public function get_teamvotegroup_for_user($userid) { + + $sql = 'SELECT gm.groupid FROM {groups_members} gm INNER JOIN {groupings_groups} gg ON gm.groupid=gg.groupid + INNER JOIN {ratingallocate} r ON gg.groupingid=r.teamvotegroupingid + WHERE gm.userid = :userid AND r.id = :ratingallocateid'; + $groupid = $this->db->get_record_sql($sql, ['userid' => $userid, 'ratingallocateid' => $this->ratingallocateid]); + return $groupid->groupid; + + } + /** * distribution of choices for each user * take care about max_execution_time and memory_limit diff --git a/mod_form.php b/mod_form.php index cb3e2baa..b8089f3d 100644 --- a/mod_form.php +++ b/mod_form.php @@ -63,7 +63,7 @@ public function __construct($current, $section, $cm, $course) { * Defines forms elements */ public function definition() { - global $CFG, $PAGE; + global $CFG, $PAGE, $COURSE; $mform = $this->_form; $info = $this->get_disable_strategy(true); @@ -157,7 +157,7 @@ public function definition() { $mform->setType('preventvotenotingroup', PARAM_BOOL); $mform->hideIf('preventvotenotingroup', 'teamvote', 'eq', 0); - $groupings = groups_get_all_groupings($ratingallocate->ratingallocate->dbrecord->course); + $groupings = groups_get_all_groupings($COURSE->id); $options = array(); $options[0] = get_string('none'); foreach ($groupings as $grouping) { diff --git a/styles.css b/styles.css index 9ef50c4a..772b70e2 100644 --- a/styles.css +++ b/styles.css @@ -81,19 +81,22 @@ } .ratingallocate_ratings_table.includegroups tbody td:nth-child(2), -.ratingallocate_ratings_table.includegroups thead th:nth-child(2) { +.ratingallocate_ratings_table.includegroups thead th:nth-child(2), +.ratingallocate_ratings_table.includeteams tbody td:nth-child(2), +.ratingallocate_ratings_table.includeteams thead th:nth-child(2) { position: sticky; left: 10rem; border-right: 2px solid #dee2e6; } -.ratingallocate_ratings_table:not(.includegroups) tbody td:first-child, -.ratingallocate_ratings_table:not(.includegroups) thead th:first-child { +.ratingallocate_ratings_table:not(.includegroups, .includeteams) tbody td:first-child, +.ratingallocate_ratings_table:not(.includegroups, .includeteams) thead th:first-child { border-right: 2px solid #dee2e6; } .ratingallocate_ratings_table thead th:first-child, -.ratingallocate_ratings_table.includegroups thead th:nth-child(2) { +.ratingallocate_ratings_table.includegroups thead th:nth-child(2), +.ratingallocate_ratings_table.includeteams thead th:nth-child(2) { z-index: 3; }