diff --git a/application/controllers/api/frontend/v1/Cms.php b/application/controllers/api/frontend/v1/Cms.php index 8b0e21afb..4b5ca5334 100644 --- a/application/controllers/api/frontend/v1/Cms.php +++ b/application/controllers/api/frontend/v1/Cms.php @@ -184,7 +184,7 @@ class Cms extends FHCAPI_Controller } - public function getNews($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true, $maxalter = 0) + public function getNews($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true, $maxAlter = 0) { //form validation $this->load->library('form_validation'); @@ -211,7 +211,7 @@ class Cms extends FHCAPI_Controller $maxAlter = intval($passedInMaxAlter); } - $news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $page_size, $sprache, $maxalter); + $news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $page_size, $sprache, $maxAlter); $news = $this->getDataOrTerminateWithError($news); $this->addMeta('phrases', json_decode($this->p->getJson())); diff --git a/application/models/content/News_model.php b/application/models/content/News_model.php index 6b224168a..1c2b40c0c 100644 --- a/application/models/content/News_model.php +++ b/application/models/content/News_model.php @@ -21,9 +21,9 @@ class News_model extends DB_Model { $this->addJoin("campus.tbl_content","content_id"); - $maxAlterQueryFilter = "datum_bis >= NOW()::date"; + $maxAlterQueryFilter = null; if ($maxAlter !== 0) { - $maxAlterQueryFilter .= " OR datum_bis IS NULL AND (NOW()-datum) < interval '" . $this->escape($maxAlter) . " days'"; + $maxAlterQueryFilter .= " (NOW()-datum) < interval '" . $this->escape($maxAlter) . " days'"; } return $this->execReadOnlyQuery(' @@ -32,7 +32,7 @@ class News_model extends DB_Model JOIN campus.tbl_content content ON content.content_id = campus.tbl_news.content_id WHERE --text IS NOT NULL AND - datum <= NOW() AND (' . $maxAlterQueryFilter . ') + datum <= NOW() AND (datum_bis >= NOW()::date OR datum_bis IS NULL)' . ($maxAlterQueryFilter ? ' AND ' . $maxAlterQueryFilter : '') . ' ORDER BY datum DESC LIMIT ' . $this->escape($limit) , ['DD/MM/YYYY']); @@ -72,15 +72,16 @@ class News_model extends DB_Model $fachbereich_kurzbz = trim($fachbereich_kurzbz); $where = []; + + if (!$all) { + $where[] = "datum <= NOW() AND (datum_bis >= NOW()::date OR datum_bis IS NULL)"; + } if ($maxalter !== 0 && is_numeric($maxalter)) { $maxalter = (int)$maxalter; - $where[] = "(now()-datum) < interval '" . $this->db->escape($maxalter) . " days'"; + $where[] = "(NOW()-datum) < interval '" . $this->escape($maxalter) . " days'"; } - if (!$all) { - $where[] = "datum <= now()"; - $where[] = "(datum_bis >= now()::date OR datum_bis IS NULL)"; - } + if ($fachbereich_kurzbz != '*') { if ($fachbereich_kurzbz == '') { $where[] = "fachbereich_kurzbz IS NULL";