cdf4ab22455ad94a154ecf968ef0511b6c9c530f
[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 = new Comment($this->getUserNotificationObject()->commentID);
91 $owner = new User($comment->objectID);
92 if ($comment->userID) {
93 $commentAuthor = new User($comment->userID);
94 }
95 else {
96 $commentAuthor = new User(null, [
97 'username' => $comment->username
98 ]);
99 }
100
101 $messageID = '<com.woltlab.wcf.user.profileComment.notification/'.$comment->commentID.'@'.Email::getHost().'>';
102
103 return [
104 'template' => 'email_notification_userProfileCommentResponseOwner',
105 'application' => 'wcf',
106 'in-reply-to' => [$messageID],
107 'references' => [$messageID],
108 'variables' => [
109 'commentAuthor' => $commentAuthor,
110 'owner' => $owner
111 ]
112 ];
113 }
114
115 /**
116 * @inheritDoc
117 */
118 public function getLink() {
119 return LinkHandler::getInstance()->getLink('User', ['object' => WCF::getUser()], '#wall');
120 }
121
122 /**
123 * @inheritDoc
124 */
125 public function getEventHash() {
126 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
127 }
128 }