Backend\Modules\Location\Engine\Model::delete PHP Method

delete() public static method

Delete an item
public static delete ( integer $id )
$id integer The id of the record to delete.
    public static function delete($id)
    {
        // get db
        $db = BackendModel::getContainer()->get('database');
        // get item
        $item = self::get($id);
        BackendModel::deleteExtraById($item['extra_id']);
        // delete location and its settings
        $db->delete('location', 'id = ? AND language = ?', array((int) $id, BL::getWorkingLanguage()));
        $db->delete('location_settings', 'map_id = ?', array((int) $id));
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendLocationModel::exists($this->id)) {
         parent::execute();
         // get all data for the item we want to edit
         $this->record = (array) BackendLocationModel::get($this->id);
         // delete item
         BackendLocationModel::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=' . urlencode($this->record['title']));
     } else {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }