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