From 35e8df3b22f6114b314461d3508900d7ec4e251e Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 7 Aug 2017 15:15:08 +0200 Subject: [PATCH] Added method getAppliedStudiengangFromNow to controller Studiengang. This method can retrive all the applied studiengang for a person from the current studiensemester --- .../api/v1/organisation/Studiengang2.php | 25 +++++++++ .../models/organisation/Studiengang_model.php | 51 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/application/controllers/api/v1/organisation/Studiengang2.php b/application/controllers/api/v1/organisation/Studiengang2.php index ea614680c..097cd64b3 100644 --- a/application/controllers/api/v1/organisation/Studiengang2.php +++ b/application/controllers/api/v1/organisation/Studiengang2.php @@ -107,4 +107,29 @@ class Studiengang2 extends APIv1_Controller $this->response(); } } + + /** + * @return void + */ + public function getAppliedStudiengangFromNow() + { + $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 + { + $this->response(); + } + } } \ No newline at end of file diff --git a/application/models/organisation/Studiengang_model.php b/application/models/organisation/Studiengang_model.php index cc09c28fd..3a454cd85 100644 --- a/application/models/organisation/Studiengang_model.php +++ b/application/models/organisation/Studiengang_model.php @@ -225,6 +225,57 @@ class Studiengang_model extends DB_Model return $result; } + + /** + * + */ + public function getAppliedStudiengangFromNow($person_id, $titel) + { + // 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 start >= NOW() + )'. + ' AND (public.tbl_prestudentstatus.status_kurzbz = \'Interessent\')', + array( + 'prestudenten', + 'prestudentstatus', + 'studienplaene', + 'notizen' + ) + ); + + return $result; + } /** *