mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-16 22:42:16 +00:00
Backendvalidation insert and update, validation local tabulator array
This commit is contained in:
@@ -67,42 +67,73 @@ class Mobility extends FHCAPI_Controller
|
||||
|
||||
public function insertMobility()
|
||||
{
|
||||
//TODO(Manu) Validations
|
||||
//Pflicht gast und herkunftsland
|
||||
$this->load->library('form_validation');
|
||||
$authUID = getAuthUID();
|
||||
|
||||
$student_uid = $this->input->post('uid');
|
||||
|
||||
if(!$student_uid)
|
||||
{
|
||||
return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Student UID']), self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
|
||||
$formData = $this->input->post('formData');
|
||||
|
||||
$von = (isset($formData['von']) && !empty($formData['von'])) ? $formData['von'] : null;
|
||||
$nation_code = (isset($formData['nation_code']) && !empty($formData['nation_code'])) ? $formData['nation_code'] : 'A';
|
||||
$mobilitaetsprogramm_code = (isset($formData['mobilitaetsprogramm_code']) && !empty($formData['mobilitaetsprogramm_code'])) ? $formData['mobilitaetsprogramm_code'] : null;
|
||||
$herkunftsland_code = (isset($formData['herkunftsland_code']) && !empty($formData['herkunftsland_code'])) ? $formData['herkunftsland_code'] : 'A';
|
||||
$_POST['von'] = (isset($formData['von']) && !empty($formData['von'])) ? $formData['von'] : null;
|
||||
$_POST['bis'] = (isset($formData['bis']) && !empty($formData['bis'])) ? $formData['bis'] : null;
|
||||
$_POST['nation_code'] = (isset($formData['nation_code']) && !empty($formData['nation_code'])) ? $formData['nation_code'] : 'A';
|
||||
$_POST['mobilitaetsprogramm_code'] = (isset($formData['mobilitaetsprogramm_code']) && !empty($formData['mobilitaetsprogramm_code'])) ? $formData['mobilitaetsprogramm_code'] : null;
|
||||
$_POST['herkunftsland_code'] = (isset($formData['herkunftsland_code']) && !empty($formData['herkunftsland_code'])) ? $formData['herkunftsland_code'] : 'A';
|
||||
$_POST['ects_erworben'] = (isset($formData['ects_erworben']) && !empty($formData['ects_erworben'])) ? $formData['ects_erworben'] : null;
|
||||
$_POST['ects_angerechnet'] = (isset($formData['ects_angerechnet']) && !empty($formData['ects_angerechnet'])) ? $formData['ects_angerechnet'] : null;
|
||||
|
||||
|
||||
$this->form_validation->set_rules('nation_code', 'Nation_code', 'required', [
|
||||
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Nation_code'])
|
||||
]);
|
||||
$this->form_validation->set_rules('herkunftsland_code', 'Herkunftsland_code', 'required', [
|
||||
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Herkunftsland_code'])
|
||||
]);
|
||||
$this->form_validation->set_rules('mobilitaetsprogramm_code', 'Mobilitaetsprogramm_code', 'required', [
|
||||
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Mobilitaetsprogramm_code'])
|
||||
]);
|
||||
$this->form_validation->set_rules('von', 'VonDatum', 'is_valid_date', [
|
||||
'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VonDatum'])
|
||||
]);
|
||||
|
||||
$this->form_validation->set_rules('bis', 'VBisDatum', 'is_valid_date', [
|
||||
'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VBisDatum'])
|
||||
]);
|
||||
|
||||
$this->form_validation->set_rules('ects_erworben', 'Ects_erworben', 'numeric', [
|
||||
'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_erworben'])
|
||||
]);
|
||||
|
||||
$this->form_validation->set_rules('ects_angerechnet', 'Ects_angerechnet', 'numeric', [
|
||||
'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_angerechnet'])
|
||||
]);
|
||||
|
||||
if ($this->form_validation->run() == false)
|
||||
{
|
||||
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
}
|
||||
|
||||
$ort = (isset($formData['ort']) && !empty($formData['ort'])) ? $formData['ort'] : null;
|
||||
$universitaet = (isset($formData['universitaet']) && !empty($formData['universitaet'])) ? $formData['universitaet'] : null;
|
||||
$ects_erworben = (isset($formData['ects_erworben']) && !empty($formData['ects_erworben'])) ? $formData['ects_erworben'] : null;
|
||||
$ects_angerechnet = (isset($formData['ects_angerechnet']) && !empty($formData['ects_angerechnet'])) ? $formData['ects_angerechnet'] : null;
|
||||
$localPurposes = (isset($formData['localPurposes']) && !empty($formData['localPurposes'])) ? $formData['localPurposes'] : null;
|
||||
$localSupports = (isset($formData['localSupports']) && !empty($formData['localSupports'])) ? $formData['localSupports'] : null;
|
||||
|
||||
|
||||
//strange fields
|
||||
/* 'zweck_code' => $this->input->post('zweck_code'),
|
||||
'aufenthalt_foerderung' => $this->input->post('aufenthalt_foerderung'),
|
||||
'lehreinheit_id' => $this->input->post('lehreinheit_id'),
|
||||
'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'),*/
|
||||
|
||||
|
||||
$result = $this->BisioModel->insert([
|
||||
'student_uid' => $this->input->post('uid'),
|
||||
'von' => $von,
|
||||
'bis' => $formData['bis'],
|
||||
'mobilitaetsprogramm_code' => $mobilitaetsprogramm_code,
|
||||
'nation_code' => $nation_code,
|
||||
'herkunftsland_code' => $herkunftsland_code,
|
||||
'student_uid' => $student_uid,
|
||||
'von' => $_POST['von'],
|
||||
'bis' => $_POST['bis'],
|
||||
'mobilitaetsprogramm_code' => $_POST['mobilitaetsprogramm_code'],
|
||||
'nation_code' => $_POST['nation_code'],
|
||||
'herkunftsland_code' => $_POST['herkunftsland_code'],
|
||||
'ort' => $ort,
|
||||
'universitaet' => $universitaet,
|
||||
'ects_erworben' => $ects_erworben,
|
||||
'ects_angerechnet' => $ects_angerechnet,
|
||||
'ects_erworben' => $_POST['ects_erworben'] ,
|
||||
'ects_angerechnet' => $_POST['ects_angerechnet'],
|
||||
'insertamum' => date('c'),
|
||||
'insertvon' => $authUID,
|
||||
]);
|
||||
@@ -111,7 +142,6 @@ class Mobility extends FHCAPI_Controller
|
||||
|
||||
//check if localData (purposes)
|
||||
if(count($localPurposes) > 0){
|
||||
|
||||
foreach ($localPurposes as $zweck){
|
||||
$zweck = (int) $zweck;
|
||||
$this->addMobilityPurpose($bisio_id, $zweck);
|
||||
@@ -139,24 +169,71 @@ class Mobility extends FHCAPI_Controller
|
||||
|
||||
public function updateMobility()
|
||||
{
|
||||
$this->load->library('form_validation');
|
||||
$authUID = getAuthUID();
|
||||
|
||||
$student_uid = $this->input->post('uid');
|
||||
|
||||
if(!$student_uid)
|
||||
{
|
||||
return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Student UID']), self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
$formData = $this->input->post('formData');
|
||||
|
||||
$_POST['von'] = (isset($formData['von']) && !empty($formData['von'])) ? $formData['von'] : null;
|
||||
$_POST['bis'] = (isset($formData['bis']) && !empty($formData['bis'])) ? $formData['bis'] : null;
|
||||
$_POST['nation_code'] = (isset($formData['nation_code']) && !empty($formData['nation_code'])) ? $formData['nation_code'] : 'A';
|
||||
$_POST['mobilitaetsprogramm_code'] = (isset($formData['mobilitaetsprogramm_code']) && !empty($formData['mobilitaetsprogramm_code'])) ? $formData['mobilitaetsprogramm_code'] : null;
|
||||
$_POST['herkunftsland_code'] = (isset($formData['herkunftsland_code']) && !empty($formData['herkunftsland_code'])) ? $formData['herkunftsland_code'] : 'A';
|
||||
$_POST['ects_erworben'] = (isset($formData['ects_erworben']) && !empty($formData['ects_erworben'])) ? $formData['ects_erworben'] : null;
|
||||
$_POST['ects_angerechnet'] = (isset($formData['ects_angerechnet']) && !empty($formData['ects_angerechnet'])) ? $formData['ects_angerechnet'] : null;
|
||||
|
||||
|
||||
$this->form_validation->set_rules('nation_code', 'Nation_code', 'required', [
|
||||
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Nation_code'])
|
||||
]);
|
||||
$this->form_validation->set_rules('herkunftsland_code', 'Herkunftsland_code', 'required', [
|
||||
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Herkunftsland_code'])
|
||||
]);
|
||||
$this->form_validation->set_rules('mobilitaetsprogramm_code', 'Mobilitaetsprogramm_code', 'required', [
|
||||
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Mobilitaetsprogramm_code'])
|
||||
]);
|
||||
$this->form_validation->set_rules('von', 'VonDatum', 'is_valid_date', [
|
||||
'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VonDatum'])
|
||||
]);
|
||||
|
||||
$this->form_validation->set_rules('bis', 'VBisDatum', 'is_valid_date', [
|
||||
'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VBisDatum'])
|
||||
]);
|
||||
|
||||
$this->form_validation->set_rules('ects_erworben', 'Ects_erworben', 'numeric', [
|
||||
'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_erworben'])
|
||||
]);
|
||||
|
||||
$this->form_validation->set_rules('ects_angerechnet', 'Ects_angerechnet', 'numeric', [
|
||||
'numeric' => $this->p->t('ui', 'error_fieldNotNumeric', ['field' => 'Ects_angerechnet'])
|
||||
]);
|
||||
|
||||
if ($this->form_validation->run() == false)
|
||||
{
|
||||
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
}
|
||||
|
||||
$result = $this->BisioModel->update(
|
||||
[
|
||||
'bisio_id' => $formData['bisio_id']
|
||||
],
|
||||
[
|
||||
'student_uid' => $this->input->post('uid'),
|
||||
'von' => $formData['von'],
|
||||
'bis' => $formData['bis'],
|
||||
'mobilitaetsprogramm_code' => $formData['mobilitaetsprogramm_code'],
|
||||
'nation_code' => $formData['nation_code'],
|
||||
'herkunftsland_code' => $formData['herkunftsland_code'],
|
||||
'student_uid' => $student_uid,
|
||||
'von' => $_POST['von'],
|
||||
'bis' => $_POST['bis'],
|
||||
'mobilitaetsprogramm_code' => $_POST['mobilitaetsprogramm_code'],
|
||||
'nation_code' => $_POST['nation_code'],
|
||||
'herkunftsland_code' => $_POST['herkunftsland_code'],
|
||||
'ort' => $formData['ort'],
|
||||
'universitaet' => $formData['universitaet'],
|
||||
'ects_erworben' => $formData['ects_erworben'],
|
||||
'ects_angerechnet' => $formData['ects_angerechnet'],
|
||||
'ects_erworben' => $_POST['ects_erworben'] ,
|
||||
'ects_angerechnet' => $_POST['ects_angerechnet'],
|
||||
'updateamum' => date('c'),
|
||||
'updatevon' => $authUID,
|
||||
]
|
||||
@@ -169,8 +246,6 @@ class Mobility extends FHCAPI_Controller
|
||||
|
||||
public function deleteMobility($bisio_id)
|
||||
{
|
||||
// $this->terminateWithError('test ' . $bisio_id, self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$result = $this->BisioModel->delete(
|
||||
array('bisio_id' => $bisio_id)
|
||||
);
|
||||
@@ -262,6 +337,19 @@ class Mobility extends FHCAPI_Controller
|
||||
}
|
||||
|
||||
$this->load->model('codex/Bisiozweck_model', 'BisiozweckModel');
|
||||
if(!$local_purpose)
|
||||
{
|
||||
$check = $this->BisiozweckModel->loadWhere(
|
||||
[
|
||||
'bisio_id' => $bisio_id,
|
||||
'zweck_code' => $zweck_code,
|
||||
]
|
||||
);
|
||||
if (hasData($check))
|
||||
{
|
||||
$this->terminateWithError( $this->p->t('ui', 'error_entryExisting'), self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->BisiozweckModel->insert(
|
||||
array(
|
||||
@@ -272,6 +360,11 @@ class Mobility extends FHCAPI_Controller
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
if($local_purpose)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $this->terminateWithSuccess(current($data));
|
||||
}
|
||||
|
||||
@@ -304,6 +397,20 @@ class Mobility extends FHCAPI_Controller
|
||||
|
||||
$this->load->model('codex/Bisioaufenthaltfoerderung_model', 'BisioaufenthaltfoerderungModel');
|
||||
|
||||
if(!$local_support)
|
||||
{
|
||||
$check = $this->BisioaufenthaltfoerderungModel->loadWhere(
|
||||
[
|
||||
'bisio_id' => $bisio_id,
|
||||
'aufenthaltfoerderung_code' => $aufenthaltfoerderung_code,
|
||||
]
|
||||
);
|
||||
if (hasData($check))
|
||||
{
|
||||
$this->terminateWithError( $this->p->t('ui', 'error_entryExisting'), self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->BisioaufenthaltfoerderungModel->insert(
|
||||
array(
|
||||
'bisio_id' => $bisio_id,
|
||||
@@ -313,11 +420,17 @@ class Mobility extends FHCAPI_Controller
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
if($local_support)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $this->terminateWithSuccess(current($data));
|
||||
}
|
||||
|
||||
public function deleteMobilitySupport($bisio_id)
|
||||
{
|
||||
//TODO(Manu) Validierung Extension
|
||||
$aufenthaltfoerderung_code = $this->input->post('aufenthaltfoerderung_code');
|
||||
|
||||
$this->load->model('codex/Bisioaufenthaltfoerderung_model', 'BisioaufenthaltfoerderungModel');
|
||||
|
||||
@@ -83,7 +83,7 @@ export default {
|
||||
],
|
||||
layout: 'fitColumns',
|
||||
layoutColumnsOnNewData: false,
|
||||
height: '200',
|
||||
height: '250',
|
||||
selectableRangeMode: 'click',
|
||||
selectable: true,
|
||||
persistenceID: 'core-mobility-purpose'
|
||||
@@ -138,16 +138,16 @@ export default {
|
||||
}
|
||||
else
|
||||
{
|
||||
const index = this.localData.findIndex(item => item.zweck_code === zweck_code);
|
||||
const data = this.$refs.table.tabulator.getData();
|
||||
const rowExists = data.some(item => item.zweck_code === zweck_code);
|
||||
|
||||
if (index !== -1) {
|
||||
this.localData.splice(index, 1);
|
||||
if (rowExists) {
|
||||
this.$refs.table.tabulator.deleteRow(zweck_code);
|
||||
}
|
||||
}
|
||||
},
|
||||
handleSubmitAction() {
|
||||
if (this.bisio_id) {
|
||||
|
||||
this.$emit('setMobilityPurpose', {
|
||||
zweck_code: this.formData.zweck_code,
|
||||
bisio_id: this.bisio_id
|
||||
@@ -155,15 +155,27 @@ export default {
|
||||
} else {
|
||||
const purpose = this.listPurposes.find(item => item.zweck_code === this.formData.zweck_code);
|
||||
const newEntry = {
|
||||
zweck_code: this.formData.zweck_code,
|
||||
id: Number (this.formData.zweck_code), //id necessary due to tabulator deleteRow-Action
|
||||
zweck_code: Number (this.formData.zweck_code),
|
||||
kurzbz: purpose.kurzbz,
|
||||
bezeichnung: purpose.bezeichnung
|
||||
};
|
||||
this.localData.push(newEntry);
|
||||
|
||||
this.$emit('setMobilityPurposeToNewMobility', {
|
||||
zweck_code: this.formData.zweck_code,
|
||||
});
|
||||
const data = this.$refs.table.tabulator.getData();
|
||||
const rowExists = data.some(item => item.zweck_code === Number (this.formData.zweck_code));
|
||||
|
||||
if(rowExists){
|
||||
this.$fhcAlert.alertError(this.$p.t('ui', 'error_entryExisting'));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.localData.push(newEntry);
|
||||
|
||||
this.$emit('setMobilityPurposeToNewMobility', {
|
||||
zweck_code: this.formData.zweck_code,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
this.closeModal();
|
||||
},
|
||||
@@ -183,6 +195,9 @@ export default {
|
||||
resetModal(){
|
||||
this.formData = {};
|
||||
this.formData.zweck_code = null;
|
||||
},
|
||||
resetLocalData() {
|
||||
this.$refs.table.tabulator.clearData();
|
||||
}
|
||||
},
|
||||
template: `
|
||||
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
],
|
||||
layout: 'fitColumns',
|
||||
layoutColumnsOnNewData: false,
|
||||
height: '200',
|
||||
height: '250',
|
||||
selectableRangeMode: 'click',
|
||||
selectable: true,
|
||||
persistenceID: 'core-mobility-support'
|
||||
@@ -133,10 +133,11 @@ export default {
|
||||
}
|
||||
else
|
||||
{
|
||||
const index = this.localData.findIndex(item => item.aufenthaltfoerderung_code === aufenthaltfoerderung_code);
|
||||
const data = this.$refs.table.tabulator.getData();
|
||||
const rowExists = data.some(item => item.aufenthaltfoerderung_code === aufenthaltfoerderung_code);
|
||||
|
||||
if (index !== -1) {
|
||||
this.localData.splice(index, 1);
|
||||
if (rowExists) {
|
||||
this.$refs.table.tabulator.deleteRow(aufenthaltfoerderung_code);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -149,18 +150,29 @@ export default {
|
||||
} else {
|
||||
const support = this.listSupports.find(item => item.aufenthaltfoerderung_code === this.formData.aufenthaltfoerderung_code);
|
||||
const newEntry = {
|
||||
id: Number (this.formData.aufenthaltfoerderung_code), //id necessary due to tabulator deleteRow-Action
|
||||
aufenthaltfoerderung_code: this.formData.aufenthaltfoerderung_code,
|
||||
bezeichnung: support.bezeichnung
|
||||
};
|
||||
this.localData.push(newEntry);
|
||||
|
||||
this.$emit('setMobilitySupportToNewMobility', {
|
||||
aufenthaltfoerderung_code: this.formData.aufenthaltfoerderung_code,
|
||||
});
|
||||
const data = this.$refs.table.tabulator.getData();
|
||||
const rowExists = data.some(item => item.aufenthaltfoerderung_code === Number (this.formData.aufenthaltfoerderung_code));
|
||||
|
||||
if(rowExists){
|
||||
this.$fhcAlert.alertError(this.$p.t('ui', 'error_entryExisting'));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.localData.push(newEntry);
|
||||
|
||||
this.$emit('setMobilitySupportToNewMobility', {
|
||||
aufenthaltfoerderung_code: this.formData.aufenthaltfoerderung_code,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
this.closeModal();
|
||||
},
|
||||
|
||||
closeModal(){
|
||||
this.$refs.mobilitySupport.hide();
|
||||
this.$emit('close-modal');
|
||||
@@ -176,6 +188,9 @@ export default {
|
||||
resetModal(){
|
||||
this.formData = {};
|
||||
this.formData.aufenthaltfoerderung_code = null;
|
||||
},
|
||||
resetLocalData() {
|
||||
this.$refs.table.tabulator.clearData();
|
||||
}
|
||||
},
|
||||
template: `
|
||||
|
||||
@@ -168,7 +168,7 @@ export default {
|
||||
uid: this.student.uid,
|
||||
formData: this.formData
|
||||
};
|
||||
return this.$fhcApi.factory.stv.mobility.addNewMobility(dataToSend)
|
||||
return this.$refs.formMobility.factory.stv.mobility.addNewMobility(dataToSend)
|
||||
.then(response => {
|
||||
this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave'));
|
||||
this.resetForm();
|
||||
@@ -176,6 +176,8 @@ export default {
|
||||
.catch(this.$fhcAlert.handleSystemError)
|
||||
.finally(() => {
|
||||
this.reload();
|
||||
this.$refs.purposes.resetLocalData();
|
||||
this.$refs.supports.resetLocalData();
|
||||
});
|
||||
},
|
||||
reload() {
|
||||
@@ -193,7 +195,7 @@ export default {
|
||||
formData: this.formData,
|
||||
uid: this.student.uid,
|
||||
};
|
||||
return this.$fhcApi.factory.stv.mobility.updateMobility(dataToSend)
|
||||
this.$refs.formMobility.factory.stv.mobility.updateMobility(dataToSend)
|
||||
.then(response => {
|
||||
this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave'));
|
||||
this.resetForm();
|
||||
|
||||
@@ -37559,6 +37559,26 @@ array(
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'app' => 'core',
|
||||
'category' => 'ui',
|
||||
'phrase' => 'error_entryExisting',
|
||||
'insertvon' => 'system',
|
||||
'phrases' => array(
|
||||
array(
|
||||
'sprache' => 'German',
|
||||
'text' => 'Eintrag bereits vorhanden',
|
||||
'description' => '',
|
||||
'insertvon' => 'system'
|
||||
),
|
||||
array(
|
||||
'sprache' => 'English',
|
||||
'text' => 'Entry already existing',
|
||||
'description' => '',
|
||||
'insertvon' => 'system'
|
||||
)
|
||||
)
|
||||
),
|
||||
// FHC4 Phrases Mobility End
|
||||
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user