From 1d1ca17dc13d7a48c82d81f3ab0e580fe03d4c5c Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 20 Sep 2017 11:33:41 +0200 Subject: [PATCH] Now the organisation unit parameter for methods: - getMessagesByPersonID - getMessagesByUID - getSentMessagesByPerson - getCountUnreadMessages of controller system/Message must be the root of the organisation unit tree --- .../controllers/api/v1/system/Message.php | 8 ++-- application/models/system/Message_model.php | 15 ++++++- application/models/system/Recipient_model.php | 45 +++++++++++++++++-- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/application/controllers/api/v1/system/Message.php b/application/controllers/api/v1/system/Message.php index 1d400b41e..0f3f79855 100644 --- a/application/controllers/api/v1/system/Message.php +++ b/application/controllers/api/v1/system/Message.php @@ -32,7 +32,7 @@ class Message extends APIv1_Controller public function getMessagesByPersonID() { $person_id = $this->get('person_id'); - $oe_kurzbz = $this->get('oe_kurzbz'); // prestudent organisation unit + $oe_kurzbz = $this->get('oe_kurzbz'); // root organisation unit $all = $this->get('all'); if (isset($person_id)) @@ -53,7 +53,7 @@ class Message extends APIv1_Controller public function getMessagesByUID() { $uid = $this->get('uid'); - $oe_kurzbz = $this->get('oe_kurzbz'); // prestudent organisation unit + $oe_kurzbz = $this->get('oe_kurzbz'); // root organisation unit $all = $this->get('all'); if (isset($uid)) @@ -93,7 +93,7 @@ class Message extends APIv1_Controller public function getSentMessagesByPerson() { $person_id = $this->get('person_id'); - $oe_kurzbz = $this->get('oe_kurzbz'); // prestudent organisation unit + $oe_kurzbz = $this->get('oe_kurzbz'); // root organisation unit $all = $this->get('all'); if (isset($person_id)) @@ -114,7 +114,7 @@ class Message extends APIv1_Controller public function getCountUnreadMessages() { $person_id = $this->get('person_id'); - $oe_kurzbz = $this->get('oe_kurzbz'); // prestudent organisation unit + $oe_kurzbz = $this->get('oe_kurzbz'); // root organisation unit if (isset($person_id)) { diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 6b8b0fbdc..b94bc3861 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -67,7 +67,20 @@ class Message_model extends DB_Model if ($oe_kurzbz != null) { array_push($parametersArray, $oe_kurzbz); - $sql .= ' AND m.oe_kurzbz = ?'; + $sql .= ' AND m.oe_kurzbz IN ( + WITH RECURSIVE organizations(_pk, _ppk) AS + ( + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o + WHERE o.oe_parent_kurzbz IS NULL + AND o.oe_kurzbz = ? + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o INNER JOIN organizations orgs ON (o.oe_parent_kurzbz = orgs._pk) + ) + SELECT orgs._pk + FROM organizations orgs + )'; } return $this->execQuery($sql, $parametersArray); diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 53170a4cc..c0fa75da2 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -141,7 +141,20 @@ class Recipient_model extends DB_Model if ($oe_kurzbz != null) { array_push($parametersArray, $oe_kurzbz); - $sql .= ' AND m.oe_kurzbz = ?'; + $sql .= ' AND m.oe_kurzbz IN ( + WITH RECURSIVE organizations(_pk, _ppk) AS + ( + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o + WHERE o.oe_parent_kurzbz IS NULL + AND o.oe_kurzbz = ? + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o INNER JOIN organizations orgs ON (o.oe_parent_kurzbz = orgs._pk) + ) + SELECT orgs._pk + FROM organizations orgs + )'; } $sql .= ' ORDER BY r.message_id DESC, s.status DESC'; @@ -207,7 +220,20 @@ class Recipient_model extends DB_Model if ($oe_kurzbz != null) { array_push($parametersArray, $oe_kurzbz); - $sql .= ' AND m.oe_kurzbz = ?'; + $sql .= ' AND m.oe_kurzbz IN ( + WITH RECURSIVE organizations(_pk, _ppk) AS + ( + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o + WHERE o.oe_parent_kurzbz IS NULL + AND o.oe_kurzbz = ? + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o INNER JOIN organizations orgs ON (o.oe_parent_kurzbz = orgs._pk) + ) + SELECT orgs._pk + FROM organizations orgs + )'; } return $this->execQuery($sql, $parametersArray); @@ -315,7 +341,20 @@ class Recipient_model extends DB_Model if ($oe_kurzbz != null) { array_push($parametersArray, $oe_kurzbz); - $sql .= ' AND m.oe_kurzbz = ?'; + $sql .= ' AND m.oe_kurzbz IN ( + WITH RECURSIVE organizations(_pk, _ppk) AS + ( + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o + WHERE o.oe_parent_kurzbz IS NULL + AND o.oe_kurzbz = ? + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz + FROM public.tbl_organisationseinheit o INNER JOIN organizations orgs ON (o.oe_parent_kurzbz = orgs._pk) + ) + SELECT orgs._pk + FROM organizations orgs + )'; } return $this->execQuery($sql, $parametersArray);