93099710abf87de1f9479acedc94cb79fe999f0c
[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\CommentRuntimeCache;
5 use wcf\system\cache\runtime\UserProfileRuntimeCache;
6 use wcf\system\email\Email;
7 use wcf\system\request\LinkHandler;
8 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
9 use wcf\system\WCF;
10
11 /**
12 * User notification event for profile's owner for comment responses.
13 *
14 * @author Alexander Ebert
15 * @copyright 2001-2017 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 * @method CommentResponseUserNotificationObject getUserNotificationObject()
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->getUserNotificationObject()->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->getUserNotificationObject()->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 = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
89 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
90 if ($comment->userID) {
91 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
92 }
93 else {
94 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
95 }
96
97 $messageID = '<com.woltlab.wcf.user.profileComment.notification/'.$comment->commentID.'@'.Email::getHost().'>';
98
99 return [
100 'template' => 'email_notification_userProfileCommentResponseOwner',
101 'application' => 'wcf',
102 'in-reply-to' => [$messageID],
103 'references' => [$messageID],
104 'variables' => [
105 'commentAuthor' => $commentAuthor,
106 'owner' => $owner
107 ]
108 ];
109 }
110
111 /**
112 * @inheritDoc
113 */
114 public function getLink() {
115 return LinkHandler::getInstance()->getLink('User', ['object' => WCF::getUser()], '#wall');
116 }
117
118 /**
119 * @inheritDoc
120 */
121 public function getEventHash() {
122 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
123 }
124 }