Stundenplan
-
diff --git a/application/controllers/CisHmvc/Cms.php b/application/controllers/CisHmvc/Cms.php index eed1a5fea..fad3366d4 100755 --- a/application/controllers/CisHmvc/Cms.php +++ b/application/controllers/CisHmvc/Cms.php @@ -69,12 +69,21 @@ class Cms extends Auth_Controller */ public function content($content_id, $version = null, $sprache = null, $sichtbar = true) { - $content = $this->cmslib->getContent($content_id, $version, $sprache, $sichtbar); + // 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)) - return $this->load->view('CisHmvc/Error', ['error' => getError($content)]); + $this->terminateWithError(getError($content)); - $this->load->view('CisHmvc/Cms/Content', ['content' => getData($content)]); + $content = getData($content); + if(NULL === $content) + $this->terminateWithError("Content not found"); + + $content = current($content); + + $this->load->view('CisVue/Cms/Content', ['content_id' => $content_id, 'template_kurzbz'=>$content->template_kurzbz , 'version' => $version, 'sprache' => $sprache, 'sichtbar' => $sichtbar]); } /** @@ -101,48 +110,6 @@ class Cms extends Auth_Controller */ public function news($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true) { - $this->load->view('CisHtml/Cms/Content', ['infoscreen' => $infoscreen, 'studiengang_kz' => $studiengang_kz, 'semester' => $semester, 'mischen' => $mischen, 'titel' => $titel, 'edit' => $edit, 'sichtbar' => $sichtbar]); - } - - 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"); - } + $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"]); } } diff --git a/application/controllers/CisHtml/Cms.php b/application/controllers/CisHtml/Cms.php index f56b3eea3..102d0eff4 100755 --- a/application/controllers/CisHtml/Cms.php +++ b/application/controllers/CisHtml/Cms.php @@ -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; } // ----------------------------------------------------------------------------------------------------------------- @@ -45,12 +41,21 @@ class Cms extends FHC_Controller */ public function content($content_id, $version = null, $sprache = null, $sichtbar = true) { - $content = $this->cmslib->getContent($content_id, $version, $sprache, $sichtbar); + // 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)) - return $this->load->view('CisHtml/Error', ['error' => getError($content)]); + $this->terminateWithError(getError($content)); - $this->load->view('CisHtml/Cms/Content', ['content' => getData($content)]); + $content = getData($content); + if(NULL === $content) + $this->terminateWithError("Content not found"); + + $content = current($content); + + $this->load->view('CisVue/Cms/Content', ['content_id' => $content_id, 'template_kurzbz'=>$content->template_kurzbz , 'version' => $version, 'sprache' => $sprache, 'sichtbar' => $sichtbar]); } /** @@ -66,48 +71,7 @@ class Cms extends FHC_Controller */ public function news($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true) { - $this->load->view('CisHtml/Cms/Content', ['infoscreen' => $infoscreen, 'studiengang_kz' => $studiengang_kz, 'semester' => $semester, 'mischen' => $mischen, 'titel' => $titel, 'edit' => $edit, 'sichtbar' => $sichtbar]); + $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"); - } - } } diff --git a/application/controllers/CisVue/Cms.php b/application/controllers/CisVue/Cms.php index 2c1fa1fc6..4770a8399 100755 --- a/application/controllers/CisVue/Cms.php +++ b/application/controllers/CisVue/Cms.php @@ -24,6 +24,7 @@ class Cms extends FHC_Controller $this->loadPhrases([ 'global' ]); + } // ----------------------------------------------------------------------------------------------------------------- @@ -39,25 +40,15 @@ class Cms extends FHC_Controller */ public function content($content_id, $version = null, $sprache = null, $sichtbar = true) { - $content = $this->cmslib->getContent($content_id, $version, $sprache, $sichtbar); + $content = $this->ContentModel->load($content_id); + + $content = $this->getDataOrTerminateWithError($content); + + $content = current($content); - if (isError($content)) - return $this->load->view('CisHtml/Error', ['error' => getError($content)]); - - $this->load->view('CisHtml/Cms/Content', ['content' => getData($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 @@ -71,48 +62,7 @@ class Cms extends FHC_Controller */ public function news($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true) { - $this->load->view('CisHtml/Cms/Content', ['infoscreen' => $infoscreen, 'studiengang_kz' => $studiengang_kz, 'semester' => $semester, 'mischen' => $mischen, 'titel' => $titel, 'edit' => $edit, 'sichtbar' => $sichtbar]); + $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"); - } - } } diff --git a/application/controllers/api/frontend/v1/Cms.php b/application/controllers/api/frontend/v1/Cms.php new file mode 100644 index 000000000..5ba635a8a --- /dev/null +++ b/application/controllers/api/frontend/v1/Cms.php @@ -0,0 +1,181 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) + * Provides data to the ajax get calls about the searchbar component + * This controller works with JSON calls on the HTTP GET and the output is always JSON + */ +class Cms extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + // NOTE(chris): additional permission checks will be done in SearchBarLib + parent::__construct([ + 'ContentID' => self::PERM_LOGGED, + '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'); + + } + + //------------------------------------------------------------------------------------------------------------------ + // Private methods + + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * fetches the content with the content_id and additional parameters + */ + public function content() + { + // 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); + + $content = $this->cmslib->getContent($content_id); + + $content = $this->getDataOrTerminateWithError($content); + + $this->terminateWithSuccess($content); + } + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function ContentID() + { + // 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); + + $content_id = $this->OrtModel->getContentID($ort_kurzbz); + + $content_id = current($this->getDataOrTerminateWithError($content_id))->content_id; + + $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); + + //query the news + $news = $this->NewsModel->getAll($limit); + + //get the data or terminate with error + $news = $this->getDataOrTerminateWithError($news); + + // collect the content of the news + foreach($news as $news_element){ + $this->addMeta("content_id",$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); + + } + + +} + diff --git a/application/controllers/api/frontend/v1/Ort.php b/application/controllers/api/frontend/v1/Ort.php new file mode 100644 index 000000000..8c4059824 --- /dev/null +++ b/application/controllers/api/frontend/v1/Ort.php @@ -0,0 +1,95 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) + * Provides data to the ajax get calls about the searchbar component + * This controller works with JSON calls on the HTTP GET and the output is always JSON + */ +class Ort extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + // NOTE(chris): additional permission checks will be done in SearchBarLib + parent::__construct([ + 'ContentID' => self::PERM_LOGGED, + 'getOrtKurzbzContent' => self::PERM_LOGGED, + ]); + + $this->load->model('ressource/Ort_model', 'OrtModel'); + + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function ContentID() + { + // if error + //$this->terminateWithError(SearchBarLib::ERROR_WRONG_JSON, self::ERROR_TYPE_GENERAL); + + $ort_kurzbz = $this->input->get('ort_kurzbz',TRUE); + + if(!$ort_kurzbz){ + $this->terminateWithError("missing ort_kurzbz parameter", self::ERROR_TYPE_GENERAL); + } + + $result = $this->OrtModel->getContentID($ort_kurzbz); + + if(isError($result)){ + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + } + + $result = hasData($result) ? current(getData($result)) : null; + + $this->terminateWithSuccess($result->content_id ?? NULL); + } + + /** + * @param int $version + * @param string $sprache + * @param boolean $sichtbar + * + * @return $content + */ + public function getOrtKurzbzContent($version = null, $sprache = null, $sichtbar = true) + { + $content_id = $this->input->get("content_id",TRUE); + + $this->load->library('CmsLib'); + + $content = $this->cmslib->getContent($content_id, $version, $sprache, $sichtbar); + + if (isError($content)) + $this->terminateWithError(getError($content), self::ERROR_TYPE_GENERAL); + + $content = hasData($content) ? getData($content) : null; + + $this->terminateWithSuccess($content); + } +} + diff --git a/application/libraries/CmsLib.php b/application/libraries/CmsLib.php index 9a898df85..746d7f831 100755 --- a/application/libraries/CmsLib.php +++ b/application/libraries/CmsLib.php @@ -66,7 +66,6 @@ class CmsLib if (!getData($isberechtigt)) return error('global/keineBerechtigungFuerDieseSeite'); } - #$this->load->model('content/Content_model', 'ContentModel'); $content = $this->ci->ContentModel->getContent($content_id, $sprache, $version, $sichtbar, true); if (isError($content)) @@ -103,6 +102,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); @@ -110,10 +115,15 @@ class CmsLib $processor = new XSLTProcessor(); $processor->importStylesheet($xsltemplate); - $content = $processor->transformToXML($XML); - $content = str_replace('dms.php', APP_ROOT . 'cms/dms.php', $content); + + $transformed_content = $processor->transformToXML($XML); + $transformed_content = str_replace('dms.php', APP_ROOT . 'cms/dms.php', $transformed_content); - return success($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 f4f98b601..0700a7057 100755 --- a/application/models/content/News_model.php +++ b/application/models/content/News_model.php @@ -19,14 +19,27 @@ class News_model extends DB_Model */ public function getAll($limit = null) { - return $this->loadWhere(' - text IS NOT NULL - AND datum <= NOW() AND (datum_bis IS NULL OR datum_bis >= now()::date) + $this->addJoin("campus.tbl_content","content_id"); + 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) ); } + public function getNewsContentIDs($limit=10){ + $this->addSelect(['content_id']); + return $this->loadWhere("datum <= NOW() AND (datum_bis IS NULL OR datum_bis >= now()::date) + ORDER BY datum DESC + LIMIT " . $this->escape($limit)); + + } + /** diff --git a/application/models/ressource/Ort_model.php b/application/models/ressource/Ort_model.php index 59b213a54..de0c8e331 100755 --- a/application/models/ressource/Ort_model.php +++ b/application/models/ressource/Ort_model.php @@ -20,4 +20,16 @@ class Ort_model extends DB_Model return $this->OrtModel->loadWhere(array("raumtyp_kurzbz" => $raumtyp_kurzbz)); } + + public function getContentID($ort_kurzbz) + { + + return $this->execReadOnlyQuery(" + SELECT content_id + FROM public.tbl_ort + WHERE ort_kurzbz = ?; + ",[$ort_kurzbz]); + + } + } \ No newline at end of file diff --git a/application/views/Cis/Stundenplan.php b/application/views/Cis/Stundenplan.php index cb8f8a712..99103b373 100755 --- a/application/views/Cis/Stundenplan.php +++ b/application/views/Cis/Stundenplan.php @@ -8,10 +8,10 @@ $includesArray = array( $this->load->view('templates/CISHTML-Header', $includesArray); ?> -