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