17f407ccdf55d18566f0acf7ad78c81c7ba81577
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\page\PageCache;
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\CommentUserNotificationObject;
10
11 /**
12 * User notification event for page comments.
13 *
14 * @author Joshua Rusweg
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 * @since 3.2
19 *
20 * @method CommentUserNotificationObject getUserNotificationObject()
21 */
22 class PageCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
23 use TTestableCommentResponseUserNotificationEvent;
24 use TTestablePageUserNotificationEvent;
25
26 /**
27 * @inheritDoc
28 */
29 protected $stackable = true;
30
31 /**
32 * @inheritDoc
33 */
34 protected function prepare() {
35 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
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.pageComment.response.title.stacked', [
45 'count' => $count,
46 'timesTriggered' => $this->notification->timesTriggered
47 ]);
48 }
49
50 return $this->getLanguage()->get('wcf.user.notification.pageComment.response.title');
51 }
52
53 /**
54 * @inheritDoc
55 */
56 public function getMessage() {
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.pageComment.response.message.stacked', [
65 'author' => $this->author,
66 'authors' => array_values($authors),
67 'commentID' => $this->getUserNotificationObject()->commentID,
68 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
69 'count' => $count,
70 'others' => $count - 1,
71 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
72 'commentAuthor' => $this->getCommentAuthorProfile()
73 ]);
74 }
75
76 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.response.message', [
77 'author' => $this->author,
78 'commentID' => $this->getUserNotificationObject()->commentID,
79 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
80 'responseID' => $this->getUserNotificationObject()->responseID,
81 'commentAuthor' => $this->getCommentAuthorProfile()
82 ]);
83 }
84
85 /**
86 * @inheritDoc
87 */
88 public function getEmailMessage($notificationType = 'instant') {
89 $messageID = '<com.woltlab.wcf.user.pageComment.notification/'.$this->getUserNotificationObject()->commentID.'@'.Email::getHost().'>';
90
91 return [
92 'template' => 'email_notification_commentResponse',
93 'in-reply-to' => [$messageID],
94 'references' => [$messageID],
95 'application' => 'wcf',
96 'variables' => [
97 'commentID' => $this->getUserNotificationObject()->commentID,
98 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
99 'languageVariablePrefix' => 'wcf.user.notification.pageComment.response',
100 'responseID' => $this->getUserNotificationObject()->responseID,
101 'commentAuthor' => $this->getCommentAuthorProfile()
102 ]
103 ];
104 }
105
106 /**
107 * Returns the comment authors profile.
108 *
109 * @return UserProfile
110 */
111 private function getCommentAuthorProfile() {
112 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
113
114 if ($comment->userID) {
115 return UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
116 }
117 else {
118 return UserProfile::getGuestUserProfile($comment->username);
119 }
120 }
121
122 /**
123 * @inheritDoc
124 */
125 public function getLink() {
126 return PageCache::getInstance()->getPage($this->additionalData['objectID'])->getLink() . '#comment'. $this->getUserNotificationObject()->commentID;
127 }
128
129 /**
130 * @inheritDoc
131 */
132 public function getEventHash() {
133 return sha1($this->eventID . '-' . $this->notification->objectID);
134 }
135
136 /**
137 * @inheritDoc
138 */
139 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
140 return [
141 'objectID' => self::getTestPage()->pageID,
142 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.page')
143 ];
144 }
145 }