a927a1b7264691feee4907bda7ca4a934cff1a3c
[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 response 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 UserProfileCommentResponseLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
20 use TTestableCommentResponseLikeUserNotificationEvent;
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 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['commentUserID']);
34 }
35
36 /**
37 * @inheritDoc
38 */
39 public function getTitle() {
40 $count = count($this->getAuthors());
41 if ($count > 1) {
42 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.like.title.stacked', [
43 'count' => $count,
44 'timesTriggered' => $this->notification->timesTriggered
45 ]);
46 }
47
48 return $this->getLanguage()->get('wcf.user.notification.commentResponse.like.title');
49 }
50
51 /**
52 * @inheritDoc
53 */
54 public function getMessage() {
55 $authors = array_values($this->getAuthors());
56 $count = count($authors);
57 $commentUser = $owner = null;
58 if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
59 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
60 }
61 if ($this->additionalData['commentUserID'] != WCF::getUser()->userID) {
62 $commentUser = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['commentUserID']);
63 }
64
65 if ($count > 1) {
66 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.like.message.stacked', [
67 'author' => $this->author,
68 'authors' => $authors,
69 'commentID' => $this->additionalData['commentID'],
70 'commentUser' => $commentUser,
71 'count' => $count,
72 'others' => $count - 1,
73 'owner' => $owner,
74 'responseID' => $this->getResponseID(),
75 'reactions' => $this->getReactionsForAuthors()
76 ]);
77 }
78
79 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.like.message', [
80 'author' => $this->author,
81 'commentID' => $this->additionalData['commentID'],
82 'owner' => $owner,
83 'responseID' => $this->getResponseID(),
84 'userNotificationObject' => $this->getUserNotificationObject(),
85 'reactions' => $this->getReactionsForAuthors()
86 ]);
87 }
88
89 /**
90 * @inheritDoc
91 */
92 public function getEmailMessage($notificationType = 'instant') {
93 throw new \LogicException('Unreachable');
94 }
95
96 /**
97 * @inheritDoc
98 */
99 public function getLink() {
100 $owner = WCF::getUser();
101 if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
102 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
103 }
104
105 return $owner->getLink() . '#wall/comment' . $this->additionalData['commentID'] . '/response' . $this->getResponseID();
106 }
107
108 /**
109 * @inheritDoc
110 */
111 public function getEventHash() {
112 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->objectID);
113 }
114
115 /**
116 * @inheritDoc
117 */
118 public function supportsEmailNotification() {
119 return false;
120 }
121
122 /**
123 * Returns the liked response's id.
124 *
125 * @return integer
126 */
127 protected function getResponseID() {
128 // this is the `wcfN_like.objectID` value
129 return $this->getUserNotificationObject()->objectID;
130 }
131
132 /**
133 * @inheritDoc
134 * @since 3.1
135 */
136 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
137 return [
138 'objectID' => $recipient->userID,
139 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment')
140 ];
141 }
142 }