3d710690db6472d8487040e0ec92e86862359362
[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 com.woltlab.wcf
18 * @subpackage system.user.notification.event
19 * @category Community Framework
20 */
21 class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractSharedUserNotificationEvent {
22 /**
23 * @inheritDoc
24 */
25 protected $stackable = true;
26
27 /**
28 * @inheritDoc
29 */
30 protected function prepare() {
31 CommentRuntimeCache::getInstance()->cacheObjectID($this->userNotificationObject->commentID);
32 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);
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.commentResponseOwner.title.stacked', [
42 'count' => $count,
43 'timesTriggered' => $this->notification->timesTriggered
44 ]);
45 }
46
47 return $this->getLanguage()->get('wcf.user.notification.commentResponseOwner.title');
48 }
49
50 /**
51 * @inheritDoc
52 */
53 public function getMessage() {
54 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
55 if ($comment->userID) {
56 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
57 }
58 else {
59 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
60 }
61
62 $authors = $this->getAuthors();
63 if (count($authors) > 1) {
64 if (isset($authors[0])) {
65 unset($authors[0]);
66 }
67 $count = count($authors);
68
69 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message.stacked', [
70 'author' => $commentAuthor,
71 'authors' => array_values($authors),
72 'count' => $count,
73 'others' => $count - 1,
74 'guestTimesTriggered' => $this->notification->guestTimesTriggered
75 ]);
76 }
77
78 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message', [
79 'author' => $this->author,
80 'commentAuthor' => $commentAuthor
81 ]);
82 }
83
84 /**
85 * @inheritDoc
86 */
87 public function getEmailMessage($notificationType = 'instant') {
88 $comment = new Comment($this->userNotificationObject->commentID);
89 $owner = new User($comment->objectID);
90 if ($comment->userID) {
91 $commentAuthor = new User($comment->userID);
92 }
93 else {
94 $commentAuthor = new User(null, [
95 'username' => $comment->username
96 ]);
97 }
98
99 $authors = $this->getAuthors();
100 if (count($authors) > 1) {
101 if (isset($authors[0])) {
102 unset($authors[0]);
103 }
104 $count = count($authors);
105
106 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.mail.stacked', [
107 'author' => $this->author,
108 'authors' => array_values($authors),
109 'commentAuthor' => $commentAuthor,
110 'count' => $count,
111 'notificationType' => $notificationType,
112 'others' => $count - 1,
113 'owner' => $owner,
114 'response' => $this->userNotificationObject,
115 'guestTimesTriggered' => $this->notification->guestTimesTriggered
116 ]);
117 }
118
119 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.mail', [
120 'response' => $this->userNotificationObject,
121 'author' => $this->author,
122 'commentAuthor' => $commentAuthor,
123 'owner' => $owner,
124 'notificationType' => $notificationType
125 ]);
126 }
127
128 /**
129 * @inheritDoc
130 */
131 public function getLink() {
132 return LinkHandler::getInstance()->getLink('User', ['object' => WCF::getUser()], '#wall');
133 }
134
135 /**
136 * @inheritDoc
137 */
138 public function getEventHash() {
139 return sha1($this->eventID . '-' . $this->userNotificationObject->commentID);
140 }
141 }