Completed
Branch FET/reg-form-builder/main (69a760)
by
unknown
04:39 queued 02:08
created
core/domain/services/registration/form/v1/RegFormAttendeeFactory.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -16,113 +16,113 @@
 block discarded – undo
16 16
 class RegFormAttendeeFactory
17 17
 {
18 18
 
19
-    /**
20
-     * @var CommandBusInterface
21
-     */
22
-    public $command_bus;
19
+	/**
20
+	 * @var CommandBusInterface
21
+	 */
22
+	public $command_bus;
23 23
 
24
-    /**
25
-     * @var RegistrantData
26
-     */
27
-    private $registrant_data;
24
+	/**
25
+	 * @var RegistrantData
26
+	 */
27
+	private $registrant_data;
28 28
 
29 29
 
30
-    /**
31
-     * RegFormAttendeeFactory constructor.
32
-     *
33
-     * @param CommandBusInterface $command_bus
34
-     * @param RegistrantData      $registrant_data
35
-     */
36
-    public function __construct(CommandBusInterface $command_bus, RegistrantData $registrant_data)
37
-    {
38
-        $this->command_bus     = $command_bus;
39
-        $this->registrant_data = $registrant_data;
40
-    }
30
+	/**
31
+	 * RegFormAttendeeFactory constructor.
32
+	 *
33
+	 * @param CommandBusInterface $command_bus
34
+	 * @param RegistrantData      $registrant_data
35
+	 */
36
+	public function __construct(CommandBusInterface $command_bus, RegistrantData $registrant_data)
37
+	{
38
+		$this->command_bus     = $command_bus;
39
+		$this->registrant_data = $registrant_data;
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * @param EE_Registration $registration
45
-     * @param string          $reg_url_link
46
-     * @return bool
47
-     * @throws EE_Error
48
-     * @throws ReflectionException
49
-     */
50
-    public function create(EE_Registration $registration, string $reg_url_link): bool
51
-    {
52
-        // this registration does not require additional attendee information ?
53
-        if (
54
-            $this->registrant_data->copyPrimary()
55
-            && $this->registrant_data->attendeeCount() > 1
56
-            && $this->registrant_data->primaryRegistrantIsValid()
57
-        ) {
58
-            // just copy the primary registrant
59
-            $attendee = $this->registrant_data->primaryRegistrant();
60
-        } else {
61
-            // ensure critical details are set for additional attendees
62
-            // raw form data was already set during call to processRegFormData()
63
-            $this->registrant_data->ensureCriticalRegistrantDataIsSet($reg_url_link);
64
-            // execute create attendee command (which may return an existing attendee)
65
-            $attendee = $this->command_bus->execute(
66
-                new CreateAttendeeCommand(
67
-                    $this->registrant_data->getRegistrantData($reg_url_link),
68
-                    $registration
69
-                )
70
-            );
71
-            // who's #1 ?
72
-            if ($this->registrant_data->currentRegistrantIsPrimary()) {
73
-                $this->registrant_data->setPrimaryRegistrant($attendee);
74
-            }
75
-        }
76
-        // add relation to registration, set attendee ID, and cache attendee
77
-        $this->associateAttendeeWithRegistration($registration, $attendee);
78
-        return $this->isValidAttendee($registration, $reg_url_link);
79
-    }
43
+	/**
44
+	 * @param EE_Registration $registration
45
+	 * @param string          $reg_url_link
46
+	 * @return bool
47
+	 * @throws EE_Error
48
+	 * @throws ReflectionException
49
+	 */
50
+	public function create(EE_Registration $registration, string $reg_url_link): bool
51
+	{
52
+		// this registration does not require additional attendee information ?
53
+		if (
54
+			$this->registrant_data->copyPrimary()
55
+			&& $this->registrant_data->attendeeCount() > 1
56
+			&& $this->registrant_data->primaryRegistrantIsValid()
57
+		) {
58
+			// just copy the primary registrant
59
+			$attendee = $this->registrant_data->primaryRegistrant();
60
+		} else {
61
+			// ensure critical details are set for additional attendees
62
+			// raw form data was already set during call to processRegFormData()
63
+			$this->registrant_data->ensureCriticalRegistrantDataIsSet($reg_url_link);
64
+			// execute create attendee command (which may return an existing attendee)
65
+			$attendee = $this->command_bus->execute(
66
+				new CreateAttendeeCommand(
67
+					$this->registrant_data->getRegistrantData($reg_url_link),
68
+					$registration
69
+				)
70
+			);
71
+			// who's #1 ?
72
+			if ($this->registrant_data->currentRegistrantIsPrimary()) {
73
+				$this->registrant_data->setPrimaryRegistrant($attendee);
74
+			}
75
+		}
76
+		// add relation to registration, set attendee ID, and cache attendee
77
+		$this->associateAttendeeWithRegistration($registration, $attendee);
78
+		return $this->isValidAttendee($registration, $reg_url_link);
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * @param EE_Registration $registration
84
-     * @param string          $reg_url_link
85
-     * @return bool
86
-     * @throws EE_Error
87
-     */
88
-    private function isValidAttendee(EE_Registration $registration, string $reg_url_link): bool
89
-    {
90
-        if ($registration->attendee() instanceof EE_Attendee) {
91
-            return true;
92
-        }
93
-        EE_Error::add_error(
94
-            sprintf(
95
-                esc_html_x(
96
-                    'Registration %s has an invalid or missing Attendee object.',
97
-                    'Registration 123-456-789 has an invalid or missing Attendee object.',
98
-                    'event_espresso'
99
-                ),
100
-                $reg_url_link
101
-            ),
102
-            __FILE__,
103
-            __FUNCTION__,
104
-            __LINE__
105
-        );
106
-        return false;
107
-    }
82
+	/**
83
+	 * @param EE_Registration $registration
84
+	 * @param string          $reg_url_link
85
+	 * @return bool
86
+	 * @throws EE_Error
87
+	 */
88
+	private function isValidAttendee(EE_Registration $registration, string $reg_url_link): bool
89
+	{
90
+		if ($registration->attendee() instanceof EE_Attendee) {
91
+			return true;
92
+		}
93
+		EE_Error::add_error(
94
+			sprintf(
95
+				esc_html_x(
96
+					'Registration %s has an invalid or missing Attendee object.',
97
+					'Registration 123-456-789 has an invalid or missing Attendee object.',
98
+					'event_espresso'
99
+				),
100
+				$reg_url_link
101
+			),
102
+			__FILE__,
103
+			__FUNCTION__,
104
+			__LINE__
105
+		);
106
+		return false;
107
+	}
108 108
 
109 109
 
110
-    /**
111
-     * @param EE_Registration $registration
112
-     * @param EE_Attendee     $attendee
113
-     * @return void
114
-     * @throws EE_Error
115
-     * @throws InvalidArgumentException
116
-     * @throws ReflectionException
117
-     * @throws RuntimeException
118
-     * @throws InvalidDataTypeException
119
-     * @throws InvalidInterfaceException
120
-     */
121
-    private function associateAttendeeWithRegistration(EE_Registration $registration, EE_Attendee $attendee)
122
-    {
123
-        // add relation to attendee
124
-        $registration->_add_relation_to($attendee, 'Attendee');
125
-        $registration->set_attendee_id($attendee->ID());
126
-        $registration->update_cache_after_object_save('Attendee', $attendee);
127
-    }
110
+	/**
111
+	 * @param EE_Registration $registration
112
+	 * @param EE_Attendee     $attendee
113
+	 * @return void
114
+	 * @throws EE_Error
115
+	 * @throws InvalidArgumentException
116
+	 * @throws ReflectionException
117
+	 * @throws RuntimeException
118
+	 * @throws InvalidDataTypeException
119
+	 * @throws InvalidInterfaceException
120
+	 */
121
+	private function associateAttendeeWithRegistration(EE_Registration $registration, EE_Attendee $attendee)
122
+	{
123
+		// add relation to attendee
124
+		$registration->_add_relation_to($attendee, 'Attendee');
125
+		$registration->set_attendee_id($attendee->ID());
126
+		$registration->update_cache_after_object_save('Attendee', $attendee);
127
+	}
128 128
 }
Please login to merge, or discard this patch.
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
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.
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -16,118 +16,118 @@
 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
-    {
36
-        $this->addRequiredQuestion = $addRequiredQuestion;
37
-        $this->answer_model = $answer_model;
38
-    }
30
+	/**
31
+	 * @param callable   $addRequiredQuestion
32
+	 * @param EEM_Answer $answer_model
33
+	 */
34
+	public function __construct(callable $addRequiredQuestion, EEM_Answer $answer_model)
35
+	{
36
+		$this->addRequiredQuestion = $addRequiredQuestion;
37
+		$this->answer_model = $answer_model;
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * @param EE_Registration $registration
43
-     * @param EE_Question     $question
44
-     * @return EE_Form_Input_Base
45
-     * @throws EE_Error
46
-     * @throws InvalidArgumentException
47
-     * @throws InvalidDataTypeException
48
-     * @throws InvalidInterfaceException
49
-     * @throws ReflectionException
50
-     */
51
-    public function create(
52
-        EE_Registration $registration,
53
-        EE_Question $question
54
-    ): EE_Form_Input_Base {
55
-        // if this question was for an attendee detail, then check for that answer
56
-        $answer_value = $this->answer_model->get_attendee_property_answer_value(
57
-            $registration,
58
-            $question->system_ID()
59
-        );
60
-        $answer       = $answer_value === null
61
-            ? $this->answer_model->get_one(
62
-                [['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]]
63
-            )
64
-            : null;
65
-        // if NOT returning to edit an existing registration
66
-        // OR if this question is for an attendee property
67
-        // OR we still don't have an EE_Answer object
68
-        if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
69
-            // create an EE_Answer object for storing everything in
70
-            $answer = EE_Answer::new_instance(
71
-                [
72
-                    'QST_ID' => $question->ID(),
73
-                    'REG_ID' => $registration->ID(),
74
-                ]
75
-            );
76
-        }
77
-        // verify instance
78
-        if ($answer instanceof EE_Answer) {
79
-            if (! empty($answer_value)) {
80
-                $answer->set('ANS_value', $answer_value);
81
-            }
82
-            $answer->cache('Question', $question);
83
-            // remember system ID had a bug where sometimes it could be null
84
-            $answer_cache_id = $question->is_system_question()
85
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
86
-                : $question->ID() . '-' . $registration->reg_url_link();
87
-            $registration->cache('Answer', $answer, $answer_cache_id);
88
-        }
89
-        return $this->generateQuestionInput($registration, $question, $answer);
90
-    }
41
+	/**
42
+	 * @param EE_Registration $registration
43
+	 * @param EE_Question     $question
44
+	 * @return EE_Form_Input_Base
45
+	 * @throws EE_Error
46
+	 * @throws InvalidArgumentException
47
+	 * @throws InvalidDataTypeException
48
+	 * @throws InvalidInterfaceException
49
+	 * @throws ReflectionException
50
+	 */
51
+	public function create(
52
+		EE_Registration $registration,
53
+		EE_Question $question
54
+	): EE_Form_Input_Base {
55
+		// if this question was for an attendee detail, then check for that answer
56
+		$answer_value = $this->answer_model->get_attendee_property_answer_value(
57
+			$registration,
58
+			$question->system_ID()
59
+		);
60
+		$answer       = $answer_value === null
61
+			? $this->answer_model->get_one(
62
+				[['QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()]]
63
+			)
64
+			: null;
65
+		// if NOT returning to edit an existing registration
66
+		// OR if this question is for an attendee property
67
+		// OR we still don't have an EE_Answer object
68
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
69
+			// create an EE_Answer object for storing everything in
70
+			$answer = EE_Answer::new_instance(
71
+				[
72
+					'QST_ID' => $question->ID(),
73
+					'REG_ID' => $registration->ID(),
74
+				]
75
+			);
76
+		}
77
+		// verify instance
78
+		if ($answer instanceof EE_Answer) {
79
+			if (! empty($answer_value)) {
80
+				$answer->set('ANS_value', $answer_value);
81
+			}
82
+			$answer->cache('Question', $question);
83
+			// remember system ID had a bug where sometimes it could be null
84
+			$answer_cache_id = $question->is_system_question()
85
+				? $question->system_ID() . '-' . $registration->reg_url_link()
86
+				: $question->ID() . '-' . $registration->reg_url_link();
87
+			$registration->cache('Answer', $answer, $answer_cache_id);
88
+		}
89
+		return $this->generateQuestionInput($registration, $question, $answer);
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * @param EE_Registration $registration
95
-     * @param EE_Question     $question
96
-     * @param                 $answer
97
-     * @return EE_Form_Input_Base
98
-     * @throws EE_Error
99
-     * @throws InvalidArgumentException
100
-     * @throws ReflectionException
101
-     * @throws InvalidDataTypeException
102
-     * @throws InvalidInterfaceException
103
-     */
104
-    private function generateQuestionInput(
105
-        EE_Registration $registration,
106
-        EE_Question $question,
107
-        $answer
108
-    ): EE_Form_Input_Base {
109
-        $identifier                              = $question->is_system_question()
110
-            ? $question->system_ID()
111
-            : $question->ID();
112
-        $callback = $this->addRequiredQuestion;
113
-        $callback($identifier, $question->required());
114
-        $input_constructor_args                  = [
115
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
116
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
117
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
118
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
119
-            'html_label_class' => 'ee-reg-qstn',
120
-        ];
121
-        $input_constructor_args['html_label_id'] .= '-lbl';
122
-        if ($answer instanceof EE_Answer && $answer->ID()) {
123
-            $input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
124
-            $input_constructor_args['html_id']       .= '-' . $answer->ID();
125
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
126
-        }
127
-        return $question->generate_form_input(
128
-            $registration,
129
-            $answer,
130
-            $input_constructor_args
131
-        );
132
-    }
93
+	/**
94
+	 * @param EE_Registration $registration
95
+	 * @param EE_Question     $question
96
+	 * @param                 $answer
97
+	 * @return EE_Form_Input_Base
98
+	 * @throws EE_Error
99
+	 * @throws InvalidArgumentException
100
+	 * @throws ReflectionException
101
+	 * @throws InvalidDataTypeException
102
+	 * @throws InvalidInterfaceException
103
+	 */
104
+	private function generateQuestionInput(
105
+		EE_Registration $registration,
106
+		EE_Question $question,
107
+		$answer
108
+	): EE_Form_Input_Base {
109
+		$identifier                              = $question->is_system_question()
110
+			? $question->system_ID()
111
+			: $question->ID();
112
+		$callback = $this->addRequiredQuestion;
113
+		$callback($identifier, $question->required());
114
+		$input_constructor_args                  = [
115
+			'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
116
+			'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
117
+			'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
118
+			'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
119
+			'html_label_class' => 'ee-reg-qstn',
120
+		];
121
+		$input_constructor_args['html_label_id'] .= '-lbl';
122
+		if ($answer instanceof EE_Answer && $answer->ID()) {
123
+			$input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
124
+			$input_constructor_args['html_id']       .= '-' . $answer->ID();
125
+			$input_constructor_args['html_label_id'] .= '-' . $answer->ID();
126
+		}
127
+		return $question->generate_form_input(
128
+			$registration,
129
+			$answer,
130
+			$input_constructor_args
131
+		);
132
+	}
133 133
 }
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
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.
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -18,309 +18,309 @@
 block discarded – undo
18 18
 class RegFormHandler
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Checkout
23
-     */
24
-    public $checkout;
21
+	/**
22
+	 * @var EE_Checkout
23
+	 */
24
+	public $checkout;
25 25
 
26
-    /**
27
-     * @var RegFormInputHandler
28
-     */
29
-    public $input_handler;
26
+	/**
27
+	 * @var RegFormInputHandler
28
+	 */
29
+	public $input_handler;
30 30
 
31
-    /**
32
-     * @var array
33
-     */
34
-    private $non_input_form_sections;
31
+	/**
32
+	 * @var array
33
+	 */
34
+	private $non_input_form_sections;
35 35
 
36
-    /**
37
-     * @var RegFormAttendeeFactory
38
-     */
39
-    private $attendee_factory;
36
+	/**
37
+	 * @var RegFormAttendeeFactory
38
+	 */
39
+	private $attendee_factory;
40 40
 
41
-    /**
42
-     * @var RegistrantData
43
-     */
44
-    private $registrant_data;
41
+	/**
42
+	 * @var RegistrantData
43
+	 */
44
+	private $registrant_data;
45 45
 
46
-    /**
47
-     * @var EE_Registration_Processor
48
-     */
49
-    private $registration_processor;
46
+	/**
47
+	 * @var EE_Registration_Processor
48
+	 */
49
+	private $registration_processor;
50 50
 
51
-    /**
52
-     * @var bool
53
-     */
54
-    private $valid;
51
+	/**
52
+	 * @var bool
53
+	 */
54
+	private $valid;
55 55
 
56 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
-    }
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 78
 
79 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
-    }
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 89
 
90 90
 
91
-    /**
92
-     * @return int
93
-     */
94
-    public function attendeeCount(): int
95
-    {
96
-        return $this->registrant_data->attendeeCount();
97
-    }
91
+	/**
92
+	 * @return int
93
+	 */
94
+	public function attendeeCount(): int
95
+	{
96
+		return $this->registrant_data->attendeeCount();
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * @return bool
102
-     */
103
-    private function isInvalid(): bool
104
-    {
105
-        $this->valid = false;
106
-        return $this->valid;
107
-    }
100
+	/**
101
+	 * @return bool
102
+	 */
103
+	private function isInvalid(): bool
104
+	{
105
+		$this->valid = false;
106
+		return $this->valid;
107
+	}
108 108
 
109 109
 
110
-    /**
111
-     * @param EE_Registration[] $registrations
112
-     * @param array[][]         $reg_form_data
113
-     * @return bool
114
-     * @throws EntityNotFoundException
115
-     * @throws EE_Error
116
-     * @throws InvalidArgumentException
117
-     * @throws ReflectionException
118
-     * @throws RuntimeException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     */
122
-    public function processRegistrations(array $registrations, array $reg_form_data): bool
123
-    {
124
-        // start off optimistic, then trip this to false if anything goes wrong
125
-        $this->valid = true;
126
-        foreach ($registrations as $registration) {
127
-            // verify EE_Registration object
128
-            if (! $this->isValidRegistration($registration)) {
129
-                return $this->isInvalid();
130
-            }
131
-            $reg_url_link = $registration->reg_url_link();
132
-            // reg_url_link exists ?
133
-            if (! $this->isValidRegUrlLink($reg_url_link)) {
134
-                return $this->isInvalid();
135
-            }
136
-            // should this registration be processed during this visit ?
137
-            if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) {
138
-                continue;
139
-            }
140
-            // if NOT revisiting, then let's save the registration now,
141
-            // so that we have a REG_ID to use when generating other objects
142
-            if (! $this->checkout->revisit) {
143
-                $registration->save();
144
-            }
145
-            /**
146
-             * This allows plugins to trigger a fail on processing of a
147
-             * registration for any conditions they may have for it to pass.
148
-             *
149
-             * @var bool if true is returned by the plugin then the registration processing is halted.
150
-             */
151
-            if (
152
-                apply_filters(
153
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
154
-                    false,
155
-                    $this->registrant_data->attendeeCount(),
156
-                    $registration,
157
-                    $registrations,
158
-                    $reg_form_data,
159
-                    $this
160
-                )
161
-            ) {
162
-                return $this->isInvalid();
163
-            }
110
+	/**
111
+	 * @param EE_Registration[] $registrations
112
+	 * @param array[][]         $reg_form_data
113
+	 * @return bool
114
+	 * @throws EntityNotFoundException
115
+	 * @throws EE_Error
116
+	 * @throws InvalidArgumentException
117
+	 * @throws ReflectionException
118
+	 * @throws RuntimeException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 */
122
+	public function processRegistrations(array $registrations, array $reg_form_data): bool
123
+	{
124
+		// start off optimistic, then trip this to false if anything goes wrong
125
+		$this->valid = true;
126
+		foreach ($registrations as $registration) {
127
+			// verify EE_Registration object
128
+			if (! $this->isValidRegistration($registration)) {
129
+				return $this->isInvalid();
130
+			}
131
+			$reg_url_link = $registration->reg_url_link();
132
+			// reg_url_link exists ?
133
+			if (! $this->isValidRegUrlLink($reg_url_link)) {
134
+				return $this->isInvalid();
135
+			}
136
+			// should this registration be processed during this visit ?
137
+			if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) {
138
+				continue;
139
+			}
140
+			// if NOT revisiting, then let's save the registration now,
141
+			// so that we have a REG_ID to use when generating other objects
142
+			if (! $this->checkout->revisit) {
143
+				$registration->save();
144
+			}
145
+			/**
146
+			 * This allows plugins to trigger a fail on processing of a
147
+			 * registration for any conditions they may have for it to pass.
148
+			 *
149
+			 * @var bool if true is returned by the plugin then the registration processing is halted.
150
+			 */
151
+			if (
152
+				apply_filters(
153
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
154
+					false,
155
+					$this->registrant_data->attendeeCount(),
156
+					$registration,
157
+					$registrations,
158
+					$reg_form_data,
159
+					$this
160
+				)
161
+			) {
162
+				return $this->isInvalid();
163
+			}
164 164
 
165
-            // Houston, we have a registration!
166
-            if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) {
167
-                return $this->isInvalid();
168
-            }
169
-        }
170
-        return $this->valid;
171
-    }
165
+			// Houston, we have a registration!
166
+			if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) {
167
+				return $this->isInvalid();
168
+			}
169
+		}
170
+		return $this->valid;
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * @param string $reg_url_link
176
-     * @return bool
177
-     */
178
-    private function isValidRegUrlLink(string $reg_url_link): bool
179
-    {
180
-        if (! empty($reg_url_link)) {
181
-            return true;
182
-        }
183
-        EE_Error::add_error(
184
-            esc_html__(
185
-                'An invalid or missing line item ID was encountered while attempting to process the registration form.',
186
-                'event_espresso'
187
-            ),
188
-            __FILE__,
189
-            __FUNCTION__,
190
-            __LINE__
191
-        );
192
-        return false;
193
-    }
174
+	/**
175
+	 * @param string $reg_url_link
176
+	 * @return bool
177
+	 */
178
+	private function isValidRegUrlLink(string $reg_url_link): bool
179
+	{
180
+		if (! empty($reg_url_link)) {
181
+			return true;
182
+		}
183
+		EE_Error::add_error(
184
+			esc_html__(
185
+				'An invalid or missing line item ID was encountered while attempting to process the registration form.',
186
+				'event_espresso'
187
+			),
188
+			__FILE__,
189
+			__FUNCTION__,
190
+			__LINE__
191
+		);
192
+		return false;
193
+	}
194 194
 
195 195
 
196
-    /**
197
-     * @param EE_Registration $registration
198
-     * @return bool
199
-     */
200
-    private function isValidRegistration(EE_Registration $registration): bool
201
-    {
202
-        // verify EE_Registration object
203
-        if ($registration instanceof EE_Registration) {
204
-            return true;
205
-        }
206
-        EE_Error::add_error(
207
-            esc_html__(
208
-                'An invalid Registration object was discovered when attempting to process your registration information.',
209
-                'event_espresso'
210
-            ),
211
-            __FILE__,
212
-            __FUNCTION__,
213
-            __LINE__
214
-        );
215
-        return false;
216
-    }
196
+	/**
197
+	 * @param EE_Registration $registration
198
+	 * @return bool
199
+	 */
200
+	private function isValidRegistration(EE_Registration $registration): bool
201
+	{
202
+		// verify EE_Registration object
203
+		if ($registration instanceof EE_Registration) {
204
+			return true;
205
+		}
206
+		EE_Error::add_error(
207
+			esc_html__(
208
+				'An invalid Registration object was discovered when attempting to process your registration information.',
209
+				'event_espresso'
210
+			),
211
+			__FILE__,
212
+			__FUNCTION__,
213
+			__LINE__
214
+		);
215
+		return false;
216
+	}
217 217
 
218 218
 
219
-    /**
220
-     * @param EE_Registration $registration
221
-     * @param string          $reg_url_link
222
-     * @param array[][]       $reg_form_data
223
-     * @return bool
224
-     * @throws EE_Error
225
-     * @throws ReflectionException
226
-     */
227
-    private function processRegistration(
228
-        EE_Registration $registration,
229
-        string $reg_url_link,
230
-        array $reg_form_data
231
-    ): bool {
232
-        $this->registrant_data->initializeRegistrantData($registration);
233
-        if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) {
234
-            return false;
235
-        }
236
-        // RegFormAttendeeFactory
237
-        if (! $this->attendee_factory->create($registration, $reg_url_link)) {
238
-            return false;
239
-        }
240
-        // at this point, we should have enough details about the registrant to consider the registration
241
-        // NOT incomplete
242
-        $this->registration_processor->toggle_incomplete_registration_status_to_default(
243
-            $registration,
244
-            false,
245
-            new Context(
246
-                'spco_reg_step_attendee_information_process_registrations',
247
-                esc_html__(
248
-                    'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
249
-                    'event_espresso'
250
-                )
251
-            )
252
-        );
253
-        // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
254
-        // abandoned
255
-        $this->checkout->transaction->toggle_failed_transaction_status();
256
-        // if we've gotten this far, then let's save what we have
257
-        $registration->save();
258
-        // add relation between TXN and registration
259
-        $this->associateRegistrationWithTransaction($registration);
260
-        return true;
261
-    }
219
+	/**
220
+	 * @param EE_Registration $registration
221
+	 * @param string          $reg_url_link
222
+	 * @param array[][]       $reg_form_data
223
+	 * @return bool
224
+	 * @throws EE_Error
225
+	 * @throws ReflectionException
226
+	 */
227
+	private function processRegistration(
228
+		EE_Registration $registration,
229
+		string $reg_url_link,
230
+		array $reg_form_data
231
+	): bool {
232
+		$this->registrant_data->initializeRegistrantData($registration);
233
+		if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) {
234
+			return false;
235
+		}
236
+		// RegFormAttendeeFactory
237
+		if (! $this->attendee_factory->create($registration, $reg_url_link)) {
238
+			return false;
239
+		}
240
+		// at this point, we should have enough details about the registrant to consider the registration
241
+		// NOT incomplete
242
+		$this->registration_processor->toggle_incomplete_registration_status_to_default(
243
+			$registration,
244
+			false,
245
+			new Context(
246
+				'spco_reg_step_attendee_information_process_registrations',
247
+				esc_html__(
248
+					'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
249
+					'event_espresso'
250
+				)
251
+			)
252
+		);
253
+		// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
254
+		// abandoned
255
+		$this->checkout->transaction->toggle_failed_transaction_status();
256
+		// if we've gotten this far, then let's save what we have
257
+		$registration->save();
258
+		// add relation between TXN and registration
259
+		$this->associateRegistrationWithTransaction($registration);
260
+		return true;
261
+	}
262 262
 
