update(News DashboardWidget): updates how to betreff is queried from the XML

This commit is contained in:
SimonGschnell
2025-01-21 14:20:40 +01:00
parent 381b6a75db
commit d72bc4fa44
3 changed files with 43 additions and 24 deletions
+21 -11
View File
@@ -124,25 +124,35 @@ class Cms extends FHCAPI_Controller
//get the data or terminate with error
$news = $this->getDataOrTerminateWithError($news);
// array that keeps track of which news don't have a betreff and have to be removed from the news array
$newsToRemove = array();
// collect the content of the news
foreach($news as $news_element){
$this->addMeta("content_id",$news_element->content_id);
foreach($news as $index=>$news_element){
//todo: quick fix, for query builder error when fetching content
$this->NewsModel->resetQuery();
$content = $this->cmslib->getContent($news_element->content_id);
$content = getData($content);
$news_element->content_obj = $content;
if(isError($content))
{
// removes the news from the news array, so that the response does not include a invalid news
array_push($newsToRemove,$index);
//add the error to the api response? visual feedback
//$this->addError(print_r($content->retval,true));
continue;
}
$content = getData($content);
$news_element->content_obj = $content;
}
//removes all news that don't have a betreff
foreach($newsToRemove as $removeNewsIndex)
{
unset($news[$removeNewsIndex]);
}
$withContent = function($news) {
return $news->content_obj != null;
};
};
$newsWithContent = array_filter($news, $withContent);
$this->terminateWithSuccess($newsWithContent);
}
+13 -1
View File
@@ -43,7 +43,7 @@ class CmsLib
* @param string $sprache
* @param boolean $sichtbar
*
* @return void
* @return stdClass
*/
public function getContent($content_id, $version = null, $sprache = null, $sichtbar = true)
{
@@ -105,7 +105,19 @@ class CmsLib
if($content->titel){
$betreff = $content->titel;
}else{
//DomDocument getElementsByTagName returns a DomNodeList
$betreff = $XML->getElementsByTagName('betreff');
//check if any betreff was found and if it is not empty
if($betreff->length > 0 && !empty($betreff->item(0)->nodeValue))
{
//DomNodeList item() return a DomNode, property nodeValue contains the value of the node
$betreff = $betreff->item(0)->nodeValue;
}
else
{
return error('no betreff found for the content');
}
}
$xsltemplate = new DOMDocument();
+9 -12
View File
@@ -178,19 +178,16 @@ export default {
<div v-else class="row h-100 g-0">
<div :class="'col-'+(width == 2? 6 : 4) + ' h-100 g-0'" style="overflow: auto;">
<template v-for="news in newsList" :key="'menu-'+news.news_id">
<template v-if="isString(news.content_obj.betreff)">
<div class="row fhc-news-menu-item" @click="setSelected(news)" :class="getMenuItemClass(news)" style="margin-right: 0px; margin-left: 0px; overflow-y: hidden;">
<div class="col-8 fhc-news-menu-item-betreff">
<p>
{{news.content_obj.betreff ?? ''}}
</p>
</div>
<span class="fhc-news-menu-item-date fw-bold">
{{ news.datumformatted ?? ''}}
</span>
<div class="row fhc-news-menu-item" @click="setSelected(news)" :class="getMenuItemClass(news)" style="margin-right: 0px; margin-left: 0px; overflow-y: hidden;">
<div class="col-8 fhc-news-menu-item-betreff">
<p >
{{news.content_obj.betreff ?? ''}}
</p>
</div>
</template>
<span class="fhc-news-menu-item-date fw-bold">
{{ news.datumformatted ?? ''}}
</span>
</div>
</template>
</div>
<div :class="'col-'+(width == 2? 6 : 8) + ' h-100'" style="padding-left: 0px; padding-right: 0px;" ref="htmlContent">