Add permalinks for responses to phrases
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / user / notification / event / UserProfileCommentResponseUserNotificationEvent.class.php
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\system\cache\runtime\CommentRuntimeCache;
4 use wcf\system\cache\runtime\UserProfileRuntimeCache;
5 use wcf\system\email\Email;
6 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
7
8 /**
9 * User notification event for profile comment responses.
10 *
11 * @author Alexander Ebert
12 * @copyright 2001-2017 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\User\Notification\Event
15 *
16 * @method CommentResponseUserNotificationObject getUserNotificationObject()
17 */
18 class UserProfileCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
19 /**
20 * @inheritDoc
21 */
22 protected $stackable = true;
23
24 /**
25 * @inheritDoc
26 */
27 protected function prepare() {
28 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
29 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['objectID']);
30 }
31
32 /**
33 * @inheritDoc
34 */
35 public function getTitle() {
36 $count = count($this->getAuthors());
37 if ($count > 1) {
38 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.title.stacked', [
39 'count' => $count,
40 'timesTriggered' => $this->notification->timesTriggered
41 ]);
42 }
43
44 return $this->getLanguage()->get('wcf.user.notification.commentResponse.title');
45 }
46
47 /**
48 * @inheritDoc
49 */
50 public function getMessage() {
51 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
52
53 $authors = $this->getAuthors();
54 if (count($authors) > 1) {
55 if (isset($authors[0])) {
56 unset($authors[0]);
57 }
58 $count = count($authors);
59
60 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message.stacked', [
61 'authors' => array_values($authors),
62 'count' => $count,
63 'others' => $count - 1,
64 'owner' => $owner,
65 'guestTimesTriggered' => $this->notification->guestTimesTriggered
66 ]);
67 }
68
69 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponse.message', [
70 'author' => $this->author,
71 'commentID' => $this->getUserNotificationObject()->commentID,
72 'owner' => $owner,
73 'responseID' => $this->getUserNotificationObject()->responseID
74 ]);
75 }
76
77 /**
78 * @inheritDoc
79 */
80 public function getEmailMessage($notificationType = 'instant') {
81 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
82 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
83
84 $messageID = '<com.woltlab.wcf.user.profileComment.notification/'.$comment->commentID.'@'.Email::getHost().'>';
85
86 return [
87 'template' => 'email_notification_userProfileCommentResponse',
88 'application' => 'wcf',
89 'in-reply-to' => [$messageID],
90 'references' => [$messageID],
91 'variables' => [
92 'commentID' => $this->getUserNotificationObject()->commentID,
93 'owner' => $owner,
94 'responseID' => $this->getUserNotificationObject()->responseID
95 ]
96 ];
97 }
98
99 /**
100 * @inheritDoc
101 */
102 public function getLink() {
103 return UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#wall/comment' . $this->getUserNotificationObject()->commentID . '/response' . $this->getUserNotificationObject()->responseID;
104 }
105
106 /**
107 * @inheritDoc
108 */
109 public function getEventHash() {
110 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
111 }
112 }