6285e02d008c7eb6796ae44d6036a74632baa51f
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\CommentRuntimeCache;
7 use wcf\system\cache\runtime\UserProfileRuntimeCache;
8 use wcf\system\comment\CommentHandler;
9 use wcf\system\email\Email;
10 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
11
12 /**
13 * User notification event for profile comment responses.
14 *
15 * @author Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 *
19 * @method CommentResponseUserNotificationObject getUserNotificationObject()
20 */
21 class UserProfileCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements
22 ITestableUserNotificationEvent
23 {
24 use TTestableCommentResponseUserNotificationEvent;
25
26 /**
27 * @inheritDoc
28 */
29 protected $stackable = true;
30
31 /**
32 * @inheritDoc
33 */
34 protected function prepare()
35 {
36 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
37 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['objectID']);
38 }
39
40 /**
41 * @inheritDoc
42 */
43 public function getTitle(): string
44 {
45 $count = \count($this->getAuthors());
46 if ($count > 1) {
47 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.title.stacked', [
48 'count' => $count,
49 'timesTriggered' => $this->notification->timesTriggered,
50 ]);
51 }
52
53 return $this->getLanguage()->get('wcf.user.notification.commentResponse.title');
54 }
55
56 /**
57 * @inheritDoc
58 */
59 public function getMessage()
60 {
61 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
62
63 $authors = $this->getAuthors();
64 if (\count($authors) > 1) {
65 if (isset($authors[0])) {
66 unset($authors[0]);
67 }
68 $count = \count($authors);
69
70 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message.stacked', [
71 'authors' => \array_values($authors),
72 'commentID' => $this->getUserNotificationObject()->commentID,
73 'count' => $count,
74 'others' => $count - 1,
75 'owner' => $owner,
76 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
77 ]);
78 }
79
80 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message', [
81 'author' => $this->author,
82 'commentID' => $this->getUserNotificationObject()->commentID,
83 'owner' => $owner,
84 'responseID' => $this->getUserNotificationObject()->responseID,
85 ]);
86 }
87
88 /**
89 * @inheritDoc
90 */
91 public function getEmailMessage($notificationType = 'instant')
92 {
93 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
94 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
95
96 $messageID = '<com.woltlab.wcf.user.profileComment.notification/' . $comment->commentID . '@' . Email::getHost() . '>';
97
98 return [
99 'template' => 'email_notification_commentResponse',
100 'application' => 'wcf',
101 'in-reply-to' => [$messageID],
102 'references' => [$messageID],
103 'variables' => [
104 'commentID' => $this->getUserNotificationObject()->commentID,
105 'owner' => $owner,
106 'responseID' => $this->getUserNotificationObject()->responseID,
107 'languageVariablePrefix' => 'wcf.user.notification.commentResponse',
108 ],
109 ];
110 }
111
112 /**
113 * @inheritDoc
114 */
115 public function getLink(): string
116 {
117 return UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#wall/comment' . $this->getUserNotificationObject()->commentID;
118 }
119
120 /**
121 * @inheritDoc
122 */
123 public function getEventHash()
124 {
125 return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
126 }
127
128 /**
129 * @inheritDoc
130 * @since 3.1
131 */
132 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
133 {
134 return [
135 'objectID' => $author->userID,
136 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment'),
137 ];
138 }
139 }