Completed
Branch master (16095c)
by
unknown
09:17 queued 04:49
created
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
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'            => ' ',
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'            => ' ',
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.
Indentation   +638 added lines, -638 removed lines patch added patch discarded remove patch
@@ -29,642 +29,642 @@
 block discarded – undo
29 29
  */
30 30
 abstract class FormHandler implements FormHandlerInterface
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
-
123
-    /**
124
-     * Form constructor.
125
-     *
126
-     * @param string           $form_name
127
-     * @param string           $admin_name
128
-     * @param string           $slug
129
-     * @param string           $form_action
130
-     * @param string           $form_config
131
-     * @param EE_Registry|null $registry
132
-     */
133
-    public function __construct(
134
-        $form_name,
135
-        $admin_name,
136
-        $slug,
137
-        $form_action = '',
138
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
139
-        EE_Registry $registry = null
140
-    ) {
141
-        $this->setFormName($form_name);
142
-        $this->setAdminName($admin_name);
143
-        $this->setSlug($slug);
144
-        $this->setFormAction($form_action);
145
-        $this->setFormConfig($form_config);
146
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
147
-        $this->registry = $registry;
148
-    }
149
-
150
-
151
-    /**
152
-     * @return array
153
-     */
154
-    public static function getFormConfigConstants()
155
-    {
156
-        return array(
157
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
158
-            FormHandler::ADD_FORM_TAGS_ONLY,
159
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
160
-            FormHandler::DO_NOT_SETUP_FORM,
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     * @param bool $for_display
167
-     * @return EE_Form_Section_Proper
168
-     * @throws EE_Error
169
-     * @throws LogicException
170
-     */
171
-    public function form($for_display = false)
172
-    {
173
-        if (! $this->formIsValid()) {
174
-            return null;
175
-        }
176
-        if ($for_display) {
177
-            $form_config = $this->formConfig();
178
-            if (
179
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
180
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
181
-            ) {
182
-                $this->appendSubmitButton();
183
-                $this->clearFormButtonFloats();
184
-            }
185
-        }
186
-        return $this->form;
187
-    }
188
-
189
-
190
-    /**
191
-     * @return boolean
192
-     * @throws LogicException
193
-     */
194
-    public function formIsValid()
195
-    {
196
-        if ($this->form instanceof EE_Form_Section_Proper) {
197
-            return true;
198
-        }
199
-        $form = apply_filters(
200
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
201
-            $this->generate(),
202
-            $this
203
-        );
204
-        if ($this->verifyForm($form)) {
205
-            $this->setForm($form);
206
-        }
207
-        return true;
208
-    }
209
-
210
-
211
-    /**
212
-     * @param EE_Form_Section_Proper|null $form
213
-     * @return bool
214
-     * @throws LogicException
215
-     */
216
-    public function verifyForm(EE_Form_Section_Proper $form = null)
217
-    {
218
-        $form = $form !== null ? $form : $this->form;
219
-        if ($form instanceof EE_Form_Section_Proper) {
220
-            return true;
221
-        }
222
-        throw new LogicException(
223
-            sprintf(
224
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
225
-                $this->form_name,
226
-                var_export($form, true)
227
-            )
228
-        );
229
-    }
230
-
231
-
232
-    /**
233
-     * @param EE_Form_Section_Proper $form
234
-     */
235
-    public function setForm(EE_Form_Section_Proper $form)
236
-    {
237
-        $this->form = $form;
238
-    }
239
-
240
-
241
-    /**
242
-     * @return boolean
243
-     */
244
-    public function displayable()
245
-    {
246
-        return $this->displayable;
247
-    }
248
-
249
-
250
-    /**
251
-     * @param boolean $displayable
252
-     */
253
-    public function setDisplayable($displayable = false)
254
-    {
255
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
256
-    }
257
-
258
-
259
-    /**
260
-     * a public name for the form that can be displayed on the frontend of a site
261
-     *
262
-     * @return string
263
-     */
264
-    public function formName()
265
-    {
266
-        return $this->form_name;
267
-    }
268
-
269
-
270
-    /**
271
-     * @param string $form_name
272
-     * @throws InvalidDataTypeException
273
-     */
274
-    public function setFormName($form_name)
275
-    {
276
-        if (! is_string($form_name)) {
277
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
278
-        }
279
-        $this->form_name = $form_name;
280
-    }
281
-
282
-
283
-    /**
284
-     * a public name for the form that can be displayed, but only in the admin
285
-     *
286
-     * @return string
287
-     */
288
-    public function adminName()
289
-    {
290
-        return $this->admin_name;
291
-    }
292
-
293
-
294
-    /**
295
-     * @param string $admin_name
296
-     * @throws InvalidDataTypeException
297
-     */
298
-    public function setAdminName($admin_name)
299
-    {
300
-        if (! is_string($admin_name)) {
301
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
302
-        }
303
-        $this->admin_name = $admin_name;
304
-    }
305
-
306
-
307
-    /**
308
-     * a URL friendly string that can be used for identifying the form
309
-     *
310
-     * @return string
311
-     */
312
-    public function slug()
313
-    {
314
-        return $this->slug;
315
-    }
316
-
317
-
318
-    /**
319
-     * @param string $slug
320
-     * @throws InvalidDataTypeException
321
-     */
322
-    public function setSlug($slug)
323
-    {
324
-        if (! is_string($slug)) {
325
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
326
-        }
327
-        $this->slug = $slug;
328
-    }
329
-
330
-
331
-    /**
332
-     * @return string
333
-     */
334
-    public function submitBtnText()
335
-    {
336
-        return $this->submit_btn_text;
337
-    }
338
-
339
-
340
-    /**
341
-     * @param string $submit_btn_text
342
-     * @throws InvalidDataTypeException
343
-     * @throws InvalidArgumentException
344
-     */
345
-    public function setSubmitBtnText($submit_btn_text)
346
-    {
347
-        if (! is_string($submit_btn_text)) {
348
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
349
-        }
350
-        if (empty($submit_btn_text)) {
351
-            throw new InvalidArgumentException(
352
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
353
-            );
354
-        }
355
-        $this->submit_btn_text = $submit_btn_text;
356
-    }
357
-
358
-
359
-    /**
360
-     * @return string
361
-     */
362
-    public function formAction()
363
-    {
364
-        return ! empty($this->form_args)
365
-            ? add_query_arg($this->form_args, $this->form_action)
366
-            : $this->form_action;
367
-    }
368
-
369
-
370
-    /**
371
-     * @param string $form_action
372
-     * @throws InvalidDataTypeException
373
-     */
374
-    public function setFormAction($form_action)
375
-    {
376
-        if (! is_string($form_action)) {
377
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
378
-        }
379
-        $this->form_action = $form_action;
380
-    }
381
-
382
-
383
-    /**
384
-     * @param array $form_args
385
-     * @throws InvalidDataTypeException
386
-     * @throws InvalidArgumentException
387
-     */
388
-    public function addFormActionArgs($form_args = array())
389
-    {
390
-        if (is_object($form_args)) {
391
-            throw new InvalidDataTypeException(
392
-                '$form_args',
393
-                $form_args,
394
-                'anything other than an object was expected.'
395
-            );
396
-        }
397
-        if (empty($form_args)) {
398
-            throw new InvalidArgumentException(
399
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
400
-            );
401
-        }
402
-        $this->form_args = array_merge($this->form_args, $form_args);
403
-    }
404
-
405
-
406
-    /**
407
-     * @return string
408
-     */
409
-    public function formConfig()
410
-    {
411
-        return $this->form_config;
412
-    }
413
-
414
-
415
-    /**
416
-     * @param string $form_config
417
-     * @throws DomainException
418
-     */
419
-    public function setFormConfig($form_config)
420
-    {
421
-        if (
422
-            ! in_array(
423
-                $form_config,
424
-                array(
425
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
426
-                FormHandler::ADD_FORM_TAGS_ONLY,
427
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
428
-                FormHandler::DO_NOT_SETUP_FORM,
429
-                ),
430
-                true
431
-            )
432
-        ) {
433
-            throw new DomainException(
434
-                sprintf(
435
-                    esc_html__(
436
-                        '"%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',
437
-                        'event_espresso'
438
-                    ),
439
-                    $form_config
440
-                )
441
-            );
442
-        }
443
-        $this->form_config = $form_config;
444
-    }
445
-
446
-
447
-    /**
448
-     * called after the form is instantiated
449
-     * and used for performing any logic that needs to occur early
450
-     * before any of the other methods are called.
451
-     * returns true if everything is ok to proceed,
452
-     * and false if no further form logic should be implemented
453
-     *
454
-     * @return boolean
455
-     */
456
-    public function initialize()
457
-    {
458
-        $this->form_has_errors = EE_Error::has_error(true);
459
-        return true;
460
-    }
461
-
462
-
463
-    /**
464
-     * used for setting up css and js
465
-     *
466
-     * @return void
467
-     * @throws LogicException
468
-     * @throws EE_Error
469
-     */
470
-    public function enqueueStylesAndScripts()
471
-    {
472
-        $this->form()->enqueue_js();
473
-    }
474
-
475
-
476
-    /**
477
-     * creates and returns the actual form
478
-     *
479
-     * @return EE_Form_Section_Proper
480
-     */
481
-    abstract public function generate();
482
-
483
-
484
-    /**
485
-     * creates and returns an EE_Submit_Input labeled "Submit"
486
-     *
487
-     * @param string $text
488
-     * @return EE_Submit_Input
489
-     */
490
-    public function generateSubmitButton($text = '')
491
-    {
492
-        $text = ! empty($text) ? $text : $this->submitBtnText();
493
-        return new EE_Submit_Input(
494
-            array(
495
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
496
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
497
-                'html_class'            => 'ee-form-submit',
498
-                'html_label'            => ' ',
499
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
500
-                'default'               => $text,
501
-            )
502
-        );
503
-    }
504
-
505
-
506
-    /**
507
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
508
-     *
509
-     * @param string $text
510
-     * @return void
511
-     * @throws EE_Error
512
-     */
513
-    public function appendSubmitButton($text = '')
514
-    {
515
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
516
-            return;
517
-        }
518
-        $this->form->add_subsections(
519
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
520
-            null,
521
-            false
522
-        );
523
-    }
524
-
525
-
526
-    /**
527
-     * creates and returns an EE_Submit_Input labeled "Cancel"
528
-     *
529
-     * @param string $text
530
-     * @return EE_Submit_Input
531
-     */
532
-    public function generateCancelButton($text = '')
533
-    {
534
-        $cancel_button = new EE_Submit_Input(
535
-            array(
536
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
537
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
538
-                'html_class'            => 'ee-cancel-form',
539
-                'html_label'            => ' ',
540
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
541
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
542
-            )
543
-        );
544
-        $cancel_button->set_button_css_attributes(false);
545
-        return $cancel_button;
546
-    }
547
-
548
-
549
-    /**
550
-     * appends a float clearing div onto end of form
551
-     *
552
-     * @return void
553
-     * @throws EE_Error
554
-     */
555
-    public function clearFormButtonFloats()
556
-    {
557
-        $this->form->add_subsections(
558
-            array(
559
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
560
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
561
-                ),
562
-            ),
563
-            null,
564
-            false
565
-        );
566
-    }
567
-
568
-
569
-    /**
570
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
571
-     * returns a string of HTML that can be directly echoed in a template
572
-     *
573
-     * @return string
574
-     * @throws InvalidArgumentException
575
-     * @throws InvalidInterfaceException
576
-     * @throws InvalidDataTypeException
577
-     * @throws LogicException
578
-     * @throws EE_Error
579
-     */
580
-    public function display()
581
-    {
582
-        $form_html = apply_filters(
583
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
584
-            ''
585
-        );
586
-        $form_config = $this->formConfig();
587
-        if (
588
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
589
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
590
-        ) {
591
-            $additional_props = $this->requiresMultipartEnctype()
592
-                ? ' enctype="multipart/form-data"'
593
-                : '';
594
-            $form_html .= $this->form()->form_open(
595
-                $this->formAction(),
596
-                'POST',
597
-                $additional_props
598
-            );
599
-        }
600
-        $form_html .= $this->form(true)->get_html();
601
-        if (
602
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
603
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
604
-        ) {
605
-            $form_html .= $this->form()->form_close();
606
-        }
607
-        $form_html .= apply_filters(
608
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
609
-            ''
610
-        );
611
-        return $form_html;
612
-    }
613
-
614
-    /**
615
-     * Determines if this form needs "enctype='multipart/form-data'" or not.
616
-     * @since 4.9.80.p
617
-     * @return bool
618
-     * @throws EE_Error
619
-     */
620
-    public function requiresMultipartEnctype()
621
-    {
622
-        foreach ($this->form()->inputs_in_subsections() as $input) {
623
-            if ($input instanceof EE_File_Input) {
624
-                return true;
625
-            }
626
-        }
627
-        return false;
628
-    }
629
-
630
-
631
-    /**
632
-     * handles processing the form submission
633
-     * returns true or false depending on whether the form was processed successfully or not
634
-     *
635
-     * @param array $submitted_form_data
636
-     * @return array
637
-     * @throws InvalidArgumentException
638
-     * @throws InvalidInterfaceException
639
-     * @throws InvalidDataTypeException
640
-     * @throws EE_Error
641
-     * @throws LogicException
642
-     * @throws InvalidFormSubmissionException
643
-     */
644
-    public function process($submitted_form_data = array())
645
-    {
646
-        if (! $this->form()->was_submitted($submitted_form_data)) {
647
-            throw new InvalidFormSubmissionException($this->form_name);
648
-        }
649
-        $this->form(true)->receive_form_submission($submitted_form_data);
650
-        if (! $this->form()->is_valid()) {
651
-            throw new InvalidFormSubmissionException(
652
-                $this->form_name,
653
-                sprintf(
654
-                    esc_html__(
655
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
656
-                        'event_espresso'
657
-                    ),
658
-                    $this->form_name,
659
-                    '<br />',
660
-                    implode('<br />', $this->form()->get_validation_errors_accumulated())
661
-                )
662
-            );
663
-        }
664
-        return (array) apply_filters(
665
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
666
-            $this->form()->valid_data(),
667
-            $this
668
-        );
669
-    }
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
+
123
+	/**
124
+	 * Form constructor.
125
+	 *
126
+	 * @param string           $form_name
127
+	 * @param string           $admin_name
128
+	 * @param string           $slug
129
+	 * @param string           $form_action
130
+	 * @param string           $form_config
131
+	 * @param EE_Registry|null $registry
132
+	 */
133
+	public function __construct(
134
+		$form_name,
135
+		$admin_name,
136
+		$slug,
137
+		$form_action = '',
138
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
139
+		EE_Registry $registry = null
140
+	) {
141
+		$this->setFormName($form_name);
142
+		$this->setAdminName($admin_name);
143
+		$this->setSlug($slug);
144
+		$this->setFormAction($form_action);
145
+		$this->setFormConfig($form_config);
146
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
147
+		$this->registry = $registry;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @return array
153
+	 */
154
+	public static function getFormConfigConstants()
155
+	{
156
+		return array(
157
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
158
+			FormHandler::ADD_FORM_TAGS_ONLY,
159
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
160
+			FormHandler::DO_NOT_SETUP_FORM,
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param bool $for_display
167
+	 * @return EE_Form_Section_Proper
168
+	 * @throws EE_Error
169
+	 * @throws LogicException
170
+	 */
171
+	public function form($for_display = false)
172
+	{
173
+		if (! $this->formIsValid()) {
174
+			return null;
175
+		}
176
+		if ($for_display) {
177
+			$form_config = $this->formConfig();
178
+			if (
179
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
180
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
181
+			) {
182
+				$this->appendSubmitButton();
183
+				$this->clearFormButtonFloats();
184
+			}
185
+		}
186
+		return $this->form;
187
+	}
188
+
189
+
190
+	/**
191
+	 * @return boolean
192
+	 * @throws LogicException
193
+	 */
194
+	public function formIsValid()
195
+	{
196
+		if ($this->form instanceof EE_Form_Section_Proper) {
197
+			return true;
198
+		}
199
+		$form = apply_filters(
200
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
201
+			$this->generate(),
202
+			$this
203
+		);
204
+		if ($this->verifyForm($form)) {
205
+			$this->setForm($form);
206
+		}
207
+		return true;
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param EE_Form_Section_Proper|null $form
213
+	 * @return bool
214
+	 * @throws LogicException
215
+	 */
216
+	public function verifyForm(EE_Form_Section_Proper $form = null)
217
+	{
218
+		$form = $form !== null ? $form : $this->form;
219
+		if ($form instanceof EE_Form_Section_Proper) {
220
+			return true;
221
+		}
222
+		throw new LogicException(
223
+			sprintf(
224
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
225
+				$this->form_name,
226
+				var_export($form, true)
227
+			)
228
+		);
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param EE_Form_Section_Proper $form
234
+	 */
235
+	public function setForm(EE_Form_Section_Proper $form)
236
+	{
237
+		$this->form = $form;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @return boolean
243
+	 */
244
+	public function displayable()
245
+	{
246
+		return $this->displayable;
247
+	}
248
+
249
+
250
+	/**
251
+	 * @param boolean $displayable
252
+	 */
253
+	public function setDisplayable($displayable = false)
254
+	{
255
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
256
+	}
257
+
258
+
259
+	/**
260
+	 * a public name for the form that can be displayed on the frontend of a site
261
+	 *
262
+	 * @return string
263
+	 */
264
+	public function formName()
265
+	{
266
+		return $this->form_name;
267
+	}
268
+
269
+
270
+	/**
271
+	 * @param string $form_name
272
+	 * @throws InvalidDataTypeException
273
+	 */
274
+	public function setFormName($form_name)
275
+	{
276
+		if (! is_string($form_name)) {
277
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
278
+		}
279
+		$this->form_name = $form_name;
280
+	}
281
+
282
+
283
+	/**
284
+	 * a public name for the form that can be displayed, but only in the admin
285
+	 *
286
+	 * @return string
287
+	 */
288
+	public function adminName()
289
+	{
290
+		return $this->admin_name;
291
+	}
292
+
293
+
294
+	/**
295
+	 * @param string $admin_name
296
+	 * @throws InvalidDataTypeException
297
+	 */
298
+	public function setAdminName($admin_name)
299
+	{
300
+		if (! is_string($admin_name)) {
301
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
302
+		}
303
+		$this->admin_name = $admin_name;
304
+	}
305
+
306
+
307
+	/**
308
+	 * a URL friendly string that can be used for identifying the form
309
+	 *
310
+	 * @return string
311
+	 */
312
+	public function slug()
313
+	{
314
+		return $this->slug;
315
+	}
316
+
317
+
318
+	/**
319
+	 * @param string $slug
320
+	 * @throws InvalidDataTypeException
321
+	 */
322
+	public function setSlug($slug)
323
+	{
324
+		if (! is_string($slug)) {
325
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
326
+		}
327
+		$this->slug = $slug;
328
+	}
329
+
330
+
331
+	/**
332
+	 * @return string
333
+	 */
334
+	public function submitBtnText()
335
+	{
336
+		return $this->submit_btn_text;
337
+	}
338
+
339
+
340
+	/**
341
+	 * @param string $submit_btn_text
342
+	 * @throws InvalidDataTypeException
343
+	 * @throws InvalidArgumentException
344
+	 */
345
+	public function setSubmitBtnText($submit_btn_text)
346
+	{
347
+		if (! is_string($submit_btn_text)) {
348
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
349
+		}
350
+		if (empty($submit_btn_text)) {
351
+			throw new InvalidArgumentException(
352
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
353
+			);
354
+		}
355
+		$this->submit_btn_text = $submit_btn_text;
356
+	}
357
+
358
+
359
+	/**
360
+	 * @return string
361
+	 */
362
+	public function formAction()
363
+	{
364
+		return ! empty($this->form_args)
365
+			? add_query_arg($this->form_args, $this->form_action)
366
+			: $this->form_action;
367
+	}
368
+
369
+
370
+	/**
371
+	 * @param string $form_action
372
+	 * @throws InvalidDataTypeException
373
+	 */
374
+	public function setFormAction($form_action)
375
+	{
376
+		if (! is_string($form_action)) {
377
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
378
+		}
379
+		$this->form_action = $form_action;
380
+	}
381
+
382
+
383
+	/**
384
+	 * @param array $form_args
385
+	 * @throws InvalidDataTypeException
386
+	 * @throws InvalidArgumentException
387
+	 */
388
+	public function addFormActionArgs($form_args = array())
389
+	{
390
+		if (is_object($form_args)) {
391
+			throw new InvalidDataTypeException(
392
+				'$form_args',
393
+				$form_args,
394
+				'anything other than an object was expected.'
395
+			);
396
+		}
397
+		if (empty($form_args)) {
398
+			throw new InvalidArgumentException(
399
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
400
+			);
401
+		}
402
+		$this->form_args = array_merge($this->form_args, $form_args);
403
+	}
404
+
405
+
406
+	/**
407
+	 * @return string
408
+	 */
409
+	public function formConfig()
410
+	{
411
+		return $this->form_config;
412
+	}
413
+
414
+
415
+	/**
416
+	 * @param string $form_config
417
+	 * @throws DomainException
418
+	 */
419
+	public function setFormConfig($form_config)
420
+	{
421
+		if (
422
+			! in_array(
423
+				$form_config,
424
+				array(
425
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
426
+				FormHandler::ADD_FORM_TAGS_ONLY,
427
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
428
+				FormHandler::DO_NOT_SETUP_FORM,
429
+				),
430
+				true
431
+			)
432
+		) {
433
+			throw new DomainException(
434
+				sprintf(
435
+					esc_html__(
436
+						'"%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',
437
+						'event_espresso'
438
+					),
439
+					$form_config
440
+				)
441
+			);
442
+		}
443
+		$this->form_config = $form_config;
444
+	}
445
+
446
+
447
+	/**
448
+	 * called after the form is instantiated
449
+	 * and used for performing any logic that needs to occur early
450
+	 * before any of the other methods are called.
451
+	 * returns true if everything is ok to proceed,
452
+	 * and false if no further form logic should be implemented
453
+	 *
454
+	 * @return boolean
455
+	 */
456
+	public function initialize()
457
+	{
458
+		$this->form_has_errors = EE_Error::has_error(true);
459
+		return true;
460
+	}
461
+
462
+
463
+	/**
464
+	 * used for setting up css and js
465
+	 *
466
+	 * @return void
467
+	 * @throws LogicException
468
+	 * @throws EE_Error
469
+	 */
470
+	public function enqueueStylesAndScripts()
471
+	{
472
+		$this->form()->enqueue_js();
473
+	}
474
+
475
+
476
+	/**
477
+	 * creates and returns the actual form
478
+	 *
479
+	 * @return EE_Form_Section_Proper
480
+	 */
481
+	abstract public function generate();
482
+
483
+
484
+	/**
485
+	 * creates and returns an EE_Submit_Input labeled "Submit"
486
+	 *
487
+	 * @param string $text
488
+	 * @return EE_Submit_Input
489
+	 */
490
+	public function generateSubmitButton($text = '')
491
+	{
492
+		$text = ! empty($text) ? $text : $this->submitBtnText();
493
+		return new EE_Submit_Input(
494
+			array(
495
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
496
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
497
+				'html_class'            => 'ee-form-submit',
498
+				'html_label'            => '&nbsp;',
499
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
500
+				'default'               => $text,
501
+			)
502
+		);
503
+	}
504
+
505
+
506
+	/**
507
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
508
+	 *
509
+	 * @param string $text
510
+	 * @return void
511
+	 * @throws EE_Error
512
+	 */
513
+	public function appendSubmitButton($text = '')
514
+	{
515
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
516
+			return;
517
+		}
518
+		$this->form->add_subsections(
519
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
520
+			null,
521
+			false
522
+		);
523
+	}
524
+
525
+
526
+	/**
527
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
528
+	 *
529
+	 * @param string $text
530
+	 * @return EE_Submit_Input
531
+	 */
532
+	public function generateCancelButton($text = '')
533
+	{
534
+		$cancel_button = new EE_Submit_Input(
535
+			array(
536
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
537
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
538
+				'html_class'            => 'ee-cancel-form',
539
+				'html_label'            => '&nbsp;',
540
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
541
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
542
+			)
543
+		);
544
+		$cancel_button->set_button_css_attributes(false);
545
+		return $cancel_button;
546
+	}
547
+
548
+
549
+	/**
550
+	 * appends a float clearing div onto end of form
551
+	 *
552
+	 * @return void
553
+	 * @throws EE_Error
554
+	 */
555
+	public function clearFormButtonFloats()
556
+	{
557
+		$this->form->add_subsections(
558
+			array(
559
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
560
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
561
+				),
562
+			),
563
+			null,
564
+			false
565
+		);
566
+	}
567
+
568
+
569
+	/**
570
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
571
+	 * returns a string of HTML that can be directly echoed in a template
572
+	 *
573
+	 * @return string
574
+	 * @throws InvalidArgumentException
575
+	 * @throws InvalidInterfaceException
576
+	 * @throws InvalidDataTypeException
577
+	 * @throws LogicException
578
+	 * @throws EE_Error
579
+	 */
580
+	public function display()
581
+	{
582
+		$form_html = apply_filters(
583
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
584
+			''
585
+		);
586
+		$form_config = $this->formConfig();
587
+		if (
588
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
589
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
590
+		) {
591
+			$additional_props = $this->requiresMultipartEnctype()
592
+				? ' enctype="multipart/form-data"'
593
+				: '';
594
+			$form_html .= $this->form()->form_open(
595
+				$this->formAction(),
596
+				'POST',
597
+				$additional_props
598
+			);
599
+		}
600
+		$form_html .= $this->form(true)->get_html();
601
+		if (
602
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
603
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
604
+		) {
605
+			$form_html .= $this->form()->form_close();
606
+		}
607
+		$form_html .= apply_filters(
608
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
609
+			''
610
+		);
611
+		return $form_html;
612
+	}
613
+
614
+	/**
615
+	 * Determines if this form needs "enctype='multipart/form-data'" or not.
616
+	 * @since 4.9.80.p
617
+	 * @return bool
618
+	 * @throws EE_Error
619
+	 */
620
+	public function requiresMultipartEnctype()
621
+	{
622
+		foreach ($this->form()->inputs_in_subsections() as $input) {
623
+			if ($input instanceof EE_File_Input) {
624
+				return true;
625
+			}
626
+		}
627
+		return false;
628
+	}
629
+
630
+
631
+	/**
632
+	 * handles processing the form submission
633
+	 * returns true or false depending on whether the form was processed successfully or not
634
+	 *
635
+	 * @param array $submitted_form_data
636
+	 * @return array
637
+	 * @throws InvalidArgumentException
638
+	 * @throws InvalidInterfaceException
639
+	 * @throws InvalidDataTypeException
640
+	 * @throws EE_Error
641
+	 * @throws LogicException
642
+	 * @throws InvalidFormSubmissionException
643
+	 */
644
+	public function process($submitted_form_data = array())
645
+	{
646
+		if (! $this->form()->was_submitted($submitted_form_data)) {
647
+			throw new InvalidFormSubmissionException($this->form_name);
648
+		}
649
+		$this->form(true)->receive_form_submission($submitted_form_data);
650
+		if (! $this->form()->is_valid()) {
651
+			throw new InvalidFormSubmissionException(
652
+				$this->form_name,
653
+				sprintf(
654
+					esc_html__(
655
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
656
+						'event_espresso'
657
+					),
658
+					$this->form_name,
659
+					'<br />',
660
+					implode('<br />', $this->form()->get_validation_errors_accumulated())
661
+				)
662
+			);
663
+		}
664
+		return (array) apply_filters(
665
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
666
+			$this->form()->valid_data(),
667
+			$this
668
+		);
669
+	}
670 670
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 2 patches
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.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -18,227 +18,227 @@
 block discarded – undo
18 18
  */
19 19
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
20 20
 {
21
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
22
-
23
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
24
-
25
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
26
-
27
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
28
-
29
-    /**
30
-     * numerical value used for sorting form steps
31
-     *
32
-     * @var int $order
33
-     */
34
-    private $order = 1;
35
-
36
-    /**
37
-     * a final URL with all form related parameters added
38
-     * that will be used to advance to the next step
39
-     *
40
-     * @var string $redirect_url
41
-     */
42
-    private $redirect_url = '';
43
-
44
-    /**
45
-     * URL params in key value pairs
46
-     *
47
-     * @var array $redirect_args
48
-     */
49
-    private $redirect_args = array();
50
-
51
-    /**
52
-     * Which step should be redirected to after form processing.
53
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
54
-     * If a form is invalid and requires errors to be corrected,
55
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
56
-     * Some form handlers do not have a form that is displayable,
57
-     * and only perform data processing, but if an error occurs,
58
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
59
-     * since the current step has no displayable content.
60
-     * if the form is completely finished, and needs to redirect to somewhere
61
-     * completely different, then this value will be REDIRECT_TO_OTHER
62
-     *
63
-     * @var string $redirect_to
64
-     */
65
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
66
-
67
-
68
-    /**
69
-     * SequentialStepForm constructor
70
-     *
71
-     * @param int         $order
72
-     * @param string      $form_name
73
-     * @param string      $admin_name
74
-     * @param string      $slug
75
-     * @param string      $form_action
76
-     * @param string      $form_config
77
-     * @param EE_Registry|null $registry
78
-     * @throws InvalidArgumentException
79
-     * @throws InvalidDataTypeException
80
-     * @throws DomainException
81
-     */
82
-    public function __construct(
83
-        $order,
84
-        $form_name,
85
-        $admin_name,
86
-        $slug,
87
-        $form_action = '',
88
-        $form_config = 'add_form_tags_and_submit',
89
-        ?EE_Registry $registry = null
90
-    ) {
91
-        $this->setOrder($order);
92
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * @return int
99
-     */
100
-    public function order()
101
-    {
102
-        return $this->order;
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * @param int $order
109
-     * @throws InvalidArgumentException
110
-     */
111
-    public function setOrder($order)
112
-    {
113
-        $order = absint($order);
114
-        if (! $order > 0) {
115
-            throw new InvalidArgumentException(
116
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
117
-            );
118
-        }
119
-        $this->order = $order;
120
-    }
121
-
122
-
123
-
124
-    /**
125
-     * @return string
126
-     */
127
-    public function redirectUrl()
128
-    {
129
-        return ! empty($this->redirect_args)
130
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
131
-            : $this->redirect_url;
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * @param string $redirect_url
138
-     * @throws InvalidDataTypeException
139
-     * @throws InvalidArgumentException
140
-     */
141
-    public function setRedirectUrl($redirect_url)
142
-    {
143
-        if (! is_string($redirect_url)) {
144
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
145
-        }
146
-        if (empty($redirect_url)) {
147
-            throw new InvalidArgumentException(
148
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
149
-            );
150
-        }
151
-        $this->redirect_url = $redirect_url;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @param array $redirect_args
158
-     * @throws InvalidDataTypeException
159
-     * @throws InvalidArgumentException
160
-     */
161
-    public function addRedirectArgs($redirect_args = array())
162
-    {
163
-        if (is_object($redirect_args)) {
164
-            throw new InvalidDataTypeException(
165
-                '$redirect_args',
166
-                $redirect_args,
167
-                'anything other than an object was expected.'
168
-            );
169
-        }
170
-        if (empty($redirect_args)) {
171
-            throw new InvalidArgumentException(
172
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
173
-            );
174
-        }
175
-        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * @param array $redirect_arg_keys_to_remove
182
-     * @throws InvalidDataTypeException
183
-     * @throws InvalidArgumentException
184
-     */
185
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
186
-    {
187
-        if (is_object($redirect_arg_keys_to_remove)) {
188
-            throw new InvalidDataTypeException(
189
-                '$redirect_arg_keys_to_remove',
190
-                $redirect_arg_keys_to_remove,
191
-                'anything other than an object was expected.'
192
-            );
193
-        }
194
-        if (empty($redirect_arg_keys_to_remove)) {
195
-            throw new InvalidArgumentException(
196
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
197
-            );
198
-        }
199
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
200
-            unset($this->redirect_args[ $redirect_arg_key ]);
201
-        }
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * @return string
208
-     */
209
-    public function redirectTo()
210
-    {
211
-        return $this->redirect_to;
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * @param string $redirect_to
218
-     * @throws InvalidDataTypeException
219
-     */
220
-    public function setRedirectTo($redirect_to)
221
-    {
222
-        if (
223
-            ! in_array(
224
-                $redirect_to,
225
-                array(
226
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
227
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
228
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
229
-                    SequentialStepForm::REDIRECT_TO_OTHER,
230
-                ),
231
-                true
232
-            )
233
-        ) {
234
-            throw new InvalidDataTypeException(
235
-                'setRedirectTo()',
236
-                $redirect_to,
237
-                'one of the SequentialStepForm class constants was expected.'
238
-            );
239
-        }
240
-        $this->redirect_to = $redirect_to;
241
-    }
21
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
22
+
23
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
24
+
25
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
26
+
27
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
28
+
29
+	/**
30
+	 * numerical value used for sorting form steps
31
+	 *
32
+	 * @var int $order
33
+	 */
34
+	private $order = 1;
35
+
36
+	/**
37
+	 * a final URL with all form related parameters added
38
+	 * that will be used to advance to the next step
39
+	 *
40
+	 * @var string $redirect_url
41
+	 */
42
+	private $redirect_url = '';
43
+
44
+	/**
45
+	 * URL params in key value pairs
46
+	 *
47
+	 * @var array $redirect_args
48
+	 */
49
+	private $redirect_args = array();
50
+
51
+	/**
52
+	 * Which step should be redirected to after form processing.
53
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
54
+	 * If a form is invalid and requires errors to be corrected,
55
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
56
+	 * Some form handlers do not have a form that is displayable,
57
+	 * and only perform data processing, but if an error occurs,
58
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
59
+	 * since the current step has no displayable content.
60
+	 * if the form is completely finished, and needs to redirect to somewhere
61
+	 * completely different, then this value will be REDIRECT_TO_OTHER
62
+	 *
63
+	 * @var string $redirect_to
64
+	 */
65
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
66
+
67
+
68
+	/**
69
+	 * SequentialStepForm constructor
70
+	 *
71
+	 * @param int         $order
72
+	 * @param string      $form_name
73
+	 * @param string      $admin_name
74
+	 * @param string      $slug
75
+	 * @param string      $form_action
76
+	 * @param string      $form_config
77
+	 * @param EE_Registry|null $registry
78
+	 * @throws InvalidArgumentException
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws DomainException
81
+	 */
82
+	public function __construct(
83
+		$order,
84
+		$form_name,
85
+		$admin_name,
86
+		$slug,
87
+		$form_action = '',
88
+		$form_config = 'add_form_tags_and_submit',
89
+		?EE_Registry $registry = null
90
+	) {
91
+		$this->setOrder($order);
92
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * @return int
99
+	 */
100
+	public function order()
101
+	{
102
+		return $this->order;
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * @param int $order
109
+	 * @throws InvalidArgumentException
110
+	 */
111
+	public function setOrder($order)
112
+	{
113
+		$order = absint($order);
114
+		if (! $order > 0) {
115
+			throw new InvalidArgumentException(
116
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
117
+			);
118
+		}
119
+		$this->order = $order;
120
+	}
121
+
122
+
123
+
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function redirectUrl()
128
+	{
129
+		return ! empty($this->redirect_args)
130
+			? add_query_arg($this->redirect_args, $this->redirect_url)
131
+			: $this->redirect_url;
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * @param string $redirect_url
138
+	 * @throws InvalidDataTypeException
139
+	 * @throws InvalidArgumentException
140
+	 */
141
+	public function setRedirectUrl($redirect_url)
142
+	{
143
+		if (! is_string($redirect_url)) {
144
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
145
+		}
146
+		if (empty($redirect_url)) {
147
+			throw new InvalidArgumentException(
148
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
149
+			);
150
+		}
151
+		$this->redirect_url = $redirect_url;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @param array $redirect_args
158
+	 * @throws InvalidDataTypeException
159
+	 * @throws InvalidArgumentException
160
+	 */
161
+	public function addRedirectArgs($redirect_args = array())
162
+	{
163
+		if (is_object($redirect_args)) {
164
+			throw new InvalidDataTypeException(
165
+				'$redirect_args',
166
+				$redirect_args,
167
+				'anything other than an object was expected.'
168
+			);
169
+		}
170
+		if (empty($redirect_args)) {
171
+			throw new InvalidArgumentException(
172
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
173
+			);
174
+		}
175
+		$this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * @param array $redirect_arg_keys_to_remove
182
+	 * @throws InvalidDataTypeException
183
+	 * @throws InvalidArgumentException
184
+	 */
185
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
186
+	{
187
+		if (is_object($redirect_arg_keys_to_remove)) {
188
+			throw new InvalidDataTypeException(
189
+				'$redirect_arg_keys_to_remove',
190
+				$redirect_arg_keys_to_remove,
191
+				'anything other than an object was expected.'
192
+			);
193
+		}
194
+		if (empty($redirect_arg_keys_to_remove)) {
195
+			throw new InvalidArgumentException(
196
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
197
+			);
198
+		}
199
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
200
+			unset($this->redirect_args[ $redirect_arg_key ]);
201
+		}
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * @return string
208
+	 */
209
+	public function redirectTo()
210
+	{
211
+		return $this->redirect_to;
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * @param string $redirect_to
218
+	 * @throws InvalidDataTypeException
219
+	 */
220
+	public function setRedirectTo($redirect_to)
221
+	{
222
+		if (
223
+			! in_array(
224
+				$redirect_to,
225
+				array(
226
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
227
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
228
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
229
+					SequentialStepForm::REDIRECT_TO_OTHER,
230
+				),
231
+				true
232
+			)
233
+		) {
234
+			throw new InvalidDataTypeException(
235
+				'setRedirectTo()',
236
+				$redirect_to,
237
+				'one of the SequentialStepForm class constants was expected.'
238
+			);
239
+		}
240
+		$this->redirect_to = $redirect_to;
241
+	}
242 242
 }
243 243
 // End of file SequentialStepForm.php
244 244
 // Location: /SequentialStepForm.php
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
@@ -11,43 +11,43 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Ticket_Price extends EEM_Base
13 13
 {
14
-    // private instance of the EEM_Ticket_Price object
15
-    protected static $_instance = null;
14
+	// private instance of the EEM_Ticket_Price object
15
+	protected static $_instance = null;
16 16
 
17
-    /**
18
-     *      private constructor to prevent direct creation
19
-     *      @Constructor
20
-     *      @access protected
21
-     *      @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)
22
-     *      @return void
23
-     */
24
-    protected function __construct($timezone)
25
-    {
26
-        $this->singular_item = esc_html__('Ticket Price', 'event_espresso');
27
-        $this->plural_item = esc_html__('Ticket Prices', 'event_espresso');
17
+	/**
18
+	 *      private constructor to prevent direct creation
19
+	 *      @Constructor
20
+	 *      @access protected
21
+	 *      @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)
22
+	 *      @return void
23
+	 */
24
+	protected function __construct($timezone)
25
+	{
26
+		$this->singular_item = esc_html__('Ticket Price', 'event_espresso');
27
+		$this->plural_item = esc_html__('Ticket Prices', 'event_espresso');
28 28
 
29
-        $this->_tables = array(
30
-            'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
31
-        );
32
-        $this->_fields = array(
33
-            'Ticket_Price' => array(
34
-                'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
35
-                'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
36
-                'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
37
-            )
38
-        );
39
-        $this->_model_relations = array(
40
-            'Ticket' => new EE_Belongs_To_Relation(),
41
-            'Price' => new EE_Belongs_To_Relation()
42
-        );
43
-        $this->_model_chain_to_wp_user = 'Ticket';
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
45
-        // account for default tickets in the caps
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        // follow the caps of the ticket
50
-        $this->_caps_slug = 'tickets';
51
-        parent::__construct($timezone);
52
-    }
29
+		$this->_tables = array(
30
+			'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
31
+		);
32
+		$this->_fields = array(
33
+			'Ticket_Price' => array(
34
+				'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
35
+				'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
36
+				'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
37
+			)
38
+		);
39
+		$this->_model_relations = array(
40
+			'Ticket' => new EE_Belongs_To_Relation(),
41
+			'Price' => new EE_Belongs_To_Relation()
42
+		);
43
+		$this->_model_chain_to_wp_user = 'Ticket';
44
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
45
+		// account for default tickets in the caps
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+		// follow the caps of the ticket
50
+		$this->_caps_slug = 'tickets';
51
+		parent::__construct($timezone);
52
+	}
53 53
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Model_Parser.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -9,153 +9,153 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Model_Parser
11 11
 {
12
-    const table_alias_model_relation_chain_separator = '__';
13
-    const table_alias_model_relation_chain_prefix_end = '___';
14
-    /**
15
-     * Adds a period onto the front and end of the string. This often helps in searching.
16
-     * For example, if we want to find the model name "Event", it can be tricky when the following are possible
17
-     * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in
18
-     * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT
19
-     * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally
20
-     * has it as a substring
21
-     * @param string $string_to_pad
22
-     * @return string
23
-     */
24
-    public static function pad_with_periods($string_to_pad)
25
-    {
26
-        return "." . $string_to_pad . ".";
27
-    }
28
-    /**
29
-     * Basically undoes _pad_with_periods
30
-     * @param string $string_to_trim
31
-     * @return string
32
-     */
33
-    public static function trim_periods($string_to_trim)
34
-    {
35
-        return trim($string_to_trim, '.');
36
-    }
12
+	const table_alias_model_relation_chain_separator = '__';
13
+	const table_alias_model_relation_chain_prefix_end = '___';
14
+	/**
15
+	 * Adds a period onto the front and end of the string. This often helps in searching.
16
+	 * For example, if we want to find the model name "Event", it can be tricky when the following are possible
17
+	 * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in
18
+	 * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT
19
+	 * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally
20
+	 * has it as a substring
21
+	 * @param string $string_to_pad
22
+	 * @return string
23
+	 */
24
+	public static function pad_with_periods($string_to_pad)
25
+	{
26
+		return "." . $string_to_pad . ".";
27
+	}
28
+	/**
29
+	 * Basically undoes _pad_with_periods
30
+	 * @param string $string_to_trim
31
+	 * @return string
32
+	 */
33
+	public static function trim_periods($string_to_trim)
34
+	{
35
+		return trim($string_to_trim, '.');
36
+	}
37 37
 
38 38
 
39 39
 
40
-    /**
41
-     * Gets the calculated table's alias
42
-     * @param string $model_relation_chain or query param
43
-     * @param        $this_model_name
44
-     * @return string which can be added onto table aliases to make them unique
45
-     */
46
-    public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name)
47
-    {
48
-        // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event'
49
-        $model_relation_chain = self::pad_with_periods($model_relation_chain);
50
-        $this_model_name = self::pad_with_periods($this_model_name);
51
-        // eg '.Venue.Event_Venue.Event.Registration." and '.Event.'
52
-        // remove this model name and everything afterwards
53
-        $pos_of_model_name = strpos($model_relation_chain, $this_model_name);
54
-        $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name);
55
-        // eg '.Venue.Event_Venue.'
56
-        // trim periods
57
-        $model_relation_chain = self::trim_periods($model_relation_chain);
58
-        // eg 'Venue.Event_Venue'
59
-        // replace periods with double-underscores
60
-        $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain);
61
-        // eg 'Venue__Event_Venue'
62
-        if ($model_relation_chain != '') {
63
-            $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end;
64
-        }
65
-        // eg 'Venue_Event_Venue___'
66
-        return $model_relation_chain;
67
-    }
68
-    /**
69
-     * Gets the table's alias (without prefix or anything)
70
-     * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not)
71
-     * @return string
72
-     */
73
-    public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
74
-    {
75
-        // does this actually have a table alias model relation chain prefix?
76
-        $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
77
-        if ($pos !== false) {
78
-            // yes
79
-            // find that triple underscore and remove it and everything before it
80
-            $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
81
-        } else {
82
-            $table_alias = $table_alias_with_model_relation_chain_prefix;
83
-        }
84
-        return $table_alias;
85
-    }
86
-    /**
87
-     * Gets the table alias model relation chain prefix from the table alias already containing it
88
-     * @param string $table_alias_with_model_relation_chain_prefix
89
-     * @return string
90
-     */
91
-    public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
92
-    {
93
-        // does this actually have a table alias model relation chain prefix?
94
-        $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
95
-        if ($pos !== false) {
96
-            // yes
97
-            // find that triple underscore and remove it and everything before it
98
-            $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
99
-        } else {
100
-            $prefix = '';
101
-        }
102
-        return $prefix;
103
-    }
40
+	/**
41
+	 * Gets the calculated table's alias
42
+	 * @param string $model_relation_chain or query param
43
+	 * @param        $this_model_name
44
+	 * @return string which can be added onto table aliases to make them unique
45
+	 */
46
+	public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name)
47
+	{
48
+		// eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event'
49
+		$model_relation_chain = self::pad_with_periods($model_relation_chain);
50
+		$this_model_name = self::pad_with_periods($this_model_name);
51
+		// eg '.Venue.Event_Venue.Event.Registration." and '.Event.'
52
+		// remove this model name and everything afterwards
53
+		$pos_of_model_name = strpos($model_relation_chain, $this_model_name);
54
+		$model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name);
55
+		// eg '.Venue.Event_Venue.'
56
+		// trim periods
57
+		$model_relation_chain = self::trim_periods($model_relation_chain);
58
+		// eg 'Venue.Event_Venue'
59
+		// replace periods with double-underscores
60
+		$model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain);
61
+		// eg 'Venue__Event_Venue'
62
+		if ($model_relation_chain != '') {
63
+			$model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end;
64
+		}
65
+		// eg 'Venue_Event_Venue___'
66
+		return $model_relation_chain;
67
+	}
68
+	/**
69
+	 * Gets the table's alias (without prefix or anything)
70
+	 * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not)
71
+	 * @return string
72
+	 */
73
+	public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
74
+	{
75
+		// does this actually have a table alias model relation chain prefix?
76
+		$pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
77
+		if ($pos !== false) {
78
+			// yes
79
+			// find that triple underscore and remove it and everything before it
80
+			$table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
81
+		} else {
82
+			$table_alias = $table_alias_with_model_relation_chain_prefix;
83
+		}
84
+		return $table_alias;
85
+	}
86
+	/**
87
+	 * Gets the table alias model relation chain prefix from the table alias already containing it
88
+	 * @param string $table_alias_with_model_relation_chain_prefix
89
+	 * @return string
90
+	 */
91
+	public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
92
+	{
93
+		// does this actually have a table alias model relation chain prefix?
94
+		$pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
95
+		if ($pos !== false) {
96
+			// yes
97
+			// find that triple underscore and remove it and everything before it
98
+			$prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
99
+		} else {
100
+			$prefix = '';
101
+		}
102
+		return $prefix;
103
+	}
104 104
 
105
-    /**
106
-     * Gets the table alias model relation chain prefix (ie, what can be prepended onto
107
-     * EE_Model_Field::get_qualified_column() to get the proper column name for that field
108
-     * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID').
109
-     *
110
-     * @param string $model_name of the model on which the related query param was found to be belong
111
-     * @param string $original_query_param
112
-     * @return string
113
-     */
114
-    public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param)
115
-    {
116
-        $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param);
117
-        $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name);
118
-        return $table_alias_with_model_relation_chain_prefix;
119
-    }
120
-    /**
121
-     * Gets the model relation chain to $model_name from the $original_query_param.
122
-     * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID',
123
-     * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment'
124
-     * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment'
125
-     * @param string $model_name
126
-     * @param string $original_query_param
127
-     * @return string
128
-     */
129
-    public static function extract_model_relation_chain($model_name, $original_query_param)
130
-    {
131
-        // prefix and postfix both with a period, as this facilitates searching
132
-        $model_name = EE_Model_Parser::pad_with_periods($model_name);
133
-        $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param);
134
-        $pos_of_model_string = strpos($original_query_param, $model_name);
135
-        // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like
136
-        // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string
137
-        // "Registration.Transaction.Payment"
138
-        $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name));
139
-        return EE_Model_Parser::trim_periods($model_relation_chain);
140
-    }
105
+	/**
106
+	 * Gets the table alias model relation chain prefix (ie, what can be prepended onto
107
+	 * EE_Model_Field::get_qualified_column() to get the proper column name for that field
108
+	 * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID').
109
+	 *
110
+	 * @param string $model_name of the model on which the related query param was found to be belong
111
+	 * @param string $original_query_param
112
+	 * @return string
113
+	 */
114
+	public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param)
115
+	{
116
+		$relation_chain = self::extract_model_relation_chain($model_name, $original_query_param);
117
+		$table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name);
118
+		return $table_alias_with_model_relation_chain_prefix;
119
+	}
120
+	/**
121
+	 * Gets the model relation chain to $model_name from the $original_query_param.
122
+	 * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID',
123
+	 * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment'
124
+	 * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment'
125
+	 * @param string $model_name
126
+	 * @param string $original_query_param
127
+	 * @return string
128
+	 */
129
+	public static function extract_model_relation_chain($model_name, $original_query_param)
130
+	{
131
+		// prefix and postfix both with a period, as this facilitates searching
132
+		$model_name = EE_Model_Parser::pad_with_periods($model_name);
133
+		$original_query_param = EE_Model_Parser::pad_with_periods($original_query_param);
134
+		$pos_of_model_string = strpos($original_query_param, $model_name);
135
+		// eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like
136
+		// "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string
137
+		// "Registration.Transaction.Payment"
138
+		$model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name));
139
+		return EE_Model_Parser::trim_periods($model_relation_chain);
140
+	}
141 141
 
142
-    /**
143
-     * Replaces the specified model in teh model relation chain with teh join model.
144
-     * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain(
145
-     * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return
146
-     * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix
147
-     * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix
148
-     * @param string $model_name
149
-     * @param string $join_model_name
150
-     * @param string $model_relation_chain
151
-     * @return string
152
-     */
153
-    public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain)
154
-    {
155
-        $model_name = EE_Model_Parser::pad_with_periods($model_name);
156
-        $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name);
157
-        $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain);
158
-        $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain);
159
-        return EE_Model_Parser::trim_periods($replaced_with_periods);
160
-    }
142
+	/**
143
+	 * Replaces the specified model in teh model relation chain with teh join model.
144
+	 * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain(
145
+	 * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return
146
+	 * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix
147
+	 * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix
148
+	 * @param string $model_name
149
+	 * @param string $join_model_name
150
+	 * @param string $model_relation_chain
151
+	 * @return string
152
+	 */
153
+	public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain)
154
+	{
155
+		$model_name = EE_Model_Parser::pad_with_periods($model_name);
156
+		$join_model_name = EE_Model_Parser::pad_with_periods($join_model_name);
157
+		$model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain);
158
+		$replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain);
159
+		return EE_Model_Parser::trim_periods($replaced_with_periods);
160
+	}
161 161
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public static function pad_with_periods($string_to_pad)
25 25
     {
26
-        return "." . $string_to_pad . ".";
26
+        return ".".$string_to_pad.".";
27 27
     }
28 28
     /**
29 29
      * Basically undoes _pad_with_periods
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain);
61 61
         // eg 'Venue__Event_Venue'
62 62
         if ($model_relation_chain != '') {
63
-            $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end;
63
+            $model_relation_chain = $model_relation_chain.self::table_alias_model_relation_chain_prefix_end;
64 64
         }
65 65
         // eg 'Venue_Event_Venue___'
66 66
         return $model_relation_chain;
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Secondary_Table.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -8,118 +8,118 @@
 block discarded – undo
8 8
  */
9 9
 class EE_Secondary_Table extends EE_Table_Base
10 10
 {
11
-    protected $_extra_join_conditions;
11
+	protected $_extra_join_conditions;
12 12
 
13
-    /**
14
-     *
15
-     * @global type $wpdb
16
-     * @param string $table_name with or without wpdb prefix
17
-     * @param string $pk_column name of primary key column on THIS table
18
-     * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key
19
-     * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
20
-     * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
21
-     *                  or whether each site on a multisite install has a copy of this table
22
-     */
23
-    public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false)
24
-    {
25
-        $this->_fk_on_table = $fk_column;
26
-        $this->_extra_join_conditions = $extra_join_conditions;
27
-        parent::__construct($table_name, $pk_column, $global);
28
-    }
29
-    public function get_fk_on_table()
30
-    {
31
-        return $this->_fk_on_table;
32
-    }
33
-    public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
34
-    {
35
-        $this->_table_to_join_with = $table;
36
-    }
37
-    /**
38
-     *
39
-     * @return string of sql like "Event.post_type = 'event'", which gets added to
40
-     * the end of the join statement with the primary table
41
-     */
42
-    public function get_extra_join_conditions()
43
-    {
44
-        return $this->_extra_join_conditions;
45
-    }
46
-    /**
47
-     *
48
-     * @return EE_Primary_Table
49
-     */
50
-    public function get_table_to_join_with()
51
-    {
52
-        return $this->_table_to_join_with;
53
-    }
54
-    /**
55
-     * creates join statement FROM primary table
56
-     * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
57
-     *
58
-     * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
59
-     * @return string of SQL
60
-     */
61
-    public function get_join_sql($primary_table_alias_with_model_chain_prefix)
62
-    {
13
+	/**
14
+	 *
15
+	 * @global type $wpdb
16
+	 * @param string $table_name with or without wpdb prefix
17
+	 * @param string $pk_column name of primary key column on THIS table
18
+	 * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key
19
+	 * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
20
+	 * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
21
+	 *                  or whether each site on a multisite install has a copy of this table
22
+	 */
23
+	public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false)
24
+	{
25
+		$this->_fk_on_table = $fk_column;
26
+		$this->_extra_join_conditions = $extra_join_conditions;
27
+		parent::__construct($table_name, $pk_column, $global);
28
+	}
29
+	public function get_fk_on_table()
30
+	{
31
+		return $this->_fk_on_table;
32
+	}
33
+	public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
34
+	{
35
+		$this->_table_to_join_with = $table;
36
+	}
37
+	/**
38
+	 *
39
+	 * @return string of sql like "Event.post_type = 'event'", which gets added to
40
+	 * the end of the join statement with the primary table
41
+	 */
42
+	public function get_extra_join_conditions()
43
+	{
44
+		return $this->_extra_join_conditions;
45
+	}
46
+	/**
47
+	 *
48
+	 * @return EE_Primary_Table
49
+	 */
50
+	public function get_table_to_join_with()
51
+	{
52
+		return $this->_table_to_join_with;
53
+	}
54
+	/**
55
+	 * creates join statement FROM primary table
56
+	 * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
57
+	 *
58
+	 * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
59
+	 * @return string of SQL
60
+	 */
61
+	public function get_join_sql($primary_table_alias_with_model_chain_prefix)
62
+	{
63 63
 
64
-        $table_name = $this->get_table_name();
65
-        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
66
-        $other_table_pk = $this->get_table_to_join_with()->get_pk_column();
67
-        $fk = $this->get_fk_on_table();
68
-        $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
69
-        if ($this->get_extra_join_conditions()) {
70
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
71
-        }
72
-        return $join_sql;
73
-    }
64
+		$table_name = $this->get_table_name();
65
+		$secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
66
+		$other_table_pk = $this->get_table_to_join_with()->get_pk_column();
67
+		$fk = $this->get_fk_on_table();
68
+		$join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
69
+		if ($this->get_extra_join_conditions()) {
70
+			$join_sql .= "AND " . $this->get_extra_join_conditions();
71
+		}
72
+		return $join_sql;
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * Produces join SQL like get_join_sql, except instead of joining the primary table to the
78
-     * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of
79
-     * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
80
-     * " LEFT JOIN primary_table AS Primary ON ...".
81
-     * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
82
-     * @return string
83
-     */
84
-    public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
85
-    {
86
-        $primary_table_name = $this->get_table_to_join_with()->get_table_name();
87
-        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
88
-        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
89
-        $fk = $this->get_fk_on_table();
90
-        $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
91
-        if ($this->get_extra_join_conditions()) {
92
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
93
-        }
94
-        return $join_sql;
95
-    }
76
+	/**
77
+	 * Produces join SQL like get_join_sql, except instead of joining the primary table to the
78
+	 * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of
79
+	 * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
80
+	 * " LEFT JOIN primary_table AS Primary ON ...".
81
+	 * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
82
+	 * @return string
83
+	 */
84
+	public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
85
+	{
86
+		$primary_table_name = $this->get_table_to_join_with()->get_table_name();
87
+		$primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
88
+		$primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
89
+		$fk = $this->get_fk_on_table();
90
+		$join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
91
+		if ($this->get_extra_join_conditions()) {
92
+			$join_sql .= "AND " . $this->get_extra_join_conditions();
93
+		}
94
+		return $join_sql;
95
+	}
96 96
 
97
-    /**
98
-     * This prepares the join on the other table using a select with a internal limit.
99
-     * @param  mixed (array|string) $limit limit
100
-     * @return string                       SQL to return
101
-     */
102
-    public function get_select_join_limit_join($limit)
103
-    {
104
-        // first get the select
105
-        $select = $this->get_select_join_limit($limit);
106
-        $join_sql = $this->get_join_sql($select);
107
-        return $join_sql;
108
-    }
97
+	/**
98
+	 * This prepares the join on the other table using a select with a internal limit.
99
+	 * @param  mixed (array|string) $limit limit
100
+	 * @return string                       SQL to return
101
+	 */
102
+	public function get_select_join_limit_join($limit)
103
+	{
104
+		// first get the select
105
+		$select = $this->get_select_join_limit($limit);
106
+		$join_sql = $this->get_join_sql($select);
107
+		return $join_sql;
108
+	}
109 109
 
110 110
 
111 111
 
112
-    public function get_fully_qualified_fk_column()
113
-    {
114
-        $table_alias = $this->get_table_alias();
115
-        $fk = $this->get_fk_on_table();
116
-        return $table_alias . '.' . $fk;
117
-    }
112
+	public function get_fully_qualified_fk_column()
113
+	{
114
+		$table_alias = $this->get_table_alias();
115
+		$fk = $this->get_fk_on_table();
116
+		return $table_alias . '.' . $fk;
117
+	}
118 118
 
