diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 94d77f8d3..b40897d82 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -524,26 +524,30 @@ class Prestudent_model extends DB_Model /** * Get organisation units for all the prestudents of a person - * TODO */ public function getOrganisationunitsByPersonId($person_id) { $query = 'SELECT o.oe_kurzbz, o.bezeichnung, - ps.prestudent_id + (CASE + WHEN sg.typ = \'b\' THEN ps.prestudent_id + WHEN sg.typ = \'m\' THEN p.prestudent_id + ELSE NULL + END) AS prestudent_id FROM public.tbl_prestudent p JOIN public.tbl_studiengang sg USING(studiengang_kz) JOIN public.tbl_organisationseinheit o USING(oe_kurzbz) LEFT JOIN ( SELECT prestudent_id FROM public.tbl_prestudentstatus - WHERE bestaetigtam IS NOT NULL - AND status_kurzbz = \'Interessent\' + WHERE status_kurzbz = \'Bewerber\' ) ps USING(prestudent_id) WHERE p.person_id = ? GROUP BY o.oe_kurzbz, o.bezeichnung, - ps.prestudent_id + sg.typ, + ps.prestudent_id, + p.prestudent_id ORDER BY o.bezeichnung'; return $this->execQuery($query, array($person_id));