e761464c13d23791fab3549c84bf6c787a2cff6e
[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\user\notification\object\LikeUserNotificationObject;
7 use wcf\system\WCF;
8
9 /**
10 * User notification event for profile comment likes.
11 *
12 * @author Alexander Ebert
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 *
17 * @method LikeUserNotificationObject getUserNotificationObject()
18 */
19 class UserProfileCommentLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
20 use TTestableCommentLikeUserNotificationEvent;
21 use TReactionUserNotificationEvent;
22
23 /**
24 * @inheritDoc
25 */
26 protected $stackable = true;
27
28 /**
29 * @inheritDoc
30 */
31 protected function prepare() {
32 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['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.like.title.stacked', [
42 'count' => $count,
43 'timesTriggered' => $this->notification->timesTriggered
44 ]);
45 }
46
47 return $this->getLanguage()->get('wcf.user.notification.comment.like.title');
48 }
49
50 /**
51 * @inheritDoc
52 */
53 public function getMessage() {
54 $authors = array_values($this->getAuthors());
55 $count = count($authors);
56 $owner = null;
57 if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
58 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
59 }
60
61 if ($count > 1) {
62 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.like.message.stacked', [
63 'author' => $this->author,
64 'authors' => $authors,
65 'commentID' => $this->getCommentID(),
66 'count' => $count,
67 'others' => $count - 1,
68 'owner' => $owner,
69 'reactions' => $this->getReactionsForAuthors()
70 ]);
71 }
72
73 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.like.message', [
74 'author' => $this->author,
75 'commentID' => $this->getCommentID(),
76 'owner' => $owner,
77 'userNotificationObject' => $this->getUserNotificationObject(),
78 'reactions' => $this->getReactionsForAuthors()
79 ]);
80 }
81
82 /**
83 * @inheritDoc
84 */
85 public function getEmailMessage($notificationType = 'instant') {
86 throw new \LogicException('Unreachable');
87 }
88
89 /**
90 * @inheritDoc
91 */
92 public function getLink() {
93 $owner = WCF::getUser();
94 if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
95 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
96 }
97
98 return $owner->getLink() . '#wall/comment' . $this->getCommentID();
99 }
100
101 /**
102 * @inheritDoc
103 */
104 public function getEventHash() {
105 return sha1($this->eventID . '-' . $this->getCommentID());
106 }
107
108 /**
109 * @inheritDoc
110 */
111 public function supportsEmailNotification() {
112 return false;
113 }
114
115 /**
116 * Returns the liked comment's id.
117 *
118 * @return integer
119 */
120 protected function getCommentID() {
121 // this is the `wcfN_like.objectID` value
122 return $this->getUserNotificationObject()->objectID;
123 }
124
125 /**
126 * @inheritDoc
127 * @since 3.1
128 */
129 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
130 return [
131 'objectID' => $recipient->userID,
132 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment')
133 ];
134 }
135 }