Backend\Modules\Faq\Engine\Model::deleteCategory PHP Method

deleteCategory() public static method

Delete a specific category
public static deleteCategory ( integer $id )
$id integer
    public static function deleteCategory($id)
    {
        $db = BackendModel::getContainer()->get('database');
        $item = self::getCategory($id);
        if (!empty($item)) {
            $db->delete('meta', 'id = ?', array($item['meta_id']));
            $db->delete('faq_categories', 'id = ?', array((int) $id));
            $db->update('faq_questions', array('category_id' => null), 'category_id = ?', array((int) $id));
            BackendModel::deleteExtraById($item['extra_id']);
        }
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendFaqModel::existsCategory($this->id)) {
         $this->record = (array) BackendFaqModel::getCategory($this->id);
         if (BackendFaqModel::deleteCategoryAllowed($this->id)) {
             parent::execute();
             // delete item
             BackendFaqModel::deleteCategory($this->id);
             BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('item' => $this->record));
             // category was deleted, so redirect
             $this->redirect(BackendModel::createURLForAction('Categories') . '&report=deleted-category&var=' . urlencode($this->record['title']));
         } else {
             $this->redirect(BackendModel::createURLForAction('Categories') . '&error=delete-category-not-allowed&var=' . urlencode($this->record['title']));
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('Categories') . '&error=non-existing');
     }
 }