Example #1
0
 /**
  * Save a category record and redirects to listing
  *
  * @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'));
     }
     User::setState('com_forum.edit.category.data', null);
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     // Initiate extended database class
     $category = Category::oneOrNew($fields['id'])->set($fields);
     // Bind the rules.
     $data = Request::getVar('jform', array(), 'post');
     if (isset($data['rules']) && is_array($data['rules'])) {
         $model = new AdminCategory();
         $form = $model->getForm($data, false);
         $validData = $model->validate($form, $data);
         $category->assetRules = new \JAccessRules($validData['rules']);
     }
     if (!$category->get('scope')) {
         $section = Section::oneOrFail($fields['section_id']);
         $category->set('scope', $section->get('scope'));
         $category->set('scope_id', $section->get('scope_id'));
     }
     // Store new content
     if (!$category->save()) {
         Notify::error($category->getError());
         return $this->editTask($category);
     }
     Notify::success(Lang::txt('COM_FORUM_CATEGORY_SAVED'));
     if ($this->getTask() == 'apply') {
         return $this->editTask($category);
     }
     // Redirect
     $this->cancelTask();
 }
Example #2
0
 /**
  * Save a category record and redirects to listing
  *
  * @return     void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     \User::setState('com_forum.edit.category.data', null);
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     // Bind the rules.
     $data = Request::getVar('jform', array(), 'post');
     if (isset($data['rules']) && is_array($data['rules'])) {
         $model = new AdminCategory();
         $form = $model->getForm($data, false);
         $validData = $model->validate($form, $data);
         $fields['rules'] = $validData['rules'];
     }
     // Initiate extended database class
     $model = new Category($this->database);
     if (!$model->bind($fields)) {
         Notify::error($model->getError());
         return $this->editTask($model);
     }
     if (!$model->scope) {
         $section = new Section($this->database);
         $section->load($fields['section_id']);
         $model->scope = $section->scope;
         $model->scope_id = $section->scope_id;
     }
     // Check content
     if (!$model->check()) {
         Notify::error($model->getError());
         return $this->editTask($model);
     }
     // Store new content
     if (!$model->store()) {
         Notify::error($model->getError());
         return $this->editTask($model);
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&section_id=' . $fields['section_id'], false), Lang::txt('COM_FORUM_CATEGORY_SAVED'));
 }