|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Factories; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use WMDE\Euro\Euro; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\FeatureToggle; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\UrlGenerator; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Factory for generating classes whose implementations differ due to A/B testing. |
|
15
|
|
|
* |
|
16
|
|
|
* @license GNU GPL v2+ |
|
17
|
|
|
*/ |
|
18
|
|
|
class ChoiceFactory { |
|
19
|
|
|
|
|
20
|
100 |
|
private $featureToggle; |
|
21
|
100 |
|
|
|
22
|
100 |
|
public function __construct( FeatureToggle $featureToggle ) { |
|
23
|
|
|
$this->featureToggle = $featureToggle; |
|
24
|
14 |
|
} |
|
25
|
|
|
|
|
26
|
14 |
|
public function getMembershipCallToActionTemplate(): string { |
|
27
|
10 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.regular' ) ) { |
|
28
|
|
|
return 'partials/donation_confirmation/feature_toggle/call_to_action_regular.html.twig'; |
|
29
|
4 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.video' ) ) { |
|
30
|
4 |
|
return 'partials/donation_confirmation/feature_toggle/call_to_action_video.html.twig'; |
|
31
|
|
|
} |
|
32
|
|
|
throw new UnknownChoiceDefinition( 'Membership Call to Action Template configuration failure.' ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getAmountOption(): array { |
|
36
|
|
|
if ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300_0' ) ) { |
|
37
|
100 |
|
return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] ); |
|
38
|
100 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300' ) ) { |
|
39
|
19 |
|
return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] ); |
|
40
|
81 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to100' ) ) { |
|
41
|
1 |
|
return $this->getAmountOptionInEuros( [ 500, 1000, 1500, 2000, 3000, 5000, 7500, 10000 ] ); |
|
42
|
80 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.15to250' ) ) { |
|
43
|
80 |
|
return $this->getAmountOptionInEuros( [ 1500, 2000, 2500, 3000, 5000, 7500, 10000, 25000 ] ); |
|
44
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.30to250' ) ) { |
|
45
|
|
|
return $this->getAmountOptionInEuros( [ 3000, 4000, 5000, 7500, 10000, 15000, 20000, 25000 ] ); |
|
46
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.50to500' ) ) { |
|
47
|
|
|
return $this->getAmountOptionInEuros( [ 5000, 10000, 15000, 20000, 25000, 30000, 50000 ] ); |
|
48
|
15 |
|
} |
|
49
|
15 |
|
throw new UnknownChoiceDefinition( 'Amount option selection configuration failure.' ); |
|
50
|
15 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getAmountOptionInEuros( array $amountOption ): array { |
|
53
|
|
|
return array_map( function ( int $amount ) { |
|
54
|
|
|
return Euro::newFromCents( $amount ); |
|
55
|
|
|
}, $amountOption ); |
|
56
|
|
|
} |
|
57
|
|
|
} |