119
-    public function get_fully_qualified_pk_on_fk_table()
120
-    {
121
-        $table_alias = $this->get_table_to_join_with()->get_table_alias();
122
-        $pk = $this->get_table_to_join_with()->get_pk_column();
123
-        return $table_alias . '.' . $pk;
124
-    }
119
+	public function get_fully_qualified_pk_on_fk_table()
120
+	{
121
+		$table_alias = $this->get_table_to_join_with()->get_table_alias();
122
+		$pk = $this->get_table_to_join_with()->get_pk_column();
123
+		return $table_alias . '.' . $pk;
124
+	}
125 125
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
     {
63 63
 
64 64
         $table_name = $this->get_table_name();
65
-        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
65
+        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias();
66 66
         $other_table_pk = $this->get_table_to_join_with()->get_pk_column();
67 67
         $fk = $this->get_fk_on_table();
68 68
         $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
69 69
         if ($this->get_extra_join_conditions()) {
70
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
70
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
71 71
         }
72 72
         return $join_sql;
73 73
     }
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
     public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
85 85
     {
86 86
         $primary_table_name = $this->get_table_to_join_with()->get_table_name();
87
-        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
88
-        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
87
+        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias();
88
+        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); // $this->get_pk_column();
89 89
         $fk = $this->get_fk_on_table();
