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