mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
refactors the news controller
This commit is contained in:
@@ -112,46 +112,4 @@ class Cms extends Auth_Controller
|
||||
{
|
||||
$this->load->view('CisHtml/Cms/Content', ['infoscreen' => $infoscreen, 'studiengang_kz' => $studiengang_kz, 'semester' => $semester, 'mischen' => $mischen, 'titel' => $titel, 'edit' => $edit, 'sichtbar' => $sichtbar, "template_kurzbz"=>"news"]);
|
||||
}
|
||||
|
||||
public function getNews($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true)
|
||||
{
|
||||
$get_page = intval($this->input->get('page', true));
|
||||
$get_page_size = intval($this->input->get('page_size', true));
|
||||
if ($get_page) {
|
||||
$page = $get_page;
|
||||
}
|
||||
if ($get_page_size) {
|
||||
$page_size = $get_page_size;
|
||||
} else {
|
||||
$page_size = $this->page_size;
|
||||
}
|
||||
$news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $page_size);
|
||||
|
||||
if (isError($news)) {
|
||||
$this->terminateWithJsonError(getError($news));
|
||||
}
|
||||
$news = hasData($news) ? getData($news) : null;
|
||||
if ($news) {
|
||||
echo json_encode($news);
|
||||
} else {
|
||||
show_error("News: No data found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getNewsRowCount($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $fachbereich_kurzbz = null, $maxalter = 0, $edit = false, $sichtbar = true, $page = 1, $page_size = 10)
|
||||
{
|
||||
list($studiengang_kz, $semester) = $this->cmslib->getStgAndSem($studiengang_kz, $semester);
|
||||
$all = $edit;
|
||||
$num_rows = $this->NewsModel->countNewsWithContent(getSprache(), $studiengang_kz, $semester, $fachbereich_kurzbz, $sichtbar, $maxalter, $page, $this->page_size, $all, $mischen);
|
||||
if (isError($num_rows)) {
|
||||
$this->terminateWithJsonError(getError($num_rows));
|
||||
}
|
||||
$num_rows = hasData($num_rows) ? getData($num_rows) : null;
|
||||
if ($num_rows) {
|
||||
echo json_encode($num_rows);
|
||||
} else {
|
||||
show_error("News number rows: No data found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,6 @@ class Cms extends FHC_Controller
|
||||
'global'
|
||||
]);
|
||||
|
||||
$this->load->model('content/News_model', 'NewsModel');
|
||||
|
||||
// setting up the papgination_size
|
||||
$this->page_size = 10;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
@@ -78,45 +74,4 @@ class Cms extends FHC_Controller
|
||||
$this->load->view('CisHtml/Cms/Content', ['infoscreen' => $infoscreen, 'studiengang_kz' => $studiengang_kz, 'semester' => $semester, 'mischen' => $mischen, 'titel' => $titel, 'edit' => $edit, 'sichtbar' => $sichtbar, "template_kurzbz"=>"news"]);
|
||||
}
|
||||
|
||||
public function getNews($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true)
|
||||
{
|
||||
$get_page = intval($this->input->get('page', true));
|
||||
$get_page_size = intval($this->input->get('page_size', true));
|
||||
if ($get_page) {
|
||||
$page = $get_page;
|
||||
}
|
||||
if ($get_page_size) {
|
||||
$page_size = $get_page_size;
|
||||
} else {
|
||||
$page_size = $this->page_size;
|
||||
}
|
||||
$news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $page_size);
|
||||
|
||||
if (isError($news)) {
|
||||
$this->terminateWithJsonError(getError($news));
|
||||
}
|
||||
$news = hasData($news) ? getData($news) : null;
|
||||
if ($news) {
|
||||
echo json_encode($news);
|
||||
} else {
|
||||
show_error("News: No data found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getNewsRowCount($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $fachbereich_kurzbz = null, $maxalter = 0, $edit = false, $sichtbar = true, $page = 1, $page_size = 10)
|
||||
{
|
||||
list($studiengang_kz, $semester) = $this->cmslib->getStgAndSem($studiengang_kz, $semester);
|
||||
$all = $edit;
|
||||
$num_rows = $this->NewsModel->countNewsWithContent(getSprache(), $studiengang_kz, $semester, $fachbereich_kurzbz, $sichtbar, $maxalter, $page, $this->page_size, $all, $mischen);
|
||||
if (isError($num_rows)) {
|
||||
$this->terminateWithJsonError(getError($num_rows));
|
||||
}
|
||||
$num_rows = hasData($num_rows) ? getData($num_rows) : null;
|
||||
if ($num_rows) {
|
||||
echo json_encode($num_rows);
|
||||
} else {
|
||||
show_error("News number rows: No data found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ class Cms extends FHC_Controller
|
||||
'global'
|
||||
]);
|
||||
|
||||
$this->load->model('content/Content_model', 'ContentModel');
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
@@ -42,35 +40,15 @@ class Cms extends FHC_Controller
|
||||
*/
|
||||
public function content($content_id, $version = null, $sprache = null, $sichtbar = true)
|
||||
{
|
||||
// return early if the content_id for the content is missing
|
||||
if(!isset($content_id))
|
||||
$this->terminateWithError("content_id is missing");
|
||||
|
||||
$content = $this->ContentModel->load($content_id);
|
||||
if (isError($content))
|
||||
$this->terminateWithError(getError($content));
|
||||
|
||||
$content = getData($content);
|
||||
|
||||
if(NULL === $content)
|
||||
$this->terminateWithError("Content not found");
|
||||
|
||||
$content = $this->getDataOrTerminateWithError($content);
|
||||
|
||||
$content = current($content);
|
||||
|
||||
$this->load->view('CisVue/Cms/Content', ['content_id' => $content_id, 'template_kurzbz'=>$content->template_kurzbz , 'version' => $version, 'sprache' => $sprache, 'sichtbar' => $sichtbar]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $infoscreen
|
||||
* @param string | null $studiengang_kz
|
||||
* @param int | null $semester
|
||||
* @param boolean $mischen
|
||||
* @param string $titel
|
||||
* @param boolean $edit
|
||||
* @param boolean $sichtbar
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* @param boolean $infoscreen
|
||||
* @param string | null $studiengang_kz
|
||||
@@ -87,45 +65,4 @@ class Cms extends FHC_Controller
|
||||
$this->load->view('CisHtml/Cms/Content', ['infoscreen' => $infoscreen, 'studiengang_kz' => $studiengang_kz, 'semester' => $semester, 'mischen' => $mischen, 'titel' => $titel, 'edit' => $edit, 'sichtbar' => $sichtbar, "template_kurzbz"=>"news"]);
|
||||
}
|
||||
|
||||
public function getNews($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true)
|
||||
{
|
||||
$get_page = intval($this->input->get('page', true));
|
||||
$get_page_size = intval($this->input->get('page_size', true));
|
||||
if ($get_page) {
|
||||
$page = $get_page;
|
||||
}
|
||||
if ($get_page_size) {
|
||||
$page_size = $get_page_size;
|
||||
} else {
|
||||
$page_size = $this->page_size;
|
||||
}
|
||||
$news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $page_size);
|
||||
|
||||
if (isError($news)) {
|
||||
$this->terminateWithJsonError(getError($news));
|
||||
}
|
||||
$news = hasData($news) ? getData($news) : null;
|
||||
if ($news) {
|
||||
echo json_encode($news);
|
||||
} else {
|
||||
show_error("News: No data found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getNewsRowCount($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $fachbereich_kurzbz = null, $maxalter = 0, $edit = false, $sichtbar = true, $page = 1, $page_size = 10)
|
||||
{
|
||||
list($studiengang_kz, $semester) = $this->cmslib->getStgAndSem($studiengang_kz, $semester);
|
||||
$all = $edit;
|
||||
$num_rows = $this->NewsModel->countNewsWithContent(getSprache(), $studiengang_kz, $semester, $fachbereich_kurzbz, $sichtbar, $maxalter, $page, $this->page_size, $all, $mischen);
|
||||
if (isError($num_rows)) {
|
||||
$this->terminateWithJsonError(getError($num_rows));
|
||||
}
|
||||
$num_rows = hasData($num_rows) ? getData($num_rows) : null;
|
||||
if ($num_rows) {
|
||||
echo json_encode($num_rows);
|
||||
} else {
|
||||
show_error("News number rows: No data found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,16 @@ class Cms extends FHCAPI_Controller
|
||||
'getOrtKurzbzContent' => self::PERM_LOGGED,
|
||||
'content' => self::PERM_LOGGED,
|
||||
'news' => self::PERM_LOGGED,
|
||||
'getNewsRowCount' => self::PERM_LOGGED,
|
||||
'getNews' => self::PERM_LOGGED,
|
||||
|
||||
]);
|
||||
|
||||
$this->load->model('content/News_model', 'NewsModel');
|
||||
|
||||
// setting up the papgination_size
|
||||
$this->page_size = 10;
|
||||
|
||||
$this->load->library('CmsLib');
|
||||
|
||||
}
|
||||
@@ -46,19 +54,6 @@ class Cms extends FHCAPI_Controller
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
private function fetchContent($content_id){
|
||||
$content = $this->cmslib->getContent($content_id);
|
||||
|
||||
if (isError($content)){
|
||||
$this->terminateWithError(getError($content), self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
|
||||
if(getData($content)){
|
||||
return getData($content);
|
||||
}else{
|
||||
$this->terminateWithError("No content was found", self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
@@ -68,17 +63,21 @@ class Cms extends FHCAPI_Controller
|
||||
*/
|
||||
public function content()
|
||||
{
|
||||
// getting the get parameters
|
||||
// form validation
|
||||
$this->load->library('form_validation');
|
||||
$this->form_validation->set_data($_GET);
|
||||
$this->form_validation->set_rules('content_id','Content ID','required|is_natural');
|
||||
if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
// getting the get parameters
|
||||
$content_id = $this->input->get("content_id",TRUE);
|
||||
$version = $this->input->get("version",TRUE);
|
||||
$sprache = $this->input->get("sprache",TRUE);
|
||||
$sichtbar = $this->input->get("sichtbar",TRUE);
|
||||
|
||||
// return early if the content_id is missing
|
||||
if(!isset($content_id))
|
||||
$this->terminateWithError("content_id is missing", self::ERROR_TYPE_GENERAL);
|
||||
$content = $this->cmslib->getContent($content_id);
|
||||
|
||||
$content = $this->fetchContent($content_id);
|
||||
$content = $this->getDataOrTerminateWithError($content);
|
||||
|
||||
$this->terminateWithSuccess($content);
|
||||
}
|
||||
@@ -88,57 +87,95 @@ class Cms extends FHCAPI_Controller
|
||||
*/
|
||||
public function ContentID()
|
||||
{
|
||||
// if error
|
||||
//$this->terminateWithError(SearchBarLib::ERROR_WRONG_JSON, self::ERROR_TYPE_GENERAL);
|
||||
|
||||
// form validation
|
||||
$this->load->library('form_validation');
|
||||
$this->form_validation->set_data($_GET);
|
||||
$this->form_validation->set_rules('ort_kurzbz', 'Ort', 'required');
|
||||
if ($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
$ort_kurzbz = $this->input->get('ort_kurzbz',TRUE);
|
||||
|
||||
if(!$ort_kurzbz){
|
||||
$this->terminateWithError("missing ort_kurzbz parameter", self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
$content_id = $this->OrtModel->getContentID($ort_kurzbz);
|
||||
|
||||
$result = $this->OrtModel->getContentID($ort_kurzbz);
|
||||
$content_id = current($this->getDataOrTerminateWithError($content_id))->content_id;
|
||||
|
||||
if(isError($result)){
|
||||
$this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
|
||||
$result = hasData($result) ? current(getData($result)) : null;
|
||||
|
||||
$this->terminateWithSuccess($result->content_id ?? NULL);
|
||||
$this->terminateWithSuccess($content_id);
|
||||
}
|
||||
|
||||
//todo: there is the method news and getNews but only one should exist
|
||||
public function news()
|
||||
{
|
||||
// form validation
|
||||
$this->load->library('form_validation');
|
||||
$this->form_validation->set_data($_GET);
|
||||
$this->form_validation->set_rules('limit','Limit','required|is_natural_no_zero');
|
||||
if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
$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 < 1)
|
||||
$this->terminateWithError("API parameters are missing", self::ERROR_TYPE_GENERAL);
|
||||
|
||||
//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");
|
||||
}
|
||||
|
||||
// collect the content of the news
|
||||
foreach($news as $news_element){
|
||||
$this->addMeta("content_id",$news_element->content_id);
|
||||
$news_element->content_obj = $this->fetchContent($news_element->content_id);
|
||||
|
||||
$content = $this->cmslib->getContent($news_element->content_id);
|
||||
|
||||
$content = $this->getDataOrTerminateWithError($content);
|
||||
|
||||
$news_element->content_obj = $content;
|
||||
}
|
||||
|
||||
$this->terminateWithSuccess($news);
|
||||
|
||||
}
|
||||
|
||||
public function getNewsRowCount($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $fachbereich_kurzbz = null, $maxalter = 0, $edit = false, $sichtbar = true, $page = 1, $page_size = 10)
|
||||
{
|
||||
list($studiengang_kz, $semester) = $this->cmslib->getStgAndSem($studiengang_kz, $semester);
|
||||
$all = $edit;
|
||||
|
||||
$this->load->model('content/News_model','NewsModel');
|
||||
|
||||
$num_rows = $this->NewsModel->countNewsWithContent(getSprache(), $studiengang_kz, $semester, $fachbereich_kurzbz, $sichtbar, $maxalter, $page, $page_size, $all, $mischen);
|
||||
|
||||
$num_rows = $this->getDataOrTerminateWithError($num_rows);
|
||||
|
||||
$this->terminateWithSuccess($num_rows);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getNews($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true)
|
||||
{
|
||||
//form validation
|
||||
$this->load->library('form_validation');
|
||||
$this->form_validation->set_data($_GET);
|
||||
$this->form_validation->set_rules('page','Page','required|is_natural');
|
||||
$this->form_validation->set_rules('page_size', 'PageSize', 'is_natural');
|
||||
if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
// getting the GET parameters
|
||||
$page = intval($this->input->get('page', true));
|
||||
$page_size = intval($this->input->get('page_size', true));
|
||||
|
||||
// default value for the page_size is 10
|
||||
$page_size = $page_size ?? 10;
|
||||
|
||||
$news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $page_size);
|
||||
|
||||
$news = $this->getDataOrTerminateWithError($news);
|
||||
|
||||
$this->terminateWithSuccess($news);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ switch($template_kurzbz){
|
||||
break;
|
||||
}
|
||||
|
||||
$this->load->view('templates/CISVUE-Header', $includesArray);
|
||||
$this->load->view('templates/CISHTML-Header', $includesArray);
|
||||
?>
|
||||
|
||||
<h2><?php echo isset($content_id)? "Content" : "News" ?></h2>
|
||||
@@ -24,5 +24,5 @@ $this->load->view('templates/CISVUE-Header', $includesArray);
|
||||
|
||||
</div>
|
||||
|
||||
<?php $this->load->view('templates/CISVUE-Footer', $includesArray); ?>
|
||||
<?php $this->load->view('templates/CISHTML-Footer', $includesArray); ?>
|
||||
|
||||
|
||||
+32
-17
@@ -1,25 +1,40 @@
|
||||
export default {
|
||||
content(content_id, version=null, sprache=null, sichtbar=null) {
|
||||
return this.$fhcApi.get(
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
"/api/frontend/v1/Cms/content",
|
||||
{ content_id: content_id,
|
||||
...(version?{version}:{}),
|
||||
...(sprache?{sprache}:{}),
|
||||
...(sichtbar?{sichtbar}:{}),
|
||||
}
|
||||
);
|
||||
},
|
||||
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
|
||||
"/api/frontend/v1/Cms/content",
|
||||
{
|
||||
content_id: content_id,
|
||||
...(version?{version}:{}),
|
||||
...(sprache?{sprache}:{}),
|
||||
...(sichtbar?{sichtbar}:{}),
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
news(limit) {
|
||||
return this.$fhcApi.get(
|
||||
"/api/frontend/v1/Cms/news",
|
||||
{
|
||||
limit: limit
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
getNews(page = 1, page_size = 10) {
|
||||
return this.$fhcApi.get(
|
||||
"/api/frontend/v1/Cms/getNews",
|
||||
{
|
||||
page,
|
||||
page_size,
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
getNewsRowCount: function () {
|
||||
return this.$fhcApi.get(
|
||||
"/api/frontend/v1/Cms/getNewsRowCount",
|
||||
{}
|
||||
);
|
||||
},
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import BsConfirm from "../../components/Bootstrap/Confirm.js";
|
||||
//import Pagination from "../../components/Pagination/Pagination.js";
|
||||
import CmsNews from "../../components/Cis/Cms/News.js";
|
||||
import CmsContent from "../../components/Cis/Cms/Content.js";
|
||||
import Fhcapi from "../../plugin/FhcApi.js";
|
||||
import Phrasen from "../../plugin/Phrasen.js";
|
||||
|
||||
|
||||
const app = Vue.createApp({
|
||||
@@ -35,6 +35,6 @@ const app = Vue.createApp({
|
||||
},
|
||||
});
|
||||
app.use(primevue.config.default, { zIndex: { overlay: 9999 } });
|
||||
app.use(Fhcapi);
|
||||
app.use(Phrasen);
|
||||
app.mount("#cms");
|
||||
//#cms [data-confirm], #cms [data-href]
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
export default {
|
||||
getNews: function (page = 1, page_size = 10) {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
"/CisHtml/Cms/getNews";
|
||||
return axios.get(url, {
|
||||
params: {
|
||||
page,
|
||||
page_size,
|
||||
},
|
||||
});
|
||||
},
|
||||
getNewsRowCount: function () {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
"/CisHtml/Cms/getNewsRowCount";
|
||||
return axios.get(url);
|
||||
},
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
import Search from "./search.js";
|
||||
import Cms from "./cms.js";
|
||||
|
||||
export default {
|
||||
"Search": Search,
|
||||
"Cms": Cms,
|
||||
};
|
||||
|
||||
@@ -13,18 +13,25 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
loadNewPageContent: function (data) {
|
||||
Vue.$fhcapi.Cms.getNews(data.page, data.rows).then((result) => {
|
||||
this.content = result.data;
|
||||
});
|
||||
this.$fhcApi.factory.cms.getNews(data.page, data.rows)
|
||||
.then(res => res.data)
|
||||
.then(result => {
|
||||
this.content = result;
|
||||
});
|
||||
|
||||
},
|
||||
},
|
||||
created() {
|
||||
Vue.$fhcapi.Cms.getNews(1, this.page_size).then((result) => {
|
||||
this.content = result.data;
|
||||
});
|
||||
this.$fhcApi.factory.cms.getNews(1, this.page_size)
|
||||
.then(res => res.data)
|
||||
.then(result => {
|
||||
this.content = result;
|
||||
});
|
||||
|
||||
Vue.$fhcapi.Cms.getNewsRowCount().then((result) => {
|
||||
this.maxPageCount = result.data;
|
||||
this.$fhcApi.factory.cms.getNewsRowCount()
|
||||
.then(res => res.data)
|
||||
.then(result => {
|
||||
this.maxPageCount = result;
|
||||
});
|
||||
},
|
||||
template: /*html*/ `
|
||||
|
||||
Reference in New Issue
Block a user