/** * 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(); }
/** * Save a category * * @return void */ public function savecategory() { // Check for request forgeries Request::checkToken(); if (!$this->course->access('manage', 'offering')) { return $this->panel(); } $fields = Request::getVar('fields', array(), 'post'); $fields = array_map('trim', $fields); // Instantiate a category $category = Category::oneOrNew($fields['id'])->set($fields); // Double-check that the user is authorized $this->_authorize('category', $category->get('id')); if (!$this->params->get('access-edit-category')) { // Set the redirect App::redirect(Route::url($this->base . '&unit=manage')); } $category->set('closed', isset($fields['closed']) && $fields['closed'] ? 1 : 0); // Forge an alias from the title if ($category->get('alias') == '') { $alias = $category->automaticAlias(array('title' => $category->get('title'))); $category->set('alias', $alias); } // Check for alias duplicates within section? if (!$category->isUnique()) { $category->set('alias', ''); //reset alias $category->set('section_id', (int) $category->get('section_id')); Request::setVar('section_id', $category->get('section_id')); Notify::error(Lang::txt('PLG_COURSES_FORUM_ERROR_CATEGORY_ALREADY_EXISTS'), 'courses_forum'); return $this->editcategory($category); } // Store new content if (!$category->save()) { Notify::error($category->getError(), 'courses_forum'); return $this->editcategory($category); } // Log activity Event::trigger('system.logActivity', ['activity' => ['action' => $fields['id'] ? 'updated' : 'created', 'scope' => 'forum.category', 'scope_id' => $category->get('id'), 'description' => Lang::txt('PLG_COURSES_FORUM_ACTIVITY_CATEGORY_' . ($fields['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($this->base) . '">' . $category->get('title') . '</a>'), 'details' => array('title' => $category->get('title'), 'url' => Route::url($this->base))], 'recipients' => array(['course', $this->offering->get('id')], ['forum.' . $this->forum->get('scope'), $this->forum->get('scope_id')], ['forum.section', $category->get('section_id')], ['user', $category->get('created_by')])]); // Set the redirect App::redirect(Route::url($this->base . '&unit=manage')); }
/** * Displays a question response for editing * * @param mixed $post * @return void */ public function editTask($post = null) { Request::setVar('hidemainmenu', 1); if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $parent = Request::getInt('parent', 0); if (!is_object($post)) { $id = Request::getVar('id', array(0)); if (is_array($id)) { $id = intval($id[0]); } $post = Post::oneOrNew($id); } if ($post->isNew()) { $post->set('parent', $parent); $post->set('created_by', User::get('id')); } if ($post->get('parent')) { $threads = Post::all()->whereEquals('category_id', $post->get('category_id'))->whereEquals('parent', 0)->ordered()->rows(); } // Get the category $category = Category::oneOrNew($post->get('category_id')); $categories = array(); foreach (Category::all()->rows() as $c) { if (!isset($categories[$c->section_id])) { $categories[$c->section_id] = array(); } $categories[$c->section_id][] = $c; asort($categories[$c->section_id]); } // Get the section $section = Section::oneOrNew($category->get('section_id')); // Get the sections for this group $sections = array(); foreach (Section::all()->rows() as $s) { $ky = $s->scope . ' (' . $s->scope_id . ')'; if ($s->scope == 'site') { $ky = '[ site ]'; } if (!isset($sections[$ky])) { $sections[$ky] = array(); } $s->categories = isset($categories[$s->id]) ? $categories[$s->id] : array(); $sections[$ky][] = $s; asort($sections[$ky]); } User::setState('com_forum.edit.thread.data', array('id' => $post->get('id'), 'asset_id' => $post->get('asset_id'))); $m = new AdminThread(); $form = $m->getForm(); // Get tags on this article $this->view->set('row', $post)->set('sections', $sections)->set('categories', $categories)->set('form', $form)->setLayout('edit')->display(); }
/** * Save an entry * * @return void */ public function saveTask() { if (User::isGuest()) { $return = Route::url('index.php?option=' . $this->_option, false, true); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return))); } // Check for request forgeries Request::checkToken(); $url = 'index.php?option=' . $this->_option; // Incoming $fields = Request::getVar('fields', array(), 'post'); $fields = array_map('trim', $fields); // Instantiate a category $category = Category::oneOrNew($fields['id'])->set($fields); // Double-check that the user is authorized $this->_authorize('category', $category->get('id')); if (!$this->config->get('access-edit-category')) { App::redirect(Route::url($url)); } $category->set('closed', isset($fields['closed']) && $fields['closed'] ? 1 : 0); // Check for alias duplicates if (!$category->isUnique()) { Notify::error(Lang::txt('COM_FORUM_ERROR_CATEGORY_ALREADY_EXISTS')); return $this->editTask($category); } // Store new content if (!$category->save()) { Notify::error($category->getError()); return $this->editTask($category); } // Log activity Event::trigger('system.logActivity', ['activity' => ['action' => $fields['id'] ? 'updated' : 'created', 'scope' => 'forum.category', 'scope_id' => $category->get('id'), 'description' => Lang::txt('COM_FORUM_ACTIVITY_CATEGORY_' . ($fields['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($url) . '">' . $category->get('title') . '</a>'), 'details' => array('title' => $category->get('title'), 'url' => Route::url($url))], 'recipients' => array(['forum.site', 1], ['forum.section', $category->get('section_id')], ['user', $category->get('created_by')])]); // Set the redirect App::redirect(Route::url($url)); }