@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function attributes(): ?Attributes |
139 | 139 | { |
140 | - if (! $this->attributes instanceof Attributes) { |
|
140 | + if ( ! $this->attributes instanceof Attributes) { |
|
141 | 141 | $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
142 | 142 | } |
143 | 143 | return $this->attributes; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function helpText(): ?HelpText |
193 | 193 | { |
194 | - if (! $this->helpText instanceof HelpText) { |
|
194 | + if ( ! $this->helpText instanceof HelpText) { |
|
195 | 195 | $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
196 | 196 | } |
197 | 197 | return $this->helpText; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public function label(): ?FormLabel |
223 | 223 | { |
224 | - if (! $this->label instanceof FormLabel) { |
|
224 | + if ( ! $this->label instanceof FormLabel) { |
|
225 | 225 | $this->label = FormLabel::fromJson($this->get('FIN_label')); |
226 | 226 | } |
227 | 227 | return $this->label; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | public function setMapsTo(string $model, string $field) |
265 | 265 | { |
266 | 266 | $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
267 | - if (! class_exists($model_name)) { |
|
267 | + if ( ! class_exists($model_name)) { |
|
268 | 268 | throw new DomainException( |
269 | 269 | sprintf( |
270 | 270 | esc_html__( |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public function options(): ?InputOptions |
290 | 290 | { |
291 | - if (! $this->options instanceof InputOptions) { |
|
291 | + if ( ! $this->options instanceof InputOptions) { |
|
292 | 292 | $this->options = InputOptions::fromJson($this->get('FIN_options')); |
293 | 293 | } |
294 | 294 | return $this->options; |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public function required(): ?Required |
369 | 369 | { |
370 | - if (! $this->required instanceof Required) { |
|
370 | + if ( ! $this->required instanceof Required) { |
|
371 | 371 | $this->required = Required::fromJson($this->get('FIN_required')); |
372 | 372 | } |
373 | 373 | return $this->required; |
@@ -28,471 +28,471 @@ |
||
28 | 28 | */ |
29 | 29 | class EE_Form_Element extends EE_Base_Class |
30 | 30 | { |
31 | - /** |
|
32 | - * @var Attributes |
|
33 | - */ |
|
34 | - private $attributes; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var FormLabel |
|
38 | - */ |
|
39 | - private $label; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var HelpText |
|
43 | - */ |
|
44 | - private $helpText; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var InputOptions |
|
48 | - */ |
|
49 | - private $options; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var Required |
|
53 | - */ |
|
54 | - private $required; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param array $props_n_values |
|
59 | - * @return EE_Form_Element |
|
60 | - * @throws EE_Error |
|
61 | - * @throws ReflectionException |
|
62 | - */ |
|
63 | - public static function new_instance(array $props_n_values = []): EE_Form_Element |
|
64 | - { |
|
65 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
66 | - return $has_object ?: new self($props_n_values); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @param array $props_n_values |
|
72 | - * @return EE_Form_Element |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Element |
|
77 | - { |
|
78 | - return new self($props_n_values); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Form Element UUID (universally unique identifier) |
|
84 | - * |
|
85 | - * @return string |
|
86 | - * @throws EE_Error |
|
87 | - * @throws ReflectionException |
|
88 | - */ |
|
89 | - public function UUID(): string |
|
90 | - { |
|
91 | - return $this->get('FIN_UUID'); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param string $UUID |
|
97 | - * @throws EE_Error |
|
98 | - * @throws ReflectionException |
|
99 | - */ |
|
100 | - public function setUUID(string $UUID) |
|
101 | - { |
|
102 | - $this->set('FIN_UUID', $UUID); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
108 | - * |
|
109 | - * @return bool |
|
110 | - * @throws EE_Error |
|
111 | - * @throws ReflectionException |
|
112 | - */ |
|
113 | - public function adminOnly(): ?bool |
|
114 | - { |
|
115 | - return $this->get('FIN_adminOnly'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param bool $admin_only |
|
121 | - * @throws EE_Error |
|
122 | - * @throws ReflectionException |
|
123 | - */ |
|
124 | - public function setAdminOnly(bool $admin_only) |
|
125 | - { |
|
126 | - $this->set('FIN_adminOnly', $admin_only); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * JSON string of HTML attributes such as class, max, min, placeholder, type, etc. |
|
132 | - * |
|
133 | - * @return Attributes |
|
134 | - * @throws EE_Error |
|
135 | - * @throws ReflectionException |
|
136 | - */ |
|
137 | - public function attributes(): ?Attributes |
|
138 | - { |
|
139 | - if (! $this->attributes instanceof Attributes) { |
|
140 | - $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
|
141 | - } |
|
142 | - return $this->attributes; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @param Attributes $attributes |
|
148 | - * @throws EE_Error |
|
149 | - * @throws ReflectionException |
|
150 | - */ |
|
151 | - public function setAttributes(Attributes $attributes) |
|
152 | - { |
|
153 | - // set local object |
|
154 | - $this->attributes = $attributes; |
|
155 | - // then pass to model as an array which will get converted to JSON by the model field |
|
156 | - $this->set('FIN_attributes', $attributes->toArray()); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * UUID of parent form section this form input belongs to. |
|
162 | - * |
|
163 | - * @return string |
|
164 | - * @throws EE_Error |
|
165 | - * @throws ReflectionException |
|
166 | - */ |
|
167 | - public function belongsTo(): string |
|
168 | - { |
|
169 | - return $this->get('FSC_UUID'); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @param string $relation_UUID |
|
175 | - * @throws EE_Error |
|
176 | - * @throws ReflectionException |
|
177 | - */ |
|
178 | - public function setBelongsTo(string $relation_UUID) |
|
179 | - { |
|
180 | - $this->set('FSC_UUID', $relation_UUID); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * returns a HelpText object for managing input help text |
|
186 | - * |
|
187 | - * @return HelpText |
|
188 | - * @throws EE_Error |
|
189 | - * @throws ReflectionException |
|
190 | - */ |
|
191 | - public function helpText(): ?HelpText |
|
192 | - { |
|
193 | - if (! $this->helpText instanceof HelpText) { |
|
194 | - $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
|
195 | - } |
|
196 | - return $this->helpText; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param HelpText $helpText |
|
202 | - * @throws EE_Error |
|
203 | - * @throws ReflectionException |
|
204 | - */ |
|
205 | - public function setHelpText(HelpText $helpText) |
|
206 | - { |
|
207 | - // set local object |
|
208 | - $this->helpText = $helpText; |
|
209 | - // then pass to model as an array which will get converted to JSON by the model field |
|
210 | - $this->set('FIN_helpText', $helpText->toArray()); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * returns a FormLabel object for managing input labels |
|
216 | - * |
|
217 | - * @return FormLabel |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function label(): ?FormLabel |
|
222 | - { |
|
223 | - if (! $this->label instanceof FormLabel) { |
|
224 | - $this->label = FormLabel::fromJson($this->get('FIN_label')); |
|
225 | - } |
|
226 | - return $this->label; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @param FormLabel $label |
|
232 | - * @throws EE_Error |
|
233 | - * @throws ReflectionException |
|
234 | - */ |
|
235 | - public function setLabel(FormLabel $label) |
|
236 | - { |
|
237 | - // set local object |
|
238 | - $this->label = $label; |
|
239 | - // then pass to model as an array which will get converted to JSON by the model field |
|
240 | - $this->set('FIN_label', $label->toArray()); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * Model and Fields name that this input maps to; ex: Attendee.email |
|
246 | - * |
|
247 | - * @return string |
|
248 | - * @throws EE_Error |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - public function mapsTo(): ?string |
|
252 | - { |
|
253 | - return $this->get('FIN_mapsTo'); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @param string $model ex: Attendee |
|
259 | - * @param string $field ex: email |
|
260 | - * @throws EE_Error |
|
261 | - * @throws ReflectionException |
|
262 | - */ |
|
263 | - public function setMapsTo(string $model, string $field) |
|
264 | - { |
|
265 | - $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
|
266 | - if (! class_exists($model_name)) { |
|
267 | - throw new DomainException( |
|
268 | - sprintf( |
|
269 | - esc_html__( |
|
270 | - 'The %1$s model does not exist or can not be located. Please verify the spelling and whether it is loaded.', |
|
271 | - 'event_espresso' |
|
272 | - ), |
|
273 | - $model_name |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
283 | - * |
|
284 | - * @return InputOptions |
|
285 | - * @throws EE_Error |
|
286 | - * @throws ReflectionException |
|
287 | - */ |
|
288 | - public function options(): ?InputOptions |
|
289 | - { |
|
290 | - if (! $this->options instanceof InputOptions) { |
|
291 | - $this->options = InputOptions::fromJson($this->get('FIN_options')); |
|
292 | - } |
|
293 | - return $this->options; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * @param InputOptions $options |
|
299 | - * @throws EE_Error |
|
300 | - * @throws ReflectionException |
|
301 | - */ |
|
302 | - public function setOptions(InputOptions $options) |
|
303 | - { |
|
304 | - // set local object |
|
305 | - $this->options = $options; |
|
306 | - // then pass to model as an array which will get converted to JSON by the model field |
|
307 | - $this->set('FIN_options', $options->toArray()); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * Order in which form input appears in a form. |
|
314 | - * |
|
315 | - * @return int |
|
316 | - * @throws EE_Error |
|
317 | - * @throws ReflectionException |
|
318 | - */ |
|
319 | - public function order(): int |
|
320 | - { |
|
321 | - return $this->get('FIN_order'); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * @param int $order |
|
327 | - * @throws EE_Error |
|
328 | - * @throws ReflectionException |
|
329 | - */ |
|
330 | - public function setOrder(int $order) |
|
331 | - { |
|
332 | - $this->set('FIN_order', $order); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Example text displayed within an input to assist users with completing the form. |
|
338 | - * |
|
339 | - * @return string |
|
340 | - * @throws EE_Error |
|
341 | - * @throws ReflectionException |
|
342 | - */ |
|
343 | - public function placeholder(): ?string |
|
344 | - { |
|
345 | - return $this->get('FIN_placeholder'); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @param string $placeholder |
|
351 | - * @throws EE_Error |
|
352 | - * @throws ReflectionException |
|
353 | - */ |
|
354 | - public function setPlaceholder(string $placeholder) |
|
355 | - { |
|
356 | - $this->set('FIN_placeholder', $placeholder); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Whether or not the input must be supplied with a value in order to complete the form. |
|
362 | - * |
|
363 | - * @return Required |
|
364 | - * @throws EE_Error |
|
365 | - * @throws ReflectionException |
|
366 | - */ |
|
367 | - public function required(): ?Required |
|
368 | - { |
|
369 | - if (! $this->required instanceof Required) { |
|
370 | - $this->required = Required::fromJson($this->get('FIN_required')); |
|
371 | - } |
|
372 | - return $this->required; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @param Required $required |
|
378 | - * @throws EE_Error |
|
379 | - * @throws ReflectionException |
|
380 | - */ |
|
381 | - public function setRequired(Required $required) |
|
382 | - { |
|
383 | - // set local object |
|
384 | - $this->required = $required; |
|
385 | - // then pass to model as an array which will get converted to JSON by the model field |
|
386 | - $this->set('FIN_required', $required->toArray()); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * version of public label for use in identifiers |
|
392 | - * |
|
393 | - * @return string |
|
394 | - * @throws EE_Error |
|
395 | - * @throws ReflectionException |
|
396 | - */ |
|
397 | - public function slug(): ?string |
|
398 | - { |
|
399 | - return sanitize_title($this->label()->publicLabel()); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
405 | - * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
406 | - * |
|
407 | - * @return string |
|
408 | - * @throws EE_Error |
|
409 | - * @throws ReflectionException |
|
410 | - */ |
|
411 | - public function status(): string |
|
412 | - { |
|
413 | - return $this->get('FIN_status'); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
419 | - * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
420 | - * |
|
421 | - * @param string $status |
|
422 | - * @throws EE_Error |
|
423 | - * @throws ReflectionException |
|
424 | - */ |
|
425 | - public function setStatus(string $status) |
|
426 | - { |
|
427 | - $this->set('FIN_status', $status); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Form input type. |
|
433 | - * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
434 | - * |
|
435 | - * @return string |
|
436 | - * @throws EE_Error |
|
437 | - * @throws ReflectionException |
|
438 | - */ |
|
439 | - public function type(): ?string |
|
440 | - { |
|
441 | - return $this->get('FIN_type'); |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * @param string $type |
|
447 | - * @throws EE_Error |
|
448 | - * @throws ReflectionException |
|
449 | - */ |
|
450 | - public function setType(string $type) |
|
451 | - { |
|
452 | - $this->set('FIN_type', $type); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * ID of the WP User that created this form input. |
|
458 | - * |
|
459 | - * @return int |
|
460 | - * @throws EE_Error |
|
461 | - * @throws ReflectionException |
|
462 | - */ |
|
463 | - public function wp_user(): int |
|
464 | - { |
|
465 | - return $this->get('FIN_wpUser'); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * returns the id the wordpress user who created this question |
|
471 | - * |
|
472 | - * @param int $wp_user |
|
473 | - * @throws EE_Error |
|
474 | - * @throws ReflectionException |
|
475 | - */ |
|
476 | - public function setWpUser(int $wp_user) |
|
477 | - { |
|
478 | - $this->set('FIN_wpUser', $wp_user); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param array $set_cols_n_values |
|
484 | - * @return bool|int|string |
|
485 | - * @throws EE_Error |
|
486 | - * @throws ReflectionException |
|
487 | - */ |
|
488 | - public function save($set_cols_n_values = []) |
|
489 | - { |
|
490 | - // make sure internal versions for all composite objects are updated |
|
491 | - $this->set('FIN_attributes', $this->attributes()->toArray()); |
|
492 | - $this->set('FIN_helpText', $this->helpText()->toArray()); |
|
493 | - $this->set('FIN_label', $this->label()->toArray()); |
|
494 | - $this->set('FIN_options', $this->options()->toArray()); |
|
495 | - $this->set('FIN_required', $this->required()->toArray()); |
|
496 | - return parent::save($set_cols_n_values); |
|
497 | - } |
|
31 | + /** |
|
32 | + * @var Attributes |
|
33 | + */ |
|
34 | + private $attributes; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var FormLabel |
|
38 | + */ |
|
39 | + private $label; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var HelpText |
|
43 | + */ |
|
44 | + private $helpText; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var InputOptions |
|
48 | + */ |
|
49 | + private $options; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var Required |
|
53 | + */ |
|
54 | + private $required; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param array $props_n_values |
|
59 | + * @return EE_Form_Element |
|
60 | + * @throws EE_Error |
|
61 | + * @throws ReflectionException |
|
62 | + */ |
|
63 | + public static function new_instance(array $props_n_values = []): EE_Form_Element |
|
64 | + { |
|
65 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
66 | + return $has_object ?: new self($props_n_values); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @param array $props_n_values |
|
72 | + * @return EE_Form_Element |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Element |
|
77 | + { |
|
78 | + return new self($props_n_values); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Form Element UUID (universally unique identifier) |
|
84 | + * |
|
85 | + * @return string |
|
86 | + * @throws EE_Error |
|
87 | + * @throws ReflectionException |
|
88 | + */ |
|
89 | + public function UUID(): string |
|
90 | + { |
|
91 | + return $this->get('FIN_UUID'); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param string $UUID |
|
97 | + * @throws EE_Error |
|
98 | + * @throws ReflectionException |
|
99 | + */ |
|
100 | + public function setUUID(string $UUID) |
|
101 | + { |
|
102 | + $this->set('FIN_UUID', $UUID); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
108 | + * |
|
109 | + * @return bool |
|
110 | + * @throws EE_Error |
|
111 | + * @throws ReflectionException |
|
112 | + */ |
|
113 | + public function adminOnly(): ?bool |
|
114 | + { |
|
115 | + return $this->get('FIN_adminOnly'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param bool $admin_only |
|
121 | + * @throws EE_Error |
|
122 | + * @throws ReflectionException |
|
123 | + */ |
|
124 | + public function setAdminOnly(bool $admin_only) |
|
125 | + { |
|
126 | + $this->set('FIN_adminOnly', $admin_only); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * JSON string of HTML attributes such as class, max, min, placeholder, type, etc. |
|
132 | + * |
|
133 | + * @return Attributes |
|
134 | + * @throws EE_Error |
|
135 | + * @throws ReflectionException |
|
136 | + */ |
|
137 | + public function attributes(): ?Attributes |
|
138 | + { |
|
139 | + if (! $this->attributes instanceof Attributes) { |
|
140 | + $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
|
141 | + } |
|
142 | + return $this->attributes; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @param Attributes $attributes |
|
148 | + * @throws EE_Error |
|
149 | + * @throws ReflectionException |
|
150 | + */ |
|
151 | + public function setAttributes(Attributes $attributes) |
|
152 | + { |
|
153 | + // set local object |
|
154 | + $this->attributes = $attributes; |
|
155 | + // then pass to model as an array which will get converted to JSON by the model field |
|
156 | + $this->set('FIN_attributes', $attributes->toArray()); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * UUID of parent form section this form input belongs to. |
|
162 | + * |
|
163 | + * @return string |
|
164 | + * @throws EE_Error |
|
165 | + * @throws ReflectionException |
|
166 | + */ |
|
167 | + public function belongsTo(): string |
|
168 | + { |
|
169 | + return $this->get('FSC_UUID'); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @param string $relation_UUID |
|
175 | + * @throws EE_Error |
|
176 | + * @throws ReflectionException |
|
177 | + */ |
|
178 | + public function setBelongsTo(string $relation_UUID) |
|
179 | + { |
|
180 | + $this->set('FSC_UUID', $relation_UUID); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * returns a HelpText object for managing input help text |
|
186 | + * |
|
187 | + * @return HelpText |
|
188 | + * @throws EE_Error |
|
189 | + * @throws ReflectionException |
|
190 | + */ |
|
191 | + public function helpText(): ?HelpText |
|
192 | + { |
|
193 | + if (! $this->helpText instanceof HelpText) { |
|
194 | + $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
|
195 | + } |
|
196 | + return $this->helpText; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param HelpText $helpText |
|
202 | + * @throws EE_Error |
|
203 | + * @throws ReflectionException |
|
204 | + */ |
|
205 | + public function setHelpText(HelpText $helpText) |
|
206 | + { |
|
207 | + // set local object |
|
208 | + $this->helpText = $helpText; |
|
209 | + // then pass to model as an array which will get converted to JSON by the model field |
|
210 | + $this->set('FIN_helpText', $helpText->toArray()); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * returns a FormLabel object for managing input labels |
|
216 | + * |
|
217 | + * @return FormLabel |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function label(): ?FormLabel |
|
222 | + { |
|
223 | + if (! $this->label instanceof FormLabel) { |
|
224 | + $this->label = FormLabel::fromJson($this->get('FIN_label')); |
|
225 | + } |
|
226 | + return $this->label; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @param FormLabel $label |
|
232 | + * @throws EE_Error |
|
233 | + * @throws ReflectionException |
|
234 | + */ |
|
235 | + public function setLabel(FormLabel $label) |
|
236 | + { |
|
237 | + // set local object |
|
238 | + $this->label = $label; |
|
239 | + // then pass to model as an array which will get converted to JSON by the model field |
|
240 | + $this->set('FIN_label', $label->toArray()); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * Model and Fields name that this input maps to; ex: Attendee.email |
|
246 | + * |
|
247 | + * @return string |
|
248 | + * @throws EE_Error |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + public function mapsTo(): ?string |
|
252 | + { |
|
253 | + return $this->get('FIN_mapsTo'); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @param string $model ex: Attendee |
|
259 | + * @param string $field ex: email |
|
260 | + * @throws EE_Error |
|
261 | + * @throws ReflectionException |
|
262 | + */ |
|
263 | + public function setMapsTo(string $model, string $field) |
|
264 | + { |
|
265 | + $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
|
266 | + if (! class_exists($model_name)) { |
|
267 | + throw new DomainException( |
|
268 | + sprintf( |
|
269 | + esc_html__( |
|
270 | + 'The %1$s model does not exist or can not be located. Please verify the spelling and whether it is loaded.', |
|
271 | + 'event_espresso' |
|
272 | + ), |
|
273 | + $model_name |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
283 | + * |
|
284 | + * @return InputOptions |
|
285 | + * @throws EE_Error |
|
286 | + * @throws ReflectionException |
|
287 | + */ |
|
288 | + public function options(): ?InputOptions |
|
289 | + { |
|
290 | + if (! $this->options instanceof InputOptions) { |
|
291 | + $this->options = InputOptions::fromJson($this->get('FIN_options')); |
|
292 | + } |
|
293 | + return $this->options; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * @param InputOptions $options |
|
299 | + * @throws EE_Error |
|
300 | + * @throws ReflectionException |
|
301 | + */ |
|
302 | + public function setOptions(InputOptions $options) |
|
303 | + { |
|
304 | + // set local object |
|
305 | + $this->options = $options; |
|
306 | + // then pass to model as an array which will get converted to JSON by the model field |
|
307 | + $this->set('FIN_options', $options->toArray()); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * Order in which form input appears in a form. |
|
314 | + * |
|
315 | + * @return int |
|
316 | + * @throws EE_Error |
|
317 | + * @throws ReflectionException |
|
318 | + */ |
|
319 | + public function order(): int |
|
320 | + { |
|
321 | + return $this->get('FIN_order'); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @param int $order |
|
327 | + * @throws EE_Error |
|
328 | + * @throws ReflectionException |
|
329 | + */ |
|
330 | + public function setOrder(int $order) |
|
331 | + { |
|
332 | + $this->set('FIN_order', $order); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Example text displayed within an input to assist users with completing the form. |
|
338 | + * |
|
339 | + * @return string |
|
340 | + * @throws EE_Error |
|
341 | + * @throws ReflectionException |
|
342 | + */ |
|
343 | + public function placeholder(): ?string |
|
344 | + { |
|
345 | + return $this->get('FIN_placeholder'); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @param string $placeholder |
|
351 | + * @throws EE_Error |
|
352 | + * @throws ReflectionException |
|
353 | + */ |
|
354 | + public function setPlaceholder(string $placeholder) |
|
355 | + { |
|
356 | + $this->set('FIN_placeholder', $placeholder); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Whether or not the input must be supplied with a value in order to complete the form. |
|
362 | + * |
|
363 | + * @return Required |
|
364 | + * @throws EE_Error |
|
365 | + * @throws ReflectionException |
|
366 | + */ |
|
367 | + public function required(): ?Required |
|
368 | + { |
|
369 | + if (! $this->required instanceof Required) { |
|
370 | + $this->required = Required::fromJson($this->get('FIN_required')); |
|
371 | + } |
|
372 | + return $this->required; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @param Required $required |
|
378 | + * @throws EE_Error |
|
379 | + * @throws ReflectionException |
|
380 | + */ |
|
381 | + public function setRequired(Required $required) |
|
382 | + { |
|
383 | + // set local object |
|
384 | + $this->required = $required; |
|
385 | + // then pass to model as an array which will get converted to JSON by the model field |
|
386 | + $this->set('FIN_required', $required->toArray()); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * version of public label for use in identifiers |
|
392 | + * |
|
393 | + * @return string |
|
394 | + * @throws EE_Error |
|
395 | + * @throws ReflectionException |
|
396 | + */ |
|
397 | + public function slug(): ?string |
|
398 | + { |
|
399 | + return sanitize_title($this->label()->publicLabel()); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
405 | + * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
406 | + * |
|
407 | + * @return string |
|
408 | + * @throws EE_Error |
|
409 | + * @throws ReflectionException |
|
410 | + */ |
|
411 | + public function status(): string |
|
412 | + { |
|
413 | + return $this->get('FIN_status'); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
419 | + * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
420 | + * |
|
421 | + * @param string $status |
|
422 | + * @throws EE_Error |
|
423 | + * @throws ReflectionException |
|
424 | + */ |
|
425 | + public function setStatus(string $status) |
|
426 | + { |
|
427 | + $this->set('FIN_status', $status); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Form input type. |
|
433 | + * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
434 | + * |
|
435 | + * @return string |
|
436 | + * @throws EE_Error |
|
437 | + * @throws ReflectionException |
|
438 | + */ |
|
439 | + public function type(): ?string |
|
440 | + { |
|
441 | + return $this->get('FIN_type'); |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * @param string $type |
|
447 | + * @throws EE_Error |
|
448 | + * @throws ReflectionException |
|
449 | + */ |
|
450 | + public function setType(string $type) |
|
451 | + { |
|
452 | + $this->set('FIN_type', $type); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * ID of the WP User that created this form input. |
|
458 | + * |
|
459 | + * @return int |
|
460 | + * @throws EE_Error |
|
461 | + * @throws ReflectionException |
|
462 | + */ |
|
463 | + public function wp_user(): int |
|
464 | + { |
|
465 | + return $this->get('FIN_wpUser'); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * returns the id the wordpress user who created this question |
|
471 | + * |
|
472 | + * @param int $wp_user |
|
473 | + * @throws EE_Error |
|
474 | + * @throws ReflectionException |
|
475 | + */ |
|
476 | + public function setWpUser(int $wp_user) |
|
477 | + { |
|
478 | + $this->set('FIN_wpUser', $wp_user); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param array $set_cols_n_values |
|
484 | + * @return bool|int|string |
|
485 | + * @throws EE_Error |
|
486 | + * @throws ReflectionException |
|
487 | + */ |
|
488 | + public function save($set_cols_n_values = []) |
|
489 | + { |
|
490 | + // make sure internal versions for all composite objects are updated |
|
491 | + $this->set('FIN_attributes', $this->attributes()->toArray()); |
|
492 | + $this->set('FIN_helpText', $this->helpText()->toArray()); |
|
493 | + $this->set('FIN_label', $this->label()->toArray()); |
|
494 | + $this->set('FIN_options', $this->options()->toArray()); |
|
495 | + $this->set('FIN_required', $this->required()->toArray()); |
|
496 | + return parent::save($set_cols_n_values); |
|
497 | + } |
|
498 | 498 | } |
@@ -12,77 +12,77 @@ |
||
12 | 12 | |
13 | 13 | class CopyAttendeeInfoForm extends EE_Form_Section_Proper |
14 | 14 | { |
15 | - /** |
|
16 | - * CopyAttendeeInfoForm constructor. |
|
17 | - * |
|
18 | - * @param EE_Registration[] $registrations |
|
19 | - * @param string $slug |
|
20 | - * @throws EE_Error |
|
21 | - * @throws ReflectionException |
|
22 | - */ |
|
23 | - public function __construct(array $registrations, string $slug) |
|
24 | - { |
|
25 | - parent::__construct( |
|
26 | - [ |
|
27 | - 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
28 | - 'layout_strategy' => new EE_Template_Layout( |
|
29 | - [ |
|
30 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
31 | - . $slug |
|
32 | - . '/copy_attendee_info.template.php', |
|
33 | - 'begin_template_file' => null, |
|
34 | - 'input_template_file' => null, |
|
35 | - 'subsection_template_file' => null, |
|
36 | - 'end_template_file' => null, |
|
37 | - ] |
|
38 | - ), |
|
39 | - ] |
|
40 | - ); |
|
41 | - } |
|
15 | + /** |
|
16 | + * CopyAttendeeInfoForm constructor. |
|
17 | + * |
|
18 | + * @param EE_Registration[] $registrations |
|
19 | + * @param string $slug |
|
20 | + * @throws EE_Error |
|
21 | + * @throws ReflectionException |
|
22 | + */ |
|
23 | + public function __construct(array $registrations, string $slug) |
|
24 | + { |
|
25 | + parent::__construct( |
|
26 | + [ |
|
27 | + 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
28 | + 'layout_strategy' => new EE_Template_Layout( |
|
29 | + [ |
|
30 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
31 | + . $slug |
|
32 | + . '/copy_attendee_info.template.php', |
|
33 | + 'begin_template_file' => null, |
|
34 | + 'input_template_file' => null, |
|
35 | + 'subsection_template_file' => null, |
|
36 | + 'end_template_file' => null, |
|
37 | + ] |
|
38 | + ), |
|
39 | + ] |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param array $registrations |
|
46 | - * @return array |
|
47 | - * @throws EE_Error |
|
48 | - * @throws ReflectionException |
|
49 | - */ |
|
50 | - private function copyAttendeeInfoInputs(array $registrations): array |
|
51 | - { |
|
52 | - $copy_attendee_info_inputs = []; |
|
53 | - $prev_ticket = null; |
|
54 | - foreach ($registrations as $registration) { |
|
55 | - // for all attendees other than the primary attendee |
|
56 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
57 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
58 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
59 | - $item_name = $registration->ticket()->name(); |
|
60 | - $item_name .= $registration->ticket()->description() !== '' |
|
61 | - ? ' - ' . $registration->ticket()->description() |
|
62 | - : ''; |
|
63 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
64 | - = new EE_Form_Section_HTML( |
|
65 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
66 | - ); |
|
67 | - $prev_ticket = $registration->ticket()->ID(); |
|
68 | - } |
|
44 | + /** |
|
45 | + * @param array $registrations |
|
46 | + * @return array |
|
47 | + * @throws EE_Error |
|
48 | + * @throws ReflectionException |
|
49 | + */ |
|
50 | + private function copyAttendeeInfoInputs(array $registrations): array |
|
51 | + { |
|
52 | + $copy_attendee_info_inputs = []; |
|
53 | + $prev_ticket = null; |
|
54 | + foreach ($registrations as $registration) { |
|
55 | + // for all attendees other than the primary attendee |
|
56 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
57 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
58 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
59 | + $item_name = $registration->ticket()->name(); |
|
60 | + $item_name .= $registration->ticket()->description() !== '' |
|
61 | + ? ' - ' . $registration->ticket()->description() |
|
62 | + : ''; |
|
63 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
64 | + = new EE_Form_Section_HTML( |
|
65 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
66 | + ); |
|
67 | + $prev_ticket = $registration->ticket()->ID(); |
|
68 | + } |
|
69 | 69 | |
70 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
71 | - = new EE_Checkbox_Multi_Input( |
|
72 | - [ |
|
73 | - $registration->ID() => sprintf( |
|
74 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
75 | - $registration->count() |
|
76 | - ) |
|
77 | - ], |
|
78 | - [ |
|
79 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
80 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
81 | - 'display_html_label_text' => false, |
|
82 | - ] |
|
83 | - ); |
|
84 | - } |
|
85 | - } |
|
86 | - return $copy_attendee_info_inputs; |
|
87 | - } |
|
70 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
71 | + = new EE_Checkbox_Multi_Input( |
|
72 | + [ |
|
73 | + $registration->ID() => sprintf( |
|
74 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
75 | + $registration->count() |
|
76 | + ) |
|
77 | + ], |
|
78 | + [ |
|
79 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
80 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
81 | + 'display_html_label_text' => false, |
|
82 | + ] |
|
83 | + ); |
|
84 | + } |
|
85 | + } |
|
86 | + return $copy_attendee_info_inputs; |
|
87 | + } |
|
88 | 88 | } |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
57 | 57 | // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
58 | 58 | if ($registration->ticket()->ID() !== $prev_ticket) { |
59 | - $item_name = $registration->ticket()->name(); |
|
60 | - $item_name .= $registration->ticket()->description() !== '' |
|
61 | - ? ' - ' . $registration->ticket()->description() |
|
59 | + $item_name = $registration->ticket()->name(); |
|
60 | + $item_name .= $registration->ticket()->description() !== '' |
|
61 | + ? ' - '.$registration->ticket()->description() |
|
62 | 62 | : ''; |
63 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
63 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] |
|
64 | 64 | = new EE_Form_Section_HTML( |
65 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
65 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
66 | 66 | ); |
67 | 67 | $prev_ticket = $registration->ticket()->ID(); |
68 | 68 | } |
69 | 69 | |
70 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
70 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] |
|
71 | 71 | = new EE_Checkbox_Multi_Input( |
72 | 72 | [ |
73 | 73 | $registration->ID() => sprintf( |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ) |
77 | 77 | ], |
78 | 78 | [ |
79 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
79 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
80 | 80 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
81 | 81 | 'display_html_label_text' => false, |
82 | 82 | ] |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getModelObjNodesInGroup($code) |
52 | 52 | { |
53 | - if (! $code) { |
|
53 | + if ( ! $code) { |
|
54 | 54 | throw new Exception( |
55 | 55 | esc_html__( |
56 | 56 | 'We aren’t sure which job you are performing. Please press back in your browser and try again.', |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | ) |
59 | 59 | ); |
60 | 60 | } |
61 | - $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
61 | + $deletion_data = get_option($this->getOptionPrefix().$code, []); |
|
62 | 62 | foreach ($deletion_data as $root) { |
63 | - if (! $root instanceof ModelObjNode) { |
|
63 | + if ( ! $root instanceof ModelObjNode) { |
|
64 | 64 | throw new UnexpectedEntityException($root, 'ModelObjNode'); |
65 | 65 | } |
66 | 66 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function persistModelObjNodesGroup(array $model_obj_nodes, $code) |
122 | 122 | { |
123 | 123 | return add_option( |
124 | - $this->getOptionPrefix() . $code, |
|
124 | + $this->getOptionPrefix().$code, |
|
125 | 125 | $model_obj_nodes, |
126 | 126 | null, |
127 | 127 | 'no' |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function deleteModelObjNodesInGroup($code) |
139 | 139 | { |
140 | - return delete_option($this->getOptionPrefix() . $code); |
|
140 | + return delete_option($this->getOptionPrefix().$code); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | // End of file NodeGroupDao.php |
@@ -22,125 +22,125 @@ |
||
22 | 22 | */ |
23 | 23 | class NodeGroupDao |
24 | 24 | { |
25 | - /** |
|
26 | - * @return mixed|void |
|
27 | - */ |
|
28 | - public function generateGroupCode() |
|
29 | - { |
|
30 | - return wp_generate_password(6, false); |
|
31 | - } |
|
25 | + /** |
|
26 | + * @return mixed|void |
|
27 | + */ |
|
28 | + public function generateGroupCode() |
|
29 | + { |
|
30 | + return wp_generate_password(6, false); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Gets the string we put in front of the WP Option name used to store the jobs. |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - private function getOptionPrefix() |
|
40 | - { |
|
41 | - return 'ee_deletion_'; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Gets the string we put in front of the WP Option name used to store the jobs. |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + private function getOptionPrefix() |
|
40 | + { |
|
41 | + return 'ee_deletion_'; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param $code |
|
47 | - * @return ModelObjNode[] |
|
48 | - * @throws Exception |
|
49 | - * @throws UnexpectedEntityException |
|
50 | - * @throws Exception |
|
51 | - */ |
|
52 | - public function getModelObjNodesInGroup($code) |
|
53 | - { |
|
54 | - if (! $code) { |
|
55 | - throw new Exception( |
|
56 | - esc_html__( |
|
57 | - 'We aren’t sure which job you are performing. Please press back in your browser and try again.', |
|
58 | - 'event_espresso' |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
62 | - $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
63 | - foreach ($deletion_data as $root) { |
|
64 | - if (! $root instanceof ModelObjNode) { |
|
65 | - throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
66 | - } |
|
67 | - } |
|
68 | - return $deletion_data; |
|
69 | - } |
|
45 | + /** |
|
46 | + * @param $code |
|
47 | + * @return ModelObjNode[] |
|
48 | + * @throws Exception |
|
49 | + * @throws UnexpectedEntityException |
|
50 | + * @throws Exception |
|
51 | + */ |
|
52 | + public function getModelObjNodesInGroup($code) |
|
53 | + { |
|
54 | + if (! $code) { |
|
55 | + throw new Exception( |
|
56 | + esc_html__( |
|
57 | + 'We aren’t sure which job you are performing. Please press back in your browser and try again.', |
|
58 | + 'event_espresso' |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | + $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
63 | + foreach ($deletion_data as $root) { |
|
64 | + if (! $root instanceof ModelObjNode) { |
|
65 | + throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
66 | + } |
|
67 | + } |
|
68 | + return $deletion_data; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Gets an array indicating what database rows are contained in the job. |
|
74 | - * Each top-level key is a model name, and its value is an array of IDs. |
|
75 | - * |
|
76 | - * @param ModelObjNode[] $model_obj_nodes |
|
77 | - * @return array |
|
78 | - * @throws EE_Error |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws InvalidInterfaceException |
|
81 | - * @throws InvalidArgumentException |
|
82 | - * @throws ReflectionException |
|
83 | - */ |
|
84 | - public function getModelsAndIdsContainedIn(array $model_obj_nodes) |
|
85 | - { |
|
86 | - $models_and_ids_to_delete = []; |
|
87 | - foreach ($model_obj_nodes as $root) { |
|
88 | - $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
89 | - } |
|
90 | - return $models_and_ids_to_delete; |
|
91 | - } |
|
72 | + /** |
|
73 | + * Gets an array indicating what database rows are contained in the job. |
|
74 | + * Each top-level key is a model name, and its value is an array of IDs. |
|
75 | + * |
|
76 | + * @param ModelObjNode[] $model_obj_nodes |
|
77 | + * @return array |
|
78 | + * @throws EE_Error |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws InvalidInterfaceException |
|
81 | + * @throws InvalidArgumentException |
|
82 | + * @throws ReflectionException |
|
83 | + */ |
|
84 | + public function getModelsAndIdsContainedIn(array $model_obj_nodes) |
|
85 | + { |
|
86 | + $models_and_ids_to_delete = []; |
|
87 | + foreach ($model_obj_nodes as $root) { |
|
88 | + $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
89 | + } |
|
90 | + return $models_and_ids_to_delete; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Gets an array indicating what database rows are contained in the job. |
|
96 | - * Each top-level key is a model name, and its value is an array of IDs. |
|
97 | - * |
|
98 | - * @param string $code |
|
99 | - * @return array |
|
100 | - * @throws EE_Error |
|
101 | - * @throws Exception |
|
102 | - * @throws InvalidArgumentException |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - * @throws InvalidInterfaceException |
|
105 | - * @throws ReflectionException |
|
106 | - * @throws UnexpectedEntityException |
|
107 | - * @throws Exception |
|
108 | - */ |
|
109 | - public function getModelsAndIdsFromGroup($code) |
|
110 | - { |
|
111 | - $model_obj_nodes = $this->getModelObjNodesInGroup($code); |
|
112 | - return $this->getModelsAndIdsContainedIn($model_obj_nodes); |
|
113 | - } |
|
94 | + /** |
|
95 | + * Gets an array indicating what database rows are contained in the job. |
|
96 | + * Each top-level key is a model name, and its value is an array of IDs. |
|
97 | + * |
|
98 | + * @param string $code |
|
99 | + * @return array |
|
100 | + * @throws EE_Error |
|
101 | + * @throws Exception |
|
102 | + * @throws InvalidArgumentException |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + * @throws InvalidInterfaceException |
|
105 | + * @throws ReflectionException |
|
106 | + * @throws UnexpectedEntityException |
|
107 | + * @throws Exception |
|
108 | + */ |
|
109 | + public function getModelsAndIdsFromGroup($code) |
|
110 | + { |
|
111 | + $model_obj_nodes = $this->getModelObjNodesInGroup($code); |
|
112 | + return $this->getModelsAndIdsContainedIn($model_obj_nodes); |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Persists the ModelObjNodes for future requests, using the code for reference. |
|
118 | - * |
|
119 | - * @param ModelObjNode[] $model_obj_nodes |
|
120 | - * @param string $code |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function persistModelObjNodesGroup(array $model_obj_nodes, $code) |
|
124 | - { |
|
125 | - return add_option( |
|
126 | - $this->getOptionPrefix() . $code, |
|
127 | - $model_obj_nodes, |
|
128 | - null, |
|
129 | - 'no' |
|
130 | - ); |
|
131 | - } |
|
116 | + /** |
|
117 | + * Persists the ModelObjNodes for future requests, using the code for reference. |
|
118 | + * |
|
119 | + * @param ModelObjNode[] $model_obj_nodes |
|
120 | + * @param string $code |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function persistModelObjNodesGroup(array $model_obj_nodes, $code) |
|
124 | + { |
|
125 | + return add_option( |
|
126 | + $this->getOptionPrefix() . $code, |
|
127 | + $model_obj_nodes, |
|
128 | + null, |
|
129 | + 'no' |
|
130 | + ); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | |
134 | - /** |
|
135 | - * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though. |
|
136 | - * |
|
137 | - * @param $code |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function deleteModelObjNodesInGroup($code) |
|
141 | - { |
|
142 | - return delete_option($this->getOptionPrefix() . $code); |
|
143 | - } |
|
134 | + /** |
|
135 | + * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though. |
|
136 | + * |
|
137 | + * @param $code |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function deleteModelObjNodesInGroup($code) |
|
141 | + { |
|
142 | + return delete_option($this->getOptionPrefix() . $code); |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | // End of file NodeGroupDao.php |
146 | 146 | // Location: EventEspresso\core\services\orm\tree_traversal/NodeGroupDao.php |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register(string $addon_name = '', array $setup_args = []): bool |
31 | 31 | { |
32 | - self::$exporters[ $addon_name ] = $setup_args; |
|
32 | + self::$exporters[$addon_name] = $setup_args; |
|
33 | 33 | // add to list of modules to be registered |
34 | 34 | add_filter( |
35 | 35 | 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public static function deregister(string $addon_name = '') |
46 | 46 | { |
47 | - unset(self::$exporters[ $addon_name ]); |
|
47 | + unset(self::$exporters[$addon_name]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 |
@@ -12,57 +12,57 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_Personal_Data_Exporter implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * FQCN for all privacy policy generators |
|
17 | - * |
|
18 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | - */ |
|
20 | - protected static $exporters = []; |
|
15 | + /** |
|
16 | + * FQCN for all privacy policy generators |
|
17 | + * |
|
18 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | + */ |
|
20 | + protected static $exporters = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $addon_name |
|
25 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | - * OR fully qualified class names of privacy policies |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | - { |
|
31 | - self::$exporters[ $addon_name ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
35 | - ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
36 | - ); |
|
37 | - return true; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $addon_name |
|
25 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | + * OR fully qualified class names of privacy policies |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | + { |
|
31 | + self::$exporters[ $addon_name ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
35 | + ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
36 | + ); |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $addon_name |
|
43 | - */ |
|
44 | - public static function deregister(string $addon_name = '') |
|
45 | - { |
|
46 | - unset(self::$exporters[ $addon_name ]); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param string $addon_name |
|
43 | + */ |
|
44 | + public static function deregister(string $addon_name = '') |
|
45 | + { |
|
46 | + unset(self::$exporters[ $addon_name ]); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Adds our personal data exporters registered by add-ons |
|
52 | - * |
|
53 | - * @param string[] $exporters |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public static function addExporters(array $exporters): array |
|
57 | - { |
|
58 | - return array_merge($exporters, ...self::$exporters); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Adds our personal data exporters registered by add-ons |
|
52 | + * |
|
53 | + * @param string[] $exporters |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public static function addExporters(array $exporters): array |
|
57 | + { |
|
58 | + return array_merge($exporters, ...self::$exporters); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - public static function reset(): void |
|
63 | - { |
|
64 | - self::$exporters = []; |
|
65 | - } |
|
62 | + public static function reset(): void |
|
63 | + { |
|
64 | + self::$exporters = []; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | // End of file EE_Register_Personal_Data_Exporter.lib.php |
68 | 68 | // Location: ${NAMESPACE}/EE_Register_Personal_Data_Exporter.lib.php |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register(string $addon_name = '', array $setup_args = []): bool |
31 | 31 | { |
32 | - self::$erasers[ $addon_name ] = $setup_args; |
|
32 | + self::$erasers[$addon_name] = $setup_args; |
|
33 | 33 | // add to list of modules to be registered |
34 | 34 | add_filter( |
35 | 35 | 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public static function deregister(string $addon_name = '') |
46 | 46 | { |
47 | - unset(self::$erasers[ $addon_name ]); |
|
47 | + unset(self::$erasers[$addon_name]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 |
@@ -12,57 +12,57 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_Personal_Data_Eraser implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * FQCN for all privacy policy generators |
|
17 | - * |
|
18 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | - */ |
|
20 | - protected static $erasers = []; |
|
15 | + /** |
|
16 | + * FQCN for all privacy policy generators |
|
17 | + * |
|
18 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | + */ |
|
20 | + protected static $erasers = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $addon_name |
|
25 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | - * OR fully qualified class names of privacy policies |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | - { |
|
31 | - self::$erasers[ $addon_name ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
|
35 | - ['EE_Register_Personal_Data_Eraser', 'addErasers'] |
|
36 | - ); |
|
37 | - return true; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $addon_name |
|
25 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | + * OR fully qualified class names of privacy policies |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | + { |
|
31 | + self::$erasers[ $addon_name ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
|
35 | + ['EE_Register_Personal_Data_Eraser', 'addErasers'] |
|
36 | + ); |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $addon_name |
|
43 | - */ |
|
44 | - public static function deregister(string $addon_name = '') |
|
45 | - { |
|
46 | - unset(self::$erasers[ $addon_name ]); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param string $addon_name |
|
43 | + */ |
|
44 | + public static function deregister(string $addon_name = '') |
|
45 | + { |
|
46 | + unset(self::$erasers[ $addon_name ]); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Adds our personal data erasers registered by add-ons |
|
52 | - * |
|
53 | - * @param string[] $erasers |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public static function addErasers(array $erasers): array |
|
57 | - { |
|
58 | - return array_merge($erasers, ...self::$erasers); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Adds our personal data erasers registered by add-ons |
|
52 | + * |
|
53 | + * @param string[] $erasers |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public static function addErasers(array $erasers): array |
|
57 | + { |
|
58 | + return array_merge($erasers, ...self::$erasers); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - public static function reset(): void |
|
63 | - { |
|
64 | - self::$erasers = []; |
|
65 | - } |
|
62 | + public static function reset(): void |
|
63 | + { |
|
64 | + self::$erasers = []; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | // End of file EE_Register_Personal_Data_Eraser.lib.php |
68 | 68 | // Location: ${NAMESPACE}/EE_Register_Personal_Data_Eraser.lib.php |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | // make sure we don't register twice |
68 | - if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
68 | + if (isset(self::$_ee_messages_shortcode_registry[$addon_name])) { |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
90 | - self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
90 | + self::$_ee_messages_shortcode_registry[$addon_name] = [ |
|
91 | 91 | 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
92 | 92 | 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
93 | 93 | ? (array) $setup_args['list_type_shortcodes'] : [], |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | ); |
102 | 102 | |
103 | 103 | // add below filters if the required callback is provided. |
104 | - if (! empty($setup_args['msgr_validator_callback'])) { |
|
104 | + if ( ! empty($setup_args['msgr_validator_callback'])) { |
|
105 | 105 | add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
106 | 106 | } |
107 | 107 | |
108 | - if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
108 | + if ( ! empty($setup_args['msgr_template_fields_callback'])) { |
|
109 | 109 | add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
110 | 110 | } |
111 | 111 | |
112 | - if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
112 | + if ( ! empty($setup_args['valid_shortcodes_callback'])) { |
|
113 | 113 | add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
114 | 114 | } |
115 | 115 | |
116 | - if (! empty($setup_args['list_type_shortcodes'])) { |
|
116 | + if ( ! empty($setup_args['list_type_shortcodes'])) { |
|
117 | 117 | add_filter( |
118 | 118 | 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
119 | 119 | ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public static function deregister(string $addon_name = '') |
135 | 135 | { |
136 | - unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
136 | + unset(self::$_ee_messages_shortcode_registry[$addon_name]); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public static function register_msgs_autoload_paths(array $paths): array |
149 | 149 | { |
150 | 150 | $autoload_paths = []; |
151 | - if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
151 | + if ( ! empty(self::$_ee_messages_shortcode_registry)) { |
|
152 | 152 | foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
153 | 153 | if (empty($st_reg['autoloadpaths'])) { |
154 | 154 | continue; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | $shortcodes = []; |
178 | 178 | foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
179 | - if (! empty($sc_reg['list_type_shortcodes'])) { |
|
179 | + if ( ! empty($sc_reg['list_type_shortcodes'])) { |
|
180 | 180 | $shortcodes[] = $sc_reg['list_type_shortcodes']; |
181 | 181 | } |
182 | 182 | } |
@@ -10,180 +10,180 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Register_Messages_Shortcode_Library implements EEI_Plugin_API |
12 | 12 | { |
13 | - /** |
|
14 | - * holds values for registered messages shortcode libraries |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected static $_ee_messages_shortcode_registry = []; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * Helper method for registering a new shortcodes library class for the messages system. |
|
23 | - * |
|
24 | - * Note this is not used for adding shortcodes to existing libraries. It's for registering anything |
|
25 | - * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class. |
|
26 | - * |
|
27 | - * @param string $addon_name What is the name of this shortcode library (e.g. 'question_list'); |
|
28 | - * @param array $setup_args An array of arguments provided for registering the new messages shortcode library. |
|
29 | - * { |
|
30 | - * |
|
31 | - * @type array $autoloadpaths An array of paths to add to the messages autoloader |
|
32 | - * for the new shortcode library class file. |
|
33 | - * @type string $msgr_validator_callback Callback for a method that will register the library with the |
|
34 | - * messenger _validator_config. Optional. |
|
35 | - * @type string $msgr_template_fields_callback Callback for changing adding the _template_fields property for |
|
36 | - * messenger. For example, the shortcode library may add a new |
|
37 | - * field to the message templates. Optional. |
|
38 | - * @type string $valid_shortcodes_callback Callback for message types _valid_shortcodes array setup. |
|
39 | - * Optional. |
|
40 | - * @type array $list_type_shortcodes If there are any specific shortcodes with this message |
|
41 | - * shortcode library that should be considered "list type" |
|
42 | - * then include them in an array. |
|
43 | - * List Type shortcodes are shortcodes that have a corresponding |
|
44 | - * field that indicates how they are parsed. Optional. |
|
45 | - * } |
|
46 | - * @return bool |
|
47 | - * @throws EE_Error |
|
48 | - * @throws EE_Error |
|
49 | - * @since 4.3.0 |
|
50 | - * |
|
51 | - */ |
|
52 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
53 | - { |
|
54 | - |
|
55 | - // required fields MUST be present, so let's make sure they are. |
|
56 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) { |
|
57 | - throw new EE_Error( |
|
58 | - esc_html__( |
|
59 | - 'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"', |
|
60 | - 'event_espresso' |
|
61 | - ) |
|
62 | - ); |
|
63 | - } |
|
64 | - |
|
65 | - // make sure we don't register twice |
|
66 | - if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
67 | - return true; |
|
68 | - } |
|
69 | - |
|
70 | - // make sure this was called in the right place! |
|
71 | - if ( |
|
72 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
73 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
74 | - ) { |
|
75 | - EE_Error::doing_it_wrong( |
|
76 | - __METHOD__, |
|
77 | - sprintf( |
|
78 | - esc_html__( |
|
79 | - 'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - $addon_name |
|
83 | - ), |
|
84 | - '4.3.0' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
89 | - 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
90 | - 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
|
91 | - ? (array) $setup_args['list_type_shortcodes'] : [], |
|
92 | - ]; |
|
93 | - |
|
94 | - // add filters |
|
95 | - add_filter( |
|
96 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
97 | - ['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'], |
|
98 | - 10 |
|
99 | - ); |
|
100 | - |
|
101 | - // add below filters if the required callback is provided. |
|
102 | - if (! empty($setup_args['msgr_validator_callback'])) { |
|
103 | - add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
|
104 | - } |
|
105 | - |
|
106 | - if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
107 | - add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
|
108 | - } |
|
109 | - |
|
110 | - if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
111 | - add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
|
112 | - } |
|
113 | - |
|
114 | - if (! empty($setup_args['list_type_shortcodes'])) { |
|
115 | - add_filter( |
|
116 | - 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
117 | - ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
|
118 | - 10 |
|
119 | - ); |
|
120 | - } |
|
121 | - return true; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * This deregisters any messages shortcode library previously registered with the given name. |
|
127 | - * |
|
128 | - * @param string $addon_name name used to register the shortcode library. |
|
129 | - * @return void |
|
130 | - * @since 4.3.0 |
|
131 | - */ |
|
132 | - public static function deregister(string $addon_name = '') |
|
133 | - { |
|
134 | - unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
140 | - * |
|
141 | - * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
142 | - * @return array |
|
143 | - * @since 4.3.0 |
|
144 | - * |
|
145 | - */ |
|
146 | - public static function register_msgs_autoload_paths(array $paths): array |
|
147 | - { |
|
148 | - $autoload_paths = []; |
|
149 | - if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
150 | - foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
|
151 | - if (empty($st_reg['autoloadpaths'])) { |
|
152 | - continue; |
|
153 | - } |
|
154 | - $autoload_paths[] = $st_reg['autoloadpaths']; |
|
155 | - } |
|
156 | - } |
|
157 | - return array_merge($paths, ...$autoload_paths); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes |
|
163 | - * filter which is used to add additional list type shortcodes. |
|
164 | - * |
|
165 | - * @param array $original_shortcodes |
|
166 | - * @return array Modifications to original shortcodes. |
|
167 | - * @since 4.3.0 |
|
168 | - * |
|
169 | - */ |
|
170 | - public static function register_list_type_shortcodes(array $original_shortcodes): array |
|
171 | - { |
|
172 | - if (empty(self::$_ee_messages_shortcode_registry)) { |
|
173 | - return $original_shortcodes; |
|
174 | - } |
|
175 | - $shortcodes = []; |
|
176 | - foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
|
177 | - if (! empty($sc_reg['list_type_shortcodes'])) { |
|
178 | - $shortcodes[] = $sc_reg['list_type_shortcodes']; |
|
179 | - } |
|
180 | - } |
|
181 | - return array_merge($original_shortcodes, ...$shortcodes); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - public static function reset(): void |
|
186 | - { |
|
187 | - self::$_ee_messages_shortcode_registry = []; |
|
188 | - } |
|
13 | + /** |
|
14 | + * holds values for registered messages shortcode libraries |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected static $_ee_messages_shortcode_registry = []; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * Helper method for registering a new shortcodes library class for the messages system. |
|
23 | + * |
|
24 | + * Note this is not used for adding shortcodes to existing libraries. It's for registering anything |
|
25 | + * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class. |
|
26 | + * |
|
27 | + * @param string $addon_name What is the name of this shortcode library (e.g. 'question_list'); |
|
28 | + * @param array $setup_args An array of arguments provided for registering the new messages shortcode library. |
|
29 | + * { |
|
30 | + * |
|
31 | + * @type array $autoloadpaths An array of paths to add to the messages autoloader |
|
32 | + * for the new shortcode library class file. |
|
33 | + * @type string $msgr_validator_callback Callback for a method that will register the library with the |
|
34 | + * messenger _validator_config. Optional. |
|
35 | + * @type string $msgr_template_fields_callback Callback for changing adding the _template_fields property for |
|
36 | + * messenger. For example, the shortcode library may add a new |
|
37 | + * field to the message templates. Optional. |
|
38 | + * @type string $valid_shortcodes_callback Callback for message types _valid_shortcodes array setup. |
|
39 | + * Optional. |
|
40 | + * @type array $list_type_shortcodes If there are any specific shortcodes with this message |
|
41 | + * shortcode library that should be considered "list type" |
|
42 | + * then include them in an array. |
|
43 | + * List Type shortcodes are shortcodes that have a corresponding |
|
44 | + * field that indicates how they are parsed. Optional. |
|
45 | + * } |
|
46 | + * @return bool |
|
47 | + * @throws EE_Error |
|
48 | + * @throws EE_Error |
|
49 | + * @since 4.3.0 |
|
50 | + * |
|
51 | + */ |
|
52 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
53 | + { |
|
54 | + |
|
55 | + // required fields MUST be present, so let's make sure they are. |
|
56 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) { |
|
57 | + throw new EE_Error( |
|
58 | + esc_html__( |
|
59 | + 'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"', |
|
60 | + 'event_espresso' |
|
61 | + ) |
|
62 | + ); |
|
63 | + } |
|
64 | + |
|
65 | + // make sure we don't register twice |
|
66 | + if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
67 | + return true; |
|
68 | + } |
|
69 | + |
|
70 | + // make sure this was called in the right place! |
|
71 | + if ( |
|
72 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
73 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
74 | + ) { |
|
75 | + EE_Error::doing_it_wrong( |
|
76 | + __METHOD__, |
|
77 | + sprintf( |
|
78 | + esc_html__( |
|
79 | + 'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + $addon_name |
|
83 | + ), |
|
84 | + '4.3.0' |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
89 | + 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
90 | + 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
|
91 | + ? (array) $setup_args['list_type_shortcodes'] : [], |
|
92 | + ]; |
|
93 | + |
|
94 | + // add filters |
|
95 | + add_filter( |
|
96 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
97 | + ['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'], |
|
98 | + 10 |
|
99 | + ); |
|
100 | + |
|
101 | + // add below filters if the required callback is provided. |
|
102 | + if (! empty($setup_args['msgr_validator_callback'])) { |
|
103 | + add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
|
104 | + } |
|
105 | + |
|
106 | + if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
107 | + add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
|
108 | + } |
|
109 | + |
|
110 | + if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
111 | + add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
|
112 | + } |
|
113 | + |
|
114 | + if (! empty($setup_args['list_type_shortcodes'])) { |
|
115 | + add_filter( |
|
116 | + 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
117 | + ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
|
118 | + 10 |
|
119 | + ); |
|
120 | + } |
|
121 | + return true; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * This deregisters any messages shortcode library previously registered with the given name. |
|
127 | + * |
|
128 | + * @param string $addon_name name used to register the shortcode library. |
|
129 | + * @return void |
|
130 | + * @since 4.3.0 |
|
131 | + */ |
|
132 | + public static function deregister(string $addon_name = '') |
|
133 | + { |
|
134 | + unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
140 | + * |
|
141 | + * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
142 | + * @return array |
|
143 | + * @since 4.3.0 |
|
144 | + * |
|
145 | + */ |
|
146 | + public static function register_msgs_autoload_paths(array $paths): array |
|
147 | + { |
|
148 | + $autoload_paths = []; |
|
149 | + if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
150 | + foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
|
151 | + if (empty($st_reg['autoloadpaths'])) { |
|
152 | + continue; |
|
153 | + } |
|
154 | + $autoload_paths[] = $st_reg['autoloadpaths']; |
|
155 | + } |
|
156 | + } |
|
157 | + return array_merge($paths, ...$autoload_paths); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes |
|
163 | + * filter which is used to add additional list type shortcodes. |
|
164 | + * |
|
165 | + * @param array $original_shortcodes |
|
166 | + * @return array Modifications to original shortcodes. |
|
167 | + * @since 4.3.0 |
|
168 | + * |
|
169 | + */ |
|
170 | + public static function register_list_type_shortcodes(array $original_shortcodes): array |
|
171 | + { |
|
172 | + if (empty(self::$_ee_messages_shortcode_registry)) { |
|
173 | + return $original_shortcodes; |
|
174 | + } |
|
175 | + $shortcodes = []; |
|
176 | + foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
|
177 | + if (! empty($sc_reg['list_type_shortcodes'])) { |
|
178 | + $shortcodes[] = $sc_reg['list_type_shortcodes']; |
|
179 | + } |
|
180 | + } |
|
181 | + return array_merge($original_shortcodes, ...$shortcodes); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + public static function reset(): void |
|
186 | + { |
|
187 | + self::$_ee_messages_shortcode_registry = []; |
|
188 | + } |
|
189 | 189 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register(string $addon_name = '', array $setup_args = []): bool |
31 | 31 | { |
32 | - self::$privacy_policies[ $addon_name ] = $setup_args; |
|
32 | + self::$privacy_policies[$addon_name] = $setup_args; |
|
33 | 33 | // add to list of modules to be registered |
34 | 34 | add_filter( |
35 | 35 | 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public static function deregister(string $addon_name = '') |
46 | 46 | { |
47 | - unset(self::$privacy_policies[ $addon_name ]); |
|
47 | + unset(self::$privacy_policies[$addon_name]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 |
@@ -12,57 +12,57 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_Privacy_Policy implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * FQCN for all privacy policy generators |
|
17 | - * |
|
18 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | - */ |
|
20 | - protected static $privacy_policies = []; |
|
15 | + /** |
|
16 | + * FQCN for all privacy policy generators |
|
17 | + * |
|
18 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | + */ |
|
20 | + protected static $privacy_policies = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $addon_name |
|
25 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | - * OR fully qualified class names of privacy policies |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | - { |
|
31 | - self::$privacy_policies[ $addon_name ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
35 | - ['EE_Register_Privacy_Policy', 'addPrivacyPolicies'] |
|
36 | - ); |
|
37 | - return true; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $addon_name |
|
25 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | + * OR fully qualified class names of privacy policies |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | + { |
|
31 | + self::$privacy_policies[ $addon_name ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
35 | + ['EE_Register_Privacy_Policy', 'addPrivacyPolicies'] |
|
36 | + ); |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $addon_name |
|
43 | - */ |
|
44 | - public static function deregister(string $addon_name = '') |
|
45 | - { |
|
46 | - unset(self::$privacy_policies[ $addon_name ]); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param string $addon_name |
|
43 | + */ |
|
44 | + public static function deregister(string $addon_name = '') |
|
45 | + { |
|
46 | + unset(self::$privacy_policies[ $addon_name ]); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Adds our privacy policy generators registered by add-ons |
|
52 | - * |
|
53 | - * @param string[] $privacy_policies |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public static function addPrivacyPolicies(array $privacy_policies): array |
|
57 | - { |
|
58 | - return array_merge($privacy_policies, ...self::$privacy_policies); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Adds our privacy policy generators registered by add-ons |
|
52 | + * |
|
53 | + * @param string[] $privacy_policies |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public static function addPrivacyPolicies(array $privacy_policies): array |
|
57 | + { |
|
58 | + return array_merge($privacy_policies, ...self::$privacy_policies); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - public static function reset(): void |
|
63 | - { |
|
64 | - self::$privacy_policies = []; |
|
65 | - } |
|
62 | + public static function reset(): void |
|
63 | + { |
|
64 | + self::$privacy_policies = []; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | // End of file EE_Register_Privacy_Policy.lib.php |
68 | 68 | // Location: ${NAMESPACE}/EE_Register_Privacy_Policy.lib.php |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ); |
60 | 60 | } |
61 | 61 | // make sure we don't register twice |
62 | - if (isset(self::$_settings[ $addon_name ])) { |
|
62 | + if (isset(self::$_settings[$addon_name])) { |
|
63 | 63 | return true; |
64 | 64 | } |
65 | 65 | // make sure this was called in the right place! |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | ); |
78 | 78 | } |
79 | 79 | // setup $_settings array from incoming values. |
80 | - self::$_settings[ $addon_name ] = [ |
|
80 | + self::$_settings[$addon_name] = [ |
|
81 | 81 | // array of full server paths to any EE_PMT_Base children used |
82 | 82 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
83 | 83 | ? (array) $setup_args['payment_method_paths'] |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
94 | 94 | $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
95 | 95 | // register payment methods directly |
96 | - foreach (self::$_settings[ $addon_name ]['payment_method_paths'] as $payment_method_path) { |
|
96 | + foreach (self::$_settings[$addon_name]['payment_method_paths'] as $payment_method_path) { |
|
97 | 97 | $payment_method_manager->register_payment_method($payment_method_path); |
98 | 98 | } |
99 | 99 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
100 | 100 | $capabilities->addCaps( |
101 | - self::getPaymentMethodCapabilities(self::$_settings[ $addon_name ]) |
|
101 | + self::getPaymentMethodCapabilities(self::$_settings[$addon_name]) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | return true; |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public static function deregister(string $addon_name = '') |
137 | 137 | { |
138 | - if (isset(self::$_settings[ $addon_name ])) { |
|
138 | + if (isset(self::$_settings[$addon_name])) { |
|
139 | 139 | // set action for just this module id to delay deregistration until core is loaded and ready. |
140 | - $module_settings = self::$_settings[ $addon_name ]; |
|
141 | - unset(self::$_settings[ $addon_name ]); |
|
140 | + $module_settings = self::$_settings[$addon_name]; |
|
141 | + unset(self::$_settings[$addon_name]); |
|
142 | 142 | add_action( |
143 | 143 | 'AHEE__EE_System__core_loaded_and_ready', |
144 | - function () use ($module_settings) { |
|
144 | + function() use ($module_settings) { |
|
145 | 145 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
146 | 146 | $capabilities->removeCaps( |
147 | 147 | EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
@@ -18,169 +18,169 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Register_Payment_Method implements EEI_Plugin_API |
20 | 20 | { |
21 | - /** |
|
22 | - * Holds values for registered payment methods |
|
23 | - * |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected static $_settings = []; |
|
21 | + /** |
|
22 | + * Holds values for registered payment methods |
|
23 | + * |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected static $_settings = []; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * Method for registering new EE_PMT_Base children |
|
31 | - * |
|
32 | - * @param string $addon_name a unique identifier for this set of modules Required. |
|
33 | - * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
34 | - * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
35 | - * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
36 | - * the files EE_PMT_Payomatic.pm.php) |
|
37 | - * } |
|
38 | - * @return bool |
|
39 | - * @throws EE_Error |
|
40 | - * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
41 | - * children, or to the EED_Module files themselves |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws DomainException |
|
44 | - * @throws InvalidArgumentException |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - * @throws InvalidDataTypeException |
|
47 | - * @since 4.5.0 |
|
48 | - */ |
|
49 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
50 | - { |
|
51 | - // required fields MUST be present, so let's make sure they are. |
|
52 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
53 | - throw new EE_Error( |
|
54 | - esc_html__( |
|
55 | - 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
56 | - 'event_espresso' |
|
57 | - ) |
|
58 | - ); |
|
59 | - } |
|
60 | - // make sure we don't register twice |
|
61 | - if (isset(self::$_settings[ $addon_name ])) { |
|
62 | - return true; |
|
63 | - } |
|
64 | - // make sure this was called in the right place! |
|
65 | - if ( |
|
66 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | - ) { |
|
69 | - EE_Error::doing_it_wrong( |
|
70 | - __METHOD__, |
|
71 | - esc_html__( |
|
72 | - 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - '4.3.0' |
|
76 | - ); |
|
77 | - } |
|
78 | - // setup $_settings array from incoming values. |
|
79 | - self::$_settings[ $addon_name ] = [ |
|
80 | - // array of full server paths to any EE_PMT_Base children used |
|
81 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
82 | - ? (array) $setup_args['payment_method_paths'] |
|
83 | - : [], |
|
84 | - ]; |
|
85 | - // add to list of modules to be registered |
|
86 | - add_filter( |
|
87 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
88 | - ['EE_Register_Payment_Method', 'add_payment_methods'] |
|
89 | - ); |
|
90 | - // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
91 | - // then we need to add our caps for this payment method manually |
|
92 | - if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
93 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
94 | - // register payment methods directly |
|
95 | - foreach (self::$_settings[ $addon_name ]['payment_method_paths'] as $payment_method_path) { |
|
96 | - $payment_method_manager->register_payment_method($payment_method_path); |
|
97 | - } |
|
98 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
99 | - $capabilities->addCaps( |
|
100 | - self::getPaymentMethodCapabilities(self::$_settings[ $addon_name ]) |
|
101 | - ); |
|
102 | - } |
|
103 | - return true; |
|
104 | - } |
|
29 | + /** |
|
30 | + * Method for registering new EE_PMT_Base children |
|
31 | + * |
|
32 | + * @param string $addon_name a unique identifier for this set of modules Required. |
|
33 | + * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
34 | + * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
35 | + * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
36 | + * the files EE_PMT_Payomatic.pm.php) |
|
37 | + * } |
|
38 | + * @return bool |
|
39 | + * @throws EE_Error |
|
40 | + * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
41 | + * children, or to the EED_Module files themselves |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws DomainException |
|
44 | + * @throws InvalidArgumentException |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + * @throws InvalidDataTypeException |
|
47 | + * @since 4.5.0 |
|
48 | + */ |
|
49 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
50 | + { |
|
51 | + // required fields MUST be present, so let's make sure they are. |
|
52 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
53 | + throw new EE_Error( |
|
54 | + esc_html__( |
|
55 | + 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
56 | + 'event_espresso' |
|
57 | + ) |
|
58 | + ); |
|
59 | + } |
|
60 | + // make sure we don't register twice |
|
61 | + if (isset(self::$_settings[ $addon_name ])) { |
|
62 | + return true; |
|
63 | + } |
|
64 | + // make sure this was called in the right place! |
|
65 | + if ( |
|
66 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | + ) { |
|
69 | + EE_Error::doing_it_wrong( |
|
70 | + __METHOD__, |
|
71 | + esc_html__( |
|
72 | + 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | + 'event_espresso' |
|
74 | + ), |
|
75 | + '4.3.0' |
|
76 | + ); |
|
77 | + } |
|
78 | + // setup $_settings array from incoming values. |
|
79 | + self::$_settings[ $addon_name ] = [ |
|
80 | + // array of full server paths to any EE_PMT_Base children used |
|
81 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
82 | + ? (array) $setup_args['payment_method_paths'] |
|
83 | + : [], |
|
84 | + ]; |
|
85 | + // add to list of modules to be registered |
|
86 | + add_filter( |
|
87 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
88 | + ['EE_Register_Payment_Method', 'add_payment_methods'] |
|
89 | + ); |
|
90 | + // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
91 | + // then we need to add our caps for this payment method manually |
|
92 | + if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
93 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
94 | + // register payment methods directly |
|
95 | + foreach (self::$_settings[ $addon_name ]['payment_method_paths'] as $payment_method_path) { |
|
96 | + $payment_method_manager->register_payment_method($payment_method_path); |
|
97 | + } |
|
98 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
99 | + $capabilities->addCaps( |
|
100 | + self::getPaymentMethodCapabilities(self::$_settings[ $addon_name ]) |
|
101 | + ); |
|
102 | + } |
|
103 | + return true; |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * Filters the list of payment methods to add ours. |
|
109 | - * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
110 | - * |
|
111 | - * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public static function add_payment_methods(array $payment_method_folders): array |
|
115 | - { |
|
116 | - $payment_method_paths = []; |
|
117 | - foreach (self::$_settings as $settings) { |
|
118 | - $payment_method_paths[] = $settings['payment_method_paths']; |
|
119 | - } |
|
120 | - return array_merge($payment_method_folders, ...$payment_method_paths); |
|
121 | - } |
|
107 | + /** |
|
108 | + * Filters the list of payment methods to add ours. |
|
109 | + * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
110 | + * |
|
111 | + * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public static function add_payment_methods(array $payment_method_folders): array |
|
115 | + { |
|
116 | + $payment_method_paths = []; |
|
117 | + foreach (self::$_settings as $settings) { |
|
118 | + $payment_method_paths[] = $settings['payment_method_paths']; |
|
119 | + } |
|
120 | + return array_merge($payment_method_folders, ...$payment_method_paths); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * This deregisters a module that was previously registered with a specific $addon_name. |
|
126 | - * |
|
127 | - * @param string $addon_name the name for the module that was previously registered |
|
128 | - * @return void |
|
129 | - * @throws DomainException |
|
130 | - * @throws InvalidArgumentException |
|
131 | - * @throws InvalidInterfaceException |
|
132 | - * @throws InvalidDataTypeException |
|
133 | - * @since 4.3.0 |
|
134 | - */ |
|
135 | - public static function deregister(string $addon_name = '') |
|
136 | - { |
|
137 | - if (isset(self::$_settings[ $addon_name ])) { |
|
138 | - // set action for just this module id to delay deregistration until core is loaded and ready. |
|
139 | - $module_settings = self::$_settings[ $addon_name ]; |
|
140 | - unset(self::$_settings[ $addon_name ]); |
|
141 | - add_action( |
|
142 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
143 | - function () use ($module_settings) { |
|
144 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
145 | - $capabilities->removeCaps( |
|
146 | - EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
147 | - ); |
|
148 | - } |
|
149 | - ); |
|
150 | - } |
|
151 | - } |
|
124 | + /** |
|
125 | + * This deregisters a module that was previously registered with a specific $addon_name. |
|
126 | + * |
|
127 | + * @param string $addon_name the name for the module that was previously registered |
|
128 | + * @return void |
|
129 | + * @throws DomainException |
|
130 | + * @throws InvalidArgumentException |
|
131 | + * @throws InvalidInterfaceException |
|
132 | + * @throws InvalidDataTypeException |
|
133 | + * @since 4.3.0 |
|
134 | + */ |
|
135 | + public static function deregister(string $addon_name = '') |
|
136 | + { |
|
137 | + if (isset(self::$_settings[ $addon_name ])) { |
|
138 | + // set action for just this module id to delay deregistration until core is loaded and ready. |
|
139 | + $module_settings = self::$_settings[ $addon_name ]; |
|
140 | + unset(self::$_settings[ $addon_name ]); |
|
141 | + add_action( |
|
142 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
143 | + function () use ($module_settings) { |
|
144 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
145 | + $capabilities->removeCaps( |
|
146 | + EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
147 | + ); |
|
148 | + } |
|
149 | + ); |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | 153 | |
154 | - /** |
|
155 | - * returns an array of the caps that get added when a Payment Method is registered |
|
156 | - * |
|
157 | - * @param array $settings |
|
158 | - * @return array |
|
159 | - * @throws DomainException |
|
160 | - * @throws InvalidArgumentException |
|
161 | - * @throws InvalidInterfaceException |
|
162 | - * @throws InvalidDataTypeException |
|
163 | - * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
164 | - * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
165 | - */ |
|
166 | - public static function getPaymentMethodCapabilities(array $settings): array |
|
167 | - { |
|
168 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
169 | - $payment_method_caps = ['administrator' => []]; |
|
170 | - if (isset($settings['payment_method_paths'])) { |
|
171 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
172 | - $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
173 | - strtolower(basename($payment_method_path)), |
|
174 | - $payment_method_caps |
|
175 | - ); |
|
176 | - } |
|
177 | - } |
|
178 | - return $payment_method_caps; |
|
179 | - } |
|
154 | + /** |
|
155 | + * returns an array of the caps that get added when a Payment Method is registered |
|
156 | + * |
|
157 | + * @param array $settings |
|
158 | + * @return array |
|
159 | + * @throws DomainException |
|
160 | + * @throws InvalidArgumentException |
|
161 | + * @throws InvalidInterfaceException |
|
162 | + * @throws InvalidDataTypeException |
|
163 | + * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
164 | + * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
165 | + */ |
|
166 | + public static function getPaymentMethodCapabilities(array $settings): array |
|
167 | + { |
|
168 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
169 | + $payment_method_caps = ['administrator' => []]; |
|
170 | + if (isset($settings['payment_method_paths'])) { |
|
171 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
172 | + $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
173 | + strtolower(basename($payment_method_path)), |
|
174 | + $payment_method_caps |
|
175 | + ); |
|
176 | + } |
|
177 | + } |
|
178 | + return $payment_method_caps; |
|
179 | + } |
|
180 | 180 | |
181 | 181 | |
182 | - public static function reset(): void |
|
183 | - { |
|
184 | - self::$_settings = []; |
|
185 | - } |
|
182 | + public static function reset(): void |
|
183 | + { |
|
184 | + self::$_settings = []; |
|
185 | + } |
|
186 | 186 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function setUUID(string $UUID) |
103 | 103 | { |
104 | - if (! Cuid::isCuid($UUID)) { |
|
104 | + if ( ! Cuid::isCuid($UUID)) { |
|
105 | 105 | throw new InvalidArgumentException( |
106 | 106 | sprintf( |
107 | 107 | /* translators: 1: UUID value, 2: UUID generator function. */ |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function attributes(): ?Attributes |
179 | 179 | { |
180 | - if (! $this->attributes instanceof Attributes) { |
|
180 | + if ( ! $this->attributes instanceof Attributes) { |
|
181 | 181 | $this->attributes = Attributes::fromJson($this->get('FSC_attributes')); |
182 | 182 | } |
183 | 183 | return $this->attributes; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $form_elements = $this->get_many_related('Form_Element', ['order_by' => ['FIN_order' => 'ASC']]); |
244 | 244 | foreach ($form_elements as $form_element) { |
245 | 245 | if ($form_element instanceof EE_Form_Element) { |
246 | - $this->form_elements[ $form_element->UUID() ] = $form_element; |
|
246 | + $this->form_elements[$form_element->UUID()] = $form_element; |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | return $this->form_elements; |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | foreach ($form_elements as $form_element) { |
261 | 261 | if ($form_element instanceof EE_Form_Element) { |
262 | 262 | $this->_add_relation_to($form_element->UUID(), 'Form_Element'); |
263 | - $this->form_elements[ $form_element->UUID() ] = $form_element; |
|
263 | + $this->form_elements[$form_element->UUID()] = $form_element; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | public function formElementFilter(): Closure |
292 | 292 | { |
293 | 293 | $FSC_UUID = strtolower($this->UUID()); |
294 | - return function ($form_element) use ($FSC_UUID) { |
|
294 | + return function($form_element) use ($FSC_UUID) { |
|
295 | 295 | return $form_element instanceof EE_Form_Element && strtolower($form_element->belongsTo()) === $FSC_UUID; |
296 | 296 | }; |
297 | 297 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function label(): ?FormLabel |
308 | 308 | { |
309 | - if (! $this->label instanceof FormLabel) { |
|
309 | + if ( ! $this->label instanceof FormLabel) { |
|
310 | 310 | $this->label = FormLabel::fromJson($this->get('FSC_label')); |
311 | 311 | } |
312 | 312 | return $this->label; |
@@ -25,494 +25,494 @@ |
||
25 | 25 | */ |
26 | 26 | class EE_Form_Section extends EE_Base_Class |
27 | 27 | { |
28 | - /** |
|
29 | - * @var Attributes |
|
30 | - */ |
|
31 | - private $attributes; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var EE_Form_Element[] |
|
35 | - */ |
|
36 | - private $form_elements = []; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var FormLabel |
|
40 | - */ |
|
41 | - private $label; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array $props_n_values |
|
47 | - * @return EE_Form_Section |
|
48 | - * @throws EE_Error |
|
49 | - * @throws ReflectionException |
|
50 | - */ |
|
51 | - public static function new_instance(array $props_n_values = []): EE_Form_Section |
|
52 | - { |
|
53 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
54 | - return $has_object ?: new self($props_n_values); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param array $props_n_values |
|
60 | - * @return EE_Form_Section |
|
61 | - * @throws EE_Error |
|
62 | - * @throws ReflectionException |
|
63 | - */ |
|
64 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Section |
|
65 | - { |
|
66 | - return new self($props_n_values, true); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Form Section UUID (universally unique identifier) |
|
72 | - * |
|
73 | - * @return string |
|
74 | - * @throws EE_Error |
|
75 | - * @throws ReflectionException |
|
76 | - */ |
|
77 | - public function UUID(): string |
|
78 | - { |
|
79 | - return $this->get('FSC_UUID'); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * last 8 characters of the UUID |
|
85 | - * |
|
86 | - * @return string |
|
87 | - * @throws EE_Error |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - public function uuidSlug(): string |
|
91 | - { |
|
92 | - return substr($this->UUID(), -8); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $UUID |
|
98 | - * @throws EE_Error |
|
99 | - * @throws ReflectionException |
|
100 | - */ |
|
101 | - public function setUUID(string $UUID) |
|
102 | - { |
|
103 | - if (! Cuid::isCuid($UUID)) { |
|
104 | - throw new InvalidArgumentException( |
|
105 | - sprintf( |
|
106 | - /* translators: 1: UUID value, 2: UUID generator function. */ |
|
107 | - esc_html__( |
|
108 | - 'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.', |
|
109 | - 'event_espresso' |
|
110 | - ), |
|
111 | - $UUID, |
|
112 | - "`Cuid::cuid()`" |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - $this->set('FSC_UUID', $UUID); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Form user types that this form section should be presented to. |
|
122 | - * Values correspond to the EEM_Form_Section::APPLIES_TO_* constants. |
|
123 | - * |
|
124 | - * @return string |
|
125 | - * @throws EE_Error |
|
126 | - * @throws ReflectionException |
|
127 | - */ |
|
128 | - public function appliesTo(): string |
|
129 | - { |
|
130 | - return $this->get('FSC_appliesTo'); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Form user types that this form section should be presented to. |
|
136 | - * Values correspond to the EEM_Form_Section::APPLIES_TO_* constants. |
|
137 | - * |
|
138 | - * @param EE_Registration|string $registrant |
|
139 | - * @return bool |
|
140 | - * @throws EE_Error |
|
141 | - * @throws ReflectionException |
|
142 | - */ |
|
143 | - public function appliesToRegistrant($registrant): bool |
|
144 | - { |
|
145 | - switch ($this->appliesTo()) { |
|
146 | - case EEM_Form_Section::APPLIES_TO_PRIMARY: |
|
147 | - return $registrant instanceof EE_Registration && $registrant->is_primary_registrant(); |
|
148 | - case EEM_Form_Section::APPLIES_TO_PURCHASER: |
|
149 | - return $registrant === 'purchaser'; |
|
150 | - case EEM_Form_Section::APPLIES_TO_REGISTRANTS: |
|
151 | - return $registrant instanceof EE_Registration && ! $registrant->is_primary_registrant(); |
|
152 | - case EEM_Form_Section::APPLIES_TO_ALL: |
|
153 | - default: |
|
154 | - return true; |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $user_type |
|
161 | - * @throws EE_Error |
|
162 | - * @throws ReflectionException |
|
163 | - */ |
|
164 | - public function setAppliesTo(string $user_type) |
|
165 | - { |
|
166 | - $this->set('FSC_appliesTo', $user_type); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * JSON string of HTML attributes, such as class, to be applied to this form section\'s container. |
|
172 | - * |
|
173 | - * @return Attributes |
|
174 | - * @throws EE_Error |
|
175 | - * @throws ReflectionException |
|
176 | - */ |
|
177 | - public function attributes(): ?Attributes |
|
178 | - { |
|
179 | - if (! $this->attributes instanceof Attributes) { |
|
180 | - $this->attributes = Attributes::fromJson($this->get('FSC_attributes')); |
|
181 | - } |
|
182 | - return $this->attributes; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param Attributes $attributes |
|
188 | - * @throws EE_Error |
|
189 | - * @throws ReflectionException |
|
190 | - */ |
|
191 | - public function setAttributes(Attributes $attributes) |
|
192 | - { |
|
193 | - // set local object |
|
194 | - $this->attributes = $attributes; |
|
195 | - // then pass to model as an array which will get converted to JSON by the model field |
|
196 | - $this->set('FSC_attributes', $attributes->toArray()); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * UUID or ID of related entity this form section belongs to. |
|
202 | - * |
|
203 | - * @return string |
|
204 | - * @throws EE_Error |
|
205 | - * @throws ReflectionException |
|
206 | - */ |
|
207 | - public function belongsTo(): ?string |
|
208 | - { |
|
209 | - return $this->get('FSC_belongsTo'); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @param string $parent_UUID |
|
215 | - * @throws EE_Error |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - public function setBelongsTo(string $parent_UUID) |
|
219 | - { |
|
220 | - $this->set('FSC_belongsTo', $parent_UUID); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @return EE_Form_Element[] |
|
226 | - * @throws EE_Error |
|
227 | - * @throws ReflectionException |
|
228 | - */ |
|
229 | - public function formElements(): array |
|
230 | - { |
|
231 | - return $this->form_elements ?: $this->getFormElements(); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @return EE_Form_Element[] |
|
237 | - * @throws EE_Error |
|
238 | - * @throws ReflectionException |
|
239 | - */ |
|
240 | - private function getFormElements(): array |
|
241 | - { |
|
242 | - $form_elements = $this->get_many_related('Form_Element', ['order_by' => ['FIN_order' => 'ASC']]); |
|
243 | - foreach ($form_elements as $form_element) { |
|
244 | - if ($form_element instanceof EE_Form_Element) { |
|
245 | - $this->form_elements[ $form_element->UUID() ] = $form_element; |
|
246 | - } |
|
247 | - } |
|
248 | - return $this->form_elements; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param EE_Form_Element[] $form_elements |
|
254 | - * @throws EE_Error |
|
255 | - * @throws ReflectionException |
|
256 | - */ |
|
257 | - public function setFormElements(array $form_elements): void |
|
258 | - { |
|
259 | - foreach ($form_elements as $form_element) { |
|
260 | - if ($form_element instanceof EE_Form_Element) { |
|
261 | - $this->_add_relation_to($form_element->UUID(), 'Form_Element'); |
|
262 | - $this->form_elements[ $form_element->UUID() ] = $form_element; |
|
263 | - } |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @param EE_Form_Element[] $all_form_elements |
|
270 | - * @return EE_Form_Element[] |
|
271 | - * @throws EE_Error |
|
272 | - * @throws ReflectionException |
|
273 | - */ |
|
274 | - public function filterFormElements(array $all_form_elements): array |
|
275 | - { |
|
276 | - return array_filter($all_form_elements, $this->formElementFilter()); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * returns a closure that can be used to filter form elements for this form section |
|
282 | - * usage: |
|
283 | - * $filter = EEM_Form_Element::formElementFilter(); |
|
284 | - * $filtered_form_elements = array_filter( $all_form_elements, $filter ); |
|
285 | - * |
|
286 | - * @return Closure |
|
287 | - * @throws EE_Error |
|
288 | - * @throws ReflectionException |
|
289 | - */ |
|
290 | - public function formElementFilter(): Closure |
|
291 | - { |
|
292 | - $FSC_UUID = strtolower($this->UUID()); |
|
293 | - return function ($form_element) use ($FSC_UUID) { |
|
294 | - return $form_element instanceof EE_Form_Element && strtolower($form_element->belongsTo()) === $FSC_UUID; |
|
295 | - }; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * returns a FormLabel object for managing form section labels, ie: the form section heading |
|
301 | - * |
|
302 | - * @return FormLabel |
|
303 | - * @throws EE_Error |
|
304 | - * @throws ReflectionException |
|
305 | - */ |
|
306 | - public function label(): ?FormLabel |
|
307 | - { |
|
308 | - if (! $this->label instanceof FormLabel) { |
|
309 | - $this->label = FormLabel::fromJson($this->get('FSC_label')); |
|
310 | - } |
|
311 | - return $this->label; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * @param FormLabel $label |
|
317 | - * @throws EE_Error |
|
318 | - * @throws ReflectionException |
|
319 | - */ |
|
320 | - public function setLabel(FormLabel $label) |
|
321 | - { |
|
322 | - // set local object |
|
323 | - $this->label = $label; |
|
324 | - // then pass to model as an array which will get converted to JSON by the model field |
|
325 | - $this->set('FSC_label', $label->toJson()); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Order in which form section appears in a form. |
|
331 | - * |
|
332 | - * @return int |
|
333 | - * @throws EE_Error |
|
334 | - * @throws ReflectionException |
|
335 | - */ |
|
336 | - public function order(): int |
|
337 | - { |
|
338 | - return $this->get('FSC_order'); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @param int $order |
|
344 | - * @throws EE_Error |
|
345 | - * @throws ReflectionException |
|
346 | - */ |
|
347 | - public function setOrder(int $order) |
|
348 | - { |
|
349 | - $this->set('FSC_order', $order); |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * combination of public label and UUID slug for use in identifiers |
|
355 | - * |
|
356 | - * @return string |
|
357 | - * @throws EE_Error |
|
358 | - * @throws ReflectionException |
|
359 | - */ |
|
360 | - public function slug(): ?string |
|
361 | - { |
|
362 | - $label = sanitize_title($this->label()->publicLabel()); |
|
363 | - return "{$label}-{$this->uuidSlug()}"; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * Whether form section is active, archived, trashed, or used as a default on new forms. |
|
369 | - * Values correspond to the EEM_Form_Section::STATUS_* constants. |
|
370 | - * |
|
371 | - * @return string |
|
372 | - * @throws EE_Error |
|
373 | - * @throws ReflectionException |
|
374 | - */ |
|
375 | - public function status(): ?string |
|
376 | - { |
|
377 | - return $this->get('FSC_status'); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Whether form section is active, archived, trashed, or used as a default on new forms. |
|
383 | - * Values correspond to the EEM_Form_Section::STATUS_* constants. |
|
384 | - * |
|
385 | - * @param string $status |
|
386 | - * @throws EE_Error |
|
387 | - * @throws ReflectionException |
|
388 | - */ |
|
389 | - public function setStatus(string $status) |
|
390 | - { |
|
391 | - $this->set('FSC_status', $status); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * returns the id the wordpress user who created this question |
|
397 | - * |
|
398 | - * @return int |
|
399 | - * @throws EE_Error |
|
400 | - * @throws ReflectionException |
|
401 | - */ |
|
402 | - public function wp_user(): int |
|
403 | - { |
|
404 | - return $this->get('FSC_wpUser'); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @param int $wp_user |
|
410 | - * @throws EE_Error |
|
411 | - * @throws ReflectionException |
|
412 | - */ |
|
413 | - public function setWpUser(int $wp_user) |
|
414 | - { |
|
415 | - $this->set('FSC_wpUser', $wp_user); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * @param array $set_cols_n_values |
|
421 | - * @return bool|int|string |
|
422 | - * @throws EE_Error |
|
423 | - * @throws ReflectionException |
|
424 | - */ |
|
425 | - public function save($set_cols_n_values = []) |
|
426 | - { |
|
427 | - // make sure internal versions for all composite objects are updated |
|
428 | - $this->set('FSC_attributes', $this->attributes()->toArray()); |
|
429 | - $this->set('FSC_label', $this->label()->toArray()); |
|
430 | - return parent::save($set_cols_n_values); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Whether the section is active. |
|
435 | - * |
|
436 | - * @return boolean TRUE if is active, FALSE if not. |
|
437 | - * @throws ReflectionException |
|
438 | - * @throws InvalidArgumentException |
|
439 | - * @throws InvalidInterfaceException |
|
440 | - * @throws InvalidDataTypeException |
|
441 | - * @throws EE_Error |
|
442 | - */ |
|
443 | - public function isActive(): bool |
|
444 | - { |
|
445 | - return $this->status() === FormStatus::ACTIVE; |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Whether the section is archived. |
|
450 | - * |
|
451 | - * @return boolean TRUE if is archived, FALSE if not. |
|
452 | - * @throws ReflectionException |
|
453 | - * @throws InvalidArgumentException |
|
454 | - * @throws InvalidInterfaceException |
|
455 | - * @throws InvalidDataTypeException |
|
456 | - * @throws EE_Error |
|
457 | - */ |
|
458 | - public function isArchived(): bool |
|
459 | - { |
|
460 | - return $this->status() === FormStatus::ARCHIVED; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * Whether the section is a default one. |
|
465 | - * |
|
466 | - * @return boolean TRUE if is default, FALSE if not. |
|
467 | - * @throws ReflectionException |
|
468 | - * @throws InvalidArgumentException |
|
469 | - * @throws InvalidInterfaceException |
|
470 | - * @throws InvalidDataTypeException |
|
471 | - * @throws EE_Error |
|
472 | - */ |
|
473 | - public function isDefault(): bool |
|
474 | - { |
|
475 | - return $this->status() === FormStatus::DEFAULT; |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Whether the section is a shared one. |
|
480 | - * |
|
481 | - * @return boolean TRUE if is shared, FALSE if not. |
|
482 | - * @throws ReflectionException |
|
483 | - * @throws InvalidArgumentException |
|
484 | - * @throws InvalidInterfaceException |
|
485 | - * @throws InvalidDataTypeException |
|
486 | - * @throws EE_Error |
|
487 | - */ |
|
488 | - public function isShared(): bool |
|
489 | - { |
|
490 | - return $this->status() === FormStatus::SHARED; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Whether the section is trashed. |
|
495 | - * |
|
496 | - * @return boolean TRUE if is trashed, FALSE if not. |
|
497 | - * @throws ReflectionException |
|
498 | - * @throws InvalidArgumentException |
|
499 | - * @throws InvalidInterfaceException |
|
500 | - * @throws InvalidDataTypeException |
|
501 | - * @throws EE_Error |
|
502 | - */ |
|
503 | - public function isTrashed(): bool |
|
504 | - { |
|
505 | - return $this->status() === FormStatus::TRASHED; |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * @return bool |
|
511 | - * @throws EE_Error |
|
512 | - * @throws ReflectionException |
|
513 | - */ |
|
514 | - public function isTopLevelFormSection(): bool |
|
515 | - { |
|
516 | - return empty($this->belongsTo()); |
|
517 | - } |
|
28 | + /** |
|
29 | + * @var Attributes |
|
30 | + */ |
|
31 | + private $attributes; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var EE_Form_Element[] |
|
35 | + */ |
|
36 | + private $form_elements = []; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var FormLabel |
|
40 | + */ |
|
41 | + private $label; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array $props_n_values |
|
47 | + * @return EE_Form_Section |
|
48 | + * @throws EE_Error |
|
49 | + * @throws ReflectionException |
|
50 | + */ |
|
51 | + public static function new_instance(array $props_n_values = []): EE_Form_Section |
|
52 | + { |
|
53 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
54 | + return $has_object ?: new self($props_n_values); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param array $props_n_values |
|
60 | + * @return EE_Form_Section |
|
61 | + * @throws EE_Error |
|
62 | + * @throws ReflectionException |
|
63 | + */ |
|
64 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Section |
|
65 | + { |
|
66 | + return new self($props_n_values, true); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Form Section UUID (universally unique identifier) |
|
72 | + * |
|
73 | + * @return string |
|
74 | + * @throws EE_Error |
|
75 | + * @throws ReflectionException |
|
76 | + */ |
|
77 | + public function UUID(): string |
|
78 | + { |
|
79 | + return $this->get('FSC_UUID'); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * last 8 characters of the UUID |
|
85 | + * |
|
86 | + * @return string |
|
87 | + * @throws EE_Error |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + public function uuidSlug(): string |
|
91 | + { |
|
92 | + return substr($this->UUID(), -8); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $UUID |
|
98 | + * @throws EE_Error |
|
99 | + * @throws ReflectionException |
|
100 | + */ |
|
101 | + public function setUUID(string $UUID) |
|
102 | + { |
|
103 | + if (! Cuid::isCuid($UUID)) { |
|
104 | + throw new InvalidArgumentException( |
|
105 | + sprintf( |
|
106 | + /* translators: 1: UUID value, 2: UUID generator function. */ |
|
107 | + esc_html__( |
|
108 | + 'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.', |
|
109 | + 'event_espresso' |
|
110 | + ), |
|
111 | + $UUID, |
|
112 | + "`Cuid::cuid()`" |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + $this->set('FSC_UUID', $UUID); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Form user types that this form section should be presented to. |
|
122 | + * Values correspond to the EEM_Form_Section::APPLIES_TO_* constants. |
|
123 | + * |
|
124 | + * @return string |
|
125 | + * @throws EE_Error |
|
126 | + * @throws ReflectionException |
|
127 | + */ |
|
128 | + public function appliesTo(): string |
|
129 | + { |
|
130 | + return $this->get('FSC_appliesTo'); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Form user types that this form section should be presented to. |
|
136 | + * Values correspond to the EEM_Form_Section::APPLIES_TO_* constants. |
|
137 | + * |
|
138 | + * @param EE_Registration|string $registrant |
|
139 | + * @return bool |
|
140 | + * @throws EE_Error |
|
141 | + * @throws ReflectionException |
|
142 | + */ |
|
143 | + public function appliesToRegistrant($registrant): bool |
|
144 | + { |
|
145 | + switch ($this->appliesTo()) { |
|
146 | + case EEM_Form_Section::APPLIES_TO_PRIMARY: |
|
147 | + return $registrant instanceof EE_Registration && $registrant->is_primary_registrant(); |
|
148 | + case EEM_Form_Section::APPLIES_TO_PURCHASER: |
|
149 | + return $registrant === 'purchaser'; |
|
150 | + case EEM_Form_Section::APPLIES_TO_REGISTRANTS: |
|
151 | + return $registrant instanceof EE_Registration && ! $registrant->is_primary_registrant(); |
|
152 | + case EEM_Form_Section::APPLIES_TO_ALL: |
|
153 | + default: |
|
154 | + return true; |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $user_type |
|
161 | + * @throws EE_Error |
|
162 | + * @throws ReflectionException |
|
163 | + */ |
|
164 | + public function setAppliesTo(string $user_type) |
|
165 | + { |
|
166 | + $this->set('FSC_appliesTo', $user_type); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * JSON string of HTML attributes, such as class, to be applied to this form section\'s container. |
|
172 | + * |
|
173 | + * @return Attributes |
|
174 | + * @throws EE_Error |
|
175 | + * @throws ReflectionException |
|
176 | + */ |
|
177 | + public function attributes(): ?Attributes |
|
178 | + { |
|
179 | + if (! $this->attributes instanceof Attributes) { |
|
180 | + $this->attributes = Attributes::fromJson($this->get('FSC_attributes')); |
|
181 | + } |
|
182 | + return $this->attributes; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param Attributes $attributes |
|
188 | + * @throws EE_Error |
|
189 | + * @throws ReflectionException |
|
190 | + */ |
|
191 | + public function setAttributes(Attributes $attributes) |
|
192 | + { |
|
193 | + // set local object |
|
194 | + $this->attributes = $attributes; |
|
195 | + // then pass to model as an array which will get converted to JSON by the model field |
|
196 | + $this->set('FSC_attributes', $attributes->toArray()); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * UUID or ID of related entity this form section belongs to. |
|
202 | + * |
|
203 | + * @return string |
|
204 | + * @throws EE_Error |
|
205 | + * @throws ReflectionException |
|
206 | + */ |
|
207 | + public function belongsTo(): ?string |
|
208 | + { |
|
209 | + return $this->get('FSC_belongsTo'); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @param string $parent_UUID |
|
215 | + * @throws EE_Error |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + public function setBelongsTo(string $parent_UUID) |
|
219 | + { |
|
220 | + $this->set('FSC_belongsTo', $parent_UUID); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @return EE_Form_Element[] |
|
226 | + * @throws EE_Error |
|
227 | + * @throws ReflectionException |
|
228 | + */ |
|
229 | + public function formElements(): array |
|
230 | + { |
|
231 | + return $this->form_elements ?: $this->getFormElements(); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @return EE_Form_Element[] |
|
237 | + * @throws EE_Error |
|
238 | + * @throws ReflectionException |
|
239 | + */ |
|
240 | + private function getFormElements(): array |
|
241 | + { |
|
242 | + $form_elements = $this->get_many_related('Form_Element', ['order_by' => ['FIN_order' => 'ASC']]); |
|
243 | + foreach ($form_elements as $form_element) { |
|
244 | + if ($form_element instanceof EE_Form_Element) { |
|
245 | + $this->form_elements[ $form_element->UUID() ] = $form_element; |
|
246 | + } |
|
247 | + } |
|
248 | + return $this->form_elements; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param EE_Form_Element[] $form_elements |
|
254 | + * @throws EE_Error |
|
255 | + * @throws ReflectionException |
|
256 | + */ |
|
257 | + public function setFormElements(array $form_elements): void |
|
258 | + { |
|
259 | + foreach ($form_elements as $form_element) { |
|
260 | + if ($form_element instanceof EE_Form_Element) { |
|
261 | + $this->_add_relation_to($form_element->UUID(), 'Form_Element'); |
|
262 | + $this->form_elements[ $form_element->UUID() ] = $form_element; |
|
263 | + } |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @param EE_Form_Element[] $all_form_elements |
|
270 | + * @return EE_Form_Element[] |
|
271 | + * @throws EE_Error |
|
272 | + * @throws ReflectionException |
|
273 | + */ |
|
274 | + public function filterFormElements(array $all_form_elements): array |
|
275 | + { |
|
276 | + return array_filter($all_form_elements, $this->formElementFilter()); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * returns a closure that can be used to filter form elements for this form section |
|
282 | + * usage: |
|
283 | + * $filter = EEM_Form_Element::formElementFilter(); |
|
284 | + * $filtered_form_elements = array_filter( $all_form_elements, $filter ); |
|
285 | + * |
|
286 | + * @return Closure |
|
287 | + * @throws EE_Error |
|
288 | + * @throws ReflectionException |
|
289 | + */ |
|
290 | + public function formElementFilter(): Closure |
|
291 | + { |
|
292 | + $FSC_UUID = strtolower($this->UUID()); |
|
293 | + return function ($form_element) use ($FSC_UUID) { |
|
294 | + return $form_element instanceof EE_Form_Element && strtolower($form_element->belongsTo()) === $FSC_UUID; |
|
295 | + }; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * returns a FormLabel object for managing form section labels, ie: the form section heading |
|
301 | + * |
|
302 | + * @return FormLabel |
|
303 | + * @throws EE_Error |
|
304 | + * @throws ReflectionException |
|
305 | + */ |
|
306 | + public function label(): ?FormLabel |
|
307 | + { |
|
308 | + if (! $this->label instanceof FormLabel) { |
|
309 | + $this->label = FormLabel::fromJson($this->get('FSC_label')); |
|
310 | + } |
|
311 | + return $this->label; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * @param FormLabel $label |
|
317 | + * @throws EE_Error |
|
318 | + * @throws ReflectionException |
|
319 | + */ |
|
320 | + public function setLabel(FormLabel $label) |
|
321 | + { |
|
322 | + // set local object |
|
323 | + $this->label = $label; |
|
324 | + // then pass to model as an array which will get converted to JSON by the model field |
|
325 | + $this->set('FSC_label', $label->toJson()); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Order in which form section appears in a form. |
|
331 | + * |
|
332 | + * @return int |
|
333 | + * @throws EE_Error |
|
334 | + * @throws ReflectionException |
|
335 | + */ |
|
336 | + public function order(): int |
|
337 | + { |
|
338 | + return $this->get('FSC_order'); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @param int $order |
|
344 | + * @throws EE_Error |
|
345 | + * @throws ReflectionException |
|
346 | + */ |
|
347 | + public function setOrder(int $order) |
|
348 | + { |
|
349 | + $this->set('FSC_order', $order); |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * combination of public label and UUID slug for use in identifiers |
|
355 | + * |
|
356 | + * @return string |
|
357 | + * @throws EE_Error |
|
358 | + * @throws ReflectionException |
|
359 | + */ |
|
360 | + public function slug(): ?string |
|
361 | + { |
|
362 | + $label = sanitize_title($this->label()->publicLabel()); |
|
363 | + return "{$label}-{$this->uuidSlug()}"; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * Whether form section is active, archived, trashed, or used as a default on new forms. |
|
369 | + * Values correspond to the EEM_Form_Section::STATUS_* constants. |
|
370 | + * |
|
371 | + * @return string |
|
372 | + * @throws EE_Error |
|
373 | + * @throws ReflectionException |
|
374 | + */ |
|
375 | + public function status(): ?string |
|
376 | + { |
|
377 | + return $this->get('FSC_status'); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Whether form section is active, archived, trashed, or used as a default on new forms. |
|
383 | + * Values correspond to the EEM_Form_Section::STATUS_* constants. |
|
384 | + * |
|
385 | + * @param string $status |
|
386 | + * @throws EE_Error |
|
387 | + * @throws ReflectionException |
|
388 | + */ |
|
389 | + public function setStatus(string $status) |
|
390 | + { |
|
391 | + $this->set('FSC_status', $status); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * returns the id the wordpress user who created this question |
|
397 | + * |
|
398 | + * @return int |
|
399 | + * @throws EE_Error |
|
400 | + * @throws ReflectionException |
|
401 | + */ |
|
402 | + public function wp_user(): int |
|
403 | + { |
|
404 | + return $this->get('FSC_wpUser'); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @param int $wp_user |
|
410 | + * @throws EE_Error |
|
411 | + * @throws ReflectionException |
|
412 | + */ |
|
413 | + public function setWpUser(int $wp_user) |
|
414 | + { |
|
415 | + $this->set('FSC_wpUser', $wp_user); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * @param array $set_cols_n_values |
|
421 | + * @return bool|int|string |
|
422 | + * @throws EE_Error |
|
423 | + * @throws ReflectionException |
|
424 | + */ |
|
425 | + public function save($set_cols_n_values = []) |
|
426 | + { |
|
427 | + // make sure internal versions for all composite objects are updated |
|
428 | + $this->set('FSC_attributes', $this->attributes()->toArray()); |
|
429 | + $this->set('FSC_label', $this->label()->toArray()); |
|
430 | + return parent::save($set_cols_n_values); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Whether the section is active. |
|
435 | + * |
|
436 | + * @return boolean TRUE if is active, FALSE if not. |
|
437 | + * @throws ReflectionException |
|
438 | + * @throws InvalidArgumentException |
|
439 | + * @throws InvalidInterfaceException |
|
440 | + * @throws InvalidDataTypeException |
|
441 | + * @throws EE_Error |
|
442 | + */ |
|
443 | + public function isActive(): bool |
|
444 | + { |
|
445 | + return $this->status() === FormStatus::ACTIVE; |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Whether the section is archived. |
|
450 | + * |
|
451 | + * @return boolean TRUE if is archived, FALSE if not. |
|
452 | + * @throws ReflectionException |
|
453 | + * @throws InvalidArgumentException |
|
454 | + * @throws InvalidInterfaceException |
|
455 | + * @throws InvalidDataTypeException |
|
456 | + * @throws EE_Error |
|
457 | + */ |
|
458 | + public function isArchived(): bool |
|
459 | + { |
|
460 | + return $this->status() === FormStatus::ARCHIVED; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * Whether the section is a default one. |
|
465 | + * |
|
466 | + * @return boolean TRUE if is default, FALSE if not. |
|
467 | + * @throws ReflectionException |
|
468 | + * @throws InvalidArgumentException |
|
469 | + * @throws InvalidInterfaceException |
|
470 | + * @throws InvalidDataTypeException |
|
471 | + * @throws EE_Error |
|
472 | + */ |
|
473 | + public function isDefault(): bool |
|
474 | + { |
|
475 | + return $this->status() === FormStatus::DEFAULT; |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Whether the section is a shared one. |
|
480 | + * |
|
481 | + * @return boolean TRUE if is shared, FALSE if not. |
|
482 | + * @throws ReflectionException |
|
483 | + * @throws InvalidArgumentException |
|
484 | + * @throws InvalidInterfaceException |
|
485 | + * @throws InvalidDataTypeException |
|
486 | + * @throws EE_Error |
|
487 | + */ |
|
488 | + public function isShared(): bool |
|
489 | + { |
|
490 | + return $this->status() === FormStatus::SHARED; |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Whether the section is trashed. |
|
495 | + * |
|
496 | + * @return boolean TRUE if is trashed, FALSE if not. |
|
497 | + * @throws ReflectionException |
|
498 | + * @throws InvalidArgumentException |
|
499 | + * @throws InvalidInterfaceException |
|
500 | + * @throws InvalidDataTypeException |
|
501 | + * @throws EE_Error |
|
502 | + */ |
|
503 | + public function isTrashed(): bool |
|
504 | + { |
|
505 | + return $this->status() === FormStatus::TRASHED; |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * @return bool |
|
511 | + * @throws EE_Error |
|
512 | + * @throws ReflectionException |
|
513 | + */ |
|
514 | + public function isTopLevelFormSection(): bool |
|
515 | + { |
|
516 | + return empty($this->belongsTo()); |
|
517 | + } |
|
518 | 518 | } |