5 use wcf\data\paid\subscription\user\PaidSubscriptionUserList
;
6 use wcf\system\cache\builder\PaidSubscriptionCacheBuilder
;
7 use wcf\system\exception\PermissionDeniedException
;
8 use wcf\system\menu\user\UserMenu
;
12 * Shows a list of the available paid subscriptions.
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 class PaidSubscriptionListPage
extends AbstractPage
23 public $loginRequired = true;
28 public $neededModules = ['MODULE_PAID_SUBSCRIPTION'];
33 public $neededPermissions = ['user.profile.payment.canBuyPaidSubscription'];
36 * list of available paid subscriptions
39 public $subscriptions = [];
42 * list of user subscriptions
43 * @var PaidSubscriptionUserList
45 public $userSubscriptionList = [];
50 public function checkPermissions()
52 parent
::checkPermissions();
54 if (WCF
::getUser()->pendingActivation()) {
55 throw new PermissionDeniedException();
62 public function readData()
66 // get available subscriptions
67 $this->subscriptions
= PaidSubscriptionCacheBuilder
::getInstance()->getData();
69 // get user subscriptions
70 $this->userSubscriptionList
= new PaidSubscriptionUserList();
71 $this->userSubscriptionList
->getConditionBuilder()->add('userID = ?', [WCF
::getUser()->userID
]);
72 $this->userSubscriptionList
->getConditionBuilder()->add('isActive = ?', [1]);
73 $this->userSubscriptionList
->readObjects();
75 foreach ($this->userSubscriptionList
as $userSubscription) {
76 if (isset($this->subscriptions
[$userSubscription->subscriptionID
])) {
77 $userSubscription->setSubscription($this->subscriptions
[$userSubscription->subscriptionID
]);
78 unset($this->subscriptions
[$userSubscription->subscriptionID
]);
81 foreach ($this->userSubscriptionList
as $userSubscription) {
82 if ($userSubscription->getSubscription()->excludedSubscriptionIDs
) {
84 \
explode(',', $userSubscription->getSubscription()->excludedSubscriptionIDs
) as $subscriptionID
86 if (isset($this->subscriptions
[$subscriptionID])) {
87 unset($this->subscriptions
[$subscriptionID]);
97 public function assignVariables()
99 parent
::assignVariables();
101 WCF
::getTPL()->assign([
102 'subscriptions' => $this->subscriptions
,
103 'userSubscriptions' => $this->userSubscriptionList
,
110 public function show()
113 UserMenu
::getInstance()->setActiveMenuItem('wcf.user.menu.settings.paidSubscription');