90 90
         $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
91 91
         if ($this->get_extra_join_conditions()) {
92
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
92
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
93 93
         }
94 94
         return $join_sql;
95 95
     }
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
     {
114 114
         $table_alias = $this->get_table_alias();
115 115
         $fk = $this->get_fk_on_table();
116
-        return $table_alias . '.' . $fk;
116
+        return $table_alias.'.'.$fk;
117 117
     }
118 118
 
119 119
     public function get_fully_qualified_pk_on_fk_table()
120 120
     {
121 121
         $table_alias = $this->get_table_to_join_with()->get_table_alias();
122 122
         $pk = $this->get_table_to_join_with()->get_pk_column();
123
-        return $table_alias . '.' . $pk;
123
+        return $table_alias.'.'.$pk;
124 124
     }
125 125
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Index.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -6,45 +6,45 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Index
8 8
 {
9
-    protected $_name;
10
-    protected $_field_names;
11
-    protected $_model_name;
12
-    public function __construct($fields)
13
-    {
14
-        $this->_field_names = $fields;
15
-    }
16
-    public function _construct_finalize($name, $model_name)
17
-    {
18
-        $this->_name = $name;
19
-        $this->_model_name = $model_name;
20
-    }
21
-    public function field_names()
22
-    {
23
-        return $this->_field_names;
24
-    }
25
-    /**
26
-     * Internally used by get_this_model() and get_other_model()
27
-     * @param string $model_name like Event, Question_Group, etc. omit the EEM_
28
-     * @return EEM_Base
29
-     */
30
-    protected function _get_model($model_name)
31
-    {
32
-        $modelInstance = call_user_func("EEM_" . $model_name . "::instance");
33
-        return $modelInstance;
34
-    }
35
-    /**
36
-     * Gets all the fields for this index
37
-     * @return EE_Model_Field_Base[]
38
-     */
39
-    public function fields()
40
-    {
41
-        $fields = array();
42
-        $model = $this->_get_model($this->_model_name);
43
-        foreach ($model->field_settings() as $field_name => $field_obj) {
44
-            if (in_array($field_name, $this->field_names())) {
45
-                $fields[ $field_name ] = $field_obj;
46
-            }
47
-        }
48
-        return $fields;
49
-    }
9
+	protected $_name;
10
+	protected $_field_names;
11
+	protected $_model_name;
12
+	public function __construct($fields)
13
+	{
14
+		$this->_field_names = $fields;
15
+	}
16
+	public function _construct_finalize($name, $model_name)
17
+	{
18
+		$this->_name = $name;
19
+		$this->_model_name = $model_name;
20
+	}
21
+	public function field_names()
22
+	{
23
+		return $this->_field_names;
24
+	}
25
+	/**
26
+	 * Internally used by get_this_model() and get_other_model()
27
+	 * @param string $model_name like Event, Question_Group, etc. omit the EEM_
28
+	 * @return EEM_Base
29
+	 */
30
+	protected function _get_model($model_name)
31
+	{
32
+		$modelInstance = call_user_func("EEM_" . $model_name . "::instance");
33
+		return $modelInstance;
34
+	}
35
+	/**
36
+	 * Gets all the fields for this index
37
+	 * @return EE_Model_Field_Base[]
38
+	 */
39
+	public function fields()
40
+	{
41
+		$fields = array();
42
+		$model = $this->_get_model($this->_model_name);
43
+		foreach ($model->field_settings() as $field_name => $field_obj) {
44
+			if (in_array($field_name, $this->field_names())) {
45
+				$fields[ $field_name ] = $field_obj;
46
+			}
47
+		}
48
+		return $fields;
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      */
30 30
     protected function _get_model($model_name)
31 31
     {
32
-        $modelInstance = call_user_func("EEM_" . $model_name . "::instance");
32
+        $modelInstance = call_user_func("EEM_".$model_name."::instance");
33 33
         return $modelInstance;
34 34
     }
35 35
     /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $model = $this->_get_model($this->_model_name);
43 43
         foreach ($model->field_settings() as $field_name => $field_obj) {
44 44
             if (in_array($field_name, $this->field_names())) {
45
-                $fields[ $field_name ] = $field_obj;
45
+                $fields[$field_name] = $field_obj;
46 46
             }
47 47
         }
48 48
         return $fields;
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Primary_Table.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,6 +25,6 @@
 block discarded – undo
25 25
      */
26 26
     public function get_table_sql()
27 27
     {
28
-        return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " ";
28
+        return " ".$this->get_table_name()." AS ".$this->get_table_alias()." ";
29 29
     }
30 30
 }
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -6,24 +6,24 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Primary_Table extends EE_Table_Base
8 8
 {
9
-    /**
10
-     *
11
-     * @global type $wpdb
12
-     * @param string $table_name with or without wpdb prefix
13
-     * @param string $pk_column name of primary key column
14
-     * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
15
-     *                  or whether each site on a multisite install has a copy of this table
16
-     */
17
-    public function __construct($table_name, $pk_column = null, $global = false)
18
-    {
19
-        parent::__construct($table_name, $pk_column, $global);
20
-    }
21
-    /**
22
-     * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee "
23
-     * @return string
24
-     */
25
-    public function get_table_sql()
26
-    {
27
-        return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " ";
28
-    }
9
+	/**
10
+	 *
11
+	 * @global type $wpdb
12
+	 * @param string $table_name with or without wpdb prefix
13
+	 * @param string $pk_column name of primary key column
14
+	 * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
15
+	 *                  or whether each site on a multisite install has a copy of this table
16
+	 */
17
+	public function __construct($table_name, $pk_column = null, $global = false)
18
+	{
19
+		parent::__construct($table_name, $pk_column, $global);
20
+	}
21
+	/**
22
+	 * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee "
23
+	 * @return string
24
+	 */
25
+	public function get_table_sql()
26
+	{
27
+		return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " ";
28
+	}
29 29
 }
Please login to merge, or discard this patch.
core/db_models/EEM_State.model.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             'Venue' => new EE_Has_Many_Relation(),
43 43
         );
44 44
         // this model is generally available for reading
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
46 46
         // @todo: only show STA_active
47 47
         parent::__construct($timezone);
48 48
     }
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
     */
74 74
     public function get_all_states()
75 75
     {
76
-        if (! self::$_all_states) {
77
-            self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 )));
76
+        if ( ! self::$_all_states) {
77
+            self::$_all_states = $this->get_all(array('order_by' => array('STA_name' => 'ASC'), 'limit' => array(0, 99999)));
78 78
         }
79 79
         return self::$_all_states;
80 80
     }
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function get_all_active_states($countries = array(), $flush_cache = false)
93 93
     {
94
-        if (! self::$_active_states || $flush_cache) {
94
+        if ( ! self::$_active_states || $flush_cache) {
95 95
             $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
96
-            self::$_active_states =  $this->get_all(array(
97
-                array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
98
-                'order_by' => array( 'STA_name' => 'ASC' ),
99
-                'limit' => array( 0, 99999 ),
100
-                'force_join' => array( 'Country' )
96
+            self::$_active_states = $this->get_all(array(
97
+                array('STA_active' => true, 'CNT_ISO' => array('IN', array_keys($countries))),
98
+                'order_by' => array('STA_name' => 'ASC'),
99
+                'limit' => array(0, 99999),
100
+                'force_join' => array('Country')
101 101
             ));
102 102
         }
103 103
         return self::$_active_states;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function get_all_states_of_active_countries()
113 113
     {
114
-        if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
114
+        if ($states = $this->get_all(array(array('Country.CNT_active' => true, 'STA_active' => true), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) {
115 115
             return $states;
116 116
         }
117 117
         return false;
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
      */
126 126
     public function get_all_active_states_for_these_countries($countries)
127 127
     {
128
-        if (! $countries) {
128
+        if ( ! $countries) {
129 129
             return false;
130 130
         }
131
-        if ($states = $this->get_all(array(  array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
131
+        if ($states = $this->get_all(array(array('Country.CNT_ISO' => array('IN', array_keys($countries)), 'STA_active' => true), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) {
132 132
             return $states;
133 133
         }
134 134
         return false;
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function get_all_states_for_these_countries($countries)
144 144
     {
145
-        if (! $countries) {
145
+        if ( ! $countries) {
146 146
             return false;
147 147
         }
148
-        if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
148
+        if ($states = $this->get_all(array(array('Country.CNT_ISO' => array('IN', array_keys($countries))), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) {
149 149
             return $states;
150 150
         }
151 151
         return false;
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
     public function get_state_name_by_ID($state_ID)
160 160
     {
161 161
         if (
162
-            isset(self::$_all_states[ $state_ID ]) &&
163
-                self::$_all_states[ $state_ID ] instanceof EE_State
162
+            isset(self::$_all_states[$state_ID]) &&
163
+                self::$_all_states[$state_ID] instanceof EE_State
164 164
         ) {
165
-            return self::$_all_states[ $state_ID ]->name();
165
+            return self::$_all_states[$state_ID]->name();
166 166
         }
167
-        $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
167
+        $names = $this->get_col(array(array('STA_ID' => $state_ID), 'limit' => 1), 'STA_name');
168 168
         if (is_array($names) && ! empty($names)) {
169 169
             return reset($names);
170 170
         } else {
Please login to merge, or discard this patch.
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -11,163 +11,163 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_State extends EEM_Base
13 13
 {
14
-    // private instance of the Attendee object
15
-    protected static $_instance = null;
16
-    // array of all states
17
-    private static $_all_states = false;
18
-    // array of all active states
19
-    private static $_active_states = false;
20
-
21
-    protected function __construct($timezone = null)
22
-    {
23
-        $this->singular_item = esc_html__('State/Province', 'event_espresso');
24
-        $this->plural_item = esc_html__('States/Provinces', 'event_espresso');
25
-
26
-        $this->_tables = array(
27
-            'State' => new EE_Primary_Table('esp_state', 'STA_ID')
28
-        );
29
-
30
-        $this->_fields = array(
31
-            'State' => array(
32
-                'STA_ID' => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')),
33
-                'CNT_ISO' => new EE_Foreign_Key_String_Field('CNT_ISO', esc_html__('Country ISO Code', 'event_espresso'), false, null, 'Country'),
34
-                'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', esc_html__('State Abbreviation', 'event_espresso'), false, ''),
35
-                'STA_name' => new EE_Plain_Text_Field('STA_name', esc_html__('State Name', 'event_espresso'), false, ''),
36
-                'STA_active' => new EE_Boolean_Field('STA_active', esc_html__('State Active Flag', 'event_espresso'), false, false)
37
-                ));
38
-        $this->_model_relations = array(
39
-            'Attendee' => new EE_Has_Many_Relation(),
40
-            'Country' => new EE_Belongs_To_Relation(),
41
-            'Venue' => new EE_Has_Many_Relation(),
42
-        );
43
-        // this model is generally available for reading
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
45
-        // @todo: only show STA_active
46
-        parent::__construct($timezone);
47
-    }
48
-
49
-
50
-
51
-
52
-    /**
53
-    *   reset_cached_states
54
-    *
55
-    *   @access     private
56
-    *   @return         void
57
-    */
58
-    public function reset_cached_states()
59
-    {
60
-        EEM_State::$_active_states = array();
61
-        EEM_State::$_all_states = array();
62
-    }
63
-
64
-
65
-
66
-
67
-    /**
68
-    *       _get_states
69
-    *
70
-    *       @access     private
71
-    *       @return         array
72
-    */
73
-    public function get_all_states()
74
-    {
75
-        if (! self::$_all_states) {
76
-            self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 )));
77
-        }
78
-        return self::$_all_states;
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     *        _get_states
85
-     *
86
-     * @access        public
87
-     * @param array $countries
88
-     * @param bool  $flush_cache
89
-     * @return        array
90
-     */
91
-    public function get_all_active_states($countries = array(), $flush_cache = false)
92
-    {
93
-        if (! self::$_active_states || $flush_cache) {
94
-            $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
95
-            self::$_active_states =  $this->get_all(array(
96
-                array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
97
-                'order_by' => array( 'STA_name' => 'ASC' ),
98
-                'limit' => array( 0, 99999 ),
99
-                'force_join' => array( 'Country' )
100
-            ));
101
-        }
102
-        return self::$_active_states;
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     *  get_all_states_of_active_countries
109
-     * @return array
110
-     */
111
-    public function get_all_states_of_active_countries()
112
-    {
113
-        if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
114
-            return $states;
115
-        }
116
-        return false;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     *  get_all_states_of_active_countries
123
-     * @return array
124
-     */
125
-    public function get_all_active_states_for_these_countries($countries)
126
-    {
127
-        if (! $countries) {
128
-            return false;
129
-        }
130
-        if ($states = $this->get_all(array(  array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
131
-            return $states;
132
-        }
133
-        return false;
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     *  get_all_states_of_active_countries
140
-     * @return array
141
-     */
142
-    public function get_all_states_for_these_countries($countries)
143
-    {
144
-        if (! $countries) {
145
-            return false;
146
-        }
147
-        if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
148
-            return $states;
149
-        }
150
-        return false;
151
-    }
152
-
153
-    /**
154
-     * Gets the state's name by its ID
155
-     * @param string $state_ID
156
-     * @return string
157
-     */
158
-    public function get_state_name_by_ID($state_ID)
159
-    {
160
-        if (
161
-            isset(self::$_all_states[ $state_ID ]) &&
162
-                self::$_all_states[ $state_ID ] instanceof EE_State
163
-        ) {
164
-            return self::$_all_states[ $state_ID ]->name();
165
-        }
166
-        $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
167
-        if (is_array($names) && ! empty($names)) {
168
-            return reset($names);
169
-        } else {
170
-            return '';
171
-        }
172
-    }
14
+	// private instance of the Attendee object
15
+	protected static $_instance = null;
16
+	// array of all states
17
+	private static $_all_states = false;
18
+	// array of all active states
19
+	private static $_active_states = false;
20
+
21
+	protected function __construct($timezone = null)
22
+	{
23
+		$this->singular_item = esc_html__('State/Province', 'event_espresso');
24
+		$this->plural_item = esc_html__('States/Provinces', 'event_espresso');
25
+
26
+		$this->_tables = array(
27
+			'State' => new EE_Primary_Table('esp_state', 'STA_ID')
28
+		);
29
+
30
+		$this->_fields = array(
31
+			'State' => array(
32
+				'STA_ID' => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')),
33
+				'CNT_ISO' => new EE_Foreign_Key_String_Field('CNT_ISO', esc_html__('Country ISO Code', 'event_espresso'), false, null, 'Country'),
34
+				'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', esc_html__('State Abbreviation', 'event_espresso'), false, ''),
35
+				'STA_name' => new EE_Plain_Text_Field('STA_name', esc_html__('State Name', 'event_espresso'), false, ''),
36
+				'STA_active' => new EE_Boolean_Field('STA_active', esc_html__('State Active Flag', 'event_espresso'), false, false)
37
+				));
38
+		$this->_model_relations = array(
39
+			'Attendee' => new EE_Has_Many_Relation(),
40
+			'Country' => new EE_Belongs_To_Relation(),
41
+			'Venue' => new EE_Has_Many_Relation(),
42
+		);
43
+		// this model is generally available for reading
44
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
45
+		// @todo: only show STA_active
46
+		parent::__construct($timezone);
47
+	}
48
+
49
+
50
+
51
+
52
+	/**
53
+	 *   reset_cached_states
54
+	 *
55
+	 *   @access     private
56
+	 *   @return         void
57
+	 */
58
+	public function reset_cached_states()
59
+	{
60
+		EEM_State::$_active_states = array();
61
+		EEM_State::$_all_states = array();
62
+	}
63
+
64
+
65
+
66
+
67
+	/**
68
+	 *       _get_states
69
+	 *
70
+	 *       @access     private
71
+	 *       @return         array
72
+	 */
73
+	public function get_all_states()
74
+	{
75
+		if (! self::$_all_states) {
76
+			self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 )));
77
+		}
78
+		return self::$_all_states;
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 *        _get_states
85
+	 *
86
+	 * @access        public
87
+	 * @param array $countries
88
+	 * @param bool  $flush_cache
89
+	 * @return        array
90
+	 */
91
+	public function get_all_active_states($countries = array(), $flush_cache = false)
92
+	{
93
+		if (! self::$_active_states || $flush_cache) {
94
+			$countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
95
+			self::$_active_states =  $this->get_all(array(
96
+				array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
97
+				'order_by' => array( 'STA_name' => 'ASC' ),
98
+				'limit' => array( 0, 99999 ),
99
+				'force_join' => array( 'Country' )
100
+			));
101
+		}
102
+		return self::$_active_states;
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 *  get_all_states_of_active_countries
109
+	 * @return array
110
+	 */
111
+	public function get_all_states_of_active_countries()
112
+	{
113
+		if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
114
+			return $states;
115
+		}
116
+		return false;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 *  get_all_states_of_active_countries
123
+	 * @return array
124
+	 */
125
+	public function get_all_active_states_for_these_countries($countries)
126
+	{
127
+		if (! $countries) {
128
+			return false;
129
+		}
130
+		if ($states = $this->get_all(array(  array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
131
+			return $states;
132
+		}
133
+		return false;
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 *  get_all_states_of_active_countries
140
+	 * @return array
141
+	 */
142
+	public function get_all_states_for_these_countries($countries)
143
+	{
144
+		if (! $countries) {
145
+			return false;
146
+		}
147
+		if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
148
+			return $states;
149
+		}
150
+		return false;
151
+	}
152
+
153
+	/**
154
+	 * Gets the state's name by its ID
155
+	 * @param string $state_ID
156
+	 * @return string
157
+	 */
158
+	public function get_state_name_by_ID($state_ID)
159
+	{
160
+		if (
161
+			isset(self::$_all_states[ $state_ID ]) &&
162
+				self::$_all_states[ $state_ID ] instanceof EE_State
163
+		) {
164
+			return self::$_all_states[ $state_ID ]->name();
165
+		}
166
+		$names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
167
+		if (is_array($names) && ! empty($names)) {
168
+			return reset($names);
169
+		} else {
170
+			return '';
171
+		}
172
+	}
173 173
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Template.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@
 block discarded – undo
43 43
             'Ticket' => new EE_Has_Many_Relation()
44 44
         );
45 45
         $this->_model_chain_to_wp_user = 'Ticket';
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47 47
         // account for default tickets in the caps
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
51 51
         parent::__construct($timezone);
52 52
     }
53 53
 }
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,40 +11,40 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Ticket_Template extends EEM_Base
13 13
 {
14
-    // private instance of the EEM_Ticket_Template object
15
-    protected static $_instance = null;
14
+	// private instance of the EEM_Ticket_Template object
15
+	protected static $_instance = null;
16 16
 
17
-    /**
18
-     *      private constructor to prevent direct creation
19
-     *      @Constructor
20
-     *      @access private
21
-     *      @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)
22
-     *      @return void
23
-     */
24
-    protected function __construct($timezone)
25
-    {
26
-        $this->singular_item = esc_html__('Ticket Template', 'event_espresso');
27
-        $this->plural_item = esc_html__('Ticket Templates', 'event_espresso');
17
+	/**
18
+	 *      private constructor to prevent direct creation
19
+	 *      @Constructor
20
+	 *      @access private
21
+	 *      @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)
22
+	 *      @return void
23
+	 */
24
+	protected function __construct($timezone)
25
+	{
26
+		$this->singular_item = esc_html__('Ticket Template', 'event_espresso');
27
+		$this->plural_item = esc_html__('Ticket Templates', 'event_espresso');
28 28
 
29
-        $this->_tables = array(
30
-            'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
31
-        );
32
-        $this->_fields = array(
33
-            'Ticket_Template' => array(
34
-                'TTM_ID' => new EE_Primary_Key_Int_Field('TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')),
35
-                'TTM_name' => new EE_Plain_Text_Field('TTM_name', esc_html__('The name of the ticket template', 'event_espresso'), false, ''),
36
-                'TTM_description' => new EE_Plain_Text_Field('TTM_description', esc_html__('The description for the ticket template', 'event_espresso'), true, ''),
37
-                'TTM_file' => new EE_Plain_Text_Field('TTM_file', esc_html__('The file name for the actual template file saved on disk', 'event_espresso'), true, ''),
38
-            ));
39
-        $this->_model_relations = array(
40
-            'Ticket' => new EE_Has_Many_Relation()
41
-        );
42
-        $this->_model_chain_to_wp_user = 'Ticket';
43
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
44
-        // account for default tickets in the caps
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        parent::__construct($timezone);
49
-    }
29
+		$this->_tables = array(
30
+			'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
31
+		);
32
+		$this->_fields = array(
33
+			'Ticket_Template' => array(
34
+				'TTM_ID' => new EE_Primary_Key_Int_Field('TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')),
35
+				'TTM_name' => new EE_Plain_Text_Field('TTM_name', esc_html__('The name of the ticket template', 'event_espresso'), false, ''),
36
+				'TTM_description' => new EE_Plain_Text_Field('TTM_description', esc_html__('The description for the ticket template', 'event_espresso'), true, ''),
37
+				'TTM_file' => new EE_Plain_Text_Field('TTM_file', esc_html__('The file name for the actual template file saved on disk', 'event_espresso'), true, ''),
38
+			));
39
+		$this->_model_relations = array(
40
+			'Ticket' => new EE_Has_Many_Relation()
41
+		);
42
+		$this->_model_chain_to_wp_user = 'Ticket';
43
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
44
+		// account for default tickets in the caps
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+		parent::__construct($timezone);
49
+	}
50 50
 }
Please login to merge, or discard this patch.