From 2a393f008774b790d9e703b6026bae619c3f793e Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 21 Feb 2024 12:31:41 +0100 Subject: [PATCH] adds the fields gemeinde and nation to the EditAdresse Component and adds autocomplete for the gemeinde if the nation is A --- application/controllers/Cis/Profil.php | 67 ++++++++----------- public/js/apps/api/userdata.js | 7 ++ .../Profil/ProfilComponents/EditAdresse.js | 53 ++++++++------- 3 files changed, 63 insertions(+), 64 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index defb753a7..0591eef60 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -25,6 +25,7 @@ class Profil extends Auth_Controller 'getZustellAdresse' => ['student/anrechnung_beantragen:r', 'user:r'], 'getZustellKontakt' => ['student/anrechnung_beantragen:r', 'user:r'], 'getAllNationen' => ['student/anrechnung_beantragen:r', 'user:r'], + 'getGemeinden' => ['student/anrechnung_beantragen:r', 'user:r'], ]); @@ -366,49 +367,35 @@ class Profil extends Auth_Controller } - //TODO: use the old query check to get the correct values to display for the user in case he selected the nation Austria (A) - /* if($_POST['nation']=='A') - { - if(is_numeric($_POST['plz']) && $_POST['plz']<32000) - { - $qry = "SELECT * FROM bis.tbl_gemeinde WHERE lower(name)=lower(".$db->db_add_param($_POST['gemeinde']).") - AND plz=".$db->db_add_param($_POST['plz']); - if($db->db_query($qry)) - { - if($row = $db->db_fetch_object()) - { - $adresse->gemeinde = $row->name; - } - else - { - $error = true; - $errormsg = 'Gemeinde ist ungueltig'; - $return = false; + + public function getGemeinden(){ + + $nation = $this->input->get('nation',true); + //? json_decode on zip to transform zip from string to integer + $zip = json_decode($this->input->get('zip',true)); + + $this->load->model('codex/Gemeinde_model',"GemeindeModel"); + $this->GemeindeModel->addSelect(["name"]); + if($nation == "A"){ + if(isset($zip) && $zip>999 && $zip <32000){ + + $gemeinde_res = $this->GemeindeModel->loadWhere(['ortschaftskennziffer'=>$zip]); + if(isError($gemeinde_res)){ + show_error("error while trying to query bis.tbl_gemeinde"); } + $gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null; + $gemeinde_res = array_map(function($obj){ + return $obj->name; + },$gemeinde_res); + echo json_encode($gemeinde_res); + + }else{ + echo json_encode(error("ortschaftskennziffer code was not valid")); } - else - { - $error = true; - $errormsg = 'Fehler beim Ermitteln der Gemeinde'; - $return = false; - } + }else{ + echo json_encode(error("Nation was not 'A' (Austria)")); } - else - { - $error = true; - $errormsg = 'Postleitzahl ist fuer diese Nation ungueltig'; - $return = false; - } - } */ - public function getAllGemeinden(){ - $this->load->model('public/Gemeinde_model',"NationModel"); - $this->NationModel->addSelect(["langtext"]); - $nation_res = $this->NationModel->load(); - if(isError($nation_res)){ - show_error("error while trying to query table codex.tbl_nation"); - } - $nation_res = hasData($nation_res) ? getData($nation_res) : null; - echo json_encode($nation_res); + } diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index 1fdc9c661..defea2cbb 100755 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -1,6 +1,13 @@ export default { //! API Calls for Profil Views + getGemeinden: function(nation,zip=null){ + const url = + FHC_JS_DATA_STORAGE_OBJECT.app_root + + `cis.php/Cis/Profil/getGemeinden`; + return axios.get(url,{params:{nation:nation,zip:zip}}); + }, + getAllNationen:function(){ const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + diff --git a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js index e6fb3877f..4ba07c603 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js +++ b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js @@ -9,12 +9,29 @@ export default { inject:["zustellAdresseCount"], data(){ return{ + gemeinden:[], + selectedNation:null, nationenList:[], originalValue:null, zustellAdressenCount:null, } }, methods:{ + + + getGemeinde: function(){ + //? only query the gemeinde is the nation is Austria and the PLZ is greater than 999 and less than 32000 + if(this.data.nation && this.data.nation ==="A" && (this.data.plz && (this.data.plz >999 && this.data.plz <32000))){ + Vue.$fhcapi.UserData.getGemeinden(this.data.nation,this.data.plz).then(res => { + + if(res.data.length){ + this.gemeinden = res.data; + } + }) + }else{ + this.gemeinden = []; + } + }, updateValue: function(event,bind){ //? sets the value of a property to null when an empty string is entered to keep the isChanged function valid if(bind ==="zustelladresse" ){ @@ -38,20 +55,6 @@ export default { } //? if this.zustellAdressenCount is still not set by the api call and is still null return false; - - - }, - ortLayoutClasses: function(){ - return this.showKontaktTyp?[ - 'col-12', - 'col-sm-7', - 'col-xl-12', - 'col-xxl-7', - ]:['col-12']; - }, - showKontaktTyp: function(){ - let kontaktTypen = ["Nebenwohnsitz","Hauptwohnsitz"]; - return kontaktTypen.includes(this.data.typ) || !this.data.typ }, isChanged: function(){ if(!this.data.strasse || !this.data.plz || !this.data.ort || !this.data.typ){ @@ -61,23 +64,23 @@ export default { return this.originalValue !== JSON.stringify(this.data); }, }, + created(){ Vue.$fhcapi.UserData.getAllNationen().then(res => { this.nationenList = res.data; + this.getGemeinde(); }); - //? same for Gemeinde - /* Vue.$fhcapi.UserData.getAllNationen().then(res => { - this.nationenList = res.data; - }); */ + this.originalValue = JSON.stringify(this.data); this.zustellAdressenCount = this.zustellAdresseCount(); }, template:` +
- +
 {{JSON.stringify(gemeinden,null,2)}}
@@ -151,22 +154,24 @@ export default {
PLZ
- +
+
Gemeinde
- - - + + +
nation
-