@@ -29,121 +29,121 @@ |
||
29 | 29 | class RegFormFactory |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * legacy SPCO reg form |
|
34 | - */ |
|
35 | - const VERSION_1 = 'v1'; |
|
32 | + /** |
|
33 | + * legacy SPCO reg form |
|
34 | + */ |
|
35 | + const VERSION_1 = 'v1'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Form Sections and Form Elements generated using Barista Form Builder |
|
39 | - */ |
|
40 | - const VERSION_2 = 'v2'; |
|
37 | + /** |
|
38 | + * Form Sections and Form Elements generated using Barista Form Builder |
|
39 | + */ |
|
40 | + const VERSION_2 = 'v2'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - private $reg_form_version; |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + private $reg_form_version; |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * RegFormFactory constructor. |
|
50 | - * |
|
51 | - * @param string $reg_form_version |
|
52 | - */ |
|
53 | - public function __construct(string $reg_form_version = RegFormFactory::VERSION_1) |
|
54 | - { |
|
55 | - $this->reg_form_version = $reg_form_version; |
|
56 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1); |
|
57 | - \EEH_Debug_Tools::printr($this->reg_form_version, '$this->reg_form_version', __FILE__, __LINE__); |
|
58 | - } |
|
48 | + /** |
|
49 | + * RegFormFactory constructor. |
|
50 | + * |
|
51 | + * @param string $reg_form_version |
|
52 | + */ |
|
53 | + public function __construct(string $reg_form_version = RegFormFactory::VERSION_1) |
|
54 | + { |
|
55 | + $this->reg_form_version = $reg_form_version; |
|
56 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1); |
|
57 | + \EEH_Debug_Tools::printr($this->reg_form_version, '$this->reg_form_version', __FILE__, __LINE__); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * @param array $dependencies |
|
63 | - * @return FormSectionProperInterface |
|
64 | - * @throws EE_Error |
|
65 | - * @throws ReflectionException |
|
66 | - */ |
|
67 | - public function getRegForm(array $dependencies): FormSectionProperInterface |
|
68 | - { |
|
69 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
70 | - $this->registerDependencies(); |
|
71 | - switch ($this->reg_form_version) { |
|
72 | - case RegFormFactory::VERSION_2: |
|
73 | - $reg_step = $dependencies[0]; |
|
74 | - if (! $reg_step instanceof EE_SPCO_Reg_Step) { |
|
75 | - throw new DomainException( |
|
76 | - esc_html__('Invalid or missing SPCO Registration Step', 'event_espresso') |
|
77 | - ); |
|
78 | - } |
|
79 | - /** @var FormSubmissionHandler $form_submission_handler */ |
|
80 | - $form_submission_handler = LoaderFactory::getNew( |
|
81 | - FormSubmissionHandler::class, |
|
82 | - [$reg_step->checkout->transaction] |
|
83 | - ); |
|
84 | - $form_data_api = $form_submission_handler->getFormDataAPI(); |
|
85 | - return LoaderFactory::getShared(RegFormV2::class, [$reg_step, $form_data_api]); |
|
86 | - case RegFormFactory::VERSION_1: |
|
87 | - default: |
|
88 | - return LoaderFactory::getShared(RegFormV1::class, $dependencies); |
|
89 | - } |
|
90 | - } |
|
61 | + /** |
|
62 | + * @param array $dependencies |
|
63 | + * @return FormSectionProperInterface |
|
64 | + * @throws EE_Error |
|
65 | + * @throws ReflectionException |
|
66 | + */ |
|
67 | + public function getRegForm(array $dependencies): FormSectionProperInterface |
|
68 | + { |
|
69 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
70 | + $this->registerDependencies(); |
|
71 | + switch ($this->reg_form_version) { |
|
72 | + case RegFormFactory::VERSION_2: |
|
73 | + $reg_step = $dependencies[0]; |
|
74 | + if (! $reg_step instanceof EE_SPCO_Reg_Step) { |
|
75 | + throw new DomainException( |
|
76 | + esc_html__('Invalid or missing SPCO Registration Step', 'event_espresso') |
|
77 | + ); |
|
78 | + } |
|
79 | + /** @var FormSubmissionHandler $form_submission_handler */ |
|
80 | + $form_submission_handler = LoaderFactory::getNew( |
|
81 | + FormSubmissionHandler::class, |
|
82 | + [$reg_step->checkout->transaction] |
|
83 | + ); |
|
84 | + $form_data_api = $form_submission_handler->getFormDataAPI(); |
|
85 | + return LoaderFactory::getShared(RegFormV2::class, [$reg_step, $form_data_api]); |
|
86 | + case RegFormFactory::VERSION_1: |
|
87 | + default: |
|
88 | + return LoaderFactory::getShared(RegFormV1::class, $dependencies); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @return void |
|
95 | - * @throws InvalidArgumentException |
|
96 | - */ |
|
97 | - private function registerDependencies() |
|
98 | - { |
|
99 | - switch ($this->reg_form_version) { |
|
100 | - case RegFormFactory::VERSION_1: |
|
101 | - /** @var RegFormDepHandlerV1 $dependency_handler */ |
|
102 | - $dependency_handler = LoaderFactory::getShared(RegFormDepHandlerV1::class); |
|
103 | - break; |
|
104 | - case RegFormFactory::VERSION_2: |
|
105 | - /** @var RegFormDepHandlerV2 $dependency_handler */ |
|
106 | - $dependency_handler = LoaderFactory::getShared(RegFormDepHandlerV2::class); |
|
107 | - break; |
|
108 | - default: |
|
109 | - throw new InvalidArgumentException( |
|
110 | - esc_html__( |
|
111 | - 'Invalid registration form version requested. Version number must match one of the RegFormFactory::VERSION_* constants.', |
|
112 | - 'event_espresso' |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - if (! $dependency_handler instanceof DependencyHandler) { |
|
117 | - throw new DomainException( |
|
118 | - esc_html__('Invalid Registration Form DependencyHandler.', 'event_espresso') |
|
119 | - ); |
|
120 | - } |
|
121 | - $dependency_handler->registerDependencies(); |
|
122 | - } |
|
93 | + /** |
|
94 | + * @return void |
|
95 | + * @throws InvalidArgumentException |
|
96 | + */ |
|
97 | + private function registerDependencies() |
|
98 | + { |
|
99 | + switch ($this->reg_form_version) { |
|
100 | + case RegFormFactory::VERSION_1: |
|
101 | + /** @var RegFormDepHandlerV1 $dependency_handler */ |
|
102 | + $dependency_handler = LoaderFactory::getShared(RegFormDepHandlerV1::class); |
|
103 | + break; |
|
104 | + case RegFormFactory::VERSION_2: |
|
105 | + /** @var RegFormDepHandlerV2 $dependency_handler */ |
|
106 | + $dependency_handler = LoaderFactory::getShared(RegFormDepHandlerV2::class); |
|
107 | + break; |
|
108 | + default: |
|
109 | + throw new InvalidArgumentException( |
|
110 | + esc_html__( |
|
111 | + 'Invalid registration form version requested. Version number must match one of the RegFormFactory::VERSION_* constants.', |
|
112 | + 'event_espresso' |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + if (! $dependency_handler instanceof DependencyHandler) { |
|
117 | + throw new DomainException( |
|
118 | + esc_html__('Invalid Registration Form DependencyHandler.', 'event_espresso') |
|
119 | + ); |
|
120 | + } |
|
121 | + $dependency_handler->registerDependencies(); |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - /** |
|
126 | - * @param EE_Checkout $checkout |
|
127 | - * @return RegFormHandlerInterface |
|
128 | - * @throws EE_Error |
|
129 | - * @throws ReflectionException |
|
130 | - */ |
|
131 | - public function getRegFormHandler(EE_Checkout $checkout): RegFormHandlerInterface |
|
132 | - { |
|
133 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
134 | - switch ($this->reg_form_version) { |
|
135 | - case RegFormFactory::VERSION_2: |
|
136 | - /** @var RegFormHandlerV2 $handler */ |
|
137 | - $handler = LoaderFactory::getNew(RegFormHandlerV2::class, [$checkout]); |
|
138 | - $handler->getFormSubmission(); |
|
139 | - $handler->initializeInputHandler(); |
|
140 | - return $handler; |
|
141 | - case RegFormFactory::VERSION_1: |
|
142 | - default: |
|
143 | - /** @var RegFormHandlerV1 $handler */ |
|
144 | - $handler = LoaderFactory::getNew(RegFormHandlerV1::class, [$checkout]); |
|
145 | - $handler->initializeInputHandler(); |
|
146 | - return $handler; |
|
147 | - } |
|
148 | - } |
|
125 | + /** |
|
126 | + * @param EE_Checkout $checkout |
|
127 | + * @return RegFormHandlerInterface |
|
128 | + * @throws EE_Error |
|
129 | + * @throws ReflectionException |
|
130 | + */ |
|
131 | + public function getRegFormHandler(EE_Checkout $checkout): RegFormHandlerInterface |
|
132 | + { |
|
133 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
134 | + switch ($this->reg_form_version) { |
|
135 | + case RegFormFactory::VERSION_2: |
|
136 | + /** @var RegFormHandlerV2 $handler */ |
|
137 | + $handler = LoaderFactory::getNew(RegFormHandlerV2::class, [$checkout]); |
|
138 | + $handler->getFormSubmission(); |
|
139 | + $handler->initializeInputHandler(); |
|
140 | + return $handler; |
|
141 | + case RegFormFactory::VERSION_1: |
|
142 | + default: |
|
143 | + /** @var RegFormHandlerV1 $handler */ |
|
144 | + $handler = LoaderFactory::getNew(RegFormHandlerV1::class, [$checkout]); |
|
145 | + $handler->initializeInputHandler(); |
|
146 | + return $handler; |
|
147 | + } |
|
148 | + } |
|
149 | 149 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | switch ($this->reg_form_version) { |
72 | 72 | case RegFormFactory::VERSION_2: |
73 | 73 | $reg_step = $dependencies[0]; |
74 | - if (! $reg_step instanceof EE_SPCO_Reg_Step) { |
|
74 | + if ( ! $reg_step instanceof EE_SPCO_Reg_Step) { |
|
75 | 75 | throw new DomainException( |
76 | 76 | esc_html__('Invalid or missing SPCO Registration Step', 'event_espresso') |
77 | 77 | ); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | FormSubmissionHandler::class, |
82 | 82 | [$reg_step->checkout->transaction] |
83 | 83 | ); |
84 | - $form_data_api = $form_submission_handler->getFormDataAPI(); |
|
84 | + $form_data_api = $form_submission_handler->getFormDataAPI(); |
|
85 | 85 | return LoaderFactory::getShared(RegFormV2::class, [$reg_step, $form_data_api]); |
86 | 86 | case RegFormFactory::VERSION_1: |
87 | 87 | default: |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ) |
114 | 114 | ); |
115 | 115 | } |
116 | - if (! $dependency_handler instanceof DependencyHandler) { |
|
116 | + if ( ! $dependency_handler instanceof DependencyHandler) { |
|
117 | 117 | throw new DomainException( |
118 | 118 | esc_html__('Invalid Registration Form DependencyHandler.', 'event_espresso') |
119 | 119 | ); |
@@ -32,263 +32,263 @@ |
||
32 | 32 | abstract class RegForm extends EE_Form_Section_Proper implements FormSectionProperInterface |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var bool |
|
37 | - */ |
|
38 | - protected $print_copy_info = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var EE_Registration_Config |
|
42 | - */ |
|
43 | - public $reg_config; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var int |
|
47 | - */ |
|
48 | - protected $reg_form_count = 0; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var EE_SPCO_Reg_Step_Attendee_Information |
|
52 | - */ |
|
53 | - public $reg_step; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected $required_questions = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - protected $template_args = []; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * RegForm constructor. |
|
68 | - * |
|
69 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
70 | - * @param EE_Registration_Config $reg_config |
|
71 | - * @throws ReflectionException |
|
72 | - * @throws EE_Error |
|
73 | - */ |
|
74 | - public function __construct( |
|
75 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
76 | - EE_Registration_Config $reg_config |
|
77 | - ) { |
|
78 | - $this->reg_step = $reg_step; |
|
79 | - $this->reg_config = $reg_config; |
|
80 | - // setup some classes so that they are ready for loading during construction of other classes |
|
81 | - LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]); |
|
82 | - LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]); |
|
83 | - parent::__construct( |
|
84 | - [ |
|
85 | - 'name' => $this->reg_step->reg_form_name(), |
|
86 | - 'html_id' => $this->reg_step->reg_form_name(), |
|
87 | - 'subsections' => $this->generateSubsections(), |
|
88 | - 'layout_strategy' => new EE_Template_Layout( |
|
89 | - [ |
|
90 | - 'layout_template_file' => $this->reg_step->template(), // layout_template |
|
91 | - 'template_args' => $this->template_args, |
|
92 | - ] |
|
93 | - ), |
|
94 | - ] |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param EE_Registration $registration |
|
101 | - * @param bool $admin_request |
|
102 | - * @param bool $copy_attendee_info |
|
103 | - * @param callable $enablePrintCopyInfo |
|
104 | - * @return RegistrantFormInterface |
|
105 | - */ |
|
106 | - abstract protected function getRegistrantForm( |
|
107 | - EE_Registration $registration, |
|
108 | - bool $admin_request, |
|
109 | - bool $copy_attendee_info, |
|
110 | - callable $enablePrintCopyInfo |
|
111 | - ): RegistrantFormInterface; |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return void |
|
116 | - */ |
|
117 | - public function enablePrintCopyInfo(): void |
|
118 | - { |
|
119 | - $this->print_copy_info = true; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - public function printCopyInfo(): bool |
|
127 | - { |
|
128 | - return $this->print_copy_info; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function regFormCount(): int |
|
136 | - { |
|
137 | - return $this->reg_form_count; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - public function requiredQuestions(): array |
|
145 | - { |
|
146 | - return $this->required_questions; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $identifier |
|
152 | - * @param bool $required_question |
|
153 | - */ |
|
154 | - public function addRequiredQuestion(string $identifier, bool $required_question): void |
|
155 | - { |
|
156 | - $this->required_questions[ $identifier ] = $required_question; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return EE_Form_Section_Proper[] |
|
162 | - * @throws DomainException |
|
163 | - * @throws EE_Error |
|
164 | - * @throws InvalidArgumentException |
|
165 | - * @throws ReflectionException |
|
166 | - * @throws EntityNotFoundException |
|
167 | - * @throws InvalidDataTypeException |
|
168 | - * @throws InvalidInterfaceException |
|
169 | - */ |
|
170 | - private function generateSubsections(): array |
|
171 | - { |
|
172 | - // Init reg forms count. |
|
173 | - $this->reg_form_count = 0; |
|
174 | - |
|
175 | - $primary_registrant = null; |
|
176 | - // autoload Line_Item_Display classes |
|
177 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
178 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
179 | - // calculate taxes |
|
180 | - $Line_Item_Display->display_line_item( |
|
181 | - $this->reg_step->checkout->cart->get_grand_total(), |
|
182 | - ['set_tax_rate' => true] |
|
183 | - ); |
|
184 | - $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs(); |
|
185 | - $this->addPrivacyConsentCheckbox($extra_inputs_section); |
|
186 | - $subsections = [ |
|
187 | - 'default_hidden_inputs' => $extra_inputs_section, |
|
188 | - ]; |
|
189 | - |
|
190 | - $this->template_args = [ |
|
191 | - 'revisit' => $this->reg_step->checkout->revisit, |
|
192 | - 'registrations' => [], |
|
193 | - 'ticket_count' => [], |
|
194 | - ]; |
|
195 | - // grab the saved registrations from the transaction |
|
196 | - $registrations = $this->reg_step->checkout->transaction->registrations( |
|
197 | - $this->reg_step->checkout->reg_cache_where_params |
|
198 | - ); |
|
199 | - if ($registrations) { |
|
200 | - foreach ($registrations as $registration) { |
|
201 | - // can this registration be processed during this visit ? |
|
202 | - if ( |
|
203 | - $registration instanceof EE_Registration |
|
204 | - && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration) |
|
205 | - ) { |
|
206 | - $reg_url_link = $registration->reg_url_link(); |
|
207 | - $registrant_form = $this->getRegistrantForm( |
|
208 | - $registration, |
|
209 | - $this->reg_step->checkout->admin_request, |
|
210 | - $this->reg_config->copyAttendeeInfo(), |
|
211 | - [$this, 'enablePrintCopyInfo'] |
|
212 | - ); |
|
213 | - // Increment the reg forms number if form is valid. |
|
214 | - if ($registrant_form->hasQuestions()) { |
|
215 | - $this->reg_form_count++; |
|
216 | - $subsections[ $reg_url_link ] = $registrant_form; |
|
217 | - } else { |
|
218 | - // or just add a blank section if there are no questions |
|
219 | - $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
220 | - } |
|
221 | - |
|
222 | - $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
223 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
224 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
225 | - ) |
|
226 | - ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
227 | - : 1; |
|
228 | - $ticket_line_item = |
|
229 | - EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
230 | - $this->reg_step->checkout->cart->get_grand_total(), |
|
231 | - 'Ticket', |
|
232 | - [$registration->ticket()->ID()] |
|
233 | - ); |
|
234 | - $ticket_line_item = |
|
235 | - is_array($ticket_line_item) |
|
236 | - ? reset($ticket_line_item) |
|
237 | - : $ticket_line_item; |
|
238 | - $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
239 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
240 | - if ($registration->is_primary_registrant()) { |
|
241 | - $primary_registrant = $reg_url_link; |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - if ($primary_registrant && count($registrations) > 1) { |
|
247 | - if ( |
|
248 | - isset($subsections[ $primary_registrant ]) |
|
249 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
250 | - ) { |
|
251 | - $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
|
252 | - ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
|
253 | - : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
|
254 | - $subsections[ $primary_registrant ]->add_subsections( |
|
255 | - $copy_options, |
|
256 | - 'primary_registrant', |
|
257 | - false |
|
258 | - ); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - // Set the registration form template (default: one form per ticket details table). |
|
264 | - // We decide the template to used based on the number of forms. |
|
265 | - $template = $this->reg_form_count > 1 |
|
266 | - ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
267 | - : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
268 | - $this->reg_step->setTemplate($template); |
|
269 | - |
|
270 | - return $subsections; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param EE_Form_Section_Proper $extra_inputs_section |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
|
279 | - { |
|
280 | - // if this isn't a revisit, and they have the privacy consent box enabled, add it |
|
281 | - if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
282 | - $extra_inputs_section->add_subsections( |
|
283 | - [ |
|
284 | - 'consent_box' => new PrivacyConsentCheckboxForm( |
|
285 | - $this->reg_step->slug(), |
|
286 | - $this->reg_config->getConsentCheckboxLabelText() |
|
287 | - ) |
|
288 | - ], |
|
289 | - null, |
|
290 | - false |
|
291 | - ); |
|
292 | - } |
|
293 | - } |
|
35 | + /** |
|
36 | + * @var bool |
|
37 | + */ |
|
38 | + protected $print_copy_info = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var EE_Registration_Config |
|
42 | + */ |
|
43 | + public $reg_config; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var int |
|
47 | + */ |
|
48 | + protected $reg_form_count = 0; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var EE_SPCO_Reg_Step_Attendee_Information |
|
52 | + */ |
|
53 | + public $reg_step; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected $required_questions = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + protected $template_args = []; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * RegForm constructor. |
|
68 | + * |
|
69 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
70 | + * @param EE_Registration_Config $reg_config |
|
71 | + * @throws ReflectionException |
|
72 | + * @throws EE_Error |
|
73 | + */ |
|
74 | + public function __construct( |
|
75 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
76 | + EE_Registration_Config $reg_config |
|
77 | + ) { |
|
78 | + $this->reg_step = $reg_step; |
|
79 | + $this->reg_config = $reg_config; |
|
80 | + // setup some classes so that they are ready for loading during construction of other classes |
|
81 | + LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]); |
|
82 | + LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]); |
|
83 | + parent::__construct( |
|
84 | + [ |
|
85 | + 'name' => $this->reg_step->reg_form_name(), |
|
86 | + 'html_id' => $this->reg_step->reg_form_name(), |
|
87 | + 'subsections' => $this->generateSubsections(), |
|
88 | + 'layout_strategy' => new EE_Template_Layout( |
|
89 | + [ |
|
90 | + 'layout_template_file' => $this->reg_step->template(), // layout_template |
|
91 | + 'template_args' => $this->template_args, |
|
92 | + ] |
|
93 | + ), |
|
94 | + ] |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param EE_Registration $registration |
|
101 | + * @param bool $admin_request |
|
102 | + * @param bool $copy_attendee_info |
|
103 | + * @param callable $enablePrintCopyInfo |
|
104 | + * @return RegistrantFormInterface |
|
105 | + */ |
|
106 | + abstract protected function getRegistrantForm( |
|
107 | + EE_Registration $registration, |
|
108 | + bool $admin_request, |
|
109 | + bool $copy_attendee_info, |
|
110 | + callable $enablePrintCopyInfo |
|
111 | + ): RegistrantFormInterface; |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return void |
|
116 | + */ |
|
117 | + public function enablePrintCopyInfo(): void |
|
118 | + { |
|
119 | + $this->print_copy_info = true; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + public function printCopyInfo(): bool |
|
127 | + { |
|
128 | + return $this->print_copy_info; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function regFormCount(): int |
|
136 | + { |
|
137 | + return $this->reg_form_count; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + public function requiredQuestions(): array |
|
145 | + { |
|
146 | + return $this->required_questions; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $identifier |
|
152 | + * @param bool $required_question |
|
153 | + */ |
|
154 | + public function addRequiredQuestion(string $identifier, bool $required_question): void |
|
155 | + { |
|
156 | + $this->required_questions[ $identifier ] = $required_question; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return EE_Form_Section_Proper[] |
|
162 | + * @throws DomainException |
|
163 | + * @throws EE_Error |
|
164 | + * @throws InvalidArgumentException |
|
165 | + * @throws ReflectionException |
|
166 | + * @throws EntityNotFoundException |
|
167 | + * @throws InvalidDataTypeException |
|
168 | + * @throws InvalidInterfaceException |
|
169 | + */ |
|
170 | + private function generateSubsections(): array |
|
171 | + { |
|
172 | + // Init reg forms count. |
|
173 | + $this->reg_form_count = 0; |
|
174 | + |
|
175 | + $primary_registrant = null; |
|
176 | + // autoload Line_Item_Display classes |
|
177 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
178 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
179 | + // calculate taxes |
|
180 | + $Line_Item_Display->display_line_item( |
|
181 | + $this->reg_step->checkout->cart->get_grand_total(), |
|
182 | + ['set_tax_rate' => true] |
|
183 | + ); |
|
184 | + $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs(); |
|
185 | + $this->addPrivacyConsentCheckbox($extra_inputs_section); |
|
186 | + $subsections = [ |
|
187 | + 'default_hidden_inputs' => $extra_inputs_section, |
|
188 | + ]; |
|
189 | + |
|
190 | + $this->template_args = [ |
|
191 | + 'revisit' => $this->reg_step->checkout->revisit, |
|
192 | + 'registrations' => [], |
|
193 | + 'ticket_count' => [], |
|
194 | + ]; |
|
195 | + // grab the saved registrations from the transaction |
|
196 | + $registrations = $this->reg_step->checkout->transaction->registrations( |
|
197 | + $this->reg_step->checkout->reg_cache_where_params |
|
198 | + ); |
|
199 | + if ($registrations) { |
|
200 | + foreach ($registrations as $registration) { |
|
201 | + // can this registration be processed during this visit ? |
|
202 | + if ( |
|
203 | + $registration instanceof EE_Registration |
|
204 | + && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration) |
|
205 | + ) { |
|
206 | + $reg_url_link = $registration->reg_url_link(); |
|
207 | + $registrant_form = $this->getRegistrantForm( |
|
208 | + $registration, |
|
209 | + $this->reg_step->checkout->admin_request, |
|
210 | + $this->reg_config->copyAttendeeInfo(), |
|
211 | + [$this, 'enablePrintCopyInfo'] |
|
212 | + ); |
|
213 | + // Increment the reg forms number if form is valid. |
|
214 | + if ($registrant_form->hasQuestions()) { |
|
215 | + $this->reg_form_count++; |
|
216 | + $subsections[ $reg_url_link ] = $registrant_form; |
|
217 | + } else { |
|
218 | + // or just add a blank section if there are no questions |
|
219 | + $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
220 | + } |
|
221 | + |
|
222 | + $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
223 | + $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
224 | + $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
225 | + ) |
|
226 | + ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
227 | + : 1; |
|
228 | + $ticket_line_item = |
|
229 | + EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
230 | + $this->reg_step->checkout->cart->get_grand_total(), |
|
231 | + 'Ticket', |
|
232 | + [$registration->ticket()->ID()] |
|
233 | + ); |
|
234 | + $ticket_line_item = |
|
235 | + is_array($ticket_line_item) |
|
236 | + ? reset($ticket_line_item) |
|
237 | + : $ticket_line_item; |
|
238 | + $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
239 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
240 | + if ($registration->is_primary_registrant()) { |
|
241 | + $primary_registrant = $reg_url_link; |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + if ($primary_registrant && count($registrations) > 1) { |
|
247 | + if ( |
|
248 | + isset($subsections[ $primary_registrant ]) |
|
249 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
250 | + ) { |
|
251 | + $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
|
252 | + ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
|
253 | + : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
|
254 | + $subsections[ $primary_registrant ]->add_subsections( |
|
255 | + $copy_options, |
|
256 | + 'primary_registrant', |
|
257 | + false |
|
258 | + ); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + // Set the registration form template (default: one form per ticket details table). |
|
264 | + // We decide the template to used based on the number of forms. |
|
265 | + $template = $this->reg_form_count > 1 |
|
266 | + ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
267 | + : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
268 | + $this->reg_step->setTemplate($template); |
|
269 | + |
|
270 | + return $subsections; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param EE_Form_Section_Proper $extra_inputs_section |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
|
279 | + { |
|
280 | + // if this isn't a revisit, and they have the privacy consent box enabled, add it |
|
281 | + if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
282 | + $extra_inputs_section->add_subsections( |
|
283 | + [ |
|
284 | + 'consent_box' => new PrivacyConsentCheckboxForm( |
|
285 | + $this->reg_step->slug(), |
|
286 | + $this->reg_config->getConsentCheckboxLabelText() |
|
287 | + ) |
|
288 | + ], |
|
289 | + null, |
|
290 | + false |
|
291 | + ); |
|
292 | + } |
|
293 | + } |
|
294 | 294 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function addRequiredQuestion(string $identifier, bool $required_question): void |
155 | 155 | { |
156 | - $this->required_questions[ $identifier ] = $required_question; |
|
156 | + $this->required_questions[$identifier] = $required_question; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | |
@@ -213,29 +213,29 @@ discard block |
||
213 | 213 | // Increment the reg forms number if form is valid. |
214 | 214 | if ($registrant_form->hasQuestions()) { |
215 | 215 | $this->reg_form_count++; |
216 | - $subsections[ $reg_url_link ] = $registrant_form; |
|
216 | + $subsections[$reg_url_link] = $registrant_form; |
|
217 | 217 | } else { |
218 | 218 | // or just add a blank section if there are no questions |
219 | - $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
219 | + $subsections[$reg_url_link] = new EE_Form_Section_HTML(); |
|
220 | 220 | } |
221 | 221 | |
222 | - $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
223 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
224 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
222 | + $this->template_args['registrations'][$reg_url_link] = $registration; |
|
223 | + $this->template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
224 | + $this->template_args['ticket_count'][$registration->ticket()->ID()] |
|
225 | 225 | ) |
226 | - ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
226 | + ? $this->template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
227 | 227 | : 1; |
228 | - $ticket_line_item = |
|
228 | + $ticket_line_item = |
|
229 | 229 | EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
230 | 230 | $this->reg_step->checkout->cart->get_grand_total(), |
231 | 231 | 'Ticket', |
232 | 232 | [$registration->ticket()->ID()] |
233 | 233 | ); |
234 | - $ticket_line_item = |
|
234 | + $ticket_line_item = |
|
235 | 235 | is_array($ticket_line_item) |
236 | 236 | ? reset($ticket_line_item) |
237 | 237 | : $ticket_line_item; |
238 | - $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
238 | + $this->template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
239 | 239 | $Line_Item_Display->display_line_item($ticket_line_item); |
240 | 240 | if ($registration->is_primary_registrant()) { |
241 | 241 | $primary_registrant = $reg_url_link; |
@@ -245,13 +245,13 @@ discard block |
||
245 | 245 | |
246 | 246 | if ($primary_registrant && count($registrations) > 1) { |
247 | 247 | if ( |
248 | - isset($subsections[ $primary_registrant ]) |
|
249 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
248 | + isset($subsections[$primary_registrant]) |
|
249 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
250 | 250 | ) { |
251 | 251 | $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
252 | 252 | ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
253 | 253 | : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
254 | - $subsections[ $primary_registrant ]->add_subsections( |
|
254 | + $subsections[$primary_registrant]->add_subsections( |
|
255 | 255 | $copy_options, |
256 | 256 | 'primary_registrant', |
257 | 257 | false |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | // Set the registration form template (default: one form per ticket details table). |
264 | 264 | // We decide the template to used based on the number of forms. |
265 | 265 | $template = $this->reg_form_count > 1 |
266 | - ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
267 | - : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
266 | + ? SPCO_REG_STEPS_PATH . $this->reg_step->slug().'/attendee_info_main.template.php' |
|
267 | + : SPCO_REG_STEPS_PATH.$this->reg_step->slug().'/attendee_info_single.template.php'; |
|
268 | 268 | $this->reg_step->setTemplate($template); |
269 | 269 | |
270 | 270 | return $subsections; |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
279 | 279 | { |
280 | 280 | // if this isn't a revisit, and they have the privacy consent box enabled, add it |
281 | - if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
281 | + if ( ! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
282 | 282 | $extra_inputs_section->add_subsections( |
283 | 283 | [ |
284 | 284 | 'consent_box' => new PrivacyConsentCheckboxForm( |
@@ -11,137 +11,137 @@ |
||
11 | 11 | |
12 | 12 | abstract class RegistrantForm extends EE_Form_Section_Proper implements RegistrantFormInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $form_args = []; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var bool |
|
21 | - */ |
|
22 | - private $has_questions = false; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * RegistrantForm constructor. |
|
27 | - * |
|
28 | - * @param array $form_args |
|
29 | - * @throws EE_Error |
|
30 | - */ |
|
31 | - public function __construct(array $form_args) |
|
32 | - { |
|
33 | - parent::__construct($form_args); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param EE_Registration $registration |
|
39 | - * @return void |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - protected function addAdditionalAttendeeRegInfoInput(EE_Registration $registration) |
|
43 | - { |
|
44 | - // generate hidden input |
|
45 | - $this->form_args['subsections']['additional_attendee_reg_info'] = new EE_Hidden_Input( |
|
46 | - [ |
|
47 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
48 | - 'default' => true, |
|
49 | - ] |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param EE_Registration $registration |
|
56 | - * @return void |
|
57 | - * @throws EE_Error |
|
58 | - */ |
|
59 | - protected function addAdditionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
60 | - { |
|
61 | - if ($registration->is_primary_registrant()) { |
|
62 | - // generate hidden input |
|
63 | - $this->form_args['subsections']['primary_registrant'] = new EE_Hidden_Input( |
|
64 | - [ |
|
65 | - 'html_id' => 'primary_registrant', |
|
66 | - 'default' => $registration->reg_url_link(), |
|
67 | - ] |
|
68 | - ); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param int $attendee_nmbr |
|
75 | - * @param bool $copy_attendee_info |
|
76 | - * @param callable $enablePrintCopyInfo |
|
77 | - */ |
|
78 | - protected function enablePrintCopyInfo( |
|
79 | - int $attendee_nmbr, |
|
80 | - bool $copy_attendee_info, |
|
81 | - callable $enablePrintCopyInfo |
|
82 | - ) { |
|
83 | - // If we have question groups for additional attendees, then display the copy options |
|
84 | - $printCopyInfo = apply_filters( |
|
85 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
86 | - $attendee_nmbr > 1 && $copy_attendee_info, |
|
87 | - $attendee_nmbr |
|
88 | - ); |
|
89 | - if ($printCopyInfo) { |
|
90 | - $enablePrintCopyInfo(); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param EE_Registration $registration |
|
97 | - * @param bool $admin_request |
|
98 | - * @param int $attendee_nmbr |
|
99 | - * @return array |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - protected function generateTopLevelFormArgs( |
|
103 | - EE_Registration $registration, |
|
104 | - bool $admin_request, |
|
105 | - int $attendee_nmbr |
|
106 | - ): array { |
|
107 | - return [ |
|
108 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
109 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
110 | - 'html_style' => $admin_request |
|
111 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
112 | - : '', |
|
113 | - 'subsections' => [], |
|
114 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
115 | - [ |
|
116 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
117 | - 'legend_text' => sprintf( |
|
118 | - esc_html_x( |
|
119 | - 'Attendee %d', |
|
120 | - 'Attendee 123', |
|
121 | - 'event_espresso' |
|
122 | - ), |
|
123 | - $attendee_nmbr |
|
124 | - ), |
|
125 | - ] |
|
126 | - ), |
|
127 | - ]; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - public function hasQuestions(): bool |
|
135 | - { |
|
136 | - return $this->has_questions; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - protected function setHasQuestions(): void |
|
144 | - { |
|
145 | - $this->has_questions = ! empty($this->form_args); |
|
146 | - } |
|
14 | + /** |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $form_args = []; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var bool |
|
21 | + */ |
|
22 | + private $has_questions = false; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * RegistrantForm constructor. |
|
27 | + * |
|
28 | + * @param array $form_args |
|
29 | + * @throws EE_Error |
|
30 | + */ |
|
31 | + public function __construct(array $form_args) |
|
32 | + { |
|
33 | + parent::__construct($form_args); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param EE_Registration $registration |
|
39 | + * @return void |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + protected function addAdditionalAttendeeRegInfoInput(EE_Registration $registration) |
|
43 | + { |
|
44 | + // generate hidden input |
|
45 | + $this->form_args['subsections']['additional_attendee_reg_info'] = new EE_Hidden_Input( |
|
46 | + [ |
|
47 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
48 | + 'default' => true, |
|
49 | + ] |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param EE_Registration $registration |
|
56 | + * @return void |
|
57 | + * @throws EE_Error |
|
58 | + */ |
|
59 | + protected function addAdditionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
60 | + { |
|
61 | + if ($registration->is_primary_registrant()) { |
|
62 | + // generate hidden input |
|
63 | + $this->form_args['subsections']['primary_registrant'] = new EE_Hidden_Input( |
|
64 | + [ |
|
65 | + 'html_id' => 'primary_registrant', |
|
66 | + 'default' => $registration->reg_url_link(), |
|
67 | + ] |
|
68 | + ); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param int $attendee_nmbr |
|
75 | + * @param bool $copy_attendee_info |
|
76 | + * @param callable $enablePrintCopyInfo |
|
77 | + */ |
|
78 | + protected function enablePrintCopyInfo( |
|
79 | + int $attendee_nmbr, |
|
80 | + bool $copy_attendee_info, |
|
81 | + callable $enablePrintCopyInfo |
|
82 | + ) { |
|
83 | + // If we have question groups for additional attendees, then display the copy options |
|
84 | + $printCopyInfo = apply_filters( |
|
85 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
86 | + $attendee_nmbr > 1 && $copy_attendee_info, |
|
87 | + $attendee_nmbr |
|
88 | + ); |
|
89 | + if ($printCopyInfo) { |
|
90 | + $enablePrintCopyInfo(); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param EE_Registration $registration |
|
97 | + * @param bool $admin_request |
|
98 | + * @param int $attendee_nmbr |
|
99 | + * @return array |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + protected function generateTopLevelFormArgs( |
|
103 | + EE_Registration $registration, |
|
104 | + bool $admin_request, |
|
105 | + int $attendee_nmbr |
|
106 | + ): array { |
|
107 | + return [ |
|
108 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
109 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
110 | + 'html_style' => $admin_request |
|
111 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
112 | + : '', |
|
113 | + 'subsections' => [], |
|
114 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
115 | + [ |
|
116 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
117 | + 'legend_text' => sprintf( |
|
118 | + esc_html_x( |
|
119 | + 'Attendee %d', |
|
120 | + 'Attendee 123', |
|
121 | + 'event_espresso' |
|
122 | + ), |
|
123 | + $attendee_nmbr |
|
124 | + ), |
|
125 | + ] |
|
126 | + ), |
|
127 | + ]; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + public function hasQuestions(): bool |
|
135 | + { |
|
136 | + return $this->has_questions; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + protected function setHasQuestions(): void |
|
144 | + { |
|
145 | + $this->has_questions = ! empty($this->form_args); |
|
146 | + } |
|
147 | 147 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | // generate hidden input |
45 | 45 | $this->form_args['subsections']['additional_attendee_reg_info'] = new EE_Hidden_Input( |
46 | 46 | [ |
47 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
47 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
48 | 48 | 'default' => true, |
49 | 49 | ] |
50 | 50 | ); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | int $attendee_nmbr |
106 | 106 | ): array { |
107 | 107 | return [ |
108 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
108 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
109 | 109 | 'html_class' => 'ee-reg-form-attendee-dv', |
110 | 110 | 'html_style' => $admin_request |
111 | 111 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -9,39 +9,39 @@ |
||
9 | 9 | |
10 | 10 | class PrivacyConsentCheckboxForm extends EE_Form_Section_Proper |
11 | 11 | { |
12 | - /** |
|
13 | - * @param string $reg_step_slug |
|
14 | - * @param string $consent_checkbox_label_text |
|
15 | - * @throws EE_Error |
|
16 | - */ |
|
17 | - public function __construct(string $reg_step_slug, string $consent_checkbox_label_text) |
|
18 | - { |
|
19 | - parent::__construct( |
|
20 | - [ |
|
21 | - 'layout_strategy' => |
|
22 | - new EE_Template_Layout( |
|
23 | - [ |
|
24 | - 'input_template_file' => SPCO_REG_STEPS_PATH |
|
25 | - . $reg_step_slug |
|
26 | - . '/privacy_consent.template.php', |
|
27 | - ] |
|
28 | - ), |
|
29 | - 'subsections' => [ |
|
30 | - 'consent' => new EE_Checkbox_Multi_Input( |
|
31 | - [ |
|
32 | - 'consent' => $consent_checkbox_label_text, |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'required' => true, |
|
36 | - 'required_validation_error_message' => esc_html__( |
|
37 | - 'You must consent to these terms in order to register.', |
|
38 | - 'event_espresso' |
|
39 | - ), |
|
40 | - 'html_label_text' => '', |
|
41 | - ] |
|
42 | - ), |
|
43 | - ], |
|
44 | - ] |
|
45 | - ); |
|
46 | - } |
|
12 | + /** |
|
13 | + * @param string $reg_step_slug |
|
14 | + * @param string $consent_checkbox_label_text |
|
15 | + * @throws EE_Error |
|
16 | + */ |
|
17 | + public function __construct(string $reg_step_slug, string $consent_checkbox_label_text) |
|
18 | + { |
|
19 | + parent::__construct( |
|
20 | + [ |
|
21 | + 'layout_strategy' => |
|
22 | + new EE_Template_Layout( |
|
23 | + [ |
|
24 | + 'input_template_file' => SPCO_REG_STEPS_PATH |
|
25 | + . $reg_step_slug |
|
26 | + . '/privacy_consent.template.php', |
|
27 | + ] |
|
28 | + ), |
|
29 | + 'subsections' => [ |
|
30 | + 'consent' => new EE_Checkbox_Multi_Input( |
|
31 | + [ |
|
32 | + 'consent' => $consent_checkbox_label_text, |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'required' => true, |
|
36 | + 'required_validation_error_message' => esc_html__( |
|
37 | + 'You must consent to these terms in order to register.', |
|
38 | + 'event_espresso' |
|
39 | + ), |
|
40 | + 'html_label_text' => '', |
|
41 | + ] |
|
42 | + ), |
|
43 | + ], |
|
44 | + ] |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | } |
@@ -12,77 +12,77 @@ |
||
12 | 12 | |
13 | 13 | class CopyAttendeeInfoForm extends EE_Form_Section_Proper |
14 | 14 | { |
15 | - /** |
|
16 | - * CopyAttendeeInfoForm constructor. |
|
17 | - * |
|
18 | - * @param EE_Registration[] $registrations |
|
19 | - * @param string $slug |
|
20 | - * @throws EE_Error |
|
21 | - * @throws ReflectionException |
|
22 | - */ |
|
23 | - public function __construct(array $registrations, string $slug) |
|
24 | - { |
|
25 | - parent::__construct( |
|
26 | - [ |
|
27 | - 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
28 | - 'layout_strategy' => new EE_Template_Layout( |
|
29 | - [ |
|
30 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
31 | - . $slug |
|
32 | - . '/copy_attendee_info.template.php', |
|
33 | - 'begin_template_file' => null, |
|
34 | - 'input_template_file' => null, |
|
35 | - 'subsection_template_file' => null, |
|
36 | - 'end_template_file' => null, |
|
37 | - ] |
|
38 | - ), |
|
39 | - ] |
|
40 | - ); |
|
41 | - } |
|
15 | + /** |
|
16 | + * CopyAttendeeInfoForm constructor. |
|
17 | + * |
|
18 | + * @param EE_Registration[] $registrations |
|
19 | + * @param string $slug |
|
20 | + * @throws EE_Error |
|
21 | + * @throws ReflectionException |
|
22 | + */ |
|
23 | + public function __construct(array $registrations, string $slug) |
|
24 | + { |
|
25 | + parent::__construct( |
|
26 | + [ |
|
27 | + 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
28 | + 'layout_strategy' => new EE_Template_Layout( |
|
29 | + [ |
|
30 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
31 | + . $slug |
|
32 | + . '/copy_attendee_info.template.php', |
|
33 | + 'begin_template_file' => null, |
|
34 | + 'input_template_file' => null, |
|
35 | + 'subsection_template_file' => null, |
|
36 | + 'end_template_file' => null, |
|
37 | + ] |
|
38 | + ), |
|
39 | + ] |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param array $registrations |
|
46 | - * @return array |
|
47 | - * @throws EE_Error |
|
48 | - * @throws ReflectionException |
|
49 | - */ |
|
50 | - private function copyAttendeeInfoInputs(array $registrations): array |
|
51 | - { |
|
52 | - $copy_attendee_info_inputs = []; |
|
53 | - $prev_ticket = null; |
|
54 | - foreach ($registrations as $registration) { |
|
55 | - // for all attendees other than the primary attendee |
|
56 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
57 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
58 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
59 | - $item_name = $registration->ticket()->name(); |
|
60 | - $item_name .= $registration->ticket()->description() !== '' |
|
61 | - ? ' - ' . $registration->ticket()->description() |
|
62 | - : ''; |
|
63 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
64 | - = new EE_Form_Section_HTML( |
|
65 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
66 | - ); |
|
67 | - $prev_ticket = $registration->ticket()->ID(); |
|
68 | - } |
|
44 | + /** |
|
45 | + * @param array $registrations |
|
46 | + * @return array |
|
47 | + * @throws EE_Error |
|
48 | + * @throws ReflectionException |
|
49 | + */ |
|
50 | + private function copyAttendeeInfoInputs(array $registrations): array |
|
51 | + { |
|
52 | + $copy_attendee_info_inputs = []; |
|
53 | + $prev_ticket = null; |
|
54 | + foreach ($registrations as $registration) { |
|
55 | + // for all attendees other than the primary attendee |
|
56 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
57 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
58 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
59 | + $item_name = $registration->ticket()->name(); |
|
60 | + $item_name .= $registration->ticket()->description() !== '' |
|
61 | + ? ' - ' . $registration->ticket()->description() |
|
62 | + : ''; |
|
63 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
64 | + = new EE_Form_Section_HTML( |
|
65 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
66 | + ); |
|
67 | + $prev_ticket = $registration->ticket()->ID(); |
|
68 | + } |
|
69 | 69 | |
70 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
71 | - = new EE_Checkbox_Multi_Input( |
|
72 | - [ |
|
73 | - $registration->ID() => sprintf( |
|
74 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
75 | - $registration->count() |
|
76 | - ) |
|
77 | - ], |
|
78 | - [ |
|
79 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
80 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
81 | - 'display_html_label_text' => false, |
|
82 | - ] |
|
83 | - ); |
|
84 | - } |
|
85 | - } |
|
86 | - return $copy_attendee_info_inputs; |
|
87 | - } |
|
70 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
71 | + = new EE_Checkbox_Multi_Input( |
|
72 | + [ |
|
73 | + $registration->ID() => sprintf( |
|
74 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
75 | + $registration->count() |
|
76 | + ) |
|
77 | + ], |
|
78 | + [ |
|
79 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
80 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
81 | + 'display_html_label_text' => false, |
|
82 | + ] |
|
83 | + ); |
|
84 | + } |
|
85 | + } |
|
86 | + return $copy_attendee_info_inputs; |
|
87 | + } |
|
88 | 88 | } |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
57 | 57 | // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
58 | 58 | if ($registration->ticket()->ID() !== $prev_ticket) { |
59 | - $item_name = $registration->ticket()->name(); |
|
60 | - $item_name .= $registration->ticket()->description() !== '' |
|
61 | - ? ' - ' . $registration->ticket()->description() |
|
59 | + $item_name = $registration->ticket()->name(); |
|
60 | + $item_name .= $registration->ticket()->description() !== '' |
|
61 | + ? ' - '.$registration->ticket()->description() |
|
62 | 62 | : ''; |
63 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
63 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] |
|
64 | 64 | = new EE_Form_Section_HTML( |
65 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
65 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
66 | 66 | ); |
67 | 67 | $prev_ticket = $registration->ticket()->ID(); |
68 | 68 | } |
69 | 69 | |
70 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
70 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] |
|
71 | 71 | = new EE_Checkbox_Multi_Input( |
72 | 72 | [ |
73 | 73 | $registration->ID() => sprintf( |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ) |
77 | 77 | ], |
78 | 78 | [ |
79 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
79 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
80 | 80 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
81 | 81 | 'display_html_label_text' => false, |
82 | 82 | ] |
@@ -19,353 +19,353 @@ |
||
19 | 19 | class RegistrantData |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var int |
|
24 | - */ |
|
25 | - private $attendee_counter = 0; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $registrant_data = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var bool |
|
34 | - */ |
|
35 | - private $copy_primary = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - private $required_questions = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Registration[] |
|
44 | - */ |
|
45 | - private $registrations = []; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Answer[][] |
|
49 | - */ |
|
50 | - private $registrant_answers = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * array for tracking reg form data for the primary registrant |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $primary_registrant_data; |
|
58 | - |
|
59 | - /** |
|
60 | - * the attendee object created for the primary registrant |
|
61 | - * |
|
62 | - * @var EE_Attendee |
|
63 | - */ |
|
64 | - private $primary_registrant; |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * RegistrantData constructor. |
|
69 | - */ |
|
70 | - public function __construct() |
|
71 | - { |
|
72 | - $this->primary_registrant_data = ['line_item_id' => null,]; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param EE_Registration $registration |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public function initializeRegistrantData(EE_Registration $registration): void |
|
81 | - { |
|
82 | - $reg_url_link = $registration->reg_url_link(); |
|
83 | - $this->registrations[ $reg_url_link ] = $registration; |
|
84 | - $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | - $this->registrant_data[ $reg_url_link ] = []; |
|
86 | - $this->attendee_counter++; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - public function attendeeCount(): int |
|
94 | - { |
|
95 | - return $this->attendee_counter; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - public function copyPrimary(): bool |
|
103 | - { |
|
104 | - return $this->copy_primary; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param bool $copy_primary |
|
110 | - */ |
|
111 | - public function setCopyPrimary(bool $copy_primary): void |
|
112 | - { |
|
113 | - $this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $reg_url_link |
|
119 | - * @return array|null |
|
120 | - */ |
|
121 | - public function getRegistrant(string $reg_url_link): ?EE_Registration |
|
122 | - { |
|
123 | - return $this->registrations[ $reg_url_link ] ?? null; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param string $reg_url_link |
|
129 | - * @return array|null |
|
130 | - */ |
|
131 | - public function getRegistrantData(string $reg_url_link): ?array |
|
132 | - { |
|
133 | - return $this->registrant_data[ $reg_url_link ] ?? null; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $reg_url_link |
|
139 | - * @param string $key |
|
140 | - * @param mixed $value |
|
141 | - */ |
|
142 | - public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
|
143 | - { |
|
144 | - $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
150 | - * |
|
151 | - * @param string $reg_url_link |
|
152 | - * @throws EE_Error |
|
153 | - * @throws ReflectionException |
|
154 | - */ |
|
155 | - public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void |
|
156 | - { |
|
157 | - if ($this->currentRegistrantIsPrimary()) { |
|
158 | - return; |
|
159 | - } |
|
160 | - // bare minimum critical details include first name, last name, email address |
|
161 | - $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email']; |
|
162 | - // add address info to critical details? |
|
163 | - if ( |
|
164 | - apply_filters( |
|
165 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
166 | - false |
|
167 | - ) |
|
168 | - ) { |
|
169 | - $critical_attendee_details += [ |
|
170 | - 'ATT_address', |
|
171 | - 'ATT_address2', |
|
172 | - 'ATT_city', |
|
173 | - 'STA_ID', |
|
174 | - 'CNT_ISO', |
|
175 | - 'ATT_zip', |
|
176 | - 'ATT_phone', |
|
177 | - ]; |
|
178 | - } |
|
179 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
180 | - if ( |
|
181 | - ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
182 | - || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
183 | - ) { |
|
184 | - $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
185 | - $critical_attendee_detail |
|
186 | - ); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @param string $reg_url_link |
|
194 | - * @param array $registrant_data |
|
195 | - */ |
|
196 | - public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
|
197 | - { |
|
198 | - $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - public function getRequiredQuestions(): array |
|
206 | - { |
|
207 | - return $this->required_questions; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param string $identifier |
|
213 | - * @param string $required_question |
|
214 | - */ |
|
215 | - public function addRequiredQuestion(string $identifier, string $required_question): void |
|
216 | - { |
|
217 | - $this->required_questions[ $identifier ] = $required_question; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @return EE_Answer[] |
|
223 | - */ |
|
224 | - public function registrantAnswers(string $reg_url_link): array |
|
225 | - { |
|
226 | - return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @param string $reg_url_link |
|
232 | - * @param string $identifier the answer cache ID |
|
233 | - * @param EE_Answer $answer |
|
234 | - */ |
|
235 | - public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
|
236 | - { |
|
237 | - $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param string $reg_url_link |
|
243 | - * @param string $identifier |
|
244 | - * @return EE_Answer|null |
|
245 | - */ |
|
246 | - public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
|
247 | - { |
|
248 | - return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param string $reg_url_link |
|
254 | - * @param string $identifier |
|
255 | - * @return bool |
|
256 | - */ |
|
257 | - public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool |
|
258 | - { |
|
259 | - $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier); |
|
260 | - return $registrant_answer instanceof EE_Answer; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - public function primaryRegistrantData(): array |
|
268 | - { |
|
269 | - return $this->primary_registrant_data; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @param string $key |
|
275 | - * @param mixed $value |
|
276 | - */ |
|
277 | - public function addPrimaryRegistrantDataValue(string $key, $value): void |
|
278 | - { |
|
279 | - $this->primary_registrant_data[ $key ] = $value; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param string $key |
|
285 | - * @return mixed |
|
286 | - */ |
|
287 | - public function getPrimaryRegistrantDataValue(string $key) |
|
288 | - { |
|
289 | - return $this->primary_registrant_data[ $key ] ?? null; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param array $primary_registrant_data |
|
295 | - */ |
|
296 | - public function setPrimaryRegistrantData(array $primary_registrant_data): void |
|
297 | - { |
|
298 | - $this->primary_registrant_data = $primary_registrant_data; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * @return EE_Attendee |
|
304 | - */ |
|
305 | - public function primaryRegistrant(): EE_Attendee |
|
306 | - { |
|
307 | - return $this->primary_registrant; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @return bool |
|
313 | - */ |
|
314 | - public function primaryRegistrantIsValid(): bool |
|
315 | - { |
|
316 | - return $this->primary_registrant instanceof EE_Attendee; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param EE_Attendee $primary_registrant |
|
322 | - */ |
|
323 | - public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void |
|
324 | - { |
|
325 | - $this->primary_registrant = $primary_registrant; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @param string $reg_url_link |
|
331 | - * @return bool |
|
332 | - */ |
|
333 | - public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool |
|
334 | - { |
|
335 | - return $this->attendeeCount() === 1 |
|
336 | - || ( |
|
337 | - $reg_url_link !== '' |
|
338 | - && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link |
|
339 | - ); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * @return bool |
|
345 | - */ |
|
346 | - public function currentRegistrantIsNotPrimary(): bool |
|
347 | - { |
|
348 | - return $this->attendeeCount() > 1; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @param string $reg_url_link |
|
354 | - * @param string $form_input |
|
355 | - * @param mixed $input_value |
|
356 | - * @return mixed|null |
|
357 | - */ |
|
358 | - public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
|
359 | - { |
|
360 | - // store a bit of data about the primary attendee |
|
361 | - if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
362 | - $this->primary_registrant_data[ $form_input ] = $input_value; |
|
363 | - return $input_value; |
|
364 | - } |
|
365 | - // or copy value from primary if incoming value is not set |
|
366 | - if ($input_value === null && $this->copyPrimary()) { |
|
367 | - $input_value = $this->getPrimaryRegistrantDataValue($form_input); |
|
368 | - } |
|
369 | - return $input_value; |
|
370 | - } |
|
22 | + /** |
|
23 | + * @var int |
|
24 | + */ |
|
25 | + private $attendee_counter = 0; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $registrant_data = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var bool |
|
34 | + */ |
|
35 | + private $copy_primary = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + private $required_questions = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Registration[] |
|
44 | + */ |
|
45 | + private $registrations = []; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Answer[][] |
|
49 | + */ |
|
50 | + private $registrant_answers = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * array for tracking reg form data for the primary registrant |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $primary_registrant_data; |
|
58 | + |
|
59 | + /** |
|
60 | + * the attendee object created for the primary registrant |
|
61 | + * |
|
62 | + * @var EE_Attendee |
|
63 | + */ |
|
64 | + private $primary_registrant; |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * RegistrantData constructor. |
|
69 | + */ |
|
70 | + public function __construct() |
|
71 | + { |
|
72 | + $this->primary_registrant_data = ['line_item_id' => null,]; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param EE_Registration $registration |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public function initializeRegistrantData(EE_Registration $registration): void |
|
81 | + { |
|
82 | + $reg_url_link = $registration->reg_url_link(); |
|
83 | + $this->registrations[ $reg_url_link ] = $registration; |
|
84 | + $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | + $this->registrant_data[ $reg_url_link ] = []; |
|
86 | + $this->attendee_counter++; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + public function attendeeCount(): int |
|
94 | + { |
|
95 | + return $this->attendee_counter; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + public function copyPrimary(): bool |
|
103 | + { |
|
104 | + return $this->copy_primary; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param bool $copy_primary |
|
110 | + */ |
|
111 | + public function setCopyPrimary(bool $copy_primary): void |
|
112 | + { |
|
113 | + $this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $reg_url_link |
|
119 | + * @return array|null |
|
120 | + */ |
|
121 | + public function getRegistrant(string $reg_url_link): ?EE_Registration |
|
122 | + { |
|
123 | + return $this->registrations[ $reg_url_link ] ?? null; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param string $reg_url_link |
|
129 | + * @return array|null |
|
130 | + */ |
|
131 | + public function getRegistrantData(string $reg_url_link): ?array |
|
132 | + { |
|
133 | + return $this->registrant_data[ $reg_url_link ] ?? null; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $reg_url_link |
|
139 | + * @param string $key |
|
140 | + * @param mixed $value |
|
141 | + */ |
|
142 | + public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
|
143 | + { |
|
144 | + $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
150 | + * |
|
151 | + * @param string $reg_url_link |
|
152 | + * @throws EE_Error |
|
153 | + * @throws ReflectionException |
|
154 | + */ |
|
155 | + public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void |
|
156 | + { |
|
157 | + if ($this->currentRegistrantIsPrimary()) { |
|
158 | + return; |
|
159 | + } |
|
160 | + // bare minimum critical details include first name, last name, email address |
|
161 | + $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email']; |
|
162 | + // add address info to critical details? |
|
163 | + if ( |
|
164 | + apply_filters( |
|
165 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
166 | + false |
|
167 | + ) |
|
168 | + ) { |
|
169 | + $critical_attendee_details += [ |
|
170 | + 'ATT_address', |
|
171 | + 'ATT_address2', |
|
172 | + 'ATT_city', |
|
173 | + 'STA_ID', |
|
174 | + 'CNT_ISO', |
|
175 | + 'ATT_zip', |
|
176 | + 'ATT_phone', |
|
177 | + ]; |
|
178 | + } |
|
179 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
180 | + if ( |
|
181 | + ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
182 | + || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
183 | + ) { |
|
184 | + $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
185 | + $critical_attendee_detail |
|
186 | + ); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @param string $reg_url_link |
|
194 | + * @param array $registrant_data |
|
195 | + */ |
|
196 | + public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
|
197 | + { |
|
198 | + $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + public function getRequiredQuestions(): array |
|
206 | + { |
|
207 | + return $this->required_questions; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param string $identifier |
|
213 | + * @param string $required_question |
|
214 | + */ |
|
215 | + public function addRequiredQuestion(string $identifier, string $required_question): void |
|
216 | + { |
|
217 | + $this->required_questions[ $identifier ] = $required_question; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * @return EE_Answer[] |
|
223 | + */ |
|
224 | + public function registrantAnswers(string $reg_url_link): array |
|
225 | + { |
|
226 | + return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @param string $reg_url_link |
|
232 | + * @param string $identifier the answer cache ID |
|
233 | + * @param EE_Answer $answer |
|
234 | + */ |
|
235 | + public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
|
236 | + { |
|
237 | + $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param string $reg_url_link |
|
243 | + * @param string $identifier |
|
244 | + * @return EE_Answer|null |
|
245 | + */ |
|
246 | + public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
|
247 | + { |
|
248 | + return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param string $reg_url_link |
|
254 | + * @param string $identifier |
|
255 | + * @return bool |
|
256 | + */ |
|
257 | + public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool |
|
258 | + { |
|
259 | + $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier); |
|
260 | + return $registrant_answer instanceof EE_Answer; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + public function primaryRegistrantData(): array |
|
268 | + { |
|
269 | + return $this->primary_registrant_data; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @param string $key |
|
275 | + * @param mixed $value |
|
276 | + */ |
|
277 | + public function addPrimaryRegistrantDataValue(string $key, $value): void |
|
278 | + { |
|
279 | + $this->primary_registrant_data[ $key ] = $value; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param string $key |
|
285 | + * @return mixed |
|
286 | + */ |
|
287 | + public function getPrimaryRegistrantDataValue(string $key) |
|
288 | + { |
|
289 | + return $this->primary_registrant_data[ $key ] ?? null; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param array $primary_registrant_data |
|
295 | + */ |
|
296 | + public function setPrimaryRegistrantData(array $primary_registrant_data): void |
|
297 | + { |
|
298 | + $this->primary_registrant_data = $primary_registrant_data; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * @return EE_Attendee |
|
304 | + */ |
|
305 | + public function primaryRegistrant(): EE_Attendee |
|
306 | + { |
|
307 | + return $this->primary_registrant; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @return bool |
|
313 | + */ |
|
314 | + public function primaryRegistrantIsValid(): bool |
|
315 | + { |
|
316 | + return $this->primary_registrant instanceof EE_Attendee; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param EE_Attendee $primary_registrant |
|
322 | + */ |
|
323 | + public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void |
|
324 | + { |
|
325 | + $this->primary_registrant = $primary_registrant; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @param string $reg_url_link |
|
331 | + * @return bool |
|
332 | + */ |
|
333 | + public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool |
|
334 | + { |
|
335 | + return $this->attendeeCount() === 1 |
|
336 | + || ( |
|
337 | + $reg_url_link !== '' |
|
338 | + && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link |
|
339 | + ); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * @return bool |
|
345 | + */ |
|
346 | + public function currentRegistrantIsNotPrimary(): bool |
|
347 | + { |
|
348 | + return $this->attendeeCount() > 1; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @param string $reg_url_link |
|
354 | + * @param string $form_input |
|
355 | + * @param mixed $input_value |
|
356 | + * @return mixed|null |
|
357 | + */ |
|
358 | + public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
|
359 | + { |
|
360 | + // store a bit of data about the primary attendee |
|
361 | + if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
362 | + $this->primary_registrant_data[ $form_input ] = $input_value; |
|
363 | + return $input_value; |
|
364 | + } |
|
365 | + // or copy value from primary if incoming value is not set |
|
366 | + if ($input_value === null && $this->copyPrimary()) { |
|
367 | + $input_value = $this->getPrimaryRegistrantDataValue($form_input); |
|
368 | + } |
|
369 | + return $input_value; |
|
370 | + } |
|
371 | 371 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function __construct() |
71 | 71 | { |
72 | - $this->primary_registrant_data = ['line_item_id' => null,]; |
|
72 | + $this->primary_registrant_data = ['line_item_id' => null, ]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | public function initializeRegistrantData(EE_Registration $registration): void |
81 | 81 | { |
82 | 82 | $reg_url_link = $registration->reg_url_link(); |
83 | - $this->registrations[ $reg_url_link ] = $registration; |
|
84 | - $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | - $this->registrant_data[ $reg_url_link ] = []; |
|
83 | + $this->registrations[$reg_url_link] = $registration; |
|
84 | + $this->registrant_answers[$reg_url_link] = $registration->answers(); |
|
85 | + $this->registrant_data[$reg_url_link] = []; |
|
86 | 86 | $this->attendee_counter++; |
87 | 87 | } |
88 | 88 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getRegistrant(string $reg_url_link): ?EE_Registration |
122 | 122 | { |
123 | - return $this->registrations[ $reg_url_link ] ?? null; |
|
123 | + return $this->registrations[$reg_url_link] ?? null; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function getRegistrantData(string $reg_url_link): ?array |
132 | 132 | { |
133 | - return $this->registrant_data[ $reg_url_link ] ?? null; |
|
133 | + return $this->registrant_data[$reg_url_link] ?? null; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
143 | 143 | { |
144 | - $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
144 | + $this->registrant_data[$reg_url_link][$key] = $value; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | } |
179 | 179 | foreach ($critical_attendee_details as $critical_attendee_detail) { |
180 | 180 | if ( |
181 | - ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
182 | - || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
181 | + ! isset($this->registrant_data[$reg_url_link][$critical_attendee_detail]) |
|
182 | + || empty($this->registrant_data[$reg_url_link][$critical_attendee_detail]) |
|
183 | 183 | ) { |
184 | - $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
184 | + $this->registrant_data[$reg_url_link][$critical_attendee_detail] = $this->primary_registrant->get( |
|
185 | 185 | $critical_attendee_detail |
186 | 186 | ); |
187 | 187 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
197 | 197 | { |
198 | - $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
198 | + $this->registrant_data[$reg_url_link] = $registrant_data; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function addRequiredQuestion(string $identifier, string $required_question): void |
216 | 216 | { |
217 | - $this->required_questions[ $identifier ] = $required_question; |
|
217 | + $this->required_questions[$identifier] = $required_question; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function registrantAnswers(string $reg_url_link): array |
225 | 225 | { |
226 | - return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
226 | + return $this->registrant_answers[$reg_url_link] ?? []; |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
236 | 236 | { |
237 | - $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
237 | + $this->registrant_answers[$reg_url_link][$identifier] = $answer; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
247 | 247 | { |
248 | - return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
248 | + return $this->registrant_answers[$reg_url_link][$identifier] ?? null; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function addPrimaryRegistrantDataValue(string $key, $value): void |
278 | 278 | { |
279 | - $this->primary_registrant_data[ $key ] = $value; |
|
279 | + $this->primary_registrant_data[$key] = $value; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function getPrimaryRegistrantDataValue(string $key) |
288 | 288 | { |
289 | - return $this->primary_registrant_data[ $key ] ?? null; |
|
289 | + return $this->primary_registrant_data[$key] ?? null; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
359 | 359 | { |
360 | 360 | // store a bit of data about the primary attendee |
361 | - if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
362 | - $this->primary_registrant_data[ $form_input ] = $input_value; |
|
361 | + if ( ! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
362 | + $this->primary_registrant_data[$form_input] = $input_value; |
|
363 | 363 | return $input_value; |
364 | 364 | } |
365 | 365 | // or copy value from primary if incoming value is not set |
@@ -13,109 +13,109 @@ |
||
13 | 13 | |
14 | 14 | class CountryOptions |
15 | 15 | { |
16 | - /** |
|
17 | - * the action being performed on the current step |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $action = ''; |
|
16 | + /** |
|
17 | + * the action being performed on the current step |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $action = ''; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var EEM_Answer |
|
25 | - */ |
|
26 | - public $answer_model; |
|
23 | + /** |
|
24 | + * @var EEM_Answer |
|
25 | + */ |
|
26 | + public $answer_model; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var EEM_Country |
|
30 | - */ |
|
31 | - public $country_model; |
|
28 | + /** |
|
29 | + * @var EEM_Country |
|
30 | + */ |
|
31 | + public $country_model; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var [][] |
|
35 | - */ |
|
36 | - private $country_options = []; |
|
33 | + /** |
|
34 | + * @var [][] |
|
35 | + */ |
|
36 | + private $country_options = []; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * CountryOptions constructor. |
|
41 | - * |
|
42 | - * @param string $action |
|
43 | - * @param EEM_Answer $answer_model |
|
44 | - * @param EEM_Country $country_model |
|
45 | - */ |
|
46 | - public function __construct(string $action, EEM_Answer $answer_model, EEM_Country $country_model) |
|
47 | - { |
|
48 | - $this->action = $action; |
|
49 | - $this->answer_model = $answer_model; |
|
50 | - $this->country_model = $country_model; |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
53 | - [$this, 'forLegacyFormInput'], |
|
54 | - 10, |
|
55 | - 4 |
|
56 | - ); |
|
57 | - } |
|
39 | + /** |
|
40 | + * CountryOptions constructor. |
|
41 | + * |
|
42 | + * @param string $action |
|
43 | + * @param EEM_Answer $answer_model |
|
44 | + * @param EEM_Country $country_model |
|
45 | + */ |
|
46 | + public function __construct(string $action, EEM_Answer $answer_model, EEM_Country $country_model) |
|
47 | + { |
|
48 | + $this->action = $action; |
|
49 | + $this->answer_model = $answer_model; |
|
50 | + $this->country_model = $country_model; |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
53 | + [$this, 'forLegacyFormInput'], |
|
54 | + 10, |
|
55 | + 4 |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Gets the list of countries for the form input |
|
62 | - * |
|
63 | - * @param array|null $countries_list deprecated prop from an old hook |
|
64 | - * @param EE_Question|null $question |
|
65 | - * @param EE_Registration|null $registration |
|
66 | - * @param EE_Answer|null $answer deprecated prop from an old hook |
|
67 | - * @return array 2d keys are country IDs, values are their names |
|
68 | - * @throws EE_Error |
|
69 | - * @throws ReflectionException |
|
70 | - */ |
|
71 | - public function forLegacyFormInput( |
|
72 | - array $countries_list = null, |
|
73 | - EE_Question $question = null, |
|
74 | - EE_Registration $registration = null, |
|
75 | - EE_Answer $answer = null |
|
76 | - ): array { |
|
77 | - if (! isset($this->country_options[ $this->action ])) { |
|
78 | - $this->generateLegacyCountryOptions($question, $registration); |
|
79 | - } |
|
80 | - return $this->country_options[ $this->action ]; |
|
81 | - } |
|
60 | + /** |
|
61 | + * Gets the list of countries for the form input |
|
62 | + * |
|
63 | + * @param array|null $countries_list deprecated prop from an old hook |
|
64 | + * @param EE_Question|null $question |
|
65 | + * @param EE_Registration|null $registration |
|
66 | + * @param EE_Answer|null $answer deprecated prop from an old hook |
|
67 | + * @return array 2d keys are country IDs, values are their names |
|
68 | + * @throws EE_Error |
|
69 | + * @throws ReflectionException |
|
70 | + */ |
|
71 | + public function forLegacyFormInput( |
|
72 | + array $countries_list = null, |
|
73 | + EE_Question $question = null, |
|
74 | + EE_Registration $registration = null, |
|
75 | + EE_Answer $answer = null |
|
76 | + ): array { |
|
77 | + if (! isset($this->country_options[ $this->action ])) { |
|
78 | + $this->generateLegacyCountryOptions($question, $registration); |
|
79 | + } |
|
80 | + return $this->country_options[ $this->action ]; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * @param EE_Question|null $question |
|
86 | - * @param EE_Registration|null $registration |
|
87 | - * @throws EE_Error |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - private function generateLegacyCountryOptions(EE_Question $question = null, EE_Registration $registration = null) |
|
91 | - { |
|
92 | - // get possibly cached list of countries |
|
93 | - $countries = $this->action === 'process_reg_step' |
|
94 | - ? $this->country_model->get_all_countries() |
|
95 | - : $this->country_model->get_all_active_countries(); |
|
96 | - // start with an empty option |
|
97 | - $country_options = ['' => '']; |
|
98 | - if (! empty($countries)) { |
|
99 | - foreach ($countries as $country) { |
|
100 | - if ($country instanceof EE_Country) { |
|
101 | - $country_options[ $country->ID() ] = $country->name(); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
106 | - $answer = $this->answer_model->get_one( |
|
107 | - [['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]] |
|
108 | - ); |
|
109 | - } else { |
|
110 | - $answer = EE_Answer::new_instance(); |
|
111 | - } |
|
112 | - $this->country_options[ $this->action ] = apply_filters( |
|
113 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
114 | - $country_options, |
|
115 | - $this, |
|
116 | - $registration, |
|
117 | - $question, |
|
118 | - $answer |
|
119 | - ); |
|
120 | - } |
|
84 | + /** |
|
85 | + * @param EE_Question|null $question |
|
86 | + * @param EE_Registration|null $registration |
|
87 | + * @throws EE_Error |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + private function generateLegacyCountryOptions(EE_Question $question = null, EE_Registration $registration = null) |
|
91 | + { |
|
92 | + // get possibly cached list of countries |
|
93 | + $countries = $this->action === 'process_reg_step' |
|
94 | + ? $this->country_model->get_all_countries() |
|
95 | + : $this->country_model->get_all_active_countries(); |
|
96 | + // start with an empty option |
|
97 | + $country_options = ['' => '']; |
|
98 | + if (! empty($countries)) { |
|
99 | + foreach ($countries as $country) { |
|
100 | + if ($country instanceof EE_Country) { |
|
101 | + $country_options[ $country->ID() ] = $country->name(); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
106 | + $answer = $this->answer_model->get_one( |
|
107 | + [['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]] |
|
108 | + ); |
|
109 | + } else { |
|
110 | + $answer = EE_Answer::new_instance(); |
|
111 | + } |
|
112 | + $this->country_options[ $this->action ] = apply_filters( |
|
113 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
114 | + $country_options, |
|
115 | + $this, |
|
116 | + $registration, |
|
117 | + $question, |
|
118 | + $answer |
|
119 | + ); |
|
120 | + } |
|
121 | 121 | } |
@@ -19,272 +19,272 @@ |
||
19 | 19 | abstract class RegFormHandler implements RegFormHandlerInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var EE_Checkout |
|
24 | - */ |
|
25 | - protected $checkout; |
|
22 | + /** |
|
23 | + * @var EE_Checkout |
|
24 | + */ |
|
25 | + protected $checkout; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $non_input_form_sections; |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $non_input_form_sections; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var RegFormAttendeeFactory |
|
34 | - */ |
|
35 | - protected $attendee_factory; |
|
32 | + /** |
|
33 | + * @var RegFormAttendeeFactory |
|
34 | + */ |
|
35 | + protected $attendee_factory; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var RegistrantData |
|
39 | - */ |
|
40 | - protected $registrant_data; |
|
37 | + /** |
|
38 | + * @var RegistrantData |
|
39 | + */ |
|
40 | + protected $registrant_data; |
|
41 | 41 | |
42 | - /** |
|
43 | - * the registration form for the current checkout step |
|
44 | - * |
|
45 | - * @var EE_Form_Section_Proper $reg_form |
|
46 | - */ |
|
47 | - protected $reg_form; |
|
42 | + /** |
|
43 | + * the registration form for the current checkout step |
|
44 | + * |
|
45 | + * @var EE_Form_Section_Proper $reg_form |
|
46 | + */ |
|
47 | + protected $reg_form; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var EE_Registration_Processor |
|
51 | - */ |
|
52 | - protected $registration_processor; |
|
49 | + /** |
|
50 | + * @var EE_Registration_Processor |
|
51 | + */ |
|
52 | + protected $registration_processor; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @var bool |
|
56 | - */ |
|
57 | - protected $valid = true; |
|
54 | + /** |
|
55 | + * @var bool |
|
56 | + */ |
|
57 | + protected $valid = true; |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * RegFormHandler constructor. |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - EE_Checkout $checkout, |
|
65 | - RegistrantData $registrant_data, |
|
66 | - EE_Form_Section_Proper $reg_form, |
|
67 | - RegFormAttendeeFactory $attendee_factory, |
|
68 | - EE_Registration_Processor $registration_processor |
|
69 | - ) { |
|
70 | - $this->checkout = $checkout; |
|
71 | - $this->reg_form = $reg_form; |
|
72 | - $this->registrant_data = $registrant_data; |
|
73 | - $this->attendee_factory = $attendee_factory; |
|
74 | - $this->registration_processor = $registration_processor; |
|
75 | - // reg form sections that do not contain inputs |
|
76 | - $this->non_input_form_sections = [ |
|
77 | - 'primary_registrant', |
|
78 | - 'additional_attendee_reg_info', |
|
79 | - 'spco_copy_attendee_chk', |
|
80 | - ]; |
|
81 | - } |
|
60 | + /** |
|
61 | + * RegFormHandler constructor. |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + EE_Checkout $checkout, |
|
65 | + RegistrantData $registrant_data, |
|
66 | + EE_Form_Section_Proper $reg_form, |
|
67 | + RegFormAttendeeFactory $attendee_factory, |
|
68 | + EE_Registration_Processor $registration_processor |
|
69 | + ) { |
|
70 | + $this->checkout = $checkout; |
|
71 | + $this->reg_form = $reg_form; |
|
72 | + $this->registrant_data = $registrant_data; |
|
73 | + $this->attendee_factory = $attendee_factory; |
|
74 | + $this->registration_processor = $registration_processor; |
|
75 | + // reg form sections that do not contain inputs |
|
76 | + $this->non_input_form_sections = [ |
|
77 | + 'primary_registrant', |
|
78 | + 'additional_attendee_reg_info', |
|
79 | + 'spco_copy_attendee_chk', |
|
80 | + ]; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - abstract public function initializeInputHandler(); |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + abstract public function initializeInputHandler(); |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * @param EE_Registration $registration |
|
92 | - * @param string $reg_url_link |
|
93 | - * @param array $reg_form_data |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - abstract protected function processRegFormData( |
|
97 | - EE_Registration $registration, |
|
98 | - string $reg_url_link, |
|
99 | - array $reg_form_data |
|
100 | - ): bool; |
|
90 | + /** |
|
91 | + * @param EE_Registration $registration |
|
92 | + * @param string $reg_url_link |
|
93 | + * @param array $reg_form_data |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + abstract protected function processRegFormData( |
|
97 | + EE_Registration $registration, |
|
98 | + string $reg_url_link, |
|
99 | + array $reg_form_data |
|
100 | + ): bool; |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public function attendeeCount(): int |
|
107 | - { |
|
108 | - return $this->registrant_data->attendeeCount(); |
|
109 | - } |
|
103 | + /** |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public function attendeeCount(): int |
|
107 | + { |
|
108 | + return $this->registrant_data->attendeeCount(); |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | - /** |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - protected function isInvalid(): bool |
|
116 | - { |
|
117 | - $this->valid = false; |
|
118 | - return $this->valid; |
|
119 | - } |
|
112 | + /** |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + protected function isInvalid(): bool |
|
116 | + { |
|
117 | + $this->valid = false; |
|
118 | + return $this->valid; |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * @param EE_Registration[] $registrations |
|
124 | - * @param array[][] $reg_form_data |
|
125 | - * @return bool |
|
126 | - * @throws EntityNotFoundException |
|
127 | - * @throws EE_Error |
|
128 | - * @throws InvalidArgumentException |
|
129 | - * @throws ReflectionException |
|
130 | - * @throws RuntimeException |
|
131 | - * @throws InvalidDataTypeException |
|
132 | - * @throws InvalidInterfaceException |
|
133 | - */ |
|
134 | - public function processRegistrations(array $registrations, array $reg_form_data): bool |
|
135 | - { |
|
136 | - // start off optimistic, then trip this to false if anything goes wrong |
|
137 | - $this->valid = true; |
|
138 | - foreach ($registrations as $registration) { |
|
139 | - // verify EE_Registration object |
|
140 | - if (! $this->isValidRegistration($registration)) { |
|
141 | - return $this->isInvalid(); |
|
142 | - } |
|
143 | - // reg_url_link exists ? |
|
144 | - $reg_url_link = $registration->reg_url_link(); |
|
145 | - if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
146 | - return $this->isInvalid(); |
|
147 | - } |
|
148 | - // should this registration be processed during this visit ? |
|
149 | - if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
150 | - continue; |
|
151 | - } |
|
152 | - // if NOT revisiting, then let's save the registration now, |
|
153 | - // so that we have a REG_ID to use when generating other objects |
|
154 | - if (! $this->checkout->revisit) { |
|
155 | - $registration->save(); |
|
156 | - } |
|
157 | - /** |
|
158 | - * This allows plugins to trigger a fail on processing of a |
|
159 | - * registration for any conditions they may have for it to pass. |
|
160 | - * |
|
161 | - * @var bool if true is returned by the plugin then the registration processing is halted. |
|
162 | - */ |
|
163 | - if ( |
|
164 | - apply_filters( |
|
165 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
166 | - false, |
|
167 | - $this->attendeeCount(), |
|
168 | - $registration, |
|
169 | - $registrations, |
|
170 | - $reg_form_data, |
|
171 | - $this |
|
172 | - ) |
|
173 | - ) { |
|
174 | - return $this->isInvalid(); |
|
175 | - } |
|
122 | + /** |
|
123 | + * @param EE_Registration[] $registrations |
|
124 | + * @param array[][] $reg_form_data |
|
125 | + * @return bool |
|
126 | + * @throws EntityNotFoundException |
|
127 | + * @throws EE_Error |
|
128 | + * @throws InvalidArgumentException |
|
129 | + * @throws ReflectionException |
|
130 | + * @throws RuntimeException |
|
131 | + * @throws InvalidDataTypeException |
|
132 | + * @throws InvalidInterfaceException |
|
133 | + */ |
|
134 | + public function processRegistrations(array $registrations, array $reg_form_data): bool |
|
135 | + { |
|
136 | + // start off optimistic, then trip this to false if anything goes wrong |
|
137 | + $this->valid = true; |
|
138 | + foreach ($registrations as $registration) { |
|
139 | + // verify EE_Registration object |
|
140 | + if (! $this->isValidRegistration($registration)) { |
|
141 | + return $this->isInvalid(); |
|
142 | + } |
|
143 | + // reg_url_link exists ? |
|
144 | + $reg_url_link = $registration->reg_url_link(); |
|
145 | + if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
146 | + return $this->isInvalid(); |
|
147 | + } |
|
148 | + // should this registration be processed during this visit ? |
|
149 | + if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
150 | + continue; |
|
151 | + } |
|
152 | + // if NOT revisiting, then let's save the registration now, |
|
153 | + // so that we have a REG_ID to use when generating other objects |
|
154 | + if (! $this->checkout->revisit) { |
|
155 | + $registration->save(); |
|
156 | + } |
|
157 | + /** |
|
158 | + * This allows plugins to trigger a fail on processing of a |
|
159 | + * registration for any conditions they may have for it to pass. |
|
160 | + * |
|
161 | + * @var bool if true is returned by the plugin then the registration processing is halted. |
|
162 | + */ |
|
163 | + if ( |
|
164 | + apply_filters( |
|
165 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
166 | + false, |
|
167 | + $this->attendeeCount(), |
|
168 | + $registration, |
|
169 | + $registrations, |
|
170 | + $reg_form_data, |
|
171 | + $this |
|
172 | + ) |
|
173 | + ) { |
|
174 | + return $this->isInvalid(); |
|
175 | + } |
|
176 | 176 | |
177 | - // Houston, we have a registration! |
|
178 | - if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
179 | - return $this->isInvalid(); |
|
180 | - } |
|
181 | - } |
|
182 | - return $this->valid; |
|
183 | - } |
|
177 | + // Houston, we have a registration! |
|
178 | + if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
179 | + return $this->isInvalid(); |
|
180 | + } |
|
181 | + } |
|
182 | + return $this->valid; |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * @param string $reg_url_link |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - protected function isValidRegUrlLink(string $reg_url_link): bool |
|
191 | - { |
|
192 | - if (! empty($reg_url_link)) { |
|
193 | - return true; |
|
194 | - } |
|
195 | - EE_Error::add_error( |
|
196 | - esc_html__( |
|
197 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
198 | - 'event_espresso' |
|
199 | - ), |
|
200 | - __FILE__, |
|
201 | - __FUNCTION__, |
|
202 | - __LINE__ |
|
203 | - ); |
|
204 | - return false; |
|
205 | - } |
|
186 | + /** |
|
187 | + * @param string $reg_url_link |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + protected function isValidRegUrlLink(string $reg_url_link): bool |
|
191 | + { |
|
192 | + if (! empty($reg_url_link)) { |
|
193 | + return true; |
|
194 | + } |
|
195 | + EE_Error::add_error( |
|
196 | + esc_html__( |
|
197 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
198 | + 'event_espresso' |
|
199 | + ), |
|
200 | + __FILE__, |
|
201 | + __FUNCTION__, |
|
202 | + __LINE__ |
|
203 | + ); |
|
204 | + return false; |
|
205 | + } |
|
206 | 206 | |
207 | 207 | |
208 | - /** |
|
209 | - * @param EE_Registration|null $registration |
|
210 | - * @return bool |
|
211 | - */ |
|
212 | - protected function isValidRegistration(?EE_Registration $registration): bool |
|
213 | - { |
|
214 | - // verify EE_Registration object |
|
215 | - if ($registration instanceof EE_Registration) { |
|
216 | - return true; |
|
217 | - } |
|
218 | - EE_Error::add_error( |
|
219 | - esc_html__( |
|
220 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
221 | - 'event_espresso' |
|
222 | - ), |
|
223 | - __FILE__, |
|
224 | - __FUNCTION__, |
|
225 | - __LINE__ |
|
226 | - ); |
|
227 | - return false; |
|
228 | - } |
|
208 | + /** |
|
209 | + * @param EE_Registration|null $registration |
|
210 | + * @return bool |
|
211 | + */ |
|
212 | + protected function isValidRegistration(?EE_Registration $registration): bool |
|
213 | + { |
|
214 | + // verify EE_Registration object |
|
215 | + if ($registration instanceof EE_Registration) { |
|
216 | + return true; |
|
217 | + } |
|
218 | + EE_Error::add_error( |
|
219 | + esc_html__( |
|
220 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
221 | + 'event_espresso' |
|
222 | + ), |
|
223 | + __FILE__, |
|
224 | + __FUNCTION__, |
|
225 | + __LINE__ |
|
226 | + ); |
|
227 | + return false; |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | - /** |
|
232 | - * @param EE_Registration $registration |
|
233 | - * @param string $reg_url_link |
|
234 | - * @param array[][] $reg_form_data |
|
235 | - * @return bool |
|
236 | - * @throws EE_Error |
|
237 | - * @throws ReflectionException |
|
238 | - */ |
|
239 | - protected function processRegistration( |
|
240 | - EE_Registration $registration, |
|
241 | - string $reg_url_link, |
|
242 | - array $reg_form_data |
|
243 | - ): bool { |
|
244 | - $this->registrant_data->initializeRegistrantData($registration); |
|
245 | - if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
246 | - return false; |
|
247 | - } |
|
248 | - // RegFormAttendeeFactory |
|
249 | - if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
250 | - return false; |
|
251 | - } |
|
252 | - // at this point, we should have enough details about the registrant to consider the registration |
|
253 | - // NOT incomplete |
|
254 | - $this->registration_processor->toggle_incomplete_registration_status_to_default( |
|
255 | - $registration, |
|
256 | - false, |
|
257 | - new Context( |
|
258 | - 'spco_reg_step_attendee_information_process_registrations', |
|
259 | - esc_html__( |
|
260 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
261 | - 'event_espresso' |
|
262 | - ) |
|
263 | - ) |
|
264 | - ); |
|
265 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
266 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
267 | - // if we've gotten this far, then let's save what we have |
|
268 | - $registration->save(); |
|
269 | - // add relation between TXN and registration |
|
270 | - $this->associateRegistrationWithTransaction($registration); |
|
271 | - return true; |
|
272 | - } |
|
231 | + /** |
|
232 | + * @param EE_Registration $registration |
|
233 | + * @param string $reg_url_link |
|
234 | + * @param array[][] $reg_form_data |
|
235 | + * @return bool |
|
236 | + * @throws EE_Error |
|
237 | + * @throws ReflectionException |
|
238 | + */ |
|
239 | + protected function processRegistration( |
|
240 | + EE_Registration $registration, |
|
241 | + string $reg_url_link, |
|
242 | + array $reg_form_data |
|
243 | + ): bool { |
|
244 | + $this->registrant_data->initializeRegistrantData($registration); |
|
245 | + if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
246 | + return false; |
|
247 | + } |
|
248 | + // RegFormAttendeeFactory |
|
249 | + if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
250 | + return false; |
|
251 | + } |
|
252 | + // at this point, we should have enough details about the registrant to consider the registration |
|
253 | + // NOT incomplete |
|
254 | + $this->registration_processor->toggle_incomplete_registration_status_to_default( |
|
255 | + $registration, |
|
256 | + false, |
|
257 | + new Context( |
|
258 | + 'spco_reg_step_attendee_information_process_registrations', |
|
259 | + esc_html__( |
|
260 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
261 | + 'event_espresso' |
|
262 | + ) |
|
263 | + ) |
|
264 | + ); |
|
265 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
266 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
267 | + // if we've gotten this far, then let's save what we have |
|
268 | + $registration->save(); |
|
269 | + // add relation between TXN and registration |
|
270 | + $this->associateRegistrationWithTransaction($registration); |
|
271 | + return true; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | |
275 | - /** |
|
276 | - * @param EE_Registration $registration |
|
277 | - * @return void |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws ReflectionException |
|
281 | - * @throws InvalidDataTypeException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - */ |
|
284 | - private function associateRegistrationWithTransaction(EE_Registration $registration) |
|
285 | - { |
|
286 | - // add relation to registration |
|
287 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
288 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
289 | - } |
|
275 | + /** |
|
276 | + * @param EE_Registration $registration |
|
277 | + * @return void |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws ReflectionException |
|
281 | + * @throws InvalidDataTypeException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + */ |
|
284 | + private function associateRegistrationWithTransaction(EE_Registration $registration) |
|
285 | + { |
|
286 | + // add relation to registration |
|
287 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
288 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
289 | + } |
|
290 | 290 | } |
@@ -137,21 +137,21 @@ discard block |
||
137 | 137 | $this->valid = true; |
138 | 138 | foreach ($registrations as $registration) { |
139 | 139 | // verify EE_Registration object |
140 | - if (! $this->isValidRegistration($registration)) { |
|
140 | + if ( ! $this->isValidRegistration($registration)) { |
|
141 | 141 | return $this->isInvalid(); |
142 | 142 | } |
143 | 143 | // reg_url_link exists ? |
144 | 144 | $reg_url_link = $registration->reg_url_link(); |
145 | - if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
145 | + if ( ! $this->isValidRegUrlLink($reg_url_link)) { |
|
146 | 146 | return $this->isInvalid(); |
147 | 147 | } |
148 | 148 | // should this registration be processed during this visit ? |
149 | - if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
149 | + if ( ! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
150 | 150 | continue; |
151 | 151 | } |
152 | 152 | // if NOT revisiting, then let's save the registration now, |
153 | 153 | // so that we have a REG_ID to use when generating other objects |
154 | - if (! $this->checkout->revisit) { |
|
154 | + if ( ! $this->checkout->revisit) { |
|
155 | 155 | $registration->save(); |
156 | 156 | } |
157 | 157 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | // Houston, we have a registration! |
178 | - if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
178 | + if ( ! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
179 | 179 | return $this->isInvalid(); |
180 | 180 | } |
181 | 181 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | protected function isValidRegUrlLink(string $reg_url_link): bool |
191 | 191 | { |
192 | - if (! empty($reg_url_link)) { |
|
192 | + if ( ! empty($reg_url_link)) { |
|
193 | 193 | return true; |
194 | 194 | } |
195 | 195 | EE_Error::add_error( |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | array $reg_form_data |
243 | 243 | ): bool { |
244 | 244 | $this->registrant_data->initializeRegistrantData($registration); |
245 | - if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
245 | + if ( ! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | // RegFormAttendeeFactory |
249 | - if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
249 | + if ( ! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
250 | 250 | return false; |
251 | 251 | } |
252 | 252 | // at this point, we should have enough details about the registrant to consider the registration |
@@ -22,66 +22,66 @@ |
||
22 | 22 | */ |
23 | 23 | class RegForm extends RegFormBase |
24 | 24 | { |
25 | - /** |
|
26 | - * @var JsonDataAPI |
|
27 | - */ |
|
28 | - public $form_data_api; |
|
25 | + /** |
|
26 | + * @var JsonDataAPI |
|
27 | + */ |
|
28 | + public $form_data_api; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var RegistrantFormInput |
|
32 | - */ |
|
33 | - public $reg_form_input_factory; |
|
30 | + /** |
|
31 | + * @var RegistrantFormInput |
|
32 | + */ |
|
33 | + public $reg_form_input_factory; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * RegForm constructor. |
|
38 | - * |
|
39 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
40 | - * @param JsonDataAPI $form_data_api |
|
41 | - * @param EE_Registration_Config $reg_config |
|
42 | - * @throws EE_Error |
|
43 | - * @throws ReflectionException |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
47 | - JsonDataAPI $form_data_api, |
|
48 | - EE_Registration_Config $reg_config |
|
49 | - ) { |
|
50 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
51 | - $this->form_data_api = $form_data_api; |
|
52 | - $this->reg_form_input_factory = LoaderFactory::getNew( |
|
53 | - RegistrantFormInput::class, |
|
54 | - [ |
|
55 | - [$this, 'addRequiredQuestion'], |
|
56 | - $this->form_data_api |
|
57 | - ] |
|
58 | - ); |
|
59 | - parent::__construct($reg_step, $reg_config); |
|
60 | - } |
|
36 | + /** |
|
37 | + * RegForm constructor. |
|
38 | + * |
|
39 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
40 | + * @param JsonDataAPI $form_data_api |
|
41 | + * @param EE_Registration_Config $reg_config |
|
42 | + * @throws EE_Error |
|
43 | + * @throws ReflectionException |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
47 | + JsonDataAPI $form_data_api, |
|
48 | + EE_Registration_Config $reg_config |
|
49 | + ) { |
|
50 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
51 | + $this->form_data_api = $form_data_api; |
|
52 | + $this->reg_form_input_factory = LoaderFactory::getNew( |
|
53 | + RegistrantFormInput::class, |
|
54 | + [ |
|
55 | + [$this, 'addRequiredQuestion'], |
|
56 | + $this->form_data_api |
|
57 | + ] |
|
58 | + ); |
|
59 | + parent::__construct($reg_step, $reg_config); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @param EE_Registration $registration |
|
65 | - * @param bool $admin_request |
|
66 | - * @param bool $copy_attendee_info |
|
67 | - * @param callable $enablePrintCopyInfo |
|
68 | - * @return RegistrantFormInterface |
|
69 | - */ |
|
70 | - protected function getRegistrantForm( |
|
71 | - EE_Registration $registration, |
|
72 | - bool $admin_request, |
|
73 | - bool $copy_attendee_info, |
|
74 | - callable $enablePrintCopyInfo |
|
75 | - ): RegistrantFormInterface { |
|
76 | - return LoaderFactory::getNew( |
|
77 | - RegistrantForm::class, |
|
78 | - [ |
|
79 | - $registration, |
|
80 | - $admin_request, |
|
81 | - $copy_attendee_info, |
|
82 | - $enablePrintCopyInfo, |
|
83 | - $this->reg_form_input_factory, |
|
84 | - ] |
|
85 | - ); |
|
86 | - } |
|
63 | + /** |
|
64 | + * @param EE_Registration $registration |
|
65 | + * @param bool $admin_request |
|
66 | + * @param bool $copy_attendee_info |
|
67 | + * @param callable $enablePrintCopyInfo |
|
68 | + * @return RegistrantFormInterface |
|
69 | + */ |
|
70 | + protected function getRegistrantForm( |
|
71 | + EE_Registration $registration, |
|
72 | + bool $admin_request, |
|
73 | + bool $copy_attendee_info, |
|
74 | + callable $enablePrintCopyInfo |
|
75 | + ): RegistrantFormInterface { |
|
76 | + return LoaderFactory::getNew( |
|
77 | + RegistrantForm::class, |
|
78 | + [ |
|
79 | + $registration, |
|
80 | + $admin_request, |
|
81 | + $copy_attendee_info, |
|
82 | + $enablePrintCopyInfo, |
|
83 | + $this->reg_form_input_factory, |
|
84 | + ] |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | } |