0bfa19f87e95e000c642c2083813bd187527af53
[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\ViewableArticleRuntimeCache;
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 article comment responses.
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 5.2
19 *
20 * @method CommentUserNotificationObject getUserNotificationObject()
21 */
22 class ArticleCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
23 use TTestableCommentResponseUserNotificationEvent;
24 use TTestableArticleUserNotificationEvent;
25 use TTestableCategorizedUserNotificationEvent;
26
27 /**
28 * @inheritDoc
29 */
30 protected $stackable = true;
31
32 /**
33 * @inheritDoc
34 */
35 protected function prepare() {
36 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
37 }
38
39 /**
40 * @inheritDoc
41 */
42 public function getTitle() {
43 $count = count($this->getAuthors());
44 if ($count > 1) {
45 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.response.title.stacked', [
46 'count' => $count,
47 'timesTriggered' => $this->notification->timesTriggered
48 ]);
49 }
50
51 return $this->getLanguage()->get('wcf.user.notification.articleComment.response.title');
52 }
53
54 /**
55 * @inheritDoc
56 */
57 public function getMessage() {
58 $authors = $this->getAuthors();
59 if (count($authors) > 1) {
60 if (isset($authors[0])) {
61 unset($authors[0]);
62 }
63 $count = count($authors);
64
65 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.response.message.stacked', [
66 'author' => $this->author,
67 'authors' => array_values($authors),
68 'commentID' => $this->getUserNotificationObject()->commentID,
69 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
70 'count' => $count,
71 'others' => $count - 1,
72 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
73 'responseID' => $this->getUserNotificationObject()->responseID
74 ]);
75 }
76
77 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.response.message', [
78 'author' => $this->author,
79 'commentID' => $this->getUserNotificationObject()->commentID,
80 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
81 'responseID' => $this->getUserNotificationObject()->responseID
82 ]);
83 }
84
85 /**
86 * @inheritDoc
87 */
88 public function getEmailMessage($notificationType = 'instant') {
89 $messageID = '<com.woltlab.wcf.user.articleComment.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 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
99 'languageVariablePrefix' => 'wcf.user.notification.articleComment.response',
100 'responseID' => $this->getUserNotificationObject()->responseID
101 ]
102 ];
103 }
104
105 /**
106 * @inheritDoc
107 */
108 public function getLink() {
109 return ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#comment'. $this->getUserNotificationObject()->commentID;
110 }
111
112 /**
113 * @inheritDoc
114 */
115 public function getEventHash() {
116 return sha1($this->eventID . '-' . $this->notification->objectID);
117 }
118
119 /**
120 * @inheritDoc
121 */
122 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
123 return [
124 'objectID' => self::getTestArticle(self::createTestCategory(ArticleCategory::OBJECT_TYPE_NAME), $author)->articleID,
125 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.articleComment')
126 ];
127 }
128 }