From 5ff875917cc38158423cfb9ec4d40f6aba706a89 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 15 Sep 2017 14:15:04 +0200 Subject: [PATCH] Added method getAppliedStudiengangFromNowOE to get all the applied study courses for one person - Starting from the current study semester - For an organisation unit present in the organisation units tree that has as root the given parameter --- .../api/v1/organisation/Studiengang2.php | 65 ++++++++++----- .../models/organisation/Studiengang_model.php | 83 +++++++++++++++++-- 2 files changed, 121 insertions(+), 27 deletions(-) diff --git a/application/controllers/api/v1/organisation/Studiengang2.php b/application/controllers/api/v1/organisation/Studiengang2.php index 097cd64b3..83d60abb1 100644 --- a/application/controllers/api/v1/organisation/Studiengang2.php +++ b/application/controllers/api/v1/organisation/Studiengang2.php @@ -24,15 +24,15 @@ class Studiengang2 extends APIv1_Controller // Load model PersonModel $this->load->model("organisation/studiengang_model", "StudiengangModel"); } - + public function getStudiengang() { $studiengang_kz = $this->get("studiengang_kz"); - + if (isset($studiengang_kz)) { $result = $this->StudiengangModel->load($studiengang_kz); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -40,12 +40,12 @@ class Studiengang2 extends APIv1_Controller $this->response(); } } - + public function getAllForBewerbung() { $this->response($this->StudiengangModel->getAllForBewerbung(), REST_Controller::HTTP_OK); } - + /** * Method getStudiengangStudienplan */ @@ -56,16 +56,16 @@ class Studiengang2 extends APIv1_Controller $ausbildungssemester = $this->get("ausbildungssemester"); $aktiv = $this->get("aktiv"); $onlinebewerbung = $this->get("onlinebewerbung"); - + // If $studiensemester_kurzbz and $ausbildungssemester are present if (isset($studiensemester_kurzbz) && isset($ausbildungssemester)) { // Check & set if (!isset($aktiv)) $aktiv = "TRUE"; if (!isset($onlinebewerbung)) $onlinebewerbung = "TRUE"; - + $result = $this->StudiengangModel->getStudienplan($studiensemester_kurzbz, $ausbildungssemester, $aktiv, $onlinebewerbung); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -73,14 +73,14 @@ class Studiengang2 extends APIv1_Controller $this->response(); } } - + public function getStudiengangBewerbung() { $result = $this->StudiengangModel->getStudiengangBewerbung(); - + $this->response($result, REST_Controller::HTTP_OK); } - + /** * @return void */ @@ -89,17 +89,17 @@ class Studiengang2 extends APIv1_Controller $person_id = $this->get('person_id'); $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); $titel = $this->get('titel'); - + if (isset($person_id) && isset($studiensemester_kurzbz) && isset($titel)) { $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); - + $result = $this->StudiengangModel->getAppliedStudiengang( $person_id, $studiensemester_kurzbz, $titel ); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -107,7 +107,7 @@ class Studiengang2 extends APIv1_Controller $this->response(); } } - + /** * @return void */ @@ -115,16 +115,16 @@ class Studiengang2 extends APIv1_Controller { $person_id = $this->get('person_id'); $titel = $this->get('titel'); - + if (isset($person_id) && isset($titel)) { $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); - + $result = $this->StudiengangModel->getAppliedStudiengangFromNow( $person_id, $titel ); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -132,4 +132,31 @@ class Studiengang2 extends APIv1_Controller $this->response(); } } -} \ No newline at end of file + + /** + * @return void + */ + public function getAppliedStudiengangFromNowOE() + { + $person_id = $this->get('person_id'); + $titel = $this->get('titel'); + $oe_kurzbz = $this->get('oe_kurzbz'); + + if (isset($person_id) && isset($titel) && isset($oe_kurzbz)) + { + $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + + $result = $this->StudiengangModel->getAppliedStudiengangFromNowOE( + $person_id, + $titel, + $oe_kurzbz + ); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } +} diff --git a/application/models/organisation/Studiengang_model.php b/application/models/organisation/Studiengang_model.php index a15191eab..4755408be 100644 --- a/application/models/organisation/Studiengang_model.php +++ b/application/models/organisation/Studiengang_model.php @@ -104,7 +104,7 @@ class Studiengang_model extends DB_Model public function getStudienplan($studiensemester_kurzbz, $ausbildungssemester, $aktiv, $onlinebewerbung) { if (isError($ent = $this->isEntitled($this->dbTable, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR))) return $ent; - + // Join table public.tbl_studiengang with table lehre.tbl_studienordnung on column studiengang_kz $this->addJoin('lehre.tbl_studienordnung', 'studiengang_kz'); // Then join with table lehre.tbl_studienplan on column studienordnung_id @@ -141,7 +141,7 @@ class Studiengang_model extends DB_Model public function getStudiengangBewerbung() { if (isError($ent = $this->isEntitled($this->dbTable, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR))) return $ent; - + // Join table public.tbl_studiengang with table lehre.tbl_studienordnung on column studiengang_kz $this->addJoin('lehre.tbl_studienordnung', 'studiengang_kz'); // Join table lehre.tbl_studienordnung with table lehre.tbl_akadgrad on column akadgrad_id @@ -191,7 +191,7 @@ class Studiengang_model extends DB_Model public function getAppliedStudiengang($person_id, $studiensemester_kurzbz, $titel) { if (isError($ent = $this->isEntitled($this->dbTable, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR))) return $ent; - + // Then join with table public.tbl_prestudent $this->addJoin('public.tbl_prestudent', 'studiengang_kz'); // Join table public.tbl_prestudentstatus @@ -233,14 +233,14 @@ class Studiengang_model extends DB_Model return $result; } - + /** * getAppliedStudiengangFromNow */ public function getAppliedStudiengangFromNow($person_id, $titel) { if (isError($ent = $this->isEntitled($this->dbTable, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR))) return $ent; - + // Then join with table public.tbl_prestudent $this->addJoin('public.tbl_prestudent', 'studiengang_kz'); // Join table public.tbl_prestudentstatus @@ -257,10 +257,10 @@ class Studiengang_model extends DB_Model 'prestudent_id', 'LEFT' ); - + // Ordering by studiengang_kz and studienplan_id $this->addOrder('public.tbl_studiengang.bezeichnung'); - + $result = $this->loadTree( 'public.tbl_studiengang', array( @@ -283,7 +283,74 @@ class Studiengang_model extends DB_Model 'notizen' ) ); - + + return $result; + } + + /** + * getAppliedStudiengangFromNowOE + */ + public function getAppliedStudiengangFromNowOE($person_id, $titel, $oe_kurzbz) + { + if (isError($ent = $this->isEntitled($this->dbTable, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR))) return $ent; + + // Then join with table public.tbl_prestudent + $this->addJoin('public.tbl_prestudent', 'studiengang_kz'); + // Join table public.tbl_prestudentstatus + $this->addJoin('public.tbl_prestudentstatus', 'prestudent_id'); + // Then join with table lehre.tbl_studienplan + $this->addJoin('lehre.tbl_studienplan', 'studienplan_id'); + // Then join with table public.tbl_notizzuordnung + public.tbl_notiz + $this->addJoin( + '( + SELECT public.tbl_notiz.*, public.tbl_notizzuordnung.prestudent_id + FROM public.tbl_notiz JOIN public.tbl_notizzuordnung USING(notiz_id) + WHERE titel = '.$this->escape($titel). + ') tbl_notiz', + 'prestudent_id', + 'LEFT' + ); + + // Ordering by studiengang_kz and studienplan_id + $this->addOrder('public.tbl_studiengang.bezeichnung'); + + $result = $this->loadTree( + 'public.tbl_studiengang', + array( + 'public.tbl_prestudent', + 'public.tbl_prestudentstatus', + 'lehre.tbl_studienplan', + 'public.tbl_notiz' + ), + 'public.tbl_prestudent.person_id = '.$this->escape($person_id). + ' AND public.tbl_prestudentstatus.studiensemester_kurzbz IN ( + SELECT studiensemester_kurzbz + FROM public.tbl_studiensemester + WHERE ende >= NOW() + ) + AND (public.tbl_prestudentstatus.status_kurzbz = \'Interessent\') + AND public.tbl_studiengang.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 = '.$this->escape($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 + )', + array( + 'prestudenten', + 'prestudentstatus', + 'studienplaene', + 'notizen' + ) + ); + return $result; }