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