Completed
Branch master (8de7dd)
by
unknown
06:29
created
modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php 2 patches
Indentation   +653 added lines, -653 removed lines patch added patch discarded remove patch
@@ -13,657 +13,657 @@
 block discarded – undo
13 13
  */
14 14
 abstract class EE_SPCO_Reg_Step
15 15
 {
16
-    /**
17
-     *    $_completed - TRUE if this step has fully completed it's duties
18
-     *
19
-     * @access protected
20
-     * @type bool $_completed
21
-     */
22
-    protected $_completed = false;
23
-
24
-    /**
25
-     *    $_is_current_step - TRUE if this is the current step
26
-     *
27
-     * @access protected
28
-     * @type bool $_is_current_step
29
-     */
30
-    protected $_is_current_step = false;
31
-
32
-    /**
33
-     *    $_order - when the reg step should be run relative to other steps
34
-     *
35
-     * @access protected
36
-     * @type int $_template
37
-     */
38
-    protected $_order = 0;
39
-
40
-    /**
41
-     *    $_slug - URL param for this step
42
-     *
43
-     * @access protected
44
-     * @type string $_slug
45
-     */
46
-    protected $_slug;
47
-
48
-    /**
49
-     *    $_name - Step Name - translatable string
50
-     *
51
-     * @access protected
52
-     * @type string $_slug
53
-     */
54
-    protected $_name;
55
-
56
-    /**
57
-     *    $_submit_button_text - translatable string that appears on this step's submit button
58
-     *
59
-     * @access protected
60
-     * @type string $_slug
61
-     */
62
-    protected $_submit_button_text;
63
-
64
-    /**
65
-     *    $_template - template name
66
-     *
67
-     * @access protected
68
-     * @type string $_template
69
-     */
70
-    protected $_template;
71
-
72
-    /**
73
-     *    $_reg_form_name - the form input name and id attribute
74
-     *
75
-     * @access protected
76
-     * @var string $_reg_form_name
77
-     */
78
-    protected $_reg_form_name;
79
-
80
-    /**
81
-     *    $_success_message - text to display upon successful form submission
82
-     *
83
-     * @access private
84
-     * @var string $_success_message
85
-     */
86
-    protected $_success_message;
87
-
88
-    /**
89
-     *    $_instructions - a brief description of how to complete the reg step.
90
-     *    Usually displayed in conjunction with the previous step's success message.
91
-     *
92
-     * @access private
93
-     * @var string $_instructions
94
-     */
95
-    protected $_instructions;
96
-
97
-    /**
98
-     *    $_valid_data - the normalized and validated data for this step
99
-     *
100
-     * @access public
101
-     * @var array $_valid_data
102
-     */
103
-    protected $_valid_data = [];
104
-
105
-    /**
106
-     *    $reg_form - the registration form for this step
107
-     *
108
-     * @access public
109
-     * @var EE_Form_Section_Proper $reg_form
110
-     */
111
-    public $reg_form;
112
-
113
-    /**
114
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
115
-     *
116
-     * @access public
117
-     * @var EE_Checkout $checkout
118
-     */
119
-    public $checkout;
120
-
121
-    /**
122
-     * @var RequestInterface $request
123
-     */
124
-    protected $request;
125
-
126
-
127
-    /**
128
-     * @return void
129
-     */
130
-    abstract public function translate_js_strings();
131
-
132
-
133
-    /**
134
-     * @return void
135
-     */
136
-    abstract public function enqueue_styles_and_scripts();
137
-
138
-
139
-    /**
140
-     * @return boolean
141
-     */
142
-    abstract public function initialize_reg_step();
143
-
144
-
145
-    /**
146
-     * @return EE_Form_Section_Proper
147
-     */
148
-    abstract public function generate_reg_form();
149
-
150
-
151
-    /**
152
-     * @return boolean
153
-     */
154
-    abstract public function process_reg_step();
155
-
156
-
157
-    /**
158
-     * @return boolean
159
-     */
160
-    abstract public function update_reg_step();
161
-
162
-
163
-    /**
164
-     * @return boolean
165
-     */
166
-    public function completed()
167
-    {
168
-        return $this->_completed;
169
-    }
170
-
171
-
172
-    /**
173
-     * set_completed - toggles $_completed to TRUE
174
-     */
175
-    public function set_completed()
176
-    {
177
-        // DEBUG LOG
178
-        // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
179
-        $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this);
180
-    }
181
-
182
-
183
-    /**
184
-     * set_completed - toggles $_completed to FALSE
185
-     */
186
-    public function set_not_completed()
187
-    {
188
-        $this->_completed = false;
189
-    }
190
-
191
-
192
-    /**
193
-     * @return string
194
-     */
195
-    public function name()
196
-    {
197
-        return $this->_name;
198
-    }
199
-
200
-
201
-    /**
202
-     * @return string
203
-     */
204
-    public function slug()
205
-    {
206
-        return $this->_slug;
207
-    }
208
-
209
-
210
-    /**
211
-     * submit_button_text
212
-     * the text that appears on the reg step form submit button
213
-     *
214
-     * @return string
215
-     */
216
-    public function submit_button_text()
217
-    {
218
-        return $this->_submit_button_text;
219
-    }
220
-
221
-
222
-    /**
223
-     * set_submit_button_text
224
-     * sets the text that appears on the reg step form submit button
225
-     *
226
-     * @param string $submit_button_text
227
-     */
228
-    public function set_submit_button_text($submit_button_text = '')
229
-    {
230
-        if (! empty($submit_button_text)) {
231
-            $this->_submit_button_text = $submit_button_text;
232
-        } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
233
-            if ($this->checkout->revisit) {
234
-                $this->_submit_button_text = sprintf(
235
-                    esc_html__('Update %s', 'event_espresso'),
236
-                    $this->checkout->current_step->name()
237
-                );
238
-            } else {
239
-                $this->_submit_button_text = sprintf(
240
-                    esc_html__('Proceed to %s', 'event_espresso'),
241
-                    $this->checkout->next_step->name()
242
-                );
243
-            }
244
-        }
245
-        // filters the submit button text
246
-        $this->_submit_button_text = apply_filters(
247
-            'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
248
-            $this->_submit_button_text,
249
-            $this->checkout
250
-        );
251
-    }
252
-
253
-
254
-    /**
255
-     * @param boolean $is_current_step
256
-     */
257
-    public function set_is_current_step($is_current_step)
258
-    {
259
-        $this->_is_current_step = $is_current_step;
260
-    }
261
-
262
-
263
-    /**
264
-     * @return boolean
265
-     */
266
-    public function is_current_step()
267
-    {
268
-        return $this->_is_current_step;
269
-    }
270
-
271
-
272
-    /**
273
-     * @return boolean
274
-     */
275
-    public function is_final_step()
276
-    {
277
-        return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration;
278
-    }
279
-
280
-
281
-    /**
282
-     * @param int $order
283
-     */
284
-    public function set_order($order)
285
-    {
286
-        $this->_order = $order;
287
-    }
288
-
289
-
290
-    /**
291
-     * @return int
292
-     */
293
-    public function order()
294
-    {
295
-        return $this->_order;
296
-    }
297
-
298
-
299
-    /**
300
-     * @return string
301
-     */
302
-    public function template(): string
303
-    {
304
-        return $this->_template;
305
-    }
306
-
307
-
308
-    /**
309
-     * @param string $template
310
-     */
311
-    public function setTemplate(string $template): void
312
-    {
313
-        $this->_template = $template;
314
-    }
315
-
316
-
317
-    /**
318
-     * @return string
319
-     */
320
-    public function success_message()
321
-    {
322
-        return $this->_success_message;
323
-    }
324
-
325
-
326
-    /**
327
-     * _set_success_message
328
-     *
329
-     * @param string $success_message
330
-     */
331
-    protected function _set_success_message($success_message)
332
-    {
333
-        $this->_success_message = $success_message;
334
-    }
335
-
336
-
337
-    /**
338
-     * _reset_success_message
339
-     *
340
-     * @return void
341
-     */
342
-    protected function _reset_success_message()
343
-    {
344
-        $this->_success_message = '';
345
-    }
346
-
347
-
348
-    /**
349
-     * @return string
350
-     */
351
-    public function _instructions()
352
-    {
353
-        return $this->_instructions;
354
-    }
355
-
356
-
357
-    /**
358
-     * @param string $instructions
359
-     */
360
-    public function set_instructions($instructions)
361
-    {
362
-        $this->_instructions = apply_filters(
363
-            'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions',
364
-            $instructions,
365
-            $this
366
-        );
367
-    }
368
-
369
-
370
-    /**
371
-     * @param array $valid_data
372
-     */
373
-    public function set_valid_data($valid_data)
374
-    {
375
-        $this->_valid_data = $valid_data;
376
-    }
377
-
378
-
379
-    /**
380
-     * @return array
381
-     * @throws EE_Error
382
-     * @throws EE_Error
383
-     */
384
-    public function valid_data()
385
-    {
386
-        if (empty($this->_valid_data)) {
387
-            $this->_valid_data = $this->reg_form->valid_data();
388
-        }
389
-        return $this->_valid_data;
390
-    }
391
-
392
-
393
-    /**
394
-     * @return string
395
-     */
396
-    public function reg_form_name()
397
-    {
398
-        if (empty($this->_reg_form_name)) {
399
-            $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
400
-        }
401
-        return $this->_reg_form_name;
402
-    }
403
-
404
-
405
-    /**
406
-     * @param string $reg_form_name
407
-     */
408
-    protected function set_reg_form_name($reg_form_name)
409
-    {
410
-        $this->_reg_form_name = $reg_form_name;
411
-    }
412
-
413
-
414
-    /**
415
-     * reg_step_url
416
-     *
417
-     * @param string $action
418
-     * @return string
419
-     */
420
-    public function reg_step_url($action = '')
421
-    {
422
-        $query_args = ['step' => $this->slug()];
423
-        if (! empty($action)) {
424
-            $query_args['action'] = $action;
425
-        }
426
-        // final step has no display
427
-        if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') {
428
-            $query_args['action'] = 'process_reg_step';
429
-        }
430
-        if ($this->checkout->revisit) {
431
-            $query_args['revisit'] = true;
432
-        }
433
-        if ($this->checkout->reg_url_link) {
434
-            $query_args['e_reg_url_link'] = $this->checkout->reg_url_link;
435
-        }
436
-        return add_query_arg($query_args, $this->checkout->reg_page_base_url);
437
-    }
438
-
439
-
440
-    /**
441
-     * creates the default hidden inputs section
442
-     *
443
-     * @return EE_Form_Section_Proper
444
-     * @throws EE_Error
445
-     */
446
-    public function reg_step_hidden_inputs()
447
-    {
448
-        // hidden inputs for admin registrations
449
-        if ($this->checkout->admin_request) {
450
-            return new EE_Form_Section_Proper(
451
-                [
452
-                    'layout_strategy' => new EE_No_Layout(),
453
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
454
-                    'subsections'     => [
455
-                        'next_step' => new EE_Fixed_Hidden_Input(
456
-                            [
457
-                                'html_name' => 'next_step',
458
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
459
-                                'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
460
-                                    ? $this->checkout->next_step->slug()
461
-                                    : '',
462
-                            ]
463
-                        ),
464
-                    ],
465
-                ]
466
-            );
467
-        }
468
-        // hidden inputs for frontend registrations
469
-        return new EE_Form_Section_Proper(
470
-            [
471
-                'layout_strategy' => new EE_No_Layout(),
472
-                'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
473
-                'subsections'     => [
474
-                    'action'         => new EE_Fixed_Hidden_Input(
475
-                        [
476
-                            'html_name' => 'action',
477
-                            'html_id'   => 'spco-' . $this->slug() . '-action',
478
-                            'default'   => apply_filters(
479
-                                'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
480
-                                empty($this->checkout->reg_url_link)
481
-                                    ? 'process_reg_step'
482
-                                    : 'update_reg_step',
483
-                                $this
484
-                            ),
485
-                        ]
486
-                    ),
487
-                    'next_step'      => new EE_Fixed_Hidden_Input(
488
-                        [
489
-                            'html_name' => 'next_step',
490
-                            'html_id'   => 'spco-' . $this->slug() . '-next-step',
491
-                            'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
492
-                                ? $this->checkout->next_step->slug()
493
-                                : '',
494
-                        ]
495
-                    ),
496
-                    'e_reg_url_link' => new EE_Fixed_Hidden_Input(
497
-                        [
498
-                            'html_name' => 'e_reg_url_link',
499
-                            'html_id'   => 'spco-reg_url_link',
500
-                            'default'   => $this->checkout->reg_url_link,
501
-                        ]
502
-                    ),
503
-                    'revisit'        => new EE_Fixed_Hidden_Input(
504
-                        [
505
-                            'html_name' => 'revisit',
506
-                            'html_id'   => 'spco-revisit',
507
-                            'default'   => $this->checkout->revisit,
508
-                        ]
509
-                    ),
510
-                ],
511
-            ]
512
-        );
513
-    }
514
-
515
-
516
-    /**
517
-     * generate_reg_form_for_actions
518
-     *
519
-     * @param array $actions
520
-     * @return void
521
-     */
522
-    public function generate_reg_form_for_actions($actions = [])
523
-    {
524
-        $actions                           = array_merge(
525
-            [
526
-                'generate_reg_form',
527
-                'display_spco_reg_step',
528
-                'process_reg_step',
529
-                'update_reg_step',
530
-            ],
531
-            $actions
532
-        );
533
-        $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true);
534
-    }
535
-
536
-
537
-    /**
538
-     * @return string
539
-     * @throws EE_Error
540
-     */
541
-    public function display_reg_form()
542
-    {
543
-        $html = '';
544
-        if ($this->reg_form instanceof EE_Form_Section_Proper) {
545
-            do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this);
546
-            $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : '';
547
-            if ($this->request->isAjax()) {
548
-                $this->reg_form->localize_validation_rules();
549
-                $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
550
-            }
551
-            $html .= $this->reg_form->get_html();
552
-            $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : '';
553
-            $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : '';
554
-        }
555
-        return $html;
556
-    }
557
-
558
-
559
-    /**
560
-     * div_class - returns nothing for current step, but a css class of "hidden" for others
561
-     *
562
-     * @return string
563
-     * @throws EE_Error
564
-     */
565
-    public function reg_step_submit_button()
566
-    {
567
-        if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
568
-            return '';
569
-        }
570
-        ob_start();
571
-        do_action(
572
-            'AHEE__before_spco_whats_next_buttons',
573
-            $this->slug(),
574
-            $this->checkout->next_step->slug(),
575
-            $this->checkout
576
-        );
577
-        $html = ob_get_clean();
578
-        // generate submit button
579
-        $submit_btn = new EE_Submit_Input(
580
-            [
581
-                'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
582
-                'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
583
-                'html_class'            => 'spco-next-step-btn',
584
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
585
-                'default'               => $this->submit_button_text(),
586
-            ]
587
-        );
588
-        $submit_btn->set_button_css_attributes(true, 'large');
589
-        $submit_btn_html = $submit_btn->get_html_for_input();
590
-        $html            .= EEH_HTML::div(
591
-            apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this),
592
-            'spco-' . $this->slug() . '-whats-next-buttons-dv',
593
-            'spco-whats-next-buttons'
594
-        );
595
-        return $html;
596
-    }
597
-
598
-
599
-    /**
600
-     * div_class - returns nothing for current step, but a css class of "hidden" for others
601
-     *
602
-     * @return string
603
-     */
604
-    public function div_class()
605
-    {
606
-        return $this->is_current_step() ? '' : ' hidden';
607
-    }
608
-
609
-
610
-    /**
611
-     * div_class - returns  a css class of "hidden" for current step, but nothing for others
612
-     *
613
-     * @return string
614
-     */
615
-    public function edit_lnk_url()
616
-    {
617
-        return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url);
618
-    }
619
-
620
-
621
-    /**
622
-     * div_class - returns  a css class of "hidden" for current step, but nothing for others
623
-     *
624
-     * @return string
625
-     */
626
-    public function edit_link_class()
627
-    {
628
-        return $this->is_current_step() ? ' hidden' : '';
629
-    }
630
-
631
-
632
-    /**
633
-     * update_checkout with changes that have been made to the cart
634
-     *
635
-     * @return void
636
-     * @throws EE_Error
637
-     * @throws ReflectionException
638
-     */
639
-    public function update_checkout()
640
-    {
641
-        // grab the cart grand total and reset TXN total
642
-        $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total());
643
-        $this->checkout->stash_transaction_and_checkout();
644
-    }
645
-
646
-
647
-    /**
648
-     *    __sleep
649
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
650
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
651
-     * reg form, because if needed, it will be regenerated anyways
652
-     *
653
-     * @return array
654
-     */
655
-    public function __sleep()
656
-    {
657
-        // remove the reg form and the checkout
658
-        return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']);
659
-    }
660
-
661
-
662
-    /**
663
-     * @param RequestInterface $request
664
-     */
665
-    public function setRequest(RequestInterface $request)
666
-    {
667
-        $this->request = $request;
668
-    }
16
+	/**
17
+	 *    $_completed - TRUE if this step has fully completed it's duties
18
+	 *
19
+	 * @access protected
20
+	 * @type bool $_completed
21
+	 */
22
+	protected $_completed = false;
23
+
24
+	/**
25
+	 *    $_is_current_step - TRUE if this is the current step
26
+	 *
27
+	 * @access protected
28
+	 * @type bool $_is_current_step
29
+	 */
30
+	protected $_is_current_step = false;
31
+
32
+	/**
33
+	 *    $_order - when the reg step should be run relative to other steps
34
+	 *
35
+	 * @access protected
36
+	 * @type int $_template
37
+	 */
38
+	protected $_order = 0;
39
+
40
+	/**
41
+	 *    $_slug - URL param for this step
42
+	 *
43
+	 * @access protected
44
+	 * @type string $_slug
45
+	 */
46
+	protected $_slug;
47
+
48
+	/**
49
+	 *    $_name - Step Name - translatable string
50
+	 *
51
+	 * @access protected
52
+	 * @type string $_slug
53
+	 */
54
+	protected $_name;
55
+
56
+	/**
57
+	 *    $_submit_button_text - translatable string that appears on this step's submit button
58
+	 *
59
+	 * @access protected
60
+	 * @type string $_slug
61
+	 */
62
+	protected $_submit_button_text;
63
+
64
+	/**
65
+	 *    $_template - template name
66
+	 *
67
+	 * @access protected
68
+	 * @type string $_template
69
+	 */
70
+	protected $_template;
71
+
72
+	/**
73
+	 *    $_reg_form_name - the form input name and id attribute
74
+	 *
75
+	 * @access protected
76
+	 * @var string $_reg_form_name
77
+	 */
78
+	protected $_reg_form_name;
79
+
80
+	/**
81
+	 *    $_success_message - text to display upon successful form submission
82
+	 *
83
+	 * @access private
84
+	 * @var string $_success_message
85
+	 */
86
+	protected $_success_message;
87
+
88
+	/**
89
+	 *    $_instructions - a brief description of how to complete the reg step.
90
+	 *    Usually displayed in conjunction with the previous step's success message.
91
+	 *
92
+	 * @access private
93
+	 * @var string $_instructions
94
+	 */
95
+	protected $_instructions;
96
+
97
+	/**
98
+	 *    $_valid_data - the normalized and validated data for this step
99
+	 *
100
+	 * @access public
101
+	 * @var array $_valid_data
102
+	 */
103
+	protected $_valid_data = [];
104
+
105
+	/**
106
+	 *    $reg_form - the registration form for this step
107
+	 *
108
+	 * @access public
109
+	 * @var EE_Form_Section_Proper $reg_form
110
+	 */
111
+	public $reg_form;
112
+
113
+	/**
114
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
115
+	 *
116
+	 * @access public
117
+	 * @var EE_Checkout $checkout
118
+	 */
119
+	public $checkout;
120
+
121
+	/**
122
+	 * @var RequestInterface $request
123
+	 */
124
+	protected $request;
125
+
126
+
127
+	/**
128
+	 * @return void
129
+	 */
130
+	abstract public function translate_js_strings();
131
+
132
+
133
+	/**
134
+	 * @return void
135
+	 */
136
+	abstract public function enqueue_styles_and_scripts();
137
+
138
+
139
+	/**
140
+	 * @return boolean
141
+	 */
142
+	abstract public function initialize_reg_step();
143
+
144
+
145
+	/**
146
+	 * @return EE_Form_Section_Proper
147
+	 */
148
+	abstract public function generate_reg_form();
149
+
150
+
151
+	/**
152
+	 * @return boolean
153
+	 */
154
+	abstract public function process_reg_step();
155
+
156
+
157
+	/**
158
+	 * @return boolean
159
+	 */
160
+	abstract public function update_reg_step();
161
+
162
+
163
+	/**
164
+	 * @return boolean
165
+	 */
166
+	public function completed()
167
+	{
168
+		return $this->_completed;
169
+	}
170
+
171
+
172
+	/**
173
+	 * set_completed - toggles $_completed to TRUE
174
+	 */
175
+	public function set_completed()
176
+	{
177
+		// DEBUG LOG
178
+		// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
179
+		$this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this);
180
+	}
181
+
182
+
183
+	/**
184
+	 * set_completed - toggles $_completed to FALSE
185
+	 */
186
+	public function set_not_completed()
187
+	{
188
+		$this->_completed = false;
189
+	}
190
+
191
+
192
+	/**
193
+	 * @return string
194
+	 */
195
+	public function name()
196
+	{
197
+		return $this->_name;
198
+	}
199
+
200
+
201
+	/**
202
+	 * @return string
203
+	 */
204
+	public function slug()
205
+	{
206
+		return $this->_slug;
207
+	}
208
+
209
+
210
+	/**
211
+	 * submit_button_text
212
+	 * the text that appears on the reg step form submit button
213
+	 *
214
+	 * @return string
215
+	 */
216
+	public function submit_button_text()
217
+	{
218
+		return $this->_submit_button_text;
219
+	}
220
+
221
+
222
+	/**
223
+	 * set_submit_button_text
224
+	 * sets the text that appears on the reg step form submit button
225
+	 *
226
+	 * @param string $submit_button_text
227
+	 */
228
+	public function set_submit_button_text($submit_button_text = '')
229
+	{
230
+		if (! empty($submit_button_text)) {
231
+			$this->_submit_button_text = $submit_button_text;
232
+		} elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
233
+			if ($this->checkout->revisit) {
234
+				$this->_submit_button_text = sprintf(
235
+					esc_html__('Update %s', 'event_espresso'),
236
+					$this->checkout->current_step->name()
237
+				);
238
+			} else {
239
+				$this->_submit_button_text = sprintf(
240
+					esc_html__('Proceed to %s', 'event_espresso'),
241
+					$this->checkout->next_step->name()
242
+				);
243
+			}
244
+		}
245
+		// filters the submit button text
246
+		$this->_submit_button_text = apply_filters(
247
+			'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
248
+			$this->_submit_button_text,
249
+			$this->checkout
250
+		);
251
+	}
252
+
253
+
254
+	/**
255
+	 * @param boolean $is_current_step
256
+	 */
257
+	public function set_is_current_step($is_current_step)
258
+	{
259
+		$this->_is_current_step = $is_current_step;
260
+	}
261
+
262
+
263
+	/**
264
+	 * @return boolean
265
+	 */
266
+	public function is_current_step()
267
+	{
268
+		return $this->_is_current_step;
269
+	}
270
+
271
+
272
+	/**
273
+	 * @return boolean
274
+	 */
275
+	public function is_final_step()
276
+	{
277
+		return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @param int $order
283
+	 */
284
+	public function set_order($order)
285
+	{
286
+		$this->_order = $order;
287
+	}
288
+
289
+
290
+	/**
291
+	 * @return int
292
+	 */
293
+	public function order()
294
+	{
295
+		return $this->_order;
296
+	}
297
+
298
+
299
+	/**
300
+	 * @return string
301
+	 */
302
+	public function template(): string
303
+	{
304
+		return $this->_template;
305
+	}
306
+
307
+
308
+	/**
309
+	 * @param string $template
310
+	 */
311
+	public function setTemplate(string $template): void
312
+	{
313
+		$this->_template = $template;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @return string
319
+	 */
320
+	public function success_message()
321
+	{
322
+		return $this->_success_message;
323
+	}
324
+
325
+
326
+	/**
327
+	 * _set_success_message
328
+	 *
329
+	 * @param string $success_message
330
+	 */
331
+	protected function _set_success_message($success_message)
332
+	{
333
+		$this->_success_message = $success_message;
334
+	}
335
+
336
+
337
+	/**
338
+	 * _reset_success_message
339
+	 *
340
+	 * @return void
341
+	 */
342
+	protected function _reset_success_message()
343
+	{
344
+		$this->_success_message = '';
345
+	}
346
+
347
+
348
+	/**
349
+	 * @return string
350
+	 */
351
+	public function _instructions()
352
+	{
353
+		return $this->_instructions;
354
+	}
355
+
356
+
357
+	/**
358
+	 * @param string $instructions
359
+	 */
360
+	public function set_instructions($instructions)
361
+	{
362
+		$this->_instructions = apply_filters(
363
+			'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions',
364
+			$instructions,
365
+			$this
366
+		);
367
+	}
368
+
369
+
370
+	/**
371
+	 * @param array $valid_data
372
+	 */
373
+	public function set_valid_data($valid_data)
374
+	{
375
+		$this->_valid_data = $valid_data;
376
+	}
377
+
378
+
379
+	/**
380
+	 * @return array
381
+	 * @throws EE_Error
382
+	 * @throws EE_Error
383
+	 */
384
+	public function valid_data()
385
+	{
386
+		if (empty($this->_valid_data)) {
387
+			$this->_valid_data = $this->reg_form->valid_data();
388
+		}
389
+		return $this->_valid_data;
390
+	}
391
+
392
+
393
+	/**
394
+	 * @return string
395
+	 */
396
+	public function reg_form_name()
397
+	{
398
+		if (empty($this->_reg_form_name)) {
399
+			$this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
400
+		}
401
+		return $this->_reg_form_name;
402
+	}
403
+
404
+
405
+	/**
406
+	 * @param string $reg_form_name
407
+	 */
408
+	protected function set_reg_form_name($reg_form_name)
409
+	{
410
+		$this->_reg_form_name = $reg_form_name;
411
+	}
412
+
413
+
414
+	/**
415
+	 * reg_step_url
416
+	 *
417
+	 * @param string $action
418
+	 * @return string
419
+	 */
420
+	public function reg_step_url($action = '')
421
+	{
422
+		$query_args = ['step' => $this->slug()];
423
+		if (! empty($action)) {
424
+			$query_args['action'] = $action;
425
+		}
426
+		// final step has no display
427
+		if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') {
428
+			$query_args['action'] = 'process_reg_step';
429
+		}
430
+		if ($this->checkout->revisit) {
431
+			$query_args['revisit'] = true;
432
+		}
433
+		if ($this->checkout->reg_url_link) {
434
+			$query_args['e_reg_url_link'] = $this->checkout->reg_url_link;
435
+		}
436
+		return add_query_arg($query_args, $this->checkout->reg_page_base_url);
437
+	}
438
+
439
+
440
+	/**
441
+	 * creates the default hidden inputs section
442
+	 *
443
+	 * @return EE_Form_Section_Proper
444
+	 * @throws EE_Error
445
+	 */
446
+	public function reg_step_hidden_inputs()
447
+	{
448
+		// hidden inputs for admin registrations
449
+		if ($this->checkout->admin_request) {
450
+			return new EE_Form_Section_Proper(
451
+				[
452
+					'layout_strategy' => new EE_No_Layout(),
453
+					'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
454
+					'subsections'     => [
455
+						'next_step' => new EE_Fixed_Hidden_Input(
456
+							[
457
+								'html_name' => 'next_step',
458
+								'html_id'   => 'spco-' . $this->slug() . '-next-step',
459
+								'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
460
+									? $this->checkout->next_step->slug()
461
+									: '',
462
+							]
463
+						),
464
+					],
465
+				]
466
+			);
467
+		}
468
+		// hidden inputs for frontend registrations
469
+		return new EE_Form_Section_Proper(
470
+			[
471
+				'layout_strategy' => new EE_No_Layout(),
472
+				'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
473
+				'subsections'     => [
474
+					'action'         => new EE_Fixed_Hidden_Input(
475
+						[
476
+							'html_name' => 'action',
477
+							'html_id'   => 'spco-' . $this->slug() . '-action',
478
+							'default'   => apply_filters(
479
+								'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
480
+								empty($this->checkout->reg_url_link)
481
+									? 'process_reg_step'
482
+									: 'update_reg_step',
483
+								$this
484
+							),
485
+						]
486
+					),
487
+					'next_step'      => new EE_Fixed_Hidden_Input(
488
+						[
489
+							'html_name' => 'next_step',
490
+							'html_id'   => 'spco-' . $this->slug() . '-next-step',
491
+							'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
492
+								? $this->checkout->next_step->slug()
493
+								: '',
494
+						]
495
+					),
496
+					'e_reg_url_link' => new EE_Fixed_Hidden_Input(
497
+						[
498
+							'html_name' => 'e_reg_url_link',
499
+							'html_id'   => 'spco-reg_url_link',
500
+							'default'   => $this->checkout->reg_url_link,
501
+						]
502
+					),
503
+					'revisit'        => new EE_Fixed_Hidden_Input(
504
+						[
505
+							'html_name' => 'revisit',
506
+							'html_id'   => 'spco-revisit',
507
+							'default'   => $this->checkout->revisit,
508
+						]
509
+					),
510
+				],
511
+			]
512
+		);
513
+	}
514
+
515
+
516
+	/**
517
+	 * generate_reg_form_for_actions
518
+	 *
519
+	 * @param array $actions
520
+	 * @return void
521
+	 */
522
+	public function generate_reg_form_for_actions($actions = [])
523
+	{
524
+		$actions                           = array_merge(
525
+			[
526
+				'generate_reg_form',
527
+				'display_spco_reg_step',
528
+				'process_reg_step',
529
+				'update_reg_step',
530
+			],
531
+			$actions
532
+		);
533
+		$this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true);
534
+	}
535
+
536
+
537
+	/**
538
+	 * @return string
539
+	 * @throws EE_Error
540
+	 */
541
+	public function display_reg_form()
542
+	{
543
+		$html = '';
544
+		if ($this->reg_form instanceof EE_Form_Section_Proper) {
545
+			do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this);
546
+			$html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : '';
547
+			if ($this->request->isAjax()) {
548
+				$this->reg_form->localize_validation_rules();
549
+				$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
550
+			}
551
+			$html .= $this->reg_form->get_html();
552
+			$html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : '';
553
+			$html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : '';
554
+		}
555
+		return $html;
556
+	}
557
+
558
+
559
+	/**
560
+	 * div_class - returns nothing for current step, but a css class of "hidden" for others
561
+	 *
562
+	 * @return string
563
+	 * @throws EE_Error
564
+	 */
565
+	public function reg_step_submit_button()
566
+	{
567
+		if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
568
+			return '';
569
+		}
570
+		ob_start();
571
+		do_action(
572
+			'AHEE__before_spco_whats_next_buttons',
573
+			$this->slug(),
574
+			$this->checkout->next_step->slug(),
575
+			$this->checkout
576
+		);
577
+		$html = ob_get_clean();
578
+		// generate submit button
579
+		$submit_btn = new EE_Submit_Input(
580
+			[
581
+				'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
582
+				'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
583
+				'html_class'            => 'spco-next-step-btn',
584
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
585
+				'default'               => $this->submit_button_text(),
586
+			]
587
+		);
588
+		$submit_btn->set_button_css_attributes(true, 'large');
589
+		$submit_btn_html = $submit_btn->get_html_for_input();
590
+		$html            .= EEH_HTML::div(
591
+			apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this),
592
+			'spco-' . $this->slug() . '-whats-next-buttons-dv',
593
+			'spco-whats-next-buttons'
594
+		);
595
+		return $html;
596
+	}
597
+
598
+
599
+	/**
600
+	 * div_class - returns nothing for current step, but a css class of "hidden" for others
601
+	 *
602
+	 * @return string
603
+	 */
604
+	public function div_class()
605
+	{
606
+		return $this->is_current_step() ? '' : ' hidden';
607
+	}
608
+
609
+
610
+	/**
611
+	 * div_class - returns  a css class of "hidden" for current step, but nothing for others
612
+	 *
613
+	 * @return string
614
+	 */
615
+	public function edit_lnk_url()
616
+	{
617
+		return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url);
618
+	}
619
+
620
+
621
+	/**
622
+	 * div_class - returns  a css class of "hidden" for current step, but nothing for others
623
+	 *
624
+	 * @return string
625
+	 */
626
+	public function edit_link_class()
627
+	{
628
+		return $this->is_current_step() ? ' hidden' : '';
629
+	}
630
+
631
+
632
+	/**
633
+	 * update_checkout with changes that have been made to the cart
634
+	 *
635
+	 * @return void
636
+	 * @throws EE_Error
637
+	 * @throws ReflectionException
638
+	 */
639
+	public function update_checkout()
640
+	{
641
+		// grab the cart grand total and reset TXN total
642
+		$this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total());
643
+		$this->checkout->stash_transaction_and_checkout();
644
+	}
645
+
646
+
647
+	/**
648
+	 *    __sleep
649
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
650
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
651
+	 * reg form, because if needed, it will be regenerated anyways
652
+	 *
653
+	 * @return array
654
+	 */
655
+	public function __sleep()
656
+	{
657
+		// remove the reg form and the checkout
658
+		return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']);
659
+	}
660
+
661
+
662
+	/**
663
+	 * @param RequestInterface $request
664
+	 */
665
+	public function setRequest(RequestInterface $request)
666
+	{
667
+		$this->request = $request;
668
+	}
669 669
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      */
228 228
     public function set_submit_button_text($submit_button_text = '')
