Total Complexity | 7 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | trait HasAcceptedAtHelpers |
||
19 | { |
||
20 | public function initializeHasAcceptedAtHelpers(): void |
||
21 | { |
||
22 | $this->dates[] = 'accepted_at'; |
||
|
|||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Set accepted flag. |
||
27 | * |
||
28 | * @return static |
||
29 | */ |
||
30 | public function setAcceptedFlag() |
||
31 | { |
||
32 | $this->setAttribute('accepted_at', Carbon::now()); |
||
33 | |||
34 | return $this; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Unset accepted flag. |
||
39 | * |
||
40 | * @return static |
||
41 | */ |
||
42 | public function unsetAcceptedFlag() |
||
43 | { |
||
44 | $this->setAttribute('accepted_at', null); |
||
45 | |||
46 | return $this; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * If entity is accepted. |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function isAccepted(): bool |
||
55 | { |
||
56 | return !is_null($this->getAttributeValue('accepted_at')); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * If entity is rejected. |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function isRejected(): bool |
||
65 | { |
||
66 | return !$this->isAccepted(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Mark entity as accepted. |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | public function accept(): void |
||
75 | { |
||
76 | $this->setAcceptedFlag()->save(); |
||
77 | |||
78 | $this->fireModelEvent('accepted', false); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Mark entity as rejected. |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | public function reject(): void |
||
91 | } |
||
92 | } |
||
93 |