From 166eb5d657e9bccfbcd0f891d78a000b7b0fcb3f Mon Sep 17 00:00:00 2001 From: Rami Jasim Date: Wed, 17 Dec 2025 09:28:53 +0000 Subject: add filtering for module.stat to the json-api route ModulesIndex and include... Closes #6119 Merge request studip/studip!4651 --- lib/classes/JsonApi/Routes/Mvv/ModulesIndex.php | 11 ++++++++++- lib/classes/JsonApi/Schemas/Module.php | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/classes/JsonApi/Routes/Mvv/ModulesIndex.php b/lib/classes/JsonApi/Routes/Mvv/ModulesIndex.php index 3018fd4..bdf78c8 100644 --- a/lib/classes/JsonApi/Routes/Mvv/ModulesIndex.php +++ b/lib/classes/JsonApi/Routes/Mvv/ModulesIndex.php @@ -11,7 +11,7 @@ use JsonApi\JsonApiController; class ModulesIndex extends JsonApiController { - protected $allowedFilteringParameters = ['q', 'institute', 'semester', 'section']; + protected $allowedFilteringParameters = ['q', 'institute', 'semester', 'section', 'stat']; protected $allowedPagingParameters = ['offset', 'limit']; @@ -70,6 +70,12 @@ class ModulesIndex extends JsonApiController if (isset($filtering['semester']) && !\Semester::exists($filtering['semester'])) { return 'Filter `semester` must be a valid id.'; } + + // stat + $allowed_module_stats = array_keys($GLOBALS['MVV_MODUL']['STATUS']['values']); + if (isset($filtering['stat']) && !in_array($filtering['stat'], $allowed_module_stats)) { + return 'Filter `stat` has no valid value. Must be one of these: ' . implode(', ', $allowed_module_stats); + } } private function getModules($filtering, $offset, $limit): array @@ -101,6 +107,9 @@ class ModulesIndex extends JsonApiController if (isset($filtering['q'])) { $where .= " AND (`mvv_modul_deskriptor`.`bezeichnung` LIKE CONCAT('%', :q, '%') OR `mvv_modul`.`code` LIKE CONCAT('%', :q, '%')) "; } + if (isset($filtering['stat'])) { + $where .= " AND `stat` = :stat "; + } $where .= ' ORDER BY `mvv_modul`.`code` ASC, `mvv_modul_deskriptor`.`bezeichnung` ASC LIMIT :limit OFFSET :offset'; return \Modul::findBySQL( diff --git a/lib/classes/JsonApi/Schemas/Module.php b/lib/classes/JsonApi/Schemas/Module.php index 55fe085..f480069 100644 --- a/lib/classes/JsonApi/Schemas/Module.php +++ b/lib/classes/JsonApi/Schemas/Module.php @@ -52,6 +52,7 @@ class Module extends SchemaProvider 'comment-capacity' => (string) $resource->deskriptoren->kommentar_kapazitaet, 'comment_sws' => (string) $resource->deskriptoren->kommentar_sws, 'type' => get_class($resource), + 'stat' => $resource->stat, 'status' => \Config::get()->MVV_MODUL['STATUS']['values'][$resource->stat], ]; } -- cgit v1.0