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