5a0680344d2b3c6613d9fa938cf38e725fb251ba
[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\ViewableArticleRuntimeCache;
6 use wcf\system\comment\CommentHandler;
7 use wcf\system\user\notification\object\CommentUserNotificationObject;
8
9 /**
10 * User notification event for article comments.
11 *
12 * @author Joshua Ruesweg
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\User\Notification\Event
16 * @since 5.2
17 *
18 * @method CommentUserNotificationObject getUserNotificationObject()
19 */
20 class ArticleCommentUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
21 use TTestableCommentUserNotificationEvent;
22 use TTestableArticleUserNotificationEvent;
23 use TTestableCategorizedUserNotificationEvent;
24
25 /**
26 * @inheritDoc
27 */
28 protected $stackable = true;
29
30 /**
31 * @inheritDoc
32 */
33 protected function prepare() {
34 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID);
35 }
36
37 /**
38 * @inheritDoc
39 */
40 public function getTitle() {
41 $count = count($this->getAuthors());
42 if ($count > 1) {
43 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.title.stacked', [
44 'count' => $count,
45 'timesTriggered' => $this->notification->timesTriggered
46 ]);
47 }
48
49 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.title');
50 }
51
52 /**
53 * @inheritDoc
54 */
55 public function getMessage() {
56 $authors = $this->getAuthors();
57 if (count($authors) > 1) {
58 if (isset($authors[0])) {
59 unset($authors[0]);
60 }
61 $count = count($authors);
62
63 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.message.stacked', [
64 'author' => $this->author,
65 'authors' => array_values($authors),
66 'commentID' => $this->getUserNotificationObject()->commentID,
67 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID),
68 'count' => $count,
69 'others' => $count - 1,
70 'guestTimesTriggered' => $this->notification->guestTimesTriggered
71 ]);
72 }
73
74 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.message', [
75 'author' => $this->author,
76 'commentID' => $this->getUserNotificationObject()->commentID,
77 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)
78 ]);
79 }
80
81 /**
82 * @inheritDoc
83 */
84 public function getEmailMessage($notificationType = 'instant') {
85 return [
86 'message-id' => 'com.woltlab.wcf.user.articleComment.notification/'.$this->getUserNotificationObject()->commentID,
87 'template' => 'email_notification_comment',
88 'application' => 'wcf',
89 'variables' => [
90 'commentID' => $this->getUserNotificationObject()->commentID,
91 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID),
92 'languageVariablePrefix' => 'wcf.user.notification.articleComment'
93 ]
94 ];
95 }
96
97 /**
98 * @inheritDoc
99 */
100 public function getLink() {
101 return ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)->getLink() . '#comment'. $this->getUserNotificationObject()->commentID;
102 }
103
104 /**
105 * @inheritDoc
106 */
107 public function getEventHash() {
108 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->objectID);
109 }
110
111 /**
112 * @inheritDoc
113 */
114 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
115 return [
116 'objectID' => self::getTestArticle(self::createTestCategory(ArticleCategory::OBJECT_TYPE_NAME), $author)->articleID,
117 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.articleComment')
118 ];
119 }
120 }