Completed
Branch FET/reg-form-builder/main (a66e69)
by
unknown
09:49 queued 19s
created
core/domain/services/registration/form/v1/RegFormDependencyHandler.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -7,61 +7,61 @@
 block discarded – undo
7 7
 
8 8
 class RegFormDependencyHandler extends DependencyHandler
9 9
 {
10
-    /**
11
-     * @return void
12
-     */
13
-    public function registerDependencies()
14
-    {
15
-        $reg_form_dependencies = [
16
-            'EventEspresso\core\domain\services\registration\form\v1\RegForm'                => [
17
-                null,
18
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
19
-            ],
20
-            'EventEspresso\core\domain\services\registration\form\v1\RegistrantForm'         => [
21
-                null,
22
-                null,
23
-                null,
24
-                null,
25
-                'EEM_Event_Question_Group' => EE_Dependency_Map::load_from_cache,
26
-            ],
27
-            'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => [
28
-                null,
29
-                'EEM_Answer' => EE_Dependency_Map::load_from_cache,
30
-            ],
31
-            'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionGroup'   => [
32
-                null,
33
-                null,
34
-                null,
35
-                'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => EE_Dependency_Map::load_from_cache,
36
-            ],
37
-            'EventEspresso\core\domain\services\registration\form\v1\CountryOptions'         => [
38
-                null,
39
-                'EEM_Answer'  => EE_Dependency_Map::load_from_cache,
40
-                'EEM_Country' => EE_Dependency_Map::load_from_cache,
41
-            ],
42
-            'EventEspresso\core\domain\services\registration\form\v1\StateOptions'           => [
43
-                null,
44
-                'EEM_State' => EE_Dependency_Map::load_from_cache,
45
-            ],
46
-            'EventEspresso\core\domain\services\registration\form\v1\RegFormHandler'         => [
47
-                null,
48
-                'EventEspresso\core\domain\services\registration\form\v1\RegistrantData'         => EE_Dependency_Map::load_from_cache,
49
-                'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => EE_Dependency_Map::load_from_cache,
50
-                'EE_Registration_Processor'                                                      => EE_Dependency_Map::load_from_cache,
51
-            ],
52
-            'EventEspresso\core\domain\services\registration\form\v1\RegFormInputHandler'    => [
53
-                null,
54
-                null,
55
-                'EEM_Attendee'                                                           => EE_Dependency_Map::load_from_cache,
56
-                'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache,
57
-            ],
58
-            'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => [
59
-                'EventEspresso\core\services\commands\CommandBus'                        => EE_Dependency_Map::load_from_cache,
60
-                'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache,
61
-            ],
62
-        ];
63
-        foreach ($reg_form_dependencies as $class => $dependencies) {
64
-            $this->dependency_map->registerDependencies($class, $dependencies);
65
-        }
66
-    }
10
+	/**
11
+	 * @return void
12
+	 */
13
+	public function registerDependencies()
14
+	{
15
+		$reg_form_dependencies = [
16
+			'EventEspresso\core\domain\services\registration\form\v1\RegForm'                => [
17
+				null,
18
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
19
+			],
20
+			'EventEspresso\core\domain\services\registration\form\v1\RegistrantForm'         => [
21
+				null,
22
+				null,
23
+				null,
24
+				null,
25
+				'EEM_Event_Question_Group' => EE_Dependency_Map::load_from_cache,
26
+			],
27
+			'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => [
28
+				null,
29
+				'EEM_Answer' => EE_Dependency_Map::load_from_cache,
30
+			],
31
+			'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionGroup'   => [
32
+				null,
33
+				null,
34
+				null,
35
+				'EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory' => EE_Dependency_Map::load_from_cache,
36
+			],
37
+			'EventEspresso\core\domain\services\registration\form\v1\CountryOptions'         => [
38
+				null,
39
+				'EEM_Answer'  => EE_Dependency_Map::load_from_cache,
40
+				'EEM_Country' => EE_Dependency_Map::load_from_cache,
41
+			],
42
+			'EventEspresso\core\domain\services\registration\form\v1\StateOptions'           => [
43
+				null,
44
+				'EEM_State' => EE_Dependency_Map::load_from_cache,
45
+			],
46
+			'EventEspresso\core\domain\services\registration\form\v1\RegFormHandler'         => [
47
+				null,
48
+				'EventEspresso\core\domain\services\registration\form\v1\RegistrantData'         => EE_Dependency_Map::load_from_cache,
49
+				'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => EE_Dependency_Map::load_from_cache,
50
+				'EE_Registration_Processor'                                                      => EE_Dependency_Map::load_from_cache,
51
+			],
52
+			'EventEspresso\core\domain\services\registration\form\v1\RegFormInputHandler'    => [
53
+				null,
54
+				null,
55
+				'EEM_Attendee'                                                           => EE_Dependency_Map::load_from_cache,
56
+				'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache,
57
+			],
58
+			'EventEspresso\core\domain\services\registration\form\v1\RegFormAttendeeFactory' => [
59
+				'EventEspresso\core\services\commands\CommandBus'                        => EE_Dependency_Map::load_from_cache,
60
+				'EventEspresso\core\domain\services\registration\form\v1\RegistrantData' => EE_Dependency_Map::load_from_cache,
61
+			],
62
+		];
63
+		foreach ($reg_form_dependencies as $class => $dependencies) {
64
+			$this->dependency_map->registerDependencies($class, $dependencies);
65
+		}
66
+	}
67 67
 }
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegFormQuestionFactory.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -16,117 +16,117 @@
 block discarded – undo
16 16
 class RegFormQuestionFactory
