Completed
Branch back-compat-edtr-taxes (752e0e)
by
unknown
12:08 queued 09:43
created
strategies/validation/EE_Text_Validation_Strategy.strategy.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -11,53 +11,53 @@
 block discarded – undo
11 11
 class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13 13
 
14
-    protected $_regex = null;
15
-    /**
16
-     *
17
-     * @param string $validation_error_message
18
-     * @param string $regex a PHP regex; the javascript regex will be derived from this
19
-     */
20
-    public function __construct($validation_error_message = null, $regex = null)
21
-    {
22
-        $this->_regex = $regex;
23
-        parent::__construct($validation_error_message);
24
-    }
14
+	protected $_regex = null;
15
+	/**
16
+	 *
17
+	 * @param string $validation_error_message
18
+	 * @param string $regex a PHP regex; the javascript regex will be derived from this
19
+	 */
20
+	public function __construct($validation_error_message = null, $regex = null)
21
+	{
22
+		$this->_regex = $regex;
23
+		parent::__construct($validation_error_message);
24
+	}
25 25
 
26
-    /**
27
-     * @param $normalized_value
28
-     */
29
-    public function validate($normalized_value)
30
-    {
31
-        $string_normalized_value = (string) $normalized_value;
32
-        if ($this->_regex &&  $string_normalized_value) {
33
-            if (! preg_match($this->_regex, $string_normalized_value)) {
34
-                throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35
-            }
36
-        }
37
-    }
26
+	/**
27
+	 * @param $normalized_value
28
+	 */
29
+	public function validate($normalized_value)
30
+	{
31
+		$string_normalized_value = (string) $normalized_value;
32
+		if ($this->_regex &&  $string_normalized_value) {
33
+			if (! preg_match($this->_regex, $string_normalized_value)) {
34
+				throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35
+			}
36
+		}
37
+	}
38 38
 
39
-    /**
40
-     * @return array
41
-     */
42
-    public function get_jquery_validation_rule_array()
43
-    {
44
-        if ($this->_regex !== null) {
45
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
46
-        } else {
47
-            return array();
48
-        }
49
-    }
39
+	/**
40
+	 * @return array
41
+	 */
42
+	public function get_jquery_validation_rule_array()
43
+	{
44
+		if ($this->_regex !== null) {
45
+			return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
46
+		} else {
47
+			return array();
48
+		}
49
+	}
50 50
 
51 51
 /**
52 52
  * Translates a PHP regex into a javscript regex (eg, PHP needs separate delimieters, whereas
53 53
  * javscript does not
54 54
  * @return string
55 55
  */
56
-    public function regex_js()
57
-    {
58
-        // first character must be the delimiter
59
-        $delimeter = $this->_regex[0];
60
-        $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
61
-        return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
62
-    }
56
+	public function regex_js()
57
+	{
58
+		// first character must be the delimiter
59
+		$delimeter = $this->_regex[0];
60
+		$last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
61
+		return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
     public function validate($normalized_value)
30 30
     {
31 31
         $string_normalized_value = (string) $normalized_value;
32
-        if ($this->_regex &&  $string_normalized_value) {
33
-            if (! preg_match($this->_regex, $string_normalized_value)) {
32
+        if ($this->_regex && $string_normalized_value) {
33
+            if ( ! preg_match($this->_regex, $string_normalized_value)) {
34 34
                 throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35 35
             }
36 36
         }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public function get_jquery_validation_rule_array()
43 43
     {
44 44
         if ($this->_regex !== null) {
45
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
+            return array('regex' => $this->regex_js(), 'messages' => array('regex' => $this->get_validation_error_message()));
46 46
         } else {
47 47
             return array();
48 48
         }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +639 added lines, -639 removed lines patch added patch discarded remove patch
@@ -29,643 +29,643 @@
 block discarded – undo
29 29
 abstract class FormHandler implements FormHandlerInterface
30 30
 {
31 31
 
32
-    /**
33
-     * will add opening and closing HTML form tags as well as a submit button
34
-     */
35
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
36
-
37
-    /**
38
-     * will add opening and closing HTML form tags but NOT a submit button
39
-     */
40
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
41
-
42
-    /**
43
-     * will NOT add opening and closing HTML form tags but will add a submit button
44
-     */
45
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
46
-
47
-    /**
48
-     * will NOT add opening and closing HTML form tags NOR a submit button
49
-     */
50
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
51
-
52
-    /**
53
-     * if set to false, then this form has no displayable content,
54
-     * and will only be used for processing data sent passed via GET or POST
55
-     * defaults to true ( ie: form has displayable content )
56
-     *
57
-     * @var boolean $displayable
58
-     */
59
-    private $displayable = true;
60
-
61
-    /**
62
-     * @var string $form_name
63
-     */
64
-    private $form_name;
65
-
66
-    /**
67
-     * @var string $admin_name
68
-     */
69
-    private $admin_name;
70
-
71
-    /**
72
-     * @var string $slug
73
-     */
74
-    private $slug;
75
-
76
-    /**
77
-     * @var string $submit_btn_text
78
-     */
79
-    private $submit_btn_text;
80
-
81
-    /**
82
-     * @var string $form_action
83
-     */
84
-    private $form_action;
85
-
86
-    /**
87
-     * form params in key value pairs
88
-     * can be added to form action URL or as hidden inputs
89
-     *
90
-     * @var array $form_args
91
-     */
92
-    private $form_args = array();
93
-
94
-    /**
95
-     * value of one of the string constant above
96
-     *
97
-     * @var string $form_config
98
-     */
99
-    private $form_config;
100
-
101
-    /**
102
-     * whether or not the form was determined to be invalid
103
-     *
104
-     * @var boolean $form_has_errors
105
-     */
106
-    private $form_has_errors;
107
-
108
-    /**
109
-     * the absolute top level form section being used on the page
110
-     *
111
-     * @var EE_Form_Section_Proper $form
112
-     */
113
-    private $form;
114
-
115
-    /**
116
-     * @var EE_Registry $registry
117
-     */
118
-    protected $registry;
119
-
120
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
121
-    /**
122
-     * Form constructor.
123
-     *
124
-     * @param string      $form_name
125
-     * @param string      $admin_name
126
-     * @param string      $slug
127
-     * @param string      $form_action
128
-     * @param string      $form_config
129
-     * @param EE_Registry $registry
130
-     * @throws InvalidDataTypeException
131
-     * @throws DomainException
132
-     * @throws InvalidArgumentException
133
-     */
134
-    public function __construct(
135
-        $form_name,
136
-        $admin_name,
137
-        $slug,
138
-        $form_action = '',
139
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
140
-        EE_Registry $registry
141
-    ) {
142
-        $this->setFormName($form_name);
143
-        $this->setAdminName($admin_name);
144
-        $this->setSlug($slug);
145
-        $this->setFormAction($form_action);
146
-        $this->setFormConfig($form_config);
147
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
148
-        $this->registry = $registry;
149
-    }
150
-
151
-
152
-    /**
153
-     * @return array
154
-     */
155
-    public static function getFormConfigConstants()
156
-    {
157
-        return array(
158
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
159
-            FormHandler::ADD_FORM_TAGS_ONLY,
160
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
161
-            FormHandler::DO_NOT_SETUP_FORM,
162
-        );
163
-    }
164
-
165
-
166
-    /**
167
-     * @param bool $for_display
168
-     * @return EE_Form_Section_Proper
169
-     * @throws EE_Error
170
-     * @throws LogicException
171
-     */
172
-    public function form($for_display = false)
173
-    {
174
-        if (! $this->formIsValid()) {
175
-            return null;
176
-        }
177
-        if ($for_display) {
178
-            $form_config = $this->formConfig();
179
-            if (
180
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
181
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
182
-            ) {
183
-                $this->appendSubmitButton();
184
-                $this->clearFormButtonFloats();
185
-            }
186
-        }
187
-        return $this->form;
188
-    }
189
-
190
-
191
-    /**
192
-     * @return boolean
193
-     * @throws LogicException
194
-     */
195
-    public function formIsValid()
196
-    {
197
-        if ($this->form instanceof EE_Form_Section_Proper) {
198
-            return true;
199
-        }
200
-        $form = apply_filters(
201
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
202
-            $this->generate(),
203
-            $this
204
-        );
205
-        if ($this->verifyForm($form)) {
206
-            $this->setForm($form);
207
-        }
208
-        return true;
209
-    }
210
-
211
-
212
-    /**
213
-     * @param EE_Form_Section_Proper|null $form
214
-     * @return bool
215
-     * @throws LogicException
216
-     */
217
-    public function verifyForm(EE_Form_Section_Proper $form = null)
218
-    {
219
-        $form = $form !== null ? $form : $this->form;
220
-        if ($form instanceof EE_Form_Section_Proper) {
221
-            return true;
222
-        }
223
-        throw new LogicException(
224
-            sprintf(
225
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
226
-                $this->form_name,
227
-                var_export($form, true)
228
-            )
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * @param EE_Form_Section_Proper $form
235
-     */
236
-    public function setForm(EE_Form_Section_Proper $form)
237
-    {
238
-        $this->form = $form;
239
-    }
240
-
241
-
242
-    /**
243
-     * @return boolean
244
-     */
245
-    public function displayable()
246
-    {
247
-        return $this->displayable;
248
-    }
249
-
250
-
251
-    /**
252
-     * @param boolean $displayable
253
-     */
254
-    public function setDisplayable($displayable = false)
255
-    {
256
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
257
-    }
258
-
259
-
260
-    /**
261
-     * a public name for the form that can be displayed on the frontend of a site
262
-     *
263
-     * @return string
264
-     */
265
-    public function formName()
266
-    {
267
-        return $this->form_name;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param string $form_name
273
-     * @throws InvalidDataTypeException
274
-     */
275
-    public function setFormName($form_name)
276
-    {
277
-        if (! is_string($form_name)) {
278
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279
-        }
280
-        $this->form_name = $form_name;
281
-    }
282
-
283
-
284
-    /**
285
-     * a public name for the form that can be displayed, but only in the admin
286
-     *
287
-     * @return string
288
-     */
289
-    public function adminName()
290
-    {
291
-        return $this->admin_name;
292
-    }
293
-
294
-
295
-    /**
296
-     * @param string $admin_name
297
-     * @throws InvalidDataTypeException
298
-     */
299
-    public function setAdminName($admin_name)
300
-    {
301
-        if (! is_string($admin_name)) {
302
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303
-        }
304
-        $this->admin_name = $admin_name;
305
-    }
306
-
307
-
308
-    /**
309
-     * a URL friendly string that can be used for identifying the form
310
-     *
311
-     * @return string
312
-     */
313
-    public function slug()
314
-    {
315
-        return $this->slug;
316
-    }
317
-
318
-
319
-    /**
320
-     * @param string $slug
321
-     * @throws InvalidDataTypeException
322
-     */
323
-    public function setSlug($slug)
324
-    {
325
-        if (! is_string($slug)) {
326
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
327
-        }
328
-        $this->slug = $slug;
329
-    }
330
-
331
-
332
-    /**
333
-     * @return string
334
-     */
335
-    public function submitBtnText()
336
-    {
337
-        return $this->submit_btn_text;
338
-    }
339
-
340
-
341
-    /**
342
-     * @param string $submit_btn_text
343
-     * @throws InvalidDataTypeException
344
-     * @throws InvalidArgumentException
345
-     */
346
-    public function setSubmitBtnText($submit_btn_text)
347
-    {
348
-        if (! is_string($submit_btn_text)) {
349
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350
-        }
351
-        if (empty($submit_btn_text)) {
352
-            throw new InvalidArgumentException(
353
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
354
-            );
355
-        }
356
-        $this->submit_btn_text = $submit_btn_text;
357
-    }
358
-
359
-
360
-    /**
361
-     * @return string
362
-     */
363
-    public function formAction()
364
-    {
365
-        return ! empty($this->form_args)
366
-            ? add_query_arg($this->form_args, $this->form_action)
367
-            : $this->form_action;
368
-    }
369
-
370
-
371
-    /**
372
-     * @param string $form_action
373
-     * @throws InvalidDataTypeException
374
-     */
375
-    public function setFormAction($form_action)
376
-    {
377
-        if (! is_string($form_action)) {
378
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379
-        }
380
-        $this->form_action = $form_action;
381
-    }
382
-
383
-
384
-    /**
385
-     * @param array $form_args
386
-     * @throws InvalidDataTypeException
387
-     * @throws InvalidArgumentException
388
-     */
389
-    public function addFormActionArgs($form_args = array())
390
-    {
391
-        if (is_object($form_args)) {
392
-            throw new InvalidDataTypeException(
393
-                '$form_args',
394
-                $form_args,
395
-                'anything other than an object was expected.'
396
-            );
397
-        }
398
-        if (empty($form_args)) {
399
-            throw new InvalidArgumentException(
400
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
401
-            );
402
-        }
403
-        $this->form_args = array_merge($this->form_args, $form_args);
404
-    }
405
-
406
-
407
-    /**
408
-     * @return string
409
-     */
410
-    public function formConfig()
411
-    {
412
-        return $this->form_config;
413
-    }
414
-
415
-
416
-    /**
417
-     * @param string $form_config
418
-     * @throws DomainException
419
-     */
420
-    public function setFormConfig($form_config)
421
-    {
422
-        if (
423
-            ! in_array(
424
-                $form_config,
425
-                array(
426
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
427
-                FormHandler::ADD_FORM_TAGS_ONLY,
428
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
429
-                FormHandler::DO_NOT_SETUP_FORM,
430
-                ),
431
-                true
432
-            )
433
-        ) {
434
-            throw new DomainException(
435
-                sprintf(
436
-                    esc_html__(
437
-                        '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
438
-                        'event_espresso'
439
-                    ),
440
-                    $form_config
441
-                )
442
-            );
443
-        }
444
-        $this->form_config = $form_config;
445
-    }
446
-
447
-
448
-    /**
449
-     * called after the form is instantiated
450
-     * and used for performing any logic that needs to occur early
451
-     * before any of the other methods are called.
452
-     * returns true if everything is ok to proceed,
453
-     * and false if no further form logic should be implemented
454
-     *
455
-     * @return boolean
456
-     */
457
-    public function initialize()
458
-    {
459
-        $this->form_has_errors = EE_Error::has_error(true);
460
-        return true;
461
-    }
462
-
463
-
464
-    /**
465
-     * used for setting up css and js
466
-     *
467
-     * @return void
468
-     * @throws LogicException
469
-     * @throws EE_Error
470
-     */
471
-    public function enqueueStylesAndScripts()
472
-    {
473
-        $this->form()->enqueue_js();
474
-    }
475
-
476
-
477
-    /**
478
-     * creates and returns the actual form
479
-     *
480
-     * @return EE_Form_Section_Proper
481
-     */
482
-    abstract public function generate();
483
-
484
-
485
-    /**
486
-     * creates and returns an EE_Submit_Input labeled "Submit"
487
-     *
488
-     * @param string $text
489
-     * @return EE_Submit_Input
490
-     */
491
-    public function generateSubmitButton($text = '')
492
-    {
493
-        $text = ! empty($text) ? $text : $this->submitBtnText();
494
-        return new EE_Submit_Input(
495
-            array(
496
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
497
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
498
-                'html_class'            => 'ee-form-submit',
499
-                'html_label'            => ' ',
500
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
501
-                'default'               => $text,
502
-            )
503
-        );
504
-    }
505
-
506
-
507
-    /**
508
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
509
-     *
510
-     * @param string $text
511
-     * @return void
512
-     * @throws EE_Error
513
-     */
514
-    public function appendSubmitButton($text = '')
515
-    {
516
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
517
-            return;
518
-        }
519
-        $this->form->add_subsections(
520
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
521
-            null,
522
-            false
523
-        );
524
-    }
525
-
526
-
527
-    /**
528
-     * creates and returns an EE_Submit_Input labeled "Cancel"
529
-     *
530
-     * @param string $text
531
-     * @return EE_Submit_Input
532
-     */
533
-    public function generateCancelButton($text = '')
534
-    {
535
-        $cancel_button = new EE_Submit_Input(
536
-            array(
537
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
539
-                'html_class'            => 'ee-cancel-form',
540
-                'html_label'            => ' ',
541
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
542
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543
-            )
544
-        );
545
-        $cancel_button->set_button_css_attributes(false);
546
-        return $cancel_button;
547
-    }
548
-
549
-
550
-    /**
551
-     * appends a float clearing div onto end of form
552
-     *
553
-     * @return void
554
-     * @throws EE_Error
555
-     */
556
-    public function clearFormButtonFloats()
557
-    {
558
-        $this->form->add_subsections(
559
-            array(
560
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
562
-                ),
563
-            ),
564
-            null,
565
-            false
566
-        );
567
-    }
568
-
569
-
570
-    /**
571
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
572
-     * returns a string of HTML that can be directly echoed in a template
573
-     *
574
-     * @return string
575
-     * @throws \InvalidArgumentException
576
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
577
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
578
-     * @throws LogicException
579
-     * @throws EE_Error
580
-     */
581
-    public function display()
582
-    {
583
-        $form_html = apply_filters(
584
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
585
-            ''
586
-        );
587
-        $form_config = $this->formConfig();
588
-        if (
589
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
590
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
591
-        ) {
592
-            $additional_props = $this->requiresMultipartEnctype()
593
-                ? 'enctype="multipart/form-data"'
594
-                : '';
595
-            $form_html .= $this->form()->form_open(
596
-                $this->formAction(),
597
-                'POST',
598
-                $additional_props
599
-            );
600
-        }
601
-        $form_html .= $this->form(true)->get_html();
602
-        if (
603
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
604
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
605
-        ) {
606
-            $form_html .= $this->form()->form_close();
607
-        }
608
-        $form_html .= apply_filters(
609
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
610
-            ''
611
-        );
612
-        return $form_html;
613
-    }
614
-
615
-    /**
616
-     * Determines if this form needs "enctype='multipart/form-data'" or not.
617
-     * @since 4.9.80.p
618
-     * @return bool
619
-     * @throws EE_Error
620
-     */
621
-    public function requiresMultipartEnctype()
622
-    {
623
-        foreach ($this->form()->inputs_in_subsections() as $input) {
624
-            if ($input instanceof EE_File_Input) {
625
-                return true;
626
-            }
627
-        }
628
-        return false;
629
-    }
630
-
631
-
632
-    /**
633
-     * handles processing the form submission
634
-     * returns true or false depending on whether the form was processed successfully or not
635
-     *
636
-     * @param array $submitted_form_data
637
-     * @return array
638
-     * @throws \InvalidArgumentException
639
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
640
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
641
-     * @throws EE_Error
642
-     * @throws LogicException
643
-     * @throws InvalidFormSubmissionException
644
-     */
645
-    public function process($submitted_form_data = array())
646
-    {
647
-        if (! $this->form()->was_submitted($submitted_form_data)) {
648
-            throw new InvalidFormSubmissionException($this->form_name);
649
-        }
650
-        $this->form(true)->receive_form_submission($submitted_form_data);
651
-        if (! $this->form()->is_valid()) {
652
-            throw new InvalidFormSubmissionException(
653
-                $this->form_name,
654
-                sprintf(
655
-                    esc_html__(
656
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
657
-                        'event_espresso'
658
-                    ),
659
-                    $this->form_name,
660
-                    '<br />',
661
-                    implode('<br />', $this->form()->get_validation_errors_accumulated())
662
-                )
663
-            );
664
-        }
665
-        return apply_filters(
666
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
667
-            $this->form()->valid_data(),
668
-            $this
669
-        );
670
-    }
32
+	/**
33
+	 * will add opening and closing HTML form tags as well as a submit button
34
+	 */
35
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
36
+
37
+	/**
38
+	 * will add opening and closing HTML form tags but NOT a submit button
39
+	 */
40
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
41
+
42
+	/**
43
+	 * will NOT add opening and closing HTML form tags but will add a submit button
44
+	 */
45
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
46
+
47
+	/**
48
+	 * will NOT add opening and closing HTML form tags NOR a submit button
49
+	 */
50
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
51
+
52
+	/**
53
+	 * if set to false, then this form has no displayable content,
54
+	 * and will only be used for processing data sent passed via GET or POST
55
+	 * defaults to true ( ie: form has displayable content )
56
+	 *
57
+	 * @var boolean $displayable
58
+	 */
59
+	private $displayable = true;
60
+
61
+	/**
62
+	 * @var string $form_name
63
+	 */
64
+	private $form_name;
65
+
66
+	/**
67
+	 * @var string $admin_name
68
+	 */
69
+	private $admin_name;
70
+
71
+	/**
72
+	 * @var string $slug
73
+	 */
74
+	private $slug;
75
+
76
+	/**
77
+	 * @var string $submit_btn_text
78
+	 */
79
+	private $submit_btn_text;
80
+
81
+	/**
82
+	 * @var string $form_action
83
+	 */
84
+	private $form_action;
85
+
86
+	/**
87
+	 * form params in key value pairs
88
+	 * can be added to form action URL or as hidden inputs
89
+	 *
90
+	 * @var array $form_args
91
+	 */
92
+	private $form_args = array();
93
+
94
+	/**
95
+	 * value of one of the string constant above
96
+	 *
97
+	 * @var string $form_config
98
+	 */
99
+	private $form_config;
100
+
101
+	/**
102
+	 * whether or not the form was determined to be invalid
103
+	 *
104
+	 * @var boolean $form_has_errors
105
+	 */
106
+	private $form_has_errors;
107
+
108
+	/**
109
+	 * the absolute top level form section being used on the page
110
+	 *
111
+	 * @var EE_Form_Section_Proper $form
112
+	 */
113
+	private $form;
114
+
115
+	/**
116
+	 * @var EE_Registry $registry
117
+	 */
118
+	protected $registry;
119
+
120
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
121
+	/**
122
+	 * Form constructor.
123
+	 *
124
+	 * @param string      $form_name
125
+	 * @param string      $admin_name
126
+	 * @param string      $slug
127
+	 * @param string      $form_action
128
+	 * @param string      $form_config
129
+	 * @param EE_Registry $registry
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws DomainException
132
+	 * @throws InvalidArgumentException
133
+	 */
134
+	public function __construct(
135
+		$form_name,
136
+		$admin_name,
137
+		$slug,
138
+		$form_action = '',
139
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
140
+		EE_Registry $registry
141
+	) {
142
+		$this->setFormName($form_name);
143
+		$this->setAdminName($admin_name);
144
+		$this->setSlug($slug);
145
+		$this->setFormAction($form_action);
146
+		$this->setFormConfig($form_config);
147
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
148
+		$this->registry = $registry;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return array
154
+	 */
155
+	public static function getFormConfigConstants()
156
+	{
157
+		return array(
158
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
159
+			FormHandler::ADD_FORM_TAGS_ONLY,
160
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
161
+			FormHandler::DO_NOT_SETUP_FORM,
162
+		);
163
+	}
164
+
165
+
166
+	/**
167
+	 * @param bool $for_display
168
+	 * @return EE_Form_Section_Proper
169
+	 * @throws EE_Error
170
+	 * @throws LogicException
171
+	 */
172
+	public function form($for_display = false)
173
+	{
174
+		if (! $this->formIsValid()) {
175
+			return null;
176
+		}
177
+		if ($for_display) {
178
+			$form_config = $this->formConfig();
179
+			if (
180
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
181
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
182
+			) {
183
+				$this->appendSubmitButton();
184
+				$this->clearFormButtonFloats();
185
+			}
186
+		}
187
+		return $this->form;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @return boolean
193
+	 * @throws LogicException
194
+	 */
195
+	public function formIsValid()
196
+	{
197
+		if ($this->form instanceof EE_Form_Section_Proper) {
198
+			return true;
199
+		}
200
+		$form = apply_filters(
201
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
202
+			$this->generate(),
203
+			$this
204
+		);
205
+		if ($this->verifyForm($form)) {
206
+			$this->setForm($form);
207
+		}
208
+		return true;
209
+	}
210
+
211
+
212
+	/**
213
+	 * @param EE_Form_Section_Proper|null $form
214
+	 * @return bool
215
+	 * @throws LogicException
216
+	 */
217
+	public function verifyForm(EE_Form_Section_Proper $form = null)
218
+	{
219
+		$form = $form !== null ? $form : $this->form;
220
+		if ($form instanceof EE_Form_Section_Proper) {
221
+			return true;
222
+		}
223
+		throw new LogicException(
224
+			sprintf(
225
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
226
+				$this->form_name,
227
+				var_export($form, true)
228
+			)
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * @param EE_Form_Section_Proper $form
235
+	 */
236
+	public function setForm(EE_Form_Section_Proper $form)
237
+	{
238
+		$this->form = $form;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @return boolean
244
+	 */
245
+	public function displayable()
246
+	{
247
+		return $this->displayable;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @param boolean $displayable
253
+	 */
254
+	public function setDisplayable($displayable = false)
255
+	{
256
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
257
+	}
258
+
259
+
260
+	/**
261
+	 * a public name for the form that can be displayed on the frontend of a site
262
+	 *
263
+	 * @return string
264
+	 */
265
+	public function formName()
266
+	{
267
+		return $this->form_name;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param string $form_name
273
+	 * @throws InvalidDataTypeException
274
+	 */
275
+	public function setFormName($form_name)
276
+	{
277
+		if (! is_string($form_name)) {
278
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279
+		}
280
+		$this->form_name = $form_name;
281
+	}
282
+
283
+
284
+	/**
285
+	 * a public name for the form that can be displayed, but only in the admin
286
+	 *
287
+	 * @return string
288
+	 */
289
+	public function adminName()
290
+	{
291
+		return $this->admin_name;
292
+	}
293
+
294
+
295
+	/**
296
+	 * @param string $admin_name
297
+	 * @throws InvalidDataTypeException
298
+	 */
299
+	public function setAdminName($admin_name)
300
+	{
301
+		if (! is_string($admin_name)) {
302
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303
+		}
304
+		$this->admin_name = $admin_name;
305
+	}
306
+
307
+
308
+	/**
309
+	 * a URL friendly string that can be used for identifying the form
310
+	 *
311
+	 * @return string
312
+	 */
313
+	public function slug()
314
+	{
315
+		return $this->slug;
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param string $slug
321
+	 * @throws InvalidDataTypeException
322
+	 */
323
+	public function setSlug($slug)
324
+	{
325
+		if (! is_string($slug)) {
326
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
327
+		}
328
+		$this->slug = $slug;
329
+	}
330
+
331
+
332
+	/**
333
+	 * @return string
334
+	 */
335
+	public function submitBtnText()
336
+	{
337
+		return $this->submit_btn_text;
338
+	}
339
+
340
+
341
+	/**
342
+	 * @param string $submit_btn_text
343
+	 * @throws InvalidDataTypeException
344
+	 * @throws InvalidArgumentException
345
+	 */
346
+	public function setSubmitBtnText($submit_btn_text)
347
+	{
348
+		if (! is_string($submit_btn_text)) {
349
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350
+		}
351
+		if (empty($submit_btn_text)) {
352
+			throw new InvalidArgumentException(
353
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
354
+			);
355
+		}
356
+		$this->submit_btn_text = $submit_btn_text;
357
+	}
358
+
359
+
360
+	/**
361
+	 * @return string
362
+	 */
363
+	public function formAction()
364
+	{
365
+		return ! empty($this->form_args)
366
+			? add_query_arg($this->form_args, $this->form_action)
367
+			: $this->form_action;
368
+	}
369
+
370
+
371
+	/**
372
+	 * @param string $form_action
373
+	 * @throws InvalidDataTypeException
374
+	 */
375
+	public function setFormAction($form_action)
376
+	{
377
+		if (! is_string($form_action)) {
378
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379
+		}
380
+		$this->form_action = $form_action;
381
+	}
382
+
383
+
384
+	/**
385
+	 * @param array $form_args
386
+	 * @throws InvalidDataTypeException
387
+	 * @throws InvalidArgumentException
388
+	 */
389
+	public function addFormActionArgs($form_args = array())
390
+	{
391
+		if (is_object($form_args)) {
392
+			throw new InvalidDataTypeException(
393
+				'$form_args',
394
+				$form_args,
395
+				'anything other than an object was expected.'
396
+			);
397
+		}
398
+		if (empty($form_args)) {
399
+			throw new InvalidArgumentException(
400
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
401
+			);
402
+		}
403
+		$this->form_args = array_merge($this->form_args, $form_args);
404
+	}
405
+
406
+
407
+	/**
408
+	 * @return string
409
+	 */
410
+	public function formConfig()
411
+	{
412
+		return $this->form_config;
413
+	}
414
+
415
+
416
+	/**
417
+	 * @param string $form_config
418
+	 * @throws DomainException
419
+	 */
420
+	public function setFormConfig($form_config)
421
+	{
422
+		if (
423
+			! in_array(
424
+				$form_config,
425
+				array(
426
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
427
+				FormHandler::ADD_FORM_TAGS_ONLY,
428
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
429
+				FormHandler::DO_NOT_SETUP_FORM,
430
+				),
431
+				true
432
+			)
433
+		) {
434
+			throw new DomainException(
435
+				sprintf(
436
+					esc_html__(
437
+						'"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
438
+						'event_espresso'
439
+					),
440
+					$form_config
441
+				)
442
+			);
443
+		}
444
+		$this->form_config = $form_config;
445
+	}
446
+
447
+
448
+	/**
449
+	 * called after the form is instantiated
450
+	 * and used for performing any logic that needs to occur early
451
+	 * before any of the other methods are called.
452
+	 * returns true if everything is ok to proceed,
453
+	 * and false if no further form logic should be implemented
454
+	 *
455
+	 * @return boolean
456
+	 */
457
+	public function initialize()
458
+	{
459
+		$this->form_has_errors = EE_Error::has_error(true);
460
+		return true;
461
+	}
462
+
463
+
464
+	/**
465
+	 * used for setting up css and js
466
+	 *
467
+	 * @return void
468
+	 * @throws LogicException
469
+	 * @throws EE_Error
470
+	 */
471
+	public function enqueueStylesAndScripts()
472
+	{
473
+		$this->form()->enqueue_js();
474
+	}
475
+
476
+
477
+	/**
478
+	 * creates and returns the actual form
479
+	 *
480
+	 * @return EE_Form_Section_Proper
481
+	 */
482
+	abstract public function generate();
483
+
484
+
485
+	/**
486
+	 * creates and returns an EE_Submit_Input labeled "Submit"
487
+	 *
488
+	 * @param string $text
489
+	 * @return EE_Submit_Input
490
+	 */
491
+	public function generateSubmitButton($text = '')
492
+	{
493
+		$text = ! empty($text) ? $text : $this->submitBtnText();
494
+		return new EE_Submit_Input(
495
+			array(
496
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
497
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
498
+				'html_class'            => 'ee-form-submit',
499
+				'html_label'            => '&nbsp;',
500
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
501
+				'default'               => $text,
502
+			)
503
+		);
504
+	}
505
+
506
+
507
+	/**
508
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
509
+	 *
510
+	 * @param string $text
511
+	 * @return void
512
+	 * @throws EE_Error
513
+	 */
514
+	public function appendSubmitButton($text = '')
515
+	{
516
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
517
+			return;
518
+		}
519
+		$this->form->add_subsections(
520
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
521
+			null,
522
+			false
523
+		);
524
+	}
525
+
526
+
527
+	/**
528
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
529
+	 *
530
+	 * @param string $text
531
+	 * @return EE_Submit_Input
532
+	 */
533
+	public function generateCancelButton($text = '')
534
+	{
535
+		$cancel_button = new EE_Submit_Input(
536
+			array(
537
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
539
+				'html_class'            => 'ee-cancel-form',
540
+				'html_label'            => '&nbsp;',
541
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
542
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543
+			)
544
+		);
545
+		$cancel_button->set_button_css_attributes(false);
546
+		return $cancel_button;
547
+	}
548
+
549
+
550
+	/**
551
+	 * appends a float clearing div onto end of form
552
+	 *
553
+	 * @return void
554
+	 * @throws EE_Error
555
+	 */
556
+	public function clearFormButtonFloats()
557
+	{
558
+		$this->form->add_subsections(
559
+			array(
560
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
562
+				),
563
+			),
564
+			null,
565
+			false
566
+		);
567
+	}
568
+
569
+
570
+	/**
571
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
572
+	 * returns a string of HTML that can be directly echoed in a template
573
+	 *
574
+	 * @return string
575
+	 * @throws \InvalidArgumentException
576
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
577
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
578
+	 * @throws LogicException
579
+	 * @throws EE_Error
580
+	 */
581
+	public function display()
582
+	{
583
+		$form_html = apply_filters(
584
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
585
+			''
586
+		);
587
+		$form_config = $this->formConfig();
588
+		if (
589
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
590
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
591
+		) {
592
+			$additional_props = $this->requiresMultipartEnctype()
593
+				? 'enctype="multipart/form-data"'
594
+				: '';
595
+			$form_html .= $this->form()->form_open(
596
+				$this->formAction(),
597
+				'POST',
598
+				$additional_props
599
+			);
600
+		}
601
+		$form_html .= $this->form(true)->get_html();
602
+		if (
603
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
604
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
605
+		) {
606
+			$form_html .= $this->form()->form_close();
607
+		}
608
+		$form_html .= apply_filters(
609
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
610
+			''
611
+		);
612
+		return $form_html;
613
+	}
614
+
615
+	/**
616
+	 * Determines if this form needs "enctype='multipart/form-data'" or not.
617
+	 * @since 4.9.80.p
618
+	 * @return bool
619
+	 * @throws EE_Error
620
+	 */
621
+	public function requiresMultipartEnctype()
622
+	{
623
+		foreach ($this->form()->inputs_in_subsections() as $input) {
624
+			if ($input instanceof EE_File_Input) {
625
+				return true;
626
+			}
627
+		}
628
+		return false;
629
+	}
630
+
631
+
632
+	/**
633
+	 * handles processing the form submission
634
+	 * returns true or false depending on whether the form was processed successfully or not
635
+	 *
636
+	 * @param array $submitted_form_data
637
+	 * @return array
638
+	 * @throws \InvalidArgumentException
639
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
640
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
641
+	 * @throws EE_Error
642
+	 * @throws LogicException
643
+	 * @throws InvalidFormSubmissionException
644
+	 */
645
+	public function process($submitted_form_data = array())
646
+	{
647
+		if (! $this->form()->was_submitted($submitted_form_data)) {
648
+			throw new InvalidFormSubmissionException($this->form_name);
649
+		}
650
+		$this->form(true)->receive_form_submission($submitted_form_data);
651
+		if (! $this->form()->is_valid()) {
652
+			throw new InvalidFormSubmissionException(
653
+				$this->form_name,
654
+				sprintf(
655
+					esc_html__(
656
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
657
+						'event_espresso'
658
+					),
659
+					$this->form_name,
660
+					'<br />',
661
+					implode('<br />', $this->form()->get_validation_errors_accumulated())
662
+				)
663
+			);
664
+		}
665
+		return apply_filters(
666
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
667
+			$this->form()->valid_data(),
668
+			$this
669
+		);
670
+	}
671 671
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function form($for_display = false)
173 173
     {
174
-        if (! $this->formIsValid()) {
174
+        if ( ! $this->formIsValid()) {
175 175
             return null;
176 176
         }
177 177
         if ($for_display) {
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      */
275 275
     public function setFormName($form_name)
276 276
     {
277
-        if (! is_string($form_name)) {
277
+        if ( ! is_string($form_name)) {
278 278
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279 279
         }
280 280
         $this->form_name = $form_name;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public function setAdminName($admin_name)
300 300
     {
301
-        if (! is_string($admin_name)) {
301
+        if ( ! is_string($admin_name)) {
302 302
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303 303
         }
304 304
         $this->admin_name = $admin_name;
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public function setSlug($slug)
324 324
     {
325
-        if (! is_string($slug)) {
325
+        if ( ! is_string($slug)) {
326 326
             throw new InvalidDataTypeException('$slug', $slug, 'string');
327 327
         }
328 328
         $this->slug = $slug;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
      */
346 346
     public function setSubmitBtnText($submit_btn_text)
347 347
     {
348
-        if (! is_string($submit_btn_text)) {
348
+        if ( ! is_string($submit_btn_text)) {
349 349
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350 350
         }
351 351
         if (empty($submit_btn_text)) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function setFormAction($form_action)
376 376
     {
377
-        if (! is_string($form_action)) {
377
+        if ( ! is_string($form_action)) {
378 378
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379 379
         }
380 380
         $this->form_action = $form_action;
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
         $text = ! empty($text) ? $text : $this->submitBtnText();
494 494
         return new EE_Submit_Input(
495 495
             array(
496
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
497
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
496
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
497
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
498 498
                 'html_class'            => 'ee-form-submit',
499 499
                 'html_label'            => '&nbsp;',
500
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
500
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
501 501
                 'default'               => $text,
502 502
             )
503 503
         );
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
      */
514 514
     public function appendSubmitButton($text = '')
515 515
     {
516
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
516
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
517 517
             return;
518 518
         }
519 519
         $this->form->add_subsections(
520
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
520
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
521 521
             null,
522 522
             false
523 523
         );
@@ -534,11 +534,11 @@  discard block
 block discarded – undo
534 534
     {
535 535
         $cancel_button = new EE_Submit_Input(
536 536
             array(
537
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
538
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
539 539
                 'html_class'            => 'ee-cancel-form',
540 540
                 'html_label'            => '&nbsp;',
541
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
541
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
542 542
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543 543
             )
544 544
         );
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
         $this->form->add_subsections(
559 559
             array(
560 560
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
561
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
562 562
                 ),
563 563
             ),
564 564
             null,
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
      */
645 645
     public function process($submitted_form_data = array())
646 646
     {
647
-        if (! $this->form()->was_submitted($submitted_form_data)) {
647
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
648 648
             throw new InvalidFormSubmissionException($this->form_name);
649 649
         }
650 650
         $this->form(true)->receive_form_submission($submitted_form_data);
651
-        if (! $this->form()->is_valid()) {
651
+        if ( ! $this->form()->is_valid()) {
652 652
             throw new InvalidFormSubmissionException(
653 653
                 $this->form_name,
654 654
                 sprintf(
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 2 patches
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -19,228 +19,228 @@
 block discarded – undo
19 19
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
20 20
 {
21 21
 
22
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
23
-
24
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
25
-
26
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
27
-
28
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
29
-
30
-    /**
31
-     * numerical value used for sorting form steps
32
-     *
33
-     * @var int $order
34
-     */
35
-    private $order = 1;
36
-
37
-    /**
38
-     * a final URL with all form related parameters added
39
-     * that will be used to advance to the next step
40
-     *
41
-     * @var string $redirect_url
42
-     */
43
-    private $redirect_url = '';
44
-
45
-    /**
46
-     * URL params in key value pairs
47
-     *
48
-     * @var array $redirect_args
49
-     */
50
-    private $redirect_args = array();
51
-
52
-    /**
53
-     * Which step should be redirected to after form processing.
54
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
55
-     * If a form is invalid and requires errors to be corrected,
56
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
57
-     * Some form handlers do not have a form that is displayable,
58
-     * and only perform data processing, but if an error occurs,
59
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
60
-     * since the current step has no displayable content.
61
-     * if the form is completely finished, and needs to redirect to somewhere
62
-     * completely different, then this value will be REDIRECT_TO_OTHER
63
-     *
64
-     * @var string $redirect_to
65
-     */
66
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
67
-
68
-
69
-
70
-    /**
71
-     * SequentialStepForm constructor
72
-     *
73
-     * @param int         $order
74
-     * @param string      $form_name
75
-     * @param string      $admin_name
76
-     * @param string      $slug
77
-     * @param string      $form_action
78
-     * @param string      $form_config
79
-     * @param EE_Registry $registry
80
-     * @throws InvalidArgumentException
81
-     * @throws InvalidDataTypeException
82
-     * @throws DomainException
83
-     */
84
-    public function __construct(
85
-        $order,
86
-        $form_name,
87
-        $admin_name,
88
-        $slug,
89
-        $form_action = '',
90
-        $form_config = 'add_form_tags_and_submit',
91
-        EE_Registry $registry
92
-    ) {
93
-        $this->setOrder($order);
94
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * @return int
101
-     */
102
-    public function order()
103
-    {
104
-        return $this->order;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @param int $order
111
-     * @throws InvalidArgumentException
112
-     */
113
-    public function setOrder($order)
114
-    {
115
-        $order = absint($order);
116
-        if (! $order > 0) {
117
-            throw new InvalidArgumentException(
118
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
119
-            );
120
-        }
121
-        $this->order = $order;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @return string
128
-     */
129
-    public function redirectUrl()
130
-    {
131
-        return ! empty($this->redirect_args)
132
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
133
-            : $this->redirect_url;
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * @param string $redirect_url
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidArgumentException
142
-     */
143
-    public function setRedirectUrl($redirect_url)
144
-    {
145
-        if (! is_string($redirect_url)) {
146
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
147
-        }
148
-        if (empty($redirect_url)) {
149
-            throw new InvalidArgumentException(
150
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
151
-            );
152
-        }
153
-        $this->redirect_url = $redirect_url;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * @param array $redirect_args
160
-     * @throws InvalidDataTypeException
161
-     * @throws InvalidArgumentException
162
-     */
163
-    public function addRedirectArgs($redirect_args = array())
164
-    {
165
-        if (is_object($redirect_args)) {
166
-            throw new InvalidDataTypeException(
167
-                '$redirect_args',
168
-                $redirect_args,
169
-                'anything other than an object was expected.'
170
-            );
171
-        }
172
-        if (empty($redirect_args)) {
173
-            throw new InvalidArgumentException(
174
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
175
-            );
176
-        }
177
-        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * @param array $redirect_arg_keys_to_remove
184
-     * @throws InvalidDataTypeException
185
-     * @throws InvalidArgumentException
186
-     */
187
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
188
-    {
189
-        if (is_object($redirect_arg_keys_to_remove)) {
190
-            throw new InvalidDataTypeException(
191
-                '$redirect_arg_keys_to_remove',
192
-                $redirect_arg_keys_to_remove,
193
-                'anything other than an object was expected.'
194
-            );
195
-        }
196
-        if (empty($redirect_arg_keys_to_remove)) {
197
-            throw new InvalidArgumentException(
198
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
199
-            );
200
-        }
201
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
202
-            unset($this->redirect_args[ $redirect_arg_key ]);
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * @return string
210
-     */
211
-    public function redirectTo()
212
-    {
213
-        return $this->redirect_to;
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * @param string $redirect_to
220
-     * @throws InvalidDataTypeException
221
-     */
222
-    public function setRedirectTo($redirect_to)
223
-    {
224
-        if (
225
-            ! in_array(
226
-                $redirect_to,
227
-                array(
228
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
229
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
230
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
231
-                    SequentialStepForm::REDIRECT_TO_OTHER,
232
-                ),
233
-                true
234
-            )
235
-        ) {
236
-            throw new InvalidDataTypeException(
237
-                'setRedirectTo()',
238
-                $redirect_to,
239
-                'one of the SequentialStepForm class constants was expected.'
240
-            );
241
-        }
242
-        $this->redirect_to = $redirect_to;
243
-    }
22
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
23
+
24
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
25
+
26
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
27
+
28
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
29
+
30
+	/**
31
+	 * numerical value used for sorting form steps
32
+	 *
33
+	 * @var int $order
34
+	 */
35
+	private $order = 1;
36
+
37
+	/**
38
+	 * a final URL with all form related parameters added
39
+	 * that will be used to advance to the next step
40
+	 *
41
+	 * @var string $redirect_url
42
+	 */
43
+	private $redirect_url = '';
44
+
45
+	/**
46
+	 * URL params in key value pairs
47
+	 *
48
+	 * @var array $redirect_args
49
+	 */
50
+	private $redirect_args = array();
51
+
52
+	/**
53
+	 * Which step should be redirected to after form processing.
54
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
55
+	 * If a form is invalid and requires errors to be corrected,
56
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
57
+	 * Some form handlers do not have a form that is displayable,
58
+	 * and only perform data processing, but if an error occurs,
59
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
60
+	 * since the current step has no displayable content.
61
+	 * if the form is completely finished, and needs to redirect to somewhere
62
+	 * completely different, then this value will be REDIRECT_TO_OTHER
63
+	 *
64
+	 * @var string $redirect_to
65
+	 */
66
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
67
+
68
+
69
+
70
+	/**
71
+	 * SequentialStepForm constructor
72
+	 *
73
+	 * @param int         $order
74
+	 * @param string      $form_name
75
+	 * @param string      $admin_name
76
+	 * @param string      $slug
77
+	 * @param string      $form_action
78
+	 * @param string      $form_config
79
+	 * @param EE_Registry $registry
80
+	 * @throws InvalidArgumentException
81
+	 * @throws InvalidDataTypeException
82
+	 * @throws DomainException
83
+	 */
84
+	public function __construct(
85
+		$order,
86
+		$form_name,
87
+		$admin_name,
88
+		$slug,
89
+		$form_action = '',
90
+		$form_config = 'add_form_tags_and_submit',
91
+		EE_Registry $registry
92
+	) {
93
+		$this->setOrder($order);
94
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * @return int
101
+	 */
102
+	public function order()
103
+	{
104
+		return $this->order;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @param int $order
111
+	 * @throws InvalidArgumentException
112
+	 */
113
+	public function setOrder($order)
114
+	{
115
+		$order = absint($order);
116
+		if (! $order > 0) {
117
+			throw new InvalidArgumentException(
118
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
119
+			);
120
+		}
121
+		$this->order = $order;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @return string
128
+	 */
129
+	public function redirectUrl()
130
+	{
131
+		return ! empty($this->redirect_args)
132
+			? add_query_arg($this->redirect_args, $this->redirect_url)
133
+			: $this->redirect_url;
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * @param string $redirect_url
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidArgumentException
142
+	 */
143
+	public function setRedirectUrl($redirect_url)
144
+	{
145
+		if (! is_string($redirect_url)) {
146
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
147
+		}
148
+		if (empty($redirect_url)) {
149
+			throw new InvalidArgumentException(
150
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
151
+			);
152
+		}
153
+		$this->redirect_url = $redirect_url;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * @param array $redirect_args
160
+	 * @throws InvalidDataTypeException
161
+	 * @throws InvalidArgumentException
162
+	 */
163
+	public function addRedirectArgs($redirect_args = array())
164
+	{
165
+		if (is_object($redirect_args)) {
166
+			throw new InvalidDataTypeException(
167
+				'$redirect_args',
168
+				$redirect_args,
169
+				'anything other than an object was expected.'
170
+			);
171
+		}
172
+		if (empty($redirect_args)) {
173
+			throw new InvalidArgumentException(
174
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
175
+			);
176
+		}
177
+		$this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * @param array $redirect_arg_keys_to_remove
184
+	 * @throws InvalidDataTypeException
185
+	 * @throws InvalidArgumentException
186
+	 */
187
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
188
+	{
189
+		if (is_object($redirect_arg_keys_to_remove)) {
190
+			throw new InvalidDataTypeException(
191
+				'$redirect_arg_keys_to_remove',
192
+				$redirect_arg_keys_to_remove,
193
+				'anything other than an object was expected.'
194
+			);
195
+		}
196
+		if (empty($redirect_arg_keys_to_remove)) {
197
+			throw new InvalidArgumentException(
198
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
199
+			);
200
+		}
201
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
202
+			unset($this->redirect_args[ $redirect_arg_key ]);
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * @return string
210
+	 */
211
+	public function redirectTo()
212
+	{
213
+		return $this->redirect_to;
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * @param string $redirect_to
220
+	 * @throws InvalidDataTypeException
221
+	 */
222
+	public function setRedirectTo($redirect_to)
223
+	{
224
+		if (
225
+			! in_array(
226
+				$redirect_to,
227
+				array(
228
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
229
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
230
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
231
+					SequentialStepForm::REDIRECT_TO_OTHER,
232
+				),
233
+				true
234
+			)
235
+		) {
236
+			throw new InvalidDataTypeException(
237
+				'setRedirectTo()',
238
+				$redirect_to,
239
+				'one of the SequentialStepForm class constants was expected.'
240
+			);
241
+		}
242
+		$this->redirect_to = $redirect_to;
243
+	}
244 244
 }
245 245
 // End of file SequentialStepForm.php
246 246
 // Location: /SequentialStepForm.php
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     public function setOrder($order)
114 114
     {
115 115
         $order = absint($order);
116
-        if (! $order > 0) {
116
+        if ( ! $order > 0) {
117 117
             throw new InvalidArgumentException(
118 118
                 esc_html__('The form order property must be a positive integer.', 'event_espresso')
119 119
             );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function setRedirectUrl($redirect_url)
144 144
     {
145
-        if (! is_string($redirect_url)) {
145
+        if ( ! is_string($redirect_url)) {
146 146
             throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
147 147
         }
148 148
         if (empty($redirect_url)) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             );
200 200
         }
201 201
         foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
202
-            unset($this->redirect_args[ $redirect_arg_key ]);
202
+            unset($this->redirect_args[$redirect_arg_key]);
203 203
         }
204 204
     }
205 205
 
Please login to merge, or discard this patch.
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -13,186 +13,186 @@
 block discarded – undo
13 13
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
14 14
 {
15 15
 
16
-    /**
17
-     * array of line item codes and their corresponding quantities for registrations
18
-     *
19
-     * @type array $_line_item_registrations
20
-     */
21
-    protected $_line_item_registrations = array();
16
+	/**
17
+	 * array of line item codes and their corresponding quantities for registrations
18
+	 *
19
+	 * @type array $_line_item_registrations
20
+	 */
21
+	protected $_line_item_registrations = array();
22 22
 
23
-    /**
24
-     * Just kept in case we want it someday. Currently unused
25
-     *
26
-     * @var EE_Registration[]
27
-     */
28
-    protected $_registrations = array();
23
+	/**
24
+	 * Just kept in case we want it someday. Currently unused
25
+	 *
26
+	 * @var EE_Registration[]
27
+	 */
28
+	protected $_registrations = array();
29 29
 
30
-    /**
31
-     * @var EE_Registration
32
-     */
33
-    protected $_current_registration;
30
+	/**
31
+	 * @var EE_Registration
32
+	 */
33
+	protected $_current_registration;
34 34
 
35
-    /**
36
-     * these reg statuses should NOT increment the line item quantity
37
-     *
38
-     * @var array
39
-     */
40
-    protected $_closed_reg_statuses = array();
35
+	/**
36
+	 * these reg statuses should NOT increment the line item quantity
37
+	 *
38
+	 * @var array
39
+	 */
40
+	protected $_closed_reg_statuses = array();
41 41
 
42 42
 
43
-    /**
44
-     * EE_Billable_Line_Item_Filter constructor.
45
-     *
46
-     * @param EE_Registration[] $registrations
47
-     * @throws EE_Error
48
-     */
49
-    public function __construct($registrations)
50
-    {
51
-        $this->_registrations = $registrations;
52
-        $this->_calculate_registrations_per_line_item_code($registrations);
53
-        // these reg statuses should NOT increment the line item quantity
54
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
55
-    }
43
+	/**
44
+	 * EE_Billable_Line_Item_Filter constructor.
45
+	 *
46
+	 * @param EE_Registration[] $registrations
47
+	 * @throws EE_Error
48
+	 */
49
+	public function __construct($registrations)
50
+	{
51
+		$this->_registrations = $registrations;
52
+		$this->_calculate_registrations_per_line_item_code($registrations);
53
+		// these reg statuses should NOT increment the line item quantity
54
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * sets the _line_item_registrations from the provided registrations
60
-     *
61
-     * @param EE_Registration[] $registrations
62
-     * @return void
63
-     * @throws EE_Error
64
-     */
65
-    protected function _calculate_registrations_per_line_item_code($registrations)
66
-    {
67
-        foreach ($registrations as $registration) {
68
-            $line_item_code = EEM_Line_Item::instance()->get_var(
69
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
70
-                    $registration,
71
-                    array('limit' => 1)
72
-                ),
73
-                'LIN_code'
74
-            );
75
-            if ($line_item_code) {
76
-                if (! isset($this->_line_item_registrations[ $line_item_code ])) {
77
-                    $this->_line_item_registrations[ $line_item_code ] = array();
78
-                }
79
-                $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
80
-            }
81
-        }
82
-    }
58
+	/**
59
+	 * sets the _line_item_registrations from the provided registrations
60
+	 *
61
+	 * @param EE_Registration[] $registrations
62
+	 * @return void
63
+	 * @throws EE_Error
64
+	 */
65
+	protected function _calculate_registrations_per_line_item_code($registrations)
66
+	{
67
+		foreach ($registrations as $registration) {
68
+			$line_item_code = EEM_Line_Item::instance()->get_var(
69
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
70
+					$registration,
71
+					array('limit' => 1)
72
+				),
73
+				'LIN_code'
74
+			);
75
+			if ($line_item_code) {
76
+				if (! isset($this->_line_item_registrations[ $line_item_code ])) {
77
+					$this->_line_item_registrations[ $line_item_code ] = array();
78
+				}
79
+				$this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
80
+			}
81
+		}
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * Creates a duplicate of the line item tree, except only includes billable items
87
-     * and the portion of line items attributed to billable things
88
-     *
89
-     * @param EEI_Line_Item $line_item
90
-     * @return EEI_Line_Item
91
-     * @throws EE_Error
92
-     */
93
-    public function process(EEI_Line_Item $line_item)
94
-    {
95
-        $this->_adjust_line_item_quantity($line_item);
96
-        if (! $line_item->children()) {
97
-            return $line_item;
98
-        }
99
-        // the original running total (taking ALL tickets into account)
100
-        $running_total_of_children = 0;
101
-        // the new running total (only taking the specified ticket quantities into account)
102
-        $running_total_of_children_under_consideration = 0;
103
-        // let's also track the quantity of tickets that pertain to the registrations
104
-        $total_child_ticket_quantity = 0;
105
-        foreach ($line_item->children() as $child_line_item) {
106
-            $original_li_total = $child_line_item->is_percent()
107
-                ? $running_total_of_children * $child_line_item->percent() / 100
108
-                : $child_line_item->unit_price() * $child_line_item->quantity();
109
-            $this->process($child_line_item);
110
-            // If this line item is a normal line item that isn't for a ticket,
111
-            // we want to modify its total (and unit price if not a percentage line item)
112
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
113
-            if (
114
-                $child_line_item->type() === EEM_Line_Item::type_line_item
115
-                && $child_line_item->OBJ_type() !== 'Ticket'
116
-            ) {
117
-                $percent_of_running_total = $running_total_of_children
118
-                    ? $original_li_total / $running_total_of_children
119
-                    : 0;
120
-                $child_line_item->set_total(
121
-                    $running_total_of_children_under_consideration * $percent_of_running_total
122
-                );
123
-                if (! $child_line_item->is_percent()) {
124
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
125
-                }
126
-            } elseif (
85
+	/**
86
+	 * Creates a duplicate of the line item tree, except only includes billable items
87
+	 * and the portion of line items attributed to billable things
88
+	 *
89
+	 * @param EEI_Line_Item $line_item
90
+	 * @return EEI_Line_Item
91
+	 * @throws EE_Error
92
+	 */
93
+	public function process(EEI_Line_Item $line_item)
94
+	{
95
+		$this->_adjust_line_item_quantity($line_item);
96
+		if (! $line_item->children()) {
97
+			return $line_item;
98
+		}
99
+		// the original running total (taking ALL tickets into account)
100
+		$running_total_of_children = 0;
101
+		// the new running total (only taking the specified ticket quantities into account)
102
+		$running_total_of_children_under_consideration = 0;
103
+		// let's also track the quantity of tickets that pertain to the registrations
104
+		$total_child_ticket_quantity = 0;
105
+		foreach ($line_item->children() as $child_line_item) {
106
+			$original_li_total = $child_line_item->is_percent()
107
+				? $running_total_of_children * $child_line_item->percent() / 100
108
+				: $child_line_item->unit_price() * $child_line_item->quantity();
109
+			$this->process($child_line_item);
110
+			// If this line item is a normal line item that isn't for a ticket,
111
+			// we want to modify its total (and unit price if not a percentage line item)
112
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
113
+			if (
114
+				$child_line_item->type() === EEM_Line_Item::type_line_item
115
+				&& $child_line_item->OBJ_type() !== 'Ticket'
116
+			) {
117
+				$percent_of_running_total = $running_total_of_children
118
+					? $original_li_total / $running_total_of_children
119
+					: 0;
120
+				$child_line_item->set_total(
121
+					$running_total_of_children_under_consideration * $percent_of_running_total
122
+				);
123
+				if (! $child_line_item->is_percent()) {
124
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
125
+				}
126
+			} elseif (
127 127
 // make sure this item's quantity and total matches its parent
128
-                $line_item->type() === EEM_Line_Item::type_line_item
129
-                && $line_item->OBJ_type() === 'Ticket'
130
-                // but not if it's a percentage modifier
131
-                && ! $child_line_item->is_percent()
132
-                && ! (
133
-                    // or a cancellation
134
-                    $child_line_item->is_cancelled()
135
-                    && ! (
136
-                        // unless it IS a cancellation and the current registration is cancelled
137
-                        $child_line_item->is_cancelled()
138
-                        && $this->_current_registration instanceof EE_Registration
139
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
140
-                    )
141
-                )
142
-            ) {
143
-                $child_line_item->set_quantity($line_item->quantity());
144
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
145
-            }
146
-            $running_total_of_children += $original_li_total;
147
-            $running_total_of_children_under_consideration += $child_line_item->total();
148
-            if ($child_line_item->OBJ_type() === 'Ticket') {
149
-                $total_child_ticket_quantity += $child_line_item->quantity();
150
-            }
151
-        }
152
-        $line_item->set_total($running_total_of_children_under_consideration);
153
-        if ($line_item->quantity()) {
154
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
155
-        } else {
156
-            $line_item->set_unit_price(0);
157
-        }
158
-        if ($line_item->OBJ_type() === 'Event') {
159
-            $line_item->set_quantity($total_child_ticket_quantity);
160
-        }
161
-        return $line_item;
162
-    }
128
+				$line_item->type() === EEM_Line_Item::type_line_item
129
+				&& $line_item->OBJ_type() === 'Ticket'
130
+				// but not if it's a percentage modifier
131
+				&& ! $child_line_item->is_percent()
132
+				&& ! (
133
+					// or a cancellation
134
+					$child_line_item->is_cancelled()
135
+					&& ! (
136
+						// unless it IS a cancellation and the current registration is cancelled
137
+						$child_line_item->is_cancelled()
138
+						&& $this->_current_registration instanceof EE_Registration
139
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
140
+					)
141
+				)
142
+			) {
143
+				$child_line_item->set_quantity($line_item->quantity());
144
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
145
+			}
146
+			$running_total_of_children += $original_li_total;
147
+			$running_total_of_children_under_consideration += $child_line_item->total();
148
+			if ($child_line_item->OBJ_type() === 'Ticket') {
149
+				$total_child_ticket_quantity += $child_line_item->quantity();
150
+			}
151
+		}
152
+		$line_item->set_total($running_total_of_children_under_consideration);
153
+		if ($line_item->quantity()) {
154
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
155
+		} else {
156
+			$line_item->set_unit_price(0);
157
+		}
158
+		if ($line_item->OBJ_type() === 'Event') {
159
+			$line_item->set_quantity($total_child_ticket_quantity);
160
+		}
161
+		return $line_item;
162
+	}
163 163
 
164 164
 
165
-    /**
166
-     * Adjusts quantities for line items for tickets according to the registrations provided
167
-     * in the constructor
168
-     *
169
-     * @param EEI_Line_Item $line_item
170
-     * @return EEI_Line_Item
171
-     */
172
-    protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
173
-    {
174
-        // is this a ticket ?
175
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
176
-            $this->_current_registration = null;
177
-            $quantity = 0;
178
-            // if this ticket is billable at this moment, then we should have a positive quantity
179
-            if (
180
-                isset($this->_line_item_registrations[ $line_item->code() ])
181
-                && is_array($this->_line_item_registrations[ $line_item->code() ])
182
-            ) {
183
-                // set quantity based on number of open registrations for this ticket
184
-                foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
185
-                    if (
186
-                        $registration instanceof EE_Registration
187
-                    ) {
188
-                        $quantity++;
189
-                        $this->_current_registration = $registration;
190
-                    }
191
-                }
192
-            }
193
-            $line_item->set_quantity($quantity);
194
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
195
-        }
196
-        return $line_item;
197
-    }
165
+	/**
166
+	 * Adjusts quantities for line items for tickets according to the registrations provided
167
+	 * in the constructor
168
+	 *
169
+	 * @param EEI_Line_Item $line_item
170
+	 * @return EEI_Line_Item
171
+	 */
172
+	protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
173
+	{
174
+		// is this a ticket ?
175
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
176
+			$this->_current_registration = null;
177
+			$quantity = 0;
178
+			// if this ticket is billable at this moment, then we should have a positive quantity
179
+			if (
180
+				isset($this->_line_item_registrations[ $line_item->code() ])
181
+				&& is_array($this->_line_item_registrations[ $line_item->code() ])
182
+			) {
183
+				// set quantity based on number of open registrations for this ticket
184
+				foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
185
+					if (
186
+						$registration instanceof EE_Registration
187
+					) {
188
+						$quantity++;
189
+						$this->_current_registration = $registration;
190
+					}
191
+				}
192
+			}
193
+			$line_item->set_quantity($quantity);
194
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
195
+		}
196
+		return $line_item;
197
+	}
198 198
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
                 'LIN_code'
74 74
             );
75 75
             if ($line_item_code) {
76
-                if (! isset($this->_line_item_registrations[ $line_item_code ])) {
77
-                    $this->_line_item_registrations[ $line_item_code ] = array();
76
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
77
+                    $this->_line_item_registrations[$line_item_code] = array();
78 78
                 }
79
-                $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
79
+                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
80 80
             }
81 81
         }
82 82
     }
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public function process(EEI_Line_Item $line_item)
94 94
     {
95 95
         $this->_adjust_line_item_quantity($line_item);
96
-        if (! $line_item->children()) {
96
+        if ( ! $line_item->children()) {
97 97
             return $line_item;
98 98
         }
99 99
         // the original running total (taking ALL tickets into account)
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                 $child_line_item->set_total(
121 121
                     $running_total_of_children_under_consideration * $percent_of_running_total
122 122
                 );
123
-                if (! $child_line_item->is_percent()) {
123
+                if ( ! $child_line_item->is_percent()) {
124 124
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
125 125
                 }
126 126
             } elseif (
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
             $quantity = 0;
178 178
             // if this ticket is billable at this moment, then we should have a positive quantity
179 179
             if (
180
-                isset($this->_line_item_registrations[ $line_item->code() ])
181
-                && is_array($this->_line_item_registrations[ $line_item->code() ])
180
+                isset($this->_line_item_registrations[$line_item->code()])
181
+                && is_array($this->_line_item_registrations[$line_item->code()])
182 182
             ) {
183 183
                 // set quantity based on number of open registrations for this ticket
184
-                foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
184
+                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
185 185
                     if (
186 186
                         $registration instanceof EE_Registration
187 187
                     ) {
Please login to merge, or discard this patch.
core/libraries/line_item_filters/EE_Billable_Line_Item_Filter.class.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -18,49 +18,49 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * EE_Billable_Line_Item_Filter constructor.
23
-     *
24
-     * @param EE_Registration[] $registrations
25
-     */
26
-    public function __construct($registrations)
27
-    {
28
-        parent::__construct($this->_remove_unbillable_registrations($registrations));
29
-    }
21
+	/**
22
+	 * EE_Billable_Line_Item_Filter constructor.
23
+	 *
24
+	 * @param EE_Registration[] $registrations
25
+	 */
26
+	public function __construct($registrations)
27
+	{
28
+		parent::__construct($this->_remove_unbillable_registrations($registrations));
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     *    _calculate_billable_ticket_quantities_from_registrations
34
-     * compiles a list of EE_Tickets for each event in the passed array
35
-     *
36
-     * @access protected
37
-     * @param EE_Registration[] $registrations
38
-     * @return mixed
39
-     */
40
-    protected function _remove_unbillable_registrations($registrations = array())
41
-    {
42
-        if (! empty($registrations)) {
43
-            // these reg statuses require payment (if event is not free)
44
-            $requires_payment = EEM_Registration::reg_statuses_that_allow_payment();
45
-            foreach ($registrations as $key => $registration) {
46
-                if (! $registration instanceof EE_Registration) {
47
-                    continue;
48
-                }
49
-                // are we billing for this registration at this moment ?
50
-                if (
51
-                    !
52
-                    $registration->owes_monies_and_can_pay($requires_payment) &&
53
-                    ! (
54
-                        // free registration with valid reg status
55
-                        $registration->final_price() == 0 &&
56
-                        in_array($registration->status_ID(), $requires_payment)
57
-                    )
58
-                ) {
59
-                    // not billable. remove it
60
-                    unset($registrations[ $key ]);
61
-                }
62
-            }
63
-        }
64
-        return $registrations;
65
-    }
32
+	/**
33
+	 *    _calculate_billable_ticket_quantities_from_registrations
34
+	 * compiles a list of EE_Tickets for each event in the passed array
35
+	 *
36
+	 * @access protected
37
+	 * @param EE_Registration[] $registrations
38
+	 * @return mixed
39
+	 */
40
+	protected function _remove_unbillable_registrations($registrations = array())
41
+	{
42
+		if (! empty($registrations)) {
43
+			// these reg statuses require payment (if event is not free)
44
+			$requires_payment = EEM_Registration::reg_statuses_that_allow_payment();
45
+			foreach ($registrations as $key => $registration) {
46
+				if (! $registration instanceof EE_Registration) {
47
+					continue;
48
+				}
49
+				// are we billing for this registration at this moment ?
50
+				if (
51
+					!
52
+					$registration->owes_monies_and_can_pay($requires_payment) &&
53
+					! (
54
+						// free registration with valid reg status
55
+						$registration->final_price() == 0 &&
56
+						in_array($registration->status_ID(), $requires_payment)
57
+					)
58
+				) {
59
+					// not billable. remove it
60
+					unset($registrations[ $key ]);
61
+				}
62
+			}
63
+		}
64
+		return $registrations;
65
+	}
66 66
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,17 +39,16 @@  discard block
 block discarded – undo
39 39
      */
40 40
     protected function _remove_unbillable_registrations($registrations = array())
41 41
     {
42
-        if (! empty($registrations)) {
42
+        if ( ! empty($registrations)) {
43 43
             // these reg statuses require payment (if event is not free)
44 44
             $requires_payment = EEM_Registration::reg_statuses_that_allow_payment();
45 45
             foreach ($registrations as $key => $registration) {
46
-                if (! $registration instanceof EE_Registration) {
46
+                if ( ! $registration instanceof EE_Registration) {
47 47
                     continue;
48 48
                 }
49 49
                 // are we billing for this registration at this moment ?
50 50
                 if (
51
-                    !
52
-                    $registration->owes_monies_and_can_pay($requires_payment) &&
51
+                    ! $registration->owes_monies_and_can_pay($requires_payment) &&
53 52
                     ! (
54 53
                         // free registration with valid reg status
55 54
                         $registration->final_price() == 0 &&
@@ -57,7 +56,7 @@  discard block
 block discarded – undo
57 56
                     )
58 57
                 ) {
59 58
                     // not billable. remove it
60
-                    unset($registrations[ $key ]);
59
+                    unset($registrations[$key]);
61 60
                 }
62 61
             }
63 62
         }
Please login to merge, or discard this patch.
core/libraries/batch/Helpers/JobParameters.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public static function load($job_id)
160 160
     {
161
-        $job_parameter_vars = get_option(JobParameters::wp_option_prefix . $job_id);
161
+        $job_parameter_vars = get_option(JobParameters::wp_option_prefix.$job_id);
162 162
         if (
163 163
             ! is_array($job_parameter_vars) ||
164 164
             ! isset($job_parameter_vars['_classname']) ||
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
                         'event_espresso'
172 172
                     ),
173 173
                     $job_id,
174
-                    get_option(JobParameters::wp_option_prefix . $job_id)
174
+                    get_option(JobParameters::wp_option_prefix.$job_id)
175 175
                 )
176 176
             );
177 177
         }
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
      */
230 230
     public function request_datum($key, $default = '')
231 231
     {
232
-        if (isset($this->_request_data[ $key ])) {
233
-            return $this->_request_data[ $key ];
232
+        if (isset($this->_request_data[$key])) {
233
+            return $this->_request_data[$key];
234 234
         } else {
235 235
             return $default;
236 236
         }
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
      */
247 247
     public function extra_datum($key, $default = '')
248 248
     {
249
-        if (isset($this->_extra_data[ $key ])) {
250
-            return $this->_extra_data[ $key ];
249
+        if (isset($this->_extra_data[$key])) {
250
+            return $this->_extra_data[$key];
251 251
         } else {
252 252
             return $default;
253 253
         }
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      */
263 263
     public function add_extra_data($key, $value)
264 264
     {
265
-        $this->_extra_data[ $key ] = $value;
265
+        $this->_extra_data[$key] = $value;
266 266
     }
267 267
 
268 268
 
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      */
386 386
     public function option_name()
387 387
     {
388
-        return JobParameters::wp_option_prefix . $this->job_id();
388
+        return JobParameters::wp_option_prefix.$this->job_id();
389 389
     }
390 390
 
391 391
 
Please login to merge, or discard this patch.
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -14,397 +14,397 @@
 block discarded – undo
14 14
  */
15 15
 class JobParameters
16 16
 {
17
-    // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
18
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
19
-    // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
20
-    /**
21
-     * status indicating the job should continue
22
-     */
23
-    const status_continue = 'continue';
24
-
25
-    /**
26
-     * status indicated the job has been completed successfully and should be cleaned up next
27
-     */
28
-    const status_complete = 'complete';
29
-
30
-    /**
31
-     * status indicating there was an error and the job should be cleaned up
32
-     */
33
-    const status_error = 'error';
34
-
35
-    /**
36
-     * status indicating the job has been cleaned up, and so this is probably the last
37
-     * time you'll see this job
38
-     */
39
-    const status_cleaned_up = 'cleaned_up';
40
-
41
-    const wp_option_prefix = 'ee_job_parameters_';
42
-
43
-
44
-    /**
45
-     * String uniquely identifying the job
46
-     *
47
-     * @var string
48
-     */
49
-    protected $_job_id;
50
-
51
-    /**
52
-     * @var string
53
-     */
54
-    protected $_classname;
55
-
56
-    /**
57
-     * @var array
58
-     */
59
-    protected $_request_data;
60
-
61
-    /**
62
-     * Array of any extra data we want to remember about this request, that
63
-     * wasn't necessarily past in with the request data
64
-     *
65
-     * @var array
66
-     */
67
-    protected $_extra_data;
68
-
69
-    /**
70
-     * Estimate of how many units HAVE been processed
71
-     *
72
-     * @var int
73
-     */
74
-    protected $_units_processed = 0;
75
-
76
-    /**
77
-     * @var string
78
-     */
79
-    protected $_status;
80
-
81
-    /**
82
-     * The size of the total job in whatever units you want.
83
-     * If you can't provide an estimate leave as 0.
84
-     * Once _units_processed equals _job_size, we should be done
85
-     *
86
-     * @var int
87
-     */
88
-    protected $_job_size = 0;
89
-
90
-
91
-    /**
92
-     * @param string $job_id
93
-     * @param string $classname
94
-     * @param array  $request_data
95
-     * @param array  $extra_data
96
-     */
97
-    public function __construct($job_id, $classname, $request_data, $extra_data = array())
98
-    {
99
-        $this->set_job_id($job_id);
100
-        $this->set_classname($classname);
101
-        $this->set_request_data($request_data);
102
-        $this->set_extra_data($extra_data);
103
-        $this->set_status(JobParameters::status_continue);
104
-    }
105
-
106
-
107
-    /**
108
-     * Returns the array of strings of valid stati
109
-     *
110
-     * @return array
111
-     */
112
-    public static function valid_stati()
113
-    {
114
-        return array(
115
-            JobParameters::status_complete,
116
-            JobParameters::status_continue,
117
-            JobParameters::status_error,
118
-            JobParameters::status_cleaned_up,
119
-        );
120
-    }
121
-
122
-
123
-    /**
124
-     * Saves this option to the database (wordpress options table)
125
-     *
126
-     * @param boolean $first
127
-     * @return boolean success
128
-     */
129
-    public function save($first = false)
130
-    {
131
-        $object_vars = get_object_vars($this);
132
-        if ($first) {
133
-            return add_option($this->option_name(), $object_vars, null, 'no');
134
-        } else {
135
-            return update_option($this->option_name(), $object_vars);
136
-        }
137
-    }
138
-
139
-
140
-    /**
141
-     * Deletes the job from teh database, although this object is still usable
142
-     * for the rest of the request
143
-     *
144
-     * @return boolean
145
-     */
146
-    public function delete()
147
-    {
148
-        return delete_option($this->option_name());
149
-    }
150
-
151
-
152
-    /**
153
-     * Loads the specified job from the database
154
-     *
155
-     * @param string $job_id
156
-     * @return JobParameters
157
-     * @throws BatchRequestException
158
-     */
159
-    public static function load($job_id)
160
-    {
161
-        $job_parameter_vars = get_option(JobParameters::wp_option_prefix . $job_id);
162
-        if (
163
-            ! is_array($job_parameter_vars) ||
164
-            ! isset($job_parameter_vars['_classname']) ||
165
-            ! isset($job_parameter_vars['_request_data'])
166
-        ) {
167
-            throw new BatchRequestException(
168
-                sprintf(
169
-                    esc_html__(
170
-                        'Could not retrieve job %1$s from the Wordpress options table, and so the job could not continue. The wordpress option was %2$s',
171
-                        'event_espresso'
172
-                    ),
173
-                    $job_id,
174
-                    get_option(JobParameters::wp_option_prefix . $job_id)
175
-                )
176
-            );
177
-        }
178
-        $job_parameters = new JobParameters(
179
-            $job_id,
180
-            $job_parameter_vars['_classname'],
181
-            $job_parameter_vars['_request_data']
182
-        );
183
-        foreach ($job_parameter_vars as $key => $value) {
184
-            $job_parameters->{$key} = $value;
185
-        }
186
-        return $job_parameters;
187
-    }
188
-
189
-
190
-    /**
191
-     * Gets the job's unique string
192
-     *
193
-     * @return string
194
-     */
195
-    public function job_id()
196
-    {
197
-        return $this->_job_id;
198
-    }
199
-
200
-
201
-    /**
202
-     * Gets the classname that should run this job
203
-     *
204
-     * @return string
205
-     */
206
-    public function classname()
207
-    {
208
-        return $this->_classname;
209
-    }
210
-
211
-
212
-    /**
213
-     * Gets the original array of request data for this job
214
-     *
215
-     * @return array
216
-     */
217
-    public function request_data()
218
-    {
219
-        return $this->_request_data;
220
-    }
221
-
222
-
223
-    /**
224
-     * Gets a single item from the request data
225
-     *
226
-     * @param string       $key
227
-     * @param string|array $default
228
-     * @return string|array
229
-     */
230
-    public function request_datum($key, $default = '')
231
-    {
232
-        if (isset($this->_request_data[ $key ])) {
233
-            return $this->_request_data[ $key ];
234
-        } else {
235
-            return $default;
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets a single item from the extra data
242
-     *
243
-     * @param string       $key
244
-     * @param string|array $default
245
-     * @return string|array
246
-     */
247
-    public function extra_datum($key, $default = '')
248
-    {
249
-        if (isset($this->_extra_data[ $key ])) {
250
-            return $this->_extra_data[ $key ];
251
-        } else {
252
-            return $default;
253
-        }
254
-    }
255
-
256
-
257
-    /**
258
-     * Adds an extra piece of extra data that we're going to want later during the job
259
-     *
260
-     * @param string                $key
261
-     * @param string|int|array|null $value almost any extra data you want to store
262
-     */
263
-    public function add_extra_data($key, $value)
264
-    {
265
-        $this->_extra_data[ $key ] = $value;
266
-    }
267
-
268
-
269
-    /**
270
-     * Array of any extra data we want to store
271
-     *
272
-     * @return array
273
-     */
274
-    public function extra_data()
275
-    {
276
-        return $this->_extra_data;
277
-    }
278
-
279
-
280
-    /**
281
-     * Returns the job size, in whatever units you want
282
-     *
283
-     * @return int
284
-     */
285
-    public function job_size()
286
-    {
287
-        return $this->_job_size;
288
-    }
289
-
290
-
291
-    /**
292
-     * Sets the job size. You decide what units to use
293
-     *
294
-     * @param int $size
295
-     */
296
-    public function set_job_size($size)
297
-    {
298
-        $this->_job_size = $size;
299
-    }
300
-
301
-
302
-    /**
303
-     * The number of "units" processed, in the same units as the "job size"
304
-     *
305
-     * @return int
306
-     */
307
-    public function units_processed()
308
-    {
309
-        return $this->_units_processed;
310
-    }
311
-
312
-
313
-    /**
314
-     * Marks more units as processed
315
-     *
316
-     * @param int $newly_processed
317
-     * @return int updated units processed
318
-     */
319
-    public function mark_processed($newly_processed)
320
-    {
321
-        $this->_units_processed += $newly_processed;
322
-        return $this->_units_processed;
323
-    }
324
-
325
-
326
-    /**
327
-     * Sets the total count of units processed. You might prefer to use mark_processed
328
-     *
329
-     * @param int $total_units_processed
330
-     */
331
-    public function set_units_processed($total_units_processed)
332
-    {
333
-        $this->_units_processed = $total_units_processed;
334
-    }
335
-
336
-
337
-    /**
338
-     * Sets the job's ID
339
-     *
340
-     * @param string $job_id
341
-     */
342
-    public function set_job_id($job_id)
343
-    {
344
-        $this->_job_id = $job_id;
345
-    }
346
-
347
-
348
-    /**
349
-     * sets the classname
350
-     *
351
-     * @param string $classname
352
-     */
353
-    public function set_classname($classname)
354
-    {
355
-        $this->_classname = $classname;
356
-    }
357
-
358
-
359
-    /**
360
-     * Sets the request data
361
-     *
362
-     * @param array $request_data
363
-     */
364
-    public function set_request_data($request_data)
365
-    {
366
-        $this->_request_data = $request_data;
367
-    }
368
-
369
-
370
-    /**
371
-     * Sets the array of extra data we want to store on this request
372
-     *
373
-     * @param array $extra_data
374
-     */
375
-    public function set_extra_data($extra_data)
376
-    {
377
-        $this->_extra_data = $extra_data;
378
-    }
379
-
380
-
381
-    /**
382
-     * Gets the name of the wordpress option that should store these job parameters
383
-     *
384
-     * @return string
385
-     */
386
-    public function option_name()
387
-    {
388
-        return JobParameters::wp_option_prefix . $this->job_id();
389
-    }
390
-
391
-
392
-    /**
393
-     * Gets the job\s current status. One of JobParameters::valid_stati();
394
-     *
395
-     * @return string
396
-     */
397
-    public function status()
398
-    {
399
-        return $this->_status;
400
-    }
401
-
402
-
403
-    /**
404
-     * @param string $status on eof JobParameters::valid_stati()
405
-     */
406
-    public function set_status($status)
407
-    {
408
-        $this->_status = $status;
409
-    }
17
+	// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
18
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
19
+	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
20
+	/**
21
+	 * status indicating the job should continue
22
+	 */
23
+	const status_continue = 'continue';
24
+
25
+	/**
26
+	 * status indicated the job has been completed successfully and should be cleaned up next
27
+	 */
28
+	const status_complete = 'complete';
29
+
30
+	/**
31
+	 * status indicating there was an error and the job should be cleaned up
32
+	 */
33
+	const status_error = 'error';
34
+
35
+	/**
36
+	 * status indicating the job has been cleaned up, and so this is probably the last
37
+	 * time you'll see this job
38
+	 */
39
+	const status_cleaned_up = 'cleaned_up';
40
+
41
+	const wp_option_prefix = 'ee_job_parameters_';
42
+
43
+
44
+	/**
45
+	 * String uniquely identifying the job
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $_job_id;
50
+
51
+	/**
52
+	 * @var string
53
+	 */
54
+	protected $_classname;
55
+
56
+	/**
57
+	 * @var array
58
+	 */
59
+	protected $_request_data;
60
+
61
+	/**
62
+	 * Array of any extra data we want to remember about this request, that
63
+	 * wasn't necessarily past in with the request data
64
+	 *
65
+	 * @var array
66
+	 */
67
+	protected $_extra_data;
68
+
69
+	/**
70
+	 * Estimate of how many units HAVE been processed
71
+	 *
72
+	 * @var int
73
+	 */
74
+	protected $_units_processed = 0;
75
+
76
+	/**
77
+	 * @var string
78
+	 */
79
+	protected $_status;
80
+
81
+	/**
82
+	 * The size of the total job in whatever units you want.
83
+	 * If you can't provide an estimate leave as 0.
84
+	 * Once _units_processed equals _job_size, we should be done
85
+	 *
86
+	 * @var int
87
+	 */
88
+	protected $_job_size = 0;
89
+
90
+
91
+	/**
92
+	 * @param string $job_id
93
+	 * @param string $classname
94
+	 * @param array  $request_data
95
+	 * @param array  $extra_data
96
+	 */
97
+	public function __construct($job_id, $classname, $request_data, $extra_data = array())
98
+	{
99
+		$this->set_job_id($job_id);
100
+		$this->set_classname($classname);
101
+		$this->set_request_data($request_data);
102
+		$this->set_extra_data($extra_data);
103
+		$this->set_status(JobParameters::status_continue);
104
+	}
105
+
106
+
107
+	/**
108
+	 * Returns the array of strings of valid stati
109
+	 *
110
+	 * @return array
111
+	 */
112
+	public static function valid_stati()
113
+	{
114
+		return array(
115
+			JobParameters::status_complete,
116
+			JobParameters::status_continue,
117
+			JobParameters::status_error,
118
+			JobParameters::status_cleaned_up,
119
+		);
120
+	}
121
+
122
+
123
+	/**
124
+	 * Saves this option to the database (wordpress options table)
125
+	 *
126
+	 * @param boolean $first
127
+	 * @return boolean success
128
+	 */
129
+	public function save($first = false)
130
+	{
131
+		$object_vars = get_object_vars($this);
132
+		if ($first) {
133
+			return add_option($this->option_name(), $object_vars, null, 'no');
134
+		} else {
135
+			return update_option($this->option_name(), $object_vars);
136
+		}
137
+	}
138
+
139
+
140
+	/**
141
+	 * Deletes the job from teh database, although this object is still usable
142
+	 * for the rest of the request
143
+	 *
144
+	 * @return boolean
145
+	 */
146
+	public function delete()
147
+	{
148
+		return delete_option($this->option_name());
149
+	}
150
+
151
+
152
+	/**
153
+	 * Loads the specified job from the database
154
+	 *
155
+	 * @param string $job_id
156
+	 * @return JobParameters
157
+	 * @throws BatchRequestException
158
+	 */
159
+	public static function load($job_id)
160
+	{
161
+		$job_parameter_vars = get_option(JobParameters::wp_option_prefix . $job_id);
162
+		if (
163
+			! is_array($job_parameter_vars) ||
164
+			! isset($job_parameter_vars['_classname']) ||
165
+			! isset($job_parameter_vars['_request_data'])
166
+		) {
167
+			throw new BatchRequestException(
168
+				sprintf(
169
+					esc_html__(
170
+						'Could not retrieve job %1$s from the Wordpress options table, and so the job could not continue. The wordpress option was %2$s',
171
+						'event_espresso'
172
+					),
173
+					$job_id,
174
+					get_option(JobParameters::wp_option_prefix . $job_id)
175
+				)
176
+			);
177
+		}
178
+		$job_parameters = new JobParameters(
179
+			$job_id,
180
+			$job_parameter_vars['_classname'],
181
+			$job_parameter_vars['_request_data']
182
+		);
183
+		foreach ($job_parameter_vars as $key => $value) {
184
+			$job_parameters->{$key} = $value;
185
+		}
186
+		return $job_parameters;
187
+	}
188
+
189
+
190
+	/**
191
+	 * Gets the job's unique string
192
+	 *
193
+	 * @return string
194
+	 */
195
+	public function job_id()
196
+	{
197
+		return $this->_job_id;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Gets the classname that should run this job
203
+	 *
204
+	 * @return string
205
+	 */
206
+	public function classname()
207
+	{
208
+		return $this->_classname;
209
+	}
210
+
211
+
212
+	/**
213
+	 * Gets the original array of request data for this job
214
+	 *
215
+	 * @return array
216
+	 */
217
+	public function request_data()
218
+	{
219
+		return $this->_request_data;
220
+	}
221
+
222
+
223
+	/**
224
+	 * Gets a single item from the request data
225
+	 *
226
+	 * @param string       $key
227
+	 * @param string|array $default
228
+	 * @return string|array
229
+	 */
230
+	public function request_datum($key, $default = '')
231
+	{
232
+		if (isset($this->_request_data[ $key ])) {
233
+			return $this->_request_data[ $key ];
234
+		} else {
235
+			return $default;
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets a single item from the extra data
242
+	 *
243
+	 * @param string       $key
244
+	 * @param string|array $default
245
+	 * @return string|array
246
+	 */
247
+	public function extra_datum($key, $default = '')
248
+	{
249
+		if (isset($this->_extra_data[ $key ])) {
250
+			return $this->_extra_data[ $key ];
251
+		} else {
252
+			return $default;
253
+		}
254
+	}
255
+
256
+
257
+	/**
258
+	 * Adds an extra piece of extra data that we're going to want later during the job
259
+	 *
260
+	 * @param string                $key
261
+	 * @param string|int|array|null $value almost any extra data you want to store
262
+	 */
263
+	public function add_extra_data($key, $value)
264
+	{
265
+		$this->_extra_data[ $key ] = $value;
266
+	}
267
+
268
+
269
+	/**
270
+	 * Array of any extra data we want to store
271
+	 *
272
+	 * @return array
273
+	 */
274
+	public function extra_data()
275
+	{
276
+		return $this->_extra_data;
277
+	}
278
+
279
+
280
+	/**
281
+	 * Returns the job size, in whatever units you want
282
+	 *
283
+	 * @return int
284
+	 */
285
+	public function job_size()
286
+	{
287
+		return $this->_job_size;
288
+	}
289
+
290
+
291
+	/**
292
+	 * Sets the job size. You decide what units to use
293
+	 *
294
+	 * @param int $size
295
+	 */
296
+	public function set_job_size($size)
297
+	{
298
+		$this->_job_size = $size;
299
+	}
300
+
301
+
302
+	/**
303
+	 * The number of "units" processed, in the same units as the "job size"
304
+	 *
305
+	 * @return int
306
+	 */
307
+	public function units_processed()
308
+	{
309
+		return $this->_units_processed;
310
+	}
311
+
312
+
313
+	/**
314
+	 * Marks more units as processed
315
+	 *
316
+	 * @param int $newly_processed
317
+	 * @return int updated units processed
318
+	 */
319
+	public function mark_processed($newly_processed)
320
+	{
321
+		$this->_units_processed += $newly_processed;
322
+		return $this->_units_processed;
323
+	}
324
+
325
+
326
+	/**
327
+	 * Sets the total count of units processed. You might prefer to use mark_processed
328
+	 *
329
+	 * @param int $total_units_processed
330
+	 */
331
+	public function set_units_processed($total_units_processed)
332
+	{
333
+		$this->_units_processed = $total_units_processed;
334
+	}
335
+
336
+
337
+	/**
338
+	 * Sets the job's ID
339
+	 *
340
+	 * @param string $job_id
341
+	 */
342
+	public function set_job_id($job_id)
343
+	{
344
+		$this->_job_id = $job_id;
345
+	}
346
+
347
+
348
+	/**
349
+	 * sets the classname
350
+	 *
351
+	 * @param string $classname
352
+	 */
353
+	public function set_classname($classname)
354
+	{
355
+		$this->_classname = $classname;
356
+	}
357
+
358
+
359
+	/**
360
+	 * Sets the request data
361
+	 *
362
+	 * @param array $request_data
363
+	 */
364
+	public function set_request_data($request_data)
365
+	{
366
+		$this->_request_data = $request_data;
367
+	}
368
+
369
+
370
+	/**
371
+	 * Sets the array of extra data we want to store on this request
372
+	 *
373
+	 * @param array $extra_data
374
+	 */
375
+	public function set_extra_data($extra_data)
376
+	{
377
+		$this->_extra_data = $extra_data;
378
+	}
379
+
380
+
381
+	/**
382
+	 * Gets the name of the wordpress option that should store these job parameters
383
+	 *
384
+	 * @return string
385
+	 */
386
+	public function option_name()
387
+	{
388
+		return JobParameters::wp_option_prefix . $this->job_id();
389
+	}
390
+
391
+
392
+	/**
393
+	 * Gets the job\s current status. One of JobParameters::valid_stati();
394
+	 *
395
+	 * @return string
396
+	 */
397
+	public function status()
398
+	{
399
+		return $this->_status;
400
+	}
401
+
402
+
403
+	/**
404
+	 * @param string $status on eof JobParameters::valid_stati()
405
+	 */
406
+	public function set_status($status)
407
+	{
408
+		$this->_status = $status;
409
+	}
410 410
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Price.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,11 +42,11 @@
 block discarded – undo
42 42
             'Price' => new EE_Belongs_To_Relation()
43 43
         );
44 44
         $this->_model_chain_to_wp_user = 'Ticket';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46 46
         // account for default tickets in the caps
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50 50
         // follow the caps of the ticket
51 51
         $this->_caps_slug = 'tickets';
52 52
         parent::__construct($timezone);
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,43 +12,43 @@
 block discarded – undo
12 12
 class EEM_Ticket_Price extends EEM_Base
13 13
 {
14 14
 
15
-    // private instance of the EEM_Ticket_Price object
16
-    protected static $_instance = null;
15
+	// private instance of the EEM_Ticket_Price object
16
+	protected static $_instance = null;
17 17
 
18
-    /**
19
-     *      private constructor to prevent direct creation
20
-     *      @Constructor
21
-     *      @access protected
22
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
-     *      @return void
24
-     */
25
-    protected function __construct($timezone)
26
-    {
27
-        $this->singular_item = esc_html__('Ticket Price', 'event_espresso');
28
-        $this->plural_item = esc_html__('Ticket Prices', 'event_espresso');
18
+	/**
19
+	 *      private constructor to prevent direct creation
20
+	 *      @Constructor
21
+	 *      @access protected
22
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
+	 *      @return void
24
+	 */
25
+	protected function __construct($timezone)
26
+	{
27
+		$this->singular_item = esc_html__('Ticket Price', 'event_espresso');
28
+		$this->plural_item = esc_html__('Ticket Prices', 'event_espresso');
29 29
 
30
-        $this->_tables = array(
31
-            'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
32
-        );
33
-        $this->_fields = array(
34
-            'Ticket_Price' => array(
35
-                'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
36
-                'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
37
-                'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
38
-            )
39
-        );
40
-        $this->_model_relations = array(
41
-            'Ticket' => new EE_Belongs_To_Relation(),
42
-            'Price' => new EE_Belongs_To_Relation()
43
-        );
44
-        $this->_model_chain_to_wp_user = 'Ticket';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
-        // account for default tickets in the caps
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
-        // follow the caps of the ticket
51
-        $this->_caps_slug = 'tickets';
52
-        parent::__construct($timezone);
53
-    }
30
+		$this->_tables = array(
31
+			'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
32
+		);
33
+		$this->_fields = array(
34
+			'Ticket_Price' => array(
35
+				'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
36
+				'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
37
+				'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
38
+			)
39
+		);
40
+		$this->_model_relations = array(
41
+			'Ticket' => new EE_Belongs_To_Relation(),
42
+			'Price' => new EE_Belongs_To_Relation()
43
+		);
44
+		$this->_model_chain_to_wp_user = 'Ticket';
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
+		// account for default tickets in the caps
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
+		// follow the caps of the ticket
51
+		$this->_caps_slug = 'tickets';
52
+		parent::__construct($timezone);
53
+	}
54 54
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Currency.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
             'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
35 35
         );
36 36
         // this model is generally available for reading
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
37
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
38 38
 
39 39
         parent::__construct($timezone);
40 40
     }
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
     public function get_all_active($query_params = array())
49 49
     {
50 50
         $query_params[0]['CUR_active'] = true;
51
-        if (! isset($query_params['order_by'])) {
52
-            $query_params['order_by'] = array('CUR_code' => 'ASC','CUR_single' => 'ASC');
51
+        if ( ! isset($query_params['order_by'])) {
52
+            $query_params['order_by'] = array('CUR_code' => 'ASC', 'CUR_single' => 'ASC');
53 53
         }
54 54
         return $this->get_all($query_params);
55 55
     }
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
72 72
             $currencies = $this->get_all_active();
73 73
         } else {
74
-            $currencies = $this->get_all_active(array(array('CUR_code' => array('IN',$currencies_supported))));
74
+            $currencies = $this->get_all_active(array(array('CUR_code' => array('IN', $currencies_supported))));
75 75
         }
76 76
         return $currencies;
77 77
     }
Please login to merge, or discard this patch.
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -11,68 +11,68 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Currency extends EEM_Base
13 13
 {
14
-        // private instance of the Attendee object
15
-    protected static $_instance = null;
14
+		// private instance of the Attendee object
15
+	protected static $_instance = null;
16 16
 
17
-    protected function __construct($timezone = null)
18
-    {
19
-        $this->singular_item = esc_html__('Currency', 'event_espresso');
20
-        $this->plural_item = esc_html__('Currencies', 'event_espresso');
21
-        $this->_tables = array(
22
-            'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code')
23
-        );
24
-        $this->_fields = array(
25
-            'Currency' => array(
26
-                'CUR_code' => new EE_Primary_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso')),
27
-                'CUR_single' => new EE_Plain_Text_Field('CUR_single', esc_html__('Currency Name Singular', 'event_espresso'), false),
28
-                'CUR_plural' => new EE_Plain_Text_Field('CUR_plural', esc_html__('Currency Name Plural', 'event_espresso'), false),
29
-                'CUR_sign' => new EE_Plain_Text_Field('CUR_sign', esc_html__('Currency Sign', 'event_espresso'), false),
30
-                'CUR_dec_plc' => new EE_Integer_Field('CUR_dec_plc', esc_html__('Currency Decimal Places', 'event_espresso'), false, 2),
31
-                'CUR_active' => new EE_Boolean_Field('CUR_active', esc_html__('Active?', 'event_espresso'), false, true),
32
-            ));
33
-        $this->_model_relations = array(
34
-            'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
35
-        );
36
-        // this model is generally available for reading
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
17
+	protected function __construct($timezone = null)
18
+	{
19
+		$this->singular_item = esc_html__('Currency', 'event_espresso');
20
+		$this->plural_item = esc_html__('Currencies', 'event_espresso');
21
+		$this->_tables = array(
22
+			'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code')
23
+		);
24
+		$this->_fields = array(
25
+			'Currency' => array(
26
+				'CUR_code' => new EE_Primary_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso')),
27
+				'CUR_single' => new EE_Plain_Text_Field('CUR_single', esc_html__('Currency Name Singular', 'event_espresso'), false),
28
+				'CUR_plural' => new EE_Plain_Text_Field('CUR_plural', esc_html__('Currency Name Plural', 'event_espresso'), false),
29
+				'CUR_sign' => new EE_Plain_Text_Field('CUR_sign', esc_html__('Currency Sign', 'event_espresso'), false),
30
+				'CUR_dec_plc' => new EE_Integer_Field('CUR_dec_plc', esc_html__('Currency Decimal Places', 'event_espresso'), false, 2),
31
+				'CUR_active' => new EE_Boolean_Field('CUR_active', esc_html__('Active?', 'event_espresso'), false, true),
32
+			));
33
+		$this->_model_relations = array(
34
+			'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
35
+		);
36
+		// this model is generally available for reading
37
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
38 38
 
39
-        parent::__construct($timezone);
40
-    }
39
+		parent::__construct($timezone);
40
+	}
41 41
 
42
-    /**
43
-     * Gets all thea ctive currencies, and orders them by their singular name, and then their code
44
-     * (may be overridden)
45
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
46
-     * @return EE_Currency[]
47
-     */
48
-    public function get_all_active($query_params = array())
49
-    {
50
-        $query_params[0]['CUR_active'] = true;
51
-        if (! isset($query_params['order_by'])) {
52
-            $query_params['order_by'] = array('CUR_code' => 'ASC','CUR_single' => 'ASC');
53
-        }
54
-        return $this->get_all($query_params);
55
-    }
56
-    /**
57
-     * Gets all the currencies which can be used by that payment method type
58
-     * @param EE_PMT_Base $payment_method_type
59
-     * @return EE_Currency[]
60
-     */
61
-    public function get_all_currencies_usable_by($payment_method_type)
62
-    {
63
-        if (
64
-            $payment_method_type instanceof EE_PMT_Base &&
65
-                $payment_method_type->get_gateway()
66
-        ) {
67
-            $currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
68
-        } else {
69
-            $currencies_supported = EE_Gateway::all_currencies_supported;
70
-        }
71
-        if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
72
-            $currencies = $this->get_all_active();
73
-        } else {
74
-            $currencies = $this->get_all_active(array(array('CUR_code' => array('IN',$currencies_supported))));
75
-        }
76
-        return $currencies;
77
-    }
42
+	/**
43
+	 * Gets all thea ctive currencies, and orders them by their singular name, and then their code
44
+	 * (may be overridden)
45
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
46
+	 * @return EE_Currency[]
47
+	 */
48
+	public function get_all_active($query_params = array())
49
+	{
50
+		$query_params[0]['CUR_active'] = true;
51
+		if (! isset($query_params['order_by'])) {
52
+			$query_params['order_by'] = array('CUR_code' => 'ASC','CUR_single' => 'ASC');
53
+		}
54
+		return $this->get_all($query_params);
55
+	}
56
+	/**
57
+	 * Gets all the currencies which can be used by that payment method type
58
+	 * @param EE_PMT_Base $payment_method_type
59
+	 * @return EE_Currency[]
60
+	 */
61
+	public function get_all_currencies_usable_by($payment_method_type)
62
+	{
63
+		if (
64
+			$payment_method_type instanceof EE_PMT_Base &&
65
+				$payment_method_type->get_gateway()
66
+		) {
67
+			$currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
68
+		} else {
69
+			$currencies_supported = EE_Gateway::all_currencies_supported;
70
+		}
71
+		if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
72
+			$currencies = $this->get_all_active();
73
+		} else {
74
+			$currencies = $this->get_all_active(array(array('CUR_code' => array('IN',$currencies_supported))));
75
+		}
76
+		return $currencies;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Currency_Payment_Method.model.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
             'Payment_Method' => new EE_Belongs_To_Relation()
35 35
         );
36 36
         // this model is generally available for reading
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
37
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
38 38
         $this->_caps_slug = 'payment_methods';
39 39
         parent::__construct($timezone);
40 40
     }
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -11,31 +11,31 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Currency_Payment_Method extends EEM_Base
13 13
 {
14
-    // private instance of the Attendee object
15
-    protected static $_instance = null;
14
+	// private instance of the Attendee object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18
-    protected function __construct($timezone = null)
19
-    {
20
-        $this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso');
21
-        $this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
22
-        $this->_tables = array(
23
-            'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID')
24
-        );
25
-        $this->_fields = array(
26
-            'Currency_Payment_Method' => array(
27
-                'CPM_ID' => new EE_Primary_Key_Int_Field('CPM_ID', esc_html__('Currency to Payment Method LInk ID', 'event_espresso')),
28
-                'CUR_code' => new EE_Foreign_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso'), false, '', 'Currency'),
29
-                'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__('Paymetn Method ID', 'event_espresso'), false, 0, 'Payment_Method')
30
-            )
31
-        );
32
-        $this->_model_relations = array(
33
-            'Currency' => new EE_Belongs_To_Relation(),
34
-            'Payment_Method' => new EE_Belongs_To_Relation()
35
-        );
36
-        // this model is generally available for reading
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
38
-        $this->_caps_slug = 'payment_methods';
39
-        parent::__construct($timezone);
40
-    }
18
+	protected function __construct($timezone = null)
19
+	{
20
+		$this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso');
21
+		$this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
22
+		$this->_tables = array(
23
+			'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID')
24
+		);
25
+		$this->_fields = array(
26
+			'Currency_Payment_Method' => array(
27
+				'CPM_ID' => new EE_Primary_Key_Int_Field('CPM_ID', esc_html__('Currency to Payment Method LInk ID', 'event_espresso')),
28
+				'CUR_code' => new EE_Foreign_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso'), false, '', 'Currency'),
29
+				'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__('Paymetn Method ID', 'event_espresso'), false, 0, 'Payment_Method')
30
+			)
31
+		);
32
+		$this->_model_relations = array(
33
+			'Currency' => new EE_Belongs_To_Relation(),
34
+			'Payment_Method' => new EE_Belongs_To_Relation()
35
+		);
36
+		// this model is generally available for reading
37
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
38
+		$this->_caps_slug = 'payment_methods';
39
+		parent::__construct($timezone);
40
+	}
41 41
 }
Please login to merge, or discard this patch.