From c94a2d2d0caa3481b27bbb3a257a254cb2d30972 Mon Sep 17 00:00:00 2001 From: Cris Date: Wed, 27 Nov 2024 17:31:02 +0100 Subject: [PATCH] Added param lehrveranstaltung_id to getTemplateLvTree method in Lehrveranstaltung_model.php and enhanced order Now ordering extra templates to appear first and directly after the assigned lvs --- .../education/Lehrveranstaltung_model.php | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/application/models/education/Lehrveranstaltung_model.php b/application/models/education/Lehrveranstaltung_model.php index 28b44a177..aa68f7f69 100644 --- a/application/models/education/Lehrveranstaltung_model.php +++ b/application/models/education/Lehrveranstaltung_model.php @@ -189,14 +189,15 @@ class Lehrveranstaltung_model extends DB_Model } /** - * Get all Templates and union with all Lehrveranstaltungen of given Studiensemester and Oes, that are assigned to - * a template. This data structure can be used for nested tabulator data tree. + * Get all Templates and its assigned Lehrveranstaltungen of given Studiensemester and Oes. + * Lvs are queried via actual Studienordnung and Studienplan. * * @param null|string $studiensemester_kurzbz * @param null|array $oes + * @param null $lehrveranstaltung_id Queries certain LV only * @return array|stdClass|null */ - public function getTemplateLvTree($studiensemester_kurzbz = null, $oes = null){ + public function getTemplateLvTree($studiensemester_kurzbz = null, $oes = null, $lehrveranstaltung_id = null){ $params = []; $qry = ' WITH @@ -223,6 +224,13 @@ class Lehrveranstaltung_model extends DB_Model -- filter lvs assigned to template (= standardisierte lv) AND lehrveranstaltung_template_id IS NOT NULL'; + if (is_numeric($lehrveranstaltung_id)) + { + /* filter by studiensemester */ + $params[]= $lehrveranstaltung_id; + $qry.= ' AND lv.lehrveranstaltung_template_id = ? '; + } + if (is_string($studiensemester_kurzbz)) { /* filter by studiensemester */ @@ -266,6 +274,13 @@ class Lehrveranstaltung_model extends DB_Model WHERE std.lehrveranstaltung_template_id = lv.lehrveranstaltung_id )'; + if (is_numeric($lehrveranstaltung_id)) + { + /* filter by studiensemester */ + $params[]= $lehrveranstaltung_id; + $qry.= ' AND lv.lehrveranstaltung_id = ? '; + } + if (is_array($oes)) { /* filter by organisationseinheit */ @@ -342,7 +357,17 @@ class Lehrveranstaltung_model extends DB_Model JOIN public.tbl_studiengangstyp stgtyp ON stgtyp.typ = stg.typ JOIN public.tbl_organisationseinheit oe ON oe.oe_kurzbz = lv.oe_kurzbz ORDER BY - oe.bezeichnung, lv.semester, lv.bezeichnung + -- Sort by organisationseinheit, semester, and lv.bezeichnung + oe.bezeichnung, + lv.semester, + lv.bezeichnung, + -- Within each group, ensure templates appear first + CASE + WHEN lv.lehrtyp_kurzbz = \'tpl\' THEN 0 + ELSE 1 + END, + -- Ensure assigend lvs follow their template, grouped by lehrveranstaltung_template_id + COALESCE(lv.lehrveranstaltung_template_id, lv.lehrveranstaltung_id) '; return $this->execQuery($qry, $params);