Total Complexity | 7 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | trait HasDraftedAtHelpers |
||
19 | { |
||
20 | public function initializeHasDraftedAtHelpers(): void |
||
21 | { |
||
22 | $this->dates[] = 'drafted_at'; |
||
|
|||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Set drafted flag. |
||
27 | * |
||
28 | * @return static |
||
29 | */ |
||
30 | public function setDraftedFlag() |
||
31 | { |
||
32 | $this->setAttribute('drafted_at', Carbon::now()); |
||
33 | |||
34 | return $this; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Unset drafted flag. |
||
39 | * |
||
40 | * @return static |
||
41 | */ |
||
42 | public function unsetDraftedFlag() |
||
43 | { |
||
44 | $this->setAttribute('drafted_at', null); |
||
45 | |||
46 | return $this; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * If entity is drafted. |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function isDrafted(): bool |
||
55 | { |
||
56 | return !is_null($this->getAttributeValue('drafted_at')); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * If entity is opened. |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function isUndrafted(): bool |
||
65 | { |
||
66 | return !$this->isDrafted(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Mark entity as drafted. |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | public function draft(): void |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Mark entity as opened. |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | public function undraft(): void |
||
93 |