From 8f07bd6b4dab33c0f1669032eb7d8b1739b27126 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 12 Dec 2024 14:46:32 +0100 Subject: [PATCH] update(Sprachen.js): shows the sprachen in the component always using their bezeichnung --- .../controllers/api/frontend/v1/Phrasen.php | 15 +++++++++++++-- public/js/components/Cis/Sprachen.js | 10 ++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/application/controllers/api/frontend/v1/Phrasen.php b/application/controllers/api/frontend/v1/Phrasen.php index 3509e6630..7cc652c71 100644 --- a/application/controllers/api/frontend/v1/Phrasen.php +++ b/application/controllers/api/frontend/v1/Phrasen.php @@ -73,11 +73,22 @@ class Phrasen extends FHCAPI_Controller // gets all languages that are set as active in the database public function getAllLanguages() { - $langs = getDBActiveLanguages(); + $this->load->model('system/Sprache_model', 'SprachenModel'); + + // Add order clause by index and select the sprache,bezeichnung and index column + $this->SprachenModel->addOrder('index'); + $this->SprachenModel->addSelect('sprache, bezeichnung, index'); + + // Retrieves from public.tbl_sprache + $langs = $this->SprachenModel->loadWhere(array('content' => true)); $langs = $this->getDataOrTerminateWithError($langs); $langs = array_map(function($lang){ - return $lang->sprache; + $data = new stdClass(); + $data->sprache = $lang->sprache; + $data->bezeichnung = $lang->bezeichnung[($lang->index-1)]; + return $data; }, $langs); + $this->terminateWithSuccess($langs); } diff --git a/public/js/components/Cis/Sprachen.js b/public/js/components/Cis/Sprachen.js index bd63b9741..72768e9f2 100644 --- a/public/js/components/Cis/Sprachen.js +++ b/public/js/components/Cis/Sprachen.js @@ -2,6 +2,7 @@ export default { data(){ return { allActiveLanguages: null, + sprachenTranslation:null, } }, methods:{ @@ -11,20 +12,25 @@ export default { this.$p.setLanguage(lang, this.$fhcApi); } }, + getSprachenBezeichnung: function(lang){ + if (!Array.isArray(this.sprachenTranslation) || this.sprachenTranslation.length == 0) return; + return this.sprachenTranslation.find(s=>s.sprache == lang)?.bezeichnung; + }, }, mounted(){ this.$fhcApi.factory.phrasen.getActiveDbLanguages() .then(res => res.data) .then( (langs) => { - this.allActiveLanguages = langs; + this.allActiveLanguages = langs.map(l=>l.sprache); + this.sprachenTranslation = langs; } ); }, template:/*html*/`
- +
`,