From 478adb740ec2d7e77a0ffd60fcb4ca5b5c8d43db Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 26 Jun 2024 13:21:32 +0200 Subject: [PATCH] changes the db query and adopts the layout of the Vue component to show the correct betreff and content of the news --- .../controllers/api/frontend/v1/Cms.php | 48 +++++++++---------- application/libraries/CmsLib.php | 7 +++ application/models/content/News_model.php | 8 +++- public/js/api/cms.js | 5 +- public/js/components/DashboardWidget/News.js | 32 +++---------- 5 files changed, 45 insertions(+), 55 deletions(-) diff --git a/application/controllers/api/frontend/v1/Cms.php b/application/controllers/api/frontend/v1/Cms.php index 6808d76d8..f6c1ba7bf 100644 --- a/application/controllers/api/frontend/v1/Cms.php +++ b/application/controllers/api/frontend/v1/Cms.php @@ -109,35 +109,33 @@ class Cms extends FHCAPI_Controller public function news() { + $this->load->model('content/news_model', 'NewsModel'); + $limit = $this->input->get('limit',TRUE); - - // return early if the limit parameter is missing or is not greater than 0 - if(!isset($limit) || $limit > 0) - $this->terminateWithError("API parameters are missing", self::ERROR_TYPE_GENERAL); - - $this->load->model('content/news_model', 'NewsModel'); - - $news_content_ids = $this->NewsModel->getNewsContentIDs($limit); - $news_metadata = $this->NewsModel->getAll($limit); - - $this->addMeta("content_ids",$news_content_ids); - $news_content = array(); + // return early if the limit parameter is missing or is not greater than 0 + if(!isset($limit) || $limit < 1) + $this->terminateWithError("API parameters are missing", self::ERROR_TYPE_GENERAL); - if(isError($news_content_ids)) - $this->terminateWithError(getError($news_content_ids), self::ERROR_TYPE_GENERAL); - - if(isError($news_metadata)) - $this->terminateWithError(getError($news_metadata), self::ERROR_TYPE_GENERAL); - - foreach(getData($news_content_ids) as $content_id){ - $news_content[] = $this->fetchContent($content_id->content_id); + //query the news + $news = $this->NewsModel->getAll($limit); + + //get the data or terminate with error + $news = $this->getDataOrTerminateWithError($news); + + // check if any news are there + if($news === NULL){ + $this->terminateWithError("No news content has been found"); } - - $this->terminateWithSuccess(["news_content" =>$news_content, "news_metadata"=>getData($news_metadata)]); - - - + + // collect the content of the news + foreach($news as $news_element){ + $this->addMeta("asdfs",$news_element->content_id); + $news_element->content_obj = $this->fetchContent($news_element->content_id); + } + + $this->terminateWithSuccess($news); + } diff --git a/application/libraries/CmsLib.php b/application/libraries/CmsLib.php index aee6f5c61..9f977ad56 100755 --- a/application/libraries/CmsLib.php +++ b/application/libraries/CmsLib.php @@ -103,6 +103,12 @@ class CmsLib $XML = new DOMDocument(); $XML->loadXML($content->content); + if($content->titel){ + $betreff = $content->titel; + }else{ + $betreff = $XML->getElementsByTagName('betreff'); + } + $xsltemplate = new DOMDocument(); $xsltemplate->loadXML($template->xslt_xhtml_c4); @@ -115,6 +121,7 @@ class CmsLib $transformed_content = str_replace('dms.php', APP_ROOT . 'cms/dms.php', $transformed_content); return success([ + "betreff"=>$betreff, "type"=>$content->template_kurzbz, "content"=>$transformed_content ]); diff --git a/application/models/content/News_model.php b/application/models/content/News_model.php index f8e1fbb66..0700a7057 100755 --- a/application/models/content/News_model.php +++ b/application/models/content/News_model.php @@ -20,8 +20,12 @@ class News_model extends DB_Model public function getAll($limit = null) { $this->addJoin("campus.tbl_content","content_id"); - return $this->loadWhere(' - text IS NOT NULL + return $this->execReadOnlyQuery(' + SELECT * + FROM campus.tbl_news + JOIN campus.tbl_content content ON content.content_id = campus.tbl_news.content_id + WHERE + --text IS NOT NULL AND datum <= NOW() AND (datum_bis IS NULL OR datum_bis >= now()::date) ORDER BY datum DESC LIMIT ' . $this->escape($limit) diff --git a/public/js/api/cms.js b/public/js/api/cms.js index c8ac8dc6f..490023053 100644 --- a/public/js/api/cms.js +++ b/public/js/api/cms.js @@ -11,14 +11,13 @@ export default { } ); }, - news(limit, metadata=false) { + news(limit) { return this.$fhcApi.get( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/api/frontend/v1/Cms/news", { - limit: limit, - metadata: metadata, + limit: limit } ); }, diff --git a/public/js/components/DashboardWidget/News.js b/public/js/components/DashboardWidget/News.js index 2bd778283..01affc4f4 100755 --- a/public/js/components/DashboardWidget/News.js +++ b/public/js/components/DashboardWidget/News.js @@ -28,30 +28,13 @@ export default { } }, created(){ - - this.$fhcApi.factory.cms.news(MAX_LOADED_NEWS,this.width === 1?true:false) + console.log(MAX_LOADED_NEWS,"this are the max news"); + this.$fhcApi.factory.cms.news(MAX_LOADED_NEWS) .then(res => { this.allNewsList = res.data }) .catch(err => { console.error('ERROR: ', err.response.data) }); - + this.$emit('setConfig', false); }, - mounted(){ - - this.$nextTick(() =>{ - - console.log(this.$refs.htmlContent,"this is the html content"); - /* //console.log(this.$refs.htmlContent,"this is the refs content"); - let newsItems = document.getElementsByClassName("news-list"); - console.log(newsItems,"i am printing something"); - for(let item of newsItems){ - //console.log(item,"this is the item"); - item.style.maxHeight = "100px"; - item.style.overflow = "scroll"; - } */ - }); - - - }, methods: { setSingleNews(singleNews){ this.singleNews = singleNews; @@ -70,7 +53,7 @@ export default {
@@ -79,7 +62,7 @@ export default {
-
+
@@ -87,7 +70,7 @@ export default {
-
+
@@ -101,9 +84,8 @@ export default {
-

{{ singleNews.betreff }}
{{ formatDateTime(singleNews.insertamum) }}

+

{{ singleNews?.content_obj?.betreff?singleNews?.content_obj?.betreff:'Kein Betreff vorhanden' }}
{{ formatDateTime(singleNews.insertamum) }}

-