|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Factories; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Euro\Euro; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\FeatureToggle; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\UrlGenerator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Factory for generating classes whose implementations differ due to A/B testing. |
|
13
|
|
|
* |
|
14
|
|
|
* @license GNU GPL v2+ |
|
15
|
|
|
*/ |
|
16
|
|
|
class ChoiceFactory { |
|
17
|
|
|
|
|
18
|
|
|
private $featureToggle; |
|
19
|
|
|
|
|
20
|
95 |
|
public function __construct( FeatureToggle $featureToggle ) { |
|
21
|
95 |
|
$this->featureToggle = $featureToggle; |
|
22
|
95 |
|
} |
|
23
|
|
|
|
|
24
|
14 |
|
public function isDonationAddressOptional(): bool { |
|
25
|
|
|
/** The "optional address" feature is only implemented for cat17 */ |
|
26
|
14 |
|
if ( $this->getSkinTemplateDirectory() !== $this->getSkinDirectory( 'cat17' ) ) { |
|
27
|
10 |
|
return false; |
|
28
|
|
|
} |
|
29
|
4 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.donation_address.required' ) ) { |
|
30
|
4 |
|
return false; |
|
31
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.donation_address.optional' ) ) { |
|
32
|
|
|
return true; |
|
33
|
|
|
} |
|
34
|
|
|
throw new UnknownChoiceDefinition( 'Confirmation Page Template configuration failure.' ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
95 |
|
public function getSkinTemplateDirectory(): string { |
|
38
|
95 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.skins.cat17' ) ) { |
|
39
|
14 |
|
return $this->getSkinDirectory( 'cat17' ); |
|
40
|
81 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.skins.10h16' ) ) { |
|
41
|
1 |
|
return $this->getSkinDirectory( '10h16' ); |
|
42
|
80 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.skins.test' ) ) { |
|
43
|
80 |
|
return $this->getSkinDirectory( 'test' ); |
|
44
|
|
|
} |
|
45
|
|
|
throw new UnknownChoiceDefinition( 'Skin selection configuration failure.' ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
15 |
|
public function getMembershipCallToActionTemplate(): string { |
|
49
|
15 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.regular' ) ) { |
|
50
|
8 |
|
return 'partials/donation_confirmation/feature_toggle/call_to_action_regular.html.twig'; |
|
51
|
7 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.video' ) ) { |
|
52
|
7 |
|
return 'partials/donation_confirmation/feature_toggle/call_to_action_video.html.twig'; |
|
53
|
|
|
} |
|
54
|
|
|
throw new UnknownChoiceDefinition( 'Membership Call to Action Template configuration failure.' ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function getAmountOption(): array { |
|
58
|
1 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300_0' ) ) { |
|
59
|
|
|
return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] ); |
|
60
|
1 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300' ) ) { |
|
61
|
1 |
|
return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] ); |
|
62
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to100' ) ) { |
|
63
|
|
|
return $this->getAmountOptionInEuros( [ 500, 1000, 1500, 2000, 3000, 5000, 7500, 10000 ] ); |
|
64
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.15to250' ) ) { |
|
65
|
|
|
return $this->getAmountOptionInEuros( [ 1500, 2000, 2500, 3000, 5000, 7500, 10000, 25000 ] ); |
|
66
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.30to250' ) ) { |
|
67
|
|
|
return $this->getAmountOptionInEuros( [ 3000, 4000, 5000, 7500, 10000, 15000, 20000, 25000 ] ); |
|
68
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.50to500' ) ) { |
|
69
|
|
|
return $this->getAmountOptionInEuros( [ 5000, 10000, 15000, 20000, 25000, 30000, 50000 ] ); |
|
70
|
|
|
} |
|
71
|
|
|
throw new UnknownChoiceDefinition( 'Amount option selection configuration failure.' ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
92 |
|
public function getMainCss(): string { |
|
75
|
92 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.donation_form_design.design_change' ) ) { |
|
76
|
|
|
return '/skins/cat17/css/variant.css'; |
|
77
|
92 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.donation_form_design.default' ) ) { |
|
78
|
92 |
|
return '/skins/cat17/css/main.css'; |
|
79
|
|
|
} |
|
80
|
|
|
throw new UnknownChoiceDefinition( 'Design selection failure.' ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
92 |
|
public function getMainMenuItems( UrlGenerator $urlGenerator ): array { |
|
84
|
92 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.donation_form_design.design_change' ) ) { |
|
85
|
|
|
return [ |
|
86
|
|
|
[ |
|
87
|
|
|
'url' => $urlGenerator->generateRelativeUrl( 'list-comments.html' ), |
|
88
|
|
|
'id' => 'comments-list', |
|
89
|
|
|
'label' => 'menu_item_donation_comments' |
|
90
|
|
|
], |
|
91
|
|
|
[ |
|
92
|
|
|
'url' => $urlGenerator->generateRelativeUrl( 'faq' ), |
|
93
|
|
|
'id' => 'faq', |
|
94
|
|
|
'label' => 'menu_item_faq' |
|
95
|
|
|
], |
|
96
|
|
|
[ |
|
97
|
|
|
'url' => $urlGenerator->generateRelativeUrl( 'use-of-funds' ), |
|
98
|
|
|
'id' => 'use_of_resources', |
|
99
|
|
|
'label' => 'menu_item_use_of_resources' |
|
100
|
|
|
], |
|
101
|
|
|
[ |
|
102
|
|
|
'url' => $urlGenerator->generateRelativeUrl( 'show-donation-form' ), |
|
103
|
|
|
'id' => 'donation', |
|
104
|
|
|
'label' => 'menu_item_donate' |
|
105
|
|
|
], |
|
106
|
|
|
]; |
|
107
|
92 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.donation_form_design.default' ) ) { |
|
108
|
|
|
return [ |
|
109
|
|
|
[ |
|
110
|
92 |
|
'url' => $urlGenerator->generateRelativeUrl( 'list-comments.html' ), |
|
111
|
92 |
|
'id' => 'comments-list', |
|
112
|
92 |
|
'label' => 'menu_item_donation_comments' |
|
113
|
|
|
], |
|
114
|
|
|
[ |
|
115
|
92 |
|
'url' => $urlGenerator->generateRelativeUrl( 'faq' ), |
|
116
|
92 |
|
'id' => 'faq', |
|
117
|
92 |
|
'label' => 'menu_item_faq' |
|
118
|
|
|
], |
|
119
|
|
|
[ |
|
120
|
92 |
|
'url' => $urlGenerator->generateRelativeUrl( 'use-of-funds' ), |
|
121
|
92 |
|
'id' => 'use_of_resources', |
|
122
|
92 |
|
'label' => 'menu_item_use_of_resources' |
|
123
|
|
|
], |
|
124
|
|
|
[ |
|
125
|
92 |
|
'url' => $urlGenerator->generateRelativeUrl( 'page', ['pageName' => 'Spendenquittung'] ), |
|
126
|
92 |
|
'id' => 'donation_receipt', |
|
127
|
92 |
|
'label' => 'menu_item_donation_receipt' |
|
128
|
|
|
], |
|
129
|
|
|
]; |
|
130
|
|
|
} |
|
131
|
|
|
throw new UnknownChoiceDefinition( 'Design selection failure.' ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
26 |
|
public function isFormScrollingActive(): bool { |
|
135
|
26 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.donation_form_design.design_change' ) ) { |
|
136
|
|
|
return false; |
|
137
|
26 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.donation_form_design.default' ) ) { |
|
138
|
26 |
|
return true; |
|
139
|
|
|
} |
|
140
|
|
|
throw new UnknownChoiceDefinition( 'Design selection failure.' ); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
95 |
|
private function getSkinDirectory( string $skin ): string { |
|
144
|
95 |
|
return 'skins/' . $skin . '/templates'; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
1 |
|
public function getAmountOptionInEuros( array $amountOption ): array { |
|
148
|
|
|
return array_map( function ( int $amount ) { |
|
149
|
1 |
|
return Euro::newFromCents( $amount ); |
|
150
|
1 |
|
}, $amountOption ); |
|
151
|
|
|
} |
|
152
|
|
|
} |