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