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