From 3a6fb08350c100c61f1f4c843754e9e33a60d6e1 Mon Sep 17 00:00:00 2001 From: Alexei Karpenko Date: Thu, 2 Oct 2025 16:52:11 +0200 Subject: [PATCH 01/30] Creating of Interessenten: moved to PRestudentlib, renamed check to getPerson, corrected transaction handling, enabled creating of Incomings --- .../api/frontend/v1/stv/Student.php | 552 ++++++++++-------- application/libraries/PrestudentLib.php | 216 +++++++ application/models/crm/Student_model.php | 4 +- public/js/api/factory/stv/students.js | 4 +- .../Stv/Studentenverwaltung/List.js | 2 - .../Stv/Studentenverwaltung/List/New.js | 48 +- 6 files changed, 541 insertions(+), 285 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Student.php b/application/controllers/api/frontend/v1/stv/Student.php index 23a8fc7cb..d5737dc2f 100644 --- a/application/controllers/api/frontend/v1/stv/Student.php +++ b/application/controllers/api/frontend/v1/stv/Student.php @@ -36,7 +36,7 @@ class Student extends FHCAPI_Controller parent::__construct([ 'get' => ['admin:r', 'assistenz:r'], 'save' => ['admin:rw', 'assistenz:rw'], - 'check' => ['admin:rw', 'assistenz:rw'], + 'getPerson' => ['admin:rw', 'assistenz:rw'], 'add' => ['admin:rw', 'assistenz:rw'] // TODO(chris): extra permissions ]); @@ -111,12 +111,12 @@ class Student extends FHCAPI_Controller if (defined('ACTIVE_ADDONS') && strpos(ACTIVE_ADDONS, 'bewerbung') !== false) { $this->PrestudentModel->addSelect( "( - SELECT kontakt - FROM public.tbl_kontakt - WHERE kontakttyp='email' - AND person_id=p.person_id - AND zustellung - ORDER BY kontakt_id + SELECT kontakt + FROM public.tbl_kontakt + WHERE kontakttyp='email' + AND person_id=p.person_id + AND zustellung + ORDER BY kontakt_id LIMIT 1 ) AS email_privat", false @@ -146,9 +146,9 @@ class Student extends FHCAPI_Controller 'LEFT');*/ $result = $this->PrestudentModel->loadWhere(['tbl_prestudent.prestudent_id' => $prestudent_id]); - + $student = $this->getDataOrTerminateWithError($result); - + if (!$student) return show_404(); @@ -208,7 +208,7 @@ class Student extends FHCAPI_Controller ]); $this->load->library('UDFLib'); - + $result = $this->udflib->getCiValidations($this->PersonModel, $this->input->post()); $udf_field_validations = $this->getDataOrTerminateWithError($result); @@ -219,7 +219,7 @@ class Student extends FHCAPI_Controller $this->terminateWithValidationErrors($this->form_validation->error_array()); $result = $this->StudentModel->loadWhere(['prestudent_id' => $prestudent_id]); - + $student = $this->getDataOrTerminateWithError($result); $uid = $student ? current($student)->student_uid : null; @@ -232,7 +232,6 @@ class Student extends FHCAPI_Controller $person_id = $person ? current($person)->person_id : null; - $array_allowed_props_lehrverband = ['verband', 'semester', 'gruppe']; $update_lehrverband = array(); foreach ($array_allowed_props_lehrverband as $prop) { @@ -282,7 +281,7 @@ class Student extends FHCAPI_Controller } $array_allowed_props_student = ['matrikelnr']; - if($this->isLaufendesSemester($studiensemester_kurzbz)) + if($this->isLaufendesSemester($studiensemester_kurzbz)) { $array_allowed_props_student = ['matrikelnr', 'verband', 'semester', 'gruppe']; } @@ -414,7 +413,7 @@ class Student extends FHCAPI_Controller ), '')); } - public function check() + public function getPerson() { $this->load->library('form_validation'); @@ -436,11 +435,11 @@ class Student extends FHCAPI_Controller $this->PersonModel->db->where('gebdatum', (new DateTime($gebdatum))->format('Y-m-d')); if ($vorname && $nachname) { $this->PersonModel->db->or_group_start(); - $this->PersonModel->db->where('LOWER(nachname)', 'LOWER(' . $this->PersonModel->db->escape($nachname) . ')', false); - $this->PersonModel->db->where('LOWER(vorname)', 'LOWER(' . $this->PersonModel->db->escape($vorname) . ')', false); + $this->PersonModel->db->where('LOWER(nachname)', 'LOWER(' . $this->PersonModel->db->escape(trim($nachname)) . ')', false); + $this->PersonModel->db->where('LOWER(vorname)', 'LOWER(' . $this->PersonModel->db->escape(trim($vorname)) . ')', false); $this->PersonModel->db->group_end(); } elseif ($nachname) { - $this->PersonModel->db->or_where('LOWER(nachname)', 'LOWER(' . $this->PersonModel->escape($nachname) . ')', false); + $this->PersonModel->db->or_where('LOWER(nachname)', 'LOWER(' . $this->PersonModel->escape(trim($nachname)) . ')', false); } $result = $this->PersonModel->load(); @@ -460,6 +459,279 @@ class Student extends FHCAPI_Controller $_POST['ausbildungssemester'] = 0; } + $this->_validate(); + + // TODO(chris): This should be in a library + $this->load->model('crm/Student_model', 'StudentModel'); + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + $this->load->model('organisation/Lehrverband_model', 'LehrverbandModel'); + $this->load->model('education/Studentlehrverband_model', 'StudentlehrverbandModel'); + + $this->load->library('PrestudentLib'); + + $errors = []; + $person_id = null; + + $this->db->trans_begin(); + + $result = $this->_addPerson(); + if (hasData($result)) + { + $person_id = getData($result); + $result = $this->_addAdresse($person_id); + if (isError($result)) $errors[] = getError($result); + $result = $this->_addKontakt($person_id); + if (isError($result)) $errors[] = getError($result); + if (!$this->input->post('personOnly')) $result = $this->_addInteressent($person_id); + if (isError($result)) $errors[] = getError($result); + } + + if ($this->db->trans_status() === FALSE || !isEmptyArray($errors)) + { + $this->db->trans_rollback(); + $this->terminateWithError(isEmptyArray($errors) ? $this->p->t('stv', 'error_add_student') : $errors); + } + $this->db->trans_commit(); + + $this->terminateWithSuccess($person_id); + } + + private function _addPerson() + { + // Person anlegen wenn nötig + $person_id = $this->input->post('person_id'); + if (!$person_id) { + $this->load->model('person/Person_model', 'PersonModel'); + + $data = [ + 'nachname' => $this->input->post('nachname'), + 'insertamum' => date('c'), + 'insertvon' => getAuthUID(), + 'zugangscode' => uniqid(), + 'aktiv' => true + ]; + if ($this->input->post('anrede')) + $data['anrede'] = $this->input->post('anrede'); + if ($this->input->post('titelpre')) + $data['titelpre'] = $this->input->post('titelpre'); + if ($this->input->post('titelpost')) + $data['titelpost'] = $this->input->post('titelpost'); + if ($this->input->post('vorname')) + $data['vorname'] = $this->input->post('vorname'); + if ($this->input->post('vornamen')) + $data['vornamen'] = $this->input->post('vornamen'); + if ($this->input->post('wahlname')) + $data['wahlname'] = $this->input->post('wahlname'); + if ($this->input->post('geschlecht')) + $data['geschlecht'] = $this->input->post('geschlecht'); + if ($this->input->post('gebdatum')) + $data['gebdatum'] = (new DateTime($this->input->post('datum_obj')))->format('Y-m-d'); + if ($this->input->post('geburtsnation')) + $data['geburtsnation'] = $this->input->post('geburtsnation'); + if ($this->input->post('staatsbuergerschaft')) + $data['staatsbuergerschaft'] = $this->input->post('staatsbuergerschaft'); + + return $this->PersonModel->insert($data); + } + + return success($person_id); + } + + private function _addAdresse($person_id) + { + // Addresse anlegen? + $anlegen = $this->input->post('address[func]'); + if ($anlegen) + { + // Adresse laden + $this->load->model('person/Adresse_model', 'AdresseModel'); + + $data = [ + 'nation' => $this->input->post('address[nation]'), + 'strasse' => $this->input->post('address[address]'), + 'plz' => $this->input->post('address[plz]'), + 'ort' => $this->input->post('address[ort]'), + 'gemeinde' => $this->input->post('address[gemeinde]'), + 'typ' => 'h', + 'zustelladresse' => true, + ]; + + if ($anlegen < 0) // Adresse überschreiben + { + $this->AdresseModel->addSelect('adresse_id'); + $this->AdresseModel->addJoin('public.tbl_adressentyp', 'typ = adressentyp_kurzbz'); + $this->AdresseModel->addOrder('zustelladresse', 'DESC'); + $this->AdresseModel->addOrder('sort'); + $result = $this->AdresseModel->loadWhere([ + 'person_id' => $person_id + ]); + + if (isError($result)) return $result; + + if (hasData($result)) + { + $address = getData($result)[0]; + + $data['updateamum'] = date('c'); + $data['updatevon'] = getAuthUID(); + + return $this->AdresseModel->update($address->adresse_id, $data); + } + else { + //Wenn keine Adrese vorhanden ist dann eine neue Anlegen + $anlegen = 1; + $data['heimatadresse'] = true; + } + } + + if ($anlegen > 0) // Adresse hinzufügen + { + $data['person_id'] = $person_id; + $data['insertamum'] = date('c'); + $data['insertvon'] = getAuthUID(); + + // Wenn die Person neu angelegt wird, dann ist die neue Adresse die Heimatadresse + if (!isset($data['heimatadresse'])) + $data['heimatadresse'] = !$this->input->post('person_id'); + + return $this->AdresseModel->insert($data); + } + } + + return success(null); + } + + private function _addKontakt($person_id) + { + // Kontaktdaten + $kontaktdaten = []; + + foreach (['email', 'telefon', 'mobil'] as $k) + { + $v = $this->input->post($k); + if ($v) + $kontaktdaten[$k] = $v; + } + + if (count($kontaktdaten)) + { + $this->load->model('person/Kontakt_model', 'KontaktModel'); + + foreach ($kontaktdaten as $typ => $kontakt) + { + $data = [ + 'person_id' => $person_id, + 'kontakttyp' => $typ, + 'kontakt' => $kontakt, + 'zustellung' => true, + 'insertamum' => date('c'), + 'insertvon' => getAuthUID() + ]; + $result = $this->KontaktModel->insert($data); + if (isError($result)) return $result; + } + } + return success(null); + } + + private function _addInteressent($person_id) + { + // Prestudent anlegen + + // Anmerkung with Ausbildungsart + $studiengang_kz = $this->input->post('studiengang_kz'); + $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + $ausbildungsart = $this->input->post('ausbildungsart'); + $anmerkung = $this->input->post('anmerkungen'); + $foerderrelevant = null; + if ($ausbildungsart) + $anmerkung .= ' Ausbildungsart:' . $ausbildungsart; + + // Incomings und ausserordentliche sind bei Meldung nicht förderrelevant + $incoming = $this->input->post('incoming'); + if ($incoming || substr($studiengang_kz, 0, 1) == '9') + $foerderrelevant = false; + + // Prestudent speichern + $result = $this->prestudentlib->setPrestudent( + $person_id, + $studiengang_kz, + $this->input->post('letzteausbildung'), + $anmerkung, + $foerderrelevant + ); + if (isError($result)) return $result; + if (!hasData($result)) return error('Error when adding prestudent'); + + $prestudent_id = getData($result); + + // Prestudent Rolle Anlegen + $this->prestudentlib->setFirstStatus( + $prestudent_id, + $incoming ? 'Incoming' : 'Interessent', + $studiensemester_kurzbz, + $this->input->post('ausbildungssemester'), + $this->input->post('orgform_kurzbz'), + $this->input->post('studienplan_id') + ); + if (!hasData($result)) return error('error when adding status'); + if (isError($result)) return $result; + + if ($incoming) + { + $result = $this->prestudentlib->setIncoming($prestudent_id, $studiengang_kz, $studiensemester_kurzbz); + if (isError($result)) return $result; + } + // TODO(chris): DEBUG + /*$result = $this->PrestudentModel->loadWhere([ + 'pestudent_id' => 1 + ]); + if (isError($result)) { + return $result; + }*/ + + return success($prestudent_id); + } + + public function requiredIfNotPersonId($value) + { + if (isset($_POST['person_id'])) + return true; + return !!$value; + } + + public function requiredIfAddressFunc($value) + { + if (!$_POST['address']['func'] || $_POST['address']['func'] == 0) + return true; + return !!$value; + } + + public function requiredIfStudentFunc($value) + { + if (isset($_POST['personOnly']) && $_POST['personOnly']) + return true; + return !!$value; + } + + public function requiredIfStudentAndNotIncomingFunc($value) + { + if ((isset($_POST['incoming']) && $_POST['incoming']) || $this->requiredIfStudentFunc($value)) + return true; + return !!$value; + } + + public function isValidDate($value) + { + return isValidDate($value); + } + + /** + * Validates input data. Terminates with validation errors, if invalid. + */ + private function _validate() + { $this->load->library('form_validation'); $this->form_validation->set_rules('nachname', 'Nachname', 'callback_requiredIfNotPersonId', [ @@ -491,247 +763,19 @@ class Student extends FHCAPI_Controller $this->form_validation->set_rules('studiensemester_kurzbz', 'Studiensemester', 'callback_requiredIfStudentFunc', [ 'requiredIfStudentFunc' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'studiensemester')]) ]); - $this->form_validation->set_rules('ausbildungssemester', 'Ausbildungssemester', 'callback_requiredIfStudentFunc|integer|less_than[9]|greater_than[-1]', [ - 'requiredIfStudentFunc' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'ausbildungssemester')]) - ]); + $this->form_validation->set_rules( + 'ausbildungssemester', + 'Ausbildungssemester', + 'callback_requiredIfStudentAndNotIncomingFunc|integer|less_than[9]|greater_than[-1]', + [ + 'requiredIfStudentAndNotIncomingFunc' => + $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'ausbildungssemester')]), + ] + ); // TODO(chris): validate studienplan with studiengang, semester and orgform? // TODO(chris): validate person_id, studiengang_kz, studiensemester_kurzbz, orgform_kurzbz, nation, gemeinde, ort, geschlecht? if (!$this->form_validation->run()) $this->terminateWithValidationErrors($this->form_validation->error_array()); - - // TODO(chris): This should be in a library - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); - - $this->db->trans_start(); - - $result = $this->addInteressent(); - - $this->db->trans_complete(); - - if ($this->db->trans_status() === FALSE) - $this->terminateWithError('TODO(chris): TEXT', self::ERROR_TYPE_GENERAL); - - $data = $this->getDataOrTerminateWithError($result); - - $this->terminateWithSuccess($data); - } - - protected function addInteressent() - { - // Person anlegen wenn nötig - $person_id = $this->input->post('person_id'); - if (!$person_id) { - $this->load->model('person/Person_model', 'PersonModel'); - - $data = [ - 'nachname' => $this->input->post('nachname'), - 'insertamum' => date('c'), - 'insertvon' => getAuthUID(), - 'zugangscode' => uniqid(), - 'aktiv' => true - ]; - if ($this->input->post('anrede')) - $data['anrede'] = $this->input->post('anrede'); - if ($this->input->post('titelpre')) - $data['titelpre'] = $this->input->post('titelpre'); - if ($this->input->post('titelpost')) - $data['titelpost'] = $this->input->post('titelpost'); - if ($this->input->post('vorname')) - $data['vorname'] = $this->input->post('vorname'); - if ($this->input->post('vornamen')) - $data['vornamen'] = $this->input->post('vornamen'); - if ($this->input->post('wahlname')) - $data['wahlname'] = $this->input->post('wahlname'); - if ($this->input->post('geschlecht')) - $data['geschlecht'] = $this->input->post('geschlecht'); - if ($this->input->post('gebdatum')) - $data['gebdatum'] = (new DateTime($this->input->post('datum_obj')))->format('Y-m-d'); - if ($this->input->post('geburtsnation')) - $data['geburtsnation'] = $this->input->post('geburtsnation'); - if ($this->input->post('staatsbuergerschaft')) - $data['staatsbuergerschaft'] = $this->input->post('staatsbuergerschaft'); - - $result = $this->PersonModel->insert($data); - $person_id = $this->getDataOrTerminateWithError($result); - } - - // Addresse anlegen - $anlegen = $this->input->post('address[func]'); - if ($anlegen) { - $this->load->model('person/Adresse_model', 'AdresseModel'); - - $data = [ - 'nation' => $this->input->post('address[nation]'), - 'strasse' => $this->input->post('address[address]'), - 'plz' => $this->input->post('address[plz]'), - 'ort' => $this->input->post('address[ort]'), - 'gemeinde' => $this->input->post('address[gemeinde]'), - 'typ' => 'h', - 'zustelladresse' => true, - ]; - if ($anlegen < 0) { // Überschreiben - $this->AdresseModel->addSelect('adresse_id'); - $this->AdresseModel->addJoin('public.tbl_adressentyp', 'typ = adressentyp_kurzbz'); - $this->AdresseModel->addOrder('zustelladresse', 'DESC'); - $this->AdresseModel->addOrder('sort'); - $result = $this->AdresseModel->loadWhere([ - 'person_id' => $person_id - ]); - $address = $this->getDataOrTerminateWithError($result); - if ($address) { - $address = current($address); - - $data['updateamum'] = date('c'); - $data['updatevon'] = getAuthUID(); - - $result = $this->AdresseModel->update($address->adresse_id, $data); - $this->getDataOrTerminateWithError($result); - } else { - //Wenn keine Adrese vorhanden ist dann eine neue Anlegen - $anlegen = 1; - $data['heimatadresse'] = true; - } - } - if ($anlegen > 0) { - $data['person_id'] = $person_id; - $data['insertamum'] = date('c'); - $data['insertvon'] = getAuthUID(); - if (!isset($data['heimatadresse'])) - $data['heimatadresse'] = !$this->input->post('person_id'); - - $result = $this->AdresseModel->insert($data); - $this->getDataOrTerminateWithError($result); - } - } - - // Kontaktdaten - $kontaktdaten = []; - foreach (['email', 'telefon', 'mobil'] as $k) { - $v = $this->input->post($k); - if ($v) - $kontaktdaten[$k] = $v; - } - if (count($kontaktdaten)) { - $this->load->model('person/Kontakt_model', 'KontaktModel'); - - foreach ($kontaktdaten as $typ => $kontakt) { - $data = [ - 'person_id' => $person_id, - 'kontakttyp' => $typ, - 'kontakt' => $kontakt, - 'zustellung' => true, - 'insertamum' => date('c'), - 'insertvon' => getAuthUID() - ]; - $result = $this->KontaktModel->insert($data); - $this->getDataOrTerminateWithError($result); - } - } - - $personOnly = $anlegen = $this->input->post('personOnly'); - - if (!$personOnly) - { - // Prestudent anlegen - $data = [ - 'aufmerksamdurch_kurzbz' => 'k.A.', - 'person_id' => $person_id, - 'studiengang_kz' => $this->input->post('studiengang_kz'), - 'ausbildungcode' => $this->input->post('letzteausbildung'), - 'anmerkung' => $this->input->post('anmerkungen'), - 'reihungstestangetreten' => false, - 'bismelden' => true - ]; - $ausbildungsart = $this->input->post('ausbildungsart'); - if ($ausbildungsart) - $data['anmerkung'] .= ' Ausbildungsart:' . $ausbildungsart; - // Incomings und ausserordentliche sind bei Meldung nicht förderrelevant - $incoming = $this->input->post('incoming'); - if ($incoming || substr($data['studiengang_kz'], 0, 1) == '9') - $data['foerderrelevant'] = false; - // Wenn die Person schon im System erfasst ist, dann die ZGV des Datensatzes uebernehmen - $this->PrestudentModel->addOrder('zgvmas_code'); - $this->PrestudentModel->addOrder('zgv_code', 'DESC'); - $this->PrestudentModel->addLimit(1); - $result = $this->PrestudentModel->loadWhere([ - 'person_id' => $person_id - ]); - $prestudent = $this->getDataOrTerminateWithError($result); - if ($prestudent) { - $prestudent = current($prestudent); - if ($prestudent->zgv_code) { - $data['zgv_code'] = $prestudent->zgv_code; - $data['zgvort'] = $prestudent->zgvort; - $data['zgvdatum'] = $prestudent->zgvdatum; - - $data['zgvmas_code'] = $prestudent->zgvmas_code; - $data['zgvmaort'] = $prestudent->zgvmaort; - $data['zgvmadatum'] = $prestudent->zgvmadatum; - } - } - // Prestudent speichern - $result = $this->PrestudentModel->insert($data); - $prestudent_id = $this->getDataOrTerminateWithError($result); - - // Prestudent Rolle Anlegen - $data = [ - 'prestudent_id' => $prestudent_id, - 'status_kurzbz' => $incoming ? 'Incoming' : 'Interessent', - 'studiensemester_kurzbz' => $this->input->post('studiensemester_kurzbz'), - 'ausbildungssemester' => $this->input->post('ausbildungssemester') ?: 0, - 'orgform_kurzbz' => $this->input->post('orgform_kurzbz') ?: null, - 'studienplan_id' => $this->input->post('studienplan_id') ?: null, - 'datum' => date('Y-m-d'), - 'insertamum' => date('c'), - 'insertvon' => getAuthUID() - ]; - $result = $this->PrestudentstatusModel->insert($data); - $this->getDataOrTerminateWithError($result); - - if ($incoming) { - // TODO(chris): IMPLEMENT! - //Matrikelnummer und UID generieren - //Benutzerdatensatz anlegen - //Studentendatensatz anlegen - //StudentLehrverband anlegen - } - } - // TODO(chris): DEBUG - /*$result = $this->PrestudentModel->loadWhere([ - 'pestudent_id' => 1 - ]); - if (isError($result)) { - return $result; - }*/ - - return success($person_id); - } - - public function requiredIfNotPersonId($value) - { - if (isset($_POST['person_id'])) - return true; - return !!$value; - } - - public function requiredIfAddressFunc($value) - { - if (!$_POST['address']['func'] || $_POST['address']['func'] == 0) - return true; - return !!$value; - } - - public function requiredIfStudentFunc($value) - { - if ($_POST['personOnly']) - return true; - return !!$value; - } - - public function isValidDate($value) - { - return isValidDate($value); } } diff --git a/application/libraries/PrestudentLib.php b/application/libraries/PrestudentLib.php index 2d795369f..fe1fa3a00 100644 --- a/application/libraries/PrestudentLib.php +++ b/application/libraries/PrestudentLib.php @@ -35,6 +35,87 @@ class PrestudentLib $this->_ci->load->model('organisation/Studiengang_model', 'StudiengangModel'); } + /** + * Sets initial prestudent entry, no status yet. + * @return object success or error + */ + public function setPrestudent( + $person_id, + $studiengang_kz, + $ausbildungscode, + $anmerkung, + $foerderrelevant + ) + { + // Prestudent anlegen + $data = [ + 'aufmerksamdurch_kurzbz' => 'k.A.', + 'person_id' => $person_id, + 'studiengang_kz' => $studiengang_kz, + 'ausbildungcode' => $ausbildungscode, + 'anmerkung' => $anmerkung, + 'reihungstestangetreten' => false, + 'bismelden' => true, + 'foerderrelevant' => $foerderrelevant + ]; + + // Wenn die Person schon im System erfasst ist, dann die ZGV des Datensatzes uebernehmen + $this->_ci->PrestudentModel->addSelect('public.tbl_prestudent.*, public.tbl_person.vorname, public.tbl_person.nachname'); + $this->_ci->PrestudentModel->addJoin('public.tbl_person', 'person_id'); + $this->_ci->PrestudentModel->addOrder('zgvmas_code'); + $this->_ci->PrestudentModel->addOrder('zgv_code', 'DESC'); + $this->_ci->PrestudentModel->addLimit(1); + $result = $this->_ci->PrestudentModel->loadWhere([ + 'person_id' => $person_id + ]); + + if (isError($result)) return $result; + + if (hasData($result)) { + $prestudent = getData($result)[0]; + if ($prestudent->zgv_code) { + $data['zgv_code'] = $prestudent->zgv_code; + $data['zgvort'] = $prestudent->zgvort; + $data['zgvdatum'] = $prestudent->zgvdatum; + + $data['zgvmas_code'] = $prestudent->zgvmas_code; + $data['zgvmaort'] = $prestudent->zgvmaort; + $data['zgvmadatum'] = $prestudent->zgvmadatum; + } + } + // Prestudent speichern + return $this->_ci->PrestudentModel->insert($data); + } + + /** + * Sets first status of a prestudent.! + * @return object success or error + */ + public function setFirstStatus( + $prestudent_id, + $status_kurzbz, + $studiensemester_kurzbz, + $ausbildungssemester = null, + $orgform_kurzbz = null, + $studienplan_id = null + ) + { + // Prestudent Rolle Anlegen + $data = [ + 'prestudent_id' => $prestudent_id, + 'status_kurzbz' => $status_kurzbz, + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'ausbildungssemester' => $ausbildungssemester ?: 0, + 'orgform_kurzbz' => $orgform_kurzbz ?: null, + 'studienplan_id' => $studienplan_id ?: null, + 'datum' => date('Y-m-d'), + 'insertamum' => date('c'), + 'insertvon' => getAuthUID() + ]; + + return $this->_ci->PrestudentstatusModel->insert($data); + } + public function setAbbrecher( $prestudent_id, $studiensemester_kurzbz, @@ -889,6 +970,141 @@ class PrestudentLib ); } + /** + * Creates an incoming, saves necessary data for an incoming. + * @param $prestudent_id existing prestudent, for which incoming entry is created + * @param $studiengang_kz Studiengang assigned to incoming + * @param $studiensemester_kurzbz start semester for incoming + * @return object success if incoming successfully saved, or error + */ + public function setIncoming($prestudent_id, $studiengang_kz, $studiensemester_kurzbz) + { + // Verband and Ausbildungssemester for incoming + $authUID = getAuthUID(); + $incomingVerband = 'I'; + $incomingAusbildungssemester = '0'; + + // get prestudent + $this->_ci->PrestudentModel->addJoin('public.tbl_person p', 'person_id'); + $this->_ci->PrestudentModel->addJoin('public.tbl_studiengang stg', 'studiengang_kz'); + $result = $this->_ci->PrestudentModel->load($prestudent_id); + + if (isError($result)) return $result; + if (!hasData($result)) return error('No prestudent'); + + $student_data = getData($result)[0]; + + // generate Personenkennzeichen + $result = $this->_ci->StudentModel->generateMatrikelnummer2($studiengang_kz, $studiensemester_kurzbz); + if (isError($result)) return $result; + if (!hasData($result)) return error('No personenkennzeichen could be generated'); + + $personenkennzeichen = getData($result); + + $jahr = mb_substr($personenkennzeichen, 0, 2); + $stg = mb_substr($personenkennzeichen, 3, 4); + + $nachname_clean = mb_strtolower(sanitizeProblemChars($student_data->nachname)); + $vorname_clean = mb_strtolower(sanitizeProblemChars($student_data->vorname)); + $nachname_clean = str_replace(' ','_', $nachname_clean); + $vorname_clean = str_replace(' ','_', $vorname_clean); + + // get Studiengang data + $result = $this->_ci->StudiengangModel->load(ltrim($stg, '0')); + if (isError($result)) return $result; + if (!hasData($result)) return error('No Studiengang'); + + $stgObj = getData($result)[0]; + + // gernerate uid + $result = $this->_ci->StudentModel->generateUID($stgObj->kurzbz, $jahr, $stgObj->typ, $personenkennzeichen, $vorname_clean, $nachname_clean); + if (isError($result)) return $result; + if (!hasData($result)) return error("UID could not be generated"); + $uid = getData($result); + + //Benutzerdatensatz anlegen + $benutzer = [ + 'uid' => $uid, + 'person_id' => $student_data->person_id, + 'aktiv' => true, + 'aktivierungscode' => $this->_ci->BenutzerModel->generateActivationkey() + ]; + + // Generate Alias + $alias = ''; + if (!defined('GENERATE_ALIAS_STUDENT') || GENERATE_ALIAS_STUDENT === true) + { + $result = $this->_ci->BenutzerModel->generateAliasFromName($student_data->vorname, $student_data->nachname); + if (isError($result)) + return $result; + $alias = getData($result); + } + + $benutzer['alias'] = $alias; + $benutzer['insertamum'] = date('Y-m-d H:i:s'); + $benutzer['insertvon'] = $authUID; + + $this->_ci->addMeta('benutzer', $benutzer); + + $result = $this->_ci->BenutzerModel->insert($benutzer); + + if (isError($result)) return $result; + + // Studentendatensatz anlegen + $student = [ + 'student_uid' => $uid, + 'matrikelnr' => $personenkennzeichen, + 'prestudent_id' => $prestudent_id, + 'studiengang_kz' => $studiengang_kz, + 'semester' => $incomingAusbildungssemester, + 'verband' => $incomingVerband, + 'gruppe' => ' ' + ]; + + // Add Lehrverband if it does not exist + $result = $this->_ci->LehrverbandModel->load([' ', ' ', $incomingAusbildungssemester, $student_data->studiengang_kz]); + + if (isError($result)) return $result; + + if (!hasData($result)) + { + $result = $this->_ci->LehrverbandModel->insert([ + 'studiengang_kz' => $student_data->studiengang_kz, + 'semester' => $incomingAusbildungssemester, + 'verband' => $incomingVerband, + 'gruppe' => $student_data->gruppe, + 'bezeichnung' => 'Incoming', + 'aktiv' => true + ]); + + if (isError($result)) return $result; + } + + // add student + $student['insertamum'] = date('Y-m-d H:i:s'); + $student['insertvon'] = $authUID; + + $result = $this->_ci->StudentModel->insert($student); + if (isError($result)) return $result; + + // Add Studentlehrverband + $result = $this->_ci->StudentlehrverbandModel->insert([ + 'student_uid' => $uid, + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'studiengang_kz' => $student_data->studiengang_kz, + 'semester' => $incomingAusbildungssemester, + 'verband' => $incomingVerband, + 'gruppe' => ' ', + 'insertamum' => date('Y-m-d H:i:s'), + 'insertvon' => $authUID + ]); + + if (isError($result)) + return $result; + + return success($prestudent_id); + } + protected function setBasic($authUID, $now, $status_kurzbz, $prestudent_id, $studiensemester_kurzbz, $ausbildungssemester, $statusgrund_id = null) { $result = $this->_ci->PrestudentstatusModel->getLastStatus($prestudent_id); diff --git a/application/models/crm/Student_model.php b/application/models/crm/Student_model.php index 539c3cf56..6f2404cbd 100644 --- a/application/models/crm/Student_model.php +++ b/application/models/crm/Student_model.php @@ -27,7 +27,7 @@ class Student_model extends DB_Model $this->addSelect('1'); $result = $this->loadWhere(array('student_uid' => $uid)); - + if(hasData($result)) { @@ -169,7 +169,7 @@ class Student_model extends DB_Model $max = 0; if ($matrikelnrres && hasData($matrikelnrres)) { - $max = mb_substr($matrikelnrres->retval[0]->matrikelnr, 7); + $max = mb_substr(getData($matrikelnrres)[0]->matrikelnr, 7); if (!is_numeric($max)) { $max = (int)$max; } diff --git a/public/js/api/factory/stv/students.js b/public/js/api/factory/stv/students.js index 07d4453d8..acb4d5f49 100644 --- a/public/js/api/factory/stv/students.js +++ b/public/js/api/factory/stv/students.js @@ -52,10 +52,10 @@ export default { url: 'api/frontend/v1/stv/students/' + relative_path }; }, - check(params) { + getPerson(params) { return { method: 'post', - url: 'api/frontend/v1/stv/student/check', + url: 'api/frontend/v1/stv/student/getPerson', params }; }, diff --git a/public/js/components/Stv/Studentenverwaltung/List.js b/public/js/components/Stv/Studentenverwaltung/List.js index 67cada523..39a46b630 100644 --- a/public/js/components/Stv/Studentenverwaltung/List.js +++ b/public/js/components/Stv/Studentenverwaltung/List.js @@ -322,9 +322,7 @@ export default { table-only :side-menu="false" reload - ` + /* TODO(chris): Ausgeblendet für Testing new-btn-show - */` :new-btn-label="$p.t('stv/action_new')" @click:new="actionNewPrestudent" > diff --git a/public/js/components/Stv/Studentenverwaltung/List/New.js b/public/js/components/Stv/Studentenverwaltung/List/New.js index 75896d408..211bb9dd3 100644 --- a/public/js/components/Stv/Studentenverwaltung/List/New.js +++ b/public/js/components/Stv/Studentenverwaltung/List/New.js @@ -6,6 +6,7 @@ import FormInput from '../../../Form/Input.js'; import accessibility from '../../../../directives/accessibility.js'; import ApiStvStudents from '../../../../api/factory/stv/students.js'; +import ApiStvAddress from '../../../../api/factory/stv/kontakt/address.js'; var _uuid = 0; const FORMDATA_DEFAULT = { @@ -35,7 +36,7 @@ export default { ], emits: ['saved'], props: { - personOnly: Boolean, + personOnly: Boolean, studiengangKz: Number, studiensemesterKurzbz: String }, @@ -112,7 +113,7 @@ export default { this.abortController.suggestions = new AbortController(); this.$api - .call(ApiStvStudents.check({ + .call(ApiStvStudents.getPerson({ vorname: this.formData.vorname, nachname: this.formData.nachname, gebdatum: this.formData.gebdatum @@ -138,23 +139,22 @@ export default { return; this.abortController.places = new AbortController(); - this.$refs.form - .get( - 'api/frontend/v1/stv/address/getPlaces/' + this.formData.address.plz, - undefined, - { - signal: this.abortController.places.signal - } - ) - .then(result => { - this.places = result.data - }) - .catch(error => { - if (error.code != "ERR_CANCELED") - window.setTimeout(this.loadPlaces, 100); - else - this.$fhcAlert.handleSystemError(error); - }); + this.$refs.form.call( + ApiStvAddress.getPlaces(this.formData.address.plz) + //~ undefined, + //~ { + //~ signal: this.abortController.places.signal + //~ } + ) + .then(result => { + this.places = result.data + }) + .catch(error => { + if (error.code != "ERR_CANCELED") + window.setTimeout(this.loadPlaces, 100); + else + this.$fhcAlert.handleSystemError(error); + }); }, loadStudienplaene() { if (this.formDataStg) @@ -228,14 +228,12 @@ export default { }, template: ` - + + + {{defaultRecipients}} | {{defaultRecipient}} || {{uid}}
@@ -381,7 +395,7 @@ export default { type="text" name="recipient" :label="$p.t('messages/recipient')" - v-model="defaultRecipient" + v-model="defaultRecipientString" disabled > @@ -502,17 +516,17 @@ export default { >

- +
diff --git a/public/js/components/Messages/Details/TableMessages.js b/public/js/components/Messages/Details/TableMessages.js index 2a12128eb..172607022 100644 --- a/public/js/components/Messages/Details/TableMessages.js +++ b/public/js/components/Messages/Details/TableMessages.js @@ -19,7 +19,7 @@ export default { }, typeId: String, id: { - type: [Number, String], + type: Array, required: true }, messageLayout: String, @@ -346,7 +346,7 @@ export default { });*/ }, created(){ - if(this.typeId != 'person_id') { + if(this.typeId != 'person_id' && Array.isArray(this.id) && this.id.length === 1) { const params = { id: this.id, type_id: this.typeId diff --git a/public/js/components/Messages/Messages.js b/public/js/components/Messages/Messages.js index 176c05b6b..53692d6a3 100644 --- a/public/js/components/Messages/Messages.js +++ b/public/js/components/Messages/Messages.js @@ -31,7 +31,7 @@ export default { } }, id: { - type: [Number, String], + type: Array, required: true }, showTable: Boolean, @@ -124,6 +124,7 @@ export default { }, template: `
+ {{typeId}} {{id}}
- - -
+ +
e.prestudent_id); + }, + person_ids() { + if (this.modelValue.person_id) + { + return [this.modelValue.person_id]; + } + return this.modelValue.map(e => e.person_id); + }, + }, template: `
- - - - + +
` }; \ No newline at end of file From 17519eac83f66f0a5303fdbd05f6ca6c58333de7 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Mon, 1 Dec 2025 13:27:42 +0100 Subject: [PATCH 10/30] refactor Messaging - headerFilter for table Messages - multiactions for sendMessages for openmodes modal and inSamePage --- .../api/frontend/v1/messages/Messages.php | 112 +++++--------- public/js/api/factory/messages/messages.js | 40 ++--- .../Messages/Details/NewMessage/Modal.js | 56 +------ .../Messages/Details/NewMessage/NewDiv.js | 140 +++++++----------- .../Messages/Details/TableMessages.js | 43 ++++-- public/js/components/Messages/Messages.js | 2 +- .../Studentenverwaltung/Details/Messages.js | 5 +- 7 files changed, 141 insertions(+), 257 deletions(-) diff --git a/application/controllers/api/frontend/v1/messages/Messages.php b/application/controllers/api/frontend/v1/messages/Messages.php index f3a40f72f..b3cb31bb6 100644 --- a/application/controllers/api/frontend/v1/messages/Messages.php +++ b/application/controllers/api/frontend/v1/messages/Messages.php @@ -16,7 +16,6 @@ class Messages extends FHCAPI_Controller 'getNameOfDefaultRecipient' => ['admin:r', 'assistenz:r'], 'getNameOfDefaultRecipients' => ['admin:r', 'assistenz:r'], 'sendMessage' => ['admin:r', 'assistenz:r'], - 'sendMessages' => ['admin:r', 'assistenz:r'], 'deleteMessage' => ['admin:r', 'assistenz:r'], 'getDataVorlage' => ['admin:r', 'assistenz:r'], 'getPreviewText' => ['admin:r', 'assistenz:r'], @@ -104,24 +103,22 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($vorlage); } - public function getMessageVarsPerson($id, $typeId) + public function getMessageVarsPerson($typeId) { - $person_id = ($typeId == 'mitarbeiter_uid') ? $this->_getPersonId($id, $typeId) : $id; - $result = $this->MessageModel->getMsgVarsDataByPersonId($person_id); - $data = $this->getDataOrTerminateWithError($result); + $ids = $this->input->post('ids'); + $messageVarsPerson = []; - $this->terminateWithSuccess($data); + foreach ($ids as $id) + { + $person_id = ($typeId == 'mitarbeiter_uid') ? $this->_getPersonId($id, $typeId) : $id; + $result = $this->MessageModel->getMsgVarsDataByPersonId($person_id); + $data = $this->getDataOrTerminateWithError($result); + $messageVarsPerson[] = current($data); + } + + $this->terminateWithSuccess($messageVarsPerson); } -/* public function getMsgVarsPrestudent($id, $typeId) - { - $prestudent_id = ($typeId == 'uid') ? $this->_getPrestudentIdFromUid($id) : $id; - $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); - $data = $this->getDataOrTerminateWithError($result); - - $this->terminateWithSuccess($data); - }*/ - public function getMsgVarsPrestudent($typeId) { $ids = $this->input->post('ids'); @@ -201,55 +198,9 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($recipients); } - public function sendMessages() + public function sendMessage($typeId) { -/* if (isset($_POST['data'])) - { - $data = json_decode($_POST['data']); - unset($_POST['data']); - } - else - $this->terminateWithError("Data missing ", self::ERROR_TYPE_GENERAL); - - if (isset($_POST['ids'])) - { - $ids = json_decode($_POST['ids']); - unset($_POST['ids']); - } - else - $this->terminateWithError("IDs missing ", self::ERROR_TYPE_GENERAL); - - - if (isset($_POST['uids'])) - { - $uids = json_decode($_POST['uids']); - unset($_POST['uids']); - } - else - $this->terminateWithError("UIDs missing ", self::ERROR_TYPE_GENERAL); -*/ - - if (isset($_POST['data'])) - { - $data = json_decode($_POST['data']); - unset($_POST['data']); - foreach ($data as $k => $v) { - $_POST[$k] = $v; - } - } - - $this->terminateWithSuccess($data); - - } - - public function sendMessage($recipient_id, $return=false) - { - //has to be uid TODO(Manu) check - // $this->terminateWithError("uid", $recipient_id, self::ERROR_TYPE_GENERAL); - - //default setting - $receiversPersonId = $this->_getPersonId($recipient_id, 'uid'); - + $resultReturn = []; $uid = getAuthUID(); $this->load->model('person/Benutzer_model', 'BenutzerModel'); $result = $this->BenutzerModel->loadWhere( @@ -287,49 +238,54 @@ class Messages extends FHCAPI_Controller $body = $this->input->post('body'); $relationmessage_id = $this->input->post('relationmessage_id'); - $typeId = $this->input->post('type_id'); - $ids = $this->input->post('id'); + if (isset($_POST['ids'])) + { + $ids = json_decode($_POST['ids']); + unset($_POST['ids']); + foreach ($data as $k => $v) { + $_POST[$k] = $v; + } + } foreach ($ids as $id) { + $receiversPersonId = $typeId == "person_id" ? $id : $this->_getPersonId($id, $typeId); + if($typeId == 'uid') { $prestudent_id = $this-> _getPrestudentIdFromUid($id); - //parseMessagetext for variables Prestudent $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $body); - $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + $bodyParsed = $this->getDataOrTerminateWithError($result); } if($typeId == 'mitarbeiter_uid') { $person_id = $this->_getPersonId($id, $typeId); $result = $this->MessagesModel->parseMessageTextPerson($person_id, $body); - $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); - $this->terminateWithError($bodyParsed[$id], self::ERROR_TYPE_GENERAL); - + $bodyParsed = $this->getDataOrTerminateWithError($result); } elseif($typeId == 'person_id') { $result = $this->MessagesModel->parseMessageTextPerson($id, $body); - $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + $bodyParsed = $this->getDataOrTerminateWithError($result); } elseif($typeId == 'prestudent_id') { $result = $this->MessagesModel->parseMessageTextPrestudent($id, $body); - $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + $bodyParsed = $this->getDataOrTerminateWithError($result); } else { $this->terminateWithError("type_id " . $typeId . " not valid", self::ERROR_TYPE_GENERAL); } + + $result =$this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id, null, $relationmessage_id); + $data = $this->getDataOrTerminateWithError($result); + $resultReturn[] = current($data); + } - - - - $result = $this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id, null, $relationmessage_id); - - $this->terminateWithSuccess($result); + $this->terminateWithSuccess($resultReturn); } public function getPreviewText($type_id) diff --git a/public/js/api/factory/messages/messages.js b/public/js/api/factory/messages/messages.js index 1c2bbe66e..c3542308a 100644 --- a/public/js/api/factory/messages/messages.js +++ b/public/js/api/factory/messages/messages.js @@ -38,19 +38,13 @@ export default { url: 'api/frontend/v1/messages/messages/getMsgVarsLoggedInUser/' }; }, - getMessageVarsPerson(userParams){ + getMessageVarsPerson(ids, type_id){ return { method: 'post', - url: 'api/frontend/v1/messages/messages/getMessageVarsPerson/' + userParams.id + '/' + userParams.type_id + url: 'api/frontend/v1/messages/messages/getMessageVarsPerson/' + type_id, + params: {ids} }; }, - //TODO(Manu) enable for id_array -/* getMsgVarsPrestudent(userParams){ - return { - method: 'post', - url: 'api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + userParams.id + '/' + userParams.type_id - }; - }, */ getMsgVarsPrestudent(ids, type_id){ return { method: 'post', @@ -58,41 +52,25 @@ export default { params: {ids} }; }, - //TODO(Manu) enable for id_array getPersonId(params){ return { method: 'post', url: 'api/frontend/v1/messages/messages/getPersonId/' + params.id + '/' + params.type_id }; }, - //TODO(Manu) enable for id_array -/* getUid(userParams){ - return { - method: 'get', - url: 'api/frontend/v1/messages/messages/getUid/' + userParams.id + '/' + userParams.type_id - }; - }, */ - getUid(ids, type_id){ +/* getUid(ids, type_id){ return { method: 'post', url: 'api/frontend/v1/messages/messages/getUids/' + type_id, params: {ids} }; - }, + },*/ getDataVorlage(vorlage_kurzbz){ return { method: 'get', url: 'api/frontend/v1/messages/messages/getDataVorlage/' + vorlage_kurzbz }; }, -/* getNameOfDefaultRecipient(params){ - console.log(params.id); - return { - method: 'get', - url: 'api/frontend/v1/messages/messages/getNameOfDefaultRecipient/' + params.id + '/' + params.type_id - }; - },*/ - //TODO(Manu) enable for id_array getNameOfDefaultRecipients(ids, type_id){ return { method: 'post', @@ -120,17 +98,17 @@ export default { params }; }, */ - sendMessageFromModalContext(params) { + sendMessageFromModalContext(type_id, params) { return { method: 'post', - url: 'api/frontend/v1/messages/messages/sendMessages/', + url: 'api/frontend/v1/messages/messages/sendMessage/' + type_id, params }; }, - sendMessage(id, params) { + sendMessage(type_id, params) { return { method: 'post', - url: 'api/frontend/v1/messages/messages/sendMessage/' + id, + url: 'api/frontend/v1/messages/messages/sendMessage/' + type_id, params }; }, diff --git a/public/js/components/Messages/Details/NewMessage/Modal.js b/public/js/components/Messages/Details/NewMessage/Modal.js index 87b8d7c87..d173bc7d0 100644 --- a/public/js/components/Messages/Details/NewMessage/Modal.js +++ b/public/js/components/Messages/Details/NewMessage/Modal.js @@ -58,8 +58,7 @@ export default { previewText: null, previewBody: "", replyData: null, - uid: null, - uids: null //necessary? + } }, methods: { @@ -116,31 +115,20 @@ export default { const data = new FormData(); data.append('data', JSON.stringify(this.formData)); data.append('ids', JSON.stringify(this.id)); - data.append('uids', JSON.stringify(this.uid)); - const params = { - id: this.id, - type_id: this.typeId - }; - const merged = { - ...this.formData, - ...params - }; - data.append('data', JSON.stringify(merged)); - - //Modal Context? return this.$refs.formMessage - .call(this.endpoint.sendMessageFromModalContext(data)) + .call(this.endpoint.sendMessageFromModalContext(this.typeId, data)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); this.hideModal('modalNewMessage'); this.resetForm(); }).catch(this.$fhcAlert.handleSystemError) .finally(() => { - //this.resetForm(); - //closeModal - //closewindwo + + //just emit if no multitasking + if(this.id.length == 1){ this.$emit('reloadTable'); + } } ); }, @@ -210,15 +198,6 @@ export default { this.previewBody = this.previewText; }); }, - //TODO(Manu) check if No_UID - getUid(id, typeId){ - this.$api - .call(this.endpoint.getUid(this.id, this.typeId)) - .then(result => { - this.uid = result.data; - }) - .catch(this.$fhcAlert.handleSystemError); - }, show(){ this.$refs.modalNewMessage.show(); }, @@ -266,15 +245,9 @@ export default { } }, created(){ - this.getUid(this.id, this.typeId); - if(this.typeId == 'person_id' || this.typeId == 'mitarbeiter_uid'){ - const params = { - id: this.id, - type_id: this.typeId - }; this.$api - .call(this.endpoint.getMessageVarsPerson(params)) + .call(this.endpoint.getMessageVarsPerson(this.id, this.typeId)) .then(result => { this.fieldsPerson = result.data; const person = this.fieldsPerson[0]; @@ -312,19 +285,6 @@ export default { }) .catch(this.$fhcAlert.handleSystemError); -/* this.$api - .call(this.endpoint.getNameOfDefaultRecipient({ - id: this.id, - type_id: this.typeId})) - .then(result => { - this.defaultRecipient = result.data; - this.recipientsArray.push({ - 'uid': this.uid, - 'details': this.defaultRecipient}); - }) - .catch(this.$fhcAlert.handleSystemError);*/ - - //for multiaction too this.$api .call(this.endpoint.getNameOfDefaultRecipients(this.id, this.typeId)) .then(result => { @@ -379,8 +339,6 @@ export default { - - {{defaultRecipients}} | {{defaultRecipient}} || {{uid}}
diff --git a/public/js/components/Messages/Details/NewMessage/NewDiv.js b/public/js/components/Messages/Details/NewMessage/NewDiv.js index 24674fd3f..07fdf569d 100644 --- a/public/js/components/Messages/Details/NewMessage/NewDiv.js +++ b/public/js/components/Messages/Details/NewMessage/NewDiv.js @@ -2,6 +2,7 @@ import FormForm from '../../../Form/Form.js'; import FormInput from '../../../Form/Input.js'; import ListBox from "../../../../../../index.ci.php/public/js/components/primevue/listbox/listbox.esm.min.js"; import DropdownComponent from '../../../VorlagenDropdown/VorlagenDropdown.js'; +import ApiMessages from "../../../../api/factory/messages/messages.js"; //props not working with route export default { name: "ComponentNewMessages", @@ -19,7 +20,7 @@ export default { openMode: String, tempTypeId: String, tempId: { - type: [Number, String], + type: Array, required: false }, tempMessageId: { @@ -37,7 +38,7 @@ export default { }, messageId(){ return this.$props.tempMessageId ||this.$route.params.messageId; - } + }, }, data(){ return { @@ -53,6 +54,8 @@ export default { vorlagen: [], recipientsArray: [], defaultRecipient: null, + defaultRecipients: [], + defaultRecipientString: null, editor: null, isVisible: false, fieldsUser: [], @@ -67,8 +70,7 @@ export default { previewText: null, previewBody: "", replyData: null, - uid: null, - messageSent: false + messageSent: false, } }, methods: { @@ -106,19 +108,11 @@ export default { }, sendMessage() { const data = new FormData(); + data.append('data', JSON.stringify(this.formData)); + data.append('ids', JSON.stringify(this.id)); - const params = { - id: this.id, - type_id: this.typeId - }; - - const merged = { - ...this.formData, - ...params - }; - data.append('data', JSON.stringify(merged)); return this.$api - .call(this.endpoint.sendMessage(this.uid, data)) + .call(ApiMessages.sendMessage(this.typeId, data)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); this.hideTemplate(); @@ -126,37 +120,34 @@ export default { this.messageSent = true; }).catch(this.$fhcAlert.handleSystemError) .finally(() => { - //TODO(Manu) hier route definieren für openmode in Tab, Page? - // ist kein child sondern mit route aufgerufen - //würde allerdings neues fenster aktualisiert öffnen, altes bleibt ohne reload gleich - //Reload vorheriges tab??? - if(this.openMode == "inSamePage"){ + if(this.openMode == "inSamePage" && this.id.length == 1 ){ this.$emit('reloadTable'); } + this.resetForm(); } ); }, getDataVorlage(vorlage_kurzbz){ return this.$api - .call(this.endpoint.getDataVorlage(vorlage_kurzbz)) + .call(ApiMessages.getDataVorlage(vorlage_kurzbz)) .then(response => { this.formData.body = response.data.text; this.formData.subject = response.data.subject; }).catch(this.$fhcAlert.handleSystemError); }, - getPreviewText(id, typeId){ + getPreviewText(){ const data = new FormData(); - data.append('data', JSON.stringify(this.formData.body)); + data.append('ids', JSON.stringify(this.id)); + return this.$api - .call(this.endpoint.getPreviewText({ - id: this.id, - type_id: this.typeId}, data)) + .call(ApiMessages.getPreviewText( + this.typeId, data)) .then(response => { - this.previewText = response.data; + const previews = response.data; + this.previewText = previews[this.defaultRecipient]; }).catch(this.$fhcAlert.handleSystemError) .finally(() => { - //this.resetForm(); }); }, insertVariable(selectedItem){ @@ -177,11 +168,13 @@ export default { vorlage_kurzbz: null, body: null, subject: null, + recipient: null, + selectedValue: null }; if (this.editor) { this.editor.setContent(""); } - this.$refs.dropdownComp.setValue(null); + // this.$refs.dropdownComp.setValue(null); this.previewBody = null; @@ -202,23 +195,11 @@ export default { if (this.openMode == "inSamePage") this.isVisible = true; }, - showPreview(id, typeId){ - this.getPreviewText(id, typeId).then(() => { + showPreview(){ + this.getPreviewText().then(() => { this.previewBody = this.previewText; }); }, - getUid(id, typeId){ - const params = { - id: id, - type_id: typeId - }; - this.$api - .call(this.endpoint.getUid(params)) - .then(result => { - this.uid = result.data; - }) - .catch(this.$fhcAlert.handleSystemError); - } }, watch: { 'formData.body': { @@ -242,38 +223,26 @@ export default { }, }, created(){ - this.getUid(this.id, this.typeId); - - if (['person_id', 'mitarbeiter_uid'].includes(this.typeId)){ - const params = { - id: this.id, - type_id: this.typeId - }; - - this.$api - .call(this.endpoint.getMessageVarsPerson(params)) - .then(result => { - this.fieldsPerson = result.data; - const person = this.fieldsPerson[0]; - this.itemsPerson = Object.entries(person).map(([key, value]) => ({ - label: key.toLowerCase(), - value: '{' + key.toLowerCase() + '}' - })); - }) - .catch(this.$fhcAlert.handleSystemError); - } - - if (['prestudent_id', 'uid'].includes(this.typeId)){ - const params = { - id: this.id, - type_id: this.typeId - }; + if(this.typeId == 'person_id' || this.typeId == 'mitarbeiter_uid'){ this.$api - .call(this.endpoint.getMsgVarsPrestudent(params)) + .call(ApiMessages.getMessageVarsPerson(this.id, this.typeId)) + .then(result => { + this.fieldsPerson = result.data; + const person = this.fieldsPerson[0]; + this.itemsPerson = Object.entries(person).map(([key, value]) => ({ + label: key.toLowerCase(), + value: '{' + key.toLowerCase() + '}' + })); + }) + .catch(this.$fhcAlert.handleSystemError); + } + + if(this.typeId == 'prestudent_id' || this.typeId == 'uid'){ + this.$api + .call(ApiMessages.getMsgVarsPrestudent(this.id, this.typeId)) .then(result => { this.fieldsPrestudent = result.data; const prestudent = this.fieldsPrestudent[0]; - this.itemsPrestudent = Object.entries(prestudent).map(([key, value]) => ({ label: key.toLowerCase(), value: '{' + key.toLowerCase() + '}' @@ -283,7 +252,7 @@ export default { } this.$api - .call(this.endpoint.getMsgVarsLoggedInUser()) + .call(ApiMessages.getMsgVarsLoggedInUser()) .then(result => { this.fieldsUser = result.data; const user = this.fieldsUser; @@ -295,21 +264,18 @@ export default { .catch(this.$fhcAlert.handleSystemError); this.$api - .call(this.endpoint.getNameOfDefaultRecipient({ - id: this.id, - type_id: this.typeId})) + .call(ApiMessages.getNameOfDefaultRecipients(this.id, this.typeId)) .then(result => { - this.defaultRecipient = result.data; - this.recipientsArray.push({ - 'uid': this.uid, - 'details': this.defaultRecipient}); + this.defaultRecipients = result.data; + this.defaultRecipientString = Object.values(this.defaultRecipients).join("; "); + }) .catch(this.$fhcAlert.handleSystemError); //case of reply if(this.messageId != null) { this.$api - .call(this.endpoint.getReplyData(this.messageId)) + .call(ApiMessages.getReplyData(this.messageId)) .then(result => { this.replyData = result.data; this.formData.subject = this.replyData[0].replySubject; @@ -343,7 +309,7 @@ export default { type="text" name="recipient" :label="$p.t('messages/recipient')" - v-model="defaultRecipient" + v-model="defaultRecipientString" disabled > @@ -472,18 +438,18 @@ export default { v-model="defaultRecipient" > -

- +
diff --git a/public/js/components/Messages/Details/TableMessages.js b/public/js/components/Messages/Details/TableMessages.js index 172607022..dd1725507 100644 --- a/public/js/components/Messages/Details/TableMessages.js +++ b/public/js/components/Messages/Details/TableMessages.js @@ -38,12 +38,13 @@ export default { }, ajaxResponse: (url, params, response) => this.buildTreemap(response), columns: [ - {title: "subject", field: "subject"}, - {title: "body", field: "body", formatter: "html", visible: false}, - {title: "message_id", field: "message_id", visible: false}, + {title: "subject", field: "subject", headerFilter: true}, + {title: "body", field: "body", formatter: "html", visible: false, headerFilter: true}, + {title: "message_id", field: "message_id", visible: false, headerFilter: true}, { title: "Datum", field: "insertamum", + headerFilter: true, formatter: function (cell) { const dateStr = cell.getValue(); const date = new Date(dateStr); // Convert to Date object @@ -55,16 +56,28 @@ export default { minute: "2-digit", hour12: false }); + }, + headerFilterFunc(headerValue, rowValue) { + const matches = headerValue.match(/^(([0-9]{2})\.)?([0-9]{2})\.([0-9]{4})?$/); + let comparestr = headerValue; + if(matches !== null) { + const year = (matches[4] !== undefined) ? matches[4] : ''; + const month = matches[3]; + const day = (matches[2] !== undefined) ? matches[2] : ''; + comparestr = year + '-' + month + '-' + day; + } + return rowValue.match(comparestr); } }, - {title: "sender", field: "sender"}, - {title: "recipient", field: "recipient"}, - {title: "senderId", field: "sender_id"}, - {title: "recipientId", field: "recipient_id"}, - {title: "Relationmessage ID", field: "relationmessage_id"}, + {title: "sender", field: "sender", headerFilter: true}, + {title: "recipient", field: "recipient", headerFilter: true}, + {title: "senderId", field: "sender_id", headerFilter: true}, + {title: "recipientId", field: "recipient_id", headerFilter: true}, + {title: "Relationmessage ID", field: "relationmessage_id", headerFilter: true}, { title: "Status", field: "status", + headerFilter: true, formatterParams: [ "unread", "read", @@ -73,11 +86,12 @@ export default { ], formatter: (cell, formatterParams) => { return formatterParams[cell.getValue()]; - } + }, }, { title: "letzte Änderung", field: "statusdatum", + headerFilter: true, formatter: function (cell) { const dateStr = cell.getValue(); const date = new Date(dateStr); // Convert to Date object @@ -89,6 +103,17 @@ export default { minute: "2-digit", hour12: false }); + }, + headerFilterFunc(headerValue, rowValue) { + const matches = headerValue.match(/^(([0-9]{2})\.)?([0-9]{2})\.([0-9]{4})?$/); + let comparestr = headerValue; + if(matches !== null) { + const year = (matches[4] !== undefined) ? matches[4] : ''; + const month = matches[3]; + const day = (matches[2] !== undefined) ? matches[2] : ''; + comparestr = year + '-' + month + '-' + day; + } + return rowValue.match(comparestr); } }, { diff --git a/public/js/components/Messages/Messages.js b/public/js/components/Messages/Messages.js index 53692d6a3..0785877d8 100644 --- a/public/js/components/Messages/Messages.js +++ b/public/js/components/Messages/Messages.js @@ -98,6 +98,7 @@ export default { } const newTab = window.open(path, "_blank"); + }, openInNewWindow(id, typeId, messageId){ let path = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router; @@ -124,7 +125,6 @@ export default { }, template: `
- {{typeId}} {{id}} +