fb5309fccb808c2812f65b6ce89001db516ed738
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\comment\Comment;
4 use wcf\data\user\User;
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\CommentRuntimeCache;
7 use wcf\system\cache\runtime\UserProfileRuntimeCache;
8 use wcf\system\request\LinkHandler;
9 use wcf\system\WCF;
10
11 /**
12 * User notification event for profile's owner for commment responses.
13 *
14 * @author Alexander Ebert
15 * @copyright 2001-2016 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 class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractSharedUserNotificationEvent {
20 /**
21 * @inheritDoc
22 */
23 protected $stackable = true;
24
25 /**
26 * @inheritDoc
27 */
28 protected function prepare() {
29 CommentRuntimeCache::getInstance()->cacheObjectID($this->userNotificationObject->commentID);
30 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);
31 }
32
33 /**
34 * @inheritDoc
35 */
36 public function getTitle() {
37 $count = count($this->getAuthors());
38 if ($count > 1) {
39 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.title.stacked', [
40 'count' => $count,
41 'timesTriggered' => $this->notification->timesTriggered
42 ]);
43 }
44
45 return $this->getLanguage()->get('wcf.user.notification.commentResponseOwner.title');
46 }
47
48 /**
49 * @inheritDoc
50 */
51 public function getMessage() {
52 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
53 if ($comment->userID) {
54 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
55 }
56 else {
57 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
58 }
59
60 $authors = $this->getAuthors();
61 if (count($authors) > 1) {
62 if (isset($authors[0])) {
63 unset($authors[0]);
64 }
65 $count = count($authors);
66
67 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message.stacked', [
68 'author' => $commentAuthor,
69 'authors' => array_values($authors),
70 'count' => $count,
71 'others' => $count - 1,
72 'guestTimesTriggered' => $this->notification->guestTimesTriggered
73 ]);
74 }
75
76 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message', [
77 'author' => $this->author,
78 'commentAuthor' => $commentAuthor
79 ]);
80 }
81
82 /**
83 * @inheritDoc
84 */
85 public function getEmailMessage($notificationType = 'instant') {
86 $comment = new Comment($this->userNotificationObject->commentID);
87 $owner = new User($comment->objectID);
88 if ($comment->userID) {
89 $commentAuthor = new User($comment->userID);
90 }
91 else {
92 $commentAuthor = new User(null, [
93 'username' => $comment->username
94 ]);
95 }
96
97 $authors = $this->getAuthors();
98 if (count($authors) > 1) {
99 if (isset($authors[0])) {
100 unset($authors[0]);
101 }
102 $count = count($authors);
103
104 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.mail.stacked', [
105 'author' => $this->author,
106 'authors' => array_values($authors),
107 'commentAuthor' => $commentAuthor,
108 'count' => $count,
109 'notificationType' => $notificationType,
110 'others' => $count - 1,
111 'owner' => $owner,
112 'response' => $this->userNotificationObject,
113 'guestTimesTriggered' => $this->notification->guestTimesTriggered
114 ]);
115 }
116
117 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.mail', [
118 'response' => $this->userNotificationObject,
119 'author' => $this->author,
120 'commentAuthor' => $commentAuthor,
121 'owner' => $owner,
122 'notificationType' => $notificationType
123 ]);
124 }
125
126 /**
127 * @inheritDoc
128 */
129 public function getLink() {
130 return LinkHandler::getInstance()->getLink('User', ['object' => WCF::getUser()], '#wall');
131 }
132
133 /**
134 * @inheritDoc
135 */
136 public function getEventHash() {
137 return sha1($this->eventID . '-' . $this->userNotificationObject->commentID);
138 }
139 }