adds getProfilRequestFiles to the new ProfilUpdate FhcAPIController

This commit is contained in:
SimonGschnell
2024-07-19 09:06:49 +02:00
parent 2711113a69
commit 9eb61649eb
6 changed files with 127 additions and 24 deletions
@@ -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;
}
*/
}
+9 -15
View File
@@ -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) {
+1 -2
View File
@@ -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;
})
@@ -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: {},
@@ -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;
}
@@ -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;