From 9eb61649eba507db13ef4518393d864f847fb1a9 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 19 Jul 2024 09:06:49 +0200 Subject: [PATCH] adds getProfilRequestFiles to the new ProfilUpdate FhcAPIController --- .../api/frontend/v1/ProfilUpdate.php | 109 +++++++++++++++++- public/js/api/profilUpdate.js | 24 ++-- public/js/apps/Cis/ProfilUpdateRequests.js | 3 +- .../ProfilComponents/FetchProfilUpdates.js | 11 +- .../EditProfilComponents/Status.js | 2 +- .../Cis/ProfilUpdate/AcceptDenyUpdate.js | 2 +- 6 files changed, 127 insertions(+), 24 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index df594d3cf..56dd4486b 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -40,10 +40,10 @@ class ProfilUpdate extends FHCAPI_Controller parent::__construct([ 'getStatus' => self::PERM_LOGGED, 'getTopic' => self::PERM_LOGGED, + 'getProfilRequestFiles' => self::PERM_LOGGED, ]); - $this->load->model('person/Profil_update_model', 'ProfilUpdateModel'); $this->load->model('person/Kontakt_model', 'KontaktModel'); $this->load->model('person/Adresse_model', 'AdresseModel'); @@ -102,6 +102,113 @@ class ProfilUpdate extends FHCAPI_Controller $this->terminateWithSuccess(self::$TOPICS); } + public function getProfilRequestFiles($id) + { + if(!$id){ + $this->terminateWithError("parameter id is missing"); + } + + $this->ProfilUpdateModel->addSelect(["attachment_id"]); + $attachmentID = $this->ProfilUpdateModel->load([$id]); + if (isError($attachmentID)) { + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_loading_error')),self::ERROR_TYPE_GENERAL); + } + //? get the attachmentID + $dms_id = $this->getDataOrTerminateWithError($attachmentID)[0]->attachment_id; + + //? get the name to the file + $this->DmsVersionModel->addSelect(["name", "dms_id"]); + $attachment = $this->DmsVersionModel->load([$dms_id, 0]); + if (isError($attachment)) { + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_dmsVersion_error')),self::ERROR_TYPE_GENERAL); + } + $attachment = $this->getDataOrTerminateWithError($attachment); + //? returns {name:..., dms_id:...} + $this->terminateWithSuccess($attachment); + } + + /* public function insertFile($replace) + { + $replace = json_decode($replace); + + if (!count($_FILES)) { + $this->terminateWithSuccess([]); + return; + } + + //? if replace is set it contains the profil_update_id in which the attachment_id has to be replaced + if (isset($replace)) { + $this->ProfilUpdateModel->addSelect(["attachment_id"]); + $profilUpdate = $this->ProfilUpdateModel->load([$replace]); + if (isError($profilUpdate)) { + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_loading_error')),self::ERROR_TYPE_GENERAL); + } + //? get the attachmentID + $dms_id = $this->getDataOrTerminateWithError($profilUpdate)[0]; + + //? delete old dms_file of Profil Update + $this->deleteOldVersionFile($dms_id); + } + + + $files = $_FILES['files']; + $file_count = count($files['name']); + + $res = []; + + for ($i = 0; $i < $file_count; $i++) { + $_FILES['files']['name'] = $files['name'][$i]; + $_FILES['files']['type'] = $files['type'][$i]; + $_FILES['files']['tmp_name'] = $files['tmp_name'][$i]; + $_FILES['files']['error'] = $files['error'][$i]; + $_FILES['files']['size'] = $files['size'][$i]; + + $dms = [ + "kategorie_kurzbz" => "profil_aenderung", + "version" => 0, + "name" => $_FILES['files']['name'], + "mimetype" => $_FILES['files']['type'], + "beschreibung" => $this->uid . " Profil Änderung", + "insertvon" => $this->uid, + "insertamum" => "NOW()", + ]; + + $tmp_res = $this->dmslib->upload($dms, 'files', array("jpg", "png", "pdf")); + + $tmp_res = $this->getDataOrTerminateWithError($tmp_res); + array_push($res, $tmp_res); + } + + $this->terminateWithSuccess($res); + } + + private function deleteOldVersionFile($dms_id) + { + if (!isset($dms_id)) { + return; + } + + //? collect all the results of the deleted versions in an array + $res = array(); + + //? delete all the different versions of the dms_file + $dmsVersions = $this->DmsVersionModel->loadWhere(["dms_id" => $dms_id]); + $dmsVersions = $this->getDataOrTerminateWithError($dmsVersions); + if (isset($dmsVersions)) { + $zwischen_res = array_map(function ($item) { + return $item->version; + }, $dmsVersions); + foreach ($zwischen_res as $version) { + array_push($res, $this->DmsVersionModel->delete([$dms_id, $version])); + } + } else { + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_dmsVersion_error')), self::ERROR_TYPE_GENERAL); + } + + //? returns a result for each deleted dms_file + return $res; + } + */ } \ No newline at end of file diff --git a/public/js/api/profilUpdate.js b/public/js/api/profilUpdate.js index 5d4978ce4..ca009547d 100644 --- a/public/js/api/profilUpdate.js +++ b/public/js/api/profilUpdate.js @@ -15,15 +15,6 @@ export default { `/api/frontend/v1/ProfilUpdate/getTopic`,{}); }, - getProfilUpdateRequest: function () { - - return this.$fhcApi.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/getAllRequests`,{}); - - }, - //TODO post request acceptProfilRequest: function (payload) { @@ -68,16 +59,19 @@ export default { headers: { "Content-Type": "multipart/form-data" }, }); }, - - //TODO post request + getProfilRequestFiles: function (requestID) { - const url = + return this.$fhcApi.get( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/getProfilRequestFiles`; - - return axios.post(url, requestID); + `/api/frontend/v1/ProfilUpdate/getProfilRequestFiles/${requestID}`,{}); }, + + search(searchsettings) { + const url = '/api/frontend/v1/searchbar/search'; + return this.$fhcApi.post(url, searchsettings); + }, + selectProfilRequest: function (uid = null, id = null) { diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js index c72a7592f..42e5bd576 100755 --- a/public/js/apps/Cis/ProfilUpdateRequests.js +++ b/public/js/apps/Cis/ProfilUpdateRequests.js @@ -22,8 +22,7 @@ const app = Vue.createApp({ }, methods: {}, created() { - console.log("this is the place i am searching for") - Vue.$fhcapi.ProfilUpdate.getStatus() + this.$fhcApi.factory.profilUpdate.getStatus() .then((response) => { this.profilUpdateStates = response.data; }) diff --git a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js index 9ae5c5a00..368b5e111 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js +++ b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js @@ -37,21 +37,23 @@ export default { }, async showEditProfilModal(updateRequest) { - let view = this.getView(updateRequest.topic, updateRequest.status); + let view = this.getView(updateRequest.topic, updateRequest.status); + let data = null; let content = null; let files = null; let withFiles = false; if (view === "TextInputDokument") { + console.log("text input") data = { titel: updateRequest.topic, value: updateRequest.requested_change.value, }; - + const filesFromDatabase = - await Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles( + await this.$fhcApi.factory.profilUpdate.getProfilRequestFiles( updateRequest.profil_update_id ).then((res) => { return res.data; @@ -140,7 +142,8 @@ export default { }, }, - created() {}, + created() { + }, computed: {}, diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/Status.js b/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/Status.js index 307a0cc62..437bb1fb5 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/Status.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/Status.js @@ -65,7 +65,7 @@ export default { topic: { type: String }, }, created() { - Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles(this.updateID).then( + this.$fhcApi.factory.profilUpdate.getProfilRequestFiles(this.updateID).then( (res) => { this.files = res.data; } diff --git a/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js b/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js index 76a2e2b6a..bbf1489a5 100755 --- a/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js +++ b/public/js/components/Cis/ProfilUpdate/AcceptDenyUpdate.js @@ -95,7 +95,7 @@ export default { created() { // only fetching the profilUpdate Attachemnts if the profilUpdate actually has attachments if (this.value.attachment_id) { - Vue.$fhcapi.ProfilUpdate.getProfilRequestFiles( + this.$fhcApi.factory.profilUpdate.getProfilRequestFiles( this.data.profil_update_id ).then((res) => { this.files = res.data;