3 namespace wcf\system\user\notification\event;
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;
16 * Notification event for expiring paid subscriptions.
18 * @author Matthias Schmidt
19 * @copyright 2001-2019 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 * @method PaidSubscriptionUserUserNotificationObject getUserNotificationObject()
25 class ExpiringPaidSubscriptionUserUserNotificationEvent extends AbstractUserNotificationEvent implements
26 ITestableUserNotificationEvent
28 use TTestableUserNotificationEvent;
33 public function getLink(): string
35 return LinkHandler::getInstance()->getLink('PaidSubscriptionList', ['forceFrontend' => true]);
41 public function getMessage()
43 return $this->getLanguage()->getDynamicVariable(
44 'wcf.paidSubscription.expiringSubscription.notification.message',
46 'author' => $this->author,
47 'notification' => $this->notification,
48 'userNotificationObject' => $this->getUserNotificationObject(),
56 public function getEmailMessage($notificationType = 'instant')
59 'template' => 'email_notification_expiringPaidSubscription',
60 'application' => 'wcf',
62 'notification' => $this->notification,
63 'subscription' => $this->getUserNotificationObject(),
71 public function getTitle(): string
73 return $this->getLanguage()->get('wcf.paidSubscription.expiringSubscription.notification.title');
79 public function isVisible()
81 $userSubscriptionList = new PaidSubscriptionUserList();
82 $userSubscriptionList->getConditionBuilder()->add('userID = ?', [WCF::getUser()->userID]);
83 $userSubscriptionList->getConditionBuilder()->add('isActive = ?', [1]);
85 return $userSubscriptionList->countObjects() > 0;
90 * @return PaidSubscriptionUserUserNotificationObject[]
93 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
95 /** @var PaidSubscription $paidSubscription */
96 $paidSubscription = (new PaidSubscriptionAction([], 'create', [
98 'title' => 'Test Subscription',
100 ]))->executeAction()['returnValues'];
102 /** @var PaidSubscriptionUser $paidSubscriptionUser */
103 $paidSubscriptionUser = (new PaidSubscriptionUserAction([], 'create', [
105 'startDate' => TIME_NOW - 24 * 24 * 60 * 60,
106 'endDate' => TIME_NOW + 24 * 60 * 60,
108 'sentExpirationNotification' => 0,
110 'subscription' => $paidSubscription,
111 'user' => $recipient,
112 ]))->executeAction()['returnValues'];
114 $paidSubscriptionUser->setSubscription($paidSubscription);
116 return [new PaidSubscriptionUserUserNotificationObject($paidSubscriptionUser)];