diff --git a/application/controllers/api/frontend/v1/stv/Status.php b/application/controllers/api/frontend/v1/stv/Status.php index 3ce4926b7..e7b416c57 100644 --- a/application/controllers/api/frontend/v1/stv/Status.php +++ b/application/controllers/api/frontend/v1/stv/Status.php @@ -39,21 +39,11 @@ class Status extends FHCAPI_Controller public function getHistoryPrestudent($prestudent_id) { - $this->load->model('system/Sprache_model', 'SpracheModel'); - $this->SpracheModel->addSelect('index'); - $result = $this->SpracheModel->loadWhere(array('sprache' => getUserLanguage())); + $result = $this->PrestudentstatusModel->getHistoryPrestudent($prestudent_id); - // Return language index - $lang = hasData($result) ? getData($result)[0]->index : 1; + $data = $this->getDataOrTerminateWithError($result); - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - - $result = $this->PrestudentModel->getHistoryPrestudent($prestudent_id, $lang); - if (isError($result)) - { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess((getData($result) ?: [])); + $this->terminateWithSuccess($data); } public function getStatusgruende() diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index b783715c2..9721e473f 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -727,62 +727,4 @@ class Prestudent_model extends DB_Model return $this->execQuery($query, array($person_id)); } - - /** - * Gets history of prestudent, prestudent_id given - * @param int $prestudent_id - * @return object - */ - public function getHistoryPrestudent($prestudent_id, $index_lang) - { - $query = " - SELECT - ps.status_kurzbz, - ps.studiensemester_kurzbz, - ps.ausbildungssemester, - CASE WHEN ps.status_kurzbz IN ('Student', 'Diplomand','Abbrecher','Unterbrecher') - THEN CONCAT(lv.semester, lv.verband, lv.gruppe) - ELSE '' - END AS lehrverband, - ps.datum, - TO_CHAR(ps.datum::timestamp, 'DD.MM.YYYY') AS format_datum, - sp.bezeichnung, - ps.bestaetigtam, - TO_CHAR(ps.bestaetigtam::timestamp, 'DD.MM.YYYY') AS format_bestaetigtam, - ps.bewerbung_abgeschicktamum, - TO_CHAR(ps.bewerbung_abgeschicktamum::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS format_bewerbung_abgeschicktamum, - stg.statusgrund_kurzbz, - ps.orgform_kurzbz, - ps.prestudent_id, - sp.studienplan_id, - ps.anmerkung, - ps.bestaetigtvon, - ps.insertamum, - TO_CHAR(ps.insertamum::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS format_insertamum, - ps.insertvon, - ps.updateamum, - TO_CHAR(ps.updateamum::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS format_updateamum, - ps.updatevon, - stg.beschreibung[?] as statusgrund_beschreibung - FROM - public.tbl_prestudentstatus ps - LEFT JOIN - public.tbl_student st USING (prestudent_id) - LEFT JOIN - public.tbl_studiengang sg ON (st.studiengang_kz = sg.studiengang_kz) - LEFT JOIN - lehre.tbl_studienplan sp USING (studienplan_id) - LEFT JOIN - public.tbl_status_grund stg USING (statusgrund_id) - LEFT JOIN - public.tbl_studentlehrverband lv ON - (st.student_uid = lv.student_uid - AND st.student_uid IS NOT NULL - AND lv.studiensemester_kurzbz = ps.studiensemester_kurzbz) - WHERE prestudent_id = ? - ORDER BY ps.datum DESC, ps.insertamum DESC, ps.ext_id DESC - "; - - return $this->execQuery($query, array($index_lang, $prestudent_id)); - } } diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index 5223d5764..dac5fbb23 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -514,4 +514,70 @@ class Prestudentstatus_model extends DB_Model return $this->execQuery($qry, array($prestudent_id)); } + + /** + * Gets status history of a prestudent + * This function uses the language of the logged in user to + * translate the given statusgrund + * + * @param integer $prestudent_id + * + * @return stdClass + */ + public function getHistoryPrestudent($prestudent_id) + { + $this->addSelect('tbl_prestudentstatus.prestudent_id'); + $this->addSelect('tbl_prestudentstatus.status_kurzbz'); + $this->addSelect('tbl_prestudentstatus.studiensemester_kurzbz'); + $this->addSelect('tbl_prestudentstatus.ausbildungssemester'); + $this->addSelect('tbl_prestudentstatus.datum'); + $this->addSelect('tbl_prestudentstatus.insertamum'); + $this->addSelect('tbl_prestudentstatus.insertvon'); + $this->addSelect('tbl_prestudentstatus.updateamum'); + $this->addSelect('tbl_prestudentstatus.updatevon'); + $this->addSelect('tbl_prestudentstatus.orgform_kurzbz'); + $this->addSelect('tbl_prestudentstatus.bestaetigtam'); + $this->addSelect('tbl_prestudentstatus.bestaetigtvon'); + $this->addSelect('tbl_prestudentstatus.bewerbung_abgeschicktamum'); + $this->addSelect('tbl_prestudentstatus.anmerkung'); + $this->addSelect('plan.studienplan_id'); + $this->addSelect('plan.bezeichnung'); + $this->addSelect('grund.beschreibung[( + SELECT index + FROM public.tbl_sprache + WHERE sprache=' . $this->escape(getUserLanguage()) . ' + )] AS statusgrund_bezeichnung', false); + $this->addSelect("CASE + WHEN s.student_uid IS NOT NULL + AND tbl_prestudentstatus.status_kurzbz IN (" . implode(",", $this->escape([ + 'Student', + 'Diplomand', + 'Abbrecher', + 'Absolvent', + 'Ausserodentlicher', + 'Incoming', + 'Outgoing', + 'Unterbrecher' + ])) . ") + THEN lv.semester || lv.verband || lv.gruppe + ELSE '-' + END AS lehrverband", false); + + $this->addJoin('lehre.tbl_studienplan plan', 'studienplan_id', 'LEFT'); + $this->addJoin('public.tbl_status_grund grund', 'statusgrund_id', 'LEFT'); + $this->addJoin('public.tbl_student s', 'prestudent_id', 'LEFT'); + $this->addJoin( + 'public.tbl_studentlehrverband lv', + 's.student_uid IS NOT NULL AND s.student_uid=lv.student_uid AND tbl_prestudentstatus.studiensemester_kurzbz=lv.studiensemester_kurzbz', + 'LEFT' + ); + + $this->addOrder('tbl_prestudentstatus.datum', 'DESC'); + $this->addOrder('tbl_prestudentstatus.insertamum', 'DESC'); + $this->addOrder('tbl_prestudentstatus.ext_id', 'DESC'); + + return $this->loadWhere([ + 'tbl_prestudentstatus.prestudent_id' => $prestudent_id + ]); + } }