updates the foto_sperre_function to automatically update the data of the vue component

This commit is contained in:
Simon Gschnell
2023-11-22 09:51:49 +01:00
parent 16b61d0560
commit 0e813f78fb
4 changed files with 186 additions and 43 deletions
+73 -22
View File
@@ -18,6 +18,9 @@ class Profil extends Auth_Controller
'index' => ['student/anrechnung_beantragen:r','user:r'], // TODO(chris): permissions?
'isMitarbeiterOrStudent' => ['student/anrechnung_beantragen:r','user:r'],
'getMitarbeiterAnsicht' => ['student/anrechnung_beantragen:r','user:r'],
'foto_sperre_function' => ['student/anrechnung_beantragen:r','user:r'],
]);
$this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel');
@@ -52,8 +55,32 @@ class Profil extends Auth_Controller
public function getMitarbeiterAnsicht(){
if(
isSuccess($this->PersonModel->addSelect('gruppe_kurzbz, beschreibung'))&&
isSuccess($this->PersonModel->addJoin('tbl_benutzer', 'person_id')) &&
isSuccess($this->PersonModel->addJoin('tbl_benutzergruppe', 'uid')) &&
isSuccess($this->PersonModel->addJoin('tbl_gruppe', 'gruppe_kurzbz'))){
$mailverteiler_res = $this->PersonModel->loadWhere(array('mailgrp' => true, 'uid'=>getAuthUID()));
if( isError($mailverteiler_res)){
// catch error
}
$mailverteiler_res = hasData($mailverteiler_res)? getData($mailverteiler_res) : null;
}
if(isSuccess($this->KontaktModel->addSelect('DISTINCT ON (kontakttyp) kontakttyp, kontakt, tbl_kontakt.anmerkung, tbl_kontakt.zustellung')) &&
isSuccess($this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT')) &&
isSuccess($this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT'))&&
isSuccess($this->KontaktModel->addOrder('kontakttyp, kontakt, tbl_kontakt.updateamum, tbl_kontakt.insertamum'))
){
$kontakte_res = $this->KontaktModel->loadWhere(array('person_id' => getAuthPersonID()));
if(isError($kontakte_res)){
// handle error
}else{
$kontakte_res = hasData($kontakte_res)? getData($kontakte_res) : null;
}
}
$zutrittskarte_ausgegebenam = $this->BetriebsmittelpersonModel->getBetriebsmittel(getAuthPersonId());
if(isError($zutrittskarte_ausgegebenam)){
@@ -64,6 +91,7 @@ class Profil extends Auth_Controller
if(
isSuccess($this->BetriebsmittelpersonModel->addSelect(["betriebsmitteltyp", "beschreibung","nummer","ausgegebenam"]))
){
$betriebsmittelperson_res = $this->BetriebsmittelpersonModel->getBetriebsmittel(getAuthPersonId());
if(isError($betriebsmittelperson_res)){
@@ -74,10 +102,11 @@ class Profil extends Auth_Controller
}
if(
isSuccess($this->BenutzerfunktionModel->addSelect(["tbl_benutzerfunktion.bezeichnung as bf_bezeichnung","tbl_organisationseinheit.bezeichnung as oe_bezeichnung","datum_von","datum_bis","wochenstunden"]))
&& isSuccess($this->BenutzerfunktionModel->addJoin("tbl_organisationseinheit","oe_kurzbz"))
//! Summe der Wochenstunden wird jetzt in der hr/tbl_dienstverhaeltnis gespeichert
isSuccess($this->BenutzerfunktionModel->addSelect(["tbl_benutzerfunktion.bezeichnung as bf_bezeichnung","tbl_organisationseinheit.bezeichnung as oe_bezeichnung","datum_von","datum_bis","wochenstunden"]))&&
isSuccess($this->BenutzerfunktionModel->addJoin("tbl_organisationseinheit","oe_kurzbz"))
){
$benutzer_funktion_res = $this->BenutzerfunktionModel->loadWhere("uid='" . getAuthUID() . "'");
$benutzer_funktion_res = $this->BenutzerfunktionModel->loadWhere(array('uid'=>getAuthUID()));
if(isError($benutzer_funktion_res)){
// error handling
}else{
@@ -85,12 +114,19 @@ class Profil extends Auth_Controller
}
}
//! THERE COULD BE MULTIPLE ADRESSES
$adresse_res = $this->AdresseModel->load(getAuthPersonId());
if(isError($adresse_res)){
// error handling
}else{ //! not only one
$adresse_res = hasData($adresse_res)? getData($adresse_res)[0] : null;
if(
isSuccess($adresse_res = $this->AdresseModel->addSelect(array("strasse","tbl_adressentyp.bezeichnung as adr_typ","plz","ort")))&&
isSuccess($adresse_res = $this->AdresseModel->addOrder("zustelladresse","DESC"))&&
isSuccess($adresse_res = $this->AdresseModel->addOrder("sort"))&&
isSuccess($adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp","typ=adressentyp_kurzbz"))
){
$adresse_res = $this->AdresseModel->loadWhere(array("person_id"=>getAuthPersonID()));
if(isError($adresse_res)){
// error handling
}else{
$adresse_res = hasData($adresse_res)? getData($adresse_res) : null;
}
}
$benutzer_res = $this->BenutzerModel->load([getAuthUID()]);
@@ -134,26 +170,20 @@ class Profil extends Auth_Controller
$res->email_intern = getAuthUID() . DOMAIN;
$res->email_extern = $benutzer_res->alias . DOMAIN;
//? Adresse Info
$res->strasse = $adresse_res->strasse;
$res->heimatadresse = $adresse_res->heimatadresse;
$res->zustelladresse = $adresse_res->zustelladresse;
$res->plz = $adresse_res->plz;
$res->ort = $adresse_res->ort;
$res->adressen = $adresse_res;
//? Benutzerfunktion Info
$res->funktionen = $benutzer_funktion_res;
//? Betriebsmittel Info
$res->mittel = $betriebsmittelperson_res;
//? Austellungsdatum von der Zutrittskarte
$res->zutrittskarte_ausgegebenam = $zutrittskarte_ausgegebenam->ausgegebenam;
$res->kontakt = $kontakte;
//? Kontakt Info
$res->kontakte = $kontakte_res;
//? Mailverteiler Info
$res->mailverteiler = $mailverteiler_res;
echo json_encode($res);
return;
}
//? check wheter the parameter uid is a Mitarbeiter or a Student
@@ -170,6 +200,27 @@ class Profil extends Auth_Controller
}
public function foto_sperre_function($value){
$res = $this->PersonModel->update(getAuthPersonID(),array("foto_sperre"=>$value));
if(isError($res)){
// error handling
}else{
//? select the value of the column foto_sperre to return
if(isSuccess($this->PersonModel->addSelect("foto_sperre"))){
$res = $this->PersonModel->load(getAuthPersonID());
if(isError($res)){
// error handling
}
$res = hasData($res) ? getData($res)[0] : null;
}
}
echo json_encode($res);
}
+2 -1
View File
@@ -9,7 +9,8 @@ $this->load->view('templates/CISHTML-Header', $includesArray);
?>
<div id="content">
<h2>Profil22</h2>
<h2>Profil</h2>
<hr>
<p><?php echo $uid; ?></p>
<!-- we can pass information from the php view file to the public js file through interpolating data from php into vue props -->
+5
View File
@@ -15,6 +15,11 @@ export default {
+ `cis.php/Cis/Profil/getMitarbeiterAnsicht`;
return axios.get(url);
},
sperre_foto_function: function(value) {
const url = FHC_JS_DATA_STORAGE_OBJECT.app_root
+ `cis.php/Cis/Profil/foto_sperre_function/${value}`;
return axios.get(url);
},
};
+106 -20
View File
@@ -1,6 +1,6 @@
import fhcapifactory from "../../../apps/api/fhcapifactory.js";
//"<ul><li v-for='element in wert'>{{element}}</li></ul>"
export default {
@@ -15,14 +15,69 @@ export default {
//? this props were passed in the Profil.php view file
props:['uid','pid'],
methods: {
concatenate_addresses(address_array){
let result = "";
for (let i = 0; i < address_array.length; i++) {
result += address_array[i].strasse + " " + address_array[i].plz + " " + address_array[i].ort + "\n";
}
return result;
},
render_unterelement(wert,bezeichnung){
if (isArray(bezeichnung)){
}
},
concatenate_kontakte(kontakt_array){
let result = "";
for (let i = 0; i < kontakt_array.length; i++) {
result += kontakt_array[i].kontakttyp + " " + kontakt_array[i].kontakt + " " + kontakt_array[i].zustellung + "\n";
}
return result;
},
sperre_foto_function(value){
fhcapifactory.UserData.sperre_foto_function(value).then(res => {
console.log(res.data);
if(res.data){
this.person_info.foto_sperre = res.data.foto_sperre;
}
});
},
},
computed:{
computed_placeholder(){
return {
//
get_image_base64_src(){
return "data:image/jpeg;base64,"+this.person_info.foto;
},
first_col(){
//! postnomen is still missing
return {
Username:this.uid,
Anrede:this.person_info.anrede,
Titel:(this.person_info.titelpre&&this.person_info.titelpost)?this.person_info.titelpre.concat(this.person_info.titelpost):"null",
Vorname:this.person_info.vorname,
Nachname:this.person_info.nachname,
Postnomen:null,
Geburtsdatum:this.person_info.gebdatum,
Geburtsort: this.person_info.gebort,
Adresse: this.person_info.adressen,
Kurzzeichen: this.person_info.kurzbz,
Telefon: this.person_info.telefonklappe,
};
},
second_col(){
//! postnomen is still missing
return {
Intern:this.person_info.email_intern,
Alias:this.person_info.email_extern,
Kontakte:this.person_info.kontakte,
};
},
},
created(){
@@ -33,24 +88,55 @@ export default {
},
template: `
<div>
<h1>test</h1>
<p>{{"here is the uid "+uid}} </p>
<p>{{"here is the pid "+pid}} </p>
<!--
//! printing 2 computed functions
//* one to output the collected need information for the cis page
//* and the other returns all the information retrieved from the model without the foto data
<pre style="color:blue">{{JSON.stringify(cis_profil_info,null,2)}}</pre>
<pre style="color:purple">{{JSON.stringify(cis_profil_info_no_foto,null,2)}}</pre>
<br/>
<pre style="color:red">{{JSON.stringify(person)}}</pre>
-->
<p v-for="element in person_info.funktionen"><span v-for="(wert,bezeichnung) in element">{{wert + ": " + bezeichnung}}</span></p>
<p>{{JSON.stringify(first_col)}}</p>
<p>{{"here is the uid "+uid}} </p>
<p>{{"here is the pid "+pid}} </p>
<div :class={'container':true}>
<div :class={'row':true}>
<div :class={'col':true}>
<img :src="get_image_base64_src"></img>
<div v-if="person_info.foto_sperre">
<p style="margin:0">Profilfoto gesperrt</p>
<a href="#" @click.prevent="sperre_foto_function(false)">Sperre des Profilfotos aufheben</a>
</div>
<a href="#" @click.prevent="sperre_foto_function(true)" style="display:block" v-else>Profilfoto sperren</a>
<p>test</p>
</div>
<div :class={'col':true}>
<ol style="list-style:none">
<li v-for="(wert,bezeichnung) in first_col">
<p v-for="element in wert" v-if="typeof wert == 'object' && bezeichnung=='Adresse'">{{element.strasse +" "+element.adr_typ+" " + element.plz+" "+element.ort}}</p>
<p v-else>{{bezeichnung +": " +wert}}</p>
</li>
</ol>
</div>
<div :class={'col':true}>
<ol style="list-style:none">
<!--render_unterelement(wert,bezeichnung)-->
<li v-for="(wert,bezeichnung) in second_col">
<p v-for="element in wert" v-if="typeof wert === 'object' && bezeichnung=='Kontakte'">
{{element.kontakttyp + " " + element.kontakt+" " }}
<i v-if="element.zustellung" class="fa-solid fa-check"></i>
<i v-else="element.zustellung" class="fa-solid fa-xmark"></i>
</p>
<p v-else >{{bezeichnung +": "+wert}}</p>
</li>
</ol>
</div>
</div>
</div>
`,
};