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