added getChild and getParents methods to CI model

This commit is contained in:
alex
2018-04-30 17:32:08 +02:00
parent b7160b00fb
commit 3b33e52df4
@@ -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));
}
}