finishes the documentation in Profil.php controller and refactors getView

This commit is contained in:
SimonGschnell
2024-02-22 11:50:08 +01:00
parent 0b84e1b608
commit 989f1ecf02
5 changed files with 47 additions and 51 deletions
+36 -39
View File
@@ -46,6 +46,7 @@ class Profil extends Auth_Controller
// -----------------------------------------------------------------------------------------------------------------
// Public methods
/**
* index loads the Profil view
@@ -57,16 +58,14 @@ class Profil extends Auth_Controller
$this->load->view('Cis/Profil');
}
/**
* redirects to the index function (needed to allow calling this URI)
* @access public
* @return void
*/
public function View($uid)
{
if ($uid === $this->uid) {
$this->index();
} else {
$this->load->view('Cis/Profil');
}
$this->load->view('Cis/Profil');
}
/**
@@ -135,38 +134,22 @@ class Profil extends Auth_Controller
/**
* function that returns the data used for the corresponding view
* the client side parses the @param $uid and calls this function to get the data to the correct view
* @access public
* @param boolean $uid the userID used to identify which information should be retrieved for which view
* @return stdClass all the information corresponding to a view of a user
* @return stdClass all the data corresponding to a view of a user
*/
public function getView($uid)
{
//TODO: refactor
$uid = $uid != "Profil" ? $uid : null;
$isMitarbeiter = null;
if ($uid) {
if (isSuccess($this->PersonModel->addSelect(["person_id"]))) {
$pid = $this->PersonModel->getByUid($uid);
$pid = hasData($pid) ? getData($pid)[0] : null;
}
if (!$pid) {
//! if no Person_ID was found, null is returned and the vue component will show a 404 View
return null;
}
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid);
} else
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($this->uid);
if (isError($isMitarbeiter)) {
//catch error
}
$isMitarbeiter = hasData($isMitarbeiter) ? getData($isMitarbeiter) : null;
$res = new stdClass();
if ($uid == $this->uid || !$uid) {
// if the $uid is empty, then no payload was supplied and the own profile is being requested
// if parsing the URL did not found a UID then the UID of the logged in user is used
if($uid =="Profil" || $uid == $this->uid){
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($this->uid);
if (isError($isMitarbeiter)) {
show_error("error while checking if UID: ".$this->uid." is a mitarbeiter");
}
$isMitarbeiter = getData($isMitarbeiter);
if ($isMitarbeiter) {
$res->view = "MitarbeiterProfil";
$res->data = $this->mitarbeiterProfil();
@@ -176,8 +159,23 @@ class Profil extends Auth_Controller
$res->data = $this->studentProfil();
$res->data->pid = $this->pid;
}
} elseif ($uid) {
// if an $uid was passed as payload to the function then the user is trying to view another profile
}
// UID is availabe when accessing Profil/View/:uid
else{
$this->PersonModel->addSelect(["person_id"]);
$pid = $this->PersonModel->getByUid($uid);
if(isError($pid)){
show_error("error while trying to update table public.tbl_person while searching for a person with UID: ".$uid);
}
$pid = hasData($pid) ? getData($pid)[0] : null;
if(!$pid){
show_error("Person with UID: ".$uid." does not exist");
}
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid);
if (isError($isMitarbeiter)) {
show_error("error while checking if UID: ".$uid." is a mitarbeiter");
}
$isMitarbeiter = getData($isMitarbeiter);
if ($isMitarbeiter) {
$res->view = "ViewMitarbeiterProfil";
$res->data = $this->viewMitarbeiterProfil($uid);
@@ -185,11 +183,9 @@ class Profil extends Auth_Controller
} else {
$res->view = "ViewStudentProfil";
$res->data = $this->viewStudentProfil($uid);
}
}
echo json_encode($res);
}
/**
@@ -245,7 +241,8 @@ class Profil extends Auth_Controller
$zip = json_decode($this->input->get('zip', true));
$this->load->model('codex/Gemeinde_model', "GemeindeModel");
$this->GemeindeModel->addSelect(["DISTINCT name"]);
$this->GemeindeModel->addDistinct();
$this->GemeindeModel->addSelect(["name"]);
if ($nation == "A") {
if (isset($zip) && $zip > 999 && $zip < 32000) {
+7 -9
View File
@@ -1,4 +1,3 @@
//import ProfilView from "../../components/Cis/Profil/Profil.js";
import StudentProfil from "../../components/Cis/Profil/StudentProfil.js";
import MitarbeiterProfil from "../../components/Cis/Profil/MitarbeiterProfil.js";
import ViewStudentProfil from "../../components/Cis/Profil/StudentViewProfil.js";
@@ -6,7 +5,6 @@ import ViewMitarbeiterProfil from "../../components/Cis/Profil/MitarbeiterViewPr
import fhcapifactory from "../api/fhcapifactory.js";
import Loading from "../../components/Loader.js";
Vue.$fhcapi = fhcapifactory;
Vue.$collapseFormatter = function(data){
//data - an array of objects containing the column title and value for each cell
@@ -38,7 +36,7 @@ Vue.$collapseFormatter = function(data){
const testapp = Vue.createApp({
const profilApp = Vue.createApp({
components: {
StudentProfil,
@@ -214,7 +212,7 @@ const testapp = Vue.createApp({
},
Private_Kontakte: {
title:"Private Kontakte" ,
data:this.data.kontakte.filter(item => {
data:this.data.kontakte?.filter(item => {
return !this.data.profilUpdates?.some((update) => update.status ==='pending' && update.requested_change?.kontakt_id === item.kontakt_id);
}).map(kontakt => {
return {
@@ -225,7 +223,7 @@ const testapp = Vue.createApp({
},
Private_Adressen: {
title: "Private Adressen",
data:this.data.adressen.filter(item => {
data:this.data.adressen?.filter(item => {
return !this.data.profilUpdates?.some(update => {
return update.status ==='pending' && update.requested_change?.adresse_id == item.adresse_id;
})
@@ -254,10 +252,9 @@ const testapp = Vue.createApp({
created(){
let path = location.pathname;
//? uid contains the last part of the uri
let uid = location.pathname.split('/').pop();
let uid = path.substring(path.lastIndexOf('/')).replace("/","");
Vue.$fhcapi.UserData.getView(uid).then((res)=>{
if(!res.data){
this.notFoundUID=uid;
@@ -286,4 +283,5 @@ const testapp = Vue.createApp({
});
testapp.mount("#content");
profilApp.mount("#content");
@@ -251,7 +251,8 @@ export default {
<div class="row mb-3">
<div class="col">
<!-- MOBILE QUICK LINKS -->
<!-- MOBILE QUICK LINKS -->
<quick-links :mobile="true"></quick-links>
</div>
</div>
@@ -80,7 +80,7 @@ export default {
template:`
<div class="gy-3 row justify-content-center align-items-center">
<pre> {{JSON.stringify(gemeinden,null,2)}}</pre>
<!-- warning message for too many zustellungs Adressen -->
<div v-if="showZustellAdressenWarning" class="col-12 ">
@@ -182,7 +182,7 @@ export default {
},
template: `
template:/*html*/ `
<div class="container-fluid text-break fhc-form" >
<!-- ROW -->