From 58403ff00ede4f0fda50f6e994c3882d290ec127 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Mon, 15 Jul 2024 15:41:45 +0200 Subject: [PATCH] bugfixes changeStatus, generateMatrikelnummer, updateLists, validations --- .../api/frontend/v1/stv/Status.php | 456 ++++++++++-------- .../libraries/PrestudentstatusCheckLib.php | 29 ++ .../models/crm/Prestudentstatus_model.php | 43 ++ application/models/crm/Student_model.php | 6 +- .../Details/Prestudent/MultiStatus.js | 112 +---- system/phrasesupdate.php | 22 +- 6 files changed, 351 insertions(+), 317 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Status.php b/application/controllers/api/frontend/v1/stv/Status.php index f305cd29e..aa779c78f 100644 --- a/application/controllers/api/frontend/v1/stv/Status.php +++ b/application/controllers/api/frontend/v1/stv/Status.php @@ -11,7 +11,7 @@ class Status extends FHCAPI_Controller parent::__construct([ 'getHistoryPrestudent' => ['admin:r', 'assistenz:r'], 'addNewStatus' => ['admin:r', 'assistenz:r', 'student/keine_studstatuspruefung'], - 'turnIntoStudent' => ['admin:r', 'assistenz:r', 'student/keine_studstatuspruefung'], + //'turnIntoStudent' => ['admin:r', 'assistenz:r', 'student/keine_studstatuspruefung'], 'addStudent' => ['admin:r', 'assistenz:r', 'student/keine_studstatuspruefung'], 'getStatusgruende' => self::PERM_LOGGED, 'getLastBismeldestichtag' => self::PERM_LOGGED, @@ -28,6 +28,7 @@ class Status extends FHCAPI_Controller //Load Models $this->load->model('crm/Prestudentstatus_model','PrestudentstatusModel'); + $this->load->model('person/Person_model','PersonModel'); // Load Libraries $this->load->library('VariableLib', ['uid' => getAuthUID()]); @@ -448,239 +449,251 @@ class Status extends FHCAPI_Controller } //TODO(Manu) DEPRECATED - public function turnIntoStudent($prestudent_id) - { + // public function turnIntoStudent($prestudent_id) + // { - //get Studiengang von prestudent_id - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $this->PrestudentModel->addJoin('public.tbl_person p', 'ON (p.person_id = public.tbl_prestudent.person_id)'); - $this->PrestudentModel->addJoin('public.tbl_studiengang sg', 'ON (sg.studiengang_kz = public.tbl_prestudent.studiengang_kz)'); - $result = $this->PrestudentModel->load([ - 'prestudent_id' => $prestudent_id, - ]); - if (isError($result)) { - return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } - $result = current(getData($result)); + // //get Studiengang von prestudent_id + // $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + // $this->PrestudentModel->addJoin('public.tbl_person p', 'ON (p.person_id = public.tbl_prestudent.person_id)'); + // $this->PrestudentModel->addJoin('public.tbl_studiengang sg', 'ON (sg.studiengang_kz = public.tbl_prestudent.studiengang_kz)'); + // $result = $this->PrestudentModel->load([ + // 'prestudent_id' => $prestudent_id, + // ]); + // if (isError($result)) { + // return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + // } + // $result = current(getData($result)); - $stg = $result->studiengang_kz; - $stgkzl = $result->kurzbz; - $person_id = $result->person_id; + // $stg = $result->studiengang_kz; + // $stgkzl = $result->kurzbz; + // $person_id = $result->person_id; - if (!$this->permissionlib->isBerechtigt('admin', 'suid', $stg) && !$this->permissionlib->isBerechtigt('assistenz', 'suid', $stg)) { - $result = $this->p->t('lehre', 'error_keineSchreibrechte'); + // if (!$this->permissionlib->isBerechtigt('admin', 'suid', $stg) && !$this->permissionlib->isBerechtigt('assistenz', 'suid', $stg)) { + // $result = $this->p->t('lehre', 'error_keineSchreibrechte'); - return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } + // return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + // } - $_POST = json_decode(utf8_encode($this->input->raw_input_stream), true); + // $_POST = json_decode(utf8_encode($this->input->raw_input_stream), true); - $uid = getAuthUID(); - $status_kurzbz = $this->input->post('status_kurzbz'); - $ausbildungssemester = $this->input->post('ausbildungssemester'); - $bestaetigtam = $this->input->post('bestaetigtam'); - $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); - $bestaetigtvon = $uid; + // $uid = getAuthUID(); + // $status_kurzbz = $this->input->post('status_kurzbz'); + // $ausbildungssemester = $this->input->post('ausbildungssemester'); + // $bestaetigtam = $this->input->post('bestaetigtam'); + // $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + // $bestaetigtvon = $uid; - //Form Validation - $this->load->library('form_validation'); + // //Form Validation + // $this->load->library('form_validation'); - $this->form_validation->set_rules('ausbildungssemester', 'Ausbildungssemester', 'integer', [ - 'integer' => $this->p->t('ui', 'error_fieldNotInteger', ['field' => 'Ausbildungssemester']) - ]); + // $this->form_validation->set_rules('ausbildungssemester', 'Ausbildungssemester', 'integer', [ + // 'integer' => $this->p->t('ui', 'error_fieldNotInteger', ['field' => 'Ausbildungssemester']) + // ]); - if (!$this->form_validation->run()) - $this->terminateWithValidationErrors($this->form_validation->error_array()); + // if (!$this->form_validation->run()) + // $this->terminateWithValidationErrors($this->form_validation->error_array()); - //GET lastStatus - $result = $this->PrestudentstatusModel->getLastStatus($prestudent_id); + // //GET lastStatus + // $result = $this->PrestudentstatusModel->getLastStatus($prestudent_id); - if (isError($result)) { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } elseif (!hasData($result)) { - $lastStatusData = []; - } else - $lastStatusData = current(getData($result)); + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } elseif (!hasData($result)) { + // $lastStatusData = []; + // } else + // $lastStatusData = current(getData($result)); - //check if studentrolle already exists - $this->load->model('crm/Student_model', 'StudentModel'); - $result = $this->StudentModel->checkIfExistingStudentRolle($prestudent_id); - if (isError($result)) { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - if ($result->retval == "0") { - $isStudent = false; - } else - $isStudent = true; + // //check if studentrolle already exists + // $this->load->model('crm/Student_model', 'StudentModel'); + // $result = $this->StudentModel->checkIfExistingStudentRolle($prestudent_id); + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } + // if ($result->retval == "0") { + // $isStudent = false; + // } else + // $isStudent = true; - if (!$isStudent) { + // return $this->terminateWithError("here: before check: isStudent: " . $isStudent, self::ERROR_TYPE_GENERAL); - //Check ZGV - if ($status_kurzbz == Prestudentstatus_model::STATUS_BEWERBER) { - $result = $this->prestudentstatuschecklib->checkIfZGVEingetragen($prestudent_id); - if (isError($result)) { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - } + // if (!$isStudent) { - //Check ZGV-Master - $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); - $result = $this->StudiengangModel->load([ - 'studiengang_kz' => $stg - ]); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } - $result = current(getData($result)); - $typ = $result->typ; + // //Check ZGV + // if ($status_kurzbz == Prestudentstatus_model::STATUS_BEWERBER) { + // $result = $this->prestudentstatuschecklib->checkIfZGVEingetragen($prestudent_id); + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } + // } - if (!defined("ZGV_CHECK") || ZGV_CHECK) { - if ($status_kurzbz == Prestudentstatus_model::STATUS_BEWERBER && $typ == 'm') { - $result = $this->prestudentstatuschecklib->checkIfZGVEingetragen($prestudent_id, $typ); - if (isError($result)) { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - } - } + // //Check ZGV-Master + // $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + // $result = $this->StudiengangModel->load([ + // 'studiengang_kz' => $stg + // ]); + // if (isError($result)) { + // $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + // return $this->outputJson(getError($result)); + // } + // $result = current(getData($result)); + // $typ = $result->typ; - //check if bewerberstatus exists - $result = $result = $this->prestudentstatuschecklib->checkIfExistingBewerberstatus($prestudent_id); - if (isError($result)) { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } + // if (!defined("ZGV_CHECK") || ZGV_CHECK) { + // if ($status_kurzbz == Prestudentstatus_model::STATUS_BEWERBER && $typ == 'm') { + // $result = $this->prestudentstatuschecklib->checkIfZGVEingetragen($prestudent_id, $typ); + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } + // } + // } - //checkIf Kaution bezahlt - //TODO(Manu) + // //check if bewerberstatus exists + // $result = $this->prestudentstatuschecklib->checkIfExistingBewerberstatus($prestudent_id); + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } - //generate Personenkennzeichen(matrikelnr) - $resultMat = $this->StudentModel->generateMatrikelnummer2($stg, $studiensemester_kurzbz, $typ); - if (isError($resultMat)) { - return $this->terminateWithError($resultMat, self::ERROR_TYPE_GENERAL); - } - $matrikelnr = getData($resultMat); - $jahr = mb_substr($matrikelnr, 0, 2); + // //checkIf Kaution bezahlt + // //TODO(Manu) - //generate UID - $resultUid = $this->StudentModel->generateUID($stgkzl, $jahr, $typ, $matrikelnr); - if (isError($resultMat)) { - return $this->terminateWithError("in generateUid" . $resultUid, self::ERROR_TYPE_GENERAL); - } - $uidStudent = getData($resultUid); + // //check if Aufgenommenener Status + // $result = $this->prestudentstatuschecklib->checkIfExistingAufgenommenerstatus($prestudent_id); + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } - //Check for additional logic (config entries, addons) - //TODO(Manu) check include/tw/generatematrikelnr.inc.php - //(1) addons durchsuchen, ob eigene Logik für Matrikelnr-erstellung existiert - //Default: keine Matrikelnummer wird generiert - - //(2) personenkz = uid - if (defined('SET_UID_AS_PERSONENKENNZEICHEN') && SET_UID_AS_PERSONENKENNZEICHEN) { - $matrikelnr = $uidStudent; - } - - //(3) Matrikelnummer = uid - if (defined('SET_UID_AS_MATRIKELNUMMER') && SET_UID_AS_MATRIKELNUMMER) { - //update person - $result = $this->PersonModel->update( - [ - 'person_id' => $person_id, - ], - [ - 'matr_nr' => $uidStudent, - ] - ); - if (isError($result)) { - return $this->terminateWithError("uidAsMatrikelnummer" . getError($result), self::ERROR_TYPE_GENERAL); - } - } - - //TODO(Manu) check if benutzer already exists to avoid conflicts.. - //person kann mehrere Benutzer haben... student_uid? - //add benutzerdatensatz mit Aktierungscode - $this->load->model('person/Benutzer_model', 'BenutzerModel'); - $result = $this->BenutzerModel->checkIfExistingBenutzer($person_id); - if (isError($result)) { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - if ($result->retval == "0") { - - //activation key - $aktivierungscode = null; - $result = $this->BenutzerModel->generateActivationKey(); - if (isError($result)) { - return $this->terminateWithError("in Error " . $result, self::ERROR_TYPE_GENERAL); - } - $aktivierungscode = getData($result); + // return $this->terminateWithError("here: after check: new Student", self::ERROR_TYPE_GENERAL); - //Alias generieren - $result = $this->PersonModel->generateAliasByPersonId($person_id); - if (isError($result)) { - return $this->terminateWithError("in generate alias " . $result, self::ERROR_TYPE_GENERAL); - } - $alias = getData($result) ?: null; - $alias = $alias->retval[0]; + // //generate Personenkennzeichen(matrikelnr) + // //getStudiensemester vom Status aufgenommen + // $resultMat = $this->StudentModel->generateMatrikelnummer2($stg, $studiensemester_kurzbz, $typ); + // if (isError($resultMat)) { + // return $this->terminateWithError($resultMat, self::ERROR_TYPE_GENERAL); + // } + // $matrikelnr = getData($resultMat); + // $jahr = mb_substr($matrikelnr, 0, 2); - $sanitizedVorname = $this->_sanitizeAliasName($alias->vorname); - $sanitizedNachname = $this->_sanitizeAliasName($alias->nachname); + // //generate UID + // $resultUid = $this->StudentModel->generateUID($stgkzl, $jahr, $typ, $matrikelnr); + // if (isError($resultMat)) { + // return $this->terminateWithError("in generateUid" . $resultUid, self::ERROR_TYPE_GENERAL); + // } + // $uidStudent = getData($resultUid); - // Erstelle den Alias - $alias = $sanitizedVorname . '.' . $sanitizedNachname; + // //Check for additional logic (config entries, addons) + // //TODO(Manu) check include/tw/generatematrikelnr.inc.php + // //(1) addons durchsuchen, ob eigene Logik für Matrikelnr-erstellung existiert + // //Default: keine Matrikelnummer wird generiert - if (isError($result)) { - return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } + // //(2) personenkz = uid + // if (defined('SET_UID_AS_PERSONENKENNZEICHEN') && SET_UID_AS_PERSONENKENNZEICHEN) { + // $matrikelnr = $uidStudent; + // } - $result = $this->BenutzerModel->insert( - [ - 'person_id' => $person_id, - 'uid' => $uidStudent, - 'aktiv' => true, - 'aktivierungscode' => $aktivierungscode, - 'alias' => $alias, - 'insertvon' => $uid, - 'insertamum' => date('c'), - ] - ); + // //(3) Matrikelnummer = uid + // if (defined('SET_UID_AS_MATRIKELNUMMER') && SET_UID_AS_MATRIKELNUMMER) { + // //update person + // $result = $this->PersonModel->update( + // [ + // 'person_id' => $person_id, + // ], + // [ + // 'matr_nr' => $uidStudent, + // ] + // ); + // if (isError($result)) { + // return $this->terminateWithError("uidAsMatrikelnummer" . getError($result), self::ERROR_TYPE_GENERAL); + // } + // } - if (isError($result)) { - return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } + // //TODO(Manu) check if benutzer already exists to avoid conflicts.. + // //person kann mehrere Benutzer haben... student_uid? + // //add benutzerdatensatz mit Aktierungscode + // $this->load->model('person/Benutzer_model', 'BenutzerModel'); + // $result = $this->BenutzerModel->checkIfExistingBenutzer($person_id); + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } + // if ($result->retval == "0") { - } else - return $this->terminateWithError("Benutzer already existing" . $person_id, self::ERROR_TYPE_GENERAL); + // //activation key + // $aktivierungscode = null; + // $result = $this->BenutzerModel->generateActivationKey(); + // if (isError($result)) { + // return $this->terminateWithError("in Error " . $result, self::ERROR_TYPE_GENERAL); + // } + // $aktivierungscode = getData($result); - //Student anlegen - $result = $this->StudentModel->insert( - [ - 'student_uid' => $uidStudent, - 'prestudent_id' => $prestudent_id, - 'matrikelnr' => $matrikelnr, - 'studiengang_kz' => $stg, - 'semester' => $ausbildungssemester, - 'verband' => '', - 'gruppe' => '', - 'insertvon' => $uid, - 'insertamum' => date('c') - ] - ); - if (isError($result)) - { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - $this->load->library('PrestudentLib'); - $result = $this->prestudentlib->setFirstStudent($prestudent_id, $studiensemester_kurzbz, $ausbildungssemester, null, $bestaetigtam, $bestaetigtvon, $stg, $uidStudent); + // //Alias generieren + // $result = $this->PersonModel->generateAliasByPersonId($person_id); + // if (isError($result)) { + // return $this->terminateWithError("in generate alias " . $result, self::ERROR_TYPE_GENERAL); + // } + // $alias = getData($result) ?: null; + // $alias = $alias->retval[0]; - if (isError($result)) { - return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } else - $this->terminateWithSuccess($prestudent_id); + // $sanitizedVorname = $this->_sanitizeAliasName($alias->vorname); + // $sanitizedNachname = $this->_sanitizeAliasName($alias->nachname); - } - else - return $this->terminateWithError("addNewStatus(student)", self::ERROR_TYPE_GENERAL); - } + // // Erstelle den Alias + // $alias = $sanitizedVorname . '.' . $sanitizedNachname; + + // if (isError($result)) { + // return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + // } + + // $result = $this->BenutzerModel->insert( + // [ + // 'person_id' => $person_id, + // 'uid' => $uidStudent, + // 'aktiv' => true, + // 'aktivierungscode' => $aktivierungscode, + // 'alias' => $alias, + // 'insertvon' => $uid, + // 'insertamum' => date('c'), + // ] + // ); + + // if (isError($result)) { + // return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + // } + + // } else + // return $this->terminateWithError("Benutzer already existing" . $person_id, self::ERROR_TYPE_GENERAL); + + // //Student anlegen + // $result = $this->StudentModel->insert( + // [ + // 'student_uid' => $uidStudent, + // 'prestudent_id' => $prestudent_id, + // 'matrikelnr' => $matrikelnr, + // 'studiengang_kz' => $stg, + // 'semester' => $ausbildungssemester, + // 'verband' => '', + // 'gruppe' => '', + // 'insertvon' => $uid, + // 'insertamum' => date('c') + // ] + // ); + // if (isError($result)) + // { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } + + // $this->load->library('PrestudentLib'); + // $result = $this->prestudentlib->setFirstStudent($prestudent_id, $studiensemester_kurzbz, $ausbildungssemester, null, $bestaetigtam, $bestaetigtvon, $stg, $uidStudent); + + // if (isError($result)) { + // return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + // } else + // $this->terminateWithSuccess($prestudent_id); + + // } + // else + // return $this->terminateWithError("addNewStatus(student)", self::ERROR_TYPE_GENERAL); + // } public function addStudent($prestudent_id) { @@ -803,7 +816,7 @@ class Status extends FHCAPI_Controller } //check if bewerberstatus exists - if($status_kurzbz == Prestudentstatus_model::STATUS_AUFGENOMMENER || $status_kurzbz == Prestudentstatus_model::STATUS_WARTENDER) + if($status_kurzbz == Prestudentstatus_model::STATUS_AUFGENOMMENER || $status_kurzbz == Prestudentstatus_model::STATUS_WARTENDER ||$status_kurzbz == Prestudentstatus_model::STATUS_STUDENT) { $result = $this->prestudentstatuschecklib->checkIfExistingBewerberstatus($prestudent_id); @@ -841,15 +854,32 @@ class Status extends FHCAPI_Controller } } - // return ($this->terminateWithError("Is Student " . $isStudent, self::ERROR_TYPE_GENERAL)); - if(!$isStudent) { //checkIf Kaution bezahlt //TODO(Manu) + //check if Aufgenommenener Status + $result = $this->prestudentstatuschecklib->checkIfExistingAufgenommenerstatus($prestudent_id); + if (isError($result)) { + return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + //getSemester of Status Aufgenommen + $result = $this->PrestudentstatusModel->loadWhere([ + "prestudent_id" => $prestudent_id, + "status_kurzbz" => Prestudentstatus_model::STATUS_AUFGENOMMENER + ]); + //$this->PrestudentstatusModel->addOrder('ausbildungssemester', 'DESC'); + $this->PrestudentstatusModel->addLimit(1); + if (isError($result)) + { + return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + $semesterAufgenommen = current(getData($result)); + //generate Personenkennzeichen(matrikelnr) - $resultMat = $this->StudentModel->generateMatrikelnummer2($stg, $studiensemester_kurzbz, $typ); + $resultMat = $this->StudentModel->generateMatrikelnummer2($stg, $semesterAufgenommen->studiensemester_kurzbz, $typ); if (isError($resultMat)) { return $this->terminateWithError($resultMat, self::ERROR_TYPE_GENERAL); } @@ -859,7 +889,7 @@ class Status extends FHCAPI_Controller //generate UID $resultUid = $this->StudentModel->generateUID($stgkzl, $jahr, $typ, $matrikelnr); if (isError($resultMat)) { - return $this->terminateWithError("in generateUid" . $resultUid, self::ERROR_TYPE_GENERAL); + return $this->terminateWithError(getData($resultUid), self::ERROR_TYPE_GENERAL); } $uidStudent = getData($resultUid); @@ -897,30 +927,29 @@ class Status extends FHCAPI_Controller } if ($result->retval != "0") { - // return ($this->terminateWithError($result->retval . " uid: " . $uid, self::ERROR_TYPE_GENERAL)); return $this->terminateWithError($this->p->t('lehre','error_benutzerBereitsVorhanden', self::ERROR_TYPE_GENERAL)); } - //activation key + $aktivierungscode = null; $result = $this->BenutzerModel->generateActivationKey(); if (isError($result)) { - return $this->terminateWithError("in Error " . $result, self::ERROR_TYPE_GENERAL); + return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); } $aktivierungscode = getData($result); - //Alias generieren + //generate Alias $result = $this->PersonModel->generateAliasByPersonId($person_id); + if (isError($result)) { - return $this->terminateWithError("in generate alias " . $result, self::ERROR_TYPE_GENERAL); + return $this->terminateWithError(getData($result), self::ERROR_TYPE_GENERAL); } + $alias = getData($result) ?: null; $alias = $alias->retval[0]; $sanitizedVorname = $this->_sanitizeAliasName($alias->vorname); $sanitizedNachname = $this->_sanitizeAliasName($alias->nachname); - - // Erstelle den Alias $alias = $sanitizedVorname . '.' . $sanitizedNachname; if (isError($result)) @@ -943,7 +972,6 @@ class Status extends FHCAPI_Controller return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); } - //Student anlegen $result = $this->StudentModel->insert( [ diff --git a/application/libraries/PrestudentstatusCheckLib.php b/application/libraries/PrestudentstatusCheckLib.php index b238219a8..23afb7563 100644 --- a/application/libraries/PrestudentstatusCheckLib.php +++ b/application/libraries/PrestudentstatusCheckLib.php @@ -245,6 +245,35 @@ class PrestudentstatusCheckLib return success(getData($result)); } + /** + * Checks if status aufgenommen already exists. + * @return error if invalid + * @return error if no status Aufgenommen, success otherwise + */ + public function checkIfExistingAufgenommenerstatus($prestudent_id) + { + $result = $this->_getApplicationData($prestudent_id); + if(isError($result)) + { + return getData($result); + } + $result = current(getData($result)); + $studentName = trim ($result->vorname.' '.$result->nachname); + + $result = $this->_ci->PrestudentstatusModel->checkIfExistingAufgenommenerstatus( + $prestudent_id + ); + if(isError($result)) + { + return getData($result); + } + if(getData($result) == "0") + { + return error($this->_ci->p->t('lehre','error_keinAufgenommener', ['name' => $studentName])); + } + return success(getData($result)); + } + /** * Check if Bismeldestichtag erreicht * @param Date $statusDatum diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index 26b603a66..b13bc6306 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -12,6 +12,7 @@ class Prestudentstatus_model extends DB_Model const STATUS_AUFGENOMMENER = 'Aufgenommener'; const STATUS_WARTENDER = 'Wartender'; const STATUS_ABGEWIESENER = 'Abgewiesener'; + const STATUS_INTERESSENT = 'Interessent'; /** * Constructor @@ -438,6 +439,48 @@ class Prestudentstatus_model extends DB_Model } } + /** + * Check if Rolle there is an existing Aufgenommenerstatus + * @param integer $prestudent_id + * @return error if no status Aufgenommener, success if existing + */ + public function checkIfExistingAufgenommenerstatus($prestudent_id) + { + $studentName = ''; + + $nameRes = $this->PersonModel->loadPrestudent($prestudent_id); + + if (hasData($nameRes)) + { + $nameData = getData($nameRes)[0]; + $studentName = $nameData->vorname.' '.$nameData->nachname; + } + + $qry = "SELECT + * + FROM + public.tbl_prestudentstatus + WHERE + prestudent_id = ? + AND + status_kurzbz = 'Aufgenommener'"; + + $result = $this->execQuery($qry, array($prestudent_id)); + + if (isError($result)) + { + return error($result); + } + elseif (!hasData($result)) + { + return success("0", $this->p->t('lehre','error_keinAufgenommener', ['name' => $studentName])); + } + else + { + return success($result); + } + } + /** * Check if there is only one prestudentstatus left * @param integer $prestudent_id diff --git a/application/models/crm/Student_model.php b/application/models/crm/Student_model.php index 92a6ed25b..1bc77420c 100644 --- a/application/models/crm/Student_model.php +++ b/application/models/crm/Student_model.php @@ -108,9 +108,9 @@ class Student_model extends DB_Model $max = 0; if ($matrikelnrres && hasData($matrikelnrres)) { $max = mb_substr($matrikelnrres->retval[0]->matrikelnr, 7); -/* if (!is_numeric($max)) { - $max = 0; - }*/ + if (!is_numeric($max)) { + $max = (int) $max; + } } $max += 1; diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js b/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js index 9261eee1d..b0569842d 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js @@ -471,99 +471,9 @@ export default{ this.newArray = this.updateData.map(objekt => ({ ...objekt, ...deltaData})); this.addNewStatus(prestudentIds); - }, - turnIntoStudent(prestudentIds){ - - //erste Voraussetzung: kein check auf checkIfExistingStudent - // macht aus einem Bewerber einen Studenten - // Voraussetzungen: - // - ZGV muss ausgefuellt sein (bei Master beide) - // - Kaution muss bezahlt sein - // - Rolle Bewerber muss existieren - // Wenn die Voraussetzungen erfuellt sind, dann wird die Matrikelnr - // und UID generiert und der Studentendatensatz angelegt. - let changeData = {}; - - //for Feedback Sucess, Error - let countSuccess = 0; - let countError = 0; - - const promises = prestudentIds.map(prestudentId => { - - this.checkIfErsterStudent(prestudentId).then(() => { - - if(this.isErsterStudent) - { - console.log(prestudentId + ": isersterStudent: " + this.isErsterStudent + " Logik turnIntoStudent"); - - changeData = this.newArray.find(item => item.prestudent_id === prestudentId); - - return this.$fhcApi.post('api/frontend/v1/stv/status/turnIntoStudent/' + prestudentId, - changeData - ).then(response => { - countSuccess++; - return response; - }) - //.catch(this.$fhcAlert.handleSystemError) - .catch(error => { - countError++; - //For each Prestudent show Error in Alert - this.$fhcAlert.handleSystemError(error); - }); - } - else - { - console.log(prestudentId + ": isersterStudent: " + this.isErsterStudent + " Add New Status"); - changeData = this.newArray.find(item => item.prestudent_id === prestudentId); - - return this.$fhcApi.post('api/frontend/v1/stv/status/addNewStatus/' + prestudentId, - changeData - ).then(response => { - countSuccess++; - return response; - }) - //.catch(this.$fhcAlert.handleSystemError) - .catch(error => { - countError++; - //For each Prestudent show Error in Alert - this.$fhcAlert.handleSystemError(error); - }); - } - }); - }); - - Promise - .allSettled(promises) - .then(values => { - - //Feedback Success als infoalert - if (countSuccess > 0) { - this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { - 'countSuccess': countSuccess, - 'status': this.newStatus, - 'countError': countError - })); - } - -/* if (this.modelValue.prestudent_id) { - this.reload(); - //TODO(manu) reload Detailtab after Abbrecher to see current status activ, verband and gruppe - }*/ - if(this.isErsterStudent) { - this.reload(); - this.isErsterStudent = false; - } - else { - this.$reloadList(); - } - this.hideModal('statusModal'); - this.resetModal(); - }); - - }, addStudent(prestudentIds){ - //Array.isArray(prestudentIds) ? this.modelValue.prestudent_id : [prestudentIds]; + let changeData = {}; //for Feedback Sucess, Error @@ -668,12 +578,16 @@ export default{ })); } - if (this.modelValue.prestudent_id) { - this.reload(); - } - else { - this.$reloadList(); - } + //TODO(Manu) bei status Interessent, Bewerber, aufgenommener, reload nicht working + this.reload(); + this.reloadList(); + + // if (this.modelValue.prestudent_id) { + // this.reload(); + // } + // else { + // this.$reloadList(); + // } this.hideModal('statusModal'); this.resetModal(); }); @@ -868,8 +782,8 @@ export default{ .then(result => { this.dataMeldestichtag = result.data[0].meldestichtag; //TODO(Manu) wirft plötzlich fehler bei multiselect status -/* if (this.$refs.table.tableBuilt) - this.$refs.table.tabulator.redraw(true);*/ + // if (this.$refs.table.tableBuilt) + // this.$refs.table.tabulator.redraw(true); }) .catch(this.$fhcAlert.handleSystemError); }, diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 171fd77e6..6f458b465 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -27535,7 +27535,7 @@ array( 'insertvon' => 'system' ) ) - ) + ), //Prestudent array( 'app' => 'core', @@ -28057,6 +28057,26 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'lehre', + 'phrase' => 'error_keinAufgenommener', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => '{name} muss zuerst Aufgenommener sein, um zum Studenten gemacht werden zu können!', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => '{name} must first be admitted in order to be made a student!', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), array( 'app' => 'core', 'category' => 'lehre',