808dbbe9ca6c7ac261f93a5481e4e8cf42eb17c2
[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 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 UserProfileCommentLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
21 use TTestableCommentLikeUserNotificationEvent;
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 }
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 'reactions' => $this->getReactionsForAuthors()
71 ]);
72 }
73
74 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.like.message', [
75 'author' => $this->author,
76 'commentID' => $this->getCommentID(),
77 'owner' => $owner,
78 'userNotificationObject' => $this->getUserNotificationObject(),
79 'reactions' => $this->getReactionsForAuthors()
80 ]);
81 }
82
83 /**
84 * @inheritDoc
85 */
86 public function getEmailMessage($notificationType = 'instant') {
87 throw new \LogicException('Unreachable');
88 }
89
90 /**
91 * @inheritDoc
92 */
93 public function getLink() {
94 $owner = WCF::getUser();
95 if ($this->additionalData['objectID'] != WCF::getUser()->userID) {
96 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
97 }
98
99 return LinkHandler::getInstance()->getLink('User', ['object' => $owner], '#wall/comment' . $this->getCommentID());
100 }
101
102 /**
103 * @inheritDoc
104 */
105 public function getEventHash() {
106 return sha1($this->eventID . '-' . $this->getCommentID());
107 }
108
109 /**
110 * @inheritDoc
111 */
112 public function supportsEmailNotification() {
113 return false;
114 }
115
116 /**
117 * Returns the liked comment's id.
118 *
119 * @return integer
120 */
121 protected function getCommentID() {
122 // this is the `wcfN_like.objectID` value
123 return $this->getUserNotificationObject()->objectID;
124 }
125
126 /**
127 * @inheritDoc
128 * @since 3.1
129 */
130 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
131 return [
132 'objectID' => $recipient->userID,
133 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment')
134 ];
135 }
136 }