229 229
     {
230
-        if (! empty($submit_button_text)) {
230
+        if ( ! empty($submit_button_text)) {
231 231
             $this->_submit_button_text = $submit_button_text;
232 232
         } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
233 233
             if ($this->checkout->revisit) {
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
     public function reg_form_name()
397 397
     {
398 398
         if (empty($this->_reg_form_name)) {
399
-            $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
399
+            $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form');
400 400
         }
401 401
         return $this->_reg_form_name;
402 402
     }
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
     public function reg_step_url($action = '')
421 421
     {
422 422
         $query_args = ['step' => $this->slug()];
423
-        if (! empty($action)) {
423
+        if ( ! empty($action)) {
424 424
             $query_args['action'] = $action;
425 425
         }
426 426
         // final step has no display
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
             return new EE_Form_Section_Proper(
451 451
                 [
452 452
                     'layout_strategy' => new EE_No_Layout(),
453
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
453
+                    'html_id'         => 'ee-'.$this->slug().'-hidden-inputs',
454 454
                     'subsections'     => [
455 455
                         'next_step' => new EE_Fixed_Hidden_Input(
456 456
                             [
457 457
                                 'html_name' => 'next_step',
458
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
458
+                                'html_id'   => 'spco-'.$this->slug().'-next-step',
459 459
                                 'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
460 460
                                     ? $this->checkout->next_step->slug()
461 461
                                     : '',
@@ -469,12 +469,12 @@  discard block
 block discarded – undo
469 469
         return new EE_Form_Section_Proper(
470 470
             [
471 471
                 'layout_strategy' => new EE_No_Layout(),
472
-                'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
472
+                'html_id'         => 'ee-'.$this->slug().'-hidden-inputs',
473 473
                 'subsections'     => [
474 474
                     'action'         => new EE_Fixed_Hidden_Input(
475 475
                         [
476 476
                             'html_name' => 'action',
477
-                            'html_id'   => 'spco-' . $this->slug() . '-action',
477
+                            'html_id'   => 'spco-'.$this->slug().'-action',
478 478
                             'default'   => apply_filters(
479 479
                                 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
480 480
                                 empty($this->checkout->reg_url_link)
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
                     'next_step'      => new EE_Fixed_Hidden_Input(
488 488
                         [
489 489
                             'html_name' => 'next_step',
490
-                            'html_id'   => 'spco-' . $this->slug() . '-next-step',
490
+                            'html_id'   => 'spco-'.$this->slug().'-next-step',
491 491
                             'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
492 492
                                 ? $this->checkout->next_step->slug()
493 493
                                 : '',
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
      */
522 522
     public function generate_reg_form_for_actions($actions = [])
523 523
     {
524
-        $actions                           = array_merge(
524
+        $actions = array_merge(
525 525
             [
526 526
                 'generate_reg_form',
527 527
                 'display_spco_reg_step',
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
      */
565 565
     public function reg_step_submit_button()
566 566
     {
567
-        if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
567
+        if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
568 568
             return '';
569 569
         }
570 570
         ob_start();
@@ -578,18 +578,18 @@  discard block
 block discarded – undo
578 578
         // generate submit button
579 579
         $submit_btn = new EE_Submit_Input(
580 580
             [
581
-                'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
582
-                'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
581
+                'html_name'             => 'spco-go-to-step-'.$this->checkout->next_step->slug(),
582
+                'html_id'               => 'spco-go-to-step-'.$this->checkout->next_step->slug(),
583 583
                 'html_class'            => 'spco-next-step-btn',
584
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
584
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
585 585
                 'default'               => $this->submit_button_text(),
586 586
             ]
587 587
         );
588 588
         $submit_btn->set_button_css_attributes(true, 'large');
589 589
         $submit_btn_html = $submit_btn->get_html_for_input();
590
-        $html            .= EEH_HTML::div(
590
+        $html .= EEH_HTML::div(
591 591
             apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this),
592
-            'spco-' . $this->slug() . '-whats-next-buttons-dv',
592
+            'spco-'.$this->slug().'-whats-next-buttons-dv',
593 593
             'spco-whats-next-buttons'
594 594
         );
595 595
         return $html;
Please login to merge, or discard this patch.
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 1 patch
Indentation   +858 added lines, -858 removed lines patch added patch discarded remove patch
@@ -23,862 +23,862 @@
 block discarded – undo
23 23
  */
24 24
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step
25 25
 {
26
-    /**
27
-     * @var RegForm
28
-     */
29
-    public $reg_form;
30
-
31
-    /**
32
-     * @var int
33
-     */
34
-    protected $reg_form_count = 0;
35
-
36
-
37
-    /**
38
-     *    class constructor
39
-     *
40
-     * @access    public
41
-     * @param EE_Checkout $checkout
42
-     */
43
-    public function __construct(EE_Checkout $checkout)
44
-    {
45
-        $this->_slug    = 'attendee_information';
46
-        $this->_name    = esc_html__('Attendee Information', 'event_espresso');
47
-        $this->checkout = $checkout;
48
-        $this->_reset_success_message();
49
-        $this->set_instructions(
50
-            esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
51
-        );
52
-    }
53
-
54
-
55
-    public function translate_js_strings()
56
-    {
57
-        EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
58
-            ' is a required question.',
59
-            'event_espresso'
60
-        );
61
-        EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
62
-            ' is a required question. Please enter a value for at least one of the options.',
63
-            'event_espresso'
64
-        );
65
-        EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
66
-            'Please answer all required questions correctly before proceeding.',
67
-            'event_espresso'
68
-        );
69
-        EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
70
-            esc_html_x(
71
-                'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
72
-                'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
73
-                'event_espresso'
74
-            ),
75
-            '<br/>'
76
-        );
77
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
78
-            'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
79
-            'event_espresso'
80
-        );
81
-        EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
82
-            'You must enter a valid email address.',
83
-            'event_espresso'
84
-        );
85
-        EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
86
-            'You must enter a valid email address and answer all other required questions before you can proceed.',
87
-            'event_espresso'
88
-        );
89
-    }
90
-
91
-
92
-    public function enqueue_styles_and_scripts()
93
-    {
94
-    }
95
-
96
-
97
-    /**
98
-     * @return boolean
99
-     */
100
-    public function initialize_reg_step(): bool
101
-    {
102
-        return true;
103
-    }
104
-
105
-
106
-    /**
107
-     * @return RegForm
108
-     * @throws DomainException
109
-     * @throws InvalidArgumentException
110
-     * @throws EntityNotFoundException
111
-     * @throws InvalidDataTypeException
112
-     * @throws InvalidInterfaceException
113
-     */
114
-    public function generate_reg_form(): RegForm
115
-    {
116
-        $this->setLegacyFiltersForRegFormGeneration();
117
-        /** @var RegFormDependencyHandler $dependency_handler */
118
-        $dependency_handler = LoaderFactory::getShared(RegFormDependencyHandler::class);
119
-        $dependency_handler->registerDependencies();
120
-        // TODO detect if event has a reg form UUID and swap this out for form generated by new reg form builder
121
-        return LoaderFactory::getShared(RegForm::class, [$this]);
122
-    }
123
-
124
-
125
-    /**
126
-     * @since   5.0.0.p
127
-     */
128
-    private function setLegacyFiltersForRegFormGeneration()
129
-    {
130
-        add_filter(
131
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantForm__generateFormArgs__question_groups_query_parameters',
132
-            [$this, 'registrationQuestionGroupsQueryParameters'],
133
-            1,
134
-            2
135
-        );
136
-        add_filter(
137
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantForm__generateFormArgs__question_group_reg_form',
138
-            [$this, 'registrationQuestionGroupsRegForm'],
139
-            1,
140
-            3
141
-        );
142
-        add_filter(
143
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantForm__generateFormArgs__printCopyInfo',
144
-            [$this, 'registrationRegFormPrintCopyInfo'],
145
-            1,
146
-            2
147
-        );
148
-        add_filter(
149
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__related_questions_query_params',
150
-            [$this, 'registrationRegFormRelatedQuestionsQueryParams'],
151
-            1,
152
-            3
153
-        );
154
-        add_filter(
155
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__before_question_group_questions',
156
-            [$this, 'registrationRegFormBeforeQuestionGroupQuestions'],
157
-            1,
158
-            3
159
-        );
160
-        add_filter(
161
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__subsections_array',
162
-            [$this, 'registrationRegFormSubsections'],
163
-            1,
164
-            3
165
-        );
166
-        add_filter(
167
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__after_question_group_questions',
168
-            [$this, 'registrationRegFormAfterQuestionGroupQuestions'],
169
-            1,
170
-            3
171
-        );
172
-        add_filter(
173
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_AutoCopyAttendeeInfoForm__construct__template_args',
174
-            [$this, 'autoCopyAttendeeInfoTemplateArgs'],
175
-            1
176
-        );
177
-        add_filter(
178
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_CountryOptions__generateLegacyCountryOptions__country_options',
179
-            [$this, 'generateQuestionInputCountryOptions'],
180
-            1,
181
-            4
182
-        );
183
-        add_filter(
184
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_StateOptions__generateLegacyStateOptions__state_options',
185
-            [$this, 'generateQuestionInputStateOptions'],
186
-            1,
187
-            4
188
-        );
189
-    }
190
-
191
-
192
-    /**
193
-     * @param array           $query_params
194
-     * @param EE_Registration $registration
195
-     * @return mixed|void
196
-     * @since   5.0.0.p
197
-     */
198
-    public function registrationQuestionGroupsQueryParameters(
199
-        array $query_params,
200
-        EE_Registration $registration
201
-    ) {
202
-        return apply_filters(
203
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
204
-            $query_params,
205
-            $registration,
206
-            $this
207
-        );
208
-    }
209
-
210
-
211
-    /**
212
-     * @param RegFormQuestions  $question_group_reg_form
213
-     * @param EE_Registration   $registration
214
-     * @param EE_Question_Group $question_group
215
-     * @return EE_Form_Section_Proper
216
-     * @since   5.0.0.p
217
-     */
218
-    public function registrationQuestionGroupsRegForm(
219
-        RegFormQuestions $question_group_reg_form,
220
-        EE_Registration $registration,
221
-        EE_Question_Group $question_group
222
-    ): EE_Form_Section_Proper {
223
-        return apply_filters(
224
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
225
-            $question_group_reg_form,
226
-            $registration,
227
-            $question_group,
228
-            $this
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * @param int $print_copy_info
235
-     * @param int $attendee_nmbr
236
-     * @return mixed|void
237
-     * @since   5.0.0.p
238
-     */
239
-    public function registrationRegFormPrintCopyInfo(
240
-        int $print_copy_info,
241
-        int $attendee_nmbr
242
-    ) {
243
-        return apply_filters(
244
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
245
-            $print_copy_info,
246
-            $attendee_nmbr
247
-        );
248
-    }
249
-
250
-
251
-    /**
252
-     * @param array             $query_params
253
-     * @param EE_Question_Group $question_group
254
-     * @param EE_Registration   $registration
255
-     * @return mixed|void
256
-     * @since   5.0.0.p
257
-     */
258
-    public function registrationRegFormRelatedQuestionsQueryParams(
259
-        array $query_params,
260
-        EE_Question_Group $question_group,
261
-        EE_Registration $registration
262
-    ) {
263
-        return apply_filters(
264
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
265
-            $query_params,
266
-            $question_group,
267
-            $registration,
268
-            $this
269
-        );
270
-    }
271
-
272
-
273
-    /**
274
-     * @param                   $html
275
-     * @param EE_Registration   $registration
276
-     * @param EE_Question_Group $question_group
277
-     * @return mixed|void
278
-     * @since   5.0.0.p
279
-     */
280
-    public function registrationRegFormBeforeQuestionGroupQuestions(
281
-        $html,
282
-        EE_Registration $registration,
283
-        EE_Question_Group $question_group
284
-    ) {
285
-        return apply_filters(
286
-            'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
287
-            $html,
288
-            $registration,
289
-            $question_group,
290
-            $this
291
-        );
292
-    }
293
-
294
-
295
-    /**
296
-     * @param array             $form_subsections
297
-     * @param EE_Registration   $registration
298
-     * @param EE_Question_Group $question_group
299
-     * @return mixed|void
300
-     * @since   5.0.0.p
301
-     */
302
-    public function registrationRegFormSubsections(
303
-        array $form_subsections,
304
-        EE_Registration $registration,
305
-        EE_Question_Group $question_group
306
-    ) {
307
-        return apply_filters(
308
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
309
-            $form_subsections,
310
-            $registration,
311
-            $question_group,
312
-            $this
313
-        );
314
-    }
315
-
316
-
317
-    /**
318
-     * @param                   $html
319
-     * @param EE_Registration   $registration
320
-     * @param EE_Question_Group $question_group
321
-     * @return mixed|void
322
-     * @since   5.0.0.p
323
-     */
324
-    public function registrationRegFormAfterQuestionGroupQuestions(
325
-        $html,
326
-        EE_Registration $registration,
327
-        EE_Question_Group $question_group
328
-    ) {
329
-        return apply_filters(
330
-            'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
331
-            $html,
332
-            $registration,
333
-            $question_group,
334
-            $this
335
-        );
336
-    }
337
-
338
-
339
-    /**
340
-     * @param array $template_args
341
-     * @return mixed|void
342
-     * @since   5.0.0.p
343
-     */
344
-    public function autoCopyAttendeeInfoTemplateArgs(array $template_args = [])
345
-    {
346
-        return apply_filters(
347
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
348
-            $template_args
349
-        );
350
-    }
351
-
352
-
353
-    /**
354
-     * @param array           $country_options
355
-     * @param EE_Registration $registration
356
-     * @param EE_Question     $question
357
-     * @param EE_Answer|null  $answer
358
-     * @return mixed|void
359
-     * @since   5.0.0.p
360
-     */
361
-    public function generateQuestionInputCountryOptions(
362
-        array $country_options,
363
-        EE_Registration $registration,
364
-        EE_Question $question,
365
-        ?EE_Answer $answer
366
-    ) {
367
-        return apply_filters(
368
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
369
-            $country_options,
370
-            $this,
371
-            $registration,
372
-            $question,
373
-            $answer
374
-        );
375
-    }
376
-
377
-
378
-    /**
379
-     * @param array           $state_options
380
-     * @param EE_Registration $registration
381
-     * @param EE_Question     $question
382
-     * @param EE_Answer|null  $answer
383
-     * @return mixed|void
384
-     * @since   5.0.0.p
385
-     */
386
-    public function generateQuestionInputStateOptions(
387
-        array $state_options,
388
-        EE_Registration $registration,
389
-        EE_Question $question,
390
-        ?EE_Answer $answer
391
-    ) {
392
-        return apply_filters(
393
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
394
-            $state_options,
395
-            $this,
396
-            $registration,
397
-            $question,
398
-            $answer
399
-        );
400
-    }
401
-
402
-
403
-    /**
404
-     * looking for hooks?
405
-     * this method has been replaced by:
406
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::getRegForm()
407
-     *
408
-     * @deprecated   5.0.0.p
409
-     */
410
-    private function _registrations_reg_form()
411
-    {
412
-    }
413
-
414
-
415
-    /**
416
-     * looking for hooks?
417
-     * this method has been replaced by:
418
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalAttendeeRegInfoInput()
419
-     *
420
-     * @deprecated   5.0.0.p
421
-     */
422
-    private function _additional_attendee_reg_info_input()
423
-    {
424
-    }
425
-
426
-
427
-    /**
428
-     * looking for hooks?
429
-     * this method has been replaced by:
430
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupRegForm()
431
-     *
432
-     * @deprecated   5.0.0.p
433
-     */
434
-    private function _question_group_reg_form()
435
-    {
436
-    }
437
-
438
-
439
-    /**
440
-     * looking for hooks?
441
-     * this method has been replaced by:
442
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupHeader()
443
-     *
444
-     * @deprecated   5.0.0.p
445
-     */
446
-    private function _question_group_header()
447
-    {
448
-    }
449
-
450
-
451
-    /**
452
-     * looking for hooks?
453
-     * this method has been replaced by:
454
-     * EventEspresso\core\domain\services\registration\form\v1\subsections\CopyAttendeeInfoForm
455
-     *
456
-     * @deprecated   5.0.0.p
457
-     */
458
-    private function _copy_attendee_info_form()
459
-    {
460
-    }
461
-
462
-
463
-    /**
464
-     * looking for hooks?
465
-     * this method has been replaced by:
466
-     * EventEspresso\core\domain\services\registration\form\v1\subsections\AutoCopyAttendeeInfoForm
467
-     *
468
-     * @deprecated   5.0.0.p
469
-     */
470
-    private function _auto_copy_attendee_info()
471
-    {
472
-    }
473
-
474
-
475
-    /**
476
-     * looking for hooks?
477
-     * this method has been replaced by:
478
-     * EventEspresso\core\domain\services\registration\form\v1\subsections\CopyAttendeeInfoForm
479
-     *
480
-     * @deprecated   5.0.0.p
481
-     */
482
-    private function _copy_attendee_info_inputs()
483
-    {
484
-    }
485
-
486
-
487
-    /**
488
-     * looking for hooks?
489
-     * this method has been replaced by:
490
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalPrimaryRegistrantInputs()
491
-     *
492
-     * @deprecated   5.0.0.p
493
-     */
494
-    private function _additional_primary_registrant_inputs()
495
-    {
496
-    }
497
-
498
-
499
-    /**
500
-     * looking for hooks?
501
-     * this method has been replaced by:
502
-     * EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory::create()
503
-     *
504
-     * @param EE_Registration $registration
505
-     * @param EE_Question     $question
506
-     * @return EE_Form_Input_Base
507
-     * @throws EE_Error
508
-     * @throws ReflectionException
509
-     * @deprecated   5.0.0.p
510
-     */
511
-    public function reg_form_question(EE_Registration $registration, EE_Question $question): EE_Form_Input_Base
512
-    {
513
-        /** @var RegFormQuestionFactory $reg_form_question_factory */
514
-        $reg_form_question_factory = LoaderFactory::getShared(RegFormQuestionFactory::class);
515
-        return $reg_form_question_factory->create($registration, $question);
516
-    }
517
-
518
-
519
-    /**
520
-     * looking for hooks?
521
-     * this method has been replaced by:
522
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::generateQuestionInput()
523
-     *
524
-     * @deprecated   5.0.0.p
525
-     */
526
-    private function _generate_question_input()
527
-    {
528
-    }
529
-
530
-
531
-    /**
532
-     * looking for hooks?
533
-     * this method has been replaced by:
534
-     * EventEspresso\core\domain\services\registration\form\utilities\CountryOptions::forLegacyFormInput()
535
-     *
536
-     * @param array|null           $countries_list
537
-     * @param EE_Question|null     $question
538
-     * @param EE_Registration|null $registration
539
-     * @param EE_Answer|null       $answer
540
-     * @return array 2d keys are country IDs, values are their names
541
-     * @throws EE_Error
542
-     * @throws ReflectionException
543
-     * @deprecated   5.0.0.p
544
-     */
545
-    public function use_cached_countries_for_form_input(
546
-        array $countries_list = null,
547
-        EE_Question $question = null,
548
-        EE_Registration $registration = null,
549
-        EE_Answer $answer = null
550
-    ): array {
551
-        /** @var CountryOptions $country_options */
552
-        $country_options = LoaderFactory::getShared(CountryOptions::class, [$this->checkout->action]);
553
-        return $country_options->forLegacyFormInput($countries_list, $question, $registration, $answer);
554
-    }
555
-
556
-
557
-    /**
558
-     * looking for hooks?
559
-     * this method has been replaced by:
560
-     * EventEspresso\core\domain\services\registration\form\utilities\StateOptions::forLegacyFormInput()
561
-     *
562
-     * @param array|null           $states_list
563
-     * @param EE_Question|null     $question
564
-     * @param EE_Registration|null $registration
565
-     * @param EE_Answer|null       $answer
566
-     * @return array 2d keys are state IDs, values are their names
567
-     * @throws EE_Error
568
-     * @throws ReflectionException
569
-     * @deprecated   5.0.0.p
570
-     */
571
-    public function use_cached_states_for_form_input(
572
-        array $states_list = null,
573
-        EE_Question $question = null,
574
-        EE_Registration $registration = null,
575
-        EE_Answer $answer = null
576
-    ): array {
577
-        /** @var StateOptions $state_options */
578
-        $state_options = LoaderFactory::getShared(StateOptions::class, [$this->checkout->action]);
579
-        return $state_options->forLegacyFormInput($states_list, $question, $registration, $answer);
580
-    }
581
-
582
-
583
-    /********************************************************************************************************/
584
-    /****************************************  PROCESS REG STEP  ****************************************/
585
-    /********************************************************************************************************/
586
-
587
-
588
-    /**
589
-     * @return bool
590
-     * @throws EE_Error
591
-     * @throws InvalidArgumentException
592
-     * @throws ReflectionException
593
-     * @throws RuntimeException
594
-     * @throws InvalidDataTypeException
595
-     * @throws InvalidInterfaceException
596
-     */
597
-    public function process_reg_step(): bool
598
-    {
599
-        $this->setLegacyFiltersForRegFormProcessing();
600
-        // grab validated data from form
601
-        $valid_data = $this->checkout->current_step->valid_data();
602
-        // if we don't have any $valid_data then something went TERRIBLY WRONG !!!
603
-        if (empty($valid_data)) {
604
-            return $this->inValidDataError();
605
-        }
606
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
607
-            return $this->inValidTransactionError();
608
-        }
609
-        // get cached registrations
610
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
611
-        // verify we got the goods
612
-        if (empty($registrations)) {
613
-            return $this->noRegistrationsError();
614
-        }
615
-        /** @var RegFormHandler $reg_form_handler */
616
-        $reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]);
617
-        // extract attendee info from form data and save to model objects
618
-        if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) {
619
-            // return immediately if the previous step exited early due to errors
620
-            return false;
621
-        }
622
-        // if first pass thru SPCO,
623
-        // then let's check processed registrations against the total number of tickets in the cart
624
-        $registrations_processed = $reg_form_handler->attendeeCount();
625
-        if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
626
-            return $this->registrationProcessingError($registrations_processed);
627
-        }
628
-        // mark this reg step as completed
629
-        $this->set_completed();
630
-        $this->_set_success_message(
631
-            esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
632
-        );
633
-        // do action in case a plugin wants to do something with the data submitted in step 1.
634
-        // passes EE_Single_Page_Checkout, and it's posted data
635
-        do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
636
-        return true;
637
-    }
638
-
639
-
640
-    /**
641
-     * @since   5.0.0.p
642
-     */
643
-    private function setLegacyFiltersForRegFormProcessing()
644
-    {
645
-        add_filter(
646
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegistrations__bypass',
647
-            [$this, 'preRegistrationProcess'],
648
-            1,
649
-            5
650
-        );
651
-        add_filter(
652
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegFormData__registrant_form_data',
653
-            [$this, 'validDataLineItem'],
654
-            1,
655
-            2
656
-        );
657
-        add_filter(
658
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormInputHandler__saveRegistrationFormInput',
659
-            [$this, 'saveRegistrationFormInput'],
660
-            1,
661
-            4
662
-        );
663
-        add_filter(
664
-            'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantData__ensureCriticalRegistrantDataIsSet',
665
-            [$this, 'mergeAddressDetailsWithCriticalAttendeeDetails'],
666
-            1
667
-        );
668
-    }
669
-
670
-
671
-    /**
672
-     * @param bool            $bypass
673
-     * @param int             $attendee_count
674
-     * @param EE_Registration $registration
675
-     * @param array           $registrations
676
-     * @param array           $reg_form_data
677
-     * @return mixed|void
678
-     * @since   5.0.0.p
679
-     */
680
-    public function preRegistrationProcess(
681
-        bool $bypass,
682
-        int $attendee_count,
683
-        EE_Registration $registration,
684
-        array $registrations,
685
-        array $reg_form_data
686
-    ) {
687
-        return apply_filters(
688
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
689
-            $bypass,
690
-            $attendee_count,
691
-            $registration,
692
-            $registrations,
693
-            $reg_form_data,
694
-            $this
695
-        );
696
-    }
697
-
698
-
699
-    /**
700
-     * @param array           $reg_form_data
701
-     * @param EE_Registration $registration
702
-     * @return mixed|void
703
-     * @since   5.0.0.p
704
-     */
705
-    public function validDataLineItem(array $reg_form_data, EE_Registration $registration)
706
-    {
707
-        return apply_filters(
708
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
709
-            $reg_form_data,
710
-            $registration
711
-        );
712
-    }
713
-
714
-
715
-    /**
716
-     * @param bool            $save
717
-     * @param EE_Registration $registration
718
-     * @param                 $form_input
719
-     * @param                 $input_value
720
-     * @return mixed|void
721
-     * @since   5.0.0.p
722
-     */
723
-    public function saveRegistrationFormInput(bool $save, EE_Registration $registration, $form_input, $input_value)
724
-    {
725
-        return apply_filters(
726
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
727
-            $save,
728
-            $registration,
729
-            $form_input,
730
-            $input_value,
731
-            $this
732
-        );
733
-    }
734
-
735
-
736
-    /**
737
-     * @param bool $merge_data
738
-     * @return mixed|void
739
-     * @since   5.0.0.p
740
-     */
741
-    public function mergeAddressDetailsWithCriticalAttendeeDetails(bool $merge_data)
742
-    {
743
-        return apply_filters(
744
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
745
-            $merge_data
746
-        );
747
-    }
748
-
749
-
750
-    /**
751
-     * @return bool
752
-     * @since   5.0.0.p
753
-     */
754
-    private function inValidDataError(): bool
755
-    {
756
-        EE_Error::add_error(
757
-            esc_html__('No valid question responses were received.', 'event_espresso'),
758
-            __FILE__,
759
-            __FUNCTION__,
760
-            __LINE__
761
-        );
762
-        return false;
763
-    }
764
-
765
-
766
-    /**
767
-     * @return bool
768
-     * @since   5.0.0.p
769
-     */
770
-    private function inValidTransactionError(): bool
771
-    {
772
-        EE_Error::add_error(
773
-            esc_html__(
774
-                'A valid transaction could not be initiated for processing your registrations.',
775
-                'event_espresso'
776
-            ),
777
-            __FILE__,
778
-            __FUNCTION__,
779
-            __LINE__
780
-        );
781
-        return false;
782
-    }
783
-
784
-
785
-    /**
786
-     * @return bool
787
-     * @since   5.0.0.p
788
-     */
789
-    private function noRegistrationsError(): bool
790
-    {
791
-        // combine the old translated string with a new one, in order to not break translations
792
-        $error_message = esc_html__(
793
-            'Your form data could not be applied to any valid registrations.',
794
-            'event_espresso'
795
-        );
796
-        $error_message .= sprintf(
797
-            esc_html_x(
798
-                '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
799
-                '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
800
-                'event_espresso'
801
-            ),
802
-            '<a href="' . get_post_type_archive_link(EspressoPostType::EVENTS) . '" >',
803
-            '</a>',
804
-            '<br />'
805
-        );
806
-        EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__);
807
-        return false;
808
-    }
809
-
810
-
811
-    /**
812
-     * @param int $registrations_processed
813
-     * @return bool
814
-     * @since   5.0.0.p
815
-     */
816
-    private function registrationProcessingError(int $registrations_processed): bool
817
-    {
818
-        // generate a correctly translated string for all possible singular/plural combinations
819
-        if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
820
-            $error_msg = sprintf(
821
-                esc_html_x(
822
-                    'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
823
-                    'There was 1 ticket in the Event Queue, but 2 registrations were processed',
824
-                    'event_espresso'
825
-                ),
826
-                $this->checkout->total_ticket_count,
827
-                $registrations_processed
828
-            );
829
-        } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
830
-            $error_msg = sprintf(
831
-                esc_html_x(
832
-                    'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
833
-                    'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
834
-                    'event_espresso'
835
-                ),
836
-                $this->checkout->total_ticket_count,
837
-                $registrations_processed
838
-            );
839
-        } else {
840
-            $error_msg = sprintf(
841
-                esc_html__(
842
-                    'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
843
-                    'event_espresso'
844
-                ),
845
-                $this->checkout->total_ticket_count,
846
-                $registrations_processed
847
-            );
848
-        }
849
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
850
-        return false;
851
-    }
852
-
853
-
854
-    /**
855
-     *    update_reg_step
856
-     *    this is the final step after a user  revisits the site to edit their attendee information
857
-     *    this gets called AFTER the process_reg_step() method above
858
-     *
859
-     * @return bool
860
-     * @throws EE_Error
861
-     * @throws InvalidArgumentException
862
-     * @throws ReflectionException
863
-     * @throws RuntimeException
864
-     * @throws InvalidDataTypeException
865
-     * @throws InvalidInterfaceException
866
-     */
867
-    public function update_reg_step(): bool
868
-    {
869
-        // save everything
870
-        if ($this->process_reg_step()) {
871
-            $this->checkout->redirect     = true;
872
-            $this->checkout->redirect_url = add_query_arg(
873
-                [
874
-                    'e_reg_url_link' => $this->checkout->reg_url_link,
875
-                    'revisit'        => true,
876
-                ],
877
-                $this->checkout->thank_you_page_url
878
-            );
879
-            $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
880
-            return true;
881
-        }
882
-        return false;
883
-    }
26
+	/**
27
+	 * @var RegForm
28
+	 */
29
+	public $reg_form;
30
+
31
+	/**
32
+	 * @var int
33
+	 */
34
+	protected $reg_form_count = 0;
35
+
36
+
37
+	/**
38
+	 *    class constructor
39
+	 *
40
+	 * @access    public
41
+	 * @param EE_Checkout $checkout
42
+	 */
43
+	public function __construct(EE_Checkout $checkout)
44
+	{
45
+		$this->_slug    = 'attendee_information';
46
+		$this->_name    = esc_html__('Attendee Information', 'event_espresso');
47
+		$this->checkout = $checkout;
48
+		$this->_reset_success_message();
49
+		$this->set_instructions(
50
+			esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
51
+		);
52
+	}
53
+
54
+
55
+	public function translate_js_strings()
56
+	{
57
+		EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
58
+			' is a required question.',
59
+			'event_espresso'
60
+		);
61
+		EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
62
+			' is a required question. Please enter a value for at least one of the options.',
63
+			'event_espresso'
64
+		);
65
+		EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
66
+			'Please answer all required questions correctly before proceeding.',
67
+			'event_espresso'
68
+		);
69
+		EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
70
+			esc_html_x(
71
+				'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
72
+				'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
73
+				'event_espresso'
74
+			),
75
+			'<br/>'
76
+		);
77
+		EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
78
+			'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
79
+			'event_espresso'
80
+		);
81
+		EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
82
+			'You must enter a valid email address.',
83
+			'event_espresso'
84
+		);
85
+		EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
86
+			'You must enter a valid email address and answer all other required questions before you can proceed.',
87
+			'event_espresso'
88
+		);
89
+	}
90
+
91
+
92
+	public function enqueue_styles_and_scripts()
93
+	{
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return boolean
99
+	 */
100
+	public function initialize_reg_step(): bool
101
+	{
102
+		return true;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return RegForm
108
+	 * @throws DomainException
109
+	 * @throws InvalidArgumentException
110
+	 * @throws EntityNotFoundException
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws InvalidInterfaceException
113
+	 */
114
+	public function generate_reg_form(): RegForm
115
+	{
116
+		$this->setLegacyFiltersForRegFormGeneration();
117
+		/** @var RegFormDependencyHandler $dependency_handler */
118
+		$dependency_handler = LoaderFactory::getShared(RegFormDependencyHandler::class);
119
+		$dependency_handler->registerDependencies();
120
+		// TODO detect if event has a reg form UUID and swap this out for form generated by new reg form builder
121
+		return LoaderFactory::getShared(RegForm::class, [$this]);
122
+	}
123
+
124
+
125
+	/**
126
+	 * @since   5.0.0.p
127
+	 */
128
+	private function setLegacyFiltersForRegFormGeneration()
129
+	{
130
+		add_filter(
131
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantForm__generateFormArgs__question_groups_query_parameters',
132
+			[$this, 'registrationQuestionGroupsQueryParameters'],
133
+			1,
134
+			2
135
+		);
136
+		add_filter(
137
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantForm__generateFormArgs__question_group_reg_form',
138
+			[$this, 'registrationQuestionGroupsRegForm'],
139
+			1,
140
+			3
141
+		);
142
+		add_filter(
143
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantForm__generateFormArgs__printCopyInfo',
144
+			[$this, 'registrationRegFormPrintCopyInfo'],
145
+			1,
146
+			2
147
+		);
148
+		add_filter(
149
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__related_questions_query_params',
150
+			[$this, 'registrationRegFormRelatedQuestionsQueryParams'],
151
+			1,
152
+			3
153
+		);
154
+		add_filter(
155
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__before_question_group_questions',
156
+			[$this, 'registrationRegFormBeforeQuestionGroupQuestions'],
157
+			1,
158
+			3
159
+		);
160
+		add_filter(
161
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__subsections_array',
162
+			[$this, 'registrationRegFormSubsections'],
163
+			1,
164
+			3
165
+		);
166
+		add_filter(
167
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormQuestionGroup__generateFormArgs__after_question_group_questions',
168
+			[$this, 'registrationRegFormAfterQuestionGroupQuestions'],
169
+			1,
170
+			3
171
+		);
172
+		add_filter(
173
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_AutoCopyAttendeeInfoForm__construct__template_args',
174
+			[$this, 'autoCopyAttendeeInfoTemplateArgs'],
175
+			1
176
+		);
177
+		add_filter(
178
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_CountryOptions__generateLegacyCountryOptions__country_options',
179
+			[$this, 'generateQuestionInputCountryOptions'],
180
+			1,
181
+			4
182
+		);
183
+		add_filter(
184
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_StateOptions__generateLegacyStateOptions__state_options',
185
+			[$this, 'generateQuestionInputStateOptions'],
186
+			1,
187
+			4
188
+		);
189
+	}
190
+
191
+
192
+	/**
193
+	 * @param array           $query_params
194
+	 * @param EE_Registration $registration
195
+	 * @return mixed|void
196
+	 * @since   5.0.0.p
197
+	 */
198
+	public function registrationQuestionGroupsQueryParameters(
199
+		array $query_params,
200
+		EE_Registration $registration
201
+	) {
202
+		return apply_filters(
203
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
204
+			$query_params,
205
+			$registration,
206
+			$this
207
+		);
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param RegFormQuestions  $question_group_reg_form
213
+	 * @param EE_Registration   $registration
214
+	 * @param EE_Question_Group $question_group
215
+	 * @return EE_Form_Section_Proper
216
+	 * @since   5.0.0.p
217
+	 */
218
+	public function registrationQuestionGroupsRegForm(
219
+		RegFormQuestions $question_group_reg_form,
220
+		EE_Registration $registration,
221
+		EE_Question_Group $question_group
222
+	): EE_Form_Section_Proper {
223
+		return apply_filters(
224
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
225
+			$question_group_reg_form,
226
+			$registration,
227
+			$question_group,
228
+			$this
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * @param int $print_copy_info
235
+	 * @param int $attendee_nmbr
236
+	 * @return mixed|void
237
+	 * @since   5.0.0.p
238
+	 */
239
+	public function registrationRegFormPrintCopyInfo(
240
+		int $print_copy_info,
241
+		int $attendee_nmbr
242
+	) {
243
+		return apply_filters(
244
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
245
+			$print_copy_info,
246
+			$attendee_nmbr
247
+		);
248
+	}
249
+
250
+
251
+	/**
252
+	 * @param array             $query_params
253
+	 * @param EE_Question_Group $question_group
254
+	 * @param EE_Registration   $registration
255
+	 * @return mixed|void
256
+	 * @since   5.0.0.p
257
+	 */
258
+	public function registrationRegFormRelatedQuestionsQueryParams(
259
+		array $query_params,
260
+		EE_Question_Group $question_group,
261
+		EE_Registration $registration
262
+	) {
263
+		return apply_filters(
264
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
265
+			$query_params,
266
+			$question_group,
267
+			$registration,
268
+			$this
269
+		);
270
+	}
271
+
272
+
273
+	/**
274
+	 * @param                   $html
275
+	 * @param EE_Registration   $registration
276
+	 * @param EE_Question_Group $question_group
277
+	 * @return mixed|void
278
+	 * @since   5.0.0.p
279
+	 */
280
+	public function registrationRegFormBeforeQuestionGroupQuestions(
281
+		$html,
282
+		EE_Registration $registration,
283
+		EE_Question_Group $question_group
284
+	) {
285
+		return apply_filters(
286
+			'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
287
+			$html,
288
+			$registration,
289
+			$question_group,
290
+			$this
291
+		);
292
+	}
293
+
294
+
295
+	/**
296
+	 * @param array             $form_subsections
297
+	 * @param EE_Registration   $registration
298
+	 * @param EE_Question_Group $question_group
299
+	 * @return mixed|void
300
+	 * @since   5.0.0.p
301
+	 */
302
+	public function registrationRegFormSubsections(
303
+		array $form_subsections,
304
+		EE_Registration $registration,
305
+		EE_Question_Group $question_group
306
+	) {
307
+		return apply_filters(
308
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
309
+			$form_subsections,
310
+			$registration,
311
+			$question_group,
312
+			$this
313
+		);
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param                   $html
319
+	 * @param EE_Registration   $registration
320
+	 * @param EE_Question_Group $question_group
321
+	 * @return mixed|void
322
+	 * @since   5.0.0.p
323
+	 */
324
+	public function registrationRegFormAfterQuestionGroupQuestions(
325
+		$html,
326
+		EE_Registration $registration,
327
+		EE_Question_Group $question_group
328
+	) {
329
+		return apply_filters(
330
+			'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
331
+			$html,
332
+			$registration,
333
+			$question_group,
334
+			$this
335
+		);
336
+	}
337
+
338
+
339
+	/**
340
+	 * @param array $template_args
341
+	 * @return mixed|void
342
+	 * @since   5.0.0.p
343
+	 */
344
+	public function autoCopyAttendeeInfoTemplateArgs(array $template_args = [])
345
+	{
346
+		return apply_filters(
347
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
348
+			$template_args
349
+		);
350
+	}
351
+
352
+
353
+	/**
354
+	 * @param array           $country_options
355
+	 * @param EE_Registration $registration
356
+	 * @param EE_Question     $question
357
+	 * @param EE_Answer|null  $answer
358
+	 * @return mixed|void
359
+	 * @since   5.0.0.p
360
+	 */
361
+	public function generateQuestionInputCountryOptions(
362
+		array $country_options,
363
+		EE_Registration $registration,
364
+		EE_Question $question,
365
+		?EE_Answer $answer
366
+	) {
367
+		return apply_filters(
368
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
369
+			$country_options,
370
+			$this,
371
+			$registration,
372
+			$question,
373
+			$answer
374
+		);
375
+	}
376
+
377
+
378
+	/**
379
+	 * @param array           $state_options
380
+	 * @param EE_Registration $registration
381
+	 * @param EE_Question     $question
382
+	 * @param EE_Answer|null  $answer
383
+	 * @return mixed|void
384
+	 * @since   5.0.0.p
385
+	 */
386
+	public function generateQuestionInputStateOptions(
387
+		array $state_options,
388
+		EE_Registration $registration,
389
+		EE_Question $question,
390
+		?EE_Answer $answer
391
+	) {
392
+		return apply_filters(
393
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
394
+			$state_options,
395
+			$this,
396
+			$registration,
397
+			$question,
398
+			$answer
399
+		);
400
+	}
401
+
402
+
403
+	/**
404
+	 * looking for hooks?
405
+	 * this method has been replaced by:
406
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::getRegForm()
407
+	 *
408
+	 * @deprecated   5.0.0.p
409
+	 */
410
+	private function _registrations_reg_form()
411
+	{
412
+	}
413
+
414
+
415
+	/**
416
+	 * looking for hooks?
417
+	 * this method has been replaced by:
418
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalAttendeeRegInfoInput()
419
+	 *
420
+	 * @deprecated   5.0.0.p
421
+	 */
422
+	private function _additional_attendee_reg_info_input()
423
+	{
424
+	}
425
+
426
+
427
+	/**
428
+	 * looking for hooks?
429
+	 * this method has been replaced by:
430
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupRegForm()
431
+	 *
432
+	 * @deprecated   5.0.0.p
433
+	 */
434
+	private function _question_group_reg_form()
435
+	{
436
+	}
437
+
438
+
439
+	/**
440
+	 * looking for hooks?
441
+	 * this method has been replaced by:
442
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupHeader()
443
+	 *
444
+	 * @deprecated   5.0.0.p
445
+	 */
446
+	private function _question_group_header()
447
+	{
448
+	}
449
+
450
+
451
+	/**
452
+	 * looking for hooks?
453
+	 * this method has been replaced by:
454
+	 * EventEspresso\core\domain\services\registration\form\v1\subsections\CopyAttendeeInfoForm
455
+	 *
456
+	 * @deprecated   5.0.0.p
457
+	 */
458
+	private function _copy_attendee_info_form()
459
+	{
460
+	}
461
+
462
+
463
+	/**
464
+	 * looking for hooks?
465
+	 * this method has been replaced by:
466
+	 * EventEspresso\core\domain\services\registration\form\v1\subsections\AutoCopyAttendeeInfoForm
467
+	 *
468
+	 * @deprecated   5.0.0.p
469
+	 */
470
+	private function _auto_copy_attendee_info()
471
+	{
472
+	}
473
+
474
+
475
+	/**
476
+	 * looking for hooks?
477
+	 * this method has been replaced by:
478
+	 * EventEspresso\core\domain\services\registration\form\v1\subsections\CopyAttendeeInfoForm
479
+	 *
480
+	 * @deprecated   5.0.0.p
481
+	 */
482
+	private function _copy_attendee_info_inputs()
483
+	{
484
+	}
485
+
486
+
487
+	/**
488
+	 * looking for hooks?
489
+	 * this method has been replaced by:
490
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalPrimaryRegistrantInputs()
491
+	 *
492
+	 * @deprecated   5.0.0.p
493
+	 */
494
+	private function _additional_primary_registrant_inputs()
495
+	{
496
+	}
497
+
498
+
499
+	/**
500
+	 * looking for hooks?
501
+	 * this method has been replaced by:
502
+	 * EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory::create()
503
+	 *
504
+	 * @param EE_Registration $registration
505
+	 * @param EE_Question     $question
506
+	 * @return EE_Form_Input_Base
507
+	 * @throws EE_Error
508
+	 * @throws ReflectionException
509
+	 * @deprecated   5.0.0.p
510
+	 */
511
+	public function reg_form_question(EE_Registration $registration, EE_Question $question): EE_Form_Input_Base
512
+	{
513
+		/** @var RegFormQuestionFactory $reg_form_question_factory */
514
+		$reg_form_question_factory = LoaderFactory::getShared(RegFormQuestionFactory::class);
515
+		return $reg_form_question_factory->create($registration, $question);
516
+	}
517
+
518
+
519
+	/**
520
+	 * looking for hooks?
521
+	 * this method has been replaced by:
522
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::generateQuestionInput()
523
+	 *
524
+	 * @deprecated   5.0.0.p
525
+	 */
526
+	private function _generate_question_input()
527
+	{
528
+	}
529
+
530
+
531
+	/**
532
+	 * looking for hooks?
533
+	 * this method has been replaced by:
534
+	 * EventEspresso\core\domain\services\registration\form\utilities\CountryOptions::forLegacyFormInput()
535
+	 *
536
+	 * @param array|null           $countries_list
537
+	 * @param EE_Question|null     $question
538
+	 * @param EE_Registration|null $registration
539
+	 * @param EE_Answer|null       $answer
540
+	 * @return array 2d keys are country IDs, values are their names
541
+	 * @throws EE_Error
542
+	 * @throws ReflectionException
543
+	 * @deprecated   5.0.0.p
544
+	 */
545
+	public function use_cached_countries_for_form_input(
546
+		array $countries_list = null,
547
+		EE_Question $question = null,
548
+		EE_Registration $registration = null,
549
+		EE_Answer $answer = null
550
+	): array {
551
+		/** @var CountryOptions $country_options */
552
+		$country_options = LoaderFactory::getShared(CountryOptions::class, [$this->checkout->action]);
553
+		return $country_options->forLegacyFormInput($countries_list, $question, $registration, $answer);
554
+	}
555
+
556
+
557
+	/**
558
+	 * looking for hooks?
559
+	 * this method has been replaced by:
560
+	 * EventEspresso\core\domain\services\registration\form\utilities\StateOptions::forLegacyFormInput()
561
+	 *
562
+	 * @param array|null           $states_list
563
+	 * @param EE_Question|null     $question
564
+	 * @param EE_Registration|null $registration
565
+	 * @param EE_Answer|null       $answer
566
+	 * @return array 2d keys are state IDs, values are their names
567
+	 * @throws EE_Error
568
+	 * @throws ReflectionException
569
+	 * @deprecated   5.0.0.p
570
+	 */
571
+	public function use_cached_states_for_form_input(
572
+		array $states_list = null,
573
+		EE_Question $question = null,
574
+		EE_Registration $registration = null,
575
+		EE_Answer $answer = null
576
+	): array {
577
+		/** @var StateOptions $state_options */
578
+		$state_options = LoaderFactory::getShared(StateOptions::class, [$this->checkout->action]);
579
+		return $state_options->forLegacyFormInput($states_list, $question, $registration, $answer);
580
+	}
581
+
582
+
583
+	/********************************************************************************************************/
584
+	/****************************************  PROCESS REG STEP  ****************************************/
585
+	/********************************************************************************************************/
586
+
587
+
588
+	/**
589
+	 * @return bool
590
+	 * @throws EE_Error
591
+	 * @throws InvalidArgumentException
592
+	 * @throws ReflectionException
593
+	 * @throws RuntimeException
594
+	 * @throws InvalidDataTypeException
595
+	 * @throws InvalidInterfaceException
596
+	 */
597
+	public function process_reg_step(): bool
598
+	{
599
+		$this->setLegacyFiltersForRegFormProcessing();
600
+		// grab validated data from form
601
+		$valid_data = $this->checkout->current_step->valid_data();
602
+		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
603
+		if (empty($valid_data)) {
604
+			return $this->inValidDataError();
605
+		}
606
+		if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
607
+			return $this->inValidTransactionError();
608
+		}
609
+		// get cached registrations
610
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
611
+		// verify we got the goods
612
+		if (empty($registrations)) {
613
+			return $this->noRegistrationsError();
614
+		}
615
+		/** @var RegFormHandler $reg_form_handler */
616
+		$reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]);
617
+		// extract attendee info from form data and save to model objects
618
+		if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) {
619
+			// return immediately if the previous step exited early due to errors
620
+			return false;
621
+		}
622
+		// if first pass thru SPCO,
623
+		// then let's check processed registrations against the total number of tickets in the cart
624
+		$registrations_processed = $reg_form_handler->attendeeCount();
625
+		if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
626
+			return $this->registrationProcessingError($registrations_processed);
627
+		}
628
+		// mark this reg step as completed
629
+		$this->set_completed();
630
+		$this->_set_success_message(
631
+			esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
632
+		);
633
+		// do action in case a plugin wants to do something with the data submitted in step 1.
634
+		// passes EE_Single_Page_Checkout, and it's posted data
635
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
636
+		return true;
637
+	}
638
+
639
+
640
+	/**
641
+	 * @since   5.0.0.p
642
+	 */
643
+	private function setLegacyFiltersForRegFormProcessing()
644
+	{
645
+		add_filter(
646
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegistrations__bypass',
647
+			[$this, 'preRegistrationProcess'],
648
+			1,
649
+			5
650
+		);
651
+		add_filter(
652
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormHandler__processRegFormData__registrant_form_data',
653
+			[$this, 'validDataLineItem'],
654
+			1,
655
+			2
656
+		);
657
+		add_filter(
658
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegFormInputHandler__saveRegistrationFormInput',
659
+			[$this, 'saveRegistrationFormInput'],
660
+			1,
661
+			4
662
+		);
663
+		add_filter(
664
+			'FHEE__EventEspresso_core_domain_services_registration_form_v1_RegistrantData__ensureCriticalRegistrantDataIsSet',
665
+			[$this, 'mergeAddressDetailsWithCriticalAttendeeDetails'],
666
+			1
667
+		);
668
+	}
669
+
670
+
671
+	/**
672
+	 * @param bool            $bypass
673
+	 * @param int             $attendee_count
674
+	 * @param EE_Registration $registration
675
+	 * @param array           $registrations
676
+	 * @param array           $reg_form_data
677
+	 * @return mixed|void
678
+	 * @since   5.0.0.p
679
+	 */
680
+	public function preRegistrationProcess(
681
+		bool $bypass,
682
+		int $attendee_count,
683
+		EE_Registration $registration,
684
+		array $registrations,
685
+		array $reg_form_data
686
+	) {
687
+		return apply_filters(
688
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
689
+			$bypass,
690
+			$attendee_count,
691
+			$registration,
692
+			$registrations,
693
+			$reg_form_data,
694
+			$this
695
+		);
696
+	}
697
+
698
+
699
+	/**
700
+	 * @param array           $reg_form_data
701
+	 * @param EE_Registration $registration
702
+	 * @return mixed|void
703
+	 * @since   5.0.0.p
704
+	 */
705
+	public function validDataLineItem(array $reg_form_data, EE_Registration $registration)
706
+	{
707
+		return apply_filters(
708
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
709
+			$reg_form_data,
710
+			$registration
711
+		);
712
+	}
713
+
714
+
715
+	/**
716
+	 * @param bool            $save
717
+	 * @param EE_Registration $registration
718
+	 * @param                 $form_input
719
+	 * @param                 $input_value
720
+	 * @return mixed|void
721
+	 * @since   5.0.0.p
722
+	 */
723
+	public function saveRegistrationFormInput(bool $save, EE_Registration $registration, $form_input, $input_value)
724
+	{
725
+		return apply_filters(
726
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
727
+			$save,
728
+			$registration,
729
+			$form_input,
730
+			$input_value,
731
+			$this
732
+		);
733
+	}
734
+
735
+
736
+	/**
737
+	 * @param bool $merge_data
738
+	 * @return mixed|void
739
+	 * @since   5.0.0.p
740
+	 */
741
+	public function mergeAddressDetailsWithCriticalAttendeeDetails(bool $merge_data)
742
+	{
743
+		return apply_filters(
744
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
745
+			$merge_data
746
+		);
747
+	}
748
+
749
+
750
+	/**
751
+	 * @return bool
752
+	 * @since   5.0.0.p
753
+	 */
754
+	private function inValidDataError(): bool
755
+	{
756
+		EE_Error::add_error(
757
+			esc_html__('No valid question responses were received.', 'event_espresso'),
758
+			__FILE__,
759
+			__FUNCTION__,
760
+			__LINE__
761
+		);
762
+		return false;
763
+	}
764
+
765
+
766
+	/**
767
+	 * @return bool
768
+	 * @since   5.0.0.p
769
+	 */
770
+	private function inValidTransactionError(): bool
771
+	{
772
+		EE_Error::add_error(
773
+			esc_html__(
774
+				'A valid transaction could not be initiated for processing your registrations.',
775
+				'event_espresso'
776
+			),
777
+			__FILE__,
778
+			__FUNCTION__,
779
+			__LINE__
780
+		);
781
+		return false;
782
+	}
783
+
784
+
785
+	/**
786
+	 * @return bool
787
+	 * @since   5.0.0.p
788
+	 */
789
+	private function noRegistrationsError(): bool
790
+	{
791
+		// combine the old translated string with a new one, in order to not break translations
792
+		$error_message = esc_html__(
793
+			'Your form data could not be applied to any valid registrations.',
794
+			'event_espresso'
795
+		);
796
+		$error_message .= sprintf(
797
+			esc_html_x(
798
+				'%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
799
+				'(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
800
+				'event_espresso'
801
+			),
802
+			'<a href="' . get_post_type_archive_link(EspressoPostType::EVENTS) . '" >',
803
+			'</a>',
804
+			'<br />'
805
+		);
806
+		EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__);
807
+		return false;
808
+	}
809
+
810
+
811
+	/**
812
+	 * @param int $registrations_processed
813
+	 * @return bool
814
+	 * @since   5.0.0.p
815
+	 */
816
+	private function registrationProcessingError(int $registrations_processed): bool
817
+	{
818
+		// generate a correctly translated string for all possible singular/plural combinations
819
+		if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
820
+			$error_msg = sprintf(
821
+				esc_html_x(
822
+					'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
823
+					'There was 1 ticket in the Event Queue, but 2 registrations were processed',
824
+					'event_espresso'
825
+				),
826
+				$this->checkout->total_ticket_count,
827
+				$registrations_processed
828
+			);
829
+		} elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
830
+			$error_msg = sprintf(
831
+				esc_html_x(
832
+					'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
833
+					'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
834
+					'event_espresso'
835
+				),
836
+				$this->checkout->total_ticket_count,
837
+				$registrations_processed
838
+			);
839
+		} else {
840
+			$error_msg = sprintf(
841
+				esc_html__(
842
+					'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
843
+					'event_espresso'
844
+				),
845
+				$this->checkout->total_ticket_count,
846
+				$registrations_processed
847
+			);
848
+		}
849
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
850
+		return false;
851
+	}
852
+
853
+
854
+	/**
855
+	 *    update_reg_step
856
+	 *    this is the final step after a user  revisits the site to edit their attendee information
857
+	 *    this gets called AFTER the process_reg_step() method above
858
+	 *
859
+	 * @return bool
860
+	 * @throws EE_Error
861
+	 * @throws InvalidArgumentException
862
+	 * @throws ReflectionException
863
+	 * @throws RuntimeException
864
+	 * @throws InvalidDataTypeException
865
+	 * @throws InvalidInterfaceException
866
+	 */
867
+	public function update_reg_step(): bool
868
+	{
869
+		// save everything
870
+		if ($this->process_reg_step()) {
871
+			$this->checkout->redirect     = true;
872
+			$this->checkout->redirect_url = add_query_arg(
873
+				[
874
+					'e_reg_url_link' => $this->checkout->reg_url_link,
875
+					'revisit'        => true,
876
+				],
877
+				$this->checkout->thank_you_page_url
878
+			);
879
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
880
+			return true;
881
+		}
882
+		return false;
883
+	}
884 884
 }
