Merge branch '2.1' into 3.0
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / user / notification / event / ConversationMessageUserNotificationEvent.class.php
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\system\email\Email;
4 use wcf\system\request\LinkHandler;
5 use wcf\system\user\notification\object\ConversationMessageUserNotificationObject;
6
7 /**
8 * User notification event for conversation messages.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2017 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\User\Notification\Event
14 *
15 * @method ConversationMessageUserNotificationObject getUserNotificationObject()
16 */
17 class ConversationMessageUserNotificationEvent extends AbstractUserNotificationEvent {
18 /**
19 * @inheritDoc
20 */
21 protected $stackable = true;
22
23 /**
24 * @inheritDoc
25 */
26 public function getTitle() {
27 $count = count($this->getAuthors());
28 if ($count > 1) {
29 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.message.title.stacked', ['count' => $count]);
30 }
31
32 return $this->getLanguage()->get('wcf.user.notification.conversation.message.title');
33 }
34
35 /**
36 * @inheritDoc
37 */
38 public function getMessage() {
39 $authors = array_values($this->getAuthors());
40 $count = count($authors);
41
42 if ($count > 1) {
43 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.message.message.stacked', [
44 'author' => $this->author,
45 'authors' => $authors,
46 'count' => $count,
47 'message' => $this->userNotificationObject,
48 'others' => $count - 1
49 ]);
50 }
51
52 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.message.message', [
53 'author' => $this->author,
54 'message' => $this->userNotificationObject
55 ]);
56 }
57
58 /** @noinspection PhpMissingParentCallCommonInspection */
59 /**
60 * @inheritDoc
61 */
62 public function getEmailMessage($notificationType = 'instant') {
63 $messageID = '<com.woltlab.wcf.conversation.notification/'.$this->getUserNotificationObject()->getConversation()->conversationID.'@'.Email::getHost().'>';
64
65 return [
66 'template' => 'email_notification_conversationMessage',
67 'application' => 'wcf',
68 'in-reply-to' => [$messageID],
69 'references' => [$messageID]
70 ];
71 }
72
73 /**
74 * @inheritDoc
75 */
76 public function getLink() {
77 return LinkHandler::getInstance()->getLink('Conversation', [
78 'object' => $this->getUserNotificationObject()->getConversation(),
79 'messageID' => $this->getUserNotificationObject()->messageID
80 ], '#message'.$this->getUserNotificationObject()->messageID);
81 }
82
83 /** @noinspection PhpMissingParentCallCommonInspection */
84 /**
85 * @inheritDoc
86 */
87 public function getEventHash() {
88 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->conversationID);
89 }
90
91 /** @noinspection PhpMissingParentCallCommonInspection */
92 /**
93 * @inheritDoc
94 */
95 public function checkAccess() {
96 return $this->getUserNotificationObject()->getConversation()->canRead();
97 }
98 }