Completed
Branch FET/reg-form-builder/edtr-rehy... (bb0b03)
by
unknown
13:21 queued 10:57
created
core/domain/services/registration/form/v1/RegForm.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -32,251 +32,251 @@
 block discarded – undo
32 32
 class RegForm extends EE_Form_Section_Proper
33 33
 {
34 34
 
35
-    /**
36
-     * @var bool
37
-     */
38
-    private $print_copy_info = false;
35
+	/**
36
+	 * @var bool
37
+	 */
38
+	private $print_copy_info = false;
39 39
 
40
-    /**
41
-     * @var EE_Registration_Config
42
-     */
43
-    public $reg_config;
40
+	/**
41
+	 * @var EE_Registration_Config
42
+	 */
43
+	public $reg_config;
44 44
 
45
-    /**
46
-     * @var int
47
-     */
48
-    protected $reg_form_count = 0;
45
+	/**
46
+	 * @var int
47
+	 */
48
+	protected $reg_form_count = 0;
49 49
 
50
-    /**
51
-     * @var EE_SPCO_Reg_Step_Attendee_Information
52
-     */
53
-    public $reg_step;
50
+	/**
51
+	 * @var EE_SPCO_Reg_Step_Attendee_Information
52
+	 */
53
+	public $reg_step;
54 54
 
55
-    /**
56
-     * @var array
57
-     */
58
-    private $required_questions = [];
55
+	/**
56
+	 * @var array
57
+	 */
58
+	private $required_questions = [];
59 59
 
60
-    /**
61
-     * @var array
62
-     */
63
-    private $template_args = [];
60
+	/**
61
+	 * @var array
62
+	 */
63
+	private $template_args = [];
64 64
 
65 65
 
66
-    /**
67
-     * RegForm constructor.
68
-     *
69
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
70
-     * @param EE_Registration_Config                $reg_config
71
-     * @throws ReflectionException
72
-     * @throws EE_Error
73
-     */
74
-    public function __construct(
75
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
76
-        EE_Registration_Config $reg_config
77
-    ) {
78
-        $this->reg_step   = $reg_step;
79
-        $this->reg_config = $reg_config;
80
-        // setup some classes so that they are ready for loading during construction of other classes
81
-        LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]);
82
-        LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]);
83
-        LoaderFactory::getShared(RegFormQuestionFactory::class, [[$this, 'addRequiredQuestion']]);
84
-        parent::__construct(
85
-            [
86
-                'name'            => $this->reg_step->reg_form_name(),
87
-                'html_id'         => $this->reg_step->reg_form_name(),
88
-                'subsections'     => $this->generateSubsections(),
89
-                'layout_strategy' => new EE_Template_Layout(
90
-                    [
91
-                        'layout_template_file' => $this->reg_step->template(), // layout_template
92
-                        'template_args'        => $this->template_args,
93
-                    ]
94
-                ),
95
-            ]
96
-        );
97
-    }
66
+	/**
67
+	 * RegForm constructor.
68
+	 *
69
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
70
+	 * @param EE_Registration_Config                $reg_config
71
+	 * @throws ReflectionException
72
+	 * @throws EE_Error
73
+	 */
74
+	public function __construct(
75
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
76
+		EE_Registration_Config $reg_config
77
+	) {
78
+		$this->reg_step   = $reg_step;
79
+		$this->reg_config = $reg_config;
80
+		// setup some classes so that they are ready for loading during construction of other classes
81
+		LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]);
82
+		LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]);
83
+		LoaderFactory::getShared(RegFormQuestionFactory::class, [[$this, 'addRequiredQuestion']]);
84
+		parent::__construct(
85
+			[
86
+				'name'            => $this->reg_step->reg_form_name(),
87
+				'html_id'         => $this->reg_step->reg_form_name(),
88
+				'subsections'     => $this->generateSubsections(),
89
+				'layout_strategy' => new EE_Template_Layout(
90
+					[
91
+						'layout_template_file' => $this->reg_step->template(), // layout_template
92
+						'template_args'        => $this->template_args,
93
+					]
94
+				),
95
+			]
96
+		);
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * @return void
102
-     */
103
-    public function enablePrintCopyInfo(): void
104
-    {
105
-        $this->print_copy_info = true;
106
-    }
100
+	/**
101
+	 * @return void
102
+	 */
103
+	public function enablePrintCopyInfo(): void
104
+	{
105
+		$this->print_copy_info = true;
106
+	}
107 107
 
108 108
 
109
-    /**
110
-     * @return bool
111
-     */
112
-    public function printCopyInfo(): bool
113
-    {
114
-        return $this->print_copy_info;
115
-    }
109
+	/**
110
+	 * @return bool
111
+	 */
112
+	public function printCopyInfo(): bool
113
+	{
114
+		return $this->print_copy_info;
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * @return int
120
-     */
121
-    public function regFormCount(): int
122
-    {
123
-        return $this->reg_form_count;
124
-    }
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function regFormCount(): int
122
+	{
123
+		return $this->reg_form_count;
124
+	}
125 125
 
126 126
 
127
-    /**
128
-     * @return array
129
-     */
130
-    public function requiredQuestions(): array
131
-    {
132
-        return $this->required_questions;
133
-    }
127
+	/**
128
+	 * @return array
129
+	 */
130
+	public function requiredQuestions(): array
131
+	{
132
+		return $this->required_questions;
133
+	}
134 134
 
135 135
 
136
-    /**
137
-     * @param string $identifier
138
-     * @param string $required_question
139
-     */
140
-    public function addRequiredQuestion(string $identifier, string $required_question): void
141
-    {
142
-        $this->required_questions[ $identifier ] = $required_question;
143
-    }
136
+	/**
137
+	 * @param string $identifier
138
+	 * @param string $required_question
139
+	 */
140
+	public function addRequiredQuestion(string $identifier, string $required_question): void
141
+	{
142
+		$this->required_questions[ $identifier ] = $required_question;
143
+	}
144 144
 
145 145
 
146
-    /**
147
-     * @return EE_Form_Section_Proper[]
148
-     * @throws DomainException
149
-     * @throws EE_Error
150
-     * @throws InvalidArgumentException
151
-     * @throws ReflectionException
152
-     * @throws EntityNotFoundException
153
-     * @throws InvalidDataTypeException
154
-     * @throws InvalidInterfaceException
155
-     */
156
-    private function generateSubsections(): array
157
-    {
158
-        // Init reg forms count.
159
-        $this->reg_form_count = 0;
146
+	/**
147
+	 * @return EE_Form_Section_Proper[]
148
+	 * @throws DomainException
149
+	 * @throws EE_Error
150
+	 * @throws InvalidArgumentException
151
+	 * @throws ReflectionException
152
+	 * @throws EntityNotFoundException
153
+	 * @throws InvalidDataTypeException
154
+	 * @throws InvalidInterfaceException
155
+	 */
156
+	private function generateSubsections(): array
157
+	{
158
+		// Init reg forms count.
159
+		$this->reg_form_count = 0;
160 160
 
161
-        $primary_registrant = null;
162
-        // autoload Line_Item_Display classes
163
-        EEH_Autoloader::register_line_item_display_autoloaders();
164
-        $Line_Item_Display = new EE_Line_Item_Display();
165
-        // calculate taxes
166
-        $Line_Item_Display->display_line_item(
167
-            $this->reg_step->checkout->cart->get_grand_total(),
168
-            ['set_tax_rate' => true]
169
-        );
170
-        $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs();
171
-        $this->addPrivacyConsentCheckbox($extra_inputs_section);
172
-        $subsections = [
173
-            'default_hidden_inputs' => $extra_inputs_section,
174
-        ];
161
+		$primary_registrant = null;
162
+		// autoload Line_Item_Display classes
163
+		EEH_Autoloader::register_line_item_display_autoloaders();
164
+		$Line_Item_Display = new EE_Line_Item_Display();
165
+		// calculate taxes
166
+		$Line_Item_Display->display_line_item(
167
+			$this->reg_step->checkout->cart->get_grand_total(),
168
+			['set_tax_rate' => true]
169
+		);
170
+		$extra_inputs_section = $this->reg_step->reg_step_hidden_inputs();
171
+		$this->addPrivacyConsentCheckbox($extra_inputs_section);
172
+		$subsections = [
173
+			'default_hidden_inputs' => $extra_inputs_section,
174
+		];
175 175
 
176
-        $this->template_args = [
177
-            'revisit'       => $this->reg_step->checkout->revisit,
178
-            'registrations' => [],
179
-            'ticket_count'  => [],
180
-        ];
181
-        // grab the saved registrations from the transaction
182
-        $registrations = $this->reg_step->checkout->transaction->registrations(
183
-            $this->reg_step->checkout->reg_cache_where_params
184
-        );
185
-        if ($registrations) {
186
-            foreach ($registrations as $registration) {
187
-                // can this registration be processed during this visit ?
188
-                if (
189
-                    $registration instanceof EE_Registration
190
-                    && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration)
191
-                ) {
192
-                    $reg_url_link = $registration->reg_url_link();
193
-                    /** @var RegistrantForm $registrant_form */
194
-                    $registrant_form = LoaderFactory::getNew(
195
-                        RegistrantForm::class,
196
-                        [
197
-                            $registration,
198
-                            $this->reg_step->checkout->admin_request,
199
-                            $this->reg_config->copyAttendeeInfo(),
200
-                            [$this, 'enablePrintCopyInfo'],
201
-                        ]
202
-                    );
203
-                    // Increment the reg forms number if form is valid.
204
-                    if ($registrant_form->hasQuestions()) {
205
-                        $this->reg_form_count++;
206
-                        $subsections[ $reg_url_link ] = $registrant_form;
207
-                    } else {
208
-                        // or just add a blank section if there are no questions
209
-                        $subsections[ $reg_url_link ] = new EE_Form_Section_HTML();
210
-                    }
176
+		$this->template_args = [
177
+			'revisit'       => $this->reg_step->checkout->revisit,
178
+			'registrations' => [],
179
+			'ticket_count'  => [],
180
+		];
181
+		// grab the saved registrations from the transaction
182
+		$registrations = $this->reg_step->checkout->transaction->registrations(
183
+			$this->reg_step->checkout->reg_cache_where_params
184
+		);
185
+		if ($registrations) {
186
+			foreach ($registrations as $registration) {
187
+				// can this registration be processed during this visit ?
188
+				if (
189
+					$registration instanceof EE_Registration
190
+					&& $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration)
191
+				) {
192
+					$reg_url_link = $registration->reg_url_link();
193
+					/** @var RegistrantForm $registrant_form */
194
+					$registrant_form = LoaderFactory::getNew(
195
+						RegistrantForm::class,
196
+						[
197
+							$registration,
198
+							$this->reg_step->checkout->admin_request,
199
+							$this->reg_config->copyAttendeeInfo(),
200
+							[$this, 'enablePrintCopyInfo'],
201
+						]
202
+					);
203
+					// Increment the reg forms number if form is valid.
204
+					if ($registrant_form->hasQuestions()) {
205
+						$this->reg_form_count++;
206
+						$subsections[ $reg_url_link ] = $registrant_form;
207
+					} else {
208
+						// or just add a blank section if there are no questions
209
+						$subsections[ $reg_url_link ] = new EE_Form_Section_HTML();
210
+					}
211 211
 
212
-                    $this->template_args['registrations'][ $reg_url_link ]                = $registration;
213
-                    $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
214
-                        $this->template_args['ticket_count'][ $registration->ticket()->ID() ]
215
-                    )
216
-                        ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
217
-                        : 1;
218
-                    $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
219
-                        $this->reg_step->checkout->cart->get_grand_total(),
220
-                        'Ticket',
221
-                        [$registration->ticket()->ID()]
222
-                    );
223
-                    $ticket_line_item = is_array($ticket_line_item)
224
-                        ? reset($ticket_line_item)
225
-                        : $ticket_line_item;
226
-                    $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
227
-                        $Line_Item_Display->display_line_item($ticket_line_item);
228
-                    if ($registration->is_primary_registrant()) {
229
-                        $primary_registrant = $reg_url_link;
230
-                    }
231
-                }
232
-            }
212
+					$this->template_args['registrations'][ $reg_url_link ]                = $registration;
213
+					$this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
214
+						$this->template_args['ticket_count'][ $registration->ticket()->ID() ]
215
+					)
216
+						? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
217
+						: 1;
218
+					$ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
219
+						$this->reg_step->checkout->cart->get_grand_total(),
220
+						'Ticket',
221
+						[$registration->ticket()->ID()]
222
+					);
223
+					$ticket_line_item = is_array($ticket_line_item)
224
+						? reset($ticket_line_item)
225
+						: $ticket_line_item;
226
+					$this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
227
+						$Line_Item_Display->display_line_item($ticket_line_item);
228
+					if ($registration->is_primary_registrant()) {
229
+						$primary_registrant = $reg_url_link;
230
+					}
231
+				}
232
+			}
233 233
 
234
-            if ($primary_registrant && count($registrations) > 1) {
235
-                if (
236
-                    isset($subsections[ $primary_registrant ])
237
-                    && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
238
-                ) {
239
-                    $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info
240
-                        ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug())
241
-                        : new AutoCopyAttendeeInfoForm($this->reg_step->slug());
242
-                    $subsections[ $primary_registrant ]->add_subsections(
243
-                        $copy_options,
244
-                        'primary_registrant',
245
-                        false
246
-                    );
247
-                }
248
-            }
249
-        }
234
+			if ($primary_registrant && count($registrations) > 1) {
235
+				if (
236
+					isset($subsections[ $primary_registrant ])
237
+					&& $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
238
+				) {
239
+					$copy_options['spco_copy_attendee_chk'] = $this->print_copy_info
240
+						? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug())
241
+						: new AutoCopyAttendeeInfoForm($this->reg_step->slug());
242
+					$subsections[ $primary_registrant ]->add_subsections(
243
+						$copy_options,
244
+						'primary_registrant',
245
+						false
246
+					);
247
+				}
248
+			}
249
+		}
250 250
 
251
-        // Set the registration form template (default: one form per ticket details table).
252
-        // We decide the template to used based on the number of forms.
253
-        $template = $this->reg_form_count > 1
254
-            ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php'
255
-            : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php';
256
-        $this->reg_step->setTemplate($template);
251
+		// Set the registration form template (default: one form per ticket details table).
252
+		// We decide the template to used based on the number of forms.
253
+		$template = $this->reg_form_count > 1
254
+			? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php'
255
+			: SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php';
256
+		$this->reg_step->setTemplate($template);
257 257
 
