|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHPHub\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use McCool\LaravelAutoPresenter\BasePresenter; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class NotificationPresenter. |
|
9
|
|
|
*/ |
|
10
|
|
|
class NotificationPresenter extends BasePresenter |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* 通知类型对应的消息. |
|
14
|
|
|
* |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $type_messages = |
|
18
|
|
|
[ |
|
19
|
|
|
'new_reply' => 'Your topic have new reply', |
|
20
|
|
|
'attention' => 'Attented topic has new reply', |
|
21
|
|
|
'at' => 'Mention you At', |
|
22
|
|
|
'topic_favorite' => 'Favorited your topic', |
|
23
|
|
|
'topic_attent' => 'Attented your topic', |
|
24
|
|
|
'topic_upvote' => 'Up Vote your topic', |
|
25
|
|
|
'reply_upvote' => 'Up Vote your reply', |
|
26
|
|
|
'topic_mark_wiki' => 'has mark your topic as wiki', |
|
27
|
|
|
'topic_mark_excellent' => 'has recomended your topic', |
|
28
|
|
|
'comment_append' => 'Commented topic has new update', |
|
29
|
|
|
'attention_append' => 'Attented topic has new update', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* 解析通知类型对应的消息. |
|
34
|
|
|
* |
|
35
|
|
|
* @return string |
|
36
|
|
|
* |
|
37
|
|
|
* @throws \Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
public function typeMessage() |
|
40
|
|
|
{ |
|
41
|
|
|
if (! array_key_exists($this->wrappedObject->type, $this->type_messages)) { |
|
42
|
|
|
throw new \Exception('Type '.$this->wrappedObject->type.'not exists'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return trans('notification.'.$this->type_messages[$this->wrappedObject->type]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* 拼装完整通知消息. |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \Exception |
|
54
|
|
|
*/ |
|
55
|
|
|
public function message() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->wrappedObject->fromUser->name |
|
58
|
|
|
.' • '.$this->typeMessage() |
|
59
|
|
|
.' • '.$this->wrappedObject->topic->title; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|