Commit | Line | Data |
---|---|---|
4d8036f5 | 1 | <?php |
a9229942 | 2 | |
4d8036f5 | 3 | namespace wcf\acp\form; |
a9229942 | 4 | |
4d8036f5 | 5 | use wcf\data\paid\subscription\PaidSubscription; |
5fdb5c9d AE |
6 | use wcf\data\paid\subscription\PaidSubscriptionAction; |
7 | use wcf\data\paid\subscription\PaidSubscriptionList; | |
d3900f69 | 8 | use wcf\form\AbstractForm; |
4d8036f5 MW |
9 | use wcf\system\exception\PermissionDeniedException; |
10 | use wcf\system\language\I18nHandler; | |
11 | use wcf\system\WCF; | |
4d8036f5 MW |
12 | |
13 | /** | |
14 | * Shows the paid subscription edit form. | |
a9229942 TD |
15 | * |
16 | * @author Marcel Werk | |
17 | * @copyright 2001-2019 WoltLab GmbH | |
18 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
19 | * @package WoltLabSuite\Core\Acp\Form | |
4d8036f5 | 20 | */ |
a9229942 TD |
21 | class PaidSubscriptionEditForm extends PaidSubscriptionAddForm |
22 | { | |
23 | /** | |
24 | * @inheritDoc | |
25 | */ | |
26 | public $activeMenuItem = 'wcf.acp.menu.link.paidSubscription.list'; | |
27 | ||
28 | /** | |
29 | * id of the edited subscription | |
30 | * @var int | |
31 | */ | |
32 | public $subscriptionID = 0; | |
33 | ||
34 | /** | |
35 | * edited subscription object | |
36 | * @var PaidSubscription | |
37 | */ | |
38 | public $subscription; | |
39 | ||
40 | /** | |
41 | * @inheritDoc | |
42 | */ | |
43 | public function readParameters() | |
44 | { | |
45 | if (isset($_REQUEST['id'])) { | |
46 | $this->subscriptionID = \intval($_REQUEST['id']); | |
47 | } | |
48 | $this->subscription = new PaidSubscription($this->subscriptionID); | |
49 | if (!$this->subscription->subscriptionID) { | |
50 | throw new PermissionDeniedException(); | |
51 | } | |
52 | ||
53 | parent::readParameters(); | |
54 | } | |
55 | ||
56 | protected function getAvailableSubscriptions() | |
57 | { | |
58 | $subscriptionList = new PaidSubscriptionList(); | |
59 | $subscriptionList->getConditionBuilder()->add('subscriptionID <> ?', [$this->subscriptionID]); | |
60 | $subscriptionList->sqlOrderBy = 'title'; | |
61 | $subscriptionList->readObjects(); | |
62 | $this->availableSubscriptions = $subscriptionList->getObjects(); | |
63 | } | |
64 | ||
65 | /** | |
66 | * @inheritDoc | |
67 | */ | |
68 | public function readData() | |
69 | { | |
70 | parent::readData(); | |
71 | ||
72 | if (empty($_POST)) { | |
73 | I18nHandler::getInstance()->setOptions( | |
74 | 'description', | |
75 | 1, | |
76 | $this->subscription->description, | |
77 | 'wcf.paidSubscription.subscription\d+.description' | |
78 | ); | |
79 | I18nHandler::getInstance()->setOptions( | |
80 | 'title', | |
81 | 1, | |
82 | $this->subscription->title, | |
83 | 'wcf.paidSubscription.subscription\d+' | |
84 | ); | |
85 | ||
86 | $this->isDisabled = $this->subscription->isDisabled; | |
87 | $this->showOrder = $this->subscription->showOrder; | |
88 | $this->cost = $this->subscription->cost; | |
89 | $this->currency = $this->subscription->currency; | |
90 | $this->subscriptionLength = $this->subscription->subscriptionLength; | |
91 | $this->subscriptionLengthUnit = $this->subscription->subscriptionLengthUnit; | |
92 | $this->isRecurring = $this->subscription->isRecurring; | |
93 | $this->groupIDs = \explode(',', $this->subscription->groupIDs); | |
94 | $this->excludedSubscriptionIDs = \explode(',', $this->subscription->excludedSubscriptionIDs); | |
95 | } | |
96 | } | |
97 | ||
98 | /** | |
99 | * @inheritDoc | |
100 | */ | |
101 | public function save() | |
102 | { | |
103 | AbstractForm::save(); | |
104 | ||
105 | // update description | |
106 | $this->description = 'wcf.paidSubscription.subscription' . $this->subscription->subscriptionID . '.description'; | |
107 | if (I18nHandler::getInstance()->isPlainValue('description')) { | |
108 | I18nHandler::getInstance()->remove($this->description); | |
109 | $this->description = I18nHandler::getInstance()->getValue('description'); | |
110 | } else { | |
111 | I18nHandler::getInstance()->save('description', $this->description, 'wcf.paidSubscription', 1); | |
112 | } | |
113 | ||
114 | // update title | |
115 | $this->title = 'wcf.paidSubscription.subscription' . $this->subscription->subscriptionID; | |
116 | if (I18nHandler::getInstance()->isPlainValue('title')) { | |
117 | I18nHandler::getInstance()->remove($this->title); | |
118 | $this->title = I18nHandler::getInstance()->getValue('title'); | |
119 | } else { | |
120 | I18nHandler::getInstance()->save('title', $this->title, 'wcf.paidSubscription', 1); | |
121 | } | |
122 | ||
123 | // save subscription | |
124 | $this->objectAction = new PaidSubscriptionAction([$this->subscription], 'update', [ | |
125 | 'data' => \array_merge($this->additionalFields, [ | |
126 | 'title' => $this->title, | |
127 | 'description' => $this->description, | |
128 | 'isDisabled' => $this->isDisabled, | |
129 | 'showOrder' => $this->showOrder, | |
130 | 'cost' => $this->cost, | |
131 | 'currency' => $this->currency, | |
132 | 'subscriptionLength' => $this->subscriptionLength, | |
133 | 'subscriptionLengthUnit' => $this->subscriptionLengthUnit, | |
134 | 'isRecurring' => $this->isRecurring, | |
135 | 'groupIDs' => \implode(',', $this->groupIDs), | |
136 | 'excludedSubscriptionIDs' => \implode(',', $this->excludedSubscriptionIDs), | |
137 | ]), | |
138 | ]); | |
139 | $this->objectAction->executeAction(); | |
140 | $this->saved(); | |
141 | ||
142 | // show success message | |
143 | WCF::getTPL()->assign('success', true); | |
144 | } | |
145 | ||
146 | /** | |
147 | * @inheritDoc | |
148 | */ | |
149 | public function assignVariables() | |
150 | { | |
151 | parent::assignVariables(); | |
152 | ||
153 | $useRequestData = empty($_POST) ? false : true; | |
154 | I18nHandler::getInstance()->assignVariables($useRequestData); | |
155 | ||
156 | WCF::getTPL()->assign([ | |
157 | 'action' => 'edit', | |
158 | 'subscriptionID' => $this->subscriptionID, | |
159 | 'subscription' => $this->subscription, | |
160 | ]); | |
161 | } | |
4d8036f5 | 162 | } |