263 263
 
264
-    /**
265
-     * @param EE_Registration $registration
266
-     * @param string          $reg_url_link
267
-     * @param array           $reg_form_data
268
-     * @return bool
269
-     * @throws EE_Error
270
-     * @throws ReflectionException
271
-     */
272
-    private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool
273
-    {
274
-        if (isset($reg_form_data[ $reg_url_link ])) {
275
-            // do we need to copy basic info from primary attendee ?
276
-            $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info'])
277
-                                  && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
278
-            $this->registrant_data->setCopyPrimary($copy_primary);
279
-            // filter form input data for this registration
280
-            $reg_form_data[ $reg_url_link ] = (array) apply_filters(
281
-                'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
282
-                $reg_form_data[ $reg_url_link ]
283
-            );
284
-            if (isset($reg_form_data['primary_attendee'])) {
285
-                $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? '';
286
-                $this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link);
287
-                unset($reg_form_data['primary_attendee']);
288
-            }
289
-            // now loop through our array of valid post data && process attendee reg forms
290
-            foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) {
291
-                if (in_array($form_section, $this->non_input_form_sections, true)) {
292
-                    continue;
293
-                }
294
-                foreach ($form_inputs as $form_input => $input_value) {
295
-                    $input_processed = $this->input_handler->processFormInput(
296
-                        $registration,
297
-                        $reg_url_link,
298
-                        $form_input,
299
-                        $input_value
300
-                    );
301
-                    if (! $input_processed) {
302
-                        return false;
303
-                    }
304
-                }
305
-            }
306
-        }
307
-        return true;
308
-    }
264
+	/**
265
+	 * @param EE_Registration $registration
266
+	 * @param string          $reg_url_link
267
+	 * @param array           $reg_form_data
268
+	 * @return bool
269
+	 * @throws EE_Error
270
+	 * @throws ReflectionException
271
+	 */
272
+	private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool
273
+	{
274
+		if (isset($reg_form_data[ $reg_url_link ])) {
275
+			// do we need to copy basic info from primary attendee ?
276
+			$copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info'])
277
+								  && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
278
+			$this->registrant_data->setCopyPrimary($copy_primary);
279
+			// filter form input data for this registration
280
+			$reg_form_data[ $reg_url_link ] = (array) apply_filters(
281
+				'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
282
+				$reg_form_data[ $reg_url_link ]
283
+			);
284
+			if (isset($reg_form_data['primary_attendee'])) {
285
+				$primary_reg_url_link = $reg_form_data['primary_attendee'] ?? '';
286
+				$this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link);
287
+				unset($reg_form_data['primary_attendee']);
288
+			}
289
+			// now loop through our array of valid post data && process attendee reg forms
290
+			foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) {
291
+				if (in_array($form_section, $this->non_input_form_sections, true)) {
292
+					continue;
293
+				}
294
+				foreach ($form_inputs as $form_input => $input_value) {
295
+					$input_processed = $this->input_handler->processFormInput(
296
+						$registration,
297
+						$reg_url_link,
298
+						$form_input,
299
+						$input_value
300
+					);
301
+					if (! $input_processed) {
302
+						return false;
303
+					}
304
+				}
305
+			}
306
+		}
307
+		return true;
308
+	}
309 309
 
310 310
 
311
-    /**
312
-     * @param EE_Registration $registration
313
-     * @return void
314
-     * @throws EE_Error
315
-     * @throws InvalidArgumentException
316
-     * @throws ReflectionException
317
-     * @throws InvalidDataTypeException
318
-     * @throws InvalidInterfaceException
319
-     */
320
-    private function associateRegistrationWithTransaction(EE_Registration $registration)
321
-    {
322
-        // add relation to registration
323
-        $this->checkout->transaction->_add_relation_to($registration, 'Registration');
324
-        $this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
325
-    }
311
+	/**
312
+	 * @param EE_Registration $registration
313
+	 * @return void
314
+	 * @throws EE_Error
315
+	 * @throws InvalidArgumentException
316
+	 * @throws ReflectionException
317
+	 * @throws InvalidDataTypeException
318
+	 * @throws InvalidInterfaceException
319
+	 */
320
+	private function associateRegistrationWithTransaction(EE_Registration $registration)
321
+	{
322
+		// add relation to registration
323
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
324
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
325
+	}
326 326
 }
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
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.
Indentation   +351 added lines, -351 removed lines patch added patch discarded remove patch
@@ -19,355 +19,355 @@
 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
-    {
157
-        if ($this->currentRegistrantIsPrimary()) {
158
-            return;
159
-        }
160
-        // bare minimum critical details include first name, last name, email address
161
-        $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email'];
162
-        // add address info to critical details?
163
-        if (
164
-            apply_filters(
165
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
166
-                false
167
-            )
168
-        ) {
169
-            $critical_attendee_details += [
170
-                'ATT_address',
171
-                'ATT_address2',
172
-                'ATT_city',
173
-                'STA_ID',
174
-                'CNT_ISO',
175
-                'ATT_zip',
176
-                'ATT_phone',
177
-            ];
178
-        }
179
-        foreach ($critical_attendee_details as $critical_attendee_detail) {
180
-            if (
181
-                ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
182
-                || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
183
-            ) {
184
-                $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get(
185
-                    $critical_attendee_detail
186
-                );
187
-            }
188
-        }
189
-    }
190
-
191
-
192
-    /**
193
-     * @param string $reg_url_link
194
-     * @param array $registrant_data
195
-     */
196
-    public function setRegistrantData(string $reg_url_link, array $registrant_data): void
197
-    {
198
-        $this->registrant_data[ $reg_url_link ] = $registrant_data;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return array
204
-     */
205
-    public function getRequiredQuestions(): array
206
-    {
207
-        return $this->required_questions;
208
-    }
209
-
210
-
211
-    /**
212
-     * @param string $identifier
213
-     * @param string $required_question
214
-     */
215
-    public function addRequiredQuestion(string $identifier, string $required_question): void
216
-    {
217
-        $this->required_questions[ $identifier ] = $required_question;
218
-    }
219
-
220
-
221
-    /**
222
-     * @return EE_Answer[]
223
-     */
224
-    public function registrantAnswers(string $reg_url_link): array
225
-    {
226
-        return $this->registrant_answers[ $reg_url_link ] ?? [];
227
-    }
228
-
229
-
230
-    /**
231
-     * @param string $reg_url_link
232
-     * @param string $identifier  the answer cache ID
233
-     * @param EE_Answer $answer
234
-     */
235
-    public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void
236
-    {
237
-        $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer;
238
-    }
239
-
240
-
241
-    /**
242
-     * @param string $reg_url_link
243
-     * @param string $identifier
244
-     * @return EE_Answer|null
245
-     */
246
-    public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer
247
-    {
248
-        return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null;
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * @param string $reg_url_link
255
-     * @param string $identifier
256
-     * @return bool
257
-     */
258
-    public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool
259
-    {
260
-        $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier);
261
-        return $registrant_answer instanceof EE_Answer;
262
-    }
263
-
264
-
265
-    /**
266
-     * @return array
267
-     */
268
-    public function primaryRegistrantData(): array
269
-    {
270
-        return $this->primary_registrant_data;
271
-    }
272
-
273
-
274
-    /**
275
-     * @param string $key
276
-     * @param mixed  $value
277
-     */
278
-    public function addPrimaryRegistrantDataValue(string $key, $value): void
279
-    {
280
-        $this->primary_registrant_data[ $key ] = $value;
281
-    }
282
-
283
-
284
-    /**
285
-     * @param string $key
286
-     * @return mixed
287
-     */
288
-    public function getPrimaryRegistrantDataValue(string $key)
289
-    {
290
-        return $this->primary_registrant_data[ $key ] ?? null;
291
-    }
292
-
293
-
294
-    /**
295
-     * @param array $primary_registrant_data
296
-     */
297
-    public function setPrimaryRegistrantData(array $primary_registrant_data): void
298
-    {
299
-        $this->primary_registrant_data = $primary_registrant_data;
300
-    }
301
-
302
-
303
-    /**
304
-     * @return EE_Attendee
305
-     */
306
-    public function primaryRegistrant(): EE_Attendee
307
-    {
308
-        return $this->primary_registrant;
309
-    }
310
-
311
-
312
-    /**
313
-     * @return bool
314
-     */
315
-    public function primaryRegistrantIsValid(): bool
316
-    {
317
-        return $this->primary_registrant instanceof EE_Attendee;
318
-    }
319
-
320
-
321
-    /**
322
-     * @param EE_Attendee $primary_registrant
323
-     */
324
-    public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void
325
-    {
326
-        $this->primary_registrant = $primary_registrant;
327
-    }
328
-
329
-
330
-    /**
331
-     * @param string $reg_url_link
332
-     * @return bool
333
-     */
334
-    public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool
335
-    {
336
-        return $this->attendeeCount() === 1
337
-            || (
338
-                $this->attendeeCount() === 1
339
-                && $reg_url_link !== ''
340
-                && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link
341
-            );
342
-    }
343
-
344
-
345
-    /**
346
-     * @return bool
347
-     */
348
-    public function currentRegistrantIsNotPrimary(): bool
349
-    {
350
-        return $this->attendeeCount() > 1;
351
-    }
352
-
353
-
354
-    /**
355
-     * @param string $reg_url_link
356
-     * @param string $form_input
357
-     * @param mixed  $input_value
358
-     * @return mixed|null
359
-     */
360
-    public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value)
361
-    {
362
-        // store a bit of data about the primary attendee
363
-        if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) {
364
-            $this->primary_registrant_data[ $form_input ] = $input_value;
365
-            return $input_value;
366
-        }
367
-        // or copy value from primary if incoming value is not set
368
-        if ($input_value === null && $this->copyPrimary()) {
369
-            $input_value = $this->getPrimaryRegistrantDataValue($form_input);
370
-        }
371
-        return $input_value;
372
-    }
22
+	/**
23
+	 * @var int
24
+	 */
25
+	private $attendee_counter = 0;
26
+
27
+	/**
28
+	 * @var array
29
+	 */
30
+	private $registrant_data = [];
31
+
32
+	/**
33
+	 * @var bool
34
+	 */
35
+	private $copy_primary = false;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private $required_questions = [];
41
+
42
+	/**
43
+	 * @var EE_Registration[]
44
+	 */
45
+	private $registrations = [];
46
+
47
+	/**
48
+	 * @var EE_Answer[][]
49
+	 */
50
+	private $registrant_answers = [];
51
+
52
+	/**
53
+	 * array for tracking reg form data for the primary registrant
54
+	 *
55
+	 * @var array
56
+	 */
57
+	private $primary_registrant_data;
58
+
59
+	/**
60
+	 * the attendee object created for the primary registrant
61
+	 *
62
+	 * @var EE_Attendee
63
+	 */
64
+	private $primary_registrant;
65
+
66
+
67
+	/**
68
+	 * RegistrantData constructor.
69
+	 */
70
+	public function __construct()
71
+	{
72
+		$this->primary_registrant_data = ['line_item_id' => null,];
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param EE_Registration $registration
78
+	 * @throws EE_Error
79
+	 */
80
+	public function initializeRegistrantData(EE_Registration $registration): void
81
+	{
82
+		$reg_url_link = $registration->reg_url_link();
83
+		$this->registrations[ $reg_url_link ] = $registration;
84
+		$this->registrant_answers[ $reg_url_link ] = $registration->answers();
85
+		$this->registrant_data[ $reg_url_link ] = [];
86
+		$this->attendee_counter++;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @return int
92
+	 */
93
+	public function attendeeCount(): int
94
+	{
95
+		return $this->attendee_counter;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return bool
101
+	 */
102
+	public function copyPrimary(): bool
103
+	{
104
+		return $this->copy_primary;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param bool $copy_primary
110
+	 */
111
+	public function setCopyPrimary(bool $copy_primary): void
112
+	{
113
+		$this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN);
114
+	}
115
+
116
+
117
+	/**
118
+	 * @param string $reg_url_link
119
+	 * @return array|null
120
+	 */
121
+	public function getRegistrant(string $reg_url_link): ?EE_Registration
122
+	{
123
+		return $this->registrations[ $reg_url_link ] ?? null;
124
+	}
125
+
126
+
127
+	/**
128
+	 * @param string $reg_url_link
129
+	 * @return array|null
130
+	 */
131
+	public function getRegistrantData(string $reg_url_link): ?array
132
+	{
133
+		return $this->registrant_data[ $reg_url_link ] ?? null;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @param string $reg_url_link
139
+	 * @param string $key
140
+	 * @param mixed $value
141
+	 */
142
+	public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void
143
+	{
144
+		$this->registrant_data[ $reg_url_link ][ $key ] = $value;
145
+	}
146
+
147
+
148
+	/**
149
+	 * ensures that all attendees at least have data for first name, last name, and email address
150
+	 *
151
+	 * @param string $reg_url_link
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void
156
+	{
157
+		if ($this->currentRegistrantIsPrimary()) {
158
+			return;
159
+		}
160
+		// bare minimum critical details include first name, last name, email address
161
+		$critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email'];
162
+		// add address info to critical details?
163
+		if (
164
+			apply_filters(
165
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
166
+				false
167
+			)
168
+		) {
169
+			$critical_attendee_details += [
170
+				'ATT_address',
171
+				'ATT_address2',
172
+				'ATT_city',
173
+				'STA_ID',
174
+				'CNT_ISO',
175
+				'ATT_zip',
176
+				'ATT_phone',
177
+			];
178
+		}
179
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
180
+			if (
181
+				! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
182
+				|| empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ])
183
+			) {
184
+				$this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get(
185
+					$critical_attendee_detail
186
+				);
187
+			}
188
+		}
189
+	}
190
+
191
+
192
+	/**
193
+	 * @param string $reg_url_link
194
+	 * @param array $registrant_data
195
+	 */
196
+	public function setRegistrantData(string $reg_url_link, array $registrant_data): void
197
+	{
198
+		$this->registrant_data[ $reg_url_link ] = $registrant_data;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return array
204
+	 */
205
+	public function getRequiredQuestions(): array
206
+	{
207
+		return $this->required_questions;
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param string $identifier
213
+	 * @param string $required_question
214
+	 */
215
+	public function addRequiredQuestion(string $identifier, string $required_question): void
216
+	{
217
+		$this->required_questions[ $identifier ] = $required_question;
218
+	}
219
+
220
+
221
+	/**
222
+	 * @return EE_Answer[]
223
+	 */
224
+	public function registrantAnswers(string $reg_url_link): array
225
+	{
226
+		return $this->registrant_answers[ $reg_url_link ] ?? [];
227
+	}
228
+
229
+
230
+	/**
231
+	 * @param string $reg_url_link
232
+	 * @param string $identifier  the answer cache ID
233
+	 * @param EE_Answer $answer
234
+	 */
235
+	public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void
236
+	{
237
+		$this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param string $reg_url_link
243
+	 * @param string $identifier
244
+	 * @return EE_Answer|null
245
+	 */
246
+	public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer
247
+	{
248
+		return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null;
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * @param string $reg_url_link
255
+	 * @param string $identifier
256
+	 * @return bool
257
+	 */
258
+	public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool
259
+	{
260
+		$registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier);
261
+		return $registrant_answer instanceof EE_Answer;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return array
267
+	 */
268
+	public function primaryRegistrantData(): array
269
+	{
270
+		return $this->primary_registrant_data;
271
+	}
272
+
273
+
274
+	/**
275
+	 * @param string $key
276
+	 * @param mixed  $value
277
+	 */
278
+	public function addPrimaryRegistrantDataValue(string $key, $value): void
279
+	{
280
+		$this->primary_registrant_data[ $key ] = $value;
281
+	}
282
+
283
+
284
+	/**
285
+	 * @param string $key
286
+	 * @return mixed
287
+	 */
288
+	public function getPrimaryRegistrantDataValue(string $key)
289
+	{
290
+		return $this->primary_registrant_data[ $key ] ?? null;
291
+	}
292
+
293
+
294
+	/**
295
+	 * @param array $primary_registrant_data
296
+	 */
297
+	public function setPrimaryRegistrantData(array $primary_registrant_data): void
298
+	{
299
+		$this->primary_registrant_data = $primary_registrant_data;
300
+	}
301
+
302
+
303
+	/**
304
+	 * @return EE_Attendee
305
+	 */
306
+	public function primaryRegistrant(): EE_Attendee
307
+	{
308
+		return $this->primary_registrant;
309
+	}
310
+
311
+
312
+	/**
313
+	 * @return bool
314
+	 */
315
+	public function primaryRegistrantIsValid(): bool
316
+	{
317
+		return $this->primary_registrant instanceof EE_Attendee;
318
+	}
319
+
320
+
321
+	/**
322
+	 * @param EE_Attendee $primary_registrant
323
+	 */
324
+	public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void
325
+	{
326
+		$this->primary_registrant = $primary_registrant;
327
+	}
328
+
329
+
330
+	/**
331
+	 * @param string $reg_url_link
332
+	 * @return bool
333
+	 */
334
+	public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool
335
+	{
336
+		return $this->attendeeCount() === 1
337
+			|| (
338
+				$this->attendeeCount() === 1
339
+				&& $reg_url_link !== ''
340
+				&& $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link
341
+			);
342
+	}
343
+
344
+
345
+	/**
346
+	 * @return bool
347
+	 */
348
+	public function currentRegistrantIsNotPrimary(): bool
349
+	{
350
+		return $this->attendeeCount() > 1;
351
+	}
352
+
353
+
354
+	/**
355
+	 * @param string $reg_url_link
356
+	 * @param string $form_input
357
+	 * @param mixed  $input_value
358
+	 * @return mixed|null
359
+	 */
360
+	public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value)
361
+	{
362
+		// store a bit of data about the primary attendee
363
+		if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) {
364
+			$this->primary_registrant_data[ $form_input ] = $input_value;
365
+			return $input_value;
366
+		}
367
+		// or copy value from primary if incoming value is not set
368
+		if ($input_value === null && $this->copyPrimary()) {
369
+			$input_value = $this->getPrimaryRegistrantDataValue($form_input);
370
+		}
371
+		return $input_value;
372
+	}
373 373
 }
Please login to merge, or discard this patch.