1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Bus\EventBuilder; |
13
|
|
|
|
14
|
|
|
use Jitamin\Bus\Event\CommentEvent; |
15
|
|
|
use Jitamin\Model\CommentModel; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class CommentEventBuilder. |
19
|
|
|
*/ |
20
|
|
|
class CommentEventBuilder extends BaseEventBuilder |
21
|
|
|
{ |
22
|
|
|
protected $commentId = 0; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Set commentId. |
26
|
|
|
* |
27
|
|
|
* @param int $commentId |
28
|
|
|
* |
29
|
|
|
* @return $this |
30
|
|
|
*/ |
31
|
|
|
public function withCommentId($commentId) |
32
|
|
|
{ |
33
|
|
|
$this->commentId = $commentId; |
34
|
|
|
|
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Build event data. |
40
|
|
|
* |
41
|
|
|
* @return CommentEvent|null |
42
|
|
|
*/ |
43
|
|
|
public function buildEvent() |
44
|
|
|
{ |
45
|
|
|
$comment = $this->commentModel->getById($this->commentId); |
|
|
|
|
46
|
|
|
|
47
|
|
|
if (empty($comment)) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return new CommentEvent([ |
52
|
|
|
'comment' => $comment, |
53
|
|
|
'task' => $this->taskFinderModel->getDetails($comment['task_id']), |
|
|
|
|
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get event title with author. |
59
|
|
|
* |
60
|
|
|
* @param string $author |
61
|
|
|
* @param string $eventName |
62
|
|
|
* @param array $eventData |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function buildTitleWithAuthor($author, $eventName, array $eventData) |
67
|
|
|
{ |
68
|
|
|
switch ($eventName) { |
69
|
|
|
case CommentModel::EVENT_UPDATE: |
70
|
|
|
return l('%s updated a comment on the task #%d', $author, $eventData['task']['id']); |
71
|
|
|
case CommentModel::EVENT_CREATE: |
72
|
|
|
return l('%s commented on the task #%d', $author, $eventData['task']['id']); |
73
|
|
|
case CommentModel::EVENT_DELETE: |
74
|
|
|
return l('%s removed a comment on the task #%d', $author, $eventData['task']['id']); |
75
|
|
|
case CommentModel::EVENT_USER_MENTION: |
76
|
|
|
return l('%s mentioned you in a comment on the task #%d', $author, $eventData['task']['id']); |
77
|
|
|
default: |
78
|
|
|
return ''; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get event title without author. |
84
|
|
|
* |
85
|
|
|
* @param string $eventName |
86
|
|
|
* @param array $eventData |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function buildTitleWithoutAuthor($eventName, array $eventData) |
91
|
|
|
{ |
92
|
|
|
switch ($eventName) { |
93
|
|
|
case CommentModel::EVENT_CREATE: |
94
|
|
|
return l('New comment on task #%d', $eventData['comment']['task_id']); |
95
|
|
|
case CommentModel::EVENT_UPDATE: |
96
|
|
|
return l('Comment updated on task #%d', $eventData['comment']['task_id']); |
97
|
|
|
case CommentModel::EVENT_DELETE: |
98
|
|
|
return l('Comment removed on task #%d', $eventData['comment']['task_id']); |
99
|
|
|
case CommentModel::EVENT_USER_MENTION: |
100
|
|
|
return l('You were mentioned in a comment on the task #%d', $eventData['task']['id']); |
101
|
|
|
default: |
102
|
|
|
return ''; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.