1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Mvc\Model\Blameable; |
13
|
|
|
|
14
|
|
|
use Zemit\Mvc\Model; |
15
|
|
|
use Zemit\Mvc\Model\AbstractTrait\AbstractBehavior; |
16
|
|
|
use Zemit\Mvc\Model\Behavior\Transformable; |
17
|
|
|
use Zemit\Mvc\Model\Identity; |
18
|
|
|
use Zemit\Mvc\Model\Options; |
19
|
|
|
use Zemit\Mvc\Model\Snapshots; |
20
|
|
|
use Zemit\Mvc\Model\SoftDelete; |
21
|
|
|
|
22
|
|
|
trait Restored |
23
|
|
|
{ |
24
|
|
|
use AbstractBehavior; |
25
|
|
|
use Options; |
26
|
|
|
use Identity; |
27
|
|
|
use Snapshots; |
28
|
|
|
use SoftDelete; |
29
|
|
|
|
30
|
|
|
public Transformable $restoredBehavior; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Initializing Restored |
34
|
|
|
*/ |
35
|
|
|
public function initializeRestored(?array $options = null): void |
36
|
|
|
{ |
37
|
|
|
$options ??= $this->getOptionsManager()->get('restored') ?? []; |
38
|
|
|
|
39
|
|
|
$fieldBy = $options['fieldBy'] ?? 'restoredBy'; |
40
|
|
|
$fieldAs = $options['fieldAs'] ?? 'restoredAs'; |
41
|
|
|
$fieldAt = $options['fieldAt'] ?? 'restoredAt'; |
42
|
|
|
|
43
|
|
|
$this->setRestoredBehavior(new Transformable([ |
44
|
|
|
'beforeRestore' => [ |
45
|
|
|
$fieldBy => $this->getCurrentUserIdCallback(), |
46
|
|
|
$fieldAs => $this->getCurrentUserIdCallback(true), |
47
|
|
|
$fieldAt => date(Model::DATETIME_FORMAT), |
48
|
|
|
], |
49
|
|
|
])); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set Restored Behavior |
54
|
|
|
*/ |
55
|
|
|
public function setRestoredBehavior(Transformable $restoredBehavior): void |
56
|
|
|
{ |
57
|
|
|
$this->restoredBehavior = $restoredBehavior; |
58
|
|
|
$this->addBehavior($this->restoredBehavior); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get Restored Behavior |
63
|
|
|
*/ |
64
|
|
|
public function getRestoredBehavior(): Transformable |
65
|
|
|
{ |
66
|
|
|
return $this->restoredBehavior; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|