Please login to merge, or discard this patch.
PaymentMethods/PayPalCommerce/PayPalCheckout/EEG_PayPalCheckout.gateway.php 2 patches
Indentation   +318 added lines, -318 removed lines patch added patch discarded remove patch
@@ -13,335 +13,335 @@
 block discarded – undo
13 13
  */
14 14
 class EEG_PayPalCheckout extends EE_Onsite_Gateway
15 15
 {
16
-    /**
17
-     * Currencies supported by this gateway.
18
-     *
19
-     * @var array
20
-     */
21
-    protected $_currencies_supported = [
22
-        'AUD',
23
-        'BRL',
24
-        'CAD',
25
-        'CNY',
26
-        'CZK',
27
-        'DKK',
28
-        'EUR',
29
-        'HKD',
30
-        'HUF',
31
-        'ILS',
32
-        'JPY',
33
-        'MYR',
34
-        'MXN',
35
-        'TWD',
36
-        'NZD',
37
-        'NOK',
38
-        'PHP',
39
-        'PLN',
40
-        'GBP',
41
-        'RUB',
42
-        'SGD',
43
-        'SEK',
44
-        'CHF',
45
-        'THB',
46
-        'USD',
47
-    ];
16
+	/**
17
+	 * Currencies supported by this gateway.
18
+	 *
19
+	 * @var array
20
+	 */
21
+	protected $_currencies_supported = [
22
+		'AUD',
23
+		'BRL',
24
+		'CAD',
25
+		'CNY',
26
+		'CZK',
27
+		'DKK',
28
+		'EUR',
29
+		'HKD',
30
+		'HUF',
31
+		'ILS',
32
+		'JPY',
33
+		'MYR',
34
+		'MXN',
35
+		'TWD',
36
+		'NZD',
37
+		'NOK',
38
+		'PHP',
39
+		'PLN',
40
+		'GBP',
41
+		'RUB',
42
+		'SGD',
43
+		'SEK',
44
+		'CHF',
45
+		'THB',
46
+		'USD',
47
+	];
48 48
 
49 49
 
50
-    /**
51
-     * Override the parent.
52
-     *
53
-     * @param EE_Payment|null $payment
54
-     * @param array|null      $billing_info
55
-     * @return EE_Payment
56
-     * @throws EE_Error|ReflectionException
57
-     */
58
-    public function do_direct_payment($payment, $billing_info = null)
59
-    {
60
-        $request         = LoaderFactory::getLoader()->getShared(RequestInterface::class);
61
-        $post_parameters = $request->postParams();
62
-        // Check the payment.
63
-        $payment = $this->validatePayment($payment, $request);
64
-        if ($payment->details() === 'error' && $payment->status() === EEM_Payment::status_id_failed) {
65
-            return $payment;
66
-        }
67
-        $transaction    = $payment->transaction();
68
-        $payment_method = $transaction->payment_method();
69
-        // Get the order details.
70
-        $order_id = $request->getRequestParam('pp_order_id');
71
-        if (! $order_id) {
72
-            return EEG_PayPalCheckout::updatePaymentStatus(
73
-                $payment,
74
-                EEM_Payment::status_id_failed,
75
-                $post_parameters,
76
-                esc_html__('Can\'t charge the Order. The Order ID is missing.', 'event_espresso')
77
-            );
78
-        }
79
-        // Capture the order.
80
-        $capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);
81
-        // Check the order status.
82
-        $order_status   = $this->isOrderCompleted($order_id, $transaction, $payment_method);
83
-        if (! $order_status['completed']) {
84
-            return EEG_PayPalCheckout::updatePaymentStatus(
85
-                $payment,
86
-                EEM_Payment::status_id_failed,
87
-                $order_status,
88
-                $order_status['message'] ?? ''
89
-            );
90
-        }
91
-        // Looks like all is good. Mark payment as a success.
92
-        $this->saveBillingDetails($payment, $transaction, $order_status['details'], $billing_info);
93
-        return EEG_PayPalCheckout::updatePaymentStatus($payment, EEM_Payment::status_id_approved, $capture_status);
94
-    }
50
+	/**
51
+	 * Override the parent.
52
+	 *
53
+	 * @param EE_Payment|null $payment
54
+	 * @param array|null      $billing_info
55
+	 * @return EE_Payment
56
+	 * @throws EE_Error|ReflectionException
57
+	 */
58
+	public function do_direct_payment($payment, $billing_info = null)
59
+	{
60
+		$request         = LoaderFactory::getLoader()->getShared(RequestInterface::class);
61
+		$post_parameters = $request->postParams();
62
+		// Check the payment.
63
+		$payment = $this->validatePayment($payment, $request);
64
+		if ($payment->details() === 'error' && $payment->status() === EEM_Payment::status_id_failed) {
65
+			return $payment;
66
+		}
67
+		$transaction    = $payment->transaction();
68
+		$payment_method = $transaction->payment_method();
69
+		// Get the order details.
70
+		$order_id = $request->getRequestParam('pp_order_id');
71
+		if (! $order_id) {
72
+			return EEG_PayPalCheckout::updatePaymentStatus(
73
+				$payment,
74
+				EEM_Payment::status_id_failed,
75
+				$post_parameters,
76
+				esc_html__('Can\'t charge the Order. The Order ID is missing.', 'event_espresso')
77
+			);
78
+		}
79
+		// Capture the order.
80
+		$capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);
81
+		// Check the order status.
82
+		$order_status   = $this->isOrderCompleted($order_id, $transaction, $payment_method);
83
+		if (! $order_status['completed']) {
84
+			return EEG_PayPalCheckout::updatePaymentStatus(
85
+				$payment,
86
+				EEM_Payment::status_id_failed,
87
+				$order_status,
88
+				$order_status['message'] ?? ''
89
+			);
90
+		}
91
+		// Looks like all is good. Mark payment as a success.
92
+		$this->saveBillingDetails($payment, $transaction, $order_status['details'], $billing_info);
93
+		return EEG_PayPalCheckout::updatePaymentStatus($payment, EEM_Payment::status_id_approved, $capture_status);
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     * Validate the Order.
99
-     *
100
-     * @param string            $order_id
101
-     * @param EE_Transaction    $transaction
102
-     * @param EE_Payment_Method $payment_method
103
-     * @return array ['completed' => {boolean}, 'message' => {string}]
104
-     * @throws EE_Error
105
-     * @throws ReflectionException
106
-     */
107
-    public static function isOrderCompleted(
108
-        string $order_id,
109
-        EE_Transaction $transaction,
110
-        EE_Payment_Method $payment_method
111
-    ): array
112
-    {
113
-        $order_details = EED_PayPalCommerce::getOrderDetails($order_id, $transaction, $payment_method);
114
-        $conclusion = [
115
-            'completed' => false,
116
-            'details'   => $order_details,
117
-        ];
118
-        if (! $order_details) {
119
-            $conclusion['message'] = esc_html__(
120
-                'Could not validate this payment. The Order details were empty.',
121
-                'event_espresso'
122
-            );
123
-        } elseif (! empty($order_details['error'])) {
124
-            $conclusion['message'] = $order_details['message'] ?? $order_details['error'];
125
-        } elseif (empty($order_details['status'])) {
126
-            $conclusion['message'] = esc_html__(
127
-                'There was an error with this payment. The status of the Order could not be determined.',
128
-                'event_espresso'
129
-            );
130
-        } elseif ($order_details['status'] !== 'COMPLETED') {
131
-            $conclusion['message'] = esc_html__(
132
-                'There was an error with this payment. Order was not approved.',
133
-                'event_espresso'
134
-            );
135
-        } elseif (empty($order_details['purchase_units'][0]['payments']['captures'][0]['status'])) {
136
-            $conclusion['message'] = esc_html__(
137
-                'There was an error with this payment. The status of the Payment could not be determined.',
138
-                'event_espresso'
139
-            );
140
-        } elseif ($order_details['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') {
141
-            $conclusion['message'] = esc_html__(
142
-                'This payment was declined or failed validation. Please check the billing information you provided.',
143
-                'event_espresso'
144
-            );
145
-        } else {
146
-            // If we didn't fail on the above, the Order should be considered valid.
147
-            $conclusion['completed'] = true;
148
-            $conclusion['message']   = esc_html__('Order Valid.', 'event_espresso');
149
-        }
150
-        return $conclusion;
151
-    }
97
+	/**
98
+	 * Validate the Order.
99
+	 *
100
+	 * @param string            $order_id
101
+	 * @param EE_Transaction    $transaction
102
+	 * @param EE_Payment_Method $payment_method
103
+	 * @return array ['completed' => {boolean}, 'message' => {string}]
104
+	 * @throws EE_Error
105
+	 * @throws ReflectionException
106
+	 */
107
+	public static function isOrderCompleted(
108
+		string $order_id,
109
+		EE_Transaction $transaction,
110
+		EE_Payment_Method $payment_method
111
+	): array
112
+	{
113
+		$order_details = EED_PayPalCommerce::getOrderDetails($order_id, $transaction, $payment_method);
114
+		$conclusion = [
115
+			'completed' => false,
116
+			'details'   => $order_details,
117
+		];
118
+		if (! $order_details) {
119
+			$conclusion['message'] = esc_html__(
120
+				'Could not validate this payment. The Order details were empty.',
121
+				'event_espresso'
122
+			);
123
+		} elseif (! empty($order_details['error'])) {
124
+			$conclusion['message'] = $order_details['message'] ?? $order_details['error'];
125
+		} elseif (empty($order_details['status'])) {
126
+			$conclusion['message'] = esc_html__(
127
+				'There was an error with this payment. The status of the Order could not be determined.',
128
+				'event_espresso'
129
+			);
130
+		} elseif ($order_details['status'] !== 'COMPLETED') {
131
+			$conclusion['message'] = esc_html__(
132
+				'There was an error with this payment. Order was not approved.',
133
+				'event_espresso'
134
+			);
135
+		} elseif (empty($order_details['purchase_units'][0]['payments']['captures'][0]['status'])) {
136
+			$conclusion['message'] = esc_html__(
137
+				'There was an error with this payment. The status of the Payment could not be determined.',
138
+				'event_espresso'
139
+			);
140
+		} elseif ($order_details['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') {
141
+			$conclusion['message'] = esc_html__(
142
+				'This payment was declined or failed validation. Please check the billing information you provided.',
143
+				'event_espresso'
144
+			);
145
+		} else {
146
+			// If we didn't fail on the above, the Order should be considered valid.
147
+			$conclusion['completed'] = true;
148
+			$conclusion['message']   = esc_html__('Order Valid.', 'event_espresso');
149
+		}
150
+		return $conclusion;
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * Create an EE Payment.
156
-     *
157
-     * @param EE_Transaction    $transaction
158
-     * @param EE_Payment_Method $payment_method
159
-     * @return EE_Payment
160
-     * @throws EE_Error
161
-     * @throws ReflectionException
162
-     */
163
-    public static function createPayment(EE_Transaction $transaction, EE_Payment_Method $payment_method): EE_Payment
164
-    {
165
-        // No payment for this transaction was created at this point.
166
-        $payment = EE_Payment::new_instance([
167
-            'PAY_timestamp'     => time(),
168
-            'TXN_ID'            => $transaction->ID(),
169
-            'PMD_ID'            => $payment_method->ID(),
170
-            'PAY_po_number'     => null,
171
-            'PAY_extra_accntng' => null,
172
-            'PAY_details'       => null,
173
-        ]);
174
-        $payment->save();
175
-        return $payment;
176
-    }
154
+	/**
155
+	 * Create an EE Payment.
156
+	 *
157
+	 * @param EE_Transaction    $transaction
158
+	 * @param EE_Payment_Method $payment_method
159
+	 * @return EE_Payment
160
+	 * @throws EE_Error
161
+	 * @throws ReflectionException
162
+	 */
163
+	public static function createPayment(EE_Transaction $transaction, EE_Payment_Method $payment_method): EE_Payment
164
+	{
165
+		// No payment for this transaction was created at this point.
166
+		$payment = EE_Payment::new_instance([
167
+			'PAY_timestamp'     => time(),
168
+			'TXN_ID'            => $transaction->ID(),
169
+			'PMD_ID'            => $payment_method->ID(),
170
+			'PAY_po_number'     => null,
171
+			'PAY_extra_accntng' => null,
172
+			'PAY_details'       => null,
173
+		]);
174
+		$payment->save();
175
+		return $payment;
176
+	}
177 177
 
178 178
 
179
-    /**
180
-     * Set a payment error and log the data.
181
-     *
182
-     * @param EE_Payment   $payment
183
-     * @param string       $status
184
-     * @param array|string $response_data
185
-     * @param string       $update_message
186
-     * @return EE_Payment
187
-     * @throws EE_Error|ReflectionException
188
-     */
189
-    public static function updatePaymentStatus(
190
-        EE_Payment $payment,
191
-        string $status,
192
-        $response_data,
193
-        string $update_message = ''
194
-    ): EE_Payment {
195
-        $paypal_pm = ! empty($payment->payment_method())
196
-            ? EEM_Payment_Method::instance()->get_one_by_slug($payment->payment_method()->name())
197
-            : null;
198
-        // Is this a successful payment ?
199
-        if ($status === EEM_Payment::status_id_approved) {
200
-            $default_message = esc_html__('Successful payment.', 'event_espresso');
201
-            $amount          = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;
202
-            // Don't set the amount if there is no info on that with this order.
203
-            if (! empty($amount)) {
204
-                $payment->set_amount((float) $amount);
205
-            }
206
-            $payment->set_txn_id_chq_nmbr(
207
-                $response_data['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']
208
-            );
209
-        } else {
210
-            $default_message = sprintf(
211
-                esc_html__(
212
-                    'Your payment could not be processed successfully due to a technical issue.%1$sPlease try again or contact%2$s for assistance.',
213
-                    'event_espresso'
214
-                ),
215
-                '<br/>',
216
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
217
-            );
218
-        }
219
-        $log_message = $update_message ?: $default_message;
220
-        PayPalLogger::errorLog($log_message, $response_data, $paypal_pm, false, $payment->transaction());
221
-        $payment->set_status($status);
222
-        $payment->set_details($log_message);
223
-        $payment->set_gateway_response($log_message);
224
-        $payment->save();
225
-        return $payment;
226
-    }
179
+	/**
180
+	 * Set a payment error and log the data.
181
+	 *
182
+	 * @param EE_Payment   $payment
183
+	 * @param string       $status
184
+	 * @param array|string $response_data
185
+	 * @param string       $update_message
186
+	 * @return EE_Payment
187
+	 * @throws EE_Error|ReflectionException
188
+	 */
189
+	public static function updatePaymentStatus(
190
+		EE_Payment $payment,
191
+		string $status,
192
+		$response_data,
193
+		string $update_message = ''
194
+	): EE_Payment {
195
+		$paypal_pm = ! empty($payment->payment_method())
196
+			? EEM_Payment_Method::instance()->get_one_by_slug($payment->payment_method()->name())
197
+			: null;
198
+		// Is this a successful payment ?
199
+		if ($status === EEM_Payment::status_id_approved) {
200
+			$default_message = esc_html__('Successful payment.', 'event_espresso');
201
+			$amount          = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;
202
+			// Don't set the amount if there is no info on that with this order.
203
+			if (! empty($amount)) {
204
+				$payment->set_amount((float) $amount);
205
+			}
206
+			$payment->set_txn_id_chq_nmbr(
207
+				$response_data['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']
208
+			);
209
+		} else {
210
+			$default_message = sprintf(
211
+				esc_html__(
212
+					'Your payment could not be processed successfully due to a technical issue.%1$sPlease try again or contact%2$s for assistance.',
213
+					'event_espresso'
214
+				),
215
+				'<br/>',
216
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
217
+			);
218
+		}
219
+		$log_message = $update_message ?: $default_message;
220
+		PayPalLogger::errorLog($log_message, $response_data, $paypal_pm, false, $payment->transaction());
221
+		$payment->set_status($status);
222
+		$payment->set_details($log_message);
223
+		$payment->set_gateway_response($log_message);
224
+		$payment->save();
225
+		return $payment;
226
+	}
227 227
 
228 228
 
229
-    /**
230
-     * Validate the payment.
231
-     *
232
-     * @param EE_Payment|null  $payment
233
-     * @param RequestInterface $request
234
-     * @return EE_Payment
235
-     * @throws EE_Error
236
-     * @throws ReflectionException
237
-     */
238
-    public function validatePayment(?EE_Payment $payment, RequestInterface $request): EE_Payment
239
-    {
240
-        $failed_status = $this->_pay_model->failed_status();
241
-        // Check the payment.
242
-        if (! $payment instanceof EE_Payment) {
243
-            $payment       = EE_Payment::new_instance();
244
-            $error_message = esc_html__('Error. No associated payment was found.', 'event_espresso');
245
-            return EEG_PayPalCheckout::updatePaymentStatus(
246
-                $payment,
247
-                $failed_status,
248
-                $request->postParams(),
249
-                $error_message
250
-            );
251
-        }
252
-        // Check the transaction.
253
-        $transaction = $payment->transaction();
254
-        if (! $transaction instanceof EE_Transaction) {
255
-            $error_message = esc_html__(
256
-                'Could not process this payment because it has no associated transaction.',
257
-                'event_espresso'
258
-            );
259
-            return EEG_PayPalCheckout::updatePaymentStatus(
260
-                $payment,
261
-                $failed_status,
262
-                $request->postParams(),
263
-                $error_message
264
-            );
265
-        }
266
-        return $payment;
267
-    }
229
+	/**
230
+	 * Validate the payment.
231
+	 *
232
+	 * @param EE_Payment|null  $payment
233
+	 * @param RequestInterface $request
234
+	 * @return EE_Payment
235
+	 * @throws EE_Error
236
+	 * @throws ReflectionException
237
+	 */
238
+	public function validatePayment(?EE_Payment $payment, RequestInterface $request): EE_Payment
239
+	{
240
+		$failed_status = $this->_pay_model->failed_status();
241
+		// Check the payment.
242
+		if (! $payment instanceof EE_Payment) {
243
+			$payment       = EE_Payment::new_instance();
244
+			$error_message = esc_html__('Error. No associated payment was found.', 'event_espresso');
245
+			return EEG_PayPalCheckout::updatePaymentStatus(
246
+				$payment,
247
+				$failed_status,
248
+				$request->postParams(),
249
+				$error_message
250
+			);
251
+		}
252
+		// Check the transaction.
253
+		$transaction = $payment->transaction();
254
+		if (! $transaction instanceof EE_Transaction) {
255
+			$error_message = esc_html__(
256
+				'Could not process this payment because it has no associated transaction.',
257
+				'event_espresso'
258
+			);
259
+			return EEG_PayPalCheckout::updatePaymentStatus(
260
+				$payment,
261
+				$failed_status,
262
+				$request->postParams(),
263
+				$error_message
264
+			);
265
+		}
266
+		return $payment;
267
+	}
268 268
 
269 269
 
270
-    /**
271
-     * Save some transaction details, like billing information.
272
-     *
273
-     * @param EE_Payment     $payment
274
-     * @param EE_Transaction $transaction
275
-     * @param array          $order
276
-     * @param array          $billing
277
-     * @return void
278
-     * @throws EE_Error
279
-     * @throws ReflectionException
280
-     */
281
-    public static function saveBillingDetails(
282
-        EE_Payment $payment,
283
-        EE_Transaction $transaction,
284
-        array $order,
285
-        array $billing
286
-    ): void {
287
-        $primary_reg = $transaction->primary_registration();
288
-        $att    = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
289
-        if (! $att instanceof EE_Attendee) {
290
-            // I guess we are done here then. Just save what we have.
291
-            $payment->set_details($order);
292
-            return;
293
-        }
294
-        // Defaults:
295
-        $billing['credit_card'] = 'empty';
296
-        $billing['first_name']  = empty($billing['first_name']) ? ($att->fname() ?: 'empty') : $billing['first_name'];
297
-        $billing['last_name']   = empty($billing['last_name']) ? ($att->lname() ?: 'empty') : $billing['last_name'];
298
-        $billing['email']       = empty($billing['email']) ? ($att->email() ?: 'empty') : $billing['email'];
299
-        $billing['country']     = empty($billing['country']) ? ($att->country() ?: 'empty') : $billing['country'];
300
-        $billing['city']        = empty($billing['city']) ? ($att->city() ?: 'empty') : $billing['city'];
301
-        $billing['state']       = empty($billing['state']) ? ($att->state_name() ?: 'empty') : $billing['state'];
302
-        $billing['address']     = empty($billing['address']) ? ($att->address() ?: 'empty') : $billing['address'];
303
-        $billing['address2']    = empty($billing['address2']) ? ($att->address2() ?: 'empty') : $billing['address2'];
304
-        $billing['zip']         = empty($billing['zip']) ? ($att->zip() ?: 'empty') : $billing['zip'];
305
-        $billing['phone']       = empty($billing['phone']) ? ($att->phone() ?: 'empty') : $billing['phone'];
270
+	/**
271
+	 * Save some transaction details, like billing information.
272
+	 *
273
+	 * @param EE_Payment     $payment
274
+	 * @param EE_Transaction $transaction
275
+	 * @param array          $order
276
+	 * @param array          $billing
277
+	 * @return void
278
+	 * @throws EE_Error
279
+	 * @throws ReflectionException
280
+	 */
281
+	public static function saveBillingDetails(
282
+		EE_Payment $payment,
283
+		EE_Transaction $transaction,
284
+		array $order,
285
+		array $billing
286
+	): void {
287
+		$primary_reg = $transaction->primary_registration();
288
+		$att    = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
289
+		if (! $att instanceof EE_Attendee) {
290
+			// I guess we are done here then. Just save what we have.
291
+			$payment->set_details($order);
292
+			return;
293
+		}
294
+		// Defaults:
295
+		$billing['credit_card'] = 'empty';
296
+		$billing['first_name']  = empty($billing['first_name']) ? ($att->fname() ?: 'empty') : $billing['first_name'];
297
+		$billing['last_name']   = empty($billing['last_name']) ? ($att->lname() ?: 'empty') : $billing['last_name'];
298
+		$billing['email']       = empty($billing['email']) ? ($att->email() ?: 'empty') : $billing['email'];
299
+		$billing['country']     = empty($billing['country']) ? ($att->country() ?: 'empty') : $billing['country'];
300
+		$billing['city']        = empty($billing['city']) ? ($att->city() ?: 'empty') : $billing['city'];
301
+		$billing['state']       = empty($billing['state']) ? ($att->state_name() ?: 'empty') : $billing['state'];
302
+		$billing['address']     = empty($billing['address']) ? ($att->address() ?: 'empty') : $billing['address'];
303
+		$billing['address2']    = empty($billing['address2']) ? ($att->address2() ?: 'empty') : $billing['address2'];
304
+		$billing['zip']         = empty($billing['zip']) ? ($att->zip() ?: 'empty') : $billing['zip'];
305
+		$billing['phone']       = empty($billing['phone']) ? ($att->phone() ?: 'empty') : $billing['phone'];
306 306
 
307
-        // Try getting the payer information from the payment source (PayPal).
308
-        if (! empty($order['payment_source'])) {
309
-            // A card (ACDC) payment ?
310
-            if (! empty($order['payment_source']['card'])) {
311
-                $payer = $order['payment_source']['card'];
312
-            // Or maybe a PayPal Express payment ?
313
-            } elseif (! empty($order['payment_source']['paypal'])) {
314
-                $payer = $order['payment_source']['paypal'];
315
-            }
316
-            if (! empty($payer)) {
317
-                if (! empty($payer['name'])) {
318
-                    // Yup, payment_source card vs PayPal have different info about the payer. So need to differentiate.
319
-                    if (is_string($payer['name'])) {
320
-                        $full_name                  = explode(' ', $payer['name']);
321
-                        $billing['first_name'] = $full_name[0] ?? $billing['first_name'];
322
-                        $billing['last_name']  = $full_name[1] ?? $billing['last_name'];
323
-                    }
324
-                    // PayPal info on the Payment:
325
-                    if (is_array($payer['name'])) {
326
-                        $billing['first_name'] = $payer['name']['given_name'] ?? $billing['first_name'];
327
-                        $billing['last_name']  = $payer['name']['surname'] ?? $billing['last_name'];
328
-                    }
329
-                }
330
-                // Possible info on the payer.
331
-                $billing['credit_card'] = $payer['last_digits'] ?? $billing['credit_card'];
332
-                $billing['email']       = $payer['email_address'] ?? $billing['email'];
333
-                $billing['country']     = $payer['address']['country_code'] ?? $billing['country'];
334
-                $billing['city']        = $payer['address']['city'] ?? $billing['city'];
335
-                $billing['state']       = $payer['address']['state'] ?? $billing['state'];
336
-                $billing['address']     = $payer['address']['address'] ?? $billing['address'];
337
-                $billing['zip']         = $payer['address']['zip'] ?? $billing['zip'];
338
-            }
339
-        }
340
-        // Update attendee billing info in the transaction details.
341
-        $payment_method = $transaction->payment_method();
342
-        $post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base
343
-            ? 'billing_info_' . $payment_method->type_obj()->system_name()
344
-            : '';
345
-        update_post_meta($att->ID(), $post_meta_name, $billing);
346
-    }
307
+		// Try getting the payer information from the payment source (PayPal).
308
+		if (! empty($order['payment_source'])) {
309
+			// A card (ACDC) payment ?
310
+			if (! empty($order['payment_source']['card'])) {
311
+				$payer = $order['payment_source']['card'];
312
+			// Or maybe a PayPal Express payment ?
313
+			} elseif (! empty($order['payment_source']['paypal'])) {
314
+				$payer = $order['payment_source']['paypal'];
315
+			}
316
+			if (! empty($payer)) {
317
+				if (! empty($payer['name'])) {
318
+					// Yup, payment_source card vs PayPal have different info about the payer. So need to differentiate.
319
+					if (is_string($payer['name'])) {
320
+						$full_name                  = explode(' ', $payer['name']);
321
+						$billing['first_name'] = $full_name[0] ?? $billing['first_name'];
322
+						$billing['last_name']  = $full_name[1] ?? $billing['last_name'];
323
+					}
324
+					// PayPal info on the Payment:
325
+					if (is_array($payer['name'])) {
326
+						$billing['first_name'] = $payer['name']['given_name'] ?? $billing['first_name'];
327
+						$billing['last_name']  = $payer['name']['surname'] ?? $billing['last_name'];
328
+					}
329
+				}
330
+				// Possible info on the payer.
331
+				$billing['credit_card'] = $payer['last_digits'] ?? $billing['credit_card'];
332
+				$billing['email']       = $payer['email_address'] ?? $billing['email'];
333
+				$billing['country']     = $payer['address']['country_code'] ?? $billing['country'];
334
+				$billing['city']        = $payer['address']['city'] ?? $billing['city'];
335
+				$billing['state']       = $payer['address']['state'] ?? $billing['state'];
336
+				$billing['address']     = $payer['address']['address'] ?? $billing['address'];
337
+				$billing['zip']         = $payer['address']['zip'] ?? $billing['zip'];
338
+			}
339
+		}
340
+		// Update attendee billing info in the transaction details.
341
+		$payment_method = $transaction->payment_method();
342
+		$post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base
343
+			? 'billing_info_' . $payment_method->type_obj()->system_name()
344
+			: '';
345
+		update_post_meta($att->ID(), $post_meta_name, $billing);
346
+	}
347 347
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         $payment_method = $transaction->payment_method();
69 69
         // Get the order details.
70 70
         $order_id = $request->getRequestParam('pp_order_id');
71
-        if (! $order_id) {
71
+        if ( ! $order_id) {
72 72
             return EEG_PayPalCheckout::updatePaymentStatus(
73 73
                 $payment,
74 74
                 EEM_Payment::status_id_failed,
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);
81 81
         // Check the order status.
82 82
         $order_status   = $this->isOrderCompleted($order_id, $transaction, $payment_method);
83
-        if (! $order_status['completed']) {
83
+        if ( ! $order_status['completed']) {
84 84
             return EEG_PayPalCheckout::updatePaymentStatus(
85 85
                 $payment,
86 86
                 EEM_Payment::status_id_failed,
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
             'completed' => false,
116 116
             'details'   => $order_details,
117 117
         ];
118
-        if (! $order_details) {
118
+        if ( ! $order_details) {
119 119
             $conclusion['message'] = esc_html__(
120 120
                 'Could not validate this payment. The Order details were empty.',
121 121
                 'event_espresso'
122 122
             );
123
-        } elseif (! empty($order_details['error'])) {
123
+        } elseif ( ! empty($order_details['error'])) {
124 124
             $conclusion['message'] = $order_details['message'] ?? $order_details['error'];
125 125
         } elseif (empty($order_details['status'])) {
126 126
             $conclusion['message'] = esc_html__(
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             $default_message = esc_html__('Successful payment.', 'event_espresso');
201 201
             $amount          = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;
202 202
             // Don't set the amount if there is no info on that with this order.
203
-            if (! empty($amount)) {
203
+            if ( ! empty($amount)) {
204 204
                 $payment->set_amount((float) $amount);
205 205
             }
206 206
             $payment->set_txn_id_chq_nmbr(
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
     {
240 240
         $failed_status = $this->_pay_model->failed_status();
241 241
         // Check the payment.
242
-        if (! $payment instanceof EE_Payment) {
242
+        if ( ! $payment instanceof EE_Payment) {
243 243
             $payment       = EE_Payment::new_instance();
244 244
             $error_message = esc_html__('Error. No associated payment was found.', 'event_espresso');
245 245
             return EEG_PayPalCheckout::updatePaymentStatus(
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
         }
252 252
         // Check the transaction.
253 253
         $transaction = $payment->transaction();
254
-        if (! $transaction instanceof EE_Transaction) {
254
+        if ( ! $transaction instanceof EE_Transaction) {
255 255
             $error_message = esc_html__(
256 256
                 'Could not process this payment because it has no associated transaction.',
257 257
                 'event_espresso'
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
         array $billing
286 286
     ): void {
287 287
         $primary_reg = $transaction->primary_registration();
288
-        $att    = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
289
-        if (! $att instanceof EE_Attendee) {
288
+        $att = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;
289
+        if ( ! $att instanceof EE_Attendee) {
290 290
             // I guess we are done here then. Just save what we have.
291 291
             $payment->set_details($order);
292 292
             return;
@@ -305,19 +305,19 @@  discard block
 block discarded – undo
305 305
         $billing['phone']       = empty($billing['phone']) ? ($att->phone() ?: 'empty') : $billing['phone'];
306 306
 
307 307
         // Try getting the payer information from the payment source (PayPal).
308
-        if (! empty($order['payment_source'])) {
308
+        if ( ! empty($order['payment_source'])) {
309 309
             // A card (ACDC) payment ?
310
-            if (! empty($order['payment_source']['card'])) {
310
+            if ( ! empty($order['payment_source']['card'])) {
311 311
                 $payer = $order['payment_source']['card'];
312 312
             // Or maybe a PayPal Express payment ?
313
-            } elseif (! empty($order['payment_source']['paypal'])) {
313
+            } elseif ( ! empty($order['payment_source']['paypal'])) {
314 314
                 $payer = $order['payment_source']['paypal'];
315 315
             }
316
-            if (! empty($payer)) {
317
-                if (! empty($payer['name'])) {
316
+            if ( ! empty($payer)) {
317
+                if ( ! empty($payer['name'])) {
318 318
                     // Yup, payment_source card vs PayPal have different info about the payer. So need to differentiate.
319 319
                     if (is_string($payer['name'])) {
320
-                        $full_name                  = explode(' ', $payer['name']);
320
+                        $full_name = explode(' ', $payer['name']);
321 321
                         $billing['first_name'] = $full_name[0] ?? $billing['first_name'];
322 322
                         $billing['last_name']  = $full_name[1] ?? $billing['last_name'];
323 323
                     }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
         // Update attendee billing info in the transaction details.
341 341
         $payment_method = $transaction->payment_method();
342 342
         $post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base
343
-            ? 'billing_info_' . $payment_method->type_obj()->system_name()
343
+            ? 'billing_info_'.$payment_method->type_obj()->system_name()
344 344
             : '';
345 345
         update_post_meta($att->ID(), $post_meta_name, $billing);
346 346
     }
Please login to merge, or discard this patch.
PaymentMethods/PayPalCommerce/api/orders/CreateOrder.php 1 patch
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -30,302 +30,302 @@
 block discarded – undo
30 30
  */
31 31
 class CreateOrder extends OrdersApi
32 32
 {
33
-    /**
34
-     * Line items total.
35
-     *
36
-     * @var float
37
-     */
38
-    protected float $items_total = 0.0;
33
+	/**
34
+	 * Line items total.
35
+	 *
36
+	 * @var float
37
+	 */
38
+	protected float $items_total = 0.0;
39 39
 
40
-    /**
41
-     * Promotions total.
42
-     *
43
-     * @var float
44
-     */
45
-    protected float $promos_total = 0.0;
40
+	/**
41
+	 * Promotions total.
42
+	 *
43
+	 * @var float
44
+	 */
45
+	protected float $promos_total = 0.0;
46 46
 
47
-    /**
48
-     * Tax total.
49
-     *
50
-     * @var float
51
-     */
52
-    protected float $tax_total = 0.0;
47
+	/**
48
+	 * Tax total.
49
+	 *
50
+	 * @var float
51
+	 */
52
+	protected float $tax_total = 0.0;
53 53
 
54
-    /**
55
-     * Currency.
56
-     *
57
-     * @var string
58
-     */
59
-    protected string $currency_code;
54
+	/**
55
+	 * Currency.
56
+	 *
57
+	 * @var string
58
+	 */
59
+	protected string $currency_code;
60 60
 
61
-    /**
62
-     * Billing info.
63
-     *
64
-     * @var array
65
-     */
66
-    protected array $billing_info;
61
+	/**
62
+	 * Billing info.
63
+	 *
64
+	 * @var array
65
+	 */
66
+	protected array $billing_info;
67 67
 
68
-    /**
69
-     * Transaction this order is for.
70
-     *
71
-     * @var EE_Transaction
72
-     */
73
-    protected EE_Transaction $transaction;
68
+	/**
69
+	 * Transaction this order is for.
70
+	 *
71
+	 * @var EE_Transaction
72
+	 */
73
+	protected EE_Transaction $transaction;
74 74
 
75
-    private FeatureFlags $feature;
75
+	private FeatureFlags $feature;
76 76
 
77 77
 
78
-    /**
79
-     * CreateOrder constructor.
80
-     *
81
-     * @param PayPalApi      $api
82
-     * @param EE_Transaction $transaction
83
-     * @param array          $billing_info
84
-     * @param FeatureFlags   $feature
85
-     */
86
-    public function __construct(PayPalApi $api, EE_Transaction $transaction, array $billing_info, FeatureFlags $feature)
87
-    {
88
-        parent::__construct($api);
89
-        $this->transaction   = $transaction;
90
-        $this->feature       = $feature;
91
-        $this->currency_code = CurrencyManager::currencyCode();
92
-        $this->sanitizeRequestParameters($billing_info);
93
-    }
78
+	/**
79
+	 * CreateOrder constructor.
80
+	 *
81
+	 * @param PayPalApi      $api
82
+	 * @param EE_Transaction $transaction
83
+	 * @param array          $billing_info
84
+	 * @param FeatureFlags   $feature
85
+	 */
86
+	public function __construct(PayPalApi $api, EE_Transaction $transaction, array $billing_info, FeatureFlags $feature)
87
+	{
88
+		parent::__construct($api);
89
+		$this->transaction   = $transaction;
90
+		$this->feature       = $feature;
91
+		$this->currency_code = CurrencyManager::currencyCode();
92
+		$this->sanitizeRequestParameters($billing_info);
93
+	}
94 94
 
95 95
 
96
-    /**
97
-     * Sanitize the array of billing form data.
98
-     *
99
-     * @param array $billing_info
100
-     * @return void
101
-     */
102
-    public function sanitizeRequestParameters(array $billing_info): void
103
-    {
104
-        $sanitizer       = new RequestSanitizer(new Basic());
105
-        foreach ($billing_info as $item => $value) {
106
-            $this->billing_info[ $item ] = $sanitizer->clean($value);
107
-        }
108
-    }
96
+	/**
97
+	 * Sanitize the array of billing form data.
98
+	 *
99
+	 * @param array $billing_info
100
+	 * @return void
101
+	 */
102
+	public function sanitizeRequestParameters(array $billing_info): void
103
+	{
104
+		$sanitizer       = new RequestSanitizer(new Basic());
105
+		foreach ($billing_info as $item => $value) {
106
+			$this->billing_info[ $item ] = $sanitizer->clean($value);
107
+		}
108
+	}
109 109
 
110 110
 
111
-    /**
112
-     * Create PayPal Order.
113
-     *
114
-     * @return array
115
-     * @throws EE_Error
116
-     * @throws ReflectionException
117
-     */
118
-    public function create(): array
119
-    {
120
-        $order_parameters = $this->getParameters();
121
-        // Create Order request.
122
-        $create_response = $this->api->sendRequest($order_parameters, $this->request_url);
123
-        return $this->validateOrder($create_response, $order_parameters);
124
-    }
111
+	/**
112
+	 * Create PayPal Order.
113
+	 *
114
+	 * @return array
115
+	 * @throws EE_Error
116
+	 * @throws ReflectionException
117
+	 */
118
+	public function create(): array
119
+	{
120
+		$order_parameters = $this->getParameters();
121
+		// Create Order request.
122
+		$create_response = $this->api->sendRequest($order_parameters, $this->request_url);
123
+		return $this->validateOrder($create_response, $order_parameters);
124
+	}
125 125
 
126 126
 
127
-    /**
128
-     * Form order parameters.
129
-     *
130
-     * @return array
131
-     * @throws EE_Error
132
-     * @throws ReflectionException
133
-     * @throws Exception
134
-     */
135
-    protected function getParameters(): array
136
-    {
137
-        $registrant  = $this->transaction->primary_registration();
138
-        $attendee    = $registrant->attendee();
139
-        $event       = $registrant->event();
140
-        $description = $event->name() ?: sprintf(
141
-            esc_html__('Tickets for an event at %1$s', 'event_espresso'),
142
-            get_bloginfo('name')
143
-        );
144
-        $parameters  = [
145
-            'intent'              => 'CAPTURE',
146
-            'purchase_units'      => [
147
-                [
148
-                    'custom_id'   => $this->transaction->ID(),
149
-                    'description' => substr(wp_strip_all_tags($description), 0, 125),
150
-                    'items'       => $this->getLineItems(),
151
-                    'amount'      => [
152
-                        'value'         => $this->transaction->remaining(),
153
-                        'currency_code' => $this->currency_code,
154
-                        'breakdown'     => $this->getBreakdown(),
155
-                    ],
156
-                ],
157
-            ],
158
-            'application_context' => [
159
-                'shipping_preference' => 'NO_SHIPPING',
160
-                'user_action'         => 'PAY_NOW',
161
-            ],
162
-            'payer'               => [
163
-                'email_address' => $attendee->email(),
164
-                'name'          => [
165
-                    'given_name' => $attendee->fname(),
166
-                    'surname'    => $attendee->lname(),
127
+	/**
128
+	 * Form order parameters.
129
+	 *
130
+	 * @return array
131
+	 * @throws EE_Error
132
+	 * @throws ReflectionException
133
+	 * @throws Exception
134
+	 */
135
+	protected function getParameters(): array
136
+	{
137
+		$registrant  = $this->transaction->primary_registration();
138
+		$attendee    = $registrant->attendee();
139
+		$event       = $registrant->event();
140
+		$description = $event->name() ?: sprintf(
141
+			esc_html__('Tickets for an event at %1$s', 'event_espresso'),
142
+			get_bloginfo('name')
143
+		);
144
+		$parameters  = [
145
+			'intent'              => 'CAPTURE',
146
+			'purchase_units'      => [
147
+				[
148
+					'custom_id'   => $this->transaction->ID(),
149
+					'description' => substr(wp_strip_all_tags($description), 0, 125),
150
+					'items'       => $this->getLineItems(),
151
+					'amount'      => [
152
+						'value'         => $this->transaction->remaining(),
153
+						'currency_code' => $this->currency_code,
154
+						'breakdown'     => $this->getBreakdown(),
155
+					],
156
+				],
157
+			],
158
+			'application_context' => [
159
+				'shipping_preference' => 'NO_SHIPPING',
160
+				'user_action'         => 'PAY_NOW',
161
+			],
162
+			'payer'               => [
163
+				'email_address' => $attendee->email(),
164
+				'name'          => [
165
+					'given_name' => $attendee->fname(),
166
+					'surname'    => $attendee->lname(),
167 167
 
168
-                ],
169
-            ],
170
-        ];
171
-        // Do we have the permissions for the fees ?
172
-        $scopes = PayPalExtraMetaManager::getPmOption(
173
-            $this->transaction->payment_method(),
174
-            Domain::META_KEY_AUTHORIZED_SCOPES
175
-        );
176
-        if (
177
-            (
178
-                (defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES)
179
-                || (! defined('EE_PPC_USE_PAYMENT_FEES')
180
-                    && $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES)
181
-                )
182
-            )
183
-            && ! empty($scopes) && in_array('partnerfee', $scopes)
184
-        ) {
185
-            /** @var PartnerPaymentFees $payment_fees */
186
-            $payment_fees                                           = LoaderFactory::getShared(PartnerPaymentFees::class);
187
-            $parameters['purchase_units'][0]['payment_instruction'] = [
188
-                'platform_fees' => [
189
-                    [
190
-                        'amount' => [
191
-                            'value'         => (string) $payment_fees->getPartnerFee($this->transaction),
192
-                            'currency_code' => $this->currency_code,
193
-                        ],
194
-                    ],
195
-                ]
196
-            ];
197
-        }
198
-        return $parameters;
199
-    }
168
+				],
169
+			],
170
+		];
171
+		// Do we have the permissions for the fees ?
172
+		$scopes = PayPalExtraMetaManager::getPmOption(
173
+			$this->transaction->payment_method(),
174
+			Domain::META_KEY_AUTHORIZED_SCOPES
175
+		);
176
+		if (
177
+			(
178
+				(defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES)
179
+				|| (! defined('EE_PPC_USE_PAYMENT_FEES')
180
+					&& $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES)
181
+				)
182
+			)
183
+			&& ! empty($scopes) && in_array('partnerfee', $scopes)
184
+		) {
185
+			/** @var PartnerPaymentFees $payment_fees */
186
+			$payment_fees                                           = LoaderFactory::getShared(PartnerPaymentFees::class);
187
+			$parameters['purchase_units'][0]['payment_instruction'] = [
188
+				'platform_fees' => [
189
+					[
190
+						'amount' => [
191
+							'value'         => (string) $payment_fees->getPartnerFee($this->transaction),
192
+							'currency_code' => $this->currency_code,
193
+						],
194
+					],
195
+				]
196
+			];
197
+		}
198
+		return $parameters;
199
+	}
200 200
 
201 201
 
202
-    /**
203
-     * Itemize the payment. List all the line items, discounts and taxes.
204
-     *
205
-     * @return array
206
-     * @throws EE_Error|ReflectionException
207
-     */
208
-    protected function getLineItems(): array
209
-    {
210
-        // Order line items.
211
-        $line_items       = [];
212
-        $event_line_items = $this->transaction->items_purchased();
213
-        // List actual line items.
214
-        foreach ($event_line_items as $line_item) {
215
-            if (
216
-                $line_item instanceof EE_Line_Item
217
-                && $line_item->OBJ_type() !== 'Promotion'
218
-                && $line_item->quantity() > 0
219
-            ) {
220
-                $item_money     = $line_item->unit_price();
221
-                $li_description = $line_item->desc() ?? esc_html__('Event Ticket', 'event_espresso');
222
-                $line_items []  = [
223
-                    'name'        => substr(wp_strip_all_tags($line_item->name()), 0, 126),
224
-                    'quantity'    => $line_item->quantity(),
225
-                    'description' => substr(wp_strip_all_tags($li_description), 0, 125),
226
-                    'unit_amount' => [
227
-                        'currency_code' => $this->currency_code,
228
-                        'value'         => $item_money,
229
-                    ],
230
-                    'category'    => 'DIGITAL_GOODS',
231
-                ];
232
-                // Line item total.
233
-                $this->items_total += $line_item->pretaxTotal();
234
-            } elseif ($line_item->OBJ_type() === 'Promotion' && $line_item->quantity() > 0) {
235
-                // Promotions total.
236
-                $this->promos_total += $line_item->total();
237
-            }
238
-        }
239
-        // Make sure we have an absolute number with only two decimal laces.
240
-        $this->items_total  = CurrencyManager::normalizeValue($this->items_total);
241
-        $this->promos_total = CurrencyManager::normalizeValue($this->promos_total);
242
-        // If this is a partial payment, apply the paid amount as a promo.
243
-        if ($this->transaction->paid() > 0) {
244
-            $this->promos_total += CurrencyManager::normalizeValue($this->transaction->paid());
245
-        }
246
-        $this->countTaxTotal();
247
-        return $line_items;
248
-    }
202
+	/**
203
+	 * Itemize the payment. List all the line items, discounts and taxes.
204
+	 *
205
+	 * @return array
206
+	 * @throws EE_Error|ReflectionException
207
+	 */
208
+	protected function getLineItems(): array
209
+	{
210
+		// Order line items.
211
+		$line_items       = [];
212
+		$event_line_items = $this->transaction->items_purchased();
213
+		// List actual line items.
214
+		foreach ($event_line_items as $line_item) {
215
+			if (
216
+				$line_item instanceof EE_Line_Item
217
+				&& $line_item->OBJ_type() !== 'Promotion'
218
+				&& $line_item->quantity() > 0
219
+			) {
220
+				$item_money     = $line_item->unit_price();
221
+				$li_description = $line_item->desc() ?? esc_html__('Event Ticket', 'event_espresso');
222
+				$line_items []  = [
223
+					'name'        => substr(wp_strip_all_tags($line_item->name()), 0, 126),
224
+					'quantity'    => $line_item->quantity(),
225
+					'description' => substr(wp_strip_all_tags($li_description), 0, 125),
226
+					'unit_amount' => [
227
+						'currency_code' => $this->currency_code,
228
+						'value'         => $item_money,
229
+					],
230
+					'category'    => 'DIGITAL_GOODS',
231
+				];
232
+				// Line item total.
233
+				$this->items_total += $line_item->pretaxTotal();
234
+			} elseif ($line_item->OBJ_type() === 'Promotion' && $line_item->quantity() > 0) {
235
+				// Promotions total.
236
+				$this->promos_total += $line_item->total();
237
+			}
238
+		}
239
+		// Make sure we have an absolute number with only two decimal laces.
240
+		$this->items_total  = CurrencyManager::normalizeValue($this->items_total);
241
+		$this->promos_total = CurrencyManager::normalizeValue($this->promos_total);
242
+		// If this is a partial payment, apply the paid amount as a promo.
243
+		if ($this->transaction->paid() > 0) {
244
+			$this->promos_total += CurrencyManager::normalizeValue($this->transaction->paid());
245
+		}
246
+		$this->countTaxTotal();
247
+		return $line_items;
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * Count the tax total.
253
-     *
254
-     * @return void
255
-     * @throws EE_Error|ReflectionException
256
-     */
257
-    protected function countTaxTotal(): void
258
-    {
259
-        // List taxes.
260
-        $this->tax_total = 0.0;
261
-        $tax_items       = $this->transaction->tax_items();
262
-        foreach ($tax_items as $tax_item) {
263
-            $this->tax_total += $tax_item->total();
264
-        }
265
-        $this->tax_total = CurrencyManager::normalizeValue($this->tax_total);
266
-    }
251
+	/**
252
+	 * Count the tax total.
253
+	 *
254
+	 * @return void
255
+	 * @throws EE_Error|ReflectionException
256
+	 */
257
+	protected function countTaxTotal(): void
258
+	{
259
+		// List taxes.
260
+		$this->tax_total = 0.0;
261
+		$tax_items       = $this->transaction->tax_items();
262
+		foreach ($tax_items as $tax_item) {
263
+			$this->tax_total += $tax_item->total();
264
+		}
265
+		$this->tax_total = CurrencyManager::normalizeValue($this->tax_total);
266
+	}
267 267
 
268 268
 
269
-    /**
270
-     * Itemize the payment the breakdown list.
271
-     *
272
-     * @return array
273
-     */
274
-    protected function getBreakdown(): array
275
-    {
276
-        $breakdown['item_total'] = [
277
-            'currency_code' => $this->currency_code,
278
-            'value'         => $this->items_total,
279
-        ];
280
-        $breakdown['tax_total']  = [
281
-            'currency_code' => $this->currency_code,
282
-            'value'         => $this->tax_total,
283
-        ];
284
-        $breakdown['discount']   = [
285
-            'currency_code' => $this->currency_code,
286
-            'value'         => abs($this->promos_total),
287
-        ];
288
-        return $breakdown;
289
-    }
269
+	/**
270
+	 * Itemize the payment the breakdown list.
271
+	 *
272
+	 * @return array
273
+	 */
274
+	protected function getBreakdown(): array
275
+	{
276
+		$breakdown['item_total'] = [
277
+			'currency_code' => $this->currency_code,
278
+			'value'         => $this->items_total,
279
+		];
280
+		$breakdown['tax_total']  = [
281
+			'currency_code' => $this->currency_code,
282
+			'value'         => $this->tax_total,
283
+		];
284
+		$breakdown['discount']   = [
285
+			'currency_code' => $this->currency_code,
286
+			'value'         => abs($this->promos_total),
287
+		];
288
+		return $breakdown;
289
+	}
290 290
 
291 291
 
292
-    /**
293
-     * Makes sure that we have received an Order back from the API call.
294
-     *
295
-     * @param $response
296
-     * @param $parameters
297
-     * @return array
298
-     * @throws EE_Error
299
-     * @throws ReflectionException
300
-     */
301
-    public function validateOrder($response, $parameters): array
302
-    {
303
-        PayPalLogger::errorLog(
304
-            esc_html__('Validating Order Create:', 'event_espresso'),
305
-            [$this->request_url, $response],
306
-            $this->transaction->payment_method(),
307
-            false,
308
-            $this->transaction
309
-        );
310
-        if (! empty($response['error'])) {
311
-            return $response;
312
-        }
313
-        if (! isset($response['id'])) {
314
-            $message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso');
315
-            try {
316
-                PayPalLogger::errorLog(
317
-                    $message,
318
-                    [$this->request_url, $parameters, $response],
319
-                    $this->transaction->payment_method()
320
-                );
321
-            } catch (EE_Error | ReflectionException $e) {
322
-                error_log("PayPalLogger Error: $message: " . json_encode($response));
323
-            }
324
-            return [
325
-                'error'   => $response['error'] ?? 'missing_order',
326
-                'message' => $response['message'] ?? $message,
327
-            ];
328
-        }
329
-        return $response;
330
-    }
292
+	/**
293
+	 * Makes sure that we have received an Order back from the API call.
294
+	 *
295
+	 * @param $response
296
+	 * @param $parameters
297
+	 * @return array
298
+	 * @throws EE_Error
299
+	 * @throws ReflectionException
300
+	 */
301
+	public function validateOrder($response, $parameters): array
302
+	{
303
+		PayPalLogger::errorLog(
304
+			esc_html__('Validating Order Create:', 'event_espresso'),
305
+			[$this->request_url, $response],
306
+			$this->transaction->payment_method(),
307
+			false,
308
+			$this->transaction
309
+		);
310
+		if (! empty($response['error'])) {
311
+			return $response;
312
+		}
313
+		if (! isset($response['id'])) {
314
+			$message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso');
315
+			try {
316
+				PayPalLogger::errorLog(
317
+					$message,
318
+					[$this->request_url, $parameters, $response],
319
+					$this->transaction->payment_method()
320
+				);
321
+			} catch (EE_Error | ReflectionException $e) {
322
+				error_log("PayPalLogger Error: $message: " . json_encode($response));
323
+			}
324
+			return [
325
+				'error'   => $response['error'] ?? 'missing_order',
326
+				'message' => $response['message'] ?? $message,
327
+			];
328
+		}
329
+		return $response;
330
+	}
331 331
 }
Please login to merge, or discard this patch.
espresso.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -37,138 +37,138 @@
 block discarded – undo
37 37
  * @since       4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time.
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time.
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
 <div class="error">
49 49
     <p>
50 50
         <?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
     </p>
56 56
 </div>
57 57
 <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
 <div class="error">
74 74
     <p>
75 75
         <?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
-                    );
86
-        ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
+					);
86
+		?>
87 87
     </p>
88 88
 </div>
89 89
 <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96 96
 
97
-        require_once __DIR__ . '/vendor/autoload.php';
97
+		require_once __DIR__ . '/vendor/autoload.php';
98 98
 
99
-        /**
100
-         * espresso_version
101
-         * Returns the plugin version
102
-         *
103
-         * @return string
104
-         */
105
-        function espresso_version(): string
106
-        {
107
-            return apply_filters('FHEE__espresso__espresso_version', '5.0.31.rc.000');
108
-        }
99
+		/**
100
+		 * espresso_version
101
+		 * Returns the plugin version
102
+		 *
103
+		 * @return string
104
+		 */
105
+		function espresso_version(): string
106
+		{
107
+			return apply_filters('FHEE__espresso__espresso_version', '5.0.31.rc.000');
108
+		}
109 109
 
110
-        /**
111
-         * espresso_plugin_activation
112
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
-         */
114
-        function espresso_plugin_activation()
115
-        {
116
-            update_option('ee_espresso_activation', true);
117
-            update_option('event-espresso-core_allow_tracking', 'no');
118
-            update_option('event-espresso-core_tracking_notice', 'hide');
119
-            // Run WP GraphQL activation callback
120
-            espressoLoadWpGraphQL();
121
-            graphql_activation_callback();
122
-        }
110
+		/**
111
+		 * espresso_plugin_activation
112
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
+		 */
114
+		function espresso_plugin_activation()
115
+		{
116
+			update_option('ee_espresso_activation', true);
117
+			update_option('event-espresso-core_allow_tracking', 'no');
118
+			update_option('event-espresso-core_tracking_notice', 'hide');
119
+			// Run WP GraphQL activation callback
120
+			espressoLoadWpGraphQL();
121
+			graphql_activation_callback();
122
+		}
123 123
 
124
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
124
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
125 125
 
126
-        /**
127
-         * espresso_plugin_deactivation
128
-         */
129
-        function espresso_plugin_deactivation()
130
-        {
131
-            // Run WP GraphQL deactivation callback
132
-            espressoLoadWpGraphQL();
133
-            graphql_deactivation_callback();
134
-            delete_option('event-espresso-core_allow_tracking');
135
-            delete_option('event-espresso-core_tracking_notice');
136
-        }
137
-        register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
126
+		/**
127
+		 * espresso_plugin_deactivation
128
+		 */
129
+		function espresso_plugin_deactivation()
130
+		{
131
+			// Run WP GraphQL deactivation callback
132
+			espressoLoadWpGraphQL();
133
+			graphql_deactivation_callback();
134
+			delete_option('event-espresso-core_allow_tracking');
135
+			delete_option('event-espresso-core_tracking_notice');
136
+		}
137
+		register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
138 138
 
139
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
140
-        bootstrap_espresso();
141
-    }
139
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
140
+		bootstrap_espresso();
141
+	}
142 142
 }
143 143
 
144 144
 if (! function_exists('espresso_deactivate_plugin')) {
145
-    /**
146
-     *    deactivate_plugin
147
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
-     *
149
-     * @access public
150
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
-     * @return    void
152
-     */
153
-    function espresso_deactivate_plugin(string $plugin_basename = '')
154
-    {
155
-        if (! function_exists('deactivate_plugins')) {
156
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
-        }
158
-        unset($_GET['activate'], $_REQUEST['activate']);
159
-        deactivate_plugins($plugin_basename);
160
-    }
145
+	/**
146
+	 *    deactivate_plugin
147
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
+	 *
149
+	 * @access public
150
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
+	 * @return    void
152
+	 */
153
+	function espresso_deactivate_plugin(string $plugin_basename = '')
154
+	{
155
+		if (! function_exists('deactivate_plugins')) {
156
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
+		}
158
+		unset($_GET['activate'], $_REQUEST['activate']);
159
+		deactivate_plugins($plugin_basename);
160
+	}
161 161
 }
162 162
 
163 163
 
164 164
 if (! function_exists('espressoLoadWpGraphQL')) {
165
-    function espressoLoadWpGraphQL()
166
-    {
167
-        if (
168
-            ! class_exists('WPGraphQL')
169
-            && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
-        ) {
171
-            require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
-        }
173
-    }
165
+	function espressoLoadWpGraphQL()
166
+	{
167
+		if (
168
+			! class_exists('WPGraphQL')
169
+			&& is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
+		) {
171
+			require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
+		}
173
+	}
174 174
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
  * @since       4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
40
+    if ( ! function_exists('espresso_duplicate_plugin_error')) {
41 41
         /**
42 42
          *    espresso_duplicate_plugin_error
43 43
          *    displays if more than one version of EE is activated at the same time.
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63 63
     define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
64
+    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65 65
         /**
66 66
          * espresso_minimum_php_version_error
67 67
          *
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     } else {
95 95
         define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96 96
 
97
-        require_once __DIR__ . '/vendor/autoload.php';
97
+        require_once __DIR__.'/vendor/autoload.php';
98 98
 
99 99
         /**
100 100
          * espresso_version
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
         }
137 137
         register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
138 138
 
139
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
139
+        require_once __DIR__.'/core/bootstrap_espresso.php';
140 140
         bootstrap_espresso();
141 141
     }
142 142
 }
143 143
 
144
-if (! function_exists('espresso_deactivate_plugin')) {
144
+if ( ! function_exists('espresso_deactivate_plugin')) {
145 145
     /**
146 146
      *    deactivate_plugin
147 147
      * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
      */
153 153
     function espresso_deactivate_plugin(string $plugin_basename = '')
154 154
     {
155
-        if (! function_exists('deactivate_plugins')) {
156
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
155
+        if ( ! function_exists('deactivate_plugins')) {
156
+            require_once ABSPATH.'wp-admin/includes/plugin.php';
157 157
         }
158 158
         unset($_GET['activate'], $_REQUEST['activate']);
159 159
         deactivate_plugins($plugin_basename);
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
 }
162 162
 
163 163
 
164
-if (! function_exists('espressoLoadWpGraphQL')) {
164
+if ( ! function_exists('espressoLoadWpGraphQL')) {
165 165
     function espressoLoadWpGraphQL()
166 166
     {
167 167
         if (
168 168
             ! class_exists('WPGraphQL')
169
-            && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
169
+            && is_readable(__DIR__.'/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170 170
         ) {
171
-            require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
171
+            require_once __DIR__.'/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172 172
         }
173 173
     }
174 174
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Relationship.model.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -9,236 +9,236 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Term_Relationship extends EEM_Base
11 11
 {
12
-    protected static ?EEM_Term_Relationship $_instance = null;
12
+	protected static ?EEM_Term_Relationship $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * EEM_Term_Relationship constructor.
17
-     *
18
-     * @param string|null $timezone
19
-     * @throws EE_Error
20
-     */
21
-    protected function __construct(?string $timezone = '')
22
-    {
23
-        $this->singular_item       = esc_html__('Term Relationship', 'event_espresso');
24
-        $this->plural_item         = esc_html__('Term Relationships', 'event_espresso');
25
-        $this->_tables             = [
26
-            'Term_Relationship' => new EE_Primary_Table('term_relationships'),
27
-        ];
28
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
29
-        $this->_fields             = [
30
-            'Term_Relationship' => [
31
-                'object_id'        => new EE_Foreign_Key_Int_Field(
32
-                    'object_id',
33
-                    esc_html__('Object(Post) ID', 'event_espresso'),
34
-                    false,
35
-                    0,
36
-                    $models_this_can_attach_to
37
-                ),
38
-                'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
39
-                    'term_taxonomy_id',
40
-                    esc_html__(
41
-                        'Term (in context of a taxonomy) ID',
42
-                        'event_espresso'
43
-                    ),
44
-                    false,
45
-                    0,
46
-                    'Term_Taxonomy'
47
-                ),
48
-                'term_order'       => new EE_Integer_Field(
49
-                    'term_order',
50
-                    esc_html__('Term Order', 'event_espresso'),
51
-                    false,
52
-                    0
53
-                ),
54
-            ],
55
-        ];
56
-        $this->_model_relations    = [
57
-            'Term_Taxonomy' => new EE_Belongs_To_Relation(),
58
-        ];
59
-        foreach ($models_this_can_attach_to as $model_name) {
60
-            $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
61
-        }
62
-        $this->_wp_core_model                                           = true;
63
-        $this->_indexes                                                 = [
64
-            'PRIMARY' => new EE_Primary_Key_Index(['object_id', 'term_taxonomy_id']),
65
-        ];
66
-        $path_to_event_model                                            = 'Event';
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
68
-            new EE_Restriction_Generator_Event_Related_Public(
69
-                $path_to_event_model
70
-            );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
72
-            new EE_Restriction_Generator_Event_Related_Protected(
73
-                $path_to_event_model
74
-            );
75
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
76
-            new EE_Restriction_Generator_Event_Related_Protected(
77
-                $path_to_event_model
78
-            );
79
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
80
-            new EE_Restriction_Generator_Event_Related_Protected(
81
-                $path_to_event_model,
82
-                EEM_Base::caps_edit
83
-            );
84
-        $path_to_tax_model                                              = 'Term_Taxonomy.';
85
-        // add cap restrictions for editing term relations to the "ee_assign_*"
86
-        // and for deleting term relations too
87
-        $cap_contexts_affected = [EEM_Base::caps_edit, EEM_Base::caps_delete];
88
-        foreach ($cap_contexts_affected as $cap_context_affected) {
89
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
90
-                new EE_Default_Where_Conditions(
91
-                    [
92
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_category' => [
93
-                            '!=',
94
-                            'espresso_event_categories',
95
-                        ],
96
-                    ]
97
-                );
98
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
99
-                new EE_Default_Where_Conditions(
100
-                    [
101
-                        $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => [
102
-                            '!=',
103
-                            'espresso_venue_categories',
104
-                        ],
105
-                    ]
106
-                );
107
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type']     =
108
-                new EE_Default_Where_Conditions(
109
-                    [
110
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_type' => ['!=', 'espresso_event_type'],
111
-                    ]
112
-                );
113
-        }
114
-        parent::__construct($timezone);
115
-        add_filter(
116
-            'FHEE__Read__create_model_query_params',
117
-            ['EEM_Term_Relationship', 'rest_api_query_params'],
118
-            10,
119
-            3
120
-        );
121
-    }
15
+	/**
16
+	 * EEM_Term_Relationship constructor.
17
+	 *
18
+	 * @param string|null $timezone
19
+	 * @throws EE_Error
20
+	 */
21
+	protected function __construct(?string $timezone = '')
22
+	{
23
+		$this->singular_item       = esc_html__('Term Relationship', 'event_espresso');
24
+		$this->plural_item         = esc_html__('Term Relationships', 'event_espresso');
25
+		$this->_tables             = [
26
+			'Term_Relationship' => new EE_Primary_Table('term_relationships'),
27
+		];
28
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
29
+		$this->_fields             = [
30
+			'Term_Relationship' => [
31
+				'object_id'        => new EE_Foreign_Key_Int_Field(
32
+					'object_id',
33
+					esc_html__('Object(Post) ID', 'event_espresso'),
34
+					false,
35
+					0,
36
+					$models_this_can_attach_to
37
+				),
38
+				'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
39
+					'term_taxonomy_id',
40
+					esc_html__(
41
+						'Term (in context of a taxonomy) ID',
42
+						'event_espresso'
43
+					),
44
+					false,
45
+					0,
46
+					'Term_Taxonomy'
47
+				),
48
+				'term_order'       => new EE_Integer_Field(
49
+					'term_order',
50
+					esc_html__('Term Order', 'event_espresso'),
51
+					false,
52
+					0
53
+				),
54
+			],
55
+		];
56
+		$this->_model_relations    = [
57
+			'Term_Taxonomy' => new EE_Belongs_To_Relation(),
58
+		];
59
+		foreach ($models_this_can_attach_to as $model_name) {
60
+			$this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
61
+		}
62
+		$this->_wp_core_model                                           = true;
63
+		$this->_indexes                                                 = [
64
+			'PRIMARY' => new EE_Primary_Key_Index(['object_id', 'term_taxonomy_id']),
65
+		];
66
+		$path_to_event_model                                            = 'Event';
67
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
68
+			new EE_Restriction_Generator_Event_Related_Public(
69
+				$path_to_event_model
70
+			);
71
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
72
+			new EE_Restriction_Generator_Event_Related_Protected(
73
+				$path_to_event_model
74
+			);
75
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
76
+			new EE_Restriction_Generator_Event_Related_Protected(
77
+				$path_to_event_model
78
+			);
79
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
80
+			new EE_Restriction_Generator_Event_Related_Protected(
81
+				$path_to_event_model,
82
+				EEM_Base::caps_edit
83
+			);
84
+		$path_to_tax_model                                              = 'Term_Taxonomy.';
85
+		// add cap restrictions for editing term relations to the "ee_assign_*"
86
+		// and for deleting term relations too
87
+		$cap_contexts_affected = [EEM_Base::caps_edit, EEM_Base::caps_delete];
88
+		foreach ($cap_contexts_affected as $cap_context_affected) {
89
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
90
+				new EE_Default_Where_Conditions(
91
+					[
92
+						$path_to_tax_model . 'taxonomy*ee_assign_event_category' => [
93
+							'!=',
94
+							'espresso_event_categories',
95
+						],
96
+					]
97
+				);
98
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
99
+				new EE_Default_Where_Conditions(
100
+					[
101
+						$path_to_tax_model . 'taxonomy*ee_assign_venue_category' => [
102
+							'!=',
103
+							'espresso_venue_categories',
104
+						],
105
+					]
106
+				);
107
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type']     =
108
+				new EE_Default_Where_Conditions(
109
+					[
110
+						$path_to_tax_model . 'taxonomy*ee_assign_event_type' => ['!=', 'espresso_event_type'],
111
+					]
112
+				);
113
+		}
114
+		parent::__construct($timezone);
115
+		add_filter(
116
+			'FHEE__Read__create_model_query_params',
117
+			['EEM_Term_Relationship', 'rest_api_query_params'],
118
+			10,
119
+			3
120
+		);
121
+	}
122 122
 
123 123
 
124
-    /**
125
-     * Makes sure all term-taxonomy counts are correct
126
-     *
127
-     * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
128
-     * @return int the number of rows affected
129
-     * @throws EE_Error
130
-     * @global wpdb $wpdb
131
-     */
132
-    public function update_term_taxonomy_counts($term_taxonomy_id = null)
133
-    {
134
-        // because this uses a subquery and sometimes assigning to column to be another column's
135
-        // value, we just write the SQL directly.
136
-        global $wpdb;
124
+	/**
125
+	 * Makes sure all term-taxonomy counts are correct
126
+	 *
127
+	 * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
128
+	 * @return int the number of rows affected
129
+	 * @throws EE_Error
130
+	 * @global wpdb $wpdb
131
+	 */
132
+	public function update_term_taxonomy_counts($term_taxonomy_id = null)
133
+	{
134
+		// because this uses a subquery and sometimes assigning to column to be another column's
135
+		// value, we just write the SQL directly.
136
+		global $wpdb;
137 137
 
138
-        $query = "
138
+		$query = "
139 139
                 UPDATE {$wpdb->term_taxonomy} AS tt
140 140
                 SET count = (
141 141
                     select count(*) as proper_count from {$wpdb->term_relationships} AS tr
142 142
                     WHERE tt.term_taxonomy_id = tr.term_taxonomy_id
143 143
                 )";
144 144
 
145
-        if ($term_taxonomy_id) {
146
-            $query .= ' WHERE tt.term_taxonomy_id = %d';
147
-            $query = $wpdb->prepare(
148
-                $query,
149
-                $term_taxonomy_id
150
-            );
151
-        }
152
-        $rows_affected = $this->_do_wpdb_query(
153
-            'query',
154
-            [
155
-                $query,
156
-            ]
157
-        );
158
-        return $rows_affected;
159
-    }
145
+		if ($term_taxonomy_id) {
146
+			$query .= ' WHERE tt.term_taxonomy_id = %d';
147
+			$query = $wpdb->prepare(
148
+				$query,
149
+				$term_taxonomy_id
150
+			);
151
+		}
152
+		$rows_affected = $this->_do_wpdb_query(
153
+			'query',
154
+			[
155
+				$query,
156
+			]
157
+		);
158
+		return $rows_affected;
159
+	}
160 160
 
161 161
 
162
-    /**
163
-     * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
164
-     * inserting
165
-     *
166
-     * @param array $field_n_values @see EEM_Base::insert
167
-     * @return boolean
168
-     */
169
-    public function insert($field_n_values)
170
-    {
171
-        $return = parent::insert($field_n_values);
172
-        if (isset($field_n_values['term_taxonomy_id'])) {
173
-            $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
174
-        }
175
-        return $return;
176
-    }
162
+	/**
163
+	 * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
164
+	 * inserting
165
+	 *
166
+	 * @param array $field_n_values @see EEM_Base::insert
167
+	 * @return boolean
168
+	 */
169
+	public function insert($field_n_values)
170
+	{
171
+		$return = parent::insert($field_n_values);
172
+		if (isset($field_n_values['term_taxonomy_id'])) {
173
+			$this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
174
+		}
175
+		return $return;
176
+	}
177 177
 
178 178
 
179
-    /**
180
-     * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
-     * all ok
182
-     *
183
-     * @param array   $fields_n_values         see EEM_Base::update
184
-     * @param array   $query_params            @see
185
-     *                                         https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
186
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
187
-     *                                         in this model's entity map according to $fields_n_values that match
188
-     *                                         $query_params. This obviously has some overhead, so you can disable it
189
-     *                                         by setting this to FALSE, but be aware that model objects being used
190
-     *                                         could get out-of-sync with the database
191
-     * @return int
192
-     */
193
-    public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
194
-    {
195
-        $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
196
-        if ($count) {
197
-            $this->update_term_taxonomy_counts();
198
-        }
199
-        return $count;
200
-    }
179
+	/**
180
+	 * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
+	 * all ok
182
+	 *
183
+	 * @param array   $fields_n_values         see EEM_Base::update
184
+	 * @param array   $query_params            @see
185
+	 *                                         https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
186
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
187
+	 *                                         in this model's entity map according to $fields_n_values that match
188
+	 *                                         $query_params. This obviously has some overhead, so you can disable it
189
+	 *                                         by setting this to FALSE, but be aware that model objects being used
190
+	 *                                         could get out-of-sync with the database
191
+	 * @return int
192
+	 */
193
+	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
194
+	{
195
+		$count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
196
+		if ($count) {
197
+			$this->update_term_taxonomy_counts();
198
+		}
199
+		return $count;
200
+	}
201 201
 
202 202
 
203
-    /**
204
-     * Overrides parent so that after running this, we also double-check
205
-     * the term taxonomy counts are up-to-date
206
-     *
207
-     * @param array   $query_params
208
-     * @param boolean $block_deletes
209
-     * @return int
210
-     * @throws EE_Error
211
-     * @throws ReflectionException
212
-     * @see EEM_Base::delete()
213
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
214
-     */
215
-    public function delete($query_params, $block_deletes = true)
216
-    {
217
-        $count = parent::delete($query_params, $block_deletes);
218
-        if ($count) {
219
-            $this->update_term_taxonomy_counts();
220
-        }
221
-        return $count;
222
-    }
203
+	/**
204
+	 * Overrides parent so that after running this, we also double-check
205
+	 * the term taxonomy counts are up-to-date
206
+	 *
207
+	 * @param array   $query_params
208
+	 * @param boolean $block_deletes
209
+	 * @return int
210
+	 * @throws EE_Error
211
+	 * @throws ReflectionException
212
+	 * @see EEM_Base::delete()
213
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
214
+	 */
215
+	public function delete($query_params, $block_deletes = true)
216
+	{
217
+		$count = parent::delete($query_params, $block_deletes);
218
+		if ($count) {
219
+			$this->update_term_taxonomy_counts();
220
+		}
221
+		return $count;
222
+	}
223 223
 
224 224
 
225
-    /**
226
-     * Makes sure that during REST API queries, we only return term relationships
227
-     * for term taxonomies which should be shown in the rest api
228
-     *
229
-     * @param array    $model_query_params
230
-     * @param array    $querystring_query_params
231
-     * @param EEM_Base $model
232
-     * @return array
233
-     */
234
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
235
-    {
236
-        if ($model === EEM_Term_Relationship::instance()) {
237
-            $taxonomies = get_taxonomies(['show_in_rest' => true]);
238
-            if (! empty($taxonomies)) {
239
-                $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies];
240
-            }
241
-        }
242
-        return $model_query_params;
243
-    }
225
+	/**
226
+	 * Makes sure that during REST API queries, we only return term relationships
227
+	 * for term taxonomies which should be shown in the rest api
228
+	 *
229
+	 * @param array    $model_query_params
230
+	 * @param array    $querystring_query_params
231
+	 * @param EEM_Base $model
232
+	 * @return array
233
+	 */
234
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
235
+	{
236
+		if ($model === EEM_Term_Relationship::instance()) {
237
+			$taxonomies = get_taxonomies(['show_in_rest' => true]);
238
+			if (! empty($taxonomies)) {
239
+				$model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies];
240
+			}
241
+		}
242
+		return $model_query_params;
243
+	}
244 244
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Question.model.php 1 patch
Indentation   +577 added lines, -577 removed lines patch added patch discarded remove patch
@@ -10,581 +10,581 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Question extends EEM_Soft_Delete_Base
12 12
 {
13
-    // constant used to indicate that the question type is CHECKBOX
14
-    const QST_type_checkbox = 'CHECKBOX';
15
-
16
-    // constant used to indicate that the question type is COUNTRY
17
-    const QST_type_country = 'COUNTRY';
18
-
19
-    // constant used to indicate that the question type is DATE
20
-    const QST_type_date = 'DATE';
21
-
22
-    // constant used to indicate that the question type is a decimal (float)
23
-    const QST_type_decimal = 'DECIMAL';
24
-
25
-    // constant used to indicate that the question type is DROPDOWN
26
-    const QST_type_dropdown = 'DROPDOWN';
27
-
28
-    // constant used to indicate that the question type is an email input
29
-    const QST_type_email = 'EMAIL';
30
-
31
-    // constant used to indicate that the question type is an email input
32
-    const QST_type_email_confirm = 'EMAIL_CONFIRM';
33
-
34
-    // constant used to indicate that the question type is a TEXTAREA that allows simple html
35
-    const QST_type_html_textarea = 'HTML_TEXTAREA';
36
-
37
-    // constant used to indicate that the question type is an integer (whole number)
38
-    const QST_type_int = 'INTEGER';
39
-
40
-    // constant used to indicate that the question type is a multi-select
41
-    const QST_type_multi_select = 'MULTI_SELECT';
42
-
43
-    // constant used to indicate that the question type is RADIO_BTN
44
-    const QST_type_radio = 'RADIO_BTN';
45
-
46
-    // constant used to indicate that the question type is STATE
47
-    const QST_type_state = 'STATE';
48
-
49
-    // constant used to indicate that the question type is TEXT
50
-    const QST_type_text = 'TEXT';
51
-
52
-    // constant used to indicate that the question type is TEXTAREA
53
-    const QST_type_textarea = 'TEXTAREA';
54
-
55
-    // constant used to indicate that the question type is a valid URL
56
-    const QST_type_url = 'URL';
57
-
58
-    // constant used to indicate that the question type is a US-formatted phone number
59
-    const QST_type_us_phone = 'US_PHONE';
60
-
61
-    // constant used to indicate that the question type is a YEAR
62
-    const QST_type_year = 'YEAR';
63
-
64
-
65
-    protected static ?EEM_Question $_instance = null;
66
-
67
-    /**
68
-     * lists all the question types which should be allowed. Ideally, this will be extensible.
69
-     */
70
-    protected array $_allowed_question_types;
71
-
72
-    /**
73
-     * brief descriptions for all the question types
74
-     */
75
-    protected array $_question_descriptions;
76
-
77
-    /**
78
-     * Question types that are interchangeable, even after answers have been provided for them.
79
-     * Top-level keys are category slugs, next level is an array of question types. If question types
80
-     * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
81
-     *
82
-     * @var array   $_question_type_categories {
83
-     * @type string $text
84
-     * @type string $single                    -answer-enum
85
-     * @type string $multi                     -answer-enum
86
-     *                                         }
87
-     */
88
-    protected array $_question_type_categories;
89
-
90
-    /**
91
-     * Question types that should have an admin-defined max input length
92
-     */
93
-    protected array $question_types_with_max_length;
94
-
95
-
96
-    /**
97
-     * EEM_Question constructor.
98
-     *
99
-     * @param string|null $timezone
100
-     * @throws EE_Error
101
-     */
102
-    protected function __construct(?string $timezone = '')
103
-    {
104
-        $this->singular_item                  = esc_html__('Question', 'event_espresso');
105
-        $this->plural_item                    = esc_html__('Questions', 'event_espresso');
106
-        $this->_allowed_question_types        = (array) apply_filters(
107
-            'FHEE__EEM_Question__construct__allowed_question_types',
108
-            [
109
-                EEM_Question::QST_type_checkbox      => esc_html__('Checkboxes', 'event_espresso'),
110
-                EEM_Question::QST_type_country       => esc_html__('Country Dropdown', 'event_espresso'),
111
-                EEM_Question::QST_type_date          => esc_html__('Date Picker', 'event_espresso'),
112
-                EEM_Question::QST_type_decimal       => esc_html__('Number', 'event_espresso'),
113
-                EEM_Question::QST_type_dropdown      => esc_html__('Dropdown', 'event_espresso'),
114
-                EEM_Question::QST_type_email         => esc_html__('Email', 'event_espresso'),
115
-                EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
116
-                EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
117
-                EEM_Question::QST_type_int           => esc_html__('Whole Number', 'event_espresso'),
118
-                EEM_Question::QST_type_multi_select  => esc_html__('Multi Select', 'event_espresso'),
119
-                EEM_Question::QST_type_radio         => esc_html__('Radio Buttons', 'event_espresso'),
120
-                EEM_Question::QST_type_state         => esc_html__('State/Province Dropdown', 'event_espresso'),
121
-                EEM_Question::QST_type_text          => esc_html__('Text', 'event_espresso'),
122
-                EEM_Question::QST_type_textarea      => esc_html__('Textarea', 'event_espresso'),
123
-                EEM_Question::QST_type_url           => esc_html__('URL', 'event_espresso'),
124
-                EEM_Question::QST_type_us_phone      => esc_html__('USA - Format Phone', 'event_espresso'),
125
-                EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
126
-            ]
127
-        );
128
-        $this->_question_descriptions         = (array) apply_filters(
129
-            'FHEE__EEM_Question__construct__question_descriptions',
130
-            [
131
-                EEM_Question::QST_type_checkbox      => esc_html__(
132
-                    'Allows multiple preset options to be selected',
133
-                    'event_espresso'
134
-                ),
135
-                EEM_Question::QST_type_country       => esc_html__(
136
-                    'A dropdown that lists countries',
137
-                    'event_espresso'
138
-                ),
139
-                EEM_Question::QST_type_date          => esc_html__(
140
-                    'A popup calendar that allows date selections',
141
-                    'event_espresso'
142
-                ),
143
-                EEM_Question::QST_type_decimal       => esc_html__(
144
-                    'A text field that allows number values with decimals',
145
-                    'event_espresso'
146
-                ),
147
-                EEM_Question::QST_type_dropdown      => esc_html__(
148
-                    'A dropdown that allows a single selection',
149
-                    'event_espresso'
150
-                ),
151
-                EEM_Question::QST_type_email         => esc_html__(
152
-                    'A text field that must contain a valid Email address',
153
-                    'event_espresso'
154
-                ),
155
-                EEM_Question::QST_type_email_confirm => esc_html__(
156
-                    'A text field that must contain a valid Email address and be equal to Email field',
157
-                    'event_espresso'
158
-                ),
159
-                EEM_Question::QST_type_html_textarea => esc_html__(
160
-                    'A multi line text input field that allows HTML',
161
-                    'event_espresso'
162
-                ),
163
-                EEM_Question::QST_type_int           => esc_html__(
164
-                    'A text field that only allows whole numbers (no decimals)',
165
-                    'event_espresso'
166
-                ),
167
-                EEM_Question::QST_type_multi_select  => esc_html__(
168
-                    'A dropdown that allows multiple selections',
169
-                    'event_espresso'
170
-                ),
171
-                EEM_Question::QST_type_radio         => esc_html__(
172
-                    'Allows a single preset option to be selected',
173
-                    'event_espresso'
174
-                ),
175
-                EEM_Question::QST_type_state         => esc_html__(
176
-                    'A dropdown that lists states/provinces',
177
-                    'event_espresso'
178
-                ),
179
-                EEM_Question::QST_type_text          => esc_html__(
180
-                    'A single line text input field',
181
-                    'event_espresso'
182
-                ),
183
-                EEM_Question::QST_type_textarea      => esc_html__(
184
-                    'A multi line text input field',
185
-                    'event_espresso'
186
-                ),
187
-                EEM_Question::QST_type_url           => esc_html__(
188
-                    'A text field that must contain a valid URL',
189
-                    'event_espresso'
190
-                ),
191
-                EEM_Question::QST_type_us_phone      => esc_html__(
192
-                    'A text field that must contain a valid US phone number',
193
-                    'event_espresso'
194
-                ),
195
-                EEM_Question::QST_type_year          => esc_html__(
196
-                    'A dropdown that lists the last 100 years',
197
-                    'event_espresso'
198
-                ),
199
-            ]
200
-        );
201
-        $this->_question_type_categories      = (array) apply_filters(
202
-            'FHEE__EEM_Question__construct__question_type_categories',
203
-            [
204
-                'text'               => [
205
-                    EEM_Question::QST_type_date,
206
-                    EEM_Question::QST_type_decimal,
207
-                    EEM_Question::QST_type_email,
208
-                    EEM_Question::QST_type_email_confirm,
209
-                    EEM_Question::QST_type_html_textarea,
210
-                    EEM_Question::QST_type_int,
211
-                    EEM_Question::QST_type_text,
212
-                    EEM_Question::QST_type_textarea,
213
-                    EEM_Question::QST_type_url,
214
-                    EEM_Question::QST_type_us_phone,
215
-                    EEM_Question::QST_type_year,
216
-                ],
217
-                'date' => [
218
-                    EEM_Question::QST_type_date,
219
-                    EEM_Question::QST_type_year,
220
-                ],
221
-                'geographic' => [
222
-                    EEM_Question::QST_type_country,
223
-                    EEM_Question::QST_type_state,
224
-                ],
225
-                'numeric' => [
226
-                    EEM_Question::QST_type_decimal,
227
-                    EEM_Question::QST_type_int,
228
-                ],
229
-                'single-answer-enum' => [
230
-                    EEM_Question::QST_type_dropdown,
231
-                    EEM_Question::QST_type_radio,
232
-                ],
233
-                'multi-answer-enum'  => [
234
-                    EEM_Question::QST_type_multi_select,
235
-                    EEM_Question::QST_type_checkbox,
236
-                ],
237
-            ]
238
-        );
239
-        $this->question_types_with_max_length = (array) apply_filters(
240
-            'FHEE__EEM_Question___construct__question_types_with_max_length',
241
-            [
242
-                EEM_Question::QST_type_html_textarea,
243
-                EEM_Question::QST_type_text,
244
-                EEM_Question::QST_type_textarea,
245
-            ]
246
-        );
247
-
248
-        $this->_tables          = [
249
-            'Question' => new EE_Primary_Table('esp_question', 'QST_ID'),
250
-        ];
251
-        $this->_fields          = [
252
-            'Question' => [
253
-                'QST_ID'            => new EE_Primary_Key_Int_Field(
254
-                    'QST_ID',
255
-                    esc_html__('Question ID', 'event_espresso')
256
-                ),
257
-                'QST_admin_label'   => new EE_Plain_Text_Field(
258
-                    'QST_admin_label',
259
-                    esc_html__('Question Label (admin-only)', 'event_espresso'),
260
-                    true,
261
-                    ''
262
-                ),
263
-                'QST_admin_only'    => new EE_Boolean_Field(
264
-                    'QST_admin_only',
265
-                    esc_html__('Admin-Only Question?', 'event_espresso'),
266
-                    false,
267
-                    false
268
-                ),
269
-                'QST_deleted'       => new EE_Trashed_Flag_Field(
270
-                    'QST_deleted',
271
-                    esc_html__('Flag Indicating question was deleted', 'event_espresso'),
272
-                    false,
273
-                    false
274
-                ),
275
-                'QST_display_text'  => new EE_Post_Content_Field(
276
-                    'QST_display_text',
277
-                    esc_html__('Question Text', 'event_espresso'),
278
-                    true,
279
-                    ''
280
-                ),
281
-                'QST_max'           => new EE_Infinite_Integer_Field(
282
-                    'QST_max',
283
-                    esc_html__('Max Size', 'event_espresso'),
284
-                    false,
285
-                    EE_INF
286
-                ),
287
-                'QST_order'         => new EE_Integer_Field(
288
-                    'QST_order',
289
-                    esc_html__('Question Order', 'event_espresso'),
290
-                    false,
291
-                    0
292
-                ),
293
-                'QST_required'      => new EE_Boolean_Field(
294
-                    'QST_required',
295
-                    esc_html__('Required Question?', 'event_espresso'),
296
-                    false,
297
-                    false
298
-                ),
299
-                'QST_required_text' => new EE_Simple_HTML_Field(
300
-                    'QST_required_text',
301
-                    esc_html__('Text to Display if Not Provided', 'event_espresso'),
302
-                    true,
303
-                    ''
304
-                ),
305
-                'QST_system'        => new EE_Plain_Text_Field(
306
-                    'QST_system',
307
-                    esc_html__('Internal string ID for question', 'event_espresso'),
308
-                    false,
309
-                    ''
310
-                ),
311
-                'QST_type'          => new EE_Enum_Text_Field(
312
-                    'QST_type',
313
-                    esc_html__('Question Type', 'event_espresso'),
314
-                    false,
315
-                    'TEXT',
316
-                    $this->_allowed_question_types
317
-                ),
318
-                'QST_wp_user'       => new EE_WP_User_Field(
319
-                    'QST_wp_user',
320
-                    esc_html__('Question Creator ID', 'event_espresso'),
321
-                    false
322
-                ),
323
-            ],
324
-        ];
325
-        $this->_model_relations = [
326
-            'Answer'                  => new EE_Has_Many_Relation(),
327
-            'Question_Group'          => new EE_HABTM_Relation('Question_Group_Question'),
328
-            // for QST_order column
329
-            'Question_Group_Question' => new EE_Has_Many_Relation(),
330
-            'Question_Option'         => new EE_Has_Many_Relation(),
331
-            'WP_User'                 => new EE_Belongs_To_Relation(),
332
-        ];
333
-        // this model is generally available for reading
334
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
335
-            new EE_Restriction_Generator_Public();
336
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
337
-            new EE_Restriction_Generator_Reg_Form('QST_system');
338
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
339
-            new EE_Restriction_Generator_Reg_Form('QST_system');
340
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
341
-            new EE_Restriction_Generator_Reg_Form('QST_system');
342
-
343
-        parent::__construct($timezone);
344
-    }
345
-
346
-
347
-    /**
348
-     * Returns the list of allowed question types, which are normally:
349
-     * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended
350
-     *
351
-     * @return string[]
352
-     */
353
-    public function allowed_question_types(): array
354
-    {
355
-        return $this->_allowed_question_types;
356
-    }
357
-
358
-
359
-    /**
360
-     * Gets all the question types in the same category
361
-     *
362
-     * @param string $question_type one of EEM_Question::allowed_question_types(
363
-     * @return string[] like EEM_Question::allowed_question_types()
364
-     */
365
-    public function question_types_in_same_category(string $question_type): array
366
-    {
367
-        $question_types = [$question_type];
368
-        foreach ($this->_question_type_categories as $category => $question_types_in_category) {
369
-            if (in_array($question_type, $question_types_in_category)) {
370
-                $question_types = $question_types_in_category;
371
-                break;
372
-            }
373
-        }
374
-
375
-        return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
376
-    }
377
-
378
-
379
-    /**
380
-     * Determines if the given question type is in the given question type category
381
-     *
382
-     * @param string $question_type one of EEM_Question::allowed_question_types()
383
-     * @param string $category      one of the top-level keys of EEM_Question::question_type_categories()
384
-     * @return boolean
385
-     */
386
-    public function question_type_is_in_category(string $question_type, string $category): bool
387
-    {
388
-        if (! isset($this->_question_type_categories[ $category ])) {
389
-            return false;
390
-        }
391
-        return in_array($question_type, $this->_question_type_categories[ $category ]);
392
-    }
393
-
394
-
395
-    /**
396
-     * Returns all the question types in the given category
397
-     *
398
-     * @param string $category
399
-     * @return array|mixed
400
-     */
401
-    public function question_types_in_category(string $category): array
402
-    {
403
-        if (isset($this->_question_type_categories[ $category ])) {
404
-            return $this->_question_type_categories[ $category ];
405
-        }
406
-        return [];
407
-    }
408
-
409
-
410
-    /**
411
-     * Returns all the question types that should have question options
412
-     *
413
-     * @return array
414
-     */
415
-    public function question_types_with_options(): array
416
-    {
417
-        return array_merge(
418
-            $this->question_types_in_category('single-answer-enum'),
419
-            $this->question_types_in_category('multi-answer-enum')
420
-        );
421
-    }
422
-
423
-
424
-    /**
425
-     * Returns the question type categories 2d array
426
-     *
427
-     * @return array see EEM_Question::_question_type_categories
428
-     */
429
-    public function question_type_categories(): array
430
-    {
431
-        return $this->_question_type_categories;
432
-    }
433
-
434
-
435
-    /**
436
-     * Returns an array of all the QST_system values that can be allowed in the system question group
437
-     * identified by $system_question_group_id
438
-     *
439
-     * @param string $system_question_group_id QSG_system
440
-     * @return array of system question names (QST_system)
441
-     */
442
-    public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array
443
-    {
444
-        $question_system_ids = [];
445
-        switch ($system_question_group_id) {
446
-            case EEM_Question_Group::system_personal:
447
-                $question_system_ids = [
448
-                    EEM_Attendee::system_question_fname,
449
-                    EEM_Attendee::system_question_lname,
450
-                    EEM_Attendee::system_question_email,
451
-                    EEM_Attendee::system_question_email_confirm,
452
-                    EEM_Attendee::system_question_phone,
453
-                ];
454
-                break;
455
-            case EEM_Question_Group::system_address:
456
-                $question_system_ids = [
457
-                    EEM_Attendee::system_question_address,
458
-                    EEM_Attendee::system_question_address2,
459
-                    EEM_Attendee::system_question_city,
460
-                    EEM_Attendee::system_question_state,
461
-                    EEM_Attendee::system_question_country,
462
-                    EEM_Attendee::system_question_zip,
463
-                    EEM_Attendee::system_question_phone,
464
-                ];
465
-                break;
466
-        }
467
-        return apply_filters(
468
-            'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return',
469
-            $question_system_ids,
470
-            $system_question_group_id
471
-        );
472
-    }
473
-
474
-
475
-    /**
476
-     * Returns an array of all the QST_system values that are required in the system question group
477
-     * identified by $system_question_group_id
478
-     *
479
-     * @param string $system_question_group_id QSG_system
480
-     * @return array of system question names (QST_system)
481
-     */
482
-    public function required_system_questions_in_system_question_group(string $system_question_group_id): array
483
-    {
484
-        $question_system_ids = null;
485
-        switch ($system_question_group_id) {
486
-            case EEM_Question_Group::system_personal:
487
-                $question_system_ids = [
488
-                    EEM_Attendee::system_question_fname,
489
-                    EEM_Attendee::system_question_email,
490
-                ];
491
-                break;
492
-            default:
493
-                $question_system_ids = [];
494
-        }
495
-        return apply_filters(
496
-            'FHEE__EEM_Question__system_questions_required_in_system_question_group',
497
-            $question_system_ids,
498
-            $system_question_group_id
499
-        );
500
-    }
501
-
502
-
503
-    /**
504
-     * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
505
-     * which system question QST_ID corresponds to the QST_system 'city', use
506
-     * EEM_Question::instance()->get_Question_ID_from_system_string('city');
507
-     *
508
-     * @param $QST_system
509
-     * @return int of QST_ID for the question that corresponds to that QST_system
510
-     * @throws EE_Error
511
-     */
512
-    public function get_Question_ID_from_system_string($QST_system): int
513
-    {
514
-        return $this->get_var([['QST_system' => $QST_system]]);
515
-    }
516
-
517
-
518
-    /**
519
-     * searches the db for the question with the latest question order and returns that value.
520
-     *
521
-     * @return int
522
-     * @throws EE_Error
523
-     */
524
-    public function get_latest_question_order(): int
525
-    {
526
-        $columns_to_select = [
527
-            'max_order' => ["MAX(QST_order)", "%d"],
528
-        ];
529
-        $max               = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select);
530
-        return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
531
-    }
532
-
533
-
534
-    /**
535
-     * Returns an array where keys are system question QST_system values,
536
-     * and values are the highest question max the admin can set on the question
537
-     * (aka the "max max"; eg, a site admin can change the zip question to have a max
538
-     * of 5, but no larger than 12)
539
-     *
540
-     * @return array
541
-     */
542
-    public function system_question_maxes(): array
543
-    {
544
-        return [
545
-            'fname'         => 45,
546
-            'lname'         => 45,
547
-            'address'       => 255,
548
-            'address2'      => 255,
549
-            'city'          => 45,
550
-            'zip'           => 12,
551
-            'email'         => 255,
552
-            'email_confirm' => 255,
553
-            'phone'         => 45,
554
-        ];
555
-    }
556
-
557
-
558
-    /**
559
-     * Given a QST_system value, gets the question's largest allowable max input.
560
-     *
561
-     * @param string $system_question_value
562
-     * @return int|float
563
-     * @see Registration_Form_Admin_Page::system_question_maxes()
564
-     */
565
-    public function absolute_max_for_system_question(string $system_question_value)
566
-    {
567
-        $maxes = $this->system_question_maxes();
568
-        return $maxes[ $system_question_value ] ?? EE_INF;
569
-    }
570
-
571
-
572
-    /**
573
-     * @return array
574
-     */
575
-    public function question_descriptions(): array
576
-    {
577
-        return $this->_question_descriptions;
578
-    }
579
-
580
-
581
-    /**
582
-     * Returns all the question types that should have an admin-defined max input length
583
-     *
584
-     * @return array
585
-     */
586
-    public function questionTypesWithMaxLength(): array
587
-    {
588
-        return (array) $this->question_types_with_max_length;
589
-    }
13
+	// constant used to indicate that the question type is CHECKBOX
14
+	const QST_type_checkbox = 'CHECKBOX';
15
+
16
+	// constant used to indicate that the question type is COUNTRY
17
+	const QST_type_country = 'COUNTRY';
18
+
19
+	// constant used to indicate that the question type is DATE
20
+	const QST_type_date = 'DATE';
21
+
22
+	// constant used to indicate that the question type is a decimal (float)
23
+	const QST_type_decimal = 'DECIMAL';
24
+
25
+	// constant used to indicate that the question type is DROPDOWN
26
+	const QST_type_dropdown = 'DROPDOWN';
27
+
28
+	// constant used to indicate that the question type is an email input
29
+	const QST_type_email = 'EMAIL';
30
+
31
+	// constant used to indicate that the question type is an email input
32
+	const QST_type_email_confirm = 'EMAIL_CONFIRM';
33
+
34
+	// constant used to indicate that the question type is a TEXTAREA that allows simple html
35
+	const QST_type_html_textarea = 'HTML_TEXTAREA';
36
+
37
+	// constant used to indicate that the question type is an integer (whole number)
38
+	const QST_type_int = 'INTEGER';
39
+
40
+	// constant used to indicate that the question type is a multi-select
41
+	const QST_type_multi_select = 'MULTI_SELECT';
42
+
43
+	// constant used to indicate that the question type is RADIO_BTN
44
+	const QST_type_radio = 'RADIO_BTN';
45
+
46
+	// constant used to indicate that the question type is STATE
47
+	const QST_type_state = 'STATE';
48
+
49
+	// constant used to indicate that the question type is TEXT
50
+	const QST_type_text = 'TEXT';
51
+
52
+	// constant used to indicate that the question type is TEXTAREA
53
+	const QST_type_textarea = 'TEXTAREA';
54
+
55
+	// constant used to indicate that the question type is a valid URL
56
+	const QST_type_url = 'URL';
57
+
58
+	// constant used to indicate that the question type is a US-formatted phone number
59
+	const QST_type_us_phone = 'US_PHONE';
60
+
61
+	// constant used to indicate that the question type is a YEAR
62
+	const QST_type_year = 'YEAR';
63
+
64
+
65
+	protected static ?EEM_Question $_instance = null;
66
+
67
+	/**
68
+	 * lists all the question types which should be allowed. Ideally, this will be extensible.
69
+	 */
70
+	protected array $_allowed_question_types;
71
+
72
+	/**
73
+	 * brief descriptions for all the question types
74
+	 */
75
+	protected array $_question_descriptions;
76
+
77
+	/**
78
+	 * Question types that are interchangeable, even after answers have been provided for them.
79
+	 * Top-level keys are category slugs, next level is an array of question types. If question types
80
+	 * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
81
+	 *
82
+	 * @var array   $_question_type_categories {
83
+	 * @type string $text
84
+	 * @type string $single                    -answer-enum
85
+	 * @type string $multi                     -answer-enum
86
+	 *                                         }
87
+	 */
88
+	protected array $_question_type_categories;
89
+
90
+	/**
91
+	 * Question types that should have an admin-defined max input length
92
+	 */
93
+	protected array $question_types_with_max_length;
94
+
95
+
96
+	/**
97
+	 * EEM_Question constructor.
98
+	 *
99
+	 * @param string|null $timezone
100
+	 * @throws EE_Error
101
+	 */
102
+	protected function __construct(?string $timezone = '')
103
+	{
104
+		$this->singular_item                  = esc_html__('Question', 'event_espresso');
105
+		$this->plural_item                    = esc_html__('Questions', 'event_espresso');
106
+		$this->_allowed_question_types        = (array) apply_filters(
107
+			'FHEE__EEM_Question__construct__allowed_question_types',
108
+			[
109
+				EEM_Question::QST_type_checkbox      => esc_html__('Checkboxes', 'event_espresso'),
110
+				EEM_Question::QST_type_country       => esc_html__('Country Dropdown', 'event_espresso'),
111
+				EEM_Question::QST_type_date          => esc_html__('Date Picker', 'event_espresso'),
112
+				EEM_Question::QST_type_decimal       => esc_html__('Number', 'event_espresso'),
113
+				EEM_Question::QST_type_dropdown      => esc_html__('Dropdown', 'event_espresso'),
114
+				EEM_Question::QST_type_email         => esc_html__('Email', 'event_espresso'),
115
+				EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
116
+				EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
117
+				EEM_Question::QST_type_int           => esc_html__('Whole Number', 'event_espresso'),
118
+				EEM_Question::QST_type_multi_select  => esc_html__('Multi Select', 'event_espresso'),
119
+				EEM_Question::QST_type_radio         => esc_html__('Radio Buttons', 'event_espresso'),
120
+				EEM_Question::QST_type_state         => esc_html__('State/Province Dropdown', 'event_espresso'),
121
+				EEM_Question::QST_type_text          => esc_html__('Text', 'event_espresso'),
122
+				EEM_Question::QST_type_textarea      => esc_html__('Textarea', 'event_espresso'),
123
+				EEM_Question::QST_type_url           => esc_html__('URL', 'event_espresso'),
124
+				EEM_Question::QST_type_us_phone      => esc_html__('USA - Format Phone', 'event_espresso'),
125
+				EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
126
+			]
127
+		);
128
+		$this->_question_descriptions         = (array) apply_filters(
129
+			'FHEE__EEM_Question__construct__question_descriptions',
130
+			[
131
+				EEM_Question::QST_type_checkbox      => esc_html__(
132
+					'Allows multiple preset options to be selected',
133
+					'event_espresso'
134
+				),
135
+				EEM_Question::QST_type_country       => esc_html__(
136
+					'A dropdown that lists countries',
137
+					'event_espresso'
138
+				),
139
+				EEM_Question::QST_type_date          => esc_html__(
140
+					'A popup calendar that allows date selections',
141
+					'event_espresso'
142
+				),
143
+				EEM_Question::QST_type_decimal       => esc_html__(
144
+					'A text field that allows number values with decimals',
145
+					'event_espresso'
146
+				),
147
+				EEM_Question::QST_type_dropdown      => esc_html__(
148
+					'A dropdown that allows a single selection',
149
+					'event_espresso'
150
+				),
151
+				EEM_Question::QST_type_email         => esc_html__(
152
+					'A text field that must contain a valid Email address',
153
+					'event_espresso'
154
+				),
155
+				EEM_Question::QST_type_email_confirm => esc_html__(
156
+					'A text field that must contain a valid Email address and be equal to Email field',
157
+					'event_espresso'
158
+				),
159
+				EEM_Question::QST_type_html_textarea => esc_html__(
160
+					'A multi line text input field that allows HTML',
161
+					'event_espresso'
162
+				),
163
+				EEM_Question::QST_type_int           => esc_html__(
164
+					'A text field that only allows whole numbers (no decimals)',
165
+					'event_espresso'
166
+				),
167
+				EEM_Question::QST_type_multi_select  => esc_html__(
168
+					'A dropdown that allows multiple selections',
169
+					'event_espresso'
170
+				),
171
+				EEM_Question::QST_type_radio         => esc_html__(
172
+					'Allows a single preset option to be selected',
173
+					'event_espresso'
174
+				),
175
+				EEM_Question::QST_type_state         => esc_html__(
176
+					'A dropdown that lists states/provinces',
177
+					'event_espresso'
178
+				),
179
+				EEM_Question::QST_type_text          => esc_html__(
180
+					'A single line text input field',
181
+					'event_espresso'
182
+				),
183
+				EEM_Question::QST_type_textarea      => esc_html__(
184
+					'A multi line text input field',
185
+					'event_espresso'
186
+				),
187
+				EEM_Question::QST_type_url           => esc_html__(
188
+					'A text field that must contain a valid URL',
189
+					'event_espresso'
190
+				),
191
+				EEM_Question::QST_type_us_phone      => esc_html__(
192
+					'A text field that must contain a valid US phone number',
193
+					'event_espresso'
194
+				),
195
+				EEM_Question::QST_type_year          => esc_html__(
196
+					'A dropdown that lists the last 100 years',
197
+					'event_espresso'
198
+				),
199
+			]
200
+		);
201
+		$this->_question_type_categories      = (array) apply_filters(
202
+			'FHEE__EEM_Question__construct__question_type_categories',
203
+			[
204
+				'text'               => [
205
+					EEM_Question::QST_type_date,
206
+					EEM_Question::QST_type_decimal,
207
+					EEM_Question::QST_type_email,
208
+					EEM_Question::QST_type_email_confirm,
209
+					EEM_Question::QST_type_html_textarea,
210
+					EEM_Question::QST_type_int,
211
+					EEM_Question::QST_type_text,
212
+					EEM_Question::QST_type_textarea,
213
+					EEM_Question::QST_type_url,
214
+					EEM_Question::QST_type_us_phone,
215
+					EEM_Question::QST_type_year,
216
+				],
217
+				'date' => [
218
+					EEM_Question::QST_type_date,
219
+					EEM_Question::QST_type_year,
220
+				],
221
+				'geographic' => [
222
+					EEM_Question::QST_type_country,
223
+					EEM_Question::QST_type_state,
224
+				],
225
+				'numeric' => [
226
+					EEM_Question::QST_type_decimal,
227
+					EEM_Question::QST_type_int,
228
+				],
229
+				'single-answer-enum' => [
230
+					EEM_Question::QST_type_dropdown,
231
+					EEM_Question::QST_type_radio,
232
+				],
233
+				'multi-answer-enum'  => [
234
+					EEM_Question::QST_type_multi_select,
235
+					EEM_Question::QST_type_checkbox,
236
+				],
237
+			]
238
+		);
239
+		$this->question_types_with_max_length = (array) apply_filters(
240
+			'FHEE__EEM_Question___construct__question_types_with_max_length',
241
+			[
242
+				EEM_Question::QST_type_html_textarea,
243
+				EEM_Question::QST_type_text,
244
+				EEM_Question::QST_type_textarea,
245
+			]
246
+		);
247
+
248
+		$this->_tables          = [
249
+			'Question' => new EE_Primary_Table('esp_question', 'QST_ID'),
250
+		];
251
+		$this->_fields          = [
252
+			'Question' => [
253
+				'QST_ID'            => new EE_Primary_Key_Int_Field(
254
+					'QST_ID',
255
+					esc_html__('Question ID', 'event_espresso')
256
+				),
257
+				'QST_admin_label'   => new EE_Plain_Text_Field(
258
+					'QST_admin_label',
259
+					esc_html__('Question Label (admin-only)', 'event_espresso'),
260
+					true,
261
+					''
262
+				),
263
+				'QST_admin_only'    => new EE_Boolean_Field(
264
+					'QST_admin_only',
265
+					esc_html__('Admin-Only Question?', 'event_espresso'),
266
+					false,
267
+					false
268
+				),
269
+				'QST_deleted'       => new EE_Trashed_Flag_Field(
270
+					'QST_deleted',
271
+					esc_html__('Flag Indicating question was deleted', 'event_espresso'),
272
+					false,
273
+					false
274
+				),
275
+				'QST_display_text'  => new EE_Post_Content_Field(
276
+					'QST_display_text',
277
+					esc_html__('Question Text', 'event_espresso'),
278
+					true,
279
+					''
280
+				),
281
+				'QST_max'           => new EE_Infinite_Integer_Field(
282
+					'QST_max',
283
+					esc_html__('Max Size', 'event_espresso'),
284
+					false,
285
+					EE_INF
286
+				),
287
+				'QST_order'         => new EE_Integer_Field(
288
+					'QST_order',
289
+					esc_html__('Question Order', 'event_espresso'),
290
+					false,
291
+					0
292
+				),
293
+				'QST_required'      => new EE_Boolean_Field(
294
+					'QST_required',
295
+					esc_html__('Required Question?', 'event_espresso'),
296
+					false,
297
+					false
298
+				),
299
+				'QST_required_text' => new EE_Simple_HTML_Field(
300
+					'QST_required_text',
301
+					esc_html__('Text to Display if Not Provided', 'event_espresso'),
302
+					true,
303
+					''
304
+				),
305
+				'QST_system'        => new EE_Plain_Text_Field(
306
+					'QST_system',
307
+					esc_html__('Internal string ID for question', 'event_espresso'),
308
+					false,
309
+					''
310
+				),
311
+				'QST_type'          => new EE_Enum_Text_Field(
312
+					'QST_type',
313
+					esc_html__('Question Type', 'event_espresso'),
314
+					false,
315
+					'TEXT',
316
+					$this->_allowed_question_types
317
+				),
318
+				'QST_wp_user'       => new EE_WP_User_Field(
319
+					'QST_wp_user',
320
+					esc_html__('Question Creator ID', 'event_espresso'),
321
+					false
322
+				),
323
+			],
324
+		];
325
+		$this->_model_relations = [
326
+			'Answer'                  => new EE_Has_Many_Relation(),
327
+			'Question_Group'          => new EE_HABTM_Relation('Question_Group_Question'),
328
+			// for QST_order column
329
+			'Question_Group_Question' => new EE_Has_Many_Relation(),
330
+			'Question_Option'         => new EE_Has_Many_Relation(),
331
+			'WP_User'                 => new EE_Belongs_To_Relation(),
332
+		];
333
+		// this model is generally available for reading
334
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
335
+			new EE_Restriction_Generator_Public();
336
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
337
+			new EE_Restriction_Generator_Reg_Form('QST_system');
338
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
339
+			new EE_Restriction_Generator_Reg_Form('QST_system');
340
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
341
+			new EE_Restriction_Generator_Reg_Form('QST_system');
342
+
343
+		parent::__construct($timezone);
344
+	}
345
+
346
+
347
+	/**
348
+	 * Returns the list of allowed question types, which are normally:
349
+	 * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended
350
+	 *
351
+	 * @return string[]
352
+	 */
353
+	public function allowed_question_types(): array
354
+	{
355
+		return $this->_allowed_question_types;
356
+	}
357
+
358
+
359
+	/**
360
+	 * Gets all the question types in the same category
361
+	 *
362
+	 * @param string $question_type one of EEM_Question::allowed_question_types(
363
+	 * @return string[] like EEM_Question::allowed_question_types()
364
+	 */
365
+	public function question_types_in_same_category(string $question_type): array
366
+	{
367
+		$question_types = [$question_type];
368
+		foreach ($this->_question_type_categories as $category => $question_types_in_category) {
369
+			if (in_array($question_type, $question_types_in_category)) {
370
+				$question_types = $question_types_in_category;
371
+				break;
372
+			}
373
+		}
374
+
375
+		return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
376
+	}
377
+
378
+
379
+	/**
380
+	 * Determines if the given question type is in the given question type category
381
+	 *
382
+	 * @param string $question_type one of EEM_Question::allowed_question_types()
383
+	 * @param string $category      one of the top-level keys of EEM_Question::question_type_categories()
384
+	 * @return boolean
385
+	 */
386
+	public function question_type_is_in_category(string $question_type, string $category): bool
387
+	{
388
+		if (! isset($this->_question_type_categories[ $category ])) {
389
+			return false;
390
+		}
391
+		return in_array($question_type, $this->_question_type_categories[ $category ]);
392
+	}
393
+
394
+
395
+	/**
396
+	 * Returns all the question types in the given category
397
+	 *
398
+	 * @param string $category
399
+	 * @return array|mixed
400
+	 */
401
+	public function question_types_in_category(string $category): array
402
+	{
403
+		if (isset($this->_question_type_categories[ $category ])) {
404
+			return $this->_question_type_categories[ $category ];
405
+		}
406
+		return [];
407
+	}
408
+
409
+
410
+	/**
411
+	 * Returns all the question types that should have question options
412
+	 *
413
+	 * @return array
414
+	 */
415
+	public function question_types_with_options(): array
416
+	{
417
+		return array_merge(
418
+			$this->question_types_in_category('single-answer-enum'),
419
+			$this->question_types_in_category('multi-answer-enum')
420
+		);
421
+	}
422
+
423
+
424
+	/**
425
+	 * Returns the question type categories 2d array
426
+	 *
427
+	 * @return array see EEM_Question::_question_type_categories
428
+	 */
429
+	public function question_type_categories(): array
430
+	{
431
+		return $this->_question_type_categories;
432
+	}
433
+
434
+
435
+	/**
436
+	 * Returns an array of all the QST_system values that can be allowed in the system question group
437
+	 * identified by $system_question_group_id
438
+	 *
439
+	 * @param string $system_question_group_id QSG_system
440
+	 * @return array of system question names (QST_system)
441
+	 */
442
+	public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array
443
+	{
444
+		$question_system_ids = [];
445
+		switch ($system_question_group_id) {
446
+			case EEM_Question_Group::system_personal:
447
+				$question_system_ids = [
448
+					EEM_Attendee::system_question_fname,
449
+					EEM_Attendee::system_question_lname,
450
+					EEM_Attendee::system_question_email,
451
+					EEM_Attendee::system_question_email_confirm,
452
+					EEM_Attendee::system_question_phone,
453
+				];
454
+				break;
455
+			case EEM_Question_Group::system_address:
456
+				$question_system_ids = [
457
+					EEM_Attendee::system_question_address,
458
+					EEM_Attendee::system_question_address2,
459
+					EEM_Attendee::system_question_city,
460
+					EEM_Attendee::system_question_state,
461
+					EEM_Attendee::system_question_country,
462
+					EEM_Attendee::system_question_zip,
463
+					EEM_Attendee::system_question_phone,
464
+				];
465
+				break;
466
+		}
467
+		return apply_filters(
468
+			'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return',
469
+			$question_system_ids,
470
+			$system_question_group_id
471
+		);
472
+	}
473
+
474
+
475
+	/**
476
+	 * Returns an array of all the QST_system values that are required in the system question group
477
+	 * identified by $system_question_group_id
478
+	 *
479
+	 * @param string $system_question_group_id QSG_system
480
+	 * @return array of system question names (QST_system)
481
+	 */
482
+	public function required_system_questions_in_system_question_group(string $system_question_group_id): array
483
+	{
484
+		$question_system_ids = null;
485
+		switch ($system_question_group_id) {
486
+			case EEM_Question_Group::system_personal:
487
+				$question_system_ids = [
488
+					EEM_Attendee::system_question_fname,
489
+					EEM_Attendee::system_question_email,
490
+				];
491
+				break;
492
+			default:
493
+				$question_system_ids = [];
494
+		}
495
+		return apply_filters(
496
+			'FHEE__EEM_Question__system_questions_required_in_system_question_group',
497
+			$question_system_ids,
498
+			$system_question_group_id
499
+		);
500
+	}
501
+
502
+
503
+	/**
504
+	 * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
505
+	 * which system question QST_ID corresponds to the QST_system 'city', use
506
+	 * EEM_Question::instance()->get_Question_ID_from_system_string('city');
507
+	 *
508
+	 * @param $QST_system
509
+	 * @return int of QST_ID for the question that corresponds to that QST_system
510
+	 * @throws EE_Error
511
+	 */
512
+	public function get_Question_ID_from_system_string($QST_system): int
513
+	{
514
+		return $this->get_var([['QST_system' => $QST_system]]);
515
+	}
516
+
517
+
518
+	/**
519
+	 * searches the db for the question with the latest question order and returns that value.
520
+	 *
521
+	 * @return int
522
+	 * @throws EE_Error
523
+	 */
524
+	public function get_latest_question_order(): int
525
+	{
526
+		$columns_to_select = [
527
+			'max_order' => ["MAX(QST_order)", "%d"],
528
+		];
529
+		$max               = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select);
530
+		return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
531
+	}
532
+
533
+
534
+	/**
535
+	 * Returns an array where keys are system question QST_system values,
536
+	 * and values are the highest question max the admin can set on the question
537
+	 * (aka the "max max"; eg, a site admin can change the zip question to have a max
538
+	 * of 5, but no larger than 12)
539
+	 *
540
+	 * @return array
541
+	 */
542
+	public function system_question_maxes(): array
543
+	{
544
+		return [
545
+			'fname'         => 45,
546
+			'lname'         => 45,
547
+			'address'       => 255,
548
+			'address2'      => 255,
549
+			'city'          => 45,
550
+			'zip'           => 12,
551
+			'email'         => 255,
552
+			'email_confirm' => 255,
553
+			'phone'         => 45,
554
+		];
555
+	}
556
+
557
+
558
+	/**
559
+	 * Given a QST_system value, gets the question's largest allowable max input.
560
+	 *
561
+	 * @param string $system_question_value
562
+	 * @return int|float
563
+	 * @see Registration_Form_Admin_Page::system_question_maxes()
564
+	 */
565
+	public function absolute_max_for_system_question(string $system_question_value)
566
+	{
567
+		$maxes = $this->system_question_maxes();
568
+		return $maxes[ $system_question_value ] ?? EE_INF;
569
+	}
570
+
571
+
572
+	/**
573
+	 * @return array
574
+	 */
575
+	public function question_descriptions(): array
576
+	{
577
+		return $this->_question_descriptions;
578
+	}
579
+
580
+
581
+	/**
582
+	 * Returns all the question types that should have an admin-defined max input length
583
+	 *
584
+	 * @return array
585
+	 */
586
+	public function questionTypesWithMaxLength(): array
587
+	{
588
+		return (array) $this->question_types_with_max_length;
589
+	}
590 590
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Country.model.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -11,215 +11,215 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Country extends EEM_Base
13 13
 {
14
-    protected static ?EEM_Country $_instance = null;
15
-
16
-    // array of all countries
17
-    private static ?array $_all_countries = null;
18
-
19
-    // array of all active countries
20
-    private static ?array $_active_countries = null;
21
-
22
-
23
-    /**
24
-     * Resets the country
25
-     *
26
-     * @param string|null $timezone
27
-     * @return EEM_Base|EEM_Country|null
28
-     * @throws EE_Error
29
-     * @throws ReflectionException
30
-     */
31
-    public static function reset($timezone = '')
32
-    {
33
-        self::$_active_countries = null;
34
-        self::$_all_countries    = null;
35
-        return parent::reset($timezone);
36
-    }
37
-
38
-
39
-    /**
40
-     * @param string|null $timezone
41
-     * @throws EE_Error
42
-     */
43
-    protected function __construct(?string $timezone = '')
44
-    {
45
-        $this->singular_item = esc_html__('Country', 'event_espresso');
46
-        $this->plural_item   = esc_html__('Countries', 'event_espresso');
47
-
48
-        $this->_tables = [
49
-            'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'),
50
-        ];
51
-
52
-        $this->_fields          = [
53
-            'Country' => [
54
-                'CNT_active'      => new EE_Boolean_Field(
55
-                    'CNT_active',
56
-                    esc_html__('Country Appears in Dropdown Select Lists', 'event_espresso'),
57
-                    false,
58
-                    true
59
-                ),
60
-                'CNT_ISO'         => new EE_Primary_Key_String_Field(
61
-                    'CNT_ISO',
62
-                    esc_html__('Country ISO Code', 'event_espresso')
63
-                ),
64
-                'CNT_ISO3'        => new EE_All_Caps_Text_Field(
65
-                    'CNT_ISO3',
66
-                    esc_html__('Country ISO3 Code', 'event_espresso'),
67
-                    false,
68
-                    ''
69
-                ),
70
-                'RGN_ID'          => new EE_Integer_Field(
71
-                    'RGN_ID',
72
-                    esc_html__('Region ID', 'event_espresso'),
73
-                    false,
74
-                    0
75
-                ),
76
-                // should be a foreign key, but no region table exists yet
77
-                'CNT_name'        => new EE_Plain_Text_Field(
78
-                    'CNT_name',
79
-                    esc_html__('Country Name', 'event_espresso'),
80
-                    false,
81
-                    ''
82
-                ),
83
-                'CNT_cur_code'    => new EE_All_Caps_Text_Field(
84
-                    'CNT_cur_code',
85
-                    esc_html__('Country Currency Code', 'event_espresso'),
86
-                    false
87
-                ),
88
-                'CNT_cur_single'  => new EE_Plain_Text_Field(
89
-                    'CNT_cur_single',
90
-                    esc_html__('Currency Name Singular', 'event_espresso'),
91
-                    false
92
-                ),
93
-                'CNT_cur_plural'  => new EE_Plain_Text_Field(
94
-                    'CNT_cur_plural',
95
-                    esc_html__('Currency Name Plural', 'event_espresso'),
96
-                    false
97
-                ),
98
-                'CNT_cur_sign'    => new EE_Plain_Text_Field(
99
-                    'CNT_cur_sign',
100
-                    esc_html__('Currency Sign', 'event_espresso'),
101
-                    false
102
-                ),
103
-                'CNT_cur_sign_b4' => new EE_Boolean_Field(
104
-                    'CNT_cur_sign_b4',
105
-                    esc_html__('Currency Sign Before Number', 'event_espresso'),
106
-                    false,
107
-                    true
108
-                ),
109
-                'CNT_cur_dec_plc' => new EE_Integer_Field(
110
-                    'CNT_cur_dec_plc',
111
-                    esc_html__('Currency Decimal Places', 'event_espresso'),
112
-                    false,
113
-                    2
114
-                ),
115
-                'CNT_cur_dec_mrk' => new EE_Plain_Text_Field(
116
-                    'CNT_cur_dec_mrk',
117
-                    esc_html__('Currency Decimal Mark', 'event_espresso'),
118
-                    false,
119
-                    '.'
120
-                ),
121
-                'CNT_cur_thsnds'  => new EE_Plain_Text_Field(
122
-                    'CNT_cur_thsnds',
123
-                    esc_html__('Currency Thousands Separator', 'event_espresso'),
124
-                    false,
125
-                    ','
126
-                ),
127
-                'CNT_tel_code'    => new EE_Plain_Text_Field(
128
-                    'CNT_tel_code',
129
-                    esc_html__('Country Telephone Code', 'event_espresso'),
130
-                    false,
131
-                    ''
132
-                ),
133
-                'CNT_is_EU'       => new EE_Boolean_Field(
134
-                    'CNT_is_EU',
135
-                    esc_html__('Country is Member of EU', 'event_espresso'),
136
-                    false,
137
-                    false
138
-                ),
139
-            ],
140
-        ];
141
-        $this->_model_relations = [
142
-            'Attendee' => new EE_Has_Many_Relation(),
143
-            'State'    => new EE_Has_Many_Relation(),
144
-            'Venue'    => new EE_Has_Many_Relation(),
145
-        ];
146
-        // only anyone to view, but only those with the default role can do anything
147
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
148
-
149
-        parent::__construct($timezone);
150
-    }
151
-
152
-
153
-    /**
154
-     * @return EE_Country[]|null
155
-     * @throws EE_Error
156
-     * @throws ReflectionException
157
-     */
158
-    public function get_all_countries(): ?array
159
-    {
160
-        if (! self::$_all_countries) {
161
-            self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
162
-        }
163
-        return self::$_all_countries;
164
-    }
165
-
166
-
167
-    /**
168
-     * Gets and caches the list of active countries. If you know the list of active countries
169
-     * has changed during this request, first use EEM_Country::reset() to flush the cache
170
-     *
171
-     * @return EE_Country[]|null
172
-     * @throws EE_Error
173
-     * @throws ReflectionException
174
-     */
175
-    public function get_all_active_countries(): ?array
176
-    {
177
-        if (! self::$_active_countries) {
178
-            self::$_active_countries =
179
-                $this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
180
-        }
181
-        return self::$_active_countries;
182
-    }
183
-
184
-
185
-    /**
186
-     * Gets the country's name by its ISO
187
-     *
188
-     * @param string $country_ISO
189
-     * @return string
190
-     * @throws EE_Error
191
-     * @throws ReflectionException
192
-     */
193
-    public function get_country_name_by_ISO(string $country_ISO): string
194
-    {
195
-        $countries = $this->get_all_countries();
196
-        if (isset($countries[ $country_ISO ]) && $countries[ $country_ISO ] instanceof EE_Country) {
197
-            return $countries[ $country_ISO ]->name();
198
-        }
199
-        $names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name');
200
-        if (is_array($names) && ! empty($names)) {
201
-            return reset($names);
202
-        }
203
-        return '';
204
-    }
205
-
206
-
207
-    /**
208
-     * Gets the country's name by its name
209
-     *
210
-     * @param string $country_name
211
-     * @return EE_Country|null
212
-     * @throws EE_Error
213
-     * @throws ReflectionException
214
-     */
215
-    public function getCountryByName(string $country_name): ?EE_Country
216
-    {
217
-        $countries = $this->get_all_countries();
218
-        foreach ($countries as $country) {
219
-            if ($country instanceof EE_Country && $country->name() === $country_name) {
220
-                return $country;
221
-            }
222
-        }
223
-        return $this->get_one([['CNT_name' => $country_name]]);
224
-    }
14
+	protected static ?EEM_Country $_instance = null;
15
+
16
+	// array of all countries
17
+	private static ?array $_all_countries = null;
18
+
19
+	// array of all active countries
20
+	private static ?array $_active_countries = null;
21
+
22
+
23
+	/**
24
+	 * Resets the country
25
+	 *
26
+	 * @param string|null $timezone
27
+	 * @return EEM_Base|EEM_Country|null
28
+	 * @throws EE_Error
29
+	 * @throws ReflectionException
30
+	 */
31
+	public static function reset($timezone = '')
32
+	{
33
+		self::$_active_countries = null;
34
+		self::$_all_countries    = null;
35
+		return parent::reset($timezone);
36
+	}
37
+
38
+
39
+	/**
40
+	 * @param string|null $timezone
41
+	 * @throws EE_Error
42
+	 */
43
+	protected function __construct(?string $timezone = '')
44
+	{
45
+		$this->singular_item = esc_html__('Country', 'event_espresso');
46
+		$this->plural_item   = esc_html__('Countries', 'event_espresso');
47
+
48
+		$this->_tables = [
49
+			'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'),
50
+		];
51
+
52
+		$this->_fields          = [
53
+			'Country' => [
54
+				'CNT_active'      => new EE_Boolean_Field(
55
+					'CNT_active',
56
+					esc_html__('Country Appears in Dropdown Select Lists', 'event_espresso'),
57
+					false,
58
+					true
59
+				),
60
+				'CNT_ISO'         => new EE_Primary_Key_String_Field(
61
+					'CNT_ISO',
62
+					esc_html__('Country ISO Code', 'event_espresso')
63
+				),
64
+				'CNT_ISO3'        => new EE_All_Caps_Text_Field(
65
+					'CNT_ISO3',
66
+					esc_html__('Country ISO3 Code', 'event_espresso'),
67
+					false,
68
+					''
69
+				),
70
+				'RGN_ID'          => new EE_Integer_Field(
71
+					'RGN_ID',
72
+					esc_html__('Region ID', 'event_espresso'),
73
+					false,
74
+					0
75
+				),
76
+				// should be a foreign key, but no region table exists yet
77
+				'CNT_name'        => new EE_Plain_Text_Field(
78
+					'CNT_name',
79
+					esc_html__('Country Name', 'event_espresso'),
80
+					false,
81
+					''
82
+				),
83
+				'CNT_cur_code'    => new EE_All_Caps_Text_Field(
84
+					'CNT_cur_code',
85
+					esc_html__('Country Currency Code', 'event_espresso'),
86
+					false
87
+				),
88
+				'CNT_cur_single'  => new EE_Plain_Text_Field(
89
+					'CNT_cur_single',
90
+					esc_html__('Currency Name Singular', 'event_espresso'),
91
+					false
92
+				),
93
+				'CNT_cur_plural'  => new EE_Plain_Text_Field(
94
+					'CNT_cur_plural',
95
+					esc_html__('Currency Name Plural', 'event_espresso'),
96
+					false
97
+				),
98
+				'CNT_cur_sign'    => new EE_Plain_Text_Field(
99
+					'CNT_cur_sign',
100
+					esc_html__('Currency Sign', 'event_espresso'),
101
+					false
102
+				),
103
+				'CNT_cur_sign_b4' => new EE_Boolean_Field(
104
+					'CNT_cur_sign_b4',
105
+					esc_html__('Currency Sign Before Number', 'event_espresso'),
106
+					false,
107
+					true
108
+				),
109
+				'CNT_cur_dec_plc' => new EE_Integer_Field(
110
+					'CNT_cur_dec_plc',
111
+					esc_html__('Currency Decimal Places', 'event_espresso'),
112
+					false,
113
+					2
114
+				),
115
+				'CNT_cur_dec_mrk' => new EE_Plain_Text_Field(
116
+					'CNT_cur_dec_mrk',
117
+					esc_html__('Currency Decimal Mark', 'event_espresso'),
118
+					false,
119
+					'.'
120
+				),
121
+				'CNT_cur_thsnds'  => new EE_Plain_Text_Field(
122
+					'CNT_cur_thsnds',
123
+					esc_html__('Currency Thousands Separator', 'event_espresso'),
124
+					false,
125
+					','
126
+				),
127
+				'CNT_tel_code'    => new EE_Plain_Text_Field(
128
+					'CNT_tel_code',
129
+					esc_html__('Country Telephone Code', 'event_espresso'),
130
+					false,
131
+					''
132
+				),
133
+				'CNT_is_EU'       => new EE_Boolean_Field(
134
+					'CNT_is_EU',
135
+					esc_html__('Country is Member of EU', 'event_espresso'),
136
+					false,
137
+					false
138
+				),
139
+			],
140
+		];
141
+		$this->_model_relations = [
142
+			'Attendee' => new EE_Has_Many_Relation(),
143
+			'State'    => new EE_Has_Many_Relation(),
144
+			'Venue'    => new EE_Has_Many_Relation(),
145
+		];
146
+		// only anyone to view, but only those with the default role can do anything
147
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
148
+
149
+		parent::__construct($timezone);
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return EE_Country[]|null
155
+	 * @throws EE_Error
156
+	 * @throws ReflectionException
157
+	 */
158
+	public function get_all_countries(): ?array
159
+	{
160
+		if (! self::$_all_countries) {
161
+			self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
162
+		}
163
+		return self::$_all_countries;
164
+	}
165
+
166
+
167
+	/**
168
+	 * Gets and caches the list of active countries. If you know the list of active countries
169
+	 * has changed during this request, first use EEM_Country::reset() to flush the cache
170
+	 *
171
+	 * @return EE_Country[]|null
172
+	 * @throws EE_Error
173
+	 * @throws ReflectionException
174
+	 */
175
+	public function get_all_active_countries(): ?array
176
+	{
177
+		if (! self::$_active_countries) {
178
+			self::$_active_countries =
179
+				$this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
180
+		}
181
+		return self::$_active_countries;
182
+	}
183
+
184
+
185
+	/**
186
+	 * Gets the country's name by its ISO
187
+	 *
188
+	 * @param string $country_ISO
189
+	 * @return string
190
+	 * @throws EE_Error
191
+	 * @throws ReflectionException
192
+	 */
193
+	public function get_country_name_by_ISO(string $country_ISO): string
194
+	{
195
+		$countries = $this->get_all_countries();
196
+		if (isset($countries[ $country_ISO ]) && $countries[ $country_ISO ] instanceof EE_Country) {
197
+			return $countries[ $country_ISO ]->name();
198
+		}
199
+		$names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name');
200
+		if (is_array($names) && ! empty($names)) {
201
+			return reset($names);
202
+		}
203
+		return '';
204
+	}
205
+
206
+
207
+	/**
208
+	 * Gets the country's name by its name
209
+	 *
210
+	 * @param string $country_name
211
+	 * @return EE_Country|null
212
+	 * @throws EE_Error
213
+	 * @throws ReflectionException
214
+	 */
215
+	public function getCountryByName(string $country_name): ?EE_Country
216
+	{
217
+		$countries = $this->get_all_countries();
218
+		foreach ($countries as $country) {
219
+			if ($country instanceof EE_Country && $country->name() === $country_name) {
220
+				return $country;
221
+			}
222
+		}
223
+		return $this->get_one([['CNT_name' => $country_name]]);
224
+	}
225 225
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
     protected static ?EEM_Country $_instance = null;
15 15
 
16 16
     // array of all countries
17
-    private static ?array $_all_countries = null;
17
+    private static ? array $_all_countries = null;
18 18
 
19 19
     // array of all active countries
20
-    private static ?array $_active_countries = null;
20
+    private static ? array $_active_countries = null;
21 21
 
22 22
 
23 23
     /**
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
             'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'),
50 50
         ];
51 51
 
52
-        $this->_fields          = [
52
+        $this->_fields = [
53 53
             'Country' => [
54 54
                 'CNT_active'      => new EE_Boolean_Field(
55 55
                     'CNT_active',
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
             'Venue'    => new EE_Has_Many_Relation(),
145 145
         ];
146 146
         // only anyone to view, but only those with the default role can do anything
147
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
147
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
148 148
 
149 149
         parent::__construct($timezone);
150 150
     }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function get_all_countries(): ?array
159 159
     {
160
-        if (! self::$_all_countries) {
160
+        if ( ! self::$_all_countries) {
161 161
             self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
162 162
         }
163 163
         return self::$_all_countries;
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      */
175 175
     public function get_all_active_countries(): ?array
176 176
     {
177
-        if (! self::$_active_countries) {
177
+        if ( ! self::$_active_countries) {
178 178
             self::$_active_countries =
179 179
                 $this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
180 180
         }
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
     public function get_country_name_by_ISO(string $country_ISO): string
194 194
     {
195 195
         $countries = $this->get_all_countries();
196
-        if (isset($countries[ $country_ISO ]) && $countries[ $country_ISO ] instanceof EE_Country) {
197
-            return $countries[ $country_ISO ]->name();
196
+        if (isset($countries[$country_ISO]) && $countries[$country_ISO] instanceof EE_Country) {
197
+            return $countries[$country_ISO]->name();
198 198
         }
199 199
         $names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name');
200 200
         if (is_array($names) && ! empty($names)) {
Please login to merge, or discard this patch.
core/db_models/EEM_Question_Option.model.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -9,89 +9,89 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Question_Option extends EEM_Soft_Delete_Base
11 11
 {
12
-    protected static ?EEM_Question_Option $_instance = null;
12
+	protected static ?EEM_Question_Option $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * @param string|null $timezone
17
-     * @throws EE_Error
18
-     */
19
-    protected function __construct(?string $timezone = '')
20
-    {
21
-        $this->singular_item = esc_html__('Question Option', 'event_espresso');
22
-        $this->plural_item   = esc_html__('Question Options', 'event_espresso');
15
+	/**
16
+	 * @param string|null $timezone
17
+	 * @throws EE_Error
18
+	 */
19
+	protected function __construct(?string $timezone = '')
20
+	{
21
+		$this->singular_item = esc_html__('Question Option', 'event_espresso');
22
+		$this->plural_item   = esc_html__('Question Options', 'event_espresso');
23 23
 
24
-        $this->_tables          = [
25
-            'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'),
26
-        ];
27
-        $this->_fields          = [
28
-            'Question_Option' => [
29
-                'QSO_ID'      => new EE_Primary_Key_Int_Field(
30
-                    'QSO_ID',
31
-                    esc_html__('Question Option ID', 'event_espresso')
32
-                ),
33
-                'QST_ID'      => new EE_Foreign_Key_Int_Field(
34
-                    'QST_ID',
35
-                    esc_html__('Question ID', 'event_espresso'),
36
-                    false,
37
-                    0,
38
-                    'Question'
39
-                ),
40
-                'QSO_default' => new EE_Boolean_Field(
41
-                    'QSO_default',
42
-                    esc_html__('Flag indicating this is the default option', 'event_espresso'),
43
-                    false,
44
-                    false
45
-                ),
46
-                'QSO_deleted' => new EE_Trashed_Flag_Field(
47
-                    'QSO_deleted',
48
-                    esc_html__('Flag indicating Option was trashed', 'event_espresso'),
49
-                    false,
50
-                    false
51
-                ),
52
-                'QSO_desc'    => new EE_Post_Content_Field(
53
-                    'QSO_desc',
54
-                    esc_html__('Question Option Description', 'event_espresso'),
55
-                    false,
56
-                    ''
57
-                ),
58
-                'QSO_order'   => new EE_Integer_Field(
59
-                    'QSO_order',
60
-                    esc_html__('Question Option Order', 'event_espresso'),
61
-                    false,
62
-                    0
63
-                ),
64
-                'QSO_system'  => new EE_Plain_Text_Field(
65
-                    'QSO_system',
66
-                    esc_html__('Internal string ID for question option', 'event_espresso'),
67
-                    true,
68
-                    null
69
-                ),
70
-                'QSO_value'   => new EE_Plain_Text_Field(
71
-                    'QSO_value',
72
-                    esc_html__("Question Option Value", "event_espresso"),
73
-                    false,
74
-                    ''
75
-                ),
76
-            ],
77
-        ];
78
-        $this->_model_relations = [
79
-            'Question' => new EE_Belongs_To_Relation(),
80
-        ];
24
+		$this->_tables          = [
25
+			'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'),
26
+		];
27
+		$this->_fields          = [
28
+			'Question_Option' => [
29
+				'QSO_ID'      => new EE_Primary_Key_Int_Field(
30
+					'QSO_ID',
31
+					esc_html__('Question Option ID', 'event_espresso')
32
+				),
33
+				'QST_ID'      => new EE_Foreign_Key_Int_Field(
34
+					'QST_ID',
35
+					esc_html__('Question ID', 'event_espresso'),
36
+					false,
37
+					0,
38
+					'Question'
39
+				),
40
+				'QSO_default' => new EE_Boolean_Field(
41
+					'QSO_default',
42
+					esc_html__('Flag indicating this is the default option', 'event_espresso'),
43
+					false,
44
+					false
45
+				),
46
+				'QSO_deleted' => new EE_Trashed_Flag_Field(
47
+					'QSO_deleted',
48
+					esc_html__('Flag indicating Option was trashed', 'event_espresso'),
49
+					false,
50
+					false
51
+				),
52
+				'QSO_desc'    => new EE_Post_Content_Field(
53
+					'QSO_desc',
54
+					esc_html__('Question Option Description', 'event_espresso'),
55
+					false,
56
+					''
57
+				),
58
+				'QSO_order'   => new EE_Integer_Field(
59
+					'QSO_order',
60
+					esc_html__('Question Option Order', 'event_espresso'),
61
+					false,
62
+					0
63
+				),
64
+				'QSO_system'  => new EE_Plain_Text_Field(
65
+					'QSO_system',
66
+					esc_html__('Internal string ID for question option', 'event_espresso'),
67
+					true,
68
+					null
69
+				),
70
+				'QSO_value'   => new EE_Plain_Text_Field(
71
+					'QSO_value',
72
+					esc_html__("Question Option Value", "event_espresso"),
73
+					false,
74
+					''
75
+				),
76
+			],
77
+		];
78
+		$this->_model_relations = [
79
+			'Question' => new EE_Belongs_To_Relation(),
80
+		];
81 81
 
82
-        $this->_caps_slug              = 'questions';
83
-        $this->_model_chain_to_wp_user = 'Question';
82
+		$this->_caps_slug              = 'questions';
83
+		$this->_model_chain_to_wp_user = 'Question';
84 84
 
85
-        // this model is generally available for reading
86
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
87
-            new EE_Restriction_Generator_Public();
88
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
89
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
90
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
91
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
92
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
93
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
85
+		// this model is generally available for reading
86
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
87
+			new EE_Restriction_Generator_Public();
88
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
89
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
90
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
91
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
92
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
93
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
94 94
 
95
-        parent::__construct($timezone);
96
-    }
95
+		parent::__construct($timezone);
96
+	}
97 97
 }
Please login to merge, or discard this patch.