Пример #1
0
 /**
  * Sets the state of one or more entries
  *
  * @return  void
  */
 public function accessTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $section = Request::getInt('section_id', 0);
     $state = Request::getInt('access', 0);
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Check for an ID
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&section_id=' . $section, false), Lang::txt('COM_FORUM_SELECT_ENTRY_TO_CHANGE_ACCESS'), 'error');
         return;
     }
     foreach ($ids as $id) {
         // Update record(s)
         $row = new Category($this->database);
         $row->load(intval($id));
         $row->access = $state;
         if (!$row->store()) {
             throw new Exception($row->getError(), 500);
         }
     }
     // set message
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&section_id=' . $section, false), Lang::txt('COM_FORUM_ITEMS_ACCESS_CHANGED', count($ids)));
 }
Пример #2
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'));
 }
Пример #3
0
 /**
  * Store changes to this entry
  *
  * @param     boolean $check Perform data validation check?
  * @return    boolean False if error, True on success
  */
 public function store($check = true)
 {
     // Get the entry before changes were made
     $old = new self($this->get('id'));
     // Store entry
     if (!parent::store($check)) {
         return false;
     }
     // If the section is marked as "deleted" and it wasn't already marked as such
     if ($this->get('state') == self::APP_STATE_DELETED && $old->get('state') != self::APP_STATE_DELETED) {
         // Collect a list of category IDs
         $cats = array();
         foreach ($this->categories('list', array('state' => -1)) as $category) {
             $cats[] = $category->get('id');
         }
         if (count($cats) > 0) {
             // Set all the threads/posts in all the categories to "deleted"
             $post = new Tables\Post($this->_db);
             if (!$post->setStateByCategory($cats, self::APP_STATE_DELETED)) {
                 $this->setError($post->getError());
             }
             // Set all the categories to "deleted"
             $cModel = new Tables\Category($this->_db);
             if (!$cModel->setStateBySection($this->get('id'), self::APP_STATE_DELETED)) {
                 $this->setError($cModel->getError());
             }
         }
     }
     return true;
 }