/** * Deletes one or more records and redirects to listing * * @return void */ public function removeTask() { // Check for request forgeries Request::checkToken(); // Incoming $section = Request::getInt('section_id', 0); $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Do we have any IDs? if (count($ids) > 0) { // Instantiate some objects $category = new Category($this->database); // Loop through each ID foreach ($ids as $id) { $id = intval($id); // Remove the posts in this category $tModel = new Post($this->database); if (!$tModel->deleteByCategory($id)) { throw new Exception($tModel->getError(), 500); } // Remove this category if (!$category->delete($id)) { throw new Exception($category->getError(), 500); } } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '§ion_id=' . $section, false), Lang::txt('COM_FORUM_CATEGORIES_DELETED')); }
/** * 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 . '§ion_id=' . Request::getInt('section_id', 0), false), Lang::txt('COM_FORUM_SECTIONS_DELETED')); }
/** * Delete a category and all associated content * * @param integer $oid Object ID (primary key) * @return boolean True if successful otherwise returns and error message */ public function delete($oid = null) { $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } include_once __DIR__ . DS . 'post.php'; $post = new Post($this->_db); if (!$post->deleteByCategory($this->{$k})) { $this->setError($post->getErrorMsg()); return false; } return parent::delete(); }