1 | <?php |
||
34 | class SoftDeleteBehavior extends Behavior |
||
35 | { |
||
36 | /** |
||
37 | * @var string SoftDelete attribute |
||
38 | */ |
||
39 | public $attribute = 'deleted_at'; |
||
40 | |||
41 | /** |
||
42 | * @var callable|Expression The expression that will be used for generating the timestamp. |
||
43 | * This can be either an anonymous function that returns the timestamp value, |
||
44 | * or an [[Expression]] object representing a DB expression (e.g. `new Expression('NOW()')`). |
||
45 | * If not set, it will use the value of `time()` to set the attributes. |
||
46 | */ |
||
47 | public $value; |
||
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | 10 | public function events() |
|
56 | |||
57 | /** |
||
58 | * Set the attribute with the current timestamp to mark as deleted |
||
59 | * |
||
60 | * @param Event $event |
||
61 | */ |
||
62 | 4 | public function softDeleteEvent($event) |
|
68 | |||
69 | /** |
||
70 | * Soft delete record |
||
71 | */ |
||
72 | 5 | public function softDelete() |
|
80 | |||
81 | /** |
||
82 | * Restore record |
||
83 | */ |
||
84 | 2 | public function unDelete() |
|
92 | |||
93 | /** |
||
94 | * Delete record from database regardless of the $safeMode attribute |
||
95 | */ |
||
96 | 2 | public function hardDelete() |
|
104 | |||
105 | /** |
||
106 | * Evaluate the timestamp to be saved. |
||
107 | * |
||
108 | * @param Event|null $event the event that triggers the current attribute updating. |
||
109 | * @return mixed the attribute value |
||
110 | */ |
||
111 | 5 | protected function getValue($event) |
|
119 | |||
120 | } |
||
121 |