1e0016ed073ec0336a2bca19a58698e80f30bfef
[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\LikeUserNotificationObject;
9 use wcf\system\WCF;
10
11 /**
12 * User notification event for profile comment likes.
13 *
14 * @author Alexander Ebert
15 * @copyright 2001-2018 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\User\Notification\Event
18 *
19 * @method LikeUserNotificationObject getUserNotificationObject()
20 */
21 class UserProfileCommentLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
22 use TTestableCommentLikeUserNotificationEvent;
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 }
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.comment.like.title.stacked', [
43 'count' => $count,
44 'timesTriggered' => $this->notification->timesTriggered
45 ]);
46 }
47
48 return $this->getLanguage()->get('wcf.user.notification.comment.like.title');
49 }
50
51 /**
52 * @inheritDoc
53 */
54 public function getMessage() {
55 $authors = array_values($this->getAuthors());
56 $count = count($authors);
57 $owner = null;
58 if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
59 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
60 }
61
62 if ($count > 1) {
63 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.like.message.stacked', [
64 'author' => $this->author,
65 'authors' => $authors,
66 'commentID' => $this->getCommentID(),
67 'count' => $count,
68 'others' => $count - 1,
69 'owner' => $owner
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 ]);
78 }
79
80 /**
81 * @inheritDoc
82 */
83 public function getEmailMessage($notificationType = 'instant') {
84 throw new \LogicException('Unreachable');
85 }
86
87 /**
88 * @inheritDoc
89 */
90 public function getLink() {
91 $owner = WCF::getUser();
92 if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
93 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
94 }
95
96 return LinkHandler::getInstance()->getLink('User', ['object' => $owner], '#wall/comment' . $this->getCommentID());
97 }
98
99 /**
100 * @inheritDoc
101 */
102 public function getEventHash() {
103 return sha1($this->eventID . '-' . $this->getCommentID());
104 }
105
106 /**
107 * @inheritDoc
108 */
109 public function supportsEmailNotification() {
110 return false;
111 }
112
113 /**
114 * Returns the liked comment's id.
115 *
116 * @return integer
117 */
118 protected function getCommentID() {
119 // this is the `wcfN_like.objectID` value
120 return $this->getUserNotificationObject()->objectID;
121 }
122
123 /**
124 * @inheritDoc
125 * @since 3.1
126 */
127 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
128 return [
129 'objectID' => $recipient->userID,
130 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment')
131 ];
132 }
133 }