1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xetaravel\Models\Presenters; |
6
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute; |
8
|
|
|
use Xetaravel\Events\Discuss\CategoryWasChangedEvent; |
9
|
|
|
use Xetaravel\Events\Discuss\ConversationWasLockedEvent; |
10
|
|
|
use Xetaravel\Events\Discuss\ConversationWasPinnedEvent; |
11
|
|
|
use Xetaravel\Events\Discuss\PostWasDeletedEvent; |
12
|
|
|
use Xetaravel\Events\Discuss\TitleWasChangedEvent; |
13
|
|
|
use Xetaravel\Models\DiscussCategory; |
14
|
|
|
use Xetaravel\Models\User; |
15
|
|
|
|
16
|
|
|
trait DiscussLogPresenter |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Get the type related to the Event. |
20
|
|
|
* |
21
|
|
|
* @return Attribute |
22
|
|
|
*/ |
23
|
|
|
protected function type(): Attribute |
24
|
|
|
{ |
25
|
|
|
return Attribute::make( |
26
|
|
|
get: fn () => match ($this->event_type) { |
27
|
|
|
CategoryWasChangedEvent::class => 'category', |
28
|
|
|
TitleWasChangedEvent::class => 'title', |
29
|
|
|
ConversationWasLockedEvent::class => 'locked', |
30
|
|
|
ConversationWasPinnedEvent::class => 'pinned', |
31
|
|
|
PostWasDeletedEvent::class => 'deleted', |
32
|
|
|
default => 'unknown', |
33
|
|
|
} |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get the user related to the deleted post. |
39
|
|
|
* |
40
|
|
|
* @return Attribute |
41
|
|
|
*/ |
42
|
|
|
protected function postUser(): Attribute |
43
|
|
|
{ |
44
|
|
|
return Attribute::make( |
45
|
|
|
get: fn () => $this->event_type !== PostWasDeletedEvent::class ? null : User::find($this->data['post_user_id']) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the old category. |
51
|
|
|
* |
52
|
|
|
* @return Attribute |
53
|
|
|
*/ |
54
|
|
|
protected function oldCategory(): Attribute |
55
|
|
|
{ |
56
|
|
|
return Attribute::make( |
57
|
|
|
get: fn () => $this->event_type !== CategoryWasChangedEvent::class ? null : DiscussCategory::find($this->data['old']) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the new category. |
63
|
|
|
* |
64
|
|
|
* @return Attribute |
65
|
|
|
*/ |
66
|
|
|
protected function newCategory(): Attribute |
67
|
|
|
{ |
68
|
|
|
return Attribute::make( |
69
|
|
|
get: fn () => $this->event_type !== CategoryWasChangedEvent::class ? null : DiscussCategory::find($this->data['new']) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|