258
-        return $subsections;
259
-    }
258
+		return $subsections;
259
+	}
260 260
 
261 261
 
262
-    /**
263
-     * @param EE_Form_Section_Proper $extra_inputs_section
264
-     * @throws EE_Error
265
-     */
266
-    private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section)
267
-    {
268
-        // if this isn't a revisit, and they have the privacy consent box enabled, add it
269
-        if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) {
270
-            $extra_inputs_section->add_subsections(
271
-                [
272
-                    'consent_box' => new PrivacyConsentCheckboxForm(
273
-                        $this->reg_step->slug(),
274
-                        $this->reg_config->getConsentCheckboxLabelText()
275
-                    )
276
-                ],
277
-                null,
278
-                false
279
-            );
280
-        }
281
-    }
262
+	/**
263
+	 * @param EE_Form_Section_Proper $extra_inputs_section
264
+	 * @throws EE_Error
265
+	 */
266
+	private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section)
267
+	{
268
+		// if this isn't a revisit, and they have the privacy consent box enabled, add it
269
+		if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) {
270
+			$extra_inputs_section->add_subsections(
271
+				[
272
+					'consent_box' => new PrivacyConsentCheckboxForm(
273
+						$this->reg_step->slug(),
274
+						$this->reg_config->getConsentCheckboxLabelText()
275
+					)
276
+				],
277
+				null,
278
+				false
279
+			);
280
+		}
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function addRequiredQuestion(string $identifier, string $required_question): void
141 141
     {
142
-        $this->required_questions[ $identifier ] = $required_question;
142
+        $this->required_questions[$identifier] = $required_question;
143 143
     }
144 144
 
145 145
 
@@ -203,17 +203,17 @@  discard block
 block discarded – undo
203 203
                     // Increment the reg forms number if form is valid.
204 204
                     if ($registrant_form->hasQuestions()) {
205 205
                         $this->reg_form_count++;
206
-                        $subsections[ $reg_url_link ] = $registrant_form;
206
+                        $subsections[$reg_url_link] = $registrant_form;
207 207
                     } else {
208 208
                         // or just add a blank section if there are no questions
209
-                        $subsections[ $reg_url_link ] = new EE_Form_Section_HTML();
209
+                        $subsections[$reg_url_link] = new EE_Form_Section_HTML();
210 210
                     }
211 211
 
212
-                    $this->template_args['registrations'][ $reg_url_link ]                = $registration;
213
-                    $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
214
-                        $this->template_args['ticket_count'][ $registration->ticket()->ID() ]
212
+                    $this->template_args['registrations'][$reg_url_link]                = $registration;
213
+                    $this->template_args['ticket_count'][$registration->ticket()->ID()] = isset(
214
+                        $this->template_args['ticket_count'][$registration->ticket()->ID()]
215 215
                     )
216
-                        ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
216
+                        ? $this->template_args['ticket_count'][$registration->ticket()->ID()] + 1
217 217
                         : 1;
218 218
                     $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
219 219
                         $this->reg_step->checkout->cart->get_grand_total(),
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
                     $ticket_line_item = is_array($ticket_line_item)
224 224
                         ? reset($ticket_line_item)
225 225
                         : $ticket_line_item;
226
-                    $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
226
+                    $this->template_args['ticket_line_item'][$registration->ticket()->ID()] =
227 227
                         $Line_Item_Display->display_line_item($ticket_line_item);
228 228
                     if ($registration->is_primary_registrant()) {
229 229
                         $primary_registrant = $reg_url_link;
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 
234 234
             if ($primary_registrant && count($registrations) > 1) {
235 235
                 if (
236
-                    isset($subsections[ $primary_registrant ])
237
-                    && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
236
+                    isset($subsections[$primary_registrant])
237
+                    && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper
238 238
                 ) {
239 239
                     $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info
240 240
                         ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug())
241 241
                         : new AutoCopyAttendeeInfoForm($this->reg_step->slug());
242
-                    $subsections[ $primary_registrant ]->add_subsections(
242
+                    $subsections[$primary_registrant]->add_subsections(
243 243
                         $copy_options,
244 244
                         'primary_registrant',
245 245
                         false
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
         // Set the registration form template (default: one form per ticket details table).
252 252
         // We decide the template to used based on the number of forms.
253 253
         $template = $this->reg_form_count > 1
254
-            ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php'
255
-            : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php';
254
+            ? SPCO_REG_STEPS_PATH . $this->reg_step->slug().'/attendee_info_main.template.php'
255
+            : SPCO_REG_STEPS_PATH.$this->reg_step->slug().'/attendee_info_single.template.php';
256 256
         $this->reg_step->setTemplate($template);
257 257
 
258 258
         return $subsections;
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
     private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section)
267 267
     {
268 268
         // if this isn't a revisit, and they have the privacy consent box enabled, add it
269
-        if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) {
269
+        if ( ! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) {
270 270
             $extra_inputs_section->add_subsections(
271 271
                 [
272 272
                     'consent_box' => new PrivacyConsentCheckboxForm(
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegFormQuestionFactory.php 1 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/RegistrantData.php 1 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.
core/domain/services/registration/form/v1/RegFormHandler.php 1 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/admin/events/editor/EventEditorGraphQLData.php 1 patch
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -21,147 +21,147 @@
 block discarded – undo
21 21
 class EventEditorGraphQLData
22 22
 {
23 23
 
24
-    /**
25
-     * @var Event
26
-     */
27
-    protected $event;
28
-
29
-    /**
30
-     * @var Datetimes
31
-     */
32
-    protected $datetimes;
33
-
34
-    /**
35
-     * @var Prices
36
-     */
37
-    protected $prices;
38
-
39
-    /**
40
-     * @var PriceTypes
41
-     */
42
-    protected $price_types;
43
-
44
-    /**
45
-     * @var Tickets
46
-     */
47
-    protected $tickets;
48
-
49
-    /**
50
-     * @var EventEntityRelations
51
-     */
52
-    protected $relations;
53
-
54
-    /**
55
-     * @var EventManagerData
56
-     */
57
-    protected $managers;
58
-
59
-    /**
60
-     * @var NewEventDefaultEntities
61
-     */
62
-    protected $default_entities;
63
-
64
-    /**
65
-     * @var TicketMeta
66
-     */
67
-    protected $ticket_meta;
68
-
69
-    /**
70
-     * @var FormBuilder
71
-     */
72
-    protected $form_builder;
73
-
74
-
75
-    /**
76
-     * EventEditorGraphQLData constructor.
77
-     *
78
-     * @param Datetimes               $datetimes
79
-     * @param Event                   $event
80
-     * @param Prices                  $prices
81
-     * @param PriceTypes              $price_types
82
-     * @param Tickets                 $tickets
83
-     * @param EventEntityRelations    $relations
84
-     * @param EventManagerData        $managers
85
-     * @param NewEventDefaultEntities $default_entities
86
-     * @param TicketMeta              $ticket_meta
87
-     * @param FormBuilder             $form_builder
88
-     */
89
-    public function __construct(
90
-        Datetimes $datetimes,
91
-        Event $event,
92
-        Prices $prices,
93
-        PriceTypes $price_types,
94
-        Tickets $tickets,
95
-        EventEntityRelations $relations,
96
-        EventManagerData $managers,
97
-        NewEventDefaultEntities $default_entities,
98
-        TicketMeta $ticket_meta,
99
-        FormBuilder $form_builder
100
-    ) {
101
-        $this->datetimes        = $datetimes;
102
-        $this->event            = $event;
103
-        $this->default_entities = $default_entities;
104
-        $this->prices           = $prices;
105
-        $this->price_types      = $price_types;
106
-        $this->managers         = $managers;
107
-        $this->relations        = $relations;
108
-        $this->tickets          = $tickets;
109
-        $this->ticket_meta      = $ticket_meta;
110
-        $this->form_builder     = $form_builder;
111
-    }
112
-
113
-
114
-    /**
115
-     * @param int $eventId
116
-     * @return array
117
-     * @throws EE_Error
118
-     * @throws ReflectionException
119
-     * @since $VID:$
120
-     */
121
-    public function getData(int $eventId)
122
-    {
123
-        $event = $this->event->getData(['id' => $eventId]);
124
-        $datetimes = $this->datetimes->getData(['eventId' => $eventId]);
125
-        $eventManagers = $this->managers ->getData($eventId);
126
-
127
-        // Avoid undefined variable warning in PHP >= 7.3
128
-        $tickets = null;
129
-        $prices  = null;
130
-
131
-        if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
132
-            $this->default_entities->getData($eventId);
133
-            $datetimes = $this->datetimes->getData(['eventId' => $eventId]);
134
-        }
135
-
136
-        $tickets = $this->tickets->getData([
137
-            'eventId'               => $eventId,
138
-            'includeDefaultTickets' => true,
139
-        ]);
140
-
141
-        $prices = $this->prices->getData([
142
-            'eventId'                     => $eventId,
143
-            'includeDefaultTicketsPrices' => true,
144
-            'includeDefaultPrices'        => true,
145
-        ]);
146
-
147
-        $priceTypes = $this->price_types->getData();
148
-
149
-        $relations = $this->relations->getData($eventId);
150
-
151
-        $ticketMeta = $this->ticket_meta->getData($eventId);
152
-
153
-        $formBuilder = $this->form_builder->getData($eventId);
154
-
155
-        return compact(
156
-            'datetimes',
157
-            'event',
158
-            'eventManagers',
159
-            'formBuilder',
160
-            'prices',
161
-            'priceTypes',
162
-            'relations',
163
-            'tickets',
164
-            'ticketMeta'
165
-        );
166
-    }
24
+	/**
25
+	 * @var Event
26
+	 */
27
+	protected $event;
28
+
29
+	/**
30
+	 * @var Datetimes
31
+	 */
32
+	protected $datetimes;
33
+
34
+	/**
35
+	 * @var Prices
36
+	 */
37
+	protected $prices;
38
+
39
+	/**
40
+	 * @var PriceTypes
41
+	 */
42
+	protected $price_types;
43
+
44
+	/**
45
+	 * @var Tickets
46
+	 */
47
+	protected $tickets;
48
+
49
+	/**
50
+	 * @var EventEntityRelations
51
+	 */
52
+	protected $relations;
53
+
54
+	/**
55
+	 * @var EventManagerData
56
+	 */
57
+	protected $managers;
58
+
59
+	/**
60
+	 * @var NewEventDefaultEntities
61
+	 */
62
+	protected $default_entities;
63
+
64
+	/**
65
+	 * @var TicketMeta
66
+	 */
67
+	protected $ticket_meta;
68
+
69
+	/**
70
+	 * @var FormBuilder
71
+	 */
72
+	protected $form_builder;
73
+
74
+
75
+	/**
76
+	 * EventEditorGraphQLData constructor.
77
+	 *
78
+	 * @param Datetimes               $datetimes
79
+	 * @param Event                   $event
80
+	 * @param Prices                  $prices
81
+	 * @param PriceTypes              $price_types
82
+	 * @param Tickets                 $tickets
83
+	 * @param EventEntityRelations    $relations
84
+	 * @param EventManagerData        $managers
85
+	 * @param NewEventDefaultEntities $default_entities
86
+	 * @param TicketMeta              $ticket_meta
87
+	 * @param FormBuilder             $form_builder
88
+	 */
89
+	public function __construct(
90
+		Datetimes $datetimes,
91
+		Event $event,
92
+		Prices $prices,
93
+		PriceTypes $price_types,
94
+		Tickets $tickets,
95
+		EventEntityRelations $relations,
96
+		EventManagerData $managers,
97
+		NewEventDefaultEntities $default_entities,
98
+		TicketMeta $ticket_meta,
99
+		FormBuilder $form_builder
100
+	) {
101
+		$this->datetimes        = $datetimes;
102
+		$this->event            = $event;
103
+		$this->default_entities = $default_entities;
104
+		$this->prices           = $prices;
105
+		$this->price_types      = $price_types;
106
+		$this->managers         = $managers;
107
+		$this->relations        = $relations;
108
+		$this->tickets          = $tickets;
109
+		$this->ticket_meta      = $ticket_meta;
110
+		$this->form_builder     = $form_builder;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @param int $eventId
116
+	 * @return array
117
+	 * @throws EE_Error
118
+	 * @throws ReflectionException
119
+	 * @since $VID:$
120
+	 */
121
+	public function getData(int $eventId)
122
+	{
123
+		$event = $this->event->getData(['id' => $eventId]);
124
+		$datetimes = $this->datetimes->getData(['eventId' => $eventId]);
125
+		$eventManagers = $this->managers ->getData($eventId);
126
+
127
+		// Avoid undefined variable warning in PHP >= 7.3
128
+		$tickets = null;
129
+		$prices  = null;
130
+
131
+		if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
132
+			$this->default_entities->getData($eventId);
133
+			$datetimes = $this->datetimes->getData(['eventId' => $eventId]);
134
+		}
135
+
136
+		$tickets = $this->tickets->getData([
137
+			'eventId'               => $eventId,
138
+			'includeDefaultTickets' => true,
139
+		]);
140
+
141
+		$prices = $this->prices->getData([
142
+			'eventId'                     => $eventId,
143
+			'includeDefaultTicketsPrices' => true,
144
+			'includeDefaultPrices'        => true,
145
+		]);
146
+
147
+		$priceTypes = $this->price_types->getData();
148
+
149
+		$relations = $this->relations->getData($eventId);
150
+
151
+		$ticketMeta = $this->ticket_meta->getData($eventId);
152
+
153
+		$formBuilder = $this->form_builder->getData($eventId);
154
+
155
+		return compact(
156
+			'datetimes',
157
+			'event',
158
+			'eventManagers',
159
+			'formBuilder',
160
+			'prices',
161
+			'priceTypes',
162
+			'relations',
163
+			'tickets',
164
+			'ticketMeta'
165
+		);
166
+	}
167 167
 }
Please login to merge, or discard this patch.
core/domain/services/admin/events/editor/FormBuilder.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -21,65 +21,65 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * @param int $eventId
26
-     * @return array
27
-     */
28
-    public function getData(int $eventId): array
29
-    {
30
-        /** @var EE_Event */
31
-        $event = EEM_Event::instance()->get_one_by_ID($eventId);
32
-        /** @var EE_Form_Section[] */
33
-        $form_sections = $event->registrationForm();
24
+	/**
25
+	 * @param int $eventId
26
+	 * @return array
27
+	 */
28
+	public function getData(int $eventId): array
29
+	{
30
+		/** @var EE_Event */
31
+		$event = EEM_Event::instance()->get_one_by_ID($eventId);
32
+		/** @var EE_Form_Section[] */
33
+		$form_sections = $event->registrationForm();
34 34
 
35
-        $sections = [];
36
-        foreach ($form_sections as $section) {
37
-            $UUID = $section->UUID();
35
+		$sections = [];
36
+		foreach ($form_sections as $section) {
37
+			$UUID = $section->UUID();
38 38
 
39
-            // Avoid duplicates, if any
40
-            $sections[ $UUID ] = [
41
-                'id'         => $UUID,
42
-                'appliesTo'  => GQLUtils::formatEnumKey($section->appliesTo()),
43
-                'attributes' => $section->attributes()->toJson(),
44
-                'belongsTo'  => $section->belongsTo(),
45
-                'label'      => $section->label()->toJson(),
46
-                'order'      => $section->order(),
47
-                'status'     => GQLUtils::formatEnumKey($section->status()),
48
-            ];
49
-        }
39
+			// Avoid duplicates, if any
40
+			$sections[ $UUID ] = [
41
+				'id'         => $UUID,
42
+				'appliesTo'  => GQLUtils::formatEnumKey($section->appliesTo()),
43
+				'attributes' => $section->attributes()->toJson(),
44
+				'belongsTo'  => $section->belongsTo(),
45
+				'label'      => $section->label()->toJson(),
46
+				'order'      => $section->order(),
47
+				'status'     => GQLUtils::formatEnumKey($section->status()),
48
+			];
49
+		}
50 50
 
51
-        /** @var EE_Form_Element[] */
52
-        $form_elements = EEM_Form_Element::instance()->get_all([
53
-            [
54
-                'FSC_UUID' => ['IN', array_keys($sections)]
55
-            ]
56
-        ]);
51
+		/** @var EE_Form_Element[] */
52
+		$form_elements = EEM_Form_Element::instance()->get_all([
53
+			[
54
+				'FSC_UUID' => ['IN', array_keys($sections)]
55
+			]
56
+		]);
57 57
 
58
-        $elements = [];
59
-        foreach ($form_elements as $element) {
60
-            $UUID = $element->UUID();
58
+		$elements = [];
59
+		foreach ($form_elements as $element) {
60
+			$UUID = $element->UUID();
61 61
 
62
-            // Avoid duplicates
63
-            $elements[ $UUID ] = [
64
-                'id'         => $UUID,
65
-                'adminOnly'  => $element->adminOnly(),
66
-                'attributes' => $element->attributes()->toJson(),
67
-                'belongsTo'  => $element->belongsTo(),
68
-                'helpText'   => $element->helpText()->toJson(),
69
-                'label'      => $element->label()->toJson(),
70
-                'mapsTo'     => $element->mapsTo(),
71
-                'options'    => $element->options()->toJson(),
72
-                'order'      => $element->order(),
73
-                'required'   => $element->required()->toJson(),
74
-                'status'     => GQLUtils::formatEnumKey($element->status()),
75
-                'type'       => GQLUtils::formatEnumKey($element->type()),
76
-            ];
77
-        }
62
+			// Avoid duplicates
63
+			$elements[ $UUID ] = [
64
+				'id'         => $UUID,
65
+				'adminOnly'  => $element->adminOnly(),
66
+				'attributes' => $element->attributes()->toJson(),
67
+				'belongsTo'  => $element->belongsTo(),
68
+				'helpText'   => $element->helpText()->toJson(),
69
+				'label'      => $element->label()->toJson(),
70
+				'mapsTo'     => $element->mapsTo(),
71
+				'options'    => $element->options()->toJson(),
72
+				'order'      => $element->order(),
73
+				'required'   => $element->required()->toJson(),
74
+				'status'     => GQLUtils::formatEnumKey($element->status()),
75
+				'type'       => GQLUtils::formatEnumKey($element->type()),
76
+			];
77
+		}
78 78
 
79
-        return [
80
-            'elements'          => array_values($elements),
81
-            'sections'          => array_values($sections),
82
-            'topLevelSectionId' => $event->registrationFormUuid()
83
-        ];
84
-    }
79
+		return [
80
+			'elements'          => array_values($elements),
81
+			'sections'          => array_values($sections),
82
+			'topLevelSectionId' => $event->registrationFormUuid()
83
+		];
84
+	}
85 85
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
             $UUID = $section->UUID();
38 38
 
39 39
             // Avoid duplicates, if any
40
-            $sections[ $UUID ] = [
40
+            $sections[$UUID] = [
41 41
                 'id'         => $UUID,
42 42
                 'appliesTo'  => GQLUtils::formatEnumKey($section->appliesTo()),
43 43
                 'attributes' => $section->attributes()->toJson(),
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $UUID = $element->UUID();
61 61
 
62 62
             // Avoid duplicates
63
-            $elements[ $UUID ] = [
63
+            $elements[$UUID] = [
64 64
                 'id'         => $UUID,
65 65
                 'adminOnly'  => $element->adminOnly(),
66 66
                 'attributes' => $element->attributes()->toJson(),
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/EntityMutator.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -22,168 +22,168 @@
 block discarded – undo
22 22
 abstract class EntityMutator
23 23
 {
24 24
 
25
-    /**
26
-     * @param EEM_Base $model
27
-     * @param integer  $ID
28
-     * @param string   $capability
29
-     * @return EE_Base_Class
30
-     * @throws OutOfBoundsException
31
-     * @throws UserError
32
-     * @throws EE_Error
33
-     */
34
-    protected static function getEntityFromID(
35
-        EEM_Base $model,
36
-        int $ID,
37
-        string $capability = 'ee_edit_events'
38
-    ): EE_Base_Class {
39
-        EntityMutator::checkPermissions($model, $capability);
40
-        return EntityMutator::getEntity($model, $ID);
41
-    }
42
-
43
-
44
-    /**
45
-     * @param EEM_Base $model
46
-     * @param array    $input
47
-     * @param string   $capability
48
-     * @return EE_Base_Class
49
-     * @throws OutOfBoundsException
50
-     * @throws UserError
51
-     * @throws EE_Error
52
-     */
53
-    protected static function getEntityFromInputData(
54
-        EEM_Base $model,
55
-        array $input,
56
-        string $capability = 'ee_edit_events'
57
-    ): EE_Base_Class {
58
-        EntityMutator::checkPermissions($model, $capability);
59
-
60
-        $primaryKey = $model->get_primary_key_field()->get_name();
61
-        // e.g. "FSC_UUID" will give us "FSC"
62
-        [$keyPrefix] = explode('_', $primaryKey);
63
-        $uuid_field  = $keyPrefix . '_UUID'; // e.g. "FSC_UUID"
64
-
65
-        // If the model has UUID field, then we will use that in place of ID.
66
-        $ID = $model->has_field($uuid_field) ? $input['id'] : EntityMutator::getEntityIDFromGlobalId($model, $input);
67
-        return EntityMutator::getEntity($model, $ID);
68
-    }
69
-
70
-
71
-    /**
72
-     * @param EEM_Base $model
73
-     * @param string   $capability
74
-     * @throws UserError
75
-     */
76
-    protected static function checkPermissions(EEM_Base $model, string $capability = 'ee_edit_events')
77
-    {
78
-        /**
79
-         * Stop now if a user isn't allowed to execute mutation
80
-         */
81
-        if (! current_user_can($capability)) {
82
-            $model_name = $model->get_this_model_name();
83
-            $message    = sprintf(
84
-                esc_html_x(
85
-                    'We\'re sorry but you do not have the required permissions to execute %1$s mutations!',
86
-                    'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!',
87
-                    'event_espresso'
88
-                ),
89
-                strtolower($model_name)
90
-            );
91
-            throw new UserError($message);
92
-        }
93
-    }
94
-
95
-
96
-    /**
97
-     * @param EEM_Base $model
98
-     * @param array    $input
99
-     * @return int
100
-     * @throws OutOfBoundsException
101
-     */
102
-    protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input): int
103
-    {
104
-        $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null;
105
-        $id       = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0;
106
-        if ($id > 0) {
107
-            return $id;
108
-        }
109
-        // no ID? throw an exception
110
-        $model_name = $model->get_this_model_name();
111
-        throw new OutOfBoundsException(
112
-            sprintf(
113
-                esc_html_x(
114
-                    'A missing or invalid %1$s ID was received.',
115
-                    'A missing or invalid entity(datetime/ticket/etc) ID was received.',
116
-                    'event_espresso'
117
-                ),
118
-                strtolower($model_name)
119
-            )
120
-        );
121
-    }
122
-
123
-
124
-    /**
125
-     * @param EEM_Base   $model
126
-     * @param int|string $ID
127
-     * @return EE_Base_Class
128
-     * @throws OutOfBoundsException
129
-     * @throws EE_Error
130
-     */
131
-    protected static function getEntity(EEM_Base $model, $ID = 0): EE_Base_Class
132
-    {
133
-        $entity = $model->get_one_by_ID($ID);
134
-        $model_name = $model->get_this_model_name();
135
-        $class_name = 'EE_' . $model_name;
136
-        if ($entity instanceof $class_name) {
137
-            return $entity;
138
-        }
139
-        // OOPS!!! invalid entity
140
-        throw new OutOfBoundsException(
141
-            sprintf(
142
-                esc_html_x(
143
-                    'A valid %1$s could not be retrieved from the database.',
144
-                    'A valid entity(datetime/ticket/etc) could not be found in the database.',
145
-                    'event_espresso'
146
-                ),
147
-                strtolower($model_name)
148
-            )
149
-        );
150
-    }
151
-
152
-
153
-    /**
154
-     * @param        $results
155
-     * @param string $message
156
-     * @throws RuntimeException
157
-     */
158
-    protected static function validateResults($results, string $message = '')
159
-    {
160
-        if (empty($results)) {
161
-            $message = $message !== ''
162
-                ? $message
163
-                : esc_html__(
164
-                    'An unknown error occurred. Please check your server\'s error  logs for more information',
165
-                    'event_espresso'
166
-                );
167
-            throw new RuntimeException($message);
168
-        }
169
-    }
170
-
171
-
172
-    /**
173
-     * @param Exception $exception
174
-     * @param string    $message_prefix
175
-     * @throws RuntimeException
176
-     */
177
-    protected static function handleExceptions(Exception $exception, string $message_prefix = '')
178
-    {
179
-        $message_prefix = $message_prefix !== ''
180
-            ? $message_prefix
181
-            : esc_html__(
182
-                'The mutation could not be executed because of the following error(s)',
183
-                'event_espresso'
184
-            );
185
-        throw new RuntimeException(
186
-            sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage())
187
-        );
188
-    }
25
+	/**
26
+	 * @param EEM_Base $model
27
+	 * @param integer  $ID
28
+	 * @param string   $capability
29
+	 * @return EE_Base_Class
30
+	 * @throws OutOfBoundsException
31
+	 * @throws UserError
32
+	 * @throws EE_Error
33
+	 */
34
+	protected static function getEntityFromID(
35
+		EEM_Base $model,
36
+		int $ID,
37
+		string $capability = 'ee_edit_events'
38
+	): EE_Base_Class {
39
+		EntityMutator::checkPermissions($model, $capability);
40
+		return EntityMutator::getEntity($model, $ID);
41
+	}
42
+
43
+
44
+	/**
45
+	 * @param EEM_Base $model
46
+	 * @param array    $input
47
+	 * @param string   $capability
48
+	 * @return EE_Base_Class
49
+	 * @throws OutOfBoundsException
50
+	 * @throws UserError
51
+	 * @throws EE_Error
52
+	 */
53
+	protected static function getEntityFromInputData(
54
+		EEM_Base $model,
55
+		array $input,
56
+		string $capability = 'ee_edit_events'
57
+	): EE_Base_Class {
58
+		EntityMutator::checkPermissions($model, $capability);
59
+
60
+		$primaryKey = $model->get_primary_key_field()->get_name();
61
+		// e.g. "FSC_UUID" will give us "FSC"
62
+		[$keyPrefix] = explode('_', $primaryKey);
63
+		$uuid_field  = $keyPrefix . '_UUID'; // e.g. "FSC_UUID"
64
+
65
+		// If the model has UUID field, then we will use that in place of ID.
66
+		$ID = $model->has_field($uuid_field) ? $input['id'] : EntityMutator::getEntityIDFromGlobalId($model, $input);
67
+		return EntityMutator::getEntity($model, $ID);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @param EEM_Base $model
73
+	 * @param string   $capability
74
+	 * @throws UserError
75
+	 */
76
+	protected static function checkPermissions(EEM_Base $model, string $capability = 'ee_edit_events')
77
+	{
78
+		/**
79
+		 * Stop now if a user isn't allowed to execute mutation
80
+		 */
81
+		if (! current_user_can($capability)) {
82
+			$model_name = $model->get_this_model_name();
83
+			$message    = sprintf(
84
+				esc_html_x(
85
+					'We\'re sorry but you do not have the required permissions to execute %1$s mutations!',
86
+					'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!',
87
+					'event_espresso'
88
+				),
89
+				strtolower($model_name)
90
+			);
91
+			throw new UserError($message);
92
+		}
93
+	}
94
+
95
+
96
+	/**
97
+	 * @param EEM_Base $model
98
+	 * @param array    $input
99
+	 * @return int
100
+	 * @throws OutOfBoundsException
101
+	 */
102
+	protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input): int
103
+	{
104
+		$id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null;
105
+		$id       = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0;
106
+		if ($id > 0) {
107
+			return $id;
108
+		}
109
+		// no ID? throw an exception
110
+		$model_name = $model->get_this_model_name();
111
+		throw new OutOfBoundsException(
112
+			sprintf(
113
+				esc_html_x(
114
+					'A missing or invalid %1$s ID was received.',
115
+					'A missing or invalid entity(datetime/ticket/etc) ID was received.',
116
+					'event_espresso'
117
+				),
118
+				strtolower($model_name)
119
+			)
120
+		);
121
+	}
122
+
123
+
124
+	/**
125
+	 * @param EEM_Base   $model
126
+	 * @param int|string $ID
127
+	 * @return EE_Base_Class
128
+	 * @throws OutOfBoundsException
129
+	 * @throws EE_Error
130
+	 */
131
+	protected static function getEntity(EEM_Base $model, $ID = 0): EE_Base_Class
132
+	{
133
+		$entity = $model->get_one_by_ID($ID);
134
+		$model_name = $model->get_this_model_name();
135
+		$class_name = 'EE_' . $model_name;
136
+		if ($entity instanceof $class_name) {
137
+			return $entity;
138
+		}
139
+		// OOPS!!! invalid entity
140
+		throw new OutOfBoundsException(
141
+			sprintf(
142
+				esc_html_x(
143
+					'A valid %1$s could not be retrieved from the database.',
144
+					'A valid entity(datetime/ticket/etc) could not be found in the database.',
145
+					'event_espresso'
146
+				),
147
+				strtolower($model_name)
148
+			)
149
+		);
150
+	}
151
+
152
+
153
+	/**
154
+	 * @param        $results
155
+	 * @param string $message
156
+	 * @throws RuntimeException
157
+	 */
158
+	protected static function validateResults($results, string $message = '')
159
+	{
160
+		if (empty($results)) {
161
+			$message = $message !== ''
162
+				? $message
163
+				: esc_html__(
164
+					'An unknown error occurred. Please check your server\'s error  logs for more information',
165
+					'event_espresso'
166
+				);
167
+			throw new RuntimeException($message);
168
+		}
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param Exception $exception
174
+	 * @param string    $message_prefix
175
+	 * @throws RuntimeException
176
+	 */
177
+	protected static function handleExceptions(Exception $exception, string $message_prefix = '')
178
+	{
179
+		$message_prefix = $message_prefix !== ''
180
+			? $message_prefix
181
+			: esc_html__(
182
+				'The mutation could not be executed because of the following error(s)',
183
+				'event_espresso'
184
+			);
185
+		throw new RuntimeException(
186
+			sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage())
187
+		);
188
+	}
189 189
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/admin/EspressoEventEditor.php 1 patch
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -18,145 +18,145 @@
 block discarded – undo
18 18
 class EspressoEventEditor extends EspressoEventsAdmin
19 19
 {
20 20
 
21
-    /**
22
-     * returns true if the current request matches this route
23
-     *
24
-     * @return bool
25
-     * @since   $VID:$
26
-     */
27
-    public function matchesCurrentRequest(): bool
28
-    {
29
-        return parent::matchesCurrentRequest()
30
-               && $this->admin_config->useAdvancedEditor()
31
-               && (
32
-                   $this->request->getRequestParam('action') === 'create_new'
33
-                || $this->request->getRequestParam('action') === 'edit'
34
-               );
35
-    }
21
+	/**
22
+	 * returns true if the current request matches this route
23
+	 *
24
+	 * @return bool
25
+	 * @since   $VID:$
26
+	 */
27
+	public function matchesCurrentRequest(): bool
28
+	{
29
+		return parent::matchesCurrentRequest()
30
+			   && $this->admin_config->useAdvancedEditor()
31
+			   && (
32
+				   $this->request->getRequestParam('action') === 'create_new'
33
+				|| $this->request->getRequestParam('action') === 'edit'
34
+			   );
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * @since $VID:$
40
-     */
41
-    protected function registerDependencies()
42
-    {
43
-        $this->dependency_map->registerDependencies(
44
-            'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData',
45
-            [
46
-                'EventEspresso\core\domain\entities\admin\GraphQLData\Datetimes'                 => EE_Dependency_Map::load_from_cache,
47
-                'EventEspresso\core\domain\entities\admin\GraphQLData\Event'                     => EE_Dependency_Map::load_from_cache,
48
-                'EventEspresso\core\domain\entities\admin\GraphQLData\Prices'                    => EE_Dependency_Map::load_from_cache,
49
-                'EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes'                => EE_Dependency_Map::load_from_cache,
50
-                'EventEspresso\core\domain\entities\admin\GraphQLData\Tickets'                   => EE_Dependency_Map::load_from_cache,
51
-                'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities' => EE_Dependency_Map::load_from_cache,
52
-                '\EventEspresso\core\domain\services\admin\events\editor\EventManagerData'       => EE_Dependency_Map::load_from_cache,
53
-                'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations'    => EE_Dependency_Map::load_from_cache,
54
-                'EventEspresso\core\domain\services\admin\events\editor\TicketMeta'              => EE_Dependency_Map::load_from_cache,
55
-                'EventEspresso\core\domain\services\admin\events\editor\FormBuilder'             => EE_Dependency_Map::load_from_cache,
56
-            ]
57
-        );
58
-        $this->dependency_map->registerDependencies(
59
-            'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations',
60
-            [
61
-                'EEM_Datetime'                                         => EE_Dependency_Map::load_from_cache,
62
-                'EEM_Event'                                            => EE_Dependency_Map::load_from_cache,
63
-                'EEM_Price'                                            => EE_Dependency_Map::load_from_cache,
64
-                'EEM_Price_Type'                                       => EE_Dependency_Map::load_from_cache,
65
-                'EEM_Ticket'                                           => EE_Dependency_Map::load_from_cache,
66
-                'EventEspresso\core\domain\services\graphql\Utilities' => EE_Dependency_Map::load_from_cache,
67
-            ]
68
-        );
69
-        $this->dependency_map->registerDependencies(
70
-            'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities',
71
-            [
72
-                'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes' => EE_Dependency_Map::load_from_cache,
73
-                'EEM_Datetime'                                                       => EE_Dependency_Map::load_from_cache,
74
-                'EEM_Event'                                                          => EE_Dependency_Map::load_from_cache,
75
-                'EEM_Price'                                                          => EE_Dependency_Map::load_from_cache,
76
-                'EEM_Price_Type'                                                     => EE_Dependency_Map::load_from_cache,
77
-                'EEM_Ticket'                                                         => EE_Dependency_Map::load_from_cache,
78
-                'EventEspresso\core\domain\services\graphql\Utilities'               => EE_Dependency_Map::load_from_cache,
79
-            ]
80
-        );
81
-        $this->dependency_map->registerDependencies(
82
-            'EventEspresso\core\domain\services\admin\events\editor\TicketMeta',
83
-            ['EEM_Ticket' => EE_Dependency_Map::load_from_cache]
84
-        );
85
-        $this->dependency_map->registerDependencies(
86
-            'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes',
87
-            [
88
-                'EventEspresso\core\domain\services\admin\entities\DefaultTickets' => EE_Dependency_Map::load_from_cache,
89
-                'EEM_Datetime'                                                     => EE_Dependency_Map::load_from_cache,
90
-            ]
91
-        );
92
-        $this->dependency_map->registerDependencies(
93
-            'EventEspresso\core\domain\services\admin\entities\DefaultTickets',
94
-            [
95
-                'EventEspresso\core\domain\services\admin\entities\DefaultPrices' => EE_Dependency_Map::load_from_cache,
96
-                'EEM_Ticket'                                                      => EE_Dependency_Map::load_from_cache,
97
-            ]
98
-        );
99
-        $this->dependency_map->registerDependencies(
100
-            'EventEspresso\core\domain\services\admin\entities\DefaultPrices',
101
-            [
102
-                'EEM_Price'      => EE_Dependency_Map::load_from_cache,
103
-                'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
104
-            ]
105
-        );
106
-        $this->dependency_map->registerDependencies(
107
-            'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor',
108
-            [
109
-                'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData' => EE_Dependency_Map::load_from_cache,
110
-                'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
111
-            ]
112
-        );
113
-        $this->dependency_map->registerDependencies(
114
-            'EventEspresso\core\domain\services\assets\EventEditorAssetManager',
115
-            [
116
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
117
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
118
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
119
-            ]
120
-        );
121
-        $this->dependency_map->registerDependencies(
122
-            'EventEspresso\core\domain\services\admin\events\editor\EventManagerData',
123
-            [
124
-                'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache,
125
-                'EventEspresso\core\domain\services\graphql\Utilities'   => EE_Dependency_Map::load_from_cache,
126
-            ]
127
-        );
128
-    }
38
+	/**
39
+	 * @since $VID:$
40
+	 */
41
+	protected function registerDependencies()
42
+	{
43
+		$this->dependency_map->registerDependencies(
44
+			'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData',
45
+			[
46
+				'EventEspresso\core\domain\entities\admin\GraphQLData\Datetimes'                 => EE_Dependency_Map::load_from_cache,
47
+				'EventEspresso\core\domain\entities\admin\GraphQLData\Event'                     => EE_Dependency_Map::load_from_cache,
48
+				'EventEspresso\core\domain\entities\admin\GraphQLData\Prices'                    => EE_Dependency_Map::load_from_cache,
49
+				'EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes'                => EE_Dependency_Map::load_from_cache,
50
+				'EventEspresso\core\domain\entities\admin\GraphQLData\Tickets'                   => EE_Dependency_Map::load_from_cache,
51
+				'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities' => EE_Dependency_Map::load_from_cache,
52
+				'\EventEspresso\core\domain\services\admin\events\editor\EventManagerData'       => EE_Dependency_Map::load_from_cache,
53
+				'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations'    => EE_Dependency_Map::load_from_cache,
54
+				'EventEspresso\core\domain\services\admin\events\editor\TicketMeta'              => EE_Dependency_Map::load_from_cache,
55
+				'EventEspresso\core\domain\services\admin\events\editor\FormBuilder'             => EE_Dependency_Map::load_from_cache,
56
+			]
57
+		);
58
+		$this->dependency_map->registerDependencies(
59
+			'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations',
60
+			[
61
+				'EEM_Datetime'                                         => EE_Dependency_Map::load_from_cache,
62
+				'EEM_Event'                                            => EE_Dependency_Map::load_from_cache,
63
+				'EEM_Price'                                            => EE_Dependency_Map::load_from_cache,
64
+				'EEM_Price_Type'                                       => EE_Dependency_Map::load_from_cache,
65
+				'EEM_Ticket'                                           => EE_Dependency_Map::load_from_cache,
66
+				'EventEspresso\core\domain\services\graphql\Utilities' => EE_Dependency_Map::load_from_cache,
67
+			]
68
+		);
69
+		$this->dependency_map->registerDependencies(
70
+			'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities',
71
+			[
72
+				'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes' => EE_Dependency_Map::load_from_cache,
73
+				'EEM_Datetime'                                                       => EE_Dependency_Map::load_from_cache,
74
+				'EEM_Event'                                                          => EE_Dependency_Map::load_from_cache,
75
+				'EEM_Price'                                                          => EE_Dependency_Map::load_from_cache,
76
+				'EEM_Price_Type'                                                     => EE_Dependency_Map::load_from_cache,
77
+				'EEM_Ticket'                                                         => EE_Dependency_Map::load_from_cache,
78
+				'EventEspresso\core\domain\services\graphql\Utilities'               => EE_Dependency_Map::load_from_cache,
79
+			]
80
+		);
81
+		$this->dependency_map->registerDependencies(
82
+			'EventEspresso\core\domain\services\admin\events\editor\TicketMeta',
83
+			['EEM_Ticket' => EE_Dependency_Map::load_from_cache]
84
+		);
85
+		$this->dependency_map->registerDependencies(
86
+			'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes',
87
+			[
88
+				'EventEspresso\core\domain\services\admin\entities\DefaultTickets' => EE_Dependency_Map::load_from_cache,
89
+				'EEM_Datetime'                                                     => EE_Dependency_Map::load_from_cache,
90
+			]
91
+		);
92
+		$this->dependency_map->registerDependencies(
93
+			'EventEspresso\core\domain\services\admin\entities\DefaultTickets',
94
+			[
95
+				'EventEspresso\core\domain\services\admin\entities\DefaultPrices' => EE_Dependency_Map::load_from_cache,
96
+				'EEM_Ticket'                                                      => EE_Dependency_Map::load_from_cache,
97
+			]
98
+		);
99
+		$this->dependency_map->registerDependencies(
100
+			'EventEspresso\core\domain\services\admin\entities\DefaultPrices',
101
+			[
102
+				'EEM_Price'      => EE_Dependency_Map::load_from_cache,
103
+				'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
104
+			]
105
+		);
106
+		$this->dependency_map->registerDependencies(
107
+			'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor',
108
+			[
109
+				'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData' => EE_Dependency_Map::load_from_cache,
110
+				'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
111
+			]
112
+		);
113
+		$this->dependency_map->registerDependencies(
114
+			'EventEspresso\core\domain\services\assets\EventEditorAssetManager',
115
+			[
116
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
117
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
118
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
119
+			]
120
+		);
121
+		$this->dependency_map->registerDependencies(
122
+			'EventEspresso\core\domain\services\admin\events\editor\EventManagerData',
123
+			[
124
+				'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache,
125
+				'EventEspresso\core\domain\services\graphql\Utilities'   => EE_Dependency_Map::load_from_cache,
126
+			]
127
+		);
128
+	}
129 129
 
130 130
 
131
-    /**
132
-     * @return string
133
-     */
134
-    protected function dataNodeClass(): string
135
-    {
136
-        return EventEditor::class;
137
-    }
131
+	/**
132
+	 * @return string
133
+	 */
134
+	protected function dataNodeClass(): string
135
+	{
136
+		return EventEditor::class;
137
+	}
138 138
 
139 139
 
140
-    /**
141
-     * implements logic required to run during request
142
-     *
143
-     * @return bool
144
-     * @since   $VID:$
145
-     */
146
-    protected function requestHandler(): bool
147
-    {
148
-        if (! class_exists('WPGraphQL')) {
149
-            require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
150
-        }
151
-        /** @var GraphQLManager $graphQL_manager */
152
-        $graphQL_manager = $this->loader->getShared('EventEspresso\core\services\graphql\GraphQLManager');
153
-        $graphQL_manager->init();
140
+	/**
141
+	 * implements logic required to run during request
142
+	 *
143
+	 * @return bool
144
+	 * @since   $VID:$
145
+	 */
146
+	protected function requestHandler(): bool
147
+	{
148
+		if (! class_exists('WPGraphQL')) {
149
+			require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
150
+		}
151
+		/** @var GraphQLManager $graphQL_manager */
152
+		$graphQL_manager = $this->loader->getShared('EventEspresso\core\services\graphql\GraphQLManager');
153
+		$graphQL_manager->init();
154 154
 
155
-        /** @var EventEditorAssetManager $asset_manager */
156
-        $asset_manager = $this->loader->getShared(
157
-            'EventEspresso\core\domain\services\assets\EventEditorAssetManager'
158
-        );
159
-        add_action('admin_enqueue_scripts', [$asset_manager, 'enqueueEventEditor']);
160
-        return true;
161
-    }
155
+		/** @var EventEditorAssetManager $asset_manager */
156
+		$asset_manager = $this->loader->getShared(
157
+			'EventEspresso\core\domain\services\assets\EventEditorAssetManager'
158
+		);
159
+		add_action('admin_enqueue_scripts', [$asset_manager, 'enqueueEventEditor']);
160
+		return true;
161
+	}
162 162
 }
Please login to merge, or discard this patch.