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