| 1 | <?php |
| 2 | |
| 3 | namespace wcf\page; |
| 4 | |
| 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; |
| 9 | use wcf\system\WCF; |
| 10 | |
| 11 | /** |
| 12 | * Shows a list of the available paid subscriptions. |
| 13 | * |
| 14 | * @author Marcel Werk |
| 15 | * @copyright 2001-2019 WoltLab GmbH |
| 16 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
| 17 | */ |
| 18 | class PaidSubscriptionListPage extends AbstractPage |
| 19 | { |
| 20 | /** |
| 21 | * @inheritDoc |
| 22 | */ |
| 23 | public $loginRequired = true; |
| 24 | |
| 25 | /** |
| 26 | * @inheritDoc |
| 27 | */ |
| 28 | public $neededModules = ['MODULE_PAID_SUBSCRIPTION']; |
| 29 | |
| 30 | /** |
| 31 | * @inheritDoc |
| 32 | */ |
| 33 | public $neededPermissions = ['user.profile.payment.canBuyPaidSubscription']; |
| 34 | |
| 35 | /** |
| 36 | * list of available paid subscriptions |
| 37 | * @var array |
| 38 | */ |
| 39 | public $subscriptions = []; |
| 40 | |
| 41 | /** |
| 42 | * list of user subscriptions |
| 43 | * @var PaidSubscriptionUserList |
| 44 | */ |
| 45 | public $userSubscriptionList = []; |
| 46 | |
| 47 | /** |
| 48 | * @inheritDoc |
| 49 | */ |
| 50 | public function checkPermissions() |
| 51 | { |
| 52 | parent::checkPermissions(); |
| 53 | |
| 54 | if (WCF::getUser()->pendingActivation()) { |
| 55 | throw new PermissionDeniedException(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @inheritDoc |
| 61 | */ |
| 62 | public function readData() |
| 63 | { |
| 64 | parent::readData(); |
| 65 | |
| 66 | // get available subscriptions |
| 67 | $this->subscriptions = PaidSubscriptionCacheBuilder::getInstance()->getData(); |
| 68 | |
| 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(); |
| 74 | |
| 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]); |
| 79 | } |
| 80 | } |
| 81 | foreach ($this->userSubscriptionList as $userSubscription) { |
| 82 | if ($userSubscription->getSubscription()->excludedSubscriptionIDs) { |
| 83 | foreach ( |
| 84 | \explode(',', $userSubscription->getSubscription()->excludedSubscriptionIDs) as $subscriptionID |
| 85 | ) { |
| 86 | if (isset($this->subscriptions[$subscriptionID])) { |
| 87 | unset($this->subscriptions[$subscriptionID]); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @inheritDoc |
| 96 | */ |
| 97 | public function assignVariables() |
| 98 | { |
| 99 | parent::assignVariables(); |
| 100 | |
| 101 | WCF::getTPL()->assign([ |
| 102 | 'subscriptions' => $this->subscriptions, |
| 103 | 'userSubscriptions' => $this->userSubscriptionList, |
| 104 | ]); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @inheritDoc |
| 109 | */ |
| 110 | public function show() |
| 111 | { |
| 112 | // set active tab |
| 113 | UserMenu::getInstance()->setActiveMenuItem('wcf.user.menu.settings.paidSubscription'); |
| 114 | |
| 115 | parent::show(); |
| 116 | } |
| 117 | } |