61aad7e52bdb52aa07635073d0cc59e63d86afcc
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\UserProfileRuntimeCache;
7 use wcf\system\comment\CommentHandler;
8 use wcf\system\user\notification\object\CommentUserNotificationObject;
9
10 /**
11 * User notification event for profile comments.
12 *
13 * @author Alexander Ebert
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 *
17 * @method CommentUserNotificationObject getUserNotificationObject()
18 */
19 class UserProfileCommentUserNotificationEvent extends AbstractSharedUserNotificationEvent implements
20 ITestableUserNotificationEvent
21 {
22 use TTestableCommentUserNotificationEvent;
23
24 /**
25 * @inheritDoc
26 */
27 protected $stackable = true;
28
29 /**
30 * @inheritDoc
31 */
32 protected function prepare()
33 {
34 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID);
35 }
36
37 /**
38 * @inheritDoc
39 */
40 public function getTitle(): string
41 {
42 $count = \count($this->getAuthors());
43 if ($count > 1) {
44 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.title.stacked', [
45 'count' => $count,
46 'timesTriggered' => $this->notification->timesTriggered,
47 ]);
48 }
49
50 return $this->getLanguage()->get('wcf.user.notification.comment.title');
51 }
52
53 /**
54 * @inheritDoc
55 */
56 public function getMessage()
57 {
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.comment.message.stacked', [
66 'author' => $this->author,
67 'authors' => \array_values($authors),
68 'commentID' => $this->getUserNotificationObject()->commentID,
69 'count' => $count,
70 'others' => $count - 1,
71 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
72 ]);
73 }
74
75 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.message', [
76 'author' => $this->author,
77 'commentID' => $this->getUserNotificationObject()->commentID,
78 ]);
79 }
80
81 /**
82 * @inheritDoc
83 */
84 public function getEmailMessage($notificationType = 'instant')
85 {
86 return [
87 'message-id' => 'com.woltlab.wcf.user.profileComment.notification/' . $this->getUserNotificationObject()->commentID,
88 'template' => 'email_notification_comment',
89 'application' => 'wcf',
90 'variables' => [
91 'commentID' => $this->getUserNotificationObject()->commentID,
92 'owner' => UserProfileRuntimeCache::getInstance()
93 ->getObject($this->getUserNotificationObject()->objectID),
94 'languageVariablePrefix' => 'wcf.user.notification.comment',
95 ],
96 ];
97 }
98
99 /**
100 * @inheritDoc
101 */
102 public function getLink(): string
103 {
104 return UserProfileRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)->getLink()
105 . '#wall/comment' . $this->getUserNotificationObject()->commentID;
106 }
107
108 /**
109 * @inheritDoc
110 */
111 public function getEventHash()
112 {
113 return \sha1($this->eventID . '-' . $this->notification->userID);
114 }
115
116 /**
117 * @inheritDoc
118 * @since 3.1
119 */
120 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
121 {
122 return [
123 'objectID' => $recipient->userID,
124 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment'),
125 ];
126 }
127 }