|
1
|
|
|
<?php |
|
2
|
|
|
namespace Xetaravel\Models\Presenters; |
|
3
|
|
|
|
|
4
|
|
|
use Xetaravel\Events\Discuss\CategoryWasChangedEvent; |
|
5
|
|
|
use Xetaravel\Events\Discuss\ConversationWasLockedEvent; |
|
6
|
|
|
use Xetaravel\Events\Discuss\ConversationWasPinnedEvent; |
|
7
|
|
|
use Xetaravel\Events\Discuss\PostWasDeletedEvent; |
|
8
|
|
|
use Xetaravel\Events\Discuss\TitleWasChangedEvent; |
|
9
|
|
|
use Xetaravel\Models\DiscussCategory; |
|
10
|
|
|
use Xetaravel\Models\User; |
|
11
|
|
|
|
|
12
|
|
|
trait DiscussLogPresenter |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Get the type related to the Event. |
|
16
|
|
|
* |
|
17
|
|
|
* @return string |
|
|
|
|
|
|
18
|
|
|
*/ |
|
19
|
|
|
public function getTypeAttribute() |
|
20
|
|
|
{ |
|
21
|
|
|
switch ($this->event_type) { |
|
|
|
|
|
|
22
|
|
|
case CategoryWasChangedEvent::class: |
|
23
|
|
|
return 'category'; |
|
24
|
|
|
break; |
|
|
|
|
|
|
25
|
|
|
case TitleWasChangedEvent::class: |
|
26
|
|
|
return 'title'; |
|
27
|
|
|
break; |
|
|
|
|
|
|
28
|
|
|
case ConversationWasLockedEvent::class: |
|
29
|
|
|
return 'locked'; |
|
30
|
|
|
break; |
|
|
|
|
|
|
31
|
|
|
case ConversationWasPinnedEvent::class: |
|
32
|
|
|
return 'pinned'; |
|
33
|
|
|
break; |
|
|
|
|
|
|
34
|
|
|
case PostWasDeletedEvent::class: |
|
35
|
|
|
return 'deleted'; |
|
36
|
|
|
break; |
|
|
|
|
|
|
37
|
|
|
default: |
|
38
|
|
|
return 'unknown'; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the user related to the deleted post. |
|
44
|
|
|
* |
|
45
|
|
|
* @return null|\Xetaravel\Models\User |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getPostUserAttribute() |
|
48
|
|
|
{ |
|
49
|
|
|
if ($this->event_type !== PostWasDeletedEvent::class) { |
|
50
|
|
|
return null; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return User::find($this->data['post_user_id']); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the old category. |
|
58
|
|
|
* |
|
59
|
|
|
* @return null|\Xetaravel\Models\DiscussCategory |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
public function getOldCategoryAttribute() |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
if ($this->event_type !== CategoryWasChangedEvent::class) { |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return DiscussCategory::find($this->data['old']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the new category. |
|
72
|
|
|
* |
|
73
|
|
|
* @return null|\Xetaravel\Models\DiscussCategory |
|
74
|
|
|
*/ |
|
75
|
|
View Code Duplication |
public function getNewCategoryAttribute() |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
if ($this->event_type !== CategoryWasChangedEvent::class) { |
|
78
|
|
|
return null; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return DiscussCategory::find($this->data['new']); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.