a9bc0009a01e9d6c2b55eb7d97db47d21a891b68
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\paid\subscription\PaidSubscription;
6 use wcf\data\paid\subscription\PaidSubscriptionAction;
7 use wcf\data\paid\subscription\user\PaidSubscriptionUser;
8 use wcf\data\paid\subscription\user\PaidSubscriptionUserAction;
9 use wcf\data\paid\subscription\user\PaidSubscriptionUserList;
10 use wcf\data\user\UserProfile;
11 use wcf\system\request\LinkHandler;
12 use wcf\system\user\notification\object\PaidSubscriptionUserUserNotificationObject;
13 use wcf\system\WCF;
14
15 /**
16 * Notification event for expiring paid subscriptions.
17 *
18 * @author Matthias Schmidt
19 * @copyright 2001-2019 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @since 3.1
22 *
23 * @method PaidSubscriptionUserUserNotificationObject getUserNotificationObject()
24 */
25 class ExpiringPaidSubscriptionUserUserNotificationEvent extends AbstractUserNotificationEvent implements
26 ITestableUserNotificationEvent
27 {
28 use TTestableUserNotificationEvent;
29
30 /**
31 * @inheritDoc
32 */
33 public function getLink(): string
34 {
35 return LinkHandler::getInstance()->getLink('PaidSubscriptionList', ['forceFrontend' => true]);
36 }
37
38 /**
39 * @inheritDoc
40 */
41 public function getMessage()
42 {
43 return $this->getLanguage()->getDynamicVariable(
44 'wcf.paidSubscription.expiringSubscription.notification.message',
45 [
46 'author' => $this->author,
47 'notification' => $this->notification,
48 'userNotificationObject' => $this->getUserNotificationObject(),
49 ]
50 );
51 }
52
53 /**
54 * @inheritDoc
55 */
56 public function getEmailMessage($notificationType = 'instant')
57 {
58 return [
59 'template' => 'email_notification_expiringPaidSubscription',
60 'application' => 'wcf',
61 'variables' => [
62 'notification' => $this->notification,
63 'subscription' => $this->getUserNotificationObject(),
64 ],
65 ];
66 }
67
68 /**
69 * @inheritDoc
70 */
71 public function getTitle(): string
72 {
73 return $this->getLanguage()->get('wcf.paidSubscription.expiringSubscription.notification.title');
74 }
75
76 /**
77 * @inheritDoc
78 */
79 public function isVisible()
80 {
81 $userSubscriptionList = new PaidSubscriptionUserList();
82 $userSubscriptionList->getConditionBuilder()->add('userID = ?', [WCF::getUser()->userID]);
83 $userSubscriptionList->getConditionBuilder()->add('isActive = ?', [1]);
84
85 return $userSubscriptionList->countObjects() > 0;
86 }
87
88 /**
89 * @inheritDoc
90 * @return PaidSubscriptionUserUserNotificationObject[]
91 * @since 3.1
92 */
93 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
94 {
95 /** @var PaidSubscription $paidSubscription */
96 $paidSubscription = (new PaidSubscriptionAction([], 'create', [
97 'data' => [
98 'title' => 'Test Subscription',
99 ],
100 ]))->executeAction()['returnValues'];
101
102 /** @var PaidSubscriptionUser $paidSubscriptionUser */
103 $paidSubscriptionUser = (new PaidSubscriptionUserAction([], 'create', [
104 'data' => [
105 'startDate' => TIME_NOW - 24 * 24 * 60 * 60,
106 'endDate' => TIME_NOW + 24 * 60 * 60,
107 'isActive' => 1,
108 'sentExpirationNotification' => 0,
109 ],
110 'subscription' => $paidSubscription,
111 'user' => $recipient,
112 ]))->executeAction()['returnValues'];
113
114 $paidSubscriptionUser->setSubscription($paidSubscription);
115
116 return [new PaidSubscriptionUserUserNotificationObject($paidSubscriptionUser)];
117 }
118 }