. */ 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, 'update' => 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() { $this->BookmarkModel->addOrder("bookmark_id"); $bookmarks = $this->BookmarkModel->loadWhere(["uid"=>$this->uid]); $bookmarks = $this->getDataOrTerminateWithError($bookmarks); $this->terminateWithSuccess($bookmarks); } /** * deletes bookmark from associated user * @access public * @return void */ public function delete($bookmark_id) { $bookmark = $this->BookmarkModel->load($bookmark_id); $bookmark = current($this->getDataOrTerminateWithError($bookmark)); // only delete bookmark if the user is the owner of the bookmark if($bookmark->uid == $this->uid || $this->permissionlib->isBerechtigt('admin')){ $delete_result = $this->BookmarkModel->delete($bookmark_id); $delete_result = $this->getDataOrTerminateWithError($delete_result); $this->terminateWithSuccess($delete_result); }else{ $this->_outputAuthError(['delete' => ['admin:rw']]); } } /** * inserts new bookmark into the bookmark table * @access public * @return void */ public function insert() { // 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); $tag = $this->input->post('tag', true); $insert_into_result = $this->BookmarkModel->insert(['uid'=>$this->uid, 'url'=>$url, 'title'=>$title,'tag'=>$tag, 'insertvon'=>$this->uid, 'updateamum'=>NULL, 'updatevon'=>NULL]); $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); $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); } }