From efe7c77ee12f71063bcc90a5f0523e015e18002b Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 12 May 2024 13:05:00 +0100 Subject: [PATCH] fix #32: allow filtering student projects by repository --- entities/ProjGroup.php | 5 +++++ pages/listprojects.php | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/entities/ProjGroup.php b/entities/ProjGroup.php index bb4ff25..5703234 100644 --- a/entities/ProjGroup.php +++ b/entities/ProjGroup.php @@ -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; diff --git a/pages/listprojects.php b/pages/listprojects.php index 11f24f9..7ff5c34 100644 --- a/pages/listprojects.php +++ b/pages/listprojects.php @@ -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 << @@ -50,14 +51,42 @@ "\n"; } -echo << - +echo "\n"; + +$groups = db_fetch_groups($selected_year); + +if (auth_at_least(ROLE_PROF)) { + echo << + +\n"; +} + +echo "\n"; + echo "

Groups:

\n"; $table = []; -foreach (db_fetch_groups($selected_year) as $group) { +foreach ($groups as $group) { if (!has_group_permissions($group)) continue; @@ -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)";