Example #1
0
 /**
  * Create an item entry
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     $id = $id ?: Request::getInt('id', 0);
     include_once PATH_CORE . DS . 'components' . DS . 'com_kb' . DS . 'models' . DS . 'article.php';
     $article = null;
     if (!$id) {
         $category = Category::all()->whereEquals('alias', Request::getVar('category'))->limit(1)->row();
         if (!$category->get('id')) {
             return true;
         }
         $article = Article::all()->whereEquals('alias', Request::getVar('alias', ''))->whereEquals('category', $category->get('id'))->limit(1)->row();
         $id = $article->get('id');
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$article) {
         $article = Article::oneOrNew($id);
     }
     if ($article->isNew()) {
         $this->setError(Lang::txt('Knowledge base article not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $article->get('id'))->set('created', $article->get('created'))->set('created_by', $article->get('created_by'))->set('title', $article->get('title'))->set('description', \Hubzero\Utility\String::truncate($article->fulltxt(), 200))->set('url', Route::url($article->link()));
     if (!$this->store()) {
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     // Initiate extended database class
     $row = Article::oneOrNew($fields['id'])->set($fields);
     // Get parameters
     $params = Request::getVar('params', array(), 'post');
     $p = $row->param();
     if (is_array($params)) {
         $txt = array();
         foreach ($params as $k => $v) {
             $p->set($k, $v);
         }
         $row->set('params', $p->toString());
     }
     // Store new content
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     // Save the tags
     $row->tag(Request::getVar('tags', '', 'post'), User::get('id'));
     if ($this->_task == 'apply') {
         Notify::success(Lang::txt('COM_KB_ARTICLE_SAVED'));
         return $this->editTask($row);
     }
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_KB_ARTICLE_SAVED'));
 }
Example #3
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     // Initiate extended database class
     $row = Article::oneOrNew($fields['id'])->set($fields);
     // Get parameters
     $params = Request::getVar('params', array(), 'post');
     $p = $row->param();
     if (is_array($params)) {
         $txt = array();
         foreach ($params as $k => $v) {
             $p->set($k, $v);
         }
         $row->set('params', $p->toString());
     }
     // Store new content
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     // Save the tags
     $row->tag(Request::getVar('tags', '', 'post'), User::get('id'));
     Notify::success(Lang::txt('COM_KB_ARTICLE_SAVED'));
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     // Set the redirect
     $this->cancelTask();
 }