fbe6f3791c03347f74a2151317b778c193f16b9a
[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\user\notification\object\CommentResponseUserNotificationObject;
10
11 /**
12 * User notification event for profile 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 UserProfileCommentResponseUserNotificationEvent 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()->cacheObjectID($this->additionalData['objectID']);
35 }
36
37 /**
38 * @inheritDoc
39 */
40 public function getTitle() {
41 $count = count($this->getAuthors());
42 if ($count > 1) {
43 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.title.stacked', [
44 'count' => $count,
45 'timesTriggered' => $this->notification->timesTriggered
46 ]);
47 }
48
49 return $this->getLanguage()->get('wcf.user.notification.commentResponse.title');
50 }
51
52 /**
53 * @inheritDoc
54 */
55 public function getMessage() {
56 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
57
58 $authors = $this->getAuthors();
59 if (count($authors) > 1) {
60 if (isset($authors[0])) {
61 unset($authors[0]);
62 }
63 $count = count($authors);
64
65 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message.stacked', [
66 'authors' => array_values($authors),
67 'commentID' => $this->getUserNotificationObject()->commentID,
68 'count' => $count,
69 'others' => $count - 1,
70 'owner' => $owner,
71 'guestTimesTriggered' => $this->notification->guestTimesTriggered
72 ]);
73 }
74
75 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message', [
76 'author' => $this->author,
77 'commentID' => $this->getUserNotificationObject()->commentID,
78 'owner' => $owner,
79 'responseID' => $this->getUserNotificationObject()->responseID
80 ]);
81 }
82
83 /**
84 * @inheritDoc
85 */
86 public function getEmailMessage($notificationType = 'instant') {
87 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
88 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
89
90 $messageID = '<com.woltlab.wcf.user.profileComment.notification/'.$comment->commentID.'@'.Email::getHost().'>';
91
92 return [
93 'template' => 'email_notification_commentResponse',
94 'application' => 'wcf',
95 'in-reply-to' => [$messageID],
96 'references' => [$messageID],
97 'variables' => [
98 'commentID' => $this->getUserNotificationObject()->commentID,
99 'owner' => $owner,
100 'responseID' => $this->getUserNotificationObject()->responseID,
101 'languageVariablePrefix' => 'wcf.user.notification.commentResponse'
102 ]
103 ];
104 }
105
106 /**
107 * @inheritDoc
108 */
109 public function getLink() {
110 return UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#wall/comment' . $this->getUserNotificationObject()->commentID;
111 }
112
113 /**
114 * @inheritDoc
115 */
116 public function getEventHash() {
117 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
118 }
119
120 /**
121 * @inheritDoc
122 * @since 3.1
123 */
124 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
125 return [
126 'objectID' => $author->userID,
127 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment')
128 ];
129 }
130 }