From f907cd72924ac6fc119fd88281a2c08832f9c502 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 28 Sep 2018 17:03:26 +0200 Subject: [PATCH] - Benutzerfunktionen can be retrieved recursively by oe (oe and all oes below) --- .../education/Lehrveranstaltung_model.php | 10 ++--- .../models/person/Benutzerfunktion_model.php | 43 ++++++++++++++++--- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/application/models/education/Lehrveranstaltung_model.php b/application/models/education/Lehrveranstaltung_model.php index c042c2e0a..0a76df4b9 100644 --- a/application/models/education/Lehrveranstaltung_model.php +++ b/application/models/education/Lehrveranstaltung_model.php @@ -14,11 +14,11 @@ class Lehrveranstaltung_model extends DB_Model /** * Gets unique Groupstrings for Lehrveranstaltungen, e.g. WS2018_BIF_1_PRJM_VZ_LV12345 - * @param $studiensemester_kurzbz - * @param null $ausbildungssemester - * @param null $studiengang_kz - * @param null $lehrveranstaltung_ids - * @return StdClass + * @param string $studiensemester_kurzbz + * @param string $ausbildungssemester + * @param string $studiengang_kz + * @param string|array $lehrveranstaltung_ids + * @return array|null */ public function getLehrveranstaltungGroupNames($studiensemester_kurzbz, $ausbildungssemester = null, $studiengang_kz = null, $lehrveranstaltung_ids = null) { diff --git a/application/models/person/Benutzerfunktion_model.php b/application/models/person/Benutzerfunktion_model.php index e6f030e7f..02a27e87a 100644 --- a/application/models/person/Benutzerfunktion_model.php +++ b/application/models/person/Benutzerfunktion_model.php @@ -25,13 +25,14 @@ class Benutzerfunktion_model extends DB_Model /** * Gets all Benutzer for a given OE and specified Benutzerfunktionen - * @param $funktion_kurzbz string with one benutzerfunktionname or array with one or more - * @param $oe_kurzbz - * @param bool $activeoeonly if true, retrieve only active Organisationseinheiten - * @param bool $activebenonly if true, retrieve only active Benutzer + * @param string $funktion_kurzbz String with one benutzerfunktionname or array with one or more. + * @param string $oe_kurzbz + * @param bool $activeoeonly If true, retrieve only active Organisationseinheiten. + * @param bool $activebenonly If true, retrieve only active Benutzer. + * @param bool $oerecursive If true, retrieve all oes under given oe_kurzbz recursively. * @return array|null */ - public function getBenutzerFunktionen($funktion_kurzbz, $oe_kurzbz = null, $activeoeonly = false, $activebenonly = false) + public function getBenutzerFunktionen($funktion_kurzbz, $oe_kurzbz = null, $activeoeonly = false, $activebenonly = false, $oerecursive = false) { $parametersArray = array(); @@ -57,7 +58,35 @@ class Benutzerfunktion_model extends DB_Model if (is_string($oe_kurzbz)) { - $query .= " AND tbl_benutzerfunktion.oe_kurzbz = ?"; + if ($oerecursive === true) + { + $query .= + " AND oe_kurzbz IN + ( + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz, aktiv) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz, aktiv FROM public.tbl_organisationseinheit + WHERE oe_kurzbz=?"; + + if ($activeoeonly === true) + $query .= " AND aktiv=true"; + + $query .= + " UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz, o.aktiv FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_parent_kurzbz=oes.oe_kurzbz + ) + SELECT oe_kurzbz + FROM oes"; + if ($activeoeonly === true) + { + $query .= " WHERE aktiv=true"; + } + $query .= " GROUP BY oe_kurzbz)"; + } + else + $query .= " AND tbl_benutzerfunktion.oe_kurzbz = ?"; + $parametersArray[] = $oe_kurzbz; } @@ -71,7 +100,7 @@ class Benutzerfunktion_model extends DB_Model $query .= " AND tbl_organisationseinheit.aktiv"; } - $query .= " ORDER BY funktion_kurzbz, oe_kurzbz, uid"; + $query .= " ORDER BY oe_kurzbz, funktion_kurzbz, uid"; return $this->execQuery($query, $parametersArray); }