public static function delete($id)
{
$id = (int) $id;
$db = BackendModel::getContainer()->get('database');
// get field ids
$fieldIds = (array) $db->getColumn('SELECT i.id FROM forms_fields AS i WHERE i.form_id = ?', $id);
// we have items to be deleted
if (!empty($fieldIds)) {
// delete all fields
$db->delete('forms_fields', 'form_id = ?', $id);
$db->delete('forms_fields_validation', 'field_id IN(' . implode(',', $fieldIds) . ')');
}
// get data ids
$dataIds = (array) $db->getColumn('SELECT i.id FROM forms_data AS i WHERE i.form_id = ?', $id);
// we have items to be deleted
if (!empty($dataIds)) {
self::deleteData($dataIds);
}
// delete extra
BackendModel::deleteExtra('FormBuilder', 'widget', array('id' => $id));
// delete form
$db->delete('forms', 'id = ?', $id);
}
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendFormBuilderModel::exists($this->id)) { parent::execute(); // get all data for the item we want to edit $this->record = (array) BackendFormBuilderModel::get($this->id); // delete item BackendFormBuilderModel::delete($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // user was deleted, so redirect $this->redirect(BackendModel::createURLForAction('Index') . '&report=deleted&var=' . rawurlencode($this->record['name'])); } else { // no item found, throw an exceptions, because somebody is f*****g with our URL $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing'); } }