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