Skip to content

Commit

Permalink
modified ratings_and_allocations_table.php to include team of each user
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe committed Apr 15, 2024
1 parent 9027fb8 commit 0531657
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 17 deletions.
63 changes: 56 additions & 7 deletions classes/ratings_and_allocations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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("</br> sortdata: ");
var_dump($this->sortdata);
var_dump("</br> 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("</br> sortdata nach preferences: ");
var_dump($this->sortdata);
var_dump("</br> sortcolumns nach preferences: ");
var_dump($this->get_sort_columns());
var_dump("</br> sortorder nach preferences: ");
var_dump($this->get_sort_order());


$fields = "u.*";
if ($userids) {
$where = "u.id in (" . implode(",", $userids) . ")";
Expand All @@ -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();
}
}

Expand Down
4 changes: 0 additions & 4 deletions form_manual_allocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0531657

Please sign in to comment.