c70a97be2d326a5937cc75ae043eecd64728d86c
[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 comment 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 return [
101 'template' => 'email_notification_userProfileCommentResponseOwner',
102 'application' => 'wcf',
103 'variables' => [
104 'commentAuthor' => $commentAuthor,
105 'owner' => $owner
106 ]
107 ];
108 }
109
110 /**
111 * @inheritDoc
112 */
113 public function getLink() {
114 return LinkHandler::getInstance()->getLink('User', ['object' => WCF::getUser()], '#wall');
115 }
116
117 /**
118 * @inheritDoc
119 */
120 public function getEventHash() {
121 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
122 }
123 }