From 7a31016b13ba6a8bee62161ca4286d3ae6f1fd4d Mon Sep 17 00:00:00 2001 From: Arthit Khunyosying Date: Mon, 26 Nov 2012 18:31:52 +0700 Subject: [PATCH] modified delete() method i'm add 2nd parameter to real delete record if soft delete is true add new method restore() to set field 'deleted' back to 0 (undeleted) --- core/MY_Model.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/core/MY_Model.php b/core/MY_Model.php index c9fc205..7a1f7c2 100644 --- a/core/MY_Model.php +++ b/core/MY_Model.php @@ -362,16 +362,24 @@ public function update_all($data) /** * Delete a row from the table by the primary value + * Add 2nd parameter to real delete if osft delete is true */ - public function delete($id) + public function delete($id, $real_delete = FALSE) { $this->trigger('before_delete', $id); $this->db->where($this->primary_key, $id); - + if ($this->soft_delete) { - $result = $this->db->update($this->_table, array( $this->soft_delete_key => TRUE )); + if ($real_delete === TRUE) + { + $result = $this->db->delete($this->_table); + } + else + { + $result = $this->db->update($this->_table, array( $this->soft_delete_key => TRUE )); + } } else { @@ -603,6 +611,19 @@ public function table() return $this->_table; } + /** + * Restore + * Set 'deleted' field to 0 + */ + public function restore( $id ) + { + if ($this->soft_delete === TRUE) + { + return $this->update($id, array($this->soft_delete_key => FALSE)); + } + return FALSE; + } + /* -------------------------------------------------------------- * GLOBAL SCOPES * ------------------------------------------------------------ */