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;
14 * Notification event for expiring paid subscriptions.
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
22 * @method PaidSubscriptionUserUserNotificationObject getUserNotificationObject()
24 class ExpiringPaidSubscriptionUserUserNotificationEvent extends AbstractUserNotificationEvent implements ITestableUserNotificationEvent {
25 use TTestableUserNotificationEvent;
30 public function getLink() {
31 return LinkHandler::getInstance()->getLink('PaidSubscriptionList', ['forceFrontend' => true]);
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()
48 public function getEmailMessage($notificationType = 'instant') {
50 'template' => 'email_notification_expiringPaidSubscription',
51 'application' => 'wcf',
53 'notification' => $this->notification,
54 'subscription' => $this->getUserNotificationObject()
62 public function getTitle() {
63 return $this->getLanguage()->get('wcf.paidSubscription.expiringSubscription.notification.title');
69 public function isVisible() {
70 $userSubscriptionList = new PaidSubscriptionUserList();
71 $userSubscriptionList->getConditionBuilder()->add('userID = ?', [WCF::getUser()->userID]);
72 $userSubscriptionList->getConditionBuilder()->add('isActive = ?', [1]);
74 return $userSubscriptionList->countObjects() > 0;
79 * @return PaidSubscriptionUserUserNotificationObject[]
82 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
83 /** @var PaidSubscription $paidSubscription */
84 $paidSubscription = (new PaidSubscriptionAction([], 'create', [
86 'title' => 'Test Subscription'
88 ]))->executeAction()['returnValues'];
90 /** @var PaidSubscriptionUser $paidSubscriptionUser */
91 $paidSubscriptionUser = (new PaidSubscriptionUserAction([], 'create', [
93 'startDate' => TIME_NOW - 24 * 24 * 60 * 60,
94 'endDate' => TIME_NOW + 24 * 60 * 60,
96 'sentExpirationNotification' => 0
98 'subscription' => $paidSubscription,
100 ]))->executeAction()['returnValues'];
102 $paidSubscriptionUser->setSubscription($paidSubscription);
104 return [new PaidSubscriptionUserUserNotificationObject($paidSubscriptionUser)];