diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 9764b0cae..4221e3837 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -16,10 +16,16 @@ class Profil extends Auth_Controller { parent::__construct([ 'index' => ['student/anrechnung_beantragen:r','user:r'], // TODO(chris): permissions? - 'getUser' => ['student/anrechnung_beantragen:r','user:r'] + 'getUser' => ['student/anrechnung_beantragen:r','user:r'], + 'isMitarbeiterOrStudent' => ['student/anrechnung_beantragen:r','user:r'], + 'getPersonInformation' => ['student/anrechnung_beantragen:r','user:r'], + ]); $this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel'); + $this->load->model('ressource/student_model', 'StudentModel'); $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $this->load->model('person/Person_model', 'PersonModel'); + } // ----------------------------------------------------------------------------------------------------------------- @@ -30,9 +36,11 @@ class Profil extends Auth_Controller */ public function index() { - //echo = getAuthUID(); - $this->load->view('Cis/Profil', ["uid" => getAuthUID()]); + //? we can pass data to the view by using the second parameter of the load->view() function + //* the first parameter is the route that Code Igniter will switch to + //* the second parameter can be used to pass data to the view + $this->load->view('Cis/Profil', ["uid" => getAuthUID(),"pid" => getAuthPersonId()]); } @@ -42,14 +50,36 @@ class Profil extends Auth_Controller //* retrieve info from the Mitarbeiter model $mitarbeiter_result = $this->MitarbeiterModel->load(getAuthUID()); //* retrieve info from the Benutzer model - $benutzer_result = $this->BenutzerModel->load([getAuthUID()]); + $benutzer_result = $this->BenutzerModel->getFromPersonId(getAuthUID()); //* return JSON with info - $res = ['mitarbeiter' => $mitarbeiter_result, - 'Benutzer' => $benutzer_result]; + //! was removed from $res for testing purposes: 'Benutzer' => $benutzer_result + $res = ['mitarbeiter' => $mitarbeiter_result,'Benutzer' => $benutzer_result + ]; echo json_encode($res); } + public function getPersonInformation($pid){ + //? get the person information using the benutzer uid + echo json_encode($this->PersonModel->getPersonStammdaten($pid)->retval); + } + + //? check wheter the parameter uid is a Mitarbeiter or a Student + public function isMitarbeiterOrStudent($uid){ + if($this->MitarbeiterModel->isMitarbeiter($uid)->retval){ + echo json_encode("Mitarbeiter"); + }//! not sure if the user is automatically a student if he is not a mitarbeiter + else if($this->StudentModel->isStudent($uid)->retval){ + echo json_encode("Student"); + }else{ + echo json_encode("Not a Mitarbeiter or Student"); + } + + + } + + + diff --git a/application/models/ressource/Student_model.php b/application/models/ressource/Student_model.php new file mode 100644 index 000000000..937361b56 --- /dev/null +++ b/application/models/ressource/Student_model.php @@ -0,0 +1,41 @@ +dbTable = 'public.tbl_student'; + $this->pk = 'student_uid'; + } + + /** + * Checks if the user is a Student. + * @param string $uid + * @return array + */ + public function isStudent($uid) + { + $this->addSelect('1'); + + + $result = $this->loadWhere(array('student_uid' => $uid)); + + + if(hasData($result)) + { + return success(true); + } + else + { + return success(false); + } + } + + //! THIS FILE WAS CREATED USING THE Mitarbeiter_model.php FILE + + +} diff --git a/application/views/Cis/Profil.php b/application/views/Cis/Profil.php index c8207f0c5..e02d895c3 100644 --- a/application/views/Cis/Profil.php +++ b/application/views/Cis/Profil.php @@ -9,10 +9,11 @@ $this->load->view('templates/CISHTML-Header', $includesArray); ?>
-

Profil

+

Profil2


- + +
load->view('templates/CISHTML-Footer', $includesArray); ?> diff --git a/public/js/apps/Cis/ProfilApp.js b/public/js/apps/Cis/ProfilApp.js index 31abc2ec9..d83e46846 100644 --- a/public/js/apps/Cis/ProfilApp.js +++ b/public/js/apps/Cis/ProfilApp.js @@ -1,8 +1,5 @@ import Profil from "../../components/Cis/Profil/Profil.js"; -import fhcapifactory from "../api/fhcapifactory.js"; - -Vue.$fhcapi = fhcapifactory; const app = Vue.createApp({ components: { @@ -10,18 +7,12 @@ const app = Vue.createApp({ }, data() { return { - stunden: [], - events: null + } }, methods: { - testsearch: function() { - return Vue.$fhcapi.UserData.getUser(); - }, - testsearch2: function() { - return Vue.$fhcapi.UserData.getUser2("ma0594"); - } + }, }); -app.mount('#content'); \ No newline at end of file +app.mount('#content'); \ No newline at end of file diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index 0b5442add..ccd408ae5 100644 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -5,6 +5,17 @@ export default { + 'Cis/Profil/getUser'; return axios.get(url); }, + isMitarbeiterOrStudent: function(uid) { + const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + + `Cis/Profil/isMitarbeiterOrStudent/${uid}`; + return axios.get(url); + }, + getPersonInformation: function(uid) { + const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + + `Cis/Profil/getPersonInformation/${uid}`; + return axios.get(url); + }, + getUser2: function(uid) { const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + 'models/person/Benutzer_model/getFromPersonId'; diff --git a/public/js/components/Cis/Profil/Profil.js b/public/js/components/Cis/Profil/Profil.js index 1a054fc80..f00f6a85e 100644 --- a/public/js/components/Cis/Profil/Profil.js +++ b/public/js/components/Cis/Profil/Profil.js @@ -1,29 +1,50 @@ - +import fhcapifactory from "../../../apps/api/fhcapifactory.js"; export default { data: function() { return { person: null, + person_info: null, + role: null, } }, + //? this prop was passed in the Profil.php view file + props:['uid','pid'], methods: { - testsearch: function() { - - } - }, - created(){ - this.$parent.testsearch().then((res) => { - this.person = res.data; - }); - - }, + }, + computed:{ + cis_profil_info(){ + return { + anrede:this.person_info.anrede, + titelpre:this.person_info.titelpre, + titelpost:this.person_info.titelpost, + vorname:this.person_info.vorname, + nachname:this.person_info.nachname, + gebdatum:this.person_info.gebdatum, + gebort:this.person_info.gebort, + }; + } + }, + created(){ + fhcapifactory.UserData.getUser().then(res => this.person = res.data); + fhcapifactory.UserData.isMitarbeiterOrStudent(this.uid).then(res => this.role = res.data); + fhcapifactory.UserData.getPersonInformation(this.pid).then(res => this.person_info = res.data); + + }, template: `

test

- {{JSON.stringify(person)}} +

{{"here is the uid "+uid}}

+

{{"here is the pid "+pid}}

+ {{JSON.stringify(cis_profil_info)}} + +
+ {{JSON.stringify(person)}} +
+ {{JSON.stringify(role)}}
`, }; \ No newline at end of file