示例#1
0
 /**
  * Deletes one or more records and redirects to listing
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Do we have any IDs?
     if (count($ids) > 0) {
         // Loop through each ID
         foreach ($ids as $id) {
             $id = intval($id);
             $section = new Tables\Section($this->database);
             $section->load($id);
             // Get the categories in this section
             $cModel = new Tables\Category($this->database);
             $categories = $cModel->getRecords(array('section_id' => $section->id));
             // Loop through each category
             foreach ($categories as $category) {
                 // Remove the posts in this category
                 $tModel = new Tables\Post($this->database);
                 if (!$tModel->deleteByCategory($category->id)) {
                     throw new Exception($tModel->getError(), 500);
                 }
                 // Remove this category
                 if (!$cModel->delete($category->id)) {
                     throw new Exception($cModel->getError(), 500);
                 }
             }
             // Remove this section
             if (!$section->delete()) {
                 throw new Exception($section->getError(), 500);
             }
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&section_id=' . Request::getInt('section_id', 0), false), Lang::txt('COM_FORUM_SECTIONS_DELETED'));
 }
示例#2
0
 /**
  * Displays a question response for editing
  *
  * @param   mixed  $post
  * @return  void
  */
 public function editTask($post = null)
 {
     Request::setVar('hidemainmenu', 1);
     // Incoming
     $id = Request::getVar('id', array(0));
     $parent = Request::getInt('parent', 0);
     $this->view->parent = $parent;
     if (is_array($id)) {
         $id = intval($id[0]);
     }
     // Incoming
     if (!is_object($post)) {
         $post = new Post($this->database);
         $post->load($id);
     }
     $this->view->row = $post;
     if (!$id) {
         $this->view->row->parent = $parent;
         $this->view->row->created_by = User::get('id');
     }
     if ($this->view->row->parent) {
         $filters = array('category_id' => $this->view->row->category_id, 'sort' => 'title', 'sort_Dir' => 'ASC', 'limit' => 100, 'start' => 0, 'parent' => 0);
         $this->view->threads = $this->view->row->getRecords($filters);
     }
     // Get the category
     $this->view->category = new Category($this->database);
     $this->view->category->load($this->view->row->category_id);
     if (!$this->view->category->id) {
         // No category? Load a default blank catgory
         $this->view->category->loadDefault();
     }
     $this->view->cateories = array();
     $categories = $this->view->category->getRecords();
     if ($categories) {
         foreach ($categories as $c) {
             if (!isset($this->view->cateories[$c->section_id])) {
                 $this->view->cateories[$c->section_id] = array();
             }
             $this->view->cateories[$c->section_id][] = $c;
             asort($this->view->cateories[$c->section_id]);
         }
     }
     // Get the section
     $this->view->section = new Section($this->database);
     $this->view->section->load($this->view->category->section_id);
     if (!$this->view->section->id) {
         // No section? Load a default blank section
         $this->view->section->loadDefault();
     }
     // Get the sections for this group
     $this->view->sections = array();
     $sections = $this->view->section->getRecords();
     if ($sections) {
         foreach ($sections as $s) {
             $ky = $s->scope . ' (' . $s->scope_id . ')';
             if ($s->scope == 'site') {
                 $ky = '[ site ]';
             }
             if (!isset($this->view->sections[$ky])) {
                 $this->view->sections[$ky] = array();
             }
             $s->categories = isset($this->view->cateories[$s->id]) ? $this->view->cateories[$s->id] : array();
             //$this->view->category->getRecords(array('section_id'=>$s->id));
             $this->view->sections[$ky][] = $s;
             asort($this->view->sections[$ky]);
         }
     } else {
         $default = new Section($this->database);
         $default->loadDefault($this->view->section->scope, $this->view->section->scope_id);
         $this->view->sections[] = $default;
     }
     asort($this->view->sections);
     \User::setState('com_forum.edit.thread.data', array('id' => $this->view->row->get('id'), 'asset_id' => $this->view->row->get('asset_id')));
     $m = new AdminThread();
     $this->view->form = $m->getForm();
     // Get tags on this article
     $this->view->tModel = new Tags($this->view->row->id);
     $this->view->tags = $this->view->tModel->render('string');
     // Set any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     $this->view->setLayout('edit')->display();
 }
示例#3
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'));
 }
示例#4
0
 /**
  * Get a list of sections for a forum
  *
  * @param   string   $rtrn     What data to return [count, list, first]
  * @param   array    $filters  Filters to apply to data fetch
  * @param   boolean  $clear    Clear cached data?
  * @return  mixed
  */
 public function sections($rtrn = '', $filters = array(), $clear = false)
 {
     if (!isset($filters['scope'])) {
         $filters['scope'] = (string) $this->get('scope');
     }
     if (!isset($filters['scope_id'])) {
         $filters['scope_id'] = (int) $this->get('scope_id');
     }
     $tbl = new Tables\Section($this->_db);
     switch (strtolower($rtrn)) {
         case 'count':
             if (!isset($this->_cache['sections_count']) || $clear) {
                 $this->_cache['sections_count'] = (int) $tbl->getCount($filters);
             }
             return $this->_cache['sections_count'];
             break;
         case 'first':
             if (!$this->_cache['sections_first'] instanceof Section || $clear) {
                 $filters['limit'] = 1;
                 $filters['start'] = 0;
                 $filters['sort'] = 'created';
                 $filters['sort_Dir'] = 'ASC';
                 $results = $tbl->getRecords($filters);
                 $res = isset($results[0]) ? $results[0] : null;
                 $this->_cache['sections_first'] = new Section($res);
             }
             return $this->_cache['sections_first'];
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_cache['sections'] instanceof ItemList || $clear) {
                 if ($results = $tbl->getRecords($filters)) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Section($result);
                     }
                 } else {
                     $results = array();
                 }
                 $this->_cache['sections'] = new ItemList($results);
             }
             return $this->_cache['sections'];
             break;
     }
 }