mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
update(Profil Profilbild): first version of the profilbild upload endpoint
This commit is contained in:
@@ -44,6 +44,7 @@ class ProfilUpdate extends FHCAPI_Controller
|
||||
'updateProfilRequest' => self::PERM_LOGGED,
|
||||
'deleteProfilRequest' => self::PERM_LOGGED,
|
||||
'insertFile' => self::PERM_LOGGED,
|
||||
'updateProfilbild' => self::PERM_LOGGED,
|
||||
'show' => self::PERM_LOGGED,
|
||||
]);
|
||||
|
||||
@@ -478,6 +479,106 @@ class ProfilUpdate extends FHCAPI_Controller
|
||||
$this->terminateWithSuccess($res);
|
||||
}
|
||||
|
||||
public function updateProfilbild()
|
||||
{
|
||||
|
||||
$resize = function($filename, $width, $height){
|
||||
// Hoehe und Breite neu berechnen
|
||||
list($width_orig, $height_orig) = getimagesize($filename);
|
||||
|
||||
if ($width && ($width_orig < $height_orig))
|
||||
{
|
||||
$width = ($height / $height_orig) * $width_orig;
|
||||
}
|
||||
else
|
||||
{
|
||||
$height = ($width / $width_orig) * $height_orig;
|
||||
}
|
||||
|
||||
$image_p = imagecreatetruecolor($width, $height);
|
||||
|
||||
$image = imagecreatefromjpeg($filename);
|
||||
|
||||
//Bild nur verkleinern aber nicht vergroessern
|
||||
if($width_orig>$width || $height_orig>$height)
|
||||
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
|
||||
else
|
||||
$image_p = $image;
|
||||
|
||||
imagejpeg($image_p, $filename, 80);
|
||||
|
||||
@imagedestroy($image_p);
|
||||
@imagedestroy($image);
|
||||
};
|
||||
|
||||
if (!count($_FILES)) {
|
||||
$this->terminateWithError("No file available for upload");
|
||||
}
|
||||
|
||||
//? if replace is set it contains the profil_update_id in which the attachment_id has to be replaced
|
||||
$files = $_FILES['files'];
|
||||
$file_count = count($files['name']);
|
||||
$count = 0;
|
||||
for ($i = 0; $i < $file_count; $i++) {
|
||||
$count++;
|
||||
$_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];
|
||||
$_FILES['files']['tmp_name'] = $files['tmp_name'][$i];
|
||||
|
||||
$filename = $_FILES['files']['tmp_name'];
|
||||
|
||||
$ext = substr($files['name'][$i], strrpos($files['name'][$i], '.') + 1);
|
||||
if($ext!='jpg' && $ext!='jpeg'){
|
||||
$this->terminateWithError("Only jpg and jpeg files are allowed for profilbild upload");
|
||||
}
|
||||
|
||||
$width = 827;
|
||||
$height = 1063;
|
||||
// resize
|
||||
$resize($filename, $width, $height);
|
||||
|
||||
|
||||
//akte
|
||||
$fp = fopen($filename,'r');
|
||||
//auslesen
|
||||
$content = fread($fp, filesize($filename));
|
||||
$base64_content = base64_encode($content);
|
||||
$this->load->library('AkteLib');
|
||||
$aktenInsertResult = $this->aktelib->add($this->pid,'Lichtbil',"Lichtbild_".$this->pid.".jpg","image/jpg",$fp,"Lichtbild gross");
|
||||
fclose($fp);
|
||||
if (isError($aktenInsertResult)) {
|
||||
$this->terminateWithError(getError($aktenInsertResult));
|
||||
}
|
||||
|
||||
// in person abspeichern
|
||||
$resize($filename, 101, 130);
|
||||
$fp = fopen($filename,'r');
|
||||
$content = fread($fp, filesize($filename));
|
||||
fclose($fp);
|
||||
$base64_content = base64_encode($content);
|
||||
$this->load->model('person/Person_model','PersonModel');
|
||||
$personUpdate = $this->PersonModel->update($this->pid, ["foto"=>$base64_content]);
|
||||
if(isError($personUpdate)){
|
||||
$this->terminateWithError(getError($personUpdate));
|
||||
}
|
||||
// update foto status
|
||||
$this->load->model('person/Fotostatusperson_model','FotostatusModel');
|
||||
$fotoInsert = $this->FotostatusModel->insert(["person_id"=>$this->pid,"fotostatus_kurzbz"=>"hochgeladen","datum"=>date('Y-m-d'),"insertamum"=>date('Y-m-d H:i:s'),"insertvon"=>$this->uid,"updateamum"=>date('Y-m-d H:i:s'),"updatevon"=>$this->uid]);
|
||||
if(isError($fotoInsert)){
|
||||
$this->terminateWithError(getError($fotoInsert));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->terminateWithSuccess(["fotoStatus"=>getData($fotoInsert),"personUpdate"=>getData($personUpdate),"akteInsert"=>getData($aktenInsertResult)]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getProfilUpdateWithPermission($status = null)
|
||||
{
|
||||
// early return if no status has been passed as argument
|
||||
|
||||
@@ -61,6 +61,13 @@ export default {
|
||||
params: dms
|
||||
};
|
||||
},
|
||||
updateProfilbild(dms) {
|
||||
return {
|
||||
method: 'post',
|
||||
url: `/api/frontend/v1/ProfilUpdate/updateProfilbild`,
|
||||
params: dms
|
||||
};
|
||||
},
|
||||
getProfilRequestFiles(requestID) {
|
||||
return {
|
||||
method: 'get',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import ApiProfil from '../../../../api/factory/profil.js';
|
||||
import ImageUpload from '../../Profil/ProfilModal/EditProfilComponents/ImageUpload.js';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@@ -17,6 +18,9 @@ export default {
|
||||
default: true
|
||||
}
|
||||
},
|
||||
components:{
|
||||
ImageUpload,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
FotoSperre: this.data.foto_sperre,
|
||||
@@ -25,6 +29,9 @@ export default {
|
||||
emits: ["showEditProfilModal"],
|
||||
|
||||
methods: {
|
||||
showModal(){
|
||||
this.$refs.imageUpload.show();
|
||||
},
|
||||
sperre_foto_function() {
|
||||
//TODO: refactor
|
||||
if (!this.data) {
|
||||
@@ -66,6 +73,7 @@ export default {
|
||||
template: /*html*/ `
|
||||
|
||||
<div class="card h-100">
|
||||
<image-upload ref="imageUpload" titel="test"></image-upload>
|
||||
<div class="card-header">
|
||||
<div class="row">
|
||||
<div v-if="editable" @click="$emit('showEditProfilModal','Personen_Informationen')" class="col-auto" type="button">
|
||||
@@ -88,7 +96,7 @@ export default {
|
||||
<div v-if="editable" role="button" @click.prevent="sperre_foto_function" class="image-lock">
|
||||
<i :class="{'fa':true, ...(FotoSperre?{'fa-lock':true}:{'fa-lock-open':true})} "></i>
|
||||
</div>
|
||||
<div v-if="!fotoStatus" role="button" @click.prevent="" class="image-upload">
|
||||
<div v-if="!fotoStatus" role="button" @click.prevent="showModal" class="image-upload">
|
||||
<i class="fa fa-upload"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import Dms from "../../../../Form/Upload/Dms.js";
|
||||
import BsModal from "../../../../Bootstrap/Modal.js";
|
||||
|
||||
import ApiProfilUpdate from '../../../../../api/factory/profilUpdate.js';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
dmsData: [],
|
||||
};
|
||||
},
|
||||
components: {
|
||||
Dms,
|
||||
BsModal,
|
||||
},
|
||||
mixins: [BsModal],
|
||||
props: {
|
||||
titel: {
|
||||
type: Object,
|
||||
},
|
||||
files: {
|
||||
type: Array,
|
||||
},
|
||||
updateID: {
|
||||
type: Boolean,
|
||||
},
|
||||
onHideBsModal: Function,
|
||||
onHiddenBsModal: Function,
|
||||
onHidePreventedBsModal: Function,
|
||||
onShowBsModal: Function,
|
||||
onShownBsModal: Function,
|
||||
},
|
||||
methods:{
|
||||
async uploadImage(){
|
||||
if(this.dmsData){
|
||||
let formData = new FormData();
|
||||
formData.append("files[]", this.dmsData[0]);
|
||||
await this.$api
|
||||
.call(ApiProfilUpdate.updateProfilbild(formData))
|
||||
.then((res) => {
|
||||
console.log("here", res.data?.map((file) => file.dms_id)) ;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.modal = this.$refs.modalContainer.modal;
|
||||
if (this.files) {
|
||||
this.dmsData = this.files;
|
||||
}
|
||||
},
|
||||
popup(options) {
|
||||
BsModal.popup.bind(this);
|
||||
return BsModal.popup(null, options);
|
||||
},
|
||||
template: /*html*/`
|
||||
|
||||
<bs-modal v-show="!loading" ref="modalContainer" v-bind="$props" body-class="" dialog-class="modal-lg" class="bootstrap-alert" :backdrop="false">
|
||||
<template #title>
|
||||
<p style="opacity:0.8" class="ms-2" v-if="!updateID">{{$p.t('profilUpdate','profilUpdateInformationMessage',[titel])}}</p>
|
||||
</template>
|
||||
<template #default>
|
||||
<div class="form-underline">
|
||||
<div class="form-underline-titel">{{titel?titel:$p.t('global','titel')}}</div>
|
||||
</div>
|
||||
<div class="row gx-2">
|
||||
<div class="col">
|
||||
<dms ref="update" id="files" name="files" :multiple="false" v-model="dmsData" @update:model-value="didFilesChange" ></dms>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button @click="dmsData=[]" class="btn btn-danger"><i style="color:white" class="fa fa-trash"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex" style="margin-left:auto;">
|
||||
<button @click="uploadImage" class="btn btn-primary">upload</button>
|
||||
</div>
|
||||
</template>
|
||||
<template #footer>
|
||||
</template>
|
||||
</bs-modal>
|
||||
`,
|
||||
};
|
||||
Reference in New Issue
Block a user