diff --git a/application/controllers/api/frontend/v1/Bookmark.php b/application/controllers/api/frontend/v1/Bookmark.php index a811843ce..3e646bb51 100644 --- a/application/controllers/api/frontend/v1/Bookmark.php +++ b/application/controllers/api/frontend/v1/Bookmark.php @@ -30,6 +30,7 @@ class Bookmark extends FHCAPI_Controller 'getBookmarks' => self::PERM_LOGGED, 'delete' => self::PERM_LOGGED, 'insert' => self::PERM_LOGGED, + 'update' => self::PERM_LOGGED, ]); $this->load->model('dashboard/Bookmark_model', 'BookmarkModel'); @@ -50,7 +51,8 @@ class Bookmark extends FHCAPI_Controller */ public function getBookmarks() { - $bookmarks = $this->BookmarkModel->loadWhere(["uid"=>$this->uid]); + $this->BookmarkModel->addOrder("bookmark_id"); + $bookmarks = $this->BookmarkModel->loadWhere(["uid"=>$this->uid]); $bookmarks = $this->getDataOrTerminateWithError($bookmarks); @@ -104,6 +106,33 @@ class Bookmark extends FHCAPI_Controller $this->terminateWithSuccess($insert_into_result); + } + + /** + * updates bookmark in the bookmark table + * @access public + * @return void + */ + public function update($bookmark_id) + { + // form validation + $this->load->library('form_validation'); + $this->form_validation->set_rules('url', 'URL', 'required|valid_url|max_length[511]'); + $this->form_validation->set_rules('title', 'Title', 'required|max_length[255]'); + if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $url = $this->input->post('url',true); + $title = $this->input->post('title',true); + + $now = new DateTime(); + $now = $now->format('Y-m-d H:i:s'); + + $update_result = $this->BookmarkModel->update($bookmark_id,['url'=>$url, 'title'=>$title,'updateamum'=>$now]); + + $update_result = $this->getDataOrTerminateWithError($update_result); + + $this->terminateWithSuccess($update_result); + } } diff --git a/application/controllers/api/frontend/v1/Cms.php b/application/controllers/api/frontend/v1/Cms.php index f1fe380de..b8937a1f4 100644 --- a/application/controllers/api/frontend/v1/Cms.php +++ b/application/controllers/api/frontend/v1/Cms.php @@ -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); } diff --git a/application/libraries/CmsLib.php b/application/libraries/CmsLib.php index 60e982eab..355cf7c56 100644 --- a/application/libraries/CmsLib.php +++ b/application/libraries/CmsLib.php @@ -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(); diff --git a/public/js/api/bookmark.js b/public/js/api/bookmark.js index 30e49d50d..5cef0a46b 100644 --- a/public/js/api/bookmark.js +++ b/public/js/api/bookmark.js @@ -14,6 +14,16 @@ export default { ); }, + update: function ({ bookmark_id, url, title, tag=null}) { + return this.$fhcApi.post( + `/api/frontend/v1/Bookmark/update/${bookmark_id}` + , { + url: url, + title: title + } + ); + }, + insert: function ({url, title, tag}) { return this.$fhcApi.post( `/api/frontend/v1/Bookmark/insert` diff --git a/public/js/components/DashboardWidget/News.js b/public/js/components/DashboardWidget/News.js index c29f538e4..a459e1325 100644 --- a/public/js/components/DashboardWidget/News.js +++ b/public/js/components/DashboardWidget/News.js @@ -39,6 +39,9 @@ export default { } }, methods: { + isString(value){ + return Object.prototype.toString.call(value) === '[object String]'; + }, setNext(){ const thisIndex = this.allNewsList.findIndex(n=>n.news_id == this.selected.news_id) const nextIndex = thisIndex == (this.allNewsList.length - 1) ? 0 : thisIndex + 1 @@ -175,13 +178,16 @@ export default {