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