c52a86333198c88861af30080afd08102991bfd7
[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 'responseID' => $this->getUserNotificationObject()->responseID
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_userProfileCommentResponseOwner',
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 ]
117 ];
118 }
119
120 /**
121 * @inheritDoc
122 */
123 public function getLink() {
124 return LinkHandler::getInstance()->getLink(
125 'User',
126 ['object' => WCF::getUser()],
127 '#wall/comment' . $this->getUserNotificationObject()->commentID . '/response' . $this->getUserNotificationObject()->responseID
128 );
129 }
130
131 /**
132 * @inheritDoc
133 */
134 public function getEventHash() {
135 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
136 }
137
138 /**
139 * @inheritDoc
140 * @since 3.1
141 */
142 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
143 return [
144 'objectID' => $recipient->userID,
145 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment')
146 ];
147 }
148 }