refactoring Fkt addNewNotiz

This commit is contained in:
ma0068
2024-01-11 07:37:46 +01:00
parent 7ef88fcc02
commit db6e1add8a
5 changed files with 75 additions and 39 deletions
@@ -61,20 +61,24 @@ class Notiz extends FHC_Controller
public function addNewNotiz($id)
{
$this->load->library('form_validation');
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
//$this->load->library('form_validation');
//$_POST = json_decode($this->input->raw_input_stream, true);
//TODO(Manu) Validation
$this->form_validation->set_rules('titel', 'titel', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');
/* $this->form_validation->set_rules('titel', 'titel', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');*/
//TODO(Manu) form validation - schon für type hier?,
//Speichern der Files
$this->load->library('DmsLib');
$uid = getAuthUID();
//multiple files
$dms_id = [];
$dms_id_arr = [];
$notiz_id = null;
foreach ($_FILES as $k => $file)
{
$dms = array(
@@ -90,7 +94,7 @@ class Notiz extends FHC_Controller
if (isSuccess($result))
{
$dms_id[] = $result->retval['dms_id'];
$dms_id_arr[] = $result->retval['dms_id'];
}
/* else {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
@@ -104,27 +108,67 @@ class Notiz extends FHC_Controller
}
//Speichern der Notiz mit Notizzuordnung
$this->load->model('person/Notiz_model', 'NotizModel');
$uid = getAuthUID();
$titel = isset($_POST['titel']) ? $_POST['titel'] : null;
$text = isset($_POST['text']) ? $_POST['text'] : null;
$bearbeiter_uid = isset($_POST['bearbeiter_uid']) ? $_POST['bearbeiter_uid'] : null;
$verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : $uid;
$erledigt = $_POST['erledigt'];
$type = $_POST['typeId'];
$titel = $this->input->post('titel');
$text = $this->input->post('text');
$bearbeiter_uid = $this->input->post('bearbeiter_uid');
$erledigt = $this->input->post('erledigt');
$type = $this->input->post('typeId');
//get rid of null value error
$start = $this->input->post(date('von'));
$ende = $this->input->post(date('bis'));
$result = $this->NotizModel->addNotizForType($type, $id, $titel, $text, $uid, $dms_id, $start, $ende, $erledigt, $verfasser_uid, $bearbeiter_uid);
$result = $this->NotizModel->addNotizForType($type, $id, $titel, $text, $uid, $start, $ende, $erledigt, $verfasser_uid, $bearbeiter_uid);
if (isError($result))
{
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson($result);
return $this->outputJson(getError($result));
}
$notiz_id = $result->retval;
//Zuordnung speichern
/* $result = $this->NotizzuordnungModel->insert(array('notiz_id' => $notiz_id, $type=> $id));
if (isError($result))
{
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson(getError($result));
}*/
//Eintrag in Notizdokument speichern
if($dms_id_arr)
{
// Loads model Notizdokument_model
$this->load->model('person/Notizdokument_model', 'NotizdokumentModel');
//Todo(manu) change for multiple files
foreach($dms_id_arr as $dms_id)
{
$result = $this->NotizdokumentModel->insert(array('notiz_id' => $notiz_id, 'dms_id' => $dms_id));
if (isError($result))
{
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson(getError($result));
}
}
}
//$result = $this->NotizModel->addNotizForType($type, $id, $titel, $text, $uid, $dms_id, $start, $ende, $erledigt, $verfasser_uid, $bearbeiter_uid);
/*
$result = $this->NotizModel->addNotizForPerson($id, $titel, $text, $erledigt, $verfasser_uid);
if (isError($result))
{
//$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson($result);
}*/
return $this->outputJsonSuccess(true);
}
+4 -21
View File
@@ -140,7 +140,7 @@ class Notiz_model extends DB_Model
* @param id for Dokumentzuordnung (person_id, prestudent_id, uid, projekt_id...)
* @param titel, text, start, ende, erledigt, verfasser_uid, bearbeiter_uid, insertvon Parameter for notiz
*/
public function addNotizForType($type, $id, $titel, $text, $insertvon, $dms_id=null, $start=null, $ende=null, $erledigt=false, $verfasser_uid=null, $bearbeiter_uid=null)
public function addNotizForType($type, $id, $titel, $text, $insertvon, $start=null, $ende=null, $erledigt=false, $verfasser_uid=null, $bearbeiter_uid=null)
{
// Loads model Notizzuordnung_model
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
@@ -153,30 +153,13 @@ class Notiz_model extends DB_Model
if (isSuccess($result))
{
//cases für alle types
$notiz_id = $result->retval;
if($dms_id)
if (isSuccess($result))
{
// Loads model Notizdokument_model
$this->load->model('person/Notizdokument_model', 'NotizdokumentModel');
//Todo(manu) change for multiple files
foreach ($dms_id as $file)
{
$result = $this->NotizdokumentModel->insert(array('notiz_id' => $notiz_id, 'dms_id' => $file));
}
//single File
//$result = $this->NotizdokumentModel->insert(array('notiz_id' => $notiz_id, 'dms_id' => $dms_id));
$notiz_id = $result->retval;
$result = $this->NotizzuordnungModel->insert(array('notiz_id' => $notiz_id, $type => $id));
}
if ($type == 'person')
$result = $this->NotizzuordnungModel->insert(array('notiz_id' => $notiz_id, 'person_id' => $id));
elseif ($type == 'prestudent')
$result = $this->NotizzuordnungModel->insert(array('notiz_id' => $notiz_id, 'prestudent_id' => $id));
else
$result = error($result->msg, "Type nicht vorhanden");
}
// Transaction complete!
+1
View File
@@ -32,6 +32,7 @@ export default {
}
},
template: `
FILES: {{dateien}}
<span v-if="multiupload">
<input type="file" multiple ref="upload" @change="handleFileChange" v-model="dateien"/>
</span>
+5 -2
View File
@@ -98,7 +98,7 @@ export default {
return this.anhang;
},
set(value) {
console.log(value);
//console.log(value);
this.$emit('update:anhang', value);
}
}
@@ -106,12 +106,15 @@ export default {
methods: {
reset() {
this.$refs.form.reset();
//this.$emit('update:anhang', dt.files);
this.intAnhang = null;
this.$emit('update:anhang', []);
},
},
template: `
<div>
{{this.intAnhang}}
<span v-for="(anhang,index) in intAnhang"> {{anhang.name}} {{index}}<br></span>
<form ref="form" @submit.prevent class="row">
<div>
<div class="row mb-3">
@@ -59,7 +59,7 @@ export default {
tabulatorEvents: [],
notizen: [],
formData: {
typeId: 'person',
typeId: 'person_id',
titel: null,
action: 'Neue Notiz',
text: null,
@@ -105,7 +105,7 @@ export default {
},
actionNewNotiz(){
this.resetFormData();
this.formData.typeId = 'person';
this.formData.typeId = 'person_id';
this.formData.titel = '';
this.formData.action = 'Neue Notiz2';
this.formData.text = null;
@@ -134,6 +134,9 @@ export default {
});
Object.entries(this.formData.anhang).forEach(([k, v]) => formData.append(k, v));
console.log(this.formData);
console.log(formData);
CoreRESTClient.post('components/stv/Notiz/addNewNotiz/' + this.modelValue.person_id,
formData,
{ Headers: { "Content-Type": "multipart/form-data" } }
@@ -211,7 +214,7 @@ export default {
this.$refs.form.reset();
//sicherstellen, dass über props nur leere felder übergeben werden
this.formData = {
typeId: 'person',
typeId: 'person_id',
titel: null,
action: 'Neue Notiz',
text: null,
@@ -330,6 +333,8 @@ export default {
<div>
Parent: {{formData.title}} {{formData.anhang}} || {{formData.anhang.name}}
<span v-for="(anhang,index) in formData.anhang"> {{anhang.name}} {{index}}<br></span> ref: {{formData.ref}}
<!-- PARENT: {{formData.anhang}} {{formData.typeId}} | single: {{formData.anhang.name}} , multi: {{formData.anhang}} <span v-for="(anhang,index) in formData.anhang"> {{anhang.name}} {{index}}<br></span> ref: {{formData.ref}}-->
</div>
</div>