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