PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / FormMigration / Steps / DonationOptions.php

DonationOptions.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/FormMigration/Steps/DonationOptions.php

68 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\FormMigration\Steps;
4
5 use Give\FormMigration\Contracts\FormMigrationStep;
6 use Give\Framework\Blocks\BlockModel;
7
8 class DonationOptions extends FormMigrationStep
9 {
10 public function process()
11 {
12 /** @var BlockModel $amountField */
13 $amountField = $this->fieldBlocks->findByName('givewp/donation-amount');
14
15 $priceOption = $this->getMetaV2('_give_price_option');
16 $amountField->setAttribute('priceOption', $priceOption);
17
18 if('set' === $priceOption) {
19 $amountField->setAttribute('setPrice', $this->getMetaV2('_give_set_price'));
20 }
21
22 if('multi' === $priceOption) {
23 // @note $formV2->levels only returns a single level
24 $donationLevels = $this->getMetaV2('_give_donation_levels');
25
26 $isDescriptionEnabled = false;
27 $amountField->setAttribute('levels',
28 array_map(function ($donationLevel) use (&$isDescriptionEnabled) {
29 $isDescriptionEnabled = $isDescriptionEnabled || ! empty($donationLevel['_give_text']);
30
31 return [
32 'value' => $this->roundAmount($donationLevel['_give_amount']),
33 'label' => $donationLevel['_give_text'],
34 'checked' => isset($donationLevel['_give_default']) && $donationLevel['_give_default'] === 'default',
35 ];
36 }, $donationLevels)
37 );
38 $amountField->setAttribute('descriptionsEnabled', $isDescriptionEnabled);
39 }
40
41 $isCustomAmountEnabled = $this->formV2->isCustomAmountOptionEnabled();
42 $amountField->setAttribute('customAmount', $isCustomAmountEnabled);
43
44 if ($isCustomAmountEnabled) {
45 $customAmountMin = $this->getMetaV2('_give_custom_amount_range_minimum');
46 $customAmountMax = $this->getMetaV2('_give_custom_amount_range_maximum');
47
48 if ($customAmountMin) {
49 $amountField->setAttribute('customAmountMin', $this->roundAmount($customAmountMin));
50 }
51
52 if ($customAmountMax) {
53 $amountField->setAttribute('customAmountMax', $this->roundAmount($customAmountMax));
54 }
55 }
56
57 // @note No corresponding setting in v3 for "Custom Amount Text"
58 }
59
60 /**
61 * @since 3.0.0
62 */
63 private function roundAmount($amount): float
64 {
65 return round((float)$amount, 2);
66 }
67 }
68