From 3b33e52df4cf88f26b5a29e71484ad92c78ef52f Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 30 Apr 2018 17:32:08 +0200 Subject: [PATCH] added getChild and getParents methods to CI model --- .../Organisationseinheit_model.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/application/models/organisation/Organisationseinheit_model.php b/application/models/organisation/Organisationseinheit_model.php index 37b269f79..75791de1b 100644 --- a/application/models/organisation/Organisationseinheit_model.php +++ b/application/models/organisation/Organisationseinheit_model.php @@ -115,4 +115,49 @@ class Organisationseinheit_model extends DB_Model return $this->execQuery($query, array($oe_kurzbz)); } + + /** + * Liefert die ChildNodes einer Organisationseinheit + * @param $oe_kurzbz + * @return Array mit den Childs inkl dem Uebergebenen Element + */ + public function getChilds($oe_kurzbz) + { + $query = " + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE oe_kurzbz=? + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_parent_kurzbz=oes.oe_kurzbz + ) + SELECT oe_kurzbz + FROM oes + GROUP BY oe_kurzbz;"; + + return $this->execQuery($query, array($oe_kurzbz)); + } + + /** + * Liefert die OEs die im Tree ueberhalb der uebergebene OE liegen + * @param $oe_kurzbz + */ + public function getParents($oe_kurzbz) + { + $query= + "WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE oe_kurzbz=? and aktiv = true + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_kurzbz=oes.oe_parent_kurzbz and aktiv = true + ) + SELECT oe_kurzbz + FROM oes"; + + return $this->execQuery($query, array($oe_kurzbz)); + } + }