From d916c6ab3170cc8d8f00d62d57efba7262d3130d Mon Sep 17 00:00:00 2001 From: chfhtw Date: Fri, 21 Nov 2025 08:27:05 +0100 Subject: [PATCH 1/2] make Pruefung->insertPruefung() behave exactly like old FAS --- .../api/frontend/v1/stv/Pruefung.php | 205 +++++++++--------- .../Details/Pruefung/Pruefunglist.js | 5 +- 2 files changed, 108 insertions(+), 102 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Pruefung.php b/application/controllers/api/frontend/v1/stv/Pruefung.php index e205c85b8..1cdbf86bd 100644 --- a/application/controllers/api/frontend/v1/stv/Pruefung.php +++ b/application/controllers/api/frontend/v1/stv/Pruefung.php @@ -18,6 +18,8 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); +use \DateTime as DateTime; + /** * This controller operates between (interface) the JS (GUI) and the back-end * Provides data to the ajax get calls about addresses @@ -111,7 +113,7 @@ class Pruefung extends FHCAPI_Controller // Load language phrases $this->loadPhrases([ - 'global', 'ui','lehre' + 'global', 'ui', 'lehre', 'exam' ]); } @@ -172,15 +174,7 @@ class Pruefung extends FHCAPI_Controller * * @param lehrveranstaltung_id, student_uid, lehreinheit_id * - * @return values on success - * retval 0: pruefung inserted - * reval 1: pruefung and zeugnisnote inserted - * retval 2: pruefung inserted, no insert Zeugnisnote - * (change after date of examination) - * retval 3: pruefung of type Termin2 inserted - * and pruefung of type Termin1 as well - * retval 5: prueufungen Termin 2 and 1 inserted - * and no insert Zeugnisnote (change after date of examination) + * @return void */ public function insertPruefung() { @@ -188,9 +182,6 @@ class Pruefung extends FHCAPI_Controller $this->load->library('form_validation'); - $this->form_validation->set_rules('lehrveranstaltung_id', $this->p->t('lehre', 'lehrveranstaltung'), 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehrveranstaltung')]), - ]); $this->form_validation->set_rules('lehreinheit_id', $this->p->t('lehre', 'lehreinheit'), 'required', [ 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehreinheit')]), ]); @@ -208,20 +199,57 @@ class Pruefung extends FHCAPI_Controller $this->terminateWithValidationErrors($this->form_validation->error_array()); } - //calculate studiensemester_kurzbz this from lehreinheit (case newPruefung) - $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); - if (!$studiensemester_kurzbz) + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $this->PruefungModel->db->trans_start(); + + if ($this->input->post('pruefungstyp_kurzbz') == "Termin2") { - $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); + //Wenn ein 2. Termin angelegt wird, und kein 1. Termin vorhanden ist, + //dann wird auch ein 1. Termin angelegt mit der derzeitigen Zeugnisnote + $resultP = $this->PruefungModel->loadWhere(array( + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'pruefungstyp_kurzbz' => 'Termin1')); - $result = $this->LehreinheitModel->load($this->input->post('lehreinheit_id')); - - $lehreinheit = $this->getDataOrTerminateWithError($result); - $studiensemester_kurzbz = current($lehreinheit)->studiensemester_kurzbz; - - if (isError($result)) + $termin1 = $this->getDataOrTerminateWithError($resultP); + if (!$termin1) { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + //check if existing Zeugnisnote + $this->ZeugnisnoteModel->addJoin('lehre.tbl_lehreinheit', 'lehrveranstaltung_id'); + + $this->ZeugnisnoteModel->db->where( + 'lehre.tbl_zeugnisnote.studiensemester_kurzbz', + 'lehre.tbl_lehreinheit.studiensemester_kurzbz', + false + ); + $resultP = $this->ZeugnisnoteModel->loadWhere(array( + 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), + 'student_uid' => $this->input->post('student_uid') + )); + + $zeugnisnoten = $this->getDataOrTerminateWithError($resultP); + if ($zeugnisnoten) + { + $zeugnisnote = current($zeugnisnoten); + + $resultN = $this->PruefungModel->insert([ + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), + 'datum' => $zeugnisnote->benotungsdatum, + 'pruefungstyp_kurzbz' => 'Termin1', + 'note' => $zeugnisnote->note, + 'punkte' => $zeugnisnote->punkte, + 'anmerkung' => 'automatisiert aus Zeugnisnote erstellt', + 'insertamum' => date('c'), + 'insertvon' => $authUID, + ]); + + $this->getDataOrTerminateWithError($resultN); + } + //Wenn keine Zeugnisnote vorhanden ist, dann wird kein + //1.Termin angelegt } } @@ -235,111 +263,90 @@ class Pruefung extends FHCAPI_Controller 'anmerkung' => $this->input->post('anmerkung'), 'insertamum' => date('c'), 'insertvon' => $authUID, + 'punkte' => $this->input->post('punkte') ? str_replace(',', '.', $this->input->post('punkte')) : null ]); $this->getDataOrTerminateWithError($result); - //check if existing zeugnisnote - $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + //get studiensemester_kurzbz and lehreveranstaltung_id from lehreinheit + $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); - $result = $this->ZeugnisnoteModel->loadWhere(array( - 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), - 'student_uid' => $this->input->post('student_uid'), - 'studiensemester_kurzbz' => $studiensemester_kurzbz)); + $result = $this->LehreinheitModel->load($this->input->post('lehreinheit_id')); - if (isError($result)) - { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $lehreinheiten = $this->getDataOrTerminateWithError($result); + + if (!$lehreinheiten) { + $this->terminateWithValidationErrors([ + 'lehreinheit_id' => $this->p->t('ui', 'error_fieldNotFound', [ + 'field' => $this->p->t('lehre', 'lehreinheit') + ]) + ]); } + $lehreinheit = current($lehreinheiten); + $studiensemester_kurzbz = $lehreinheit->studiensemester_kurzbz; + $lehrveranstaltung_id = $lehreinheit->lehrveranstaltung_id; - if (!hasData($result)) + //check if existing zeugnisnote + $result = $this->ZeugnisnoteModel->loadWhere(array( + 'lehrveranstaltung_id' => $lehrveranstaltung_id, + 'student_uid' => $this->input->post('student_uid'), + 'studiensemester_kurzbz' => $studiensemester_kurzbz + )); + + $zeugnisnoten = $this->getDataOrTerminateWithError($result); + + if (!$zeugnisnoten) { //insert zeugnisnote, if not existing $result = $this->ZeugnisnoteModel->insert(array( - 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), + 'lehrveranstaltung_id' => $lehrveranstaltung_id, 'student_uid' => $this->input->post('student_uid'), 'studiensemester_kurzbz' => $studiensemester_kurzbz, 'note' => $this->input->post('note'), 'uebernahmedatum' => date('c'), 'benotungsdatum' => $this->input->post('datum'), 'insertamum' => date('c'), - 'insertvon' => $authUID + 'insertvon' => $authUID, + 'punkte' => $this->input->post('punkte') ? str_replace(',', '.', $this->input->post('punkte')) : null )); - if (isError($result)) - { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess(1); + $this->getDataOrTerminateWithError($result); + + $this->PruefungModel->db->trans_complete(); + $this->terminateWithSuccess(); } - $return_code = 0; - - //handling Termin1 if not existing - if($this->input->post('pruefungstyp_kurzbz') == "Termin2") - { - $resultP = $this->PruefungModel->loadWhere(array( - 'lehreinheit_id' => $this->input->post('lehreinheit_id'), - 'student_uid' => $this->input->post('student_uid'), - 'pruefungstyp_kurzbz' => 'Termin1')); - - if (isError($resultP)) - { - $this->terminateWithError(getError($resultP), self::ERROR_TYPE_GENERAL); - } - if(!hasData($resultP)) - { - //check if existing Zeugnisnote - $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); - $this->ZeugnisnoteModel->addJoin('lehre.tbl_lehreinheit', 'lehrveranstaltung_id'); - - $resultP = $this->ZeugnisnoteModel->loadWhere(array( - 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), - 'student_uid' => $this->input->input->post('student_uid'), - 'lehre.tbl_zeugnisnote.studiensemester_kurzbz' => $studiensemester_kurzbz)); - if (isError($resultP)) - { - $this->terminateWithError(getError($resultP), self::ERROR_TYPE_GENERAL); - } - if (!hasData($resultP)) - { - $this->terminateWithError("Zeugnisnote existiert nicht", self::ERROR_TYPE_GENERAL); - } - $dataNote = current(getData($resultP)); - - $resultN = $this->PruefungModel->insert([ - 'lehreinheit_id' => $this->input->post('lehreinheit_id'), - 'student_uid' => $this->input->post('student_uid'), - 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), - 'datum' => $dataNote->benotungsdatum, - 'pruefungstyp_kurzbz' => 'Termin1', - 'note' => $dataNote->note, - 'punkte' => $dataNote->punkte, - 'anmerkung' => 'automatisiert aus Zeugnisnote erstellt', - 'insertamum' => date('c'), - 'insertvon' => $authUID, - ]); - - if (isError($resultN)) { - $this->terminateWithError(getError($resultN), self::ERROR_TYPE_GENERAL); - } - $return_code = 3; - } - } - - $note = current(getData($result)); + $note = current($zeugnisnoten); $uebernahmedatum = new DateTime($note->uebernahmedatum); $benotungsdatum = new DateTime($note->benotungsdatum); - $checkDate = $uebernahmedatum === '' || $benotungsdatum > $uebernahmedatum + $checkDate = $uebernahmedatum === '' || $benotungsdatum > $uebernahmedatum ? $benotungsdatum : $uebernahmedatum; if ($checkDate >= $this->input->post('datum') && $note !== $note->note) { - $this->terminateWithSuccess($return_code + 2); + $this->PruefungModel->db->trans_complete(); + $this->terminateWithSuccess($this->p->t('exam', 'hinweis_changeAfterExamDate')); } - $this->terminateWithSuccess($return_code + 2); + + //update zeugnisnote, if existing and valid datum + $result = $this->ZeugnisnoteModel->update([ + 'lehrveranstaltung_id' => $lehrveranstaltung_id, + 'student_uid' => $this->input->post('student_uid'), + 'studiensemester_kurzbz' => $studiensemester_kurzbz + ], [ + 'note' => $this->input->post('note'), + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $this->input->post('datum'), + 'updateamum' => date('c'), + 'updatevon' => $authUID, + 'punkte' => $this->input->post('punkte') ? str_replace(',', '.', $this->input->post('punkte')) : null + ]); + + + $this->PruefungModel->db->trans_complete(); + $this->terminateWithSuccess(); } /** diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js b/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js index 4dd3139ab..c0c3fd448 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js @@ -229,9 +229,8 @@ export default{ return this.$refs.examData .call(ApiStvExam.addPruefung(this.pruefungData)) .then(response => { - this.checkData = response.data; - if (this.checkData === 2 || this.checkData === 5) - this.$fhcAlert.alertInfo(this.$p.t('exam', 'hinweis_changeAfterExamDate')); + if (response.data) + this.$fhcAlert.alertDefault('info', 'Info', response.data, true); else this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.hideModal('pruefungModal'); From 1666ba82b2bb940fc3ae8ec9ff39a8cc9bfc09b7 Mon Sep 17 00:00:00 2001 From: chfhtw Date: Fri, 21 Nov 2025 10:42:13 +0100 Subject: [PATCH 2/2] Bugfix: correct compare values in Pruefung->insertPruefung() --- application/controllers/api/frontend/v1/stv/Pruefung.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Pruefung.php b/application/controllers/api/frontend/v1/stv/Pruefung.php index 1cdbf86bd..56f0d9597 100644 --- a/application/controllers/api/frontend/v1/stv/Pruefung.php +++ b/application/controllers/api/frontend/v1/stv/Pruefung.php @@ -324,7 +324,7 @@ class Pruefung extends FHCAPI_Controller ? $benotungsdatum : $uebernahmedatum; - if ($checkDate >= $this->input->post('datum') && $note !== $note->note) + if ($checkDate >= $this->input->post('datum') && $this->input->post('note') !== $note->note) { $this->PruefungModel->db->trans_complete(); $this->terminateWithSuccess($this->p->t('exam', 'hinweis_changeAfterExamDate')); @@ -344,7 +344,6 @@ class Pruefung extends FHCAPI_Controller 'punkte' => $this->input->post('punkte') ? str_replace(',', '.', $this->input->post('punkte')) : null ]); - $this->PruefungModel->db->trans_complete(); $this->terminateWithSuccess(); }