003cefb68d5a602d87a524b6939f9d1e70383259
[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's owner for 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 UserProfileCommentResponseOwnerUserNotificationEvent 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()->cacheObjectIDs([
38 $this->additionalData['userID'],
39 $this->additionalData['objectID'],
40 ]);
41 }
42
43 /**
44 * @inheritDoc
45 */
46 public function getTitle(): string
47 {
48 $count = \count($this->getAuthors());
49 if ($count > 1) {
50 return $this->getLanguage()->getDynamicVariable(
51 'wcf.user.notification.commentResponseOwner.title.stacked',
52 [
53 'count' => $count,
54 'timesTriggered' => $this->notification->timesTriggered,
55 ]
56 );
57 }
58
59 return $this->getLanguage()->get('wcf.user.notification.commentResponseOwner.title');
60 }
61
62 /**
63 * @inheritDoc
64 */
65 public function getMessage()
66 {
67 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
68 if ($comment->userID) {
69 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
70 } else {
71 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
72 }
73
74 $authors = $this->getAuthors();
75 if (\count($authors) > 1) {
76 if (isset($authors[0])) {
77 unset($authors[0]);
78 }
79 $count = \count($authors);
80
81 return $this->getLanguage()->getDynamicVariable(
82 'wcf.user.notification.commentResponseOwner.message.stacked',
83 [
84 'author' => $commentAuthor,
85 'authors' => \array_values($authors),
86 'count' => $count,
87 'others' => $count - 1,
88 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
89 'commentID' => $this->getUserNotificationObject()->commentID,
90 ]
91 );
92 }
93
94 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message', [
95 'author' => $this->author,
96 'commentAuthor' => $commentAuthor,
97 'commentID' => $this->getUserNotificationObject()->commentID,
98 'responseID' => $this->getUserNotificationObject()->responseID,
99 ]);
100 }
101
102 /**
103 * @inheritDoc
104 */
105 public function getEmailMessage($notificationType = 'instant')
106 {
107 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
108 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
109 if ($comment->userID) {
110 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
111 } else {
112 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
113 }
114
115 $messageID = '<com.woltlab.wcf.user.profileComment.notification/' . $comment->commentID . '@' . Email::getHost() . '>';
116
117 return [
118 'template' => 'email_notification_commentResponseOwner',
119 'application' => 'wcf',
120 'in-reply-to' => [$messageID],
121 'references' => [$messageID],
122 'variables' => [
123 'commentAuthor' => $commentAuthor,
124 'commentID' => $this->getUserNotificationObject()->commentID,
125 'owner' => $owner,
126 'responseID' => $this->getUserNotificationObject()->responseID,
127 'languageVariablePrefix' => 'wcf.user.notification.commentResponseOwner',
128 ],
129 ];
130 }
131
132 /**
133 * @inheritDoc
134 */
135 public function getLink(): string
136 {
137 return UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink()
138 . '#wall/comment' . $this->getUserNotificationObject()->commentID;
139 }
140
141 /**
142 * @inheritDoc
143 */
144 public function getEventHash()
145 {
146 return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
147 }
148
149 /**
150 * @inheritDoc
151 * @since 3.1
152 */
153 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
154 {
155 return [
156 'objectID' => $recipient->userID,
157 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment'),
158 ];
159 }
160 }