diff --git a/application/controllers/components/stv/Notiz.php b/application/controllers/components/stv/Notiz.php index 36504d77d..1850a5609 100644 --- a/application/controllers/components/stv/Notiz.php +++ b/application/controllers/components/stv/Notiz.php @@ -29,18 +29,30 @@ class Notiz extends FHC_Controller $this->outputJsonError($result); } - public function getNotizen($person_id) + public function getNotizen($id, $type) { $this->load->model('person/Notiz_model', 'NotizModel'); - $type = 'person'; + $this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel'); - $result = $this->NotizModel->getNotizWithDocEntries($person_id); + //check if valid type + $isValidType = $this->NotizzuordnungModel->isValidType($type); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + if($isValidType) + { + $result = $this->NotizModel->getNotizWithDocEntries($id, $type); + + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + $this->outputJson(getError($result)); + } else { + $this->outputJson(getData($result) ?: []); + } + } + else + { + //Todo manu (correct return to ajax) + $result = "datatype not yet implemented for notes"; $this->outputJson(getError($result)); - } else { - $this->outputJson(getData($result) ?: []); } } @@ -60,8 +72,7 @@ class Notiz extends FHC_Controller } elseif (!hasData($result)) { - $this->outputJson($result); //success mit Wert null - // $this->outputJson(getData($result) ?: []); + $this->outputJson($result); } else { @@ -69,7 +80,7 @@ class Notiz extends FHC_Controller } } - public function addNewNotiz($id) + public function addNewNotiz($id, $paramTyp = null) { $this->load->model('person/Notiz_model', 'NotizModel'); @@ -87,6 +98,18 @@ class Notiz extends FHC_Controller } } + //Überprüfung ob type übergeben wurde (entweder Funktions- oder Postparameter) + if ($paramTyp) + $type = $paramTyp; + if(isset($_POST['typeId'])) + $type = $this->input->post('typeId'); + + if(!$type) + { + //Todo(manu) return error + var_dump("ERROR no type"); + } + //Form Validation $this->form_validation->set_rules('titel', 'titel', 'required'); $this->form_validation->set_rules('text', 'Text', 'required'); @@ -101,11 +124,11 @@ class Notiz extends FHC_Controller $erledigt = $this->input->post('erledigt'); $verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : $uid; $bearbeiter_uid = isset($_POST['bearbeiter']) ? $_POST['bearbeiter'] : null; - $type = $this->input->post('typeId'); + //$type = $this->input->post('typeId'); $start = $this->input->post('von'); $ende = $this->input->post('bis'); - //Speichern der Notiz und Notizzuordnung + //Speichern der Notiz und Notizzuordnung inkl Prüfung ob valid type $result = $this->NotizModel->addNotizForType($type, $id, $titel, $text, $uid, $start, $ende, $erledigt, $verfasser_uid, $bearbeiter_uid); if (isError($result)) { @@ -219,7 +242,10 @@ class Notiz extends FHC_Controller return $this->outputJson(getError($result)); } + //Todo(manu) update von Notizzuordnung?? typeId? + //neue Files speichern + //Todo(manu) update files foreach ($_FILES as $k => $file) { $dms = array( @@ -291,7 +317,6 @@ class Notiz extends FHC_Controller } } - //Todo(manu) rollback? //delete Notiz und Notizzuordnung $this->load->model('person/Notiz_model', 'NotizModel'); diff --git a/application/models/person/Notiz_model.php b/application/models/person/Notiz_model.php index 7e7ffbe32..21c91884b 100644 --- a/application/models/person/Notiz_model.php +++ b/application/models/person/Notiz_model.php @@ -140,11 +140,31 @@ 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, $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'); + //check if valid type + $isValidType = $this->NotizzuordnungModel->isValidType($type); + + if(!$isValidType) + { + //Todo manu (correct return to controller) + $msg = "datatype " . $type . " not implemented for notes"; + return error($msg, EXIT_ERROR); + } + // Start DB transaction $this->db->trans_start(false); @@ -180,13 +200,10 @@ class Notiz_model extends DB_Model return $result; } - - /** * Add a Notiz for a given person with DMS_id */ - //TODO(manu) add type for Notizzuordnung - public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis, $dms_id=null) + public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis, $dms_id = null) { // Loads model Notizzuordnung_model $this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel'); @@ -243,16 +260,12 @@ class Notiz_model extends DB_Model /** * gets all Notizen with Documententries for a certain type and type_id - * @param $person_id + * @param String type of id eg. person_id, prestudent_id, mitarbeiter_uid, projekt_kurzbz, projektphase_id, projekttask_id, + * bestellung_id, lehreinheit_id, anrechnung_id, uid) + * @param $id the corresponding id, part of public.tbl_notizzuordnung */ - //Todo(Manu) rewrite in CI-Style - //Todo(Manu) auf andere types erweitern - public function getNotizWithDocEntries($id) + public function getNotizWithDocEntries($id, $type) { - $type = 'writeFunction'; - //$type_id = 'z.person_id'; - - $qry = " SELECT n.*, count(dms_id) as countDoc, z.notizzuordnung_id @@ -265,16 +278,15 @@ class Notiz_model extends DB_Model LEFT JOIN campus.tbl_dms_version USING (dms_id) WHERE - z.person_id = ? + z.$type = ? GROUP BY notiz_id, z.notizzuordnung_id "; - return $this->execQuery($qry, array($id)); - } + /** * gets all Notizen for a person with a specific title * @param $person_id @@ -361,6 +373,4 @@ class Notiz_model extends DB_Model return $this->loadWhere(array('anrechnung_id' => $anrechnung_id)); } - // ------------------------------------------------------------------------------------------------------ - } diff --git a/application/models/person/Notizzuordnung_model.php b/application/models/person/Notizzuordnung_model.php index 187a8399b..542c68e6f 100644 --- a/application/models/person/Notizzuordnung_model.php +++ b/application/models/person/Notizzuordnung_model.php @@ -11,4 +11,35 @@ class Notizzuordnung_model extends DB_Model $this->dbTable = 'public.tbl_notizzuordnung'; $this->pk = 'notizzuordnung_id'; } + + public function isValidType($type) + { + //var_dump($type); + $validTypes = []; + + $qry = " + SELECT column_name + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'tbl_notizzuordnung' + "; + + $type_arr = $this->execQuery($qry); + $type_arr = $type_arr->retval; + + foreach ($type_arr as $t) { + $validTypes[] = $t->column_name; + } + + if (in_array($type, $validTypes)) + { + // var_dump($type . " is IN ARRAY"); + return true; + } + else + { + //var_dump($type . " is NOT IN ARRAY"); + return false; + } + } } diff --git a/public/js/components/Notiz/Notiz.js b/public/js/components/Notiz/Notiz.js index 46b6a6992..be472de6d 100644 --- a/public/js/components/Notiz/Notiz.js +++ b/public/js/components/Notiz/Notiz.js @@ -29,7 +29,7 @@ export default { multiupload: true, mitarbeiter: [], filteredMitarbeiter: [], - filteredFirmen: [] +/* filteredFirmen: []*/ } }, computed: { @@ -138,17 +138,16 @@ export default {
- {{action}}
[{{this.typeId}}] -
+
-
+
@@ -159,25 +158,21 @@ export default {
-
- + +
- -
+ +
-
- - - -
- -
- - +
+ + +
+
@@ -186,15 +181,15 @@ export default {
- -
+
@@ -205,32 +200,28 @@ export default {
-
- -
- +
+
- - -
- - - - -
` +
+ + + +
` } diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js b/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js index f88ce0627..8e9917287 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js @@ -6,7 +6,7 @@ import BsModal from "../../../Bootstrap/Modal"; var editIcon = function (cell, formatterParams) { return ""; }; -var deleteIcon = function (cell, formatterParams){ +var deleteIcon = function (cell, formatterParams) { return ""; }; @@ -20,11 +20,11 @@ export default { props: { modelValue: Object }, - data() { + data(){ return { tabulatorOptions: { - ajaxURL: CoreRESTClient._generateRouterURI('components/stv/Notiz/getNotizen/' + this.modelValue.person_id), - // + this.modelValue.person_id, 'person'), + ajaxURL: CoreRESTClient._generateRouterURI('components/stv/Notiz/getNotizen/' + this.modelValue.person_id + '/person_id'), + //ajaxURL: CoreRESTClient._generateRouterURI('components/stv/Notiz/getNotizen/' + this.modelValue.person_id + '/' + this.typeId), columns: [ {title: "Titel", field: "titel"}, {title: "Text", field: "text", width: 350}, @@ -52,7 +52,7 @@ export default { ], layout: 'fitDataFill', layoutColumnsOnNewData: false, - height: '200', + height: '150', selectable: true, index: 'notiz_id' }, @@ -74,10 +74,10 @@ export default { bearbeiter: null, anhang: [] }, - showErweitert: true, - showDocument: true + showErweitert: true, //show details verfasser, bearbeiter, von, bis, erledigt + showDocument: true //show upload documents - } + }; }, methods:{ actionDeleteNotiz(notiz_id){ @@ -107,8 +107,7 @@ export default { this.loadDocEntries(this.notizen.notiz_id); //console.log(this.formData.anhang); } - }) - ; + }); }, actionNewNotiz(){ this.resetFormData(); @@ -125,13 +124,13 @@ export default { this.formData.anhang = []; }, addNewNotiz(notizData) { - const formData = new FormData(); formData.append('data', JSON.stringify(this.formData)); Object.entries(this.formData.anhang).forEach(([k, v]) => formData.append(k, v)); - CoreRESTClient.post('components/stv/Notiz/addNewNotiz/' + this.modelValue.person_id, + CoreRESTClient.post( + 'components/stv/Notiz/addNewNotiz/' + this.modelValue.person_id, formData, { Headers: { "Content-Type": "multipart/form-data" } } ).then(response => { @@ -163,16 +162,15 @@ export default { this.$fhcAlert.alertError('Keine Notiz mit Id ' + notiz_id + ' gefunden'); } }).catch(error => { - this.$fhcAlert.alertError('Fehler bei Löschroutine aufgetreten'); - }).finally(()=> { - window.scrollTo(0, 0); - }); + this.$fhcAlert.alertError('Fehler bei Löschroutine aufgetreten'); + }).finally(()=> { + window.scrollTo(0, 0); + }); }, loadDocEntries(notiz_id){ return CoreRESTClient.get('components/stv/Notiz/loadDokumente/' + notiz_id) .then( result => { - //console.log(result.data); if(result.data.retval) { this.formData.anhang = result.data.retval; console.log(this.formData.anhang); @@ -187,15 +185,15 @@ export default { ); }, loadNotiz(notiz_id){ - return CoreRESTClient.get('components/stv/Notiz/loadNotiz/' + notiz_id) + return CoreRESTClient.get( + 'components/stv/Notiz/loadNotiz/' + notiz_id) .then( result => { if(result.data.retval) { this.notizen = result.data.retval; - console.log(this.notizen); + //console.log(this.notizen); } - else - { + else { this.notizen = {}; this.$fhcAlert.alertError('Keine Notiz mit Id ' + notiz_id + ' gefunden'); } @@ -230,7 +228,8 @@ export default { Object.entries(this.formData.anhang).forEach(([k, v]) => formData.append(k, v)); //console.log(this.formData); - CoreRESTClient.post('components/stv/Notiz/updateNotiz/' + notiz_id, + CoreRESTClient.post( + 'components/stv/Notiz/updateNotiz/' + notiz_id, formData, { Headers: { "Content-Type": "multipart/form-data" } } ).then(response => { @@ -256,9 +255,9 @@ export default { CoreRESTClient .get('components/stv/Notiz/getUid') .then(result => { - if(result.data.retval) { - this.formData.verfasser = result.data.retval; - } + if(result.data.retval) { + this.formData.verfasser = result.data.retval; + } }) .catch(this.$fhcAlert.handleSystemError); }, @@ -277,7 +276,7 @@ export default { - + -
+

- Neu anlegen - -
- -
-` -}; \ No newline at end of file + ` +};