31cd9d3fc0bce0a9bfcfe5440026e3d9ec2a74db
[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-2017 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 'responseID' => $this->getUserNotificationObject()->responseID
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_userProfileCommentResponse',
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 ]
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 . '/response' . $this->getUserNotificationObject()->responseID;
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 }