Merge branch '5.3'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / user / notification / event / ArticleUserNotificationEvent.class.php
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\article\Article;
6 use wcf\data\article\category\ArticleCategory;
7 use wcf\data\user\UserProfile;
8 use wcf\system\user\notification\object\ArticleUserNotificationObject;
9
10 /**
11 * Notification event for new articles.
12 *
13 * @author Joshua Ruesweg
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\User\Notification\Object\Type
17 *
18 * @method ArticleUserNotificationObject getUserNotificationObject()
19 */
20 class ArticleUserNotificationEvent extends AbstractUserNotificationEvent implements ITestableUserNotificationEvent
21 {
22 use TTestableUserNotificationEvent;
23 use TTestableArticleUserNotificationEvent;
24 use TTestableCategorizedUserNotificationEvent;
25
26 /**
27 * @inheritDoc
28 */
29 public function getTitle()
30 {
31 return $this->getLanguage()->get('wcf.user.notification.article.title');
32 }
33
34 /**
35 * @inheritDoc
36 */
37 public function getMessage()
38 {
39 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.article.message', [
40 'article' => $this->userNotificationObject,
41 'author' => $this->author,
42 ]);
43 }
44
45 /**
46 * @inheritDoc
47 */
48 public function getEmailMessage($notificationType = 'instant')
49 {
50 if ($this->getUserNotificationObject()->isMultilingual) {
51 $articleContent = $this->getUserNotificationObject()
52 ->getArticleContents()[$this->getLanguage()->languageID];
53 } else {
54 $articleContent = $this->getUserNotificationObject()
55 ->getArticleContents()[0];
56 }
57
58 return [
59 'message-id' => 'com.woltlab.wcf.article/' . $this->getUserNotificationObject()->articleID,
60 'template' => 'email_notification_article',
61 'application' => 'wcf',
62 'variables' => [
63 'article' => $this->getUserNotificationObject(),
64 'articleContent' => $articleContent,
65 'languageVariablePrefix' => 'wcf.user.notification.article',
66 'author' => $this->author,
67 ],
68 ];
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public function getLink()
75 {
76 return $this->getUserNotificationObject()->getLink();
77 }
78
79 /**
80 * @inheritDoc
81 */
82 public function checkAccess()
83 {
84 return $this->getUserNotificationObject()->canRead();
85 }
86
87 /**
88 * @inheritDoc
89 */
90 public static function canBeTriggeredByGuests()
91 {
92 return true;
93 }
94
95 /**
96 * @inheritDoc
97 * @return Article[]
98 */
99 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
100 {
101 return [
102 new ArticleUserNotificationObject(
103 self::getTestArticle(self::createTestCategory(ArticleCategory::OBJECT_TYPE_NAME), $author)
104 ),
105 ];
106 }
107 }