9cb8be9316d61d78e0019c839f5c791184f058d9
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\article\category\ArticleCategory;
4 use wcf\data\user\UserProfile;
5 use wcf\system\cache\runtime\CommentRuntimeCache;
6 use wcf\system\cache\runtime\UserProfileRuntimeCache;
7 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
8 use wcf\system\comment\CommentHandler;
9 use wcf\system\email\Email;
10 use wcf\system\user\notification\object\CommentUserNotificationObject;
11
12 /**
13 * User notification event for article comment responses.
14 *
15 * @author Joshua Ruesweg
16 * @copyright 2001-2019 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 * @since 5.2
20 *
21 * @method CommentUserNotificationObject getUserNotificationObject()
22 */
23 class ArticleCommentResponseOwnerUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
24 use TTestableCommentResponseUserNotificationEvent;
25 use TTestableArticleUserNotificationEvent;
26 use TTestableCategorizedUserNotificationEvent;
27
28 /**
29 * @inheritDoc
30 */
31 protected $stackable = true;
32
33 /**
34 * @inheritDoc
35 */
36 protected function prepare() {
37 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
38 }
39
40 /**
41 * @inheritDoc
42 */
43 public function getTitle() {
44 $count = count($this->getAuthors());
45 if ($count > 1) {
46 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.title.stacked', [
47 'count' => $count,
48 'timesTriggered' => $this->notification->timesTriggered
49 ]);
50 }
51
52 return $this->getLanguage()->get('wcf.user.notification.articleComment.responseOwner.title');
53 }
54
55 /**
56 * @inheritDoc
57 */
58 public function getMessage() {
59 $authors = $this->getAuthors();
60 if (count($authors) > 1) {
61 if (isset($authors[0])) {
62 unset($authors[0]);
63 }
64 $count = count($authors);
65
66 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.message.stacked', [
67 'author' => $this->author,
68 'authors' => array_values($authors),
69 'commentID' => $this->getUserNotificationObject()->commentID,
70 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
71 'count' => $count,
72 'others' => $count - 1,
73 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
74 'responseID' => $this->getUserNotificationObject()->responseID,
75 'commentAuthor' => $this->getCommentAuthorProfile()
76 ]);
77 }
78
79 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.message', [
80 'author' => $this->author,
81 'commentID' => $this->getUserNotificationObject()->commentID,
82 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
83 'responseID' => $this->getUserNotificationObject()->responseID,
84 'commentAuthor' => $this->getCommentAuthorProfile()
85 ]);
86 }
87
88 /**
89 * @inheritDoc
90 */
91 public function getEmailMessage($notificationType = 'instant') {
92 $messageID = '<com.woltlab.wcf.user.articleComment.notification/'.$this->getUserNotificationObject()->commentID.'@'.Email::getHost().'>';
93
94 return [
95 'template' => 'email_notification_commentResponseOwner',
96 'in-reply-to' => [$messageID],
97 'references' => [$messageID],
98 'application' => 'wcf',
99 'variables' => [
100 'commentID' => $this->getUserNotificationObject()->commentID,
101 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
102 'languageVariablePrefix' => 'wcf.user.notification.articleComment.responseOwner',
103 'responseID' => $this->getUserNotificationObject()->responseID,
104 'commentAuthor' => $this->getCommentAuthorProfile(),
105 ]
106 ];
107 }
108
109 /**
110 * Returns the comment authors profile.
111 *
112 * @return UserProfile
113 */
114 private function getCommentAuthorProfile() {
115 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
116
117 if ($comment->userID) {
118 return UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
119 }
120 else {
121 return UserProfile::getGuestUserProfile($comment->username);
122 }
123 }
124
125 /**
126 * @inheritDoc
127 */
128 public function getLink() {
129 return ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#comment'. $this->getUserNotificationObject()->commentID;
130 }
131
132 /**
133 * @inheritDoc
134 */
135 public function getEventHash() {
136 return sha1($this->eventID . '-' . $this->notification->objectID);
137 }
138
139 /**
140 * @inheritDoc
141 */
142 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
143 return [
144 'objectID' => self::getTestArticle(self::createTestCategory(ArticleCategory::OBJECT_TYPE_NAME), $author)->articleID,
145 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.articleComment')
146 ];
147 }
148 }