1 | <?php |
||
8 | class SoftDbRepository extends DbRepository implements SoftRepositoryInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var string Soft deletion attribute. |
||
12 | */ |
||
13 | protected $deleted; |
||
14 | |||
15 | |||
16 | /** |
||
17 | * Constructor. |
||
18 | * |
||
19 | * @param \Anax\Database\DatabaseQueryBuilder $db Database service. |
||
20 | * @param string $table Database table name. |
||
21 | * @param string $modelClass Model class name. |
||
22 | * @param string $deleted Soft deletion attribute. |
||
23 | * @param string $key Primary key column. |
||
24 | */ |
||
25 | 15 | public function __construct($db, $table, $modelClass, $deleted = 'deleted', $key = 'id') |
|
30 | |||
31 | |||
32 | /** |
||
33 | * Return the name of the attribute used to mark soft deletion. |
||
34 | */ |
||
35 | 3 | public function getDeletedAttribute() |
|
39 | |||
40 | |||
41 | /** |
||
42 | * Find and return first entry by key, ignoring soft-deleted entries. |
||
43 | * |
||
44 | * @param string|null $column Key column name (pass null to use registered primary key). |
||
45 | * @param mixed $value Key value. |
||
46 | * |
||
47 | * @return mixed Model instance. |
||
48 | */ |
||
49 | 8 | public function findSoft($column, $value) |
|
53 | |||
54 | |||
55 | /** |
||
56 | * Retrieve first entry ignoring soft-deleted ones, optionally filtered by search criteria. |
||
57 | * |
||
58 | * @param string $conditions Where conditions. |
||
59 | * @param array $values Array of condition values to bind. |
||
60 | * @param array $options Query options. |
||
61 | * |
||
62 | * @return mixed Model instance. |
||
63 | */ |
||
64 | 9 | public function getFirstSoft($conditions = null, $values = [], $options = []) |
|
68 | |||
69 | |||
70 | /** |
||
71 | * Retrieve all entries ignoring soft-deleted ones, optionally filtered by search criteria. |
||
72 | * |
||
73 | * @param string $conditions Where conditions. |
||
74 | * @param array $values Array of condition values to bind. |
||
75 | * @param array $options Query options. |
||
76 | * |
||
77 | * @return array Array of all matching entries. |
||
78 | */ |
||
79 | 2 | public function getAllSoft($conditions = null, $values = [], $options = []) |
|
83 | |||
84 | |||
85 | /** |
||
86 | * Soft delete entry. |
||
87 | * |
||
88 | * @param mixed $model Model instance. |
||
89 | */ |
||
90 | 1 | public function deleteSoft($model) |
|
95 | |||
96 | |||
97 | /** |
||
98 | * Restore soft-deleted entry. |
||
99 | * |
||
100 | * @param mixed $model Model instance. |
||
101 | */ |
||
102 | 1 | public function restoreSoft($model) |
|
107 | |||
108 | |||
109 | /** |
||
110 | * Count entries ignoring soft-deleted ones, optionally filtered by search criteria. |
||
111 | * |
||
112 | * @param string $conditions Where conditions. |
||
113 | * @param array $values Array of condition values to bind. |
||
114 | * |
||
115 | * @return int Number of entries. |
||
116 | */ |
||
117 | 1 | public function countSoft($conditions = null, $values = []) |
|
123 | |||
124 | |||
125 | /** |
||
126 | * Execute soft-deletion-aware query for selection methods. |
||
127 | * |
||
128 | * @param string $select Selection criteria. |
||
129 | * @param string $conditions Where conditions. |
||
130 | * @param array $values Array of where condition values to bind. |
||
131 | * @param array $options Query options. |
||
132 | * |
||
133 | * @return \Anax\Database\DatabaseQueryBuilder Database service instance with executed internal query. |
||
134 | */ |
||
135 | 11 | protected function executeQuerySoft($select = null, $conditions = null, $values = [], $options = []) |
|
141 | } |
||
142 |