diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 71f9335a5..b8b6fa685 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -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) { diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index 26897039a..476bf6c36 100755 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -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"); \ No newline at end of file + +profilApp.mount("#content"); diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index a4044ee88..5ed6a4b02 100755 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -251,7 +251,8 @@ export default {
- + +
diff --git a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js index 4ba07c603..d8cfc5e0c 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js +++ b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js @@ -80,7 +80,7 @@ export default { template:`
-
 {{JSON.stringify(gemeinden,null,2)}}
+
diff --git a/public/js/components/Cis/Profil/StudentProfil.js b/public/js/components/Cis/Profil/StudentProfil.js index ad9513655..735007ed5 100755 --- a/public/js/components/Cis/Profil/StudentProfil.js +++ b/public/js/components/Cis/Profil/StudentProfil.js @@ -182,7 +182,7 @@ export default { }, - template: ` + template:/*html*/ `