17 17
 {
18 18
 
19
-    /**
20
-     * @var callable
21
-     */
22
-    protected $addRequiredQuestion;
19
+	/**
20
+	 * @var callable
21
+	 */
22
+	protected $addRequiredQuestion;
23 23
 
24
-    /**
25
-     * @var EEM_Answer
26
-     */
27
-    public $answer_model;
24
+	/**
25
+	 * @var EEM_Answer
26
+	 */
27
+	public $answer_model;
28 28
 
29 29
 
30
-    /**
31
-     * @param callable   $addRequiredQuestion
32
-     * @param EEM_Answer $answer_model
33
-     */
34
-    public function __construct(callable $addRequiredQuestion, EEM_Answer $answer_model) {
35
-        $this->addRequiredQuestion = $addRequiredQuestion;
36
-        $this->answer_model = $answer_model;
37
-    }
30
+	/**
31
+	 * @param callable   $addRequiredQuestion
32
+	 * @param EEM_Answer $answer_model
33
+	 */
34
+	public function __construct(callable $addRequiredQuestion, EEM_Answer $answer_model) {
35
+		$this->addRequiredQuestion = $addRequiredQuestion;
36
+		$this->answer_model = $answer_model;
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * @param EE_Registration $registration
42
-     * @param EE_Question     $question
43
-     * @return EE_Form_Input_Base
44
-     * @throws EE_Error
45
-     * @throws InvalidArgumentException
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws ReflectionException
49
-     */
50
-    public function create(
51
-        EE_Registration $registration,
52
-        EE_Question $question
53
-    ): EE_Form_Input_Base {
54
-        // if this question was for an attendee detail, then check for that answer
55
-        $answer_value = $this->answer_model->get_attendee_property_answer_value(
56
-            $registration,
57
-            $question->system_ID()
58
-        );
59
-        $answer       = $answer_value === null
60
-            ? $this->answer_model->get_one(
61
-                [['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]]
62
-            )
63
-            : null;
64
-        // if NOT returning to edit an existing registration
65
-        // OR if this question is for an attendee property
66
-        // OR we still don't have an EE_Answer object
67
-        if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
68
-            // create an EE_Answer object for storing everything in
69
-            $answer = EE_Answer::new_instance(
70
-                [
71
-                    'QST_ID' => $question->ID(),
72
-                    'REG_ID' => $registration->ID(),
73
-                ]
74
-            );
75
-        }
76
-        // verify instance
77
-        if ($answer instanceof EE_Answer) {
78
-            if (! empty($answer_value)) {
79
-                $answer->set('ANS_value', $answer_value);
80
-            }
81
-            $answer->cache('Question', $question);
82
-            // remember system ID had a bug where sometimes it could be null
83
-            $answer_cache_id = $question->is_system_question()
84
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
85
-                : $question->ID() . '-' . $registration->reg_url_link();
86
-            $registration->cache('Answer', $answer, $answer_cache_id);
87
-        }
88
-        return $this->generateQuestionInput($registration, $question, $answer);
89
-    }
40
+	/**
41
+	 * @param EE_Registration $registration
42
+	 * @param EE_Question     $question
43
+	 * @return EE_Form_Input_Base
44
+	 * @throws EE_Error
45
+	 * @throws InvalidArgumentException
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws ReflectionException
49
+	 */
50
+	public function create(
51
+		EE_Registration $registration,
52
+		EE_Question $question
53
+	): EE_Form_Input_Base {
54
+		// if this question was for an attendee detail, then check for that answer
55
+		$answer_value = $this->answer_model->get_attendee_property_answer_value(
56
+			$registration,
57
+			$question->system_ID()
58
+		);
59
+		$answer       = $answer_value === null
60
+			? $this->answer_model->get_one(
61
+				[['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]]
62
+			)
63
+			: null;
64
+		// if NOT returning to edit an existing registration
65
+		// OR if this question is for an attendee property
66
+		// OR we still don't have an EE_Answer object
67
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
68
+			// create an EE_Answer object for storing everything in
69
+			$answer = EE_Answer::new_instance(
70
+				[
71
+					'QST_ID' => $question->ID(),
72
+					'REG_ID' => $registration->ID(),
73
+				]
74
+			);
75
+		}
76
+		// verify instance
77
+		if ($answer instanceof EE_Answer) {
78
+			if (! empty($answer_value)) {
79
+				$answer->set('ANS_value', $answer_value);
80
+			}
81
+			$answer->cache('Question', $question);
82
+			// remember system ID had a bug where sometimes it could be null
83
+			$answer_cache_id = $question->is_system_question()
84
+				? $question->system_ID() . '-' . $registration->reg_url_link()
85
+				: $question->ID() . '-' . $registration->reg_url_link();
86
+			$registration->cache('Answer', $answer, $answer_cache_id);
87
+		}
88
+		return $this->generateQuestionInput($registration, $question, $answer);
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * @param EE_Registration $registration
94
-     * @param EE_Question     $question
95
-     * @param                 $answer
96
-     * @return EE_Form_Input_Base
97
-     * @throws EE_Error
98
-     * @throws InvalidArgumentException
99
-     * @throws ReflectionException
100
-     * @throws InvalidDataTypeException
101
-     * @throws InvalidInterfaceException
102
-     */
103
-    private function generateQuestionInput(
104
-        EE_Registration $registration,
105
-        EE_Question $question,
106
-        $answer
107
-    ): EE_Form_Input_Base {
108
-        $identifier                              = $question->is_system_question()
109
-            ? $question->system_ID()
110
-            : $question->ID();
111
-        $callback = $this->addRequiredQuestion;
112
-        $callback($identifier, $question->required());
113
-        $input_constructor_args                  = [
114
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
115
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
116
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
117
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
118
-            'html_label_class' => 'ee-reg-qstn',
119
-        ];
120
-        $input_constructor_args['html_label_id'] .= '-lbl';
121
-        if ($answer instanceof EE_Answer && $answer->ID()) {
122
-            $input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
123
-            $input_constructor_args['html_id']       .= '-' . $answer->ID();
124
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
125
-        }
126
-        return $question->generate_form_input(
127
-            $registration,
128
-            $answer,
129
-            $input_constructor_args
130
-        );
131
-    }
92
+	/**
93
+	 * @param EE_Registration $registration
94
+	 * @param EE_Question     $question
95
+	 * @param                 $answer
96
+	 * @return EE_Form_Input_Base
97
+	 * @throws EE_Error
98
+	 * @throws InvalidArgumentException
99
+	 * @throws ReflectionException
100
+	 * @throws InvalidDataTypeException
101
+	 * @throws InvalidInterfaceException
102
+	 */
103
+	private function generateQuestionInput(
104
+		EE_Registration $registration,
105
+		EE_Question $question,
106
+		$answer
107
+	): EE_Form_Input_Base {
108
+		$identifier                              = $question->is_system_question()
109
+			? $question->system_ID()
110
+			: $question->ID();
111
+		$callback = $this->addRequiredQuestion;
112
+		$callback($identifier, $question->required());
113
+		$input_constructor_args                  = [
114
+			'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
115
+			'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
116
+			'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
117
+			'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
118
+			'html_label_class' => 'ee-reg-qstn',
119
+		];
120
+		$input_constructor_args['html_label_id'] .= '-lbl';
121
+		if ($answer instanceof EE_Answer && $answer->ID()) {
122
+			$input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
123
+			$input_constructor_args['html_id']       .= '-' . $answer->ID();
124
+			$input_constructor_args['html_label_id'] .= '-' . $answer->ID();
125
+		}
126
+		return $question->generate_form_input(
127
+			$registration,
128
+			$answer,
129
+			$input_constructor_args
130
+		);
131
+	}
132 132
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             $registration,
57 57
             $question->system_ID()
58 58
         );
59
-        $answer       = $answer_value === null
59
+        $answer = $answer_value === null
60 60
             ? $this->answer_model->get_one(
61 61
                 [['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]]
62 62
             )
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
         }
76 76
         // verify instance
77 77
         if ($answer instanceof EE_Answer) {
78
-            if (! empty($answer_value)) {
78
+            if ( ! empty($answer_value)) {
79 79
                 $answer->set('ANS_value', $answer_value);
80 80
             }
81 81
             $answer->cache('Question', $question);
82 82
             // remember system ID had a bug where sometimes it could be null
83 83
             $answer_cache_id = $question->is_system_question()
84
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
85
-                : $question->ID() . '-' . $registration->reg_url_link();
84
+                ? $question->system_ID().'-'.$registration->reg_url_link()
85
+                : $question->ID().'-'.$registration->reg_url_link();
86 86
             $registration->cache('Answer', $answer, $answer_cache_id);
87 87
         }
88 88
         return $this->generateQuestionInput($registration, $question, $answer);
@@ -105,23 +105,23 @@  discard block
 block discarded – undo
105 105
         EE_Question $question,
106 106
         $answer
107 107
     ): EE_Form_Input_Base {
108
-        $identifier                              = $question->is_system_question()
108
+        $identifier = $question->is_system_question()
109 109
             ? $question->system_ID()
110 110
             : $question->ID();
111 111
         $callback = $this->addRequiredQuestion;
112 112
         $callback($identifier, $question->required());
113
-        $input_constructor_args                  = [
114
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
115
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
116
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
117
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
113
+        $input_constructor_args = [
114
+            'html_name'        => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']',
115
+            'html_id'          => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
116
+            'html_class'       => 'ee-reg-qstn ee-reg-qstn-'.$identifier,
117
+            'html_label_id'    => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
118 118
             'html_label_class' => 'ee-reg-qstn',
119 119
         ];
120 120
         $input_constructor_args['html_label_id'] .= '-lbl';
121 121
         if ($answer instanceof EE_Answer && $answer->ID()) {
122
-            $input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
123
-            $input_constructor_args['html_id']       .= '-' . $answer->ID();
124
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
122
+            $input_constructor_args['html_name']     .= '['.$answer->ID().']';
123
+            $input_constructor_args['html_id']       .= '-'.$answer->ID();
124
+            $input_constructor_args['html_label_id'] .= '-'.$answer->ID();
125 125
         }
126 126
         return $question->generate_form_input(
127 127
             $registration,
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegistrantForm.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -17,192 +17,192 @@
 block discarded – undo
17 17
 class RegistrantForm extends EE_Form_Section_Proper
18 18
 {
19 19
 
20
-    /**
21
-     * @var EEM_Event_Question_Group
22
-     */
23
-    public $event_question_group_model;
24
-
25
-    /**
26
-     * @var bool
27
-     */
28
-    private $has_questions = false;
29
-
30
-
31
-    /**
32
-     * RegistrantForm constructor.
33
-     *
34
-     * @param EE_Registration          $registration
35
-     * @param bool                     $admin_request
36
-     * @param bool                     $copy_attendee_info
37
-     * @param callable                 $enablePrintCopyInfo
38
-     * @param EEM_Event_Question_Group $event_question_group_model
39
-     * @throws EE_Error
40
-     * @throws ReflectionException
41
-     */
42
-    public function __construct(
43
-        EE_Registration $registration,
44
-        bool $admin_request,
45
-        bool $copy_attendee_info,
46
-        callable $enablePrintCopyInfo,
47
-        EEM_Event_Question_Group $event_question_group_model
48
-    ) {
49
-        $this->event_question_group_model = $event_question_group_model;
50
-        parent::__construct(
51
-            $this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo)
52
-        );
53
-    }
54
-
55
-
56
-    /**
57
-     * @return bool
58
-     */
59
-    public function hasQuestions(): bool
60
-    {
61
-        return $this->has_questions;
62
-    }
63
-
64
-
65
-    /**
66
-     * @param EE_Registration $registration
67
-     * @param bool            $admin_request
68
-     * @param bool            $copy_attendee_info
69
-     * @param callable        $enablePrintCopyInfo
70
-     * @return array
71
-     * @throws EE_Error
72
-     * @throws ReflectionException
73
-     */
74
-    private function generateFormArgs(
75
-        EE_Registration $registration,
76
-        bool $admin_request,
77
-        bool $copy_attendee_info,
78
-        callable $enablePrintCopyInfo
79
-    ): array {
80
-        static $attendee_nmbr = 1;
81
-        $form_args = [];
82
-        // verify that registration has valid event
83
-        if ($registration->event() instanceof EE_Event) {
84
-            $field_name      = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext(
85
-                $registration->is_primary_registrant()
86
-            );
87
-            $question_groups = $registration->event()->question_groups(
88
-                apply_filters(
89
-                    // @codingStandardsIgnoreStart
90
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
91
-                    // @codingStandardsIgnoreEnd
92
-                    [
93
-                        [
94
-                            'Event.EVT_ID' => $registration->event()->ID(),
95
-                            $field_name    => true,
96
-                        ],
97
-                        'order_by' => ['QSG_order' => 'ASC'],
98
-                    ],
99
-                    $registration,
100
-                    $this
101
-                )
102
-            );
103
-            if ($question_groups) {
104
-                // array of params to pass to parent constructor
105
-                $form_args = [
106
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
107
-                    'html_class'      => 'ee-reg-form-attendee-dv',
108
-                    'html_style'      => $admin_request
109
-                        ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
110
-                        : '',
111
-                    'subsections'     => [],
112
-                    'layout_strategy' => new EE_Fieldset_Section_Layout(
113
-                        [
114
-                            'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
115
-                            'legend_text'  => sprintf(
116
-                                esc_html_x(
117
-                                    'Attendee %d',
118
-                                    'Attendee 123',
119
-                                    'event_espresso'
120
-                                ),
121
-                                $attendee_nmbr
122
-                            ),
123
-                        ]
124
-                    ),
125
-                ];
126
-                foreach ($question_groups as $question_group) {
127
-                    if ($question_group instanceof EE_Question_Group) {
128
-                        $question_group_reg_form = LoaderFactory::getNew(
129
-                            RegFormQuestionGroup::class,
130
-                            [$registration, $question_group, $admin_request]
131
-                        );
132
-                        $form_args['subsections'][ $question_group->identifier() ] = apply_filters(
133
-                            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
134
-                            $question_group_reg_form,
135
-                            $registration,
136
-                            $question_group,
137
-                            $this
138
-                        );
139
-                    }
140
-                }
141
-                // add hidden input
142
-                $form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput(
143
-                    $registration
144
-                );
145
-
146
-                // If we have question groups for additional attendees, then display the copy options
147
-                $printCopyInfo = apply_filters(
148
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
149
-                    $attendee_nmbr > 1 && $copy_attendee_info,
150
-                    $attendee_nmbr
151
-                );
152
-                if ($printCopyInfo) {
153
-                    $enablePrintCopyInfo();
154
-                }
155
-
156
-
157
-                if ($registration->is_primary_registrant()) {
158
-                    // generate hidden input
159
-                    $form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs(
160
-                        $registration
161
-                    );
162
-                }
163
-            }
164
-        }
165
-        $attendee_nmbr++;
166
-
167
-        // Increment the reg forms number if form is valid.
168
-        if (! empty($form_args)) {
169
-            $this->has_questions = true;
170
-        }
171
-
172
-        return $form_args;
173
-    }
174
-
175
-
176
-    /**
177
-     * @param EE_Registration $registration
178
-     * @return EE_Form_Input_Base
179
-     * @throws EE_Error
180
-     */
181
-    private function additionalAttendeeRegInfoInput(EE_Registration $registration)
182
-    {
183
-        // generate hidden input
184
-        return new EE_Hidden_Input(
185
-            [
186
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
187
-                'default' => true,
188
-            ]
189
-        );
190
-    }
191
-
192
-
193
-    /**
194
-     * @param EE_Registration $registration
195
-     * @return    EE_Form_Input_Base
196
-     * @throws EE_Error
197
-     */
198
-    private function additionalPrimaryRegistrantInputs(EE_Registration $registration)
199
-    {
200
-        // generate hidden input
201
-        return new EE_Hidden_Input(
202
-            [
203
-                'html_id' => 'primary_registrant',
204
-                'default' => $registration->reg_url_link(),
205
-            ]
206
-        );
207
-    }
20
+	/**
21
+	 * @var EEM_Event_Question_Group
22
+	 */
23
+	public $event_question_group_model;
24
+
25
+	/**
26
+	 * @var bool
27
+	 */
28
+	private $has_questions = false;
29
+
30
+
31
+	/**
32
+	 * RegistrantForm constructor.
33
+	 *
34
+	 * @param EE_Registration          $registration
35
+	 * @param bool                     $admin_request
36
+	 * @param bool                     $copy_attendee_info
37
+	 * @param callable                 $enablePrintCopyInfo
38
+	 * @param EEM_Event_Question_Group $event_question_group_model
39
+	 * @throws EE_Error
40
+	 * @throws ReflectionException
41
+	 */
42
+	public function __construct(
43
+		EE_Registration $registration,
44
+		bool $admin_request,
45
+		bool $copy_attendee_info,
46
+		callable $enablePrintCopyInfo,
47
+		EEM_Event_Question_Group $event_question_group_model
48
+	) {
49
+		$this->event_question_group_model = $event_question_group_model;
50
+		parent::__construct(
51
+			$this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo)
52
+		);
53
+	}
54
+
55
+
56
+	/**
57
+	 * @return bool
58
+	 */
59
+	public function hasQuestions(): bool
60
+	{
61
+		return $this->has_questions;
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param EE_Registration $registration
67
+	 * @param bool            $admin_request
68
+	 * @param bool            $copy_attendee_info
69
+	 * @param callable        $enablePrintCopyInfo
70
+	 * @return array
71
+	 * @throws EE_Error
72
+	 * @throws ReflectionException
73
+	 */
74
+	private function generateFormArgs(
75
+		EE_Registration $registration,
76
+		bool $admin_request,
77
+		bool $copy_attendee_info,
78
+		callable $enablePrintCopyInfo
79
+	): array {
80
+		static $attendee_nmbr = 1;
81
+		$form_args = [];
82
+		// verify that registration has valid event
83
+		if ($registration->event() instanceof EE_Event) {
84
+			$field_name      = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext(
85
+				$registration->is_primary_registrant()
86
+			);
87
+			$question_groups = $registration->event()->question_groups(
88
+				apply_filters(
89
+					// @codingStandardsIgnoreStart
90
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
91
+					// @codingStandardsIgnoreEnd
92
+					[
93
+						[
94
+							'Event.EVT_ID' => $registration->event()->ID(),
95
+							$field_name    => true,
96
+						],
97
+						'order_by' => ['QSG_order' => 'ASC'],
98
+					],
99
+					$registration,
100
+					$this
101
+				)
102
+			);
103
+			if ($question_groups) {
104
+				// array of params to pass to parent constructor
105
+				$form_args = [
106
+					'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
107
+					'html_class'      => 'ee-reg-form-attendee-dv',
108
+					'html_style'      => $admin_request
109
+						? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
110
+						: '',
111
+					'subsections'     => [],
112
+					'layout_strategy' => new EE_Fieldset_Section_Layout(
113
+						[
114
+							'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
115
+							'legend_text'  => sprintf(
116
+								esc_html_x(
117
+									'Attendee %d',
118
+									'Attendee 123',
119
+									'event_espresso'
120
+								),
121
+								$attendee_nmbr
122
+							),
123
+						]
124
+					),
125
+				];
126
+				foreach ($question_groups as $question_group) {
127
+					if ($question_group instanceof EE_Question_Group) {
128
+						$question_group_reg_form = LoaderFactory::getNew(
129
+							RegFormQuestionGroup::class,
130
+							[$registration, $question_group, $admin_request]
131
+						);
132
+						$form_args['subsections'][ $question_group->identifier() ] = apply_filters(
133
+							'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
134
+							$question_group_reg_form,
135
+							$registration,
136
+							$question_group,
137
+							$this
138
+						);
139
+					}
140
+				}
141
+				// add hidden input
142
+				$form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput(
143
+					$registration
144
+				);
145
+
146
+				// If we have question groups for additional attendees, then display the copy options
147
+				$printCopyInfo = apply_filters(
148
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
149
+					$attendee_nmbr > 1 && $copy_attendee_info,
150
+					$attendee_nmbr
151
+				);
152
+				if ($printCopyInfo) {
153
+					$enablePrintCopyInfo();
154
+				}
155
+
156
+
157
+				if ($registration->is_primary_registrant()) {
158
+					// generate hidden input
159
+					$form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs(
160
+						$registration
161
+					);
162
+				}
163
+			}
164
+		}
165
+		$attendee_nmbr++;
166
+
167
+		// Increment the reg forms number if form is valid.
168
+		if (! empty($form_args)) {
169
+			$this->has_questions = true;
170
+		}
171
+
172
+		return $form_args;
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param EE_Registration $registration
178
+	 * @return EE_Form_Input_Base
179
+	 * @throws EE_Error
180
+	 */
181
+	private function additionalAttendeeRegInfoInput(EE_Registration $registration)
182
+	{
183
+		// generate hidden input
184
+		return new EE_Hidden_Input(
185
+			[
186
+				'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
187
+				'default' => true,
188
+			]
189
+		);
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param EE_Registration $registration
195
+	 * @return    EE_Form_Input_Base
196
+	 * @throws EE_Error
197
+	 */
198
+	private function additionalPrimaryRegistrantInputs(EE_Registration $registration)
199
+	{
200
+		// generate hidden input
201
+		return new EE_Hidden_Input(
202
+			[
203
+				'html_id' => 'primary_registrant',
204
+				'default' => $registration->reg_url_link(),
205
+			]
206
+		);
207
+	}
208 208
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         $form_args = [];
82 82
         // verify that registration has valid event
83 83
         if ($registration->event() instanceof EE_Event) {
84
-            $field_name      = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext(
84
+            $field_name      = 'Event_Question_Group.'.$this->event_question_group_model->fieldNameForContext(
85 85
                 $registration->is_primary_registrant()
86 86
             );
87 87
             $question_groups = $registration->event()->question_groups(
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
             if ($question_groups) {
104 104
                 // array of params to pass to parent constructor
105 105
                 $form_args = [
106
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
106
+                    'html_id'         => 'ee-registration-'.$registration->reg_url_link(),
107 107
                     'html_class'      => 'ee-reg-form-attendee-dv',
108 108
                     'html_style'      => $admin_request
109 109
                         ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
                             RegFormQuestionGroup::class,
130 130
                             [$registration, $question_group, $admin_request]
131 131
                         );
132
-                        $form_args['subsections'][ $question_group->identifier() ] = apply_filters(
132
+                        $form_args['subsections'][$question_group->identifier()] = apply_filters(
133 133
                             'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
134 134
                             $question_group_reg_form,
135 135
                             $registration,
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
         $attendee_nmbr++;
166 166
 
167 167
         // Increment the reg forms number if form is valid.
168
-        if (! empty($form_args)) {
168
+        if ( ! empty($form_args)) {
169 169
             $this->has_questions = true;
170 170
         }
171 171
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         // generate hidden input
184 184
         return new EE_Hidden_Input(
185 185
             [
186
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
186
+                'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(),
187 187
                 'default' => true,
188 188
             ]
189 189
         );
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegFormInputHandler.php 2 patches
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -14,223 +14,223 @@
 block discarded – undo
14 14
 class RegFormInputHandler
15 15
 {
16 16
 
17
-    /**
18
-     * @var EEM_Attendee
19
-     */
20
-    private $attendee_model;
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    private $checkout_reg_url_link;
26
-
27
-    /**
28
-     * @var RegistrantData
29
-     */
30
-    private $registrant_data;
31
-
32
-    /**
33
-     * @var array
34
-     */
35
-    private $required_questions;
36
-
37
-
38
-    /**
39
-     * RegFormHandler constructor.
40
-     */
41
-    public function __construct(
42
-        string $checkout_reg_url_link,
43
-        array $required_questions,
44
-        EEM_Attendee $attendee_model,
45
-        RegistrantData $registrant_data
46
-    ) {
47
-        $this->attendee_model        = $attendee_model;
48
-        $this->checkout_reg_url_link = $checkout_reg_url_link;
49
-        $this->registrant_data       = $registrant_data;
50
-        $this->required_questions    = $required_questions;
51
-    }
52
-
53
-
54
-    /**
55
-     * @param EE_Registration  $registration
56
-     * @param string           $reg_url_link
57
-     * @param int|string       $form_input
58
-     * @param float|int|string $input_value
59
-     * @return bool
60
-     * @throws EE_Error
61
-     * @throws ReflectionException
62
-     */
63
-    public function processFormInput(
64
-        EE_Registration $registration,
65
-        string $reg_url_link,
66
-        $form_input,
67
-        $input_value
68
-    ): bool {
69
-        // check for critical inputs
70
-        if (! $this->verifyCriticalAttendeeDetailsAreSetAndValidateEmail($form_input, $input_value)) {
71
-            return false;
72
-        }
73
-        $input_value = $this->registrant_data->saveOrCopyPrimaryRegistrantData(
74
-            $reg_url_link,
75
-            $form_input,
76
-            $input_value
77
-        );
78
-        if (! $this->saveRegistrationFormInput($registration, $reg_url_link, $form_input, $input_value)) {
79
-            EE_Error::add_error(
80
-                sprintf(
81
-                    esc_html_x(
82
-                        'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
83
-                        'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
84
-                        'event_espresso'
85
-                    ),
86
-                    $form_input,
87
-                    $input_value
88
-                ),
89
-                __FILE__,
90
-                __FUNCTION__,
91
-                __LINE__
92
-            );
93
-            return false;
94
-        }
95
-        return true;
96
-    }
97
-
98
-
99
-    /**
100
-     * @param EE_Registration  $registration
101
-     * @param string           $reg_url_link
102
-     * @param int|string       $form_input
103
-     * @param float|int|string $input_value
104
-     * @return bool
105
-     * @throws EE_Error
106
-     * @throws InvalidArgumentException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     * @throws ReflectionException
110
-     */
111
-    private function saveRegistrationFormInput(
112
-        EE_Registration $registration,
113
-        string $reg_url_link,
114
-        $form_input = '',
115
-        $input_value = ''
116
-    ): bool {
117
-        // If email_confirm is sent it's not saved
118
-        if ((string) $form_input === 'email_confirm') {
119
-            return true;
120
-        }
121
-        // allow for plugins to hook in and do their own processing of the form input.
122
-        // For plugins to bypass normal processing here, they just need to return a truthy value.
123
-        if (
124
-            apply_filters(
125
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
126
-                false,
127
-                $registration,
128
-                $form_input,
129
-                $input_value,
130
-                $this
131
-            )
132
-        ) {
133
-            return true;
134
-        }
135
-        /*
17
+	/**
18
+	 * @var EEM_Attendee
19
+	 */
20
+	private $attendee_model;
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	private $checkout_reg_url_link;
26
+
27
+	/**
28
+	 * @var RegistrantData
29
+	 */
30
+	private $registrant_data;
31
+
32
+	/**
33
+	 * @var array
34
+	 */
35
+	private $required_questions;
36
+
37
+
38
+	/**
39
+	 * RegFormHandler constructor.
40
+	 */
41
+	public function __construct(
42
+		string $checkout_reg_url_link,
43
+		array $required_questions,
44
+		EEM_Attendee $attendee_model,
45
+		RegistrantData $registrant_data
46
+	) {
47
+		$this->attendee_model        = $attendee_model;
48
+		$this->checkout_reg_url_link = $checkout_reg_url_link;
49
+		$this->registrant_data       = $registrant_data;
50
+		$this->required_questions    = $required_questions;
51
+	}
52
+
53
+
54
+	/**
55
+	 * @param EE_Registration  $registration
56
+	 * @param string           $reg_url_link
57
+	 * @param int|string       $form_input
58
+	 * @param float|int|string $input_value
59
+	 * @return bool
60
+	 * @throws EE_Error
61
+	 * @throws ReflectionException
62
+	 */
63
+	public function processFormInput(
64
+		EE_Registration $registration,
65
+		string $reg_url_link,
66
+		$form_input,
67
+		$input_value
68
+	): bool {
69
+		// check for critical inputs
70
+		if (! $this->verifyCriticalAttendeeDetailsAreSetAndValidateEmail($form_input, $input_value)) {
71
+			return false;
72
+		}
73
+		$input_value = $this->registrant_data->saveOrCopyPrimaryRegistrantData(
74
+			$reg_url_link,
75
+			$form_input,
76
+			$input_value
77
+		);
78
+		if (! $this->saveRegistrationFormInput($registration, $reg_url_link, $form_input, $input_value)) {
79
+			EE_Error::add_error(
80
+				sprintf(
81
+					esc_html_x(
82
+						'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
83
+						'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
84
+						'event_espresso'
85
+					),
86
+					$form_input,
87
+					$input_value
88
+				),
89
+				__FILE__,
90
+				__FUNCTION__,
91
+				__LINE__
92
+			);
93
+			return false;
94
+		}
95
+		return true;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param EE_Registration  $registration
101
+	 * @param string           $reg_url_link
102
+	 * @param int|string       $form_input
103
+	 * @param float|int|string $input_value
104
+	 * @return bool
105
+	 * @throws EE_Error
106
+	 * @throws InvalidArgumentException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 * @throws ReflectionException
110
+	 */
111
+	private function saveRegistrationFormInput(
112
+		EE_Registration $registration,
113
+		string $reg_url_link,
114
+		$form_input = '',
115
+		$input_value = ''
116
+	): bool {
117
+		// If email_confirm is sent it's not saved
118
+		if ((string) $form_input === 'email_confirm') {
119
+			return true;
120
+		}
121
+		// allow for plugins to hook in and do their own processing of the form input.
122
+		// For plugins to bypass normal processing here, they just need to return a truthy value.
123
+		if (
124
+			apply_filters(
125
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
126
+				false,
127
+				$registration,
128
+				$form_input,
129
+				$input_value,
130
+				$this
131
+			)
132
+		) {
133
+			return true;
134
+		}
135
+		/*
136 136
          * $answer_cache_id is the key used to find the EE_Answer we want
137 137
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
138 138
          */
139
-        $answer_cache_id   = $this->checkout_reg_url_link
140
-            ? $form_input . '-' . $reg_url_link
141
-            : $form_input;
142
-        $registrant_answer = $this->registrant_data->getRegistrantAnswer($reg_url_link, $answer_cache_id);
143
-        $answer_is_obj     = $registrant_answer instanceof EE_Answer;
144
-        // rename form_inputs if they are EE_Attendee properties
145
-        switch ((string) $form_input) {
146
-            case 'state':
147
-            case 'STA_ID':
148
-                $attendee_property = true;
149
-                $form_input        = 'STA_ID';
150
-                break;
151
-
152
-            case 'country':
153
-            case 'CNT_ISO':
154
-                $attendee_property = true;
155
-                $form_input        = 'CNT_ISO';
156
-                break;
157
-
158
-            default:
159
-                $ATT_input         = 'ATT_' . $form_input;
160
-                $attendee_property = $this->attendee_model->has_field($ATT_input);
161
-                $form_input        = $attendee_property
162
-                    ? 'ATT_' . $form_input
163
-                    : $form_input;
164
-        }
165
-
166
-        // if this form input has a corresponding attendee property
167
-        if ($attendee_property) {
168
-            $this->registrant_data->addRegistrantDataValue($reg_url_link, $form_input, $input_value);
169
-            if ($answer_is_obj) {
170
-                // and delete the corresponding answer since we won't be storing this data in that object
171
-                $registration->_remove_relation_to($registrant_answer, 'Answer');
172
-                $registrant_answer->delete_permanently();
173
-            }
174
-            return true;
175
-        }
176
-        if ($answer_is_obj) {
177
-            // save this data to the answer object
178
-            $registrant_answer->set_value($input_value);
179
-            $result = $registrant_answer->save();
180
-            return $result !== false;
181
-        }
182
-        foreach ($this->registrant_data->registrantAnswers($reg_url_link) as $answer) {
183
-            if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
184
-                $answer->set_value($input_value);
185
-                $result = $answer->save();
186
-                return $result !== false;
187
-            }
188
-        }
189
-        return false;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param int|string       $form_input
195
-     * @param float|int|string $input_value
196
-     * @return boolean
197
-     */
198
-    private function verifyCriticalAttendeeDetailsAreSetAndValidateEmail(
199
-        $form_input = '',
200
-        $input_value = ''
201
-    ): bool {
202
-        if (empty($input_value)) {
203
-            // if the form input isn't marked as being required, then just return
204
-            if (! isset($this->required_questions[ $form_input ]) || ! $this->required_questions[ $form_input ]) {
205
-                return true;
206
-            }
207
-            switch ($form_input) {
208
-                case 'fname':
209
-                    EE_Error::add_error(
210
-                        esc_html__('First Name is a required value.', 'event_espresso'),
211
-                        __FILE__,
212
-                        __FUNCTION__,
213
-                        __LINE__
214
-                    );
215
-                    return false;
216
-                case 'lname':
217
-                    EE_Error::add_error(
218
-                        esc_html__('Last Name is a required value.', 'event_espresso'),
219
-                        __FILE__,
220
-                        __FUNCTION__,
221
-                        __LINE__
222
-                    );
223
-                    return false;
224
-                case 'email':
225
-                    EE_Error::add_error(
226
-                        esc_html__('Please enter a valid email address.', 'event_espresso'),
227
-                        __FILE__,
228
-                        __FUNCTION__,
229
-                        __LINE__
230
-                    );
231
-                    return false;
232
-            }
233
-        }
234
-        return true;
235
-    }
139
+		$answer_cache_id   = $this->checkout_reg_url_link
140
+			? $form_input . '-' . $reg_url_link
141
+			: $form_input;
142
+		$registrant_answer = $this->registrant_data->getRegistrantAnswer($reg_url_link, $answer_cache_id);
143
+		$answer_is_obj     = $registrant_answer instanceof EE_Answer;
144
+		// rename form_inputs if they are EE_Attendee properties
145
+		switch ((string) $form_input) {
146
+			case 'state':
147
+			case 'STA_ID':
148
+				$attendee_property = true;
149
+				$form_input        = 'STA_ID';
150
+				break;
151
+
152
+			case 'country':
153
+			case 'CNT_ISO':
154
+				$attendee_property = true;
155
+				$form_input        = 'CNT_ISO';
156
+				break;
157
+
158
+			default:
159
+				$ATT_input         = 'ATT_' . $form_input;
160
+				$attendee_property = $this->attendee_model->has_field($ATT_input);
161
+				$form_input        = $attendee_property
162
+					? 'ATT_' . $form_input
163
+					: $form_input;
164
+		}
165
+
166
+		// if this form input has a corresponding attendee property
167
+		if ($attendee_property) {
168
+			$this->registrant_data->addRegistrantDataValue($reg_url_link, $form_input, $input_value);
169
+			if ($answer_is_obj) {
170
+				// and delete the corresponding answer since we won't be storing this data in that object
171
+				$registration->_remove_relation_to($registrant_answer, 'Answer');
172
+				$registrant_answer->delete_permanently();
173
+			}
174
+			return true;
175
+		}
176
+		if ($answer_is_obj) {
177
+			// save this data to the answer object
178
+			$registrant_answer->set_value($input_value);
179
+			$result = $registrant_answer->save();
180
+			return $result !== false;
181
+		}
182
+		foreach ($this->registrant_data->registrantAnswers($reg_url_link) as $answer) {
183
+			if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
184
+				$answer->set_value($input_value);
185
+				$result = $answer->save();
186
+				return $result !== false;
187
+			}
188
+		}
189
+		return false;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param int|string       $form_input
195
+	 * @param float|int|string $input_value
196
+	 * @return boolean
197
+	 */
198
+	private function verifyCriticalAttendeeDetailsAreSetAndValidateEmail(
199
+		$form_input = '',
200
+		$input_value = ''
201
+	): bool {
202
+		if (empty($input_value)) {
203
+			// if the form input isn't marked as being required, then just return
204
+			if (! isset($this->required_questions[ $form_input ]) || ! $this->required_questions[ $form_input ]) {
205
+				return true;
206
+			}
207
+			switch ($form_input) {
208
+				case 'fname':
209
+					EE_Error::add_error(
210
+						esc_html__('First Name is a required value.', 'event_espresso'),
211
+						__FILE__,
212
+						__FUNCTION__,
213
+						__LINE__
214
+					);
215
+					return false;
216
+				case 'lname':
217
+					EE_Error::add_error(
218
+						esc_html__('Last Name is a required value.', 'event_espresso'),
219
+						__FILE__,
220
+						__FUNCTION__,
221
+						__LINE__
222
+					);
223
+					return false;
224
+				case 'email':
225
+					EE_Error::add_error(
226
+						esc_html__('Please enter a valid email address.', 'event_espresso'),
227
+						__FILE__,
228
+						__FUNCTION__,
229
+						__LINE__
230
+					);
231
+					return false;
232
+			}
233
+		}
234
+		return true;
235
+	}
236 236
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $input_value
68 68
     ): bool {
69 69
         // check for critical inputs
70
-        if (! $this->verifyCriticalAttendeeDetailsAreSetAndValidateEmail($form_input, $input_value)) {
70
+        if ( ! $this->verifyCriticalAttendeeDetailsAreSetAndValidateEmail($form_input, $input_value)) {
71 71
             return false;
72 72
         }
73 73
         $input_value = $this->registrant_data->saveOrCopyPrimaryRegistrantData(
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             $form_input,
76 76
             $input_value
77 77
         );
78
-        if (! $this->saveRegistrationFormInput($registration, $reg_url_link, $form_input, $input_value)) {
78
+        if ( ! $this->saveRegistrationFormInput($registration, $reg_url_link, $form_input, $input_value)) {
79 79
             EE_Error::add_error(
80 80
                 sprintf(
81 81
                     esc_html_x(
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
138 138
          */
139 139
         $answer_cache_id   = $this->checkout_reg_url_link
140
-            ? $form_input . '-' . $reg_url_link
140
+            ? $form_input.'-'.$reg_url_link
141 141
             : $form_input;
142 142
         $registrant_answer = $this->registrant_data->getRegistrantAnswer($reg_url_link, $answer_cache_id);
143 143
         $answer_is_obj     = $registrant_answer instanceof EE_Answer;
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
                 break;
157 157
 
158 158
             default:
159
-                $ATT_input         = 'ATT_' . $form_input;
159
+                $ATT_input         = 'ATT_'.$form_input;
160 160
                 $attendee_property = $this->attendee_model->has_field($ATT_input);
161 161
                 $form_input        = $attendee_property
162
-                    ? 'ATT_' . $form_input
162
+                    ? 'ATT_'.$form_input
163 163
                     : $form_input;
164 164
         }
165 165
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     ): bool {
202 202
         if (empty($input_value)) {
203 203
             // if the form input isn't marked as being required, then just return
204
-            if (! isset($this->required_questions[ $form_input ]) || ! $this->required_questions[ $form_input ]) {
204
+            if ( ! isset($this->required_questions[$form_input]) || ! $this->required_questions[$form_input]) {
205 205
                 return true;
206 206
             }
207 207
             switch ($form_input) {
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegFormQuestionGroup.php 2 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -15,163 +15,163 @@
 block discarded – undo
15 15
 
16 16
 class RegFormQuestionGroup extends EE_Form_Section_Proper
17 17
 {
18
-    /**
19
-     * @var RegFormQuestionFactory
20
-     */
21
-    public $reg_form_question_factory;
18
+	/**
19
+	 * @var RegFormQuestionFactory
20
+	 */
21
+	public $reg_form_question_factory;
22 22
 
23 23
 
24
-    /**
25
-     * RegFormQuestionGroup constructor.
26
-     *
27
-     * @param EE_Registration        $registration
28
-     * @param EE_Question_Group      $question_group
29
-     * @param bool                   $admin_request
30
-     * @param RegFormQuestionFactory $reg_form_question_factory
31
-     * @throws EE_Error
32
-     * @throws ReflectionException
33
-     */
34
-    public function __construct(
35
-        EE_Registration $registration,
36
-        EE_Question_Group $question_group,
37
-        bool $admin_request,
38
-        RegFormQuestionFactory $reg_form_question_factory
39
-    ) {
40
-        $this->reg_form_question_factory = $reg_form_question_factory;
41
-        parent::__construct($this->generateFormArgs($registration, $question_group, $admin_request));
42
-    }
24
+	/**
25
+	 * RegFormQuestionGroup constructor.
26
+	 *
27
+	 * @param EE_Registration        $registration
28
+	 * @param EE_Question_Group      $question_group
29
+	 * @param bool                   $admin_request
30
+	 * @param RegFormQuestionFactory $reg_form_question_factory
31
+	 * @throws EE_Error
32
+	 * @throws ReflectionException
33
+	 */
34
+	public function __construct(
35
+		EE_Registration $registration,
36
+		EE_Question_Group $question_group,
37
+		bool $admin_request,
38
+		RegFormQuestionFactory $reg_form_question_factory
39
+	) {
40
+		$this->reg_form_question_factory = $reg_form_question_factory;
41
+		parent::__construct($this->generateFormArgs($registration, $question_group, $admin_request));
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * @param EE_Registration   $registration
47
-     * @param EE_Question_Group $question_group
48
-     * @param bool              $admin_request
49
-     * @return array
50
-     * @throws EE_Error
51
-     * @throws ReflectionException
52
-     */
53
-    private function generateFormArgs(
54
-        EE_Registration $registration,
55
-        EE_Question_Group $question_group,
56
-        bool $admin_request
57
-    ): array {
58
-        // array of params to pass to parent constructor
59
-        $form_args = [
60
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
61
-            'html_class'      => $admin_request
62
-                ? 'form-table ee-reg-form-qstn-grp-dv'
63
-                : 'ee-reg-form-qstn-grp-dv',
64
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
65
-                                 . $registration->ID() . '-lbl',
66
-            'subsections'     => [
67
-                'reg_form_qstn_grp_hdr' => $this->questionGroupHeader($question_group, $admin_request),
68
-            ],
69
-            'layout_strategy' => $admin_request
70
-                ? new EE_Admin_Two_Column_Layout()
71
-                : new EE_Div_Per_Section_Layout(),
72
-        ];
73
-        // where params
74
-        $query_params = ['QST_deleted' => 0];
75
-        // don't load admin only questions on the frontend
76
-        if (! $admin_request) {
77
-            $query_params['QST_admin_only'] = ['!=', true];
78
-        }
79
-        $questions = $question_group->get_many_related(
80
-            'Question',
81
-            apply_filters(
82
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
83
-                [
84
-                    $query_params,
85
-                    'order_by' => [
86
-                        'Question_Group_Question.QGQ_order' => 'ASC',
87
-                    ],
88
-                ],
89
-                $question_group,
90
-                $registration,
91
-                $this
92
-            )
93
-        );
94
-        // filter for additional content before questions
95
-        $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
96
-            apply_filters(
97
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
98
-                '',
99
-                $registration,
100
-                $question_group,
101
-                $this
102
-            )
103
-        );
104
-        // loop thru questions
105
-        foreach ($questions as $question) {
106
-            if ($question instanceof EE_Question) {
107
-                $identifier = $question->is_system_question()
108
-                    ? $question->system_ID()
109
-                    : $question->ID();
45
+	/**
46
+	 * @param EE_Registration   $registration
47
+	 * @param EE_Question_Group $question_group
48
+	 * @param bool              $admin_request
49
+	 * @return array
50
+	 * @throws EE_Error
51
+	 * @throws ReflectionException
52
+	 */
53
+	private function generateFormArgs(
54
+		EE_Registration $registration,
55
+		EE_Question_Group $question_group,
56
+		bool $admin_request
57
+	): array {
58
+		// array of params to pass to parent constructor
59
+		$form_args = [
60
+			'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
61
+			'html_class'      => $admin_request
62
+				? 'form-table ee-reg-form-qstn-grp-dv'
63
+				: 'ee-reg-form-qstn-grp-dv',
64
+			'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
65
+								 . $registration->ID() . '-lbl',
66
+			'subsections'     => [
67
+				'reg_form_qstn_grp_hdr' => $this->questionGroupHeader($question_group, $admin_request),
68
+			],
69
+			'layout_strategy' => $admin_request
70
+				? new EE_Admin_Two_Column_Layout()
71
+				: new EE_Div_Per_Section_Layout(),
72
+		];
73
+		// where params
74
+		$query_params = ['QST_deleted' => 0];
75
+		// don't load admin only questions on the frontend
76
+		if (! $admin_request) {
77
+			$query_params['QST_admin_only'] = ['!=', true];
78
+		}
79
+		$questions = $question_group->get_many_related(
80
+			'Question',
81
+			apply_filters(
82
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
83
+				[
84
+					$query_params,
85
+					'order_by' => [
86
+						'Question_Group_Question.QGQ_order' => 'ASC',
87
+					],
88
+				],
89
+				$question_group,
90
+				$registration,
91
+				$this
92
+			)
93
+		);
94
+		// filter for additional content before questions
95
+		$form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
96
+			apply_filters(
97
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
98
+				'',
99
+				$registration,
100
+				$question_group,
101
+				$this
102
+			)
103
+		);
104
+		// loop thru questions
105
+		foreach ($questions as $question) {
106
+			if ($question instanceof EE_Question) {
107
+				$identifier = $question->is_system_question()
108
+					? $question->system_ID()
109
+					: $question->ID();
110 110
 
111
-                $form_args['subsections'][ $identifier ] = $this->reg_form_question_factory->create(
112
-                    $registration,
113
-                    $question
114
-                );
115
-            }
116
-        }
117
-        $form_args['subsections'] = apply_filters(
118
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
119
-            $form_args['subsections'],
120
-            $registration,
121
-            $question_group,
122
-            $this
123
-        );
124
-        // filter for additional content after questions
125
-        $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
126
-            apply_filters(
127
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
128
-                '',
129
-                $registration,
130
-                $question_group,
131
-                $this
132
-            )
133
-        );
111
+				$form_args['subsections'][ $identifier ] = $this->reg_form_question_factory->create(
112
+					$registration,
113
+					$question
114
+				);
115
+			}
116
+		}
117
+		$form_args['subsections'] = apply_filters(
118
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
119
+			$form_args['subsections'],
120
+			$registration,
121
+			$question_group,
122
+			$this
123
+		);
124
+		// filter for additional content after questions
125
+		$form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
126
+			apply_filters(
127
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
128
+				'',
129
+				$registration,
130
+				$question_group,
131
+				$this
132
+			)
133
+		);
134 134
 
135
-        return $form_args;
136
-    }
135
+		return $form_args;
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * @param EE_Question_Group $question_group
141
-     * @param bool              $admin_request
142
-     * @return EE_Form_Section_HTML
143
-     */
144
-    private function questionGroupHeader(EE_Question_Group $question_group, bool $admin_request): EE_Form_Section_HTML
145
-    {
146
-        $html = '';
147
-        // group_name
148
-        if ($question_group->show_group_name() && $question_group->name() !== '') {
149
-            if ($admin_request) {
150
-                $html .= EEH_HTML::br();
151
-                $html .= EEH_HTML::h3(
152
-                    $question_group->name(),
153
-                    '',
154
-                    'ee-reg-form-qstn-grp-title title',
155
-                    'font-size: 1.3em; padding-left:0;'
156
-                );
157
-            } else {
158
-                $html .= EEH_HTML::h4(
159
-                    $question_group->name(),
160
-                    '',
161
-                    'ee-reg-form-qstn-grp-title section-title'
162
-                );
163
-            }
164
-        }
165
-        // group_desc
166
-        if ($question_group->show_group_desc() && $question_group->desc() !== '') {
167
-            $html .= EEH_HTML::p(
168
-                $question_group->desc(),
169
-                '',
170
-                $admin_request
171
-                    ? 'ee-reg-form-qstn-grp-desc-pg'
172
-                    : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
173
-            );
174
-        }
175
-        return new EE_Form_Section_HTML($html);
176
-    }
139
+	/**
140
+	 * @param EE_Question_Group $question_group
141
+	 * @param bool              $admin_request
142
+	 * @return EE_Form_Section_HTML
143
+	 */
144
+	private function questionGroupHeader(EE_Question_Group $question_group, bool $admin_request): EE_Form_Section_HTML
145
+	{
146
+		$html = '';
147
+		// group_name
148
+		if ($question_group->show_group_name() && $question_group->name() !== '') {
149
+			if ($admin_request) {
150
+				$html .= EEH_HTML::br();
151
+				$html .= EEH_HTML::h3(
152
+					$question_group->name(),
153
+					'',
154
+					'ee-reg-form-qstn-grp-title title',
155
+					'font-size: 1.3em; padding-left:0;'
156
+				);
157
+			} else {
158
+				$html .= EEH_HTML::h4(
159
+					$question_group->name(),
160
+					'',
161
+					'ee-reg-form-qstn-grp-title section-title'
162
+				);
163
+			}
164
+		}
165
+		// group_desc
166
+		if ($question_group->show_group_desc() && $question_group->desc() !== '') {
167
+			$html .= EEH_HTML::p(
168
+				$question_group->desc(),
169
+				'',
170
+				$admin_request
171
+					? 'ee-reg-form-qstn-grp-desc-pg'
172
+					: 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
173
+			);
174
+		}
175
+		return new EE_Form_Section_HTML($html);
176
+	}
177 177
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
     ): array {
58 58
         // array of params to pass to parent constructor
59 59
         $form_args = [
60
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
60
+            'html_id'         => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID(),
61 61
             'html_class'      => $admin_request
62 62
                 ? 'form-table ee-reg-form-qstn-grp-dv'
63 63
                 : 'ee-reg-form-qstn-grp-dv',
64
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
65
-                                 . $registration->ID() . '-lbl',
64
+            'html_label_id'   => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'
65
+                                 . $registration->ID().'-lbl',
66 66
             'subsections'     => [
67 67
                 'reg_form_qstn_grp_hdr' => $this->questionGroupHeader($question_group, $admin_request),
68 68
             ],
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         // where params
74 74
         $query_params = ['QST_deleted' => 0];
75 75
         // don't load admin only questions on the frontend
76
-        if (! $admin_request) {
76
+        if ( ! $admin_request) {
77 77
             $query_params['QST_admin_only'] = ['!=', true];
78 78
         }
79 79
         $questions = $question_group->get_many_related(
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
                     ? $question->system_ID()
109 109
                     : $question->ID();
110 110
 
111
-                $form_args['subsections'][ $identifier ] = $this->reg_form_question_factory->create(
111
+                $form_args['subsections'][$identifier] = $this->reg_form_question_factory->create(
112 112
                     $registration,
113 113
                     $question
114 114
                 );
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegFormHandler.php 2 patches
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -18,310 +18,310 @@
 block discarded – undo
18 18
 class RegFormHandler
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Checkout
23
-     */
24
-    public $checkout;
25
-
26
-    /**
27
-     * @var RegFormInputHandler
28
-     */
29
-    public $input_handler;
30
-
31
-    /**
32
-     * @var array
33
-     */
34
-    private $non_input_form_sections;
35
-
36
-    /**
37
-     * @var RegFormAttendeeFactory
38
-     */
39
-    private $attendee_factory;
40
-
41
-    /**
42
-     * @var RegistrantData
43
-     */
44
-    private $registrant_data;
45
-
46
-    /**
47
-     * @var EE_Registration_Processor
48
-     */
49
-    private $registration_processor;
50
-
51
-    /**
52
-     * @var bool
53
-     */
54
-    private $valid;
55
-
56
-
57
-    /**
58
-     * RegFormHandler constructor.
59
-     */
60
-    public function __construct(
61
-        EE_Checkout $checkout,
62
-        RegistrantData $registrant_data,
63
-        RegFormAttendeeFactory $attendee_factory,
64
-        EE_Registration_Processor $registration_processor
65
-    ) {
66
-        $this->checkout                = $checkout;
67
-        $this->registrant_data         = $registrant_data;
68
-        $this->attendee_factory        = $attendee_factory;
69
-        $this->registration_processor  = $registration_processor;
70
-        // reg form sections that do not contain inputs
71
-        $this->non_input_form_sections = [
72
-            'primary_registrant_data',
73
-            'additional_attendee_reg_info',
74
-            'spco_copy_attendee_chk',
75
-        ];
76
-        $this->initializeInputHandler();
77
-    }
78
-
79
-
80
-    private function initializeInputHandler()
81
-    {
82
-        $reg_form = $this->checkout->current_step->reg_form;
83
-        $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : [];
84
-        $this->input_handler = LoaderFactory::getShared(
85
-            RegFormInputHandler::class,
86
-            [ $this->checkout->reg_url_link, $required_questions ]
87
-        );
88
-
89
-    }
90
-
91
-
92
-    /**
93
-     * @return int
94
-     */
95
-    public function attendeeCount(): int
96
-    {
97
-        return $this->registrant_data->attendeeCount();
98
-    }
99
-
100
-
101
-    /**
102
-     * @return bool
103
-     */
104
-    private function isInvalid(): bool
105
-    {
106
-        $this->valid = false;
107
-        return $this->valid;
108
-    }
109
-
110
-
111
-    /**
112
-     * @param EE_Registration[] $registrations
113
-     * @param array[][]         $reg_form_data
114
-     * @return bool
115
-     * @throws EntityNotFoundException
116
-     * @throws EE_Error
117
-     * @throws InvalidArgumentException
118
-     * @throws ReflectionException
119
-     * @throws RuntimeException
120
-     * @throws InvalidDataTypeException
121
-     * @throws InvalidInterfaceException
122
-     */
123
-    public function processRegistrations(array $registrations, array $reg_form_data): bool
124
-    {
125
-        // start off optimistic, then trip this to false if anything goes wrong
126
-        $this->valid = true;
127
-        foreach ($registrations as $registration) {
128
-            // verify EE_Registration object
129
-            if (! $this->isValidRegistration($registration)) {
130
-                return $this->isInvalid();
131
-            }
132
-            $reg_url_link = $registration->reg_url_link();
133
-            // reg_url_link exists ?
134
-            if (! $this->isValidRegUrlLink($reg_url_link)) {
135
-                return $this->isInvalid();
136
-            }
137
-            // should this registration be processed during this visit ?
138
-            if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) {
139
-                continue;
140
-            }
141
-            // if NOT revisiting, then let's save the registration now,
142
-            // so that we have a REG_ID to use when generating other objects
143
-            if (! $this->checkout->revisit) {
144
-                $registration->save();
145
-            }
146
-            /**
147
-             * This allows plugins to trigger a fail on processing of a
148
-             * registration for any conditions they may have for it to pass.
149
-             *
150
-             * @var bool if true is returned by the plugin then the registration processing is halted.
151
-             */
152
-            if (
153
-                apply_filters(
154
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
155
-                    false,
156
-                    $this->registrant_data->attendeeCount(),
157
-                    $registration,
158
-                    $registrations,
159
-                    $reg_form_data,
160
-                    $this
161
-                )
162
-            ) {
163
-                return $this->isInvalid();
164
-            }
165
-
166
-            // Houston, we have a registration!
167
-            if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) {
168
-                return $this->isInvalid();
169
-            }
170
-        }
171
-        return $this->valid;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param string $reg_url_link
177
-     * @return bool
178
-     */
179
-    private function isValidRegUrlLink(string $reg_url_link): bool
180
-    {
181
-        if (! empty($reg_url_link)) {
182
-            return true;
183
-        }
184
-        EE_Error::add_error(
185
-            esc_html__(
186
-                'An invalid or missing line item ID was encountered while attempting to process the registration form.',
187
-                'event_espresso'
188
-            ),
189
-            __FILE__,
190
-            __FUNCTION__,
191
-            __LINE__
192
-        );
193
-        return false;
194
-    }
195
-
196
-
197
-    /**
198
-     * @param EE_Registration $registration
199
-     * @return bool
200
-     */
201
-    private function isValidRegistration(EE_Registration $registration): bool
202
-    {
203
-        // verify EE_Registration object
204
-        if ($registration instanceof EE_Registration) {
205
-            return true;
206
-        }
207
-        EE_Error::add_error(
208
-            esc_html__(
209
-                'An invalid Registration object was discovered when attempting to process your registration information.',
210
-                'event_espresso'
211
-            ),
212
-            __FILE__,
213
-            __FUNCTION__,
214
-            __LINE__
215
-        );
216
-        return false;
217
-    }
218
-
219
-
220
-    /**
221
-     * @param EE_Registration $registration
222
-     * @param string          $reg_url_link
223
-     * @param array[][]       $reg_form_data
224
-     * @return bool
225
-     * @throws EE_Error
226
-     * @throws ReflectionException
227
-     */
228
-    private function processRegistration(
229
-        EE_Registration $registration,
230
-        string $reg_url_link,
231
-        array $reg_form_data
232
-    ): bool {
233
-        $this->registrant_data->initializeRegistrantData($registration);
234
-        if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) {
235
-            return false;
236
-        }
237
-        // RegFormAttendeeFactory
238
-        if (! $this->attendee_factory->create($registration, $reg_url_link)) {
239
-            return false;
240
-        }
241
-        // at this point, we should have enough details about the registrant to consider the registration
242
-        // NOT incomplete
243
-        $this->registration_processor->toggle_incomplete_registration_status_to_default(
244
-            $registration,
245
-            false,
246
-            new Context(
247
-                'spco_reg_step_attendee_information_process_registrations',
248
-                esc_html__(
249
-                    'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
250
-                    'event_espresso'
251
-                )
252
-            )
253
-        );
254
-        // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
255
-        // abandoned
256
-        $this->checkout->transaction->toggle_failed_transaction_status();
257
-        // if we've gotten this far, then let's save what we have
258
-        $registration->save();
259
-        // add relation between TXN and registration
260
-        $this->associateRegistrationWithTransaction($registration);
261
-        return true;
262
-    }
263
-
264
-
265
-    /**
266
-     * @param EE_Registration $registration
267
-     * @param string          $reg_url_link
268
-     * @param array           $reg_form_data
269
-     * @return bool
270
-     * @throws EE_Error
271
-     * @throws ReflectionException
272
-     */
273
-    private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool
274
-    {
275
-        if (isset($reg_form_data[ $reg_url_link ])) {
276
-            // do we need to copy basic info from primary attendee ?
277
-            $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info'])
278
-                                  && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
279
-            $this->registrant_data->setCopyPrimary($copy_primary);
280
-            // filter form input data for this registration
281
-            $reg_form_data[ $reg_url_link ] = (array) apply_filters(
282
-                'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
283
-                $reg_form_data[ $reg_url_link ]
284
-            );
285
-            if (isset($reg_form_data['primary_attendee'])) {
286
-                $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? '';
287
-                $this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link);
288
-                unset($reg_form_data['primary_attendee']);
289
-            }
290
-            // now loop through our array of valid post data && process attendee reg forms
291
-            foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) {
292
-                if (in_array($form_section, $this->non_input_form_sections, true)) {
293
-                    continue;
294
-                }
295
-                foreach ($form_inputs as $form_input => $input_value) {
296
-                    $input_processed = $this->input_handler->processFormInput(
297
-                        $registration,
298
-                        $reg_url_link,
299
-                        $form_input,
300
-                        $input_value
301
-                    );
302
-                    if (! $input_processed) {
303
-                        return false;
304
-                    }
305
-                }
306
-            }
307
-        }
308
-        return true;
309
-    }
310
-
311
-
312
-    /**
313
-     * @param EE_Registration $registration
314
-     * @return void
315
-     * @throws EE_Error
316
-     * @throws InvalidArgumentException
317
-     * @throws ReflectionException
318
-     * @throws InvalidDataTypeException
319
-     * @throws InvalidInterfaceException
320
-     */
321
-    private function associateRegistrationWithTransaction(EE_Registration $registration)
322
-    {
323
-        // add relation to registration
324
-        $this->checkout->transaction->_add_relation_to($registration, 'Registration');
325
-        $this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
326
-    }
21
+	/**
22
+	 * @var EE_Checkout
23
+	 */
24
+	public $checkout;
25
+
26
+	/**
27
+	 * @var RegFormInputHandler
28
+	 */
29
+	public $input_handler;
30
+
31
+	/**
32
+	 * @var array
33
+	 */
34
+	private $non_input_form_sections;
35
+
36
+	/**
37
+	 * @var RegFormAttendeeFactory
38
+	 */
39
+	private $attendee_factory;
40
+
41
+	/**
42
+	 * @var RegistrantData
43
+	 */
44
+	private $registrant_data;
45
+
46
+	/**
47
+	 * @var EE_Registration_Processor
48
+	 */
49
+	private $registration_processor;
50
+
51
+	/**
52
+	 * @var bool
53
+	 */
54
+	private $valid;
55
+
56
+
57
+	/**
58
+	 * RegFormHandler constructor.
59
+	 */
60
+	public function __construct(
61
+		EE_Checkout $checkout,
62
+		RegistrantData $registrant_data,
63
+		RegFormAttendeeFactory $attendee_factory,
64
+		EE_Registration_Processor $registration_processor
65
+	) {
66
+		$this->checkout                = $checkout;
67
+		$this->registrant_data         = $registrant_data;
68
+		$this->attendee_factory        = $attendee_factory;
69
+		$this->registration_processor  = $registration_processor;
70
+		// reg form sections that do not contain inputs
71
+		$this->non_input_form_sections = [
72
+			'primary_registrant_data',
73
+			'additional_attendee_reg_info',
74
+			'spco_copy_attendee_chk',
75
+		];
76
+		$this->initializeInputHandler();
77
+	}
78
+
79
+
80
+	private function initializeInputHandler()
81
+	{
82
+		$reg_form = $this->checkout->current_step->reg_form;
83
+		$required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : [];
84
+		$this->input_handler = LoaderFactory::getShared(
85
+			RegFormInputHandler::class,
86
+			[ $this->checkout->reg_url_link, $required_questions ]
87
+		);
88
+
89
+	}
90
+
91
+
92
+	/**
93
+	 * @return int
94
+	 */
95
+	public function attendeeCount(): int
96
+	{
97
+		return $this->registrant_data->attendeeCount();
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return bool
103
+	 */
104
+	private function isInvalid(): bool
105
+	{
106
+		$this->valid = false;
107
+		return $this->valid;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @param EE_Registration[] $registrations
113
+	 * @param array[][]         $reg_form_data
114
+	 * @return bool
115
+	 * @throws EntityNotFoundException
116
+	 * @throws EE_Error
117
+	 * @throws InvalidArgumentException
118
+	 * @throws ReflectionException
119
+	 * @throws RuntimeException
120
+	 * @throws InvalidDataTypeException
121
+	 * @throws InvalidInterfaceException
122
+	 */
123
+	public function processRegistrations(array $registrations, array $reg_form_data): bool
124
+	{
125
+		// start off optimistic, then trip this to false if anything goes wrong
126
+		$this->valid = true;
127
+		foreach ($registrations as $registration) {
128
+			// verify EE_Registration object
129
+			if (! $this->isValidRegistration($registration)) {
130
+				return $this->isInvalid();
131
+			}
132
+			$reg_url_link = $registration->reg_url_link();
133
+			// reg_url_link exists ?
134
+			if (! $this->isValidRegUrlLink($reg_url_link)) {
135
+				return $this->isInvalid();
136
+			}
137
+			// should this registration be processed during this visit ?
138
+			if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) {
139
+				continue;
140
+			}
141
+			// if NOT revisiting, then let's save the registration now,
142
+			// so that we have a REG_ID to use when generating other objects
143
+			if (! $this->checkout->revisit) {
144
+				$registration->save();
145
+			}
146
+			/**
147
+			 * This allows plugins to trigger a fail on processing of a
148
+			 * registration for any conditions they may have for it to pass.
149
+			 *
150
+			 * @var bool if true is returned by the plugin then the registration processing is halted.
151
+			 */
152
+			if (
153
+				apply_filters(
154
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
155
+					false,
156
+					$this->registrant_data->attendeeCount(),
157
+					$registration,
158
+					$registrations,
159
+					$reg_form_data,
160
+					$this
161
+				)
162
+			) {
163
+				return $this->isInvalid();
164
+			}
165
+
166
+			// Houston, we have a registration!
167
+			if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) {
168
+				return $this->isInvalid();
169
+			}
170
+		}
171
+		return $this->valid;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param string $reg_url_link
177
+	 * @return bool
178
+	 */
179
+	private function isValidRegUrlLink(string $reg_url_link): bool
180
+	{
181
+		if (! empty($reg_url_link)) {
182
+			return true;
183
+		}
184
+		EE_Error::add_error(
185
+			esc_html__(
186
+				'An invalid or missing line item ID was encountered while attempting to process the registration form.',
187
+				'event_espresso'
188
+			),
189
+			__FILE__,
190
+			__FUNCTION__,
191
+			__LINE__
192
+		);
193
+		return false;
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param EE_Registration $registration
199
+	 * @return bool
200
+	 */
201
+	private function isValidRegistration(EE_Registration $registration): bool
202
+	{
203
+		// verify EE_Registration object
204
+		if ($registration instanceof EE_Registration) {
205
+			return true;
206
+		}
207
+		EE_Error::add_error(
208
+			esc_html__(
209
+				'An invalid Registration object was discovered when attempting to process your registration information.',
210
+				'event_espresso'
211
+			),
212
+			__FILE__,
213
+			__FUNCTION__,
214
+			__LINE__
215
+		);
216
+		return false;
217
+	}
218
+
219
+
220
+	/**
221
+	 * @param EE_Registration $registration
222
+	 * @param string          $reg_url_link
223
+	 * @param array[][]       $reg_form_data
224
+	 * @return bool
225
+	 * @throws EE_Error
226
+	 * @throws ReflectionException
227
+	 */
228
+	private function processRegistration(
229
+		EE_Registration $registration,
230
+		string $reg_url_link,
231
+		array $reg_form_data
232
+	): bool {
233
+		$this->registrant_data->initializeRegistrantData($registration);
234
+		if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) {
235
+			return false;
236
+		}
237
+		// RegFormAttendeeFactory
238
+		if (! $this->attendee_factory->create($registration, $reg_url_link)) {
239
+			return false;
240
+		}
241
+		// at this point, we should have enough details about the registrant to consider the registration
242
+		// NOT incomplete
243
+		$this->registration_processor->toggle_incomplete_registration_status_to_default(
244
+			$registration,
245
+			false,
246
+			new Context(
247
+				'spco_reg_step_attendee_information_process_registrations',
248
+				esc_html__(
249
+					'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
250
+					'event_espresso'
251
+				)
252
+			)
253
+		);
254
+		// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
255
+		// abandoned
256
+		$this->checkout->transaction->toggle_failed_transaction_status();
257
+		// if we've gotten this far, then let's save what we have
258
+		$registration->save();
259
+		// add relation between TXN and registration
260
+		$this->associateRegistrationWithTransaction($registration);
261
+		return true;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param EE_Registration $registration
267
+	 * @param string          $reg_url_link
268
+	 * @param array           $reg_form_data
269
+	 * @return bool
270
+	 * @throws EE_Error
271
+	 * @throws ReflectionException
272
+	 */
273
+	private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool
274
+	{
275
+		if (isset($reg_form_data[ $reg_url_link ])) {
276
+			// do we need to copy basic info from primary attendee ?
277
+			$copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info'])
278
+								  && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
279
+			$this->registrant_data->setCopyPrimary($copy_primary);
280
+			// filter form input data for this registration
281
+			$reg_form_data[ $reg_url_link ] = (array) apply_filters(
282
+				'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
283
+				$reg_form_data[ $reg_url_link ]
284
+			);
285
+			if (isset($reg_form_data['primary_attendee'])) {
286
+				$primary_reg_url_link = $reg_form_data['primary_attendee'] ?? '';
287
+				$this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link);
288
+				unset($reg_form_data['primary_attendee']);
289
+			}
290
+			// now loop through our array of valid post data && process attendee reg forms
291
+			foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) {
292
+				if (in_array($form_section, $this->non_input_form_sections, true)) {
293
+					continue;
294
+				}
295
+				foreach ($form_inputs as $form_input => $input_value) {
296
+					$input_processed = $this->input_handler->processFormInput(
297
+						$registration,
298
+						$reg_url_link,
299
+						$form_input,
300
+						$input_value
301
+					);
302
+					if (! $input_processed) {
303
+						return false;
304
+					}
305
+				}
306
+			}
307
+		}
308
+		return true;
309
+	}
310
+
311
+
312
+	/**
313
+	 * @param EE_Registration $registration
314
+	 * @return void
315
+	 * @throws EE_Error
316
+	 * @throws InvalidArgumentException
317
+	 * @throws ReflectionException
318
+	 * @throws InvalidDataTypeException
319
+	 * @throws InvalidInterfaceException
320
+	 */
321
+	private function associateRegistrationWithTransaction(EE_Registration $registration)
322
+	{
323
+		// add relation to registration
324
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
325
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
326
+	}
327 327
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : [];
84 84
         $this->input_handler = LoaderFactory::getShared(
85 85
             RegFormInputHandler::class,
86
-            [ $this->checkout->reg_url_link, $required_questions ]
86
+            [$this->checkout->reg_url_link, $required_questions]
87 87
         );
88 88
 
89 89
     }
@@ -126,21 +126,21 @@  discard block
 block discarded – undo
126 126
         $this->valid = true;
127 127
         foreach ($registrations as $registration) {
128 128
             // verify EE_Registration object
129
-            if (! $this->isValidRegistration($registration)) {
129
+            if ( ! $this->isValidRegistration($registration)) {
130 130
                 return $this->isInvalid();
131 131
             }
132 132
             $reg_url_link = $registration->reg_url_link();
133 133
             // reg_url_link exists ?
134
-            if (! $this->isValidRegUrlLink($reg_url_link)) {
134
+            if ( ! $this->isValidRegUrlLink($reg_url_link)) {
135 135
                 return $this->isInvalid();
136 136
             }
137 137
             // should this registration be processed during this visit ?
138
-            if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) {
138
+            if ( ! $this->checkout->visit_allows_processing_of_this_registration($registration)) {
139 139
                 continue;
140 140
             }
141 141
             // if NOT revisiting, then let's save the registration now,
142 142
             // so that we have a REG_ID to use when generating other objects
143
-            if (! $this->checkout->revisit) {
143
+            if ( ! $this->checkout->revisit) {
144 144
                 $registration->save();
145 145
             }
146 146
             /**
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
             }
165 165
 
166 166
             // Houston, we have a registration!
167
-            if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) {
167
+            if ( ! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) {
168 168
                 return $this->isInvalid();
169 169
             }
170 170
         }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     private function isValidRegUrlLink(string $reg_url_link): bool
180 180
     {
181
-        if (! empty($reg_url_link)) {
181
+        if ( ! empty($reg_url_link)) {
182 182
             return true;
183 183
         }
184 184
         EE_Error::add_error(
@@ -231,11 +231,11 @@  discard block
 block discarded – undo
231 231
         array $reg_form_data
232 232
     ): bool {
233 233
         $this->registrant_data->initializeRegistrantData($registration);
234
-        if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) {
234
+        if ( ! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) {
235 235
             return false;
236 236
         }
237 237
         // RegFormAttendeeFactory
238
-        if (! $this->attendee_factory->create($registration, $reg_url_link)) {
238
+        if ( ! $this->attendee_factory->create($registration, $reg_url_link)) {
239 239
             return false;
240 240
         }
241 241
         // at this point, we should have enough details about the registrant to consider the registration
@@ -272,15 +272,15 @@  discard block
 block discarded – undo
272 272
      */
273 273
     private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool
274 274
     {
275
-        if (isset($reg_form_data[ $reg_url_link ])) {
275
+        if (isset($reg_form_data[$reg_url_link])) {
276 276
             // do we need to copy basic info from primary attendee ?
277
-            $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info'])
278
-                                  && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
277
+            $copy_primary = isset($reg_form_data[$reg_url_link]['additional_attendee_reg_info'])
278
+                                  && absint($reg_form_data[$reg_url_link]['additional_attendee_reg_info']) === 0;
279 279
             $this->registrant_data->setCopyPrimary($copy_primary);
280 280
             // filter form input data for this registration
281
-            $reg_form_data[ $reg_url_link ] = (array) apply_filters(
281
+            $reg_form_data[$reg_url_link] = (array) apply_filters(
282 282
                 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
283
-                $reg_form_data[ $reg_url_link ]
283
+                $reg_form_data[$reg_url_link]
284 284
             );
285 285
             if (isset($reg_form_data['primary_attendee'])) {
286 286
                 $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? '';
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 unset($reg_form_data['primary_attendee']);
289 289
             }
290 290
             // now loop through our array of valid post data && process attendee reg forms
291
-            foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) {
291
+            foreach ($reg_form_data[$reg_url_link] as $form_section => $form_inputs) {
292 292
                 if (in_array($form_section, $this->non_input_form_sections, true)) {
293 293
                     continue;
294 294
                 }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
                         $form_input,
300 300
                         $input_value
301 301
                     );
302
-                    if (! $input_processed) {
302
+                    if ( ! $input_processed) {
303 303
                         return false;
304 304
                     }
305 305
                 }
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/PrivacyConsentCheckboxForm.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@
 block discarded – undo
9 9
 
10 10
 class PrivacyConsentCheckboxForm extends EE_Form_Section_Proper
11 11
 {
12
-    /**
13
-     * @param string $reg_step_slug
14
-     * @param string $consent_checkbox_label_text
15
-     * @throws EE_Error
16
-     */
17
-    public function __construct(string $reg_step_slug, string $consent_checkbox_label_text)
18
-    {
19
-        parent::__construct(
20
-            [
21
-                'layout_strategy' =>
22
-                    new EE_Template_Layout(
23
-                        [
24
-                            'input_template_file' => SPCO_REG_STEPS_PATH
25
-                                                     . $reg_step_slug
26
-                                                     . '/privacy_consent.template.php',
27
-                        ]
28
-                    ),
29
-                'subsections'     => [
30
-                    'consent' => new EE_Checkbox_Multi_Input(
31
-                        [
32
-                            'consent' => $consent_checkbox_label_text,
33
-                        ],
34
-                        [
35
-                            'required'                          => true,
36
-                            'required_validation_error_message' => esc_html__(
37
-                                'You must consent to these terms in order to register.',
38
-                                'event_espresso'
39
-                            ),
40
-                            'html_label_text'                   => '',
41
-                        ]
42
-                    ),
43
-                ],
44
-            ]
45
-        );
46
-    }
12
+	/**
13
+	 * @param string $reg_step_slug
14
+	 * @param string $consent_checkbox_label_text
15
+	 * @throws EE_Error
16
+	 */
17
+	public function __construct(string $reg_step_slug, string $consent_checkbox_label_text)
18
+	{
19
+		parent::__construct(
20
+			[
21
+				'layout_strategy' =>
22
+					new EE_Template_Layout(
23
+						[
24
+							'input_template_file' => SPCO_REG_STEPS_PATH
25
+													 . $reg_step_slug
26
+													 . '/privacy_consent.template.php',
27
+						]
28
+					),
29
+				'subsections'     => [
30
+					'consent' => new EE_Checkbox_Multi_Input(
31
+						[
32
+							'consent' => $consent_checkbox_label_text,
33
+						],
34
+						[
35
+							'required'                          => true,
36
+							'required_validation_error_message' => esc_html__(
37
+								'You must consent to these terms in order to register.',
38
+								'event_espresso'
39
+							),
40
+							'html_label_text'                   => '',
41
+						]
42
+					),
43
+				],
44
+			]
45
+		);
46
+	}
47 47
 }
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegistrantData.php 2 patches
Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -19,354 +19,354 @@
 block discarded – undo
19 19
 class RegistrantData
20 20
 {
21 21
 
22
-    /**
23
-     * @var int
24
-     */
25
-    private $attendee_counter = 0;
26
-
27
-    /**
28
-     * @var array
29
-     */
30
-    private $registrant_data = [];
31
-
32
-    /**
33
-     * @var bool
34
-     */
35
-    private $copy_primary = false;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private $required_questions = [];
41
-
42
-    /**
43
-     * @var EE_Registration[]
44
-     */
45
-    private $registrations = [];
46
-
47
-    /**
48
-     * @var EE_Answer[][]
49
-     */
50
-    private $registrant_answers = [];
51
-
52
-    /**
53
-     * array for tracking reg form data for the primary registrant
54
-     *
55
-     * @var array
56
-     */
57
-    private $primary_registrant_data;
58
-
59
-    /**
60
-     * the attendee object created for the primary registrant
61
-     *
62
-     * @var EE_Attendee
63
-     */
64
-    private $primary_registrant;
65
-
66
-
67
-    /**
68
-     * RegistrantData constructor.
69
-     */
70
-    public function __construct()
71
-    {
72
-        $this->primary_registrant_data = ['line_item_id' => null,];
73
-    }
74
-
75
-
76
-    /**
77
-     * @param EE_Registration $registration
78
-     * @throws EE_Error
79
-     */
80
-    public function initializeRegistrantData(EE_Registration $registration): void
81
-    {
82
-        $reg_url_link = $registration->reg_url_link();
83
-        $this->registrations[ $reg_url_link ] = $registration;
84
-        $this->registrant_answers[ $reg_url_link ] = $registration->answers();
85
-        $this->registrant_data[ $reg_url_link ] = [];
86
-        $this->attendee_counter++;
87
-    }
88
-
89
-
90
-    /**
91
-     * @return int
92
-     */
93
-    public function attendeeCount(): int
94
-    {
95
-        return $this->attendee_counter;
96
-    }
97
-
98
-
99
-    /**
100
-     * @return bool
101
-     */
102
-    public function copyPrimary(): bool
103
-    {
104
-        return $this->copy_primary;
105
-    }
106
-
107
-
108
-    /**
109
-     * @param bool $copy_primary
110
-     */
111
-    public function setCopyPrimary(bool $copy_primary): void
112
-    {
113
-        $this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN);
114
-    }
115
-
116
-
117
-    /**
118
-     * @param string $reg_url_link
119
-     * @return array|null
120
-     */
121
-    public function getRegistrant(string $reg_url_link): ?EE_Registration
122
-    {
123
-        return $this->registrations[ $reg_url_link ] ?? null;
124
-    }
125
-
126
-
127
-    /**
128
-     * @param string $reg_url_link
129
-     * @return array|null
130
-     */
131
-    public function getRegistrantData(string $reg_url_link): ?array
132
-    {
133
-        return $this->registrant_data[ $reg_url_link ] ?? null;
134
-    }
135
-
136
-
137
-    /**
138
-     * @param string $reg_url_link
139
-     * @param string $key
140
-     * @param mixed $value
141
-     */
142
-    public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void
143
-    {
144
-        $this->registrant_data[ $reg_url_link ][ $key ] = $value;
145
-    }
146
-
147
-
148
-    /**
149
-     * ensures that all attendees at least have data for first name, last name, and email address
150
-     *
151
-     * @param string $reg_url_link
152
-     * @throws EE_Error
153
-     * @throws ReflectionException
154
-     */
155
-    public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void {
156
-        if ($this->currentRegistrantIsPrimary()) {
157
-            return;
158
-        }
159
-        // bare minimum critical details include first name, last name, email address
160
-        $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email'];
161
-        // add address info to critical details?
162
-        if (
163
-        apply_filters(
164
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
165
-            false
166
-        )
167
-        ) {
168
-            $critical_attendee_details += [
169
-                'ATT_address',
170
-                'ATT_address2',
171
-                'ATT_city',
172
-                'STA_ID',
173
-                'CNT_ISO',
174
-                'ATT_zip',
175
-                'ATT_phone',
176
-            ];
177
-        }
178
-        foreach ($critical_attendee_details as $critical_attendee_detail) {
179
-            if (
180
-                ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
181
-                || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
182
-            ) {
183
-                $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get(
184
-                    $critical_attendee_detail
185
-                );
186
-            }
187
-        }
188
-    }
189
-
190
-
191
-    /**
192
-     * @param string $reg_url_link
193
-     * @param array $registrant_data
194
-     */
195
-    public function setRegistrantData(string $reg_url_link, array $registrant_data): void
196
-    {
197
-        $this->registrant_data[ $reg_url_link ] = $registrant_data;
198
-    }
199
-
200
-
201
-    /**
202
-     * @return array
203
-     */
204
-    public function getRequiredQuestions(): array
205
-    {
206
-        return $this->required_questions;
207
-    }
208
-
209
-
210
-    /**
211
-     * @param string $identifier
212
-     * @param string $required_question
213
-     */
214
-    public function addRequiredQuestion(string $identifier, string $required_question): void
215
-    {
216
-        $this->required_questions[ $identifier ] = $required_question;
217
-    }
218
-
219
-
220
-    /**
221
-     * @return EE_Answer[]
222
-     */
223
-    public function registrantAnswers(string $reg_url_link): array
224
-    {
225
-        return $this->registrant_answers[ $reg_url_link ] ?? [];
226
-    }
227
-
228
-
229
-    /**
230
-     * @param string $reg_url_link
231
-     * @param string $identifier  the answer cache ID
232
-     * @param EE_Answer $answer
233
-     */
234
-    public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void
235
-    {
236
-        $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer;
237
-    }
238
-
239
-
240
-    /**
241
-     * @param string $reg_url_link
242
-     * @param string $identifier
243
-     * @return EE_Answer|null
244
-     */
245
-    public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer
246
-    {
247
-        return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param string $reg_url_link
254
-     * @param string $identifier
255
-     * @return bool
256
-     */
257
-    public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool
258
-    {
259
-        $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier);
260
-        return $registrant_answer instanceof EE_Answer;
261
-    }
262
-
263
-
264
-    /**
265
-     * @return array
266
-     */
267
-    public function primaryRegistrantData(): array
268
-    {
269
-        return $this->primary_registrant_data;
270
-    }
271
-
272
-
273
-    /**
274
-     * @param string $key
275
-     * @param mixed  $value
276
-     */
277
-    public function addPrimaryRegistrantDataValue(string $key, $value): void
278
-    {
279
-        $this->primary_registrant_data[ $key ] = $value;
280
-    }
281
-
282
-
283
-    /**
284
-     * @param string $key
285
-     * @return mixed
286
-     */
287
-    public function getPrimaryRegistrantDataValue(string $key)
288
-    {
289
-        return $this->primary_registrant_data[ $key ] ?? null;
290
-    }
291
-
292
-
293
-    /**
294
-     * @param array $primary_registrant_data
295
-     */
296
-    public function setPrimaryRegistrantData(array $primary_registrant_data): void
297
-    {
298
-        $this->primary_registrant_data = $primary_registrant_data;
299
-    }
300
-
301
-
302
-    /**
303
-     * @return EE_Attendee
304
-     */
305
-    public function primaryRegistrant(): EE_Attendee
306
-    {
307
-        return $this->primary_registrant;
308
-    }
309
-
310
-
311
-    /**
312
-     * @return bool
313
-     */
314
-    public function primaryRegistrantIsValid(): bool
315
-    {
316
-        return $this->primary_registrant instanceof EE_Attendee;
317
-    }
318
-
319
-
320
-    /**
321
-     * @param EE_Attendee $primary_registrant
322
-     */
323
-    public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void
324
-    {
325
-        $this->primary_registrant = $primary_registrant;
326
-    }
327
-
328
-
329
-    /**
330
-     * @param string $reg_url_link
331
-     * @return bool
332
-     */
333
-    public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool
334
-    {
335
-        return $this->attendeeCount() === 1
336
-            || (
337
-                $this->attendeeCount() === 1
338
-                && $reg_url_link !== ''
339
-                && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link
340
-           );
341
-    }
342
-
343
-
344
-    /**
345
-     * @return bool
346
-     */
347
-    public function currentRegistrantIsNotPrimary(): bool
348
-    {
349
-        return $this->attendeeCount() > 1;
350
-    }
351
-
352
-
353
-    /**
354
-     * @param string $reg_url_link
355
-     * @param string $form_input
356
-     * @param mixed  $input_value
357
-     * @return mixed|null
358
-     */
359
-    public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value)
360
-    {
361
-        // store a bit of data about the primary attendee
362
-        if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) {
363
-            $this->primary_registrant_data[ $form_input ] = $input_value;
364
-            return $input_value;
365
-        }
366
-        // or copy value from primary if incoming value is not set
367
-        if ($input_value === null && $this->copyPrimary()) {
368
-            $input_value = $this->getPrimaryRegistrantDataValue($form_input);
369
-        }
370
-        return $input_value;
371
-    }
22
+	/**
23
+	 * @var int
24
+	 */
25
+	private $attendee_counter = 0;
26
+
27
+	/**
28
+	 * @var array
29
+	 */
30
+	private $registrant_data = [];
31
+
32
+	/**
33
+	 * @var bool
34
+	 */
35
+	private $copy_primary = false;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private $required_questions = [];
41
+
42
+	/**
43
+	 * @var EE_Registration[]
44
+	 */
45
+	private $registrations = [];
46
+
47
+	/**
48
+	 * @var EE_Answer[][]
49
+	 */
50
+	private $registrant_answers = [];
51
+
52
+	/**
53
+	 * array for tracking reg form data for the primary registrant
54
+	 *
55
+	 * @var array
56
+	 */
57
+	private $primary_registrant_data;
58
+
59
+	/**
60
+	 * the attendee object created for the primary registrant
61
+	 *
62
+	 * @var EE_Attendee
63
+	 */
64
+	private $primary_registrant;
65
+
66
+
67
+	/**
68
+	 * RegistrantData constructor.
69
+	 */
70
+	public function __construct()
71
+	{
72
+		$this->primary_registrant_data = ['line_item_id' => null,];
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param EE_Registration $registration
78
+	 * @throws EE_Error
79
+	 */
80
+	public function initializeRegistrantData(EE_Registration $registration): void
81
+	{
82
+		$reg_url_link = $registration->reg_url_link();
83
+		$this->registrations[ $reg_url_link ] = $registration;
84
+		$this->registrant_answers[ $reg_url_link ] = $registration->answers();
85
+		$this->registrant_data[ $reg_url_link ] = [];
86
+		$this->attendee_counter++;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @return int
92
+	 */
93
+	public function attendeeCount(): int
94
+	{
95
+		return $this->attendee_counter;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return bool
101
+	 */
102
+	public function copyPrimary(): bool
103
+	{
104
+		return $this->copy_primary;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param bool $copy_primary
110
+	 */
111
+	public function setCopyPrimary(bool $copy_primary): void
112
+	{
113
+		$this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN);
114
+	}
115
+
116
+
117
+	/**
118
+	 * @param string $reg_url_link
119
+	 * @return array|null
120
+	 */
121
+	public function getRegistrant(string $reg_url_link): ?EE_Registration
122
+	{
123
+		return $this->registrations[ $reg_url_link ] ?? null;
124
+	}
125
+
126
+
127
+	/**
128
+	 * @param string $reg_url_link
129
+	 * @return array|null
130
+	 */
131
+	public function getRegistrantData(string $reg_url_link): ?array
132
+	{
133
+		return $this->registrant_data[ $reg_url_link ] ?? null;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @param string $reg_url_link
139
+	 * @param string $key
140
+	 * @param mixed $value
141
+	 */
142
+	public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void
143
+	{
144
+		$this->registrant_data[ $reg_url_link ][ $key ] = $value;
145
+	}
146
+
147
+
148
+	/**
149
+	 * ensures that all attendees at least have data for first name, last name, and email address
150
+	 *
151
+	 * @param string $reg_url_link
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void {
156
+		if ($this->currentRegistrantIsPrimary()) {
157
+			return;
158
+		}
159
+		// bare minimum critical details include first name, last name, email address
160
+		$critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email'];
161
+		// add address info to critical details?
162
+		if (
163
+		apply_filters(
164
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
165
+			false
166
+		)
167
+		) {
168
+			$critical_attendee_details += [
169
+				'ATT_address',
170
+				'ATT_address2',
171
+				'ATT_city',
172
+				'STA_ID',
173
+				'CNT_ISO',
174
+				'ATT_zip',
175
+				'ATT_phone',
176
+			];
177
+		}
178
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
179
+			if (
180
+				! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
181
+				|| empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
182
+			) {
183
+				$this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get(
184
+					$critical_attendee_detail
185
+				);
186
+			}
187
+		}
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param string $reg_url_link
193
+	 * @param array $registrant_data
194
+	 */
195
+	public function setRegistrantData(string $reg_url_link, array $registrant_data): void
196
+	{
197
+		$this->registrant_data[ $reg_url_link ] = $registrant_data;
198
+	}
199
+
200
+
201
+	/**
202
+	 * @return array
203
+	 */
204
+	public function getRequiredQuestions(): array
205
+	{
206
+		return $this->required_questions;
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param string $identifier
212
+	 * @param string $required_question
213
+	 */
214
+	public function addRequiredQuestion(string $identifier, string $required_question): void
215
+	{
216
+		$this->required_questions[ $identifier ] = $required_question;
217
+	}
218
+
219
+
220
+	/**
221
+	 * @return EE_Answer[]
222
+	 */
223
+	public function registrantAnswers(string $reg_url_link): array
224
+	{
225
+		return $this->registrant_answers[ $reg_url_link ] ?? [];
226
+	}
227
+
228
+
229
+	/**
230
+	 * @param string $reg_url_link
231
+	 * @param string $identifier  the answer cache ID
232
+	 * @param EE_Answer $answer
233
+	 */
234
+	public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void
235
+	{
236
+		$this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param string $reg_url_link
242
+	 * @param string $identifier
243
+	 * @return EE_Answer|null
244
+	 */
245
+	public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer
246
+	{
247
+		return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param string $reg_url_link
254
+	 * @param string $identifier
255
+	 * @return bool
256
+	 */
257
+	public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool
258
+	{
259
+		$registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier);
260
+		return $registrant_answer instanceof EE_Answer;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @return array
266
+	 */
267
+	public function primaryRegistrantData(): array
268
+	{
269
+		return $this->primary_registrant_data;
270
+	}
271
+
272
+
273
+	/**
274
+	 * @param string $key
275
+	 * @param mixed  $value
276
+	 */
277
+	public function addPrimaryRegistrantDataValue(string $key, $value): void
278
+	{
279
+		$this->primary_registrant_data[ $key ] = $value;
280
+	}
281
+
282
+
283
+	/**
284
+	 * @param string $key
285
+	 * @return mixed
286
+	 */
287
+	public function getPrimaryRegistrantDataValue(string $key)
288
+	{
289
+		return $this->primary_registrant_data[ $key ] ?? null;
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param array $primary_registrant_data
295
+	 */
296
+	public function setPrimaryRegistrantData(array $primary_registrant_data): void
297
+	{
298
+		$this->primary_registrant_data = $primary_registrant_data;
299
+	}
300
+
301
+
302
+	/**
303
+	 * @return EE_Attendee
304
+	 */
305
+	public function primaryRegistrant(): EE_Attendee
306
+	{
307
+		return $this->primary_registrant;
308
+	}
309
+
310
+
311
+	/**
312
+	 * @return bool
313
+	 */
314
+	public function primaryRegistrantIsValid(): bool
315
+	{
316
+		return $this->primary_registrant instanceof EE_Attendee;
317
+	}
318
+
319
+
320
+	/**
321
+	 * @param EE_Attendee $primary_registrant
322
+	 */
323
+	public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void
324
+	{
325
+		$this->primary_registrant = $primary_registrant;
326
+	}
327
+
328
+
329
+	/**
330
+	 * @param string $reg_url_link
331
+	 * @return bool
332
+	 */
333
+	public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool
334
+	{
335
+		return $this->attendeeCount() === 1
336
+			|| (
337
+				$this->attendeeCount() === 1
338
+				&& $reg_url_link !== ''
339
+				&& $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link
340
+		   );
341
+	}
342
+
343
+
344
+	/**
345
+	 * @return bool
346
+	 */
347
+	public function currentRegistrantIsNotPrimary(): bool
348
+	{
349
+		return $this->attendeeCount() > 1;
350
+	}
351
+
352
+
353
+	/**
354
+	 * @param string $reg_url_link
355
+	 * @param string $form_input
356
+	 * @param mixed  $input_value
357
+	 * @return mixed|null
358
+	 */
359
+	public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value)
360
+	{
361
+		// store a bit of data about the primary attendee
362
+		if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) {
363
+			$this->primary_registrant_data[ $form_input ] = $input_value;
364
+			return $input_value;
365
+		}
366
+		// or copy value from primary if incoming value is not set
367
+		if ($input_value === null && $this->copyPrimary()) {
368
+			$input_value = $this->getPrimaryRegistrantDataValue($form_input);
369
+		}
370
+		return $input_value;
371
+	}
372 372
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function __construct()
71 71
     {
72
-        $this->primary_registrant_data = ['line_item_id' => null,];
72
+        $this->primary_registrant_data = ['line_item_id' => null, ];
73 73
     }
74 74
 
75 75
 
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
     public function initializeRegistrantData(EE_Registration $registration): void
81 81
     {
82 82
         $reg_url_link = $registration->reg_url_link();
83
-        $this->registrations[ $reg_url_link ] = $registration;
84
-        $this->registrant_answers[ $reg_url_link ] = $registration->answers();
85
-        $this->registrant_data[ $reg_url_link ] = [];
83
+        $this->registrations[$reg_url_link] = $registration;
84
+        $this->registrant_answers[$reg_url_link] = $registration->answers();
85
+        $this->registrant_data[$reg_url_link] = [];
86 86
         $this->attendee_counter++;
87 87
     }
88 88
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function getRegistrant(string $reg_url_link): ?EE_Registration
122 122
     {
123
-        return $this->registrations[ $reg_url_link ] ?? null;
123
+        return $this->registrations[$reg_url_link] ?? null;
124 124
     }
125 125
 
126 126
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function getRegistrantData(string $reg_url_link): ?array
132 132
     {
133
-        return $this->registrant_data[ $reg_url_link ] ?? null;
133
+        return $this->registrant_data[$reg_url_link] ?? null;
134 134
     }
135 135
 
136 136
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void
143 143
     {
144
-        $this->registrant_data[ $reg_url_link ][ $key ] = $value;
144
+        $this->registrant_data[$reg_url_link][$key] = $value;
145 145
     }
146 146
 
147 147
 
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
         }
178 178
         foreach ($critical_attendee_details as $critical_attendee_detail) {
179 179
             if (
180
-                ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
181
-                || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
180
+                ! isset($this->registrant_data[$reg_url_link][$critical_attendee_detail])
181
+                || empty($this->registrant_data[$reg_url_link][$critical_attendee_detail])
182 182
             ) {
183
-                $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get(
183
+                $this->registrant_data[$reg_url_link][$critical_attendee_detail] = $this->primary_registrant->get(
184 184
                     $critical_attendee_detail
185 185
                 );
186 186
             }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     public function setRegistrantData(string $reg_url_link, array $registrant_data): void
196 196
     {
197
-        $this->registrant_data[ $reg_url_link ] = $registrant_data;
197
+        $this->registrant_data[$reg_url_link] = $registrant_data;
198 198
     }
199 199
 
200 200
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
      */
214 214
     public function addRequiredQuestion(string $identifier, string $required_question): void
215 215
     {
216
-        $this->required_questions[ $identifier ] = $required_question;
216
+        $this->required_questions[$identifier] = $required_question;
217 217
     }
218 218
 
219 219
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
      */
223 223
     public function registrantAnswers(string $reg_url_link): array
224 224
     {
225
-        return $this->registrant_answers[ $reg_url_link ] ?? [];
225
+        return $this->registrant_answers[$reg_url_link] ?? [];
226 226
     }
227 227
 
228 228
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void
235 235
     {
236
-        $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer;
236
+        $this->registrant_answers[$reg_url_link][$identifier] = $answer;
237 237
     }
238 238
 
239 239
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer
246 246
     {
247
-        return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null;
247
+        return $this->registrant_answers[$reg_url_link][$identifier] ?? null;
248 248
     }
249 249
 
250 250
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
      */
277 277
     public function addPrimaryRegistrantDataValue(string $key, $value): void
278 278
     {
279
-        $this->primary_registrant_data[ $key ] = $value;
279
+        $this->primary_registrant_data[$key] = $value;
280 280
     }
281 281
 
282 282
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      */
287 287
     public function getPrimaryRegistrantDataValue(string $key)
288 288
     {
289
-        return $this->primary_registrant_data[ $key ] ?? null;
289
+        return $this->primary_registrant_data[$key] ?? null;
290 290
     }
291 291
 
292 292
 
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
     public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value)
360 360
     {
361 361
         // store a bit of data about the primary attendee
362
-        if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) {
363
-            $this->primary_registrant_data[ $form_input ] = $input_value;
362
+        if ( ! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) {
363
+            $this->primary_registrant_data[$form_input] = $input_value;
364 364
             return $input_value;
365 365
         }
366 366
         // or copy value from primary if incoming value is not set
Please login to merge, or discard this patch.
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 2 patches
Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -22,472 +22,472 @@
 block discarded – undo
22 22
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step
23 23
 {
24 24
 
25
-    /**
26
-     * @var RegForm
27
-     */
28
-    public $reg_form;
29
-
30
-    /**
31
-     * @var int
32
-     */
33
-    protected $reg_form_count = 0;
34
-
35
-
36
-    /**
37
-     *    class constructor
38
-     *
39
-     * @access    public
40
-     * @param EE_Checkout $checkout
41
-     */
42
-    public function __construct(EE_Checkout $checkout)
43
-    {
44
-        $this->_slug    = 'attendee_information';
45
-        $this->_name    = esc_html__('Attendee Information', 'event_espresso');
46
-        $this->checkout = $checkout;
47
-        $this->_reset_success_message();
48
-        $this->set_instructions(
49
-            esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
50
-        );
51
-    }
52
-
53
-
54
-    public function translate_js_strings()
55
-    {
56
-        EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
57
-            ' is a required question.',
58
-            'event_espresso'
59
-        );
60
-        EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
61
-            ' is a required question. Please enter a value for at least one of the options.',
62
-            'event_espresso'
63
-        );
64
-        EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
65
-            'Please answer all required questions correctly before proceeding.',
66
-            'event_espresso'
67
-        );
68
-        EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
69
-            esc_html_x(
70
-                'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
71
-                'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
72
-                'event_espresso'
73
-            ),
74
-            '<br/>'
75
-        );
76
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
77
-            'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
78
-            'event_espresso'
79
-        );
80
-        EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
81
-            'You must enter a valid email address.',
82
-            'event_espresso'
83
-        );
84
-        EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
85
-            'You must enter a valid email address and answer all other required questions before you can proceed.',
86
-            'event_espresso'
87
-        );
88
-    }
89
-
90
-
91
-    public function enqueue_styles_and_scripts()
92
-    {
93
-    }
94
-
95
-
96
-    /**
97
-     * @return boolean
98
-     */
99
-    public function initialize_reg_step(): bool
100
-    {
101
-        return true;
102
-    }
103
-
104
-
105
-    /**
106
-     * @return RegForm
107
-     * @throws DomainException
108
-     * @throws InvalidArgumentException
109
-     * @throws EntityNotFoundException
110
-     * @throws InvalidDataTypeException
111
-     * @throws InvalidInterfaceException
112
-     */
113
-    public function generate_reg_form(): RegForm
114
-    {
115
-        /** @var RegFormDependencyHandler $dependency_handler */
116
-        $dependency_handler = LoaderFactory::getShared(RegFormDependencyHandler::class);
117
-        $dependency_handler->registerDependencies();
118
-        // TODO detect if event has a reg form UUID and swap this out for form generated by new reg form builder
119
-        return LoaderFactory::getShared(RegForm::class, [$this]);
120
-    }
121
-
122
-
123
-    /**
124
-     * looking for hooks?
125
-     * this method has been replaced by:
126
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::getRegForm()
127
-     *
128
-     * @deprecated   $VID:$
129
-     */
130
-    private function _registrations_reg_form()
131
-    {
132
-    }
133
-
134
-
135
-    /**
136
-     * looking for hooks?
137
-     * this method has been replaced by:
138
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalAttendeeRegInfoInput()
139
-     *
140
-     * @deprecated   $VID:$
141
-     */
142
-    private function _additional_attendee_reg_info_input()
143
-    {
144
-    }
145
-
146
-
147
-    /**
148
-     * looking for hooks?
149
-     * this method has been replaced by:
150
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupRegForm()
151
-     *
152
-     * @deprecated   $VID:$
153
-     */
154
-    private function _question_group_reg_form()
155
-    {
156
-    }
157
-
158
-
159
-    /**
160
-     * looking for hooks?
161
-     * this method has been replaced by:
162
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupHeader()
163
-     *
164
-     * @deprecated   $VID:$
165
-     */
166
-    private function _question_group_header()
167
-    {
168
-    }
169
-
170
-
171
-    /**
172
-     * looking for hooks?
173
-     * this method has been replaced by:
174
-     * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm
175
-     *
176
-     * @deprecated   $VID:$
177
-     */
178
-    private function _copy_attendee_info_form()
179
-    {
180
-    }
181
-
182
-
183
-    /**
184
-     * looking for hooks?
185
-     * this method has been replaced by:
186
-     * EventEspresso\core\domain\services\registration\form\v1\AutoCopyAttendeeInfoForm
187
-     *
188
-     * @deprecated   $VID:$
189
-     */
190
-    private function _auto_copy_attendee_info()
191
-    {
192
-    }
193
-
194
-
195
-    /**
196
-     * looking for hooks?
197
-     * this method has been replaced by:
198
-     * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm
199
-     *
200
-     * @deprecated   $VID:$
201
-     */
202
-    private function _copy_attendee_info_inputs()
203
-    {
204
-    }
205
-
206
-
207
-    /**
208
-     * looking for hooks?
209
-     * this method has been replaced by:
210
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalPrimaryRegistrantInputs()
211
-     *
212
-     * @deprecated   $VID:$
213
-     */
214
-    private function _additional_primary_registrant_inputs()
215
-    {
216
-    }
217
-
218
-
219
-    /**
220
-     * looking for hooks?
221
-     * this method has been replaced by:
222
-     * EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory::create()
223
-     *
224
-     * @param EE_Registration $registration
225
-     * @param EE_Question     $question
226
-     * @return EE_Form_Input_Base
227
-     * @throws EE_Error
228
-     * @throws ReflectionException
229
-     * @deprecated   $VID:$
230
-     */
231
-    public function reg_form_question(EE_Registration $registration, EE_Question $question): EE_Form_Input_Base
232
-    {
233
-        /** @var RegFormQuestionFactory $reg_form_question_factory */
234
-        $reg_form_question_factory = LoaderFactory::getShared(RegFormQuestionFactory::class);
235
-        return $reg_form_question_factory->create($registration, $question);
236
-    }
237
-
238
-
239
-    /**
240
-     * looking for hooks?
241
-     * this method has been replaced by:
242
-     * EventEspresso\core\domain\services\registration\form\v1\RegForm::generateQuestionInput()
243
-     *
244
-     * @deprecated   $VID:$
245
-     */
246
-    private function _generate_question_input()
247
-    {
248
-    }
249
-
250
-
251
-    /**
252
-     * looking for hooks?
253
-     * this method has been replaced by:
254
-     * EventEspresso\core\domain\services\registration\form\v1\CountryOptions::forLegacyFormInput()
255
-     *
256
-     * @param array|null           $countries_list
257
-     * @param EE_Question|null     $question
258
-     * @param EE_Registration|null $registration
259
-     * @param EE_Answer|null       $answer
260
-     * @return array 2d keys are country IDs, values are their names
261
-     * @throws EE_Error
262
-     * @throws ReflectionException
263
-     * @deprecated   $VID:$
264
-     */
265
-    public function use_cached_countries_for_form_input(
266
-        array $countries_list = null,
267
-        EE_Question $question = null,
268
-        EE_Registration $registration = null,
269
-        EE_Answer $answer = null
270
-    ): array {
271
-        /** @var CountryOptions $country_options */
272
-        $country_options = LoaderFactory::getShared(CountryOptions::class, [$this->checkout->action]);
273
-        return $country_options->forLegacyFormInput($countries_list, $question, $registration, $answer);
274
-    }
275
-
276
-
277
-    /**
278
-     * looking for hooks?
279
-     * this method has been replaced by:
280
-     * EventEspresso\core\domain\services\registration\form\v1\StateOptions::forLegacyFormInput()
281
-     *
282
-     * @param array|null           $states_list
283
-     * @param EE_Question|null     $question
284
-     * @param EE_Registration|null $registration
285
-     * @param EE_Answer|null       $answer
286
-     * @return array 2d keys are state IDs, values are their names
287
-     * @throws EE_Error
288
-     * @throws ReflectionException
289
-     * @deprecated   $VID:$
290
-     */
291
-    public function use_cached_states_for_form_input(
292
-        array $states_list = null,
293
-        EE_Question $question = null,
294
-        EE_Registration $registration = null,
295
-        EE_Answer $answer = null
296
-    ): array {
297
-        /** @var StateOptions $state_options */
298
-        $state_options = LoaderFactory::getShared(StateOptions::class, [$this->checkout->action]);
299
-        return $state_options->forLegacyFormInput($states_list, $question, $registration, $answer);
300
-    }
301
-
302
-
303
-    /********************************************************************************************************/
304
-    /****************************************  PROCESS REG STEP  ****************************************/
305
-    /********************************************************************************************************/
306
-
307
-
308
-    /**
309
-     * @return bool
310
-     * @throws EE_Error
311
-     * @throws InvalidArgumentException
312
-     * @throws ReflectionException
313
-     * @throws RuntimeException
314
-     * @throws InvalidDataTypeException
315
-     * @throws InvalidInterfaceException
316
-     */
317
-    public function process_reg_step(): bool
318
-    {
319
-        // grab validated data from form
320
-        $valid_data = $this->checkout->current_step->valid_data();
321
-        // if we don't have any $valid_data then something went TERRIBLY WRONG !!!
322
-        if (empty($valid_data)) {
323
-            return $this->inValidDataError();
324
-        }
325
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
326
-            return $this->inValidTransactionError();
327
-        }
328
-        // get cached registrations
329
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
330
-        // verify we got the goods
331
-        if (empty($registrations)) {
332
-            return $this->noRegistrationsError();
333
-        }
334
-        /** @var RegFormHandler $reg_form_handler */
335
-        $reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]);
336
-        // extract attendee info from form data and save to model objects
337
-        if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) {
338
-            // return immediately if the previous step exited early due to errors
339
-            return false;
340
-        }
341
-        // if first pass thru SPCO,
342
-        // then let's check processed registrations against the total number of tickets in the cart
343
-        $registrations_processed = $reg_form_handler->attendeeCount();
344
-        if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
345
-            return $this->registrationProcessingError($registrations_processed);
346
-        }
347
-        // mark this reg step as completed
348
-        $this->set_completed();
349
-        $this->_set_success_message(
350
-            esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
351
-        );
352
-        // do action in case a plugin wants to do something with the data submitted in step 1.
353
-        // passes EE_Single_Page_Checkout, and it's posted data
354
-        do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
355
-        return true;
356
-    }
357
-
358
-
359
-    /**
360
-     * @return bool
361
-     * @since   $VID:$
362
-     */
363
-    private function inValidDataError(): bool
364
-    {
365
-        EE_Error::add_error(
366
-            esc_html__('No valid question responses were received.', 'event_espresso'),
367
-            __FILE__,
368
-            __FUNCTION__,
369
-            __LINE__
370
-        );
371
-        return false;
372
-    }
373
-
374
-
375
-    /**
376
-     * @return bool
377
-     * @since   $VID:$
378
-     */
379
-    private function inValidTransactionError(): bool
380
-    {
381
-        EE_Error::add_error(
382
-            esc_html__(
383
-                'A valid transaction could not be initiated for processing your registrations.',
384
-                'event_espresso'
385
-            ),
386
-            __FILE__,
387
-            __FUNCTION__,
388
-            __LINE__
389
-        );
390
-        return false;
391
-    }
392
-
393
-
394
-    /**
395
-     * @return bool
396
-     * @since   $VID:$
397
-     */
398
-    private function noRegistrationsError(): bool
399
-    {
400
-        // combine the old translated string with a new one, in order to not break translations
401
-        $error_message = esc_html__(
402
-            'Your form data could not be applied to any valid registrations.',
403
-            'event_espresso'
404
-        );
405
-        $error_message .= sprintf(
406
-            esc_html_x(
407
-                '%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.',
408
-                '(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.',
409
-                'event_espresso'
410
-            ),
411
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
412
-            '</a>',
413
-            '<br />'
414
-        );
415
-        EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__);
416
-        return false;
417
-    }
418
-
419
-
420
-    /**
421
-     * @param int $registrations_processed
422
-     * @return bool
423
-     * @since   $VID:$
424
-     */
425
-    private function registrationProcessingError(int $registrations_processed): bool
426
-    {
427
-        // generate a correctly translated string for all possible singular/plural combinations
428
-        if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
429
-            $error_msg = sprintf(
430
-                esc_html_x(
431
-                    'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
432
-                    'There was 1 ticket in the Event Queue, but 2 registrations were processed',
433
-                    'event_espresso'
434
-                ),
435
-                $this->checkout->total_ticket_count,
436
-                $registrations_processed
437
-            );
438
-        } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
439
-            $error_msg = sprintf(
440
-                esc_html_x(
441
-                    'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
442
-                    'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
443
-                    'event_espresso'
444
-                ),
445
-                $this->checkout->total_ticket_count,
446
-                $registrations_processed
447
-            );
448
-        } else {
449
-            $error_msg = sprintf(
450
-                esc_html__(
451
-                    'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
452
-                    'event_espresso'
453
-                ),
454
-                $this->checkout->total_ticket_count,
455
-                $registrations_processed
456
-            );
457
-        }
458
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
459
-        return false;
460
-    }
461
-
462
-
463
-    /**
464
-     *    update_reg_step
465
-     *    this is the final step after a user  revisits the site to edit their attendee information
466
-     *    this gets called AFTER the process_reg_step() method above
467
-     *
468
-     * @return bool
469
-     * @throws EE_Error
470
-     * @throws InvalidArgumentException
471
-     * @throws ReflectionException
472
-     * @throws RuntimeException
473
-     * @throws InvalidDataTypeException
474
-     * @throws InvalidInterfaceException
475
-     */
476
-    public function update_reg_step(): bool
477
-    {
478
-        // save everything
479
-        if ($this->process_reg_step()) {
480
-            $this->checkout->redirect     = true;
481
-            $this->checkout->redirect_url = add_query_arg(
482
-                [
483
-                    'e_reg_url_link' => $this->checkout->reg_url_link,
484
-                    'revisit'        => true,
485
-                ],
486
-                $this->checkout->thank_you_page_url
487
-            );
488
-            $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
489
-            return true;
490
-        }
491
-        return false;
492
-    }
25
+	/**
26
+	 * @var RegForm
27
+	 */
28
+	public $reg_form;
29
+
30
+	/**
31
+	 * @var int
32
+	 */
33
+	protected $reg_form_count = 0;
34
+
35
+
36
+	/**
37
+	 *    class constructor
38
+	 *
39
+	 * @access    public
40
+	 * @param EE_Checkout $checkout
41
+	 */
42
+	public function __construct(EE_Checkout $checkout)
43
+	{
44
+		$this->_slug    = 'attendee_information';
45
+		$this->_name    = esc_html__('Attendee Information', 'event_espresso');
46
+		$this->checkout = $checkout;
47
+		$this->_reset_success_message();
48
+		$this->set_instructions(
49
+			esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
50
+		);
51
+	}
52
+
53
+
54
+	public function translate_js_strings()
55
+	{
56
+		EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
57
+			' is a required question.',
58
+			'event_espresso'
59
+		);
60
+		EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
61
+			' is a required question. Please enter a value for at least one of the options.',
62
+			'event_espresso'
63
+		);
64
+		EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
65
+			'Please answer all required questions correctly before proceeding.',
66
+			'event_espresso'
67
+		);
68
+		EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
69
+			esc_html_x(
70
+				'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
71
+				'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
72
+				'event_espresso'
73
+			),
74
+			'<br/>'
75
+		);
76
+		EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
77
+			'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
78
+			'event_espresso'
79
+		);
80
+		EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
81
+			'You must enter a valid email address.',
82
+			'event_espresso'
83
+		);
84
+		EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
85
+			'You must enter a valid email address and answer all other required questions before you can proceed.',
86
+			'event_espresso'
87
+		);
88
+	}
89
+
90
+
91
+	public function enqueue_styles_and_scripts()
92
+	{
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return boolean
98
+	 */
99
+	public function initialize_reg_step(): bool
100
+	{
101
+		return true;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @return RegForm
107
+	 * @throws DomainException
108
+	 * @throws InvalidArgumentException
109
+	 * @throws EntityNotFoundException
110
+	 * @throws InvalidDataTypeException
111
+	 * @throws InvalidInterfaceException
112
+	 */
113
+	public function generate_reg_form(): RegForm
114
+	{
115
+		/** @var RegFormDependencyHandler $dependency_handler */
116
+		$dependency_handler = LoaderFactory::getShared(RegFormDependencyHandler::class);
117
+		$dependency_handler->registerDependencies();
118
+		// TODO detect if event has a reg form UUID and swap this out for form generated by new reg form builder
119
+		return LoaderFactory::getShared(RegForm::class, [$this]);
120
+	}
121
+
122
+
123
+	/**
124
+	 * looking for hooks?
125
+	 * this method has been replaced by:
126
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::getRegForm()
127
+	 *
128
+	 * @deprecated   $VID:$
129
+	 */
130
+	private function _registrations_reg_form()
131
+	{
132
+	}
133
+
134
+
135
+	/**
136
+	 * looking for hooks?
137
+	 * this method has been replaced by:
138
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalAttendeeRegInfoInput()
139
+	 *
140
+	 * @deprecated   $VID:$
141
+	 */
142
+	private function _additional_attendee_reg_info_input()
143
+	{
144
+	}
145
+
146
+
147
+	/**
148
+	 * looking for hooks?
149
+	 * this method has been replaced by:
150
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupRegForm()
151
+	 *
152
+	 * @deprecated   $VID:$
153
+	 */
154
+	private function _question_group_reg_form()
155
+	{
156
+	}
157
+
158
+
159
+	/**
160
+	 * looking for hooks?
161
+	 * this method has been replaced by:
162
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupHeader()
163
+	 *
164
+	 * @deprecated   $VID:$
165
+	 */
166
+	private function _question_group_header()
167
+	{
168
+	}
169
+
170
+
171
+	/**
172
+	 * looking for hooks?
173
+	 * this method has been replaced by:
174
+	 * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm
175
+	 *
176
+	 * @deprecated   $VID:$
177
+	 */
178
+	private function _copy_attendee_info_form()
179
+	{
180
+	}
181
+
182
+
183
+	/**
184
+	 * looking for hooks?
185
+	 * this method has been replaced by:
186
+	 * EventEspresso\core\domain\services\registration\form\v1\AutoCopyAttendeeInfoForm
187
+	 *
188
+	 * @deprecated   $VID:$
189
+	 */
190
+	private function _auto_copy_attendee_info()
191
+	{
192
+	}
193
+
194
+
195
+	/**
196
+	 * looking for hooks?
197
+	 * this method has been replaced by:
198
+	 * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm
199
+	 *
200
+	 * @deprecated   $VID:$
201
+	 */
202
+	private function _copy_attendee_info_inputs()
203
+	{
204
+	}
205
+
206
+
207
+	/**
208
+	 * looking for hooks?
209
+	 * this method has been replaced by:
210
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalPrimaryRegistrantInputs()
211
+	 *
212
+	 * @deprecated   $VID:$
213
+	 */
214
+	private function _additional_primary_registrant_inputs()
215
+	{
216
+	}
217
+
218
+
219
+	/**
220
+	 * looking for hooks?
221
+	 * this method has been replaced by:
222
+	 * EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory::create()
223
+	 *
224
+	 * @param EE_Registration $registration
225
+	 * @param EE_Question     $question
226
+	 * @return EE_Form_Input_Base
227
+	 * @throws EE_Error
228
+	 * @throws ReflectionException
229
+	 * @deprecated   $VID:$
230
+	 */
231
+	public function reg_form_question(EE_Registration $registration, EE_Question $question): EE_Form_Input_Base
232
+	{
233
+		/** @var RegFormQuestionFactory $reg_form_question_factory */
234
+		$reg_form_question_factory = LoaderFactory::getShared(RegFormQuestionFactory::class);
235
+		return $reg_form_question_factory->create($registration, $question);
236
+	}
237
+
238
+
239
+	/**
240
+	 * looking for hooks?
241
+	 * this method has been replaced by:
242
+	 * EventEspresso\core\domain\services\registration\form\v1\RegForm::generateQuestionInput()
243
+	 *
244
+	 * @deprecated   $VID:$
245
+	 */
246
+	private function _generate_question_input()
247
+	{
248
+	}
249
+
250
+
251
+	/**
252
+	 * looking for hooks?
253
+	 * this method has been replaced by:
254
+	 * EventEspresso\core\domain\services\registration\form\v1\CountryOptions::forLegacyFormInput()
255
+	 *
256
+	 * @param array|null           $countries_list
257
+	 * @param EE_Question|null     $question
258
+	 * @param EE_Registration|null $registration
259
+	 * @param EE_Answer|null       $answer
260
+	 * @return array 2d keys are country IDs, values are their names
261
+	 * @throws EE_Error
262
+	 * @throws ReflectionException
263
+	 * @deprecated   $VID:$
264
+	 */
265
+	public function use_cached_countries_for_form_input(
266
+		array $countries_list = null,
267
+		EE_Question $question = null,
268
+		EE_Registration $registration = null,
269
+		EE_Answer $answer = null
270
+	): array {
271
+		/** @var CountryOptions $country_options */
272
+		$country_options = LoaderFactory::getShared(CountryOptions::class, [$this->checkout->action]);
273
+		return $country_options->forLegacyFormInput($countries_list, $question, $registration, $answer);
274
+	}
275
+
276
+
277
+	/**
278
+	 * looking for hooks?
279
+	 * this method has been replaced by:
280
+	 * EventEspresso\core\domain\services\registration\form\v1\StateOptions::forLegacyFormInput()
281
+	 *
282
+	 * @param array|null           $states_list
283
+	 * @param EE_Question|null     $question
284
+	 * @param EE_Registration|null $registration
285
+	 * @param EE_Answer|null       $answer
286
+	 * @return array 2d keys are state IDs, values are their names
287
+	 * @throws EE_Error
288
+	 * @throws ReflectionException
289
+	 * @deprecated   $VID:$
290
+	 */
291
+	public function use_cached_states_for_form_input(
292
+		array $states_list = null,
293
+		EE_Question $question = null,
294
+		EE_Registration $registration = null,
295
+		EE_Answer $answer = null
296
+	): array {
297
+		/** @var StateOptions $state_options */
298
+		$state_options = LoaderFactory::getShared(StateOptions::class, [$this->checkout->action]);
299
+		return $state_options->forLegacyFormInput($states_list, $question, $registration, $answer);
300
+	}
301
+
302
+
303
+	/********************************************************************************************************/
304
+	/****************************************  PROCESS REG STEP  ****************************************/
305
+	/********************************************************************************************************/
306
+
307
+
308
+	/**
309
+	 * @return bool
310
+	 * @throws EE_Error
311
+	 * @throws InvalidArgumentException
312
+	 * @throws ReflectionException
313
+	 * @throws RuntimeException
314
+	 * @throws InvalidDataTypeException
315
+	 * @throws InvalidInterfaceException
316
+	 */
317
+	public function process_reg_step(): bool
318
+	{
319
+		// grab validated data from form
320
+		$valid_data = $this->checkout->current_step->valid_data();
321
+		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
322
+		if (empty($valid_data)) {
323
+			return $this->inValidDataError();
324
+		}
325
+		if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
326
+			return $this->inValidTransactionError();
327
+		}
328
+		// get cached registrations
329
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
330
+		// verify we got the goods
331
+		if (empty($registrations)) {
332
+			return $this->noRegistrationsError();
333
+		}
334
+		/** @var RegFormHandler $reg_form_handler */
335
+		$reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]);
336
+		// extract attendee info from form data and save to model objects
337
+		if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) {
338
+			// return immediately if the previous step exited early due to errors
339
+			return false;
340
+		}
341
+		// if first pass thru SPCO,
342
+		// then let's check processed registrations against the total number of tickets in the cart
343
+		$registrations_processed = $reg_form_handler->attendeeCount();
344
+		if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
345
+			return $this->registrationProcessingError($registrations_processed);
346
+		}
347
+		// mark this reg step as completed
348
+		$this->set_completed();
349
+		$this->_set_success_message(
350
+			esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
351
+		);
352
+		// do action in case a plugin wants to do something with the data submitted in step 1.
353
+		// passes EE_Single_Page_Checkout, and it's posted data
354
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
355
+		return true;
356
+	}
357
+
358
+
359
+	/**
360
+	 * @return bool
361
+	 * @since   $VID:$
362
+	 */
363
+	private function inValidDataError(): bool
364
+	{
365
+		EE_Error::add_error(
366
+			esc_html__('No valid question responses were received.', 'event_espresso'),
367
+			__FILE__,
368
+			__FUNCTION__,
369
+			__LINE__
370
+		);
371
+		return false;
372
+	}
373
+
374
+
375
+	/**
376
+	 * @return bool
377
+	 * @since   $VID:$
378
+	 */
379
+	private function inValidTransactionError(): bool
380
+	{
381
+		EE_Error::add_error(
382
+			esc_html__(
383
+				'A valid transaction could not be initiated for processing your registrations.',
384
+				'event_espresso'
385
+			),
386
+			__FILE__,
387
+			__FUNCTION__,
388
+			__LINE__
389
+		);
390
+		return false;
391
+	}
392
+
393
+
394
+	/**
395
+	 * @return bool
396
+	 * @since   $VID:$
397
+	 */
398
+	private function noRegistrationsError(): bool
399
+	{
400
+		// combine the old translated string with a new one, in order to not break translations
401
+		$error_message = esc_html__(
402
+			'Your form data could not be applied to any valid registrations.',
403
+			'event_espresso'
404
+		);
405
+		$error_message .= sprintf(
406
+			esc_html_x(
407
+				'%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.',
408
+				'(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.',
409
+				'event_espresso'
410
+			),
411
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" >',
412
+			'</a>',
413
+			'<br />'
414
+		);
415
+		EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__);
416
+		return false;
417
+	}
418
+
419
+
420
+	/**
421
+	 * @param int $registrations_processed
422
+	 * @return bool
423
+	 * @since   $VID:$
424
+	 */
425
+	private function registrationProcessingError(int $registrations_processed): bool
426
+	{
427
+		// generate a correctly translated string for all possible singular/plural combinations
428
+		if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
429
+			$error_msg = sprintf(
430
+				esc_html_x(
431
+					'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
432
+					'There was 1 ticket in the Event Queue, but 2 registrations were processed',
433
+					'event_espresso'
434
+				),
435
+				$this->checkout->total_ticket_count,
436
+				$registrations_processed
437
+			);
438
+		} elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
439
+			$error_msg = sprintf(
440
+				esc_html_x(
441
+					'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
442
+					'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
443
+					'event_espresso'
444
+				),
445
+				$this->checkout->total_ticket_count,
446
+				$registrations_processed
447
+			);
448
+		} else {
449
+			$error_msg = sprintf(
450
+				esc_html__(
451
+					'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
452
+					'event_espresso'
453
+				),
454
+				$this->checkout->total_ticket_count,
455
+				$registrations_processed
456
+			);
457
+		}
458
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
459
+		return false;
460
+	}
461
+
462
+
463
+	/**
464
+	 *    update_reg_step
465
+	 *    this is the final step after a user  revisits the site to edit their attendee information
466
+	 *    this gets called AFTER the process_reg_step() method above
467
+	 *
468
+	 * @return bool
469
+	 * @throws EE_Error
470
+	 * @throws InvalidArgumentException
471
+	 * @throws ReflectionException
472
+	 * @throws RuntimeException
473
+	 * @throws InvalidDataTypeException
474
+	 * @throws InvalidInterfaceException
475
+	 */
476
+	public function update_reg_step(): bool
477
+	{
478
+		// save everything
479
+		if ($this->process_reg_step()) {
480
+			$this->checkout->redirect     = true;
481
+			$this->checkout->redirect_url = add_query_arg(
482
+				[
483
+					'e_reg_url_link' => $this->checkout->reg_url_link,
484
+					'revisit'        => true,
485
+				],
486
+				$this->checkout->thank_you_page_url
487
+			);
488
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
489
+			return true;
490
+		}
491
+		return false;
492
+	}
493 493
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 
54 54
     public function translate_js_strings()
55 55
     {
56
-        EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
56
+        EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
57 57
             ' is a required question.',
58 58
             'event_espresso'
59 59
         );
60
-        EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
60
+        EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
61 61
             ' is a required question. Please enter a value for at least one of the options.',
62 62
             'event_espresso'
63 63
         );
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             'Please answer all required questions correctly before proceeding.',
66 66
             'event_espresso'
67 67
         );
68
-        EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
68
+        EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
69 69
             esc_html_x(
70 70
                 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
71 71
                 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
             ),
74 74
             '<br/>'
75 75
         );
76
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
76
+        EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
77 77
             'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
78 78
             'event_espresso'
79 79
         );
80
-        EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
80
+        EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
81 81
             'You must enter a valid email address.',
82 82
             'event_espresso'
83 83
         );
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         if (empty($valid_data)) {
323 323
             return $this->inValidDataError();
324 324
         }
325
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
325
+        if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
326 326
             return $this->inValidTransactionError();
327 327
         }
328 328
         // get cached registrations
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
         /** @var RegFormHandler $reg_form_handler */
335 335
         $reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]);
336 336
         // extract attendee info from form data and save to model objects
337
-        if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) {
337
+        if ( ! $reg_form_handler->processRegistrations($registrations, $valid_data)) {
338 338
             // return immediately if the previous step exited early due to errors
339 339
             return false;
340 340
         }
341 341
         // if first pass thru SPCO,
342 342
         // then let's check processed registrations against the total number of tickets in the cart
343 343
         $registrations_processed = $reg_form_handler->attendeeCount();
344
-        if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
344
+        if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
345 345
             return $this->registrationProcessingError($registrations_processed);
346 346
         }
347 347
         // mark this reg step as completed
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
                 '(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.',
409 409
                 'event_espresso'
410 410
             ),
411
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
411
+            '<a href="'.get_post_type_archive_link('espresso_events').'" >',
412 412
             '</a>',
413 413
             '<br />'
414 414
         );
Please login to merge, or discard this patch.