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