Skip to content

Commit

Permalink
fix #32: allow filtering student projects by repository
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed May 12, 2024
1 parent 58f5565 commit efe7c77
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions entities/ProjGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public function getRepository() : ?Repository {
return $this->repository ? new Repository($this->repository) : null;
}

public function getRepositoryId() : string {
$repo = $this->getRepository();
return $repo ? $repo->id : '';
}

public function getValidRepository() : ?Repository {
$repo = $this->getRepository();
return $repo && $repo->isValid() ? $repo : null;
Expand Down
40 changes: 36 additions & 4 deletions pages/listprojects.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$selected_shift
= isset($_POST['shift']) ? db_fetch_shift_id($_POST['shift']) : null;
$own_shifts_only = !empty($_POST['own_shifts']);
$selected_repo = $_POST['repo'] ?? 'all';

echo <<<EOF
<form action="index.php?page=listprojects" method="post">
Expand Down Expand Up @@ -50,14 +51,42 @@
"</option>\n";
}

echo <<<EOF
</select>
</form>
echo "</select>\n";

$groups = db_fetch_groups($selected_year);

if (auth_at_least(ROLE_PROF)) {
echo <<<EOF
<br>
<label for="repo">Filter by repository:</label>
<select name="repo" id="repo" onchange='this.form.submit()'>
<option value="all">All</option>
EOF;

$repos = [];
foreach ($groups as $group) {
if (!has_group_permissions($group))
continue;

if ($repo = $group->getRepositoryId())
$repos[$repo] = true;
}
$repos = array_keys($repos);
natsort($repos);

foreach ($repos as $repo) {
$select = $repo == $selected_repo ? ' selected' : '';
echo "<option value=\"$repo\"$select>", htmlspecialchars($repo),
"</option>\n";
}
echo "</select>\n";
}

echo "</form>\n";

echo "<p>Groups:</p>\n";
$table = [];
foreach (db_fetch_groups($selected_year) as $group) {
foreach ($groups as $group) {
if (!has_group_permissions($group))
continue;

Expand All @@ -67,6 +96,9 @@
if ($own_shifts_only && $group->prof() != get_user())
continue;

if ($selected_repo != 'all' && $group->getRepositoryId() != $selected_repo)
continue;

$students = [];
foreach ($group->students as $s) {
$students[] = "$s->name ($s->id)";
Expand Down

0 comments on commit efe7c77

Please sign in to comment.