. */ if (! defined('BASEPATH')) exit('No direct script access allowed'); class Bookmark extends FHCAPI_Controller { /** * Object initialization */ public function __construct() { parent::__construct([ 'getBookmarks' => self::PERM_LOGGED, 'delete' => self::PERM_LOGGED, 'insert' => self::PERM_LOGGED, ]); $this->load->model('dashboard/Bookmark_model', 'BookmarkModel'); $this->uid = getAuthUID(); $this->pid = getAuthPersonID(); } //------------------------------------------------------------------------------------------------------------------ // Public methods /** * gets the bookmarks associated to a user * @access public * @return void */ public function getBookmarks() { $bookmarks = $this->BookmarkModel->loadWhere(["uid"=>$this->uid]); if(isError($bookmarks)){ $this->terminateWithError(getError($bookmarks)); } $bookmarks = $this->getDataOrTerminateWithError($bookmarks); $this->terminateWithSuccess($bookmarks); } /** * deletes bookmark from associated user * @access public * @return void */ public function delete($bookmark_id) { if(!isset($bookmark_id)) $this->terminateWithError("missing required parameters"); $bookmark = $this->BookmarkModel->load($bookmark_id); if(isError($bookmark)){ $this->terminateWithError(getError($bookmark)); } $bookmark = current($this->getDataOrTerminateWithError($bookmark)); // only delete bookmark if the user is the owner of the bookmark $this->load->library('PermissionLib'); if($bookmark->uid == $this->uid || $this->permissionlib->isBerechtigt('admin')){ $delete_result = $this->BookmarkModel->delete($bookmark_id); if(isError($delete_result)){ $this->terminateWithError(getError($delete_result)); } $delete_result = $this->getDataOrTerminateWithError($delete_result); $this->terminateWithSuccess($delete_result); }else{ $this->terminateWithError("You are not authorized to delete this bookmark"); } } /** * inserts new bookmark into the bookmark table * @access public * @return void */ public function insert() { $url = $this->input->post('url',true); $title = $this->input->post('title',true); $tag = $this->input->post('tag',true); // set the parameters to null if they are not present in the request payload if($title == FALSE) $title = NULL; if($tag == FALSE) $tag = NULL; if(!isset($url))$this->terminateWithError("missing required parameters"); $insert_into_result = $this->BookmarkModel->execReadOnlyQuery(" INSERT INTO dashboard.tbl_bookmark (uid, url, title,tag, insertvon, updateamum, updatevon) VALUES (?,?,?,?,?,NULL,NULL);",[$this->uid,$url,$title,$tag,$this->uid]); if(isError($insert_into_result)){ $this->terminateWithError(getError($insert_into_result)); } $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); $this->terminateWithSuccess($insert_into_result); } }