Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the soft-delete values configurable #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions core/MY_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class MY_Model extends CI_Model
*/
protected $soft_delete = FALSE;
protected $soft_delete_key = 'deleted';
protected $soft_delete_deleted_value = TRUE;
protected $soft_delete_default_value = FALSE;
protected $_temporary_with_deleted = FALSE;

/**
Expand Down Expand Up @@ -123,7 +125,7 @@ public function get($primary_value)

if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
{
$this->db->where($this->soft_delete_key, FALSE);
$this->db->where($this->soft_delete_key, $this->soft_delete_default_value);
}

$row = $this->db->where($this->primary_key, $primary_value)
Expand All @@ -148,7 +150,7 @@ public function get_by()

if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
{
$this->db->where($this->soft_delete_key, FALSE);
$this->db->where($this->soft_delete_key, $this->soft_delete_default_value);
}

$this->trigger('before_get');
Expand All @@ -170,7 +172,7 @@ public function get_many($values)
{
if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
{
$this->db->where($this->soft_delete_key, FALSE);
$this->db->where($this->soft_delete_key, $this->soft_delete_default_value);
}

$this->db->where_in($this->primary_key, $values);
Expand All @@ -188,7 +190,7 @@ public function get_many_by()

if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
{
$this->db->where($this->soft_delete_key, FALSE);
$this->db->where($this->soft_delete_key, $this->soft_delete_default_value);
}

return $this->get_all();
Expand All @@ -204,7 +206,7 @@ public function get_all()

if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
{
$this->db->where($this->soft_delete_key, FALSE);
$this->db->where($this->soft_delete_key, $this->soft_delete_default_value);
}

$result = $this->db->get($this->_table)
Expand Down Expand Up @@ -372,7 +374,7 @@ public function delete($id)

if ($this->soft_delete)
{
$result = $this->db->update($this->_table, array( $this->soft_delete_key => TRUE ));
$result = $this->db->update($this->_table, array( $this->soft_delete_key => $this->soft_delete_deleted_value ));
}
else
{
Expand All @@ -396,7 +398,7 @@ public function delete_by()

if ($this->soft_delete)
{
$result = $this->db->update($this->_table, array( $this->soft_delete_key => TRUE ));
$result = $this->db->update($this->_table, array( $this->soft_delete_key => $this->soft_delete_deleted_value ));
}
else
{
Expand All @@ -419,7 +421,7 @@ public function delete_many($primary_values)

if ($this->soft_delete)
{
$result = $this->db->update($this->_table, array( $this->soft_delete_key => TRUE ));
$result = $this->db->update($this->_table, array( $this->soft_delete_key => $this->soft_delete_deleted_value ));
}
else
{
Expand Down Expand Up @@ -528,7 +530,7 @@ function dropdown()

if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
{
$this->db->where($this->soft_delete_key, FALSE);
$this->db->where($this->soft_delete_key, $this->soft_delete_default_value);
}

$result = $this->db->select(array($key, $value))
Expand Down