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

WIP: Feature/vote in groups #295

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
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_groupingid();
}

/**
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
Loading
Loading