Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/db_classes/EE_Payment.class.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      */
297 297
     public function timestamp($dt_frmt = '', $tm_frmt = '')
298 298
     {
299
-        return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt));
299
+        return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt));
300 300
     }
301 301
 
302 302
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
                     : '';
482 482
                 break;
483 483
         }
484
-        return $icon . $status[ $this->STS_ID() ];
484
+        return $icon.$status[$this->STS_ID()];
485 485
     }
486 486
 
487 487
 
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
     public function redirect_form($inside_form_html = null)
628 628
     {
629 629
         $redirect_url = $this->redirect_url();
630
-        if (! empty($redirect_url)) {
630
+        if ( ! empty($redirect_url)) {
631 631
             // what ? no inner form content?
632 632
             if ($inside_form_html === null) {
633 633
                 $inside_form_html = EEH_HTML::p(
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
                 $get_params = null;
658 658
                 parse_str($querystring, $get_params);
659 659
                 $inside_form_html .= $this->_args_as_inputs($get_params);
660
-                $redirect_url = str_replace('?' . $querystring, '', $redirect_url);
660
+                $redirect_url = str_replace('?'.$querystring, '', $redirect_url);
661 661
             }
662 662
             $form = EEH_HTML::nl(1)
663 663
                     . '<form method="'
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
                     . '" name="gateway_form" action="'
666 666
                     . $redirect_url
667 667
                     . '">';
668
-            $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs();
668
+            $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs();
669 669
             $form .= $inside_form_html;
670
-            $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1);
670
+            $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1);
671 671
             return $form;
672 672
         } else {
673 673
             return null;
@@ -725,8 +725,8 @@  discard block
 block discarded – undo
725 725
             return $html;
726 726
         }
727 727
         return EEH_HTML::nl()
728
-            . '<input type="hidden" name="' . $name . '"'
729
-            . ' value="' . esc_attr($value) . '"/>';
728
+            . '<input type="hidden" name="'.$name.'"'
729
+            . ' value="'.esc_attr($value).'"/>';
730 730
     }
731 731
 
732 732
 
Please login to merge, or discard this patch.
Indentation   +870 added lines, -870 removed lines patch added patch discarded remove patch
@@ -10,874 +10,874 @@
 block discarded – undo
10 10
 class EE_Payment extends EE_Base_Class implements EEI_Payment
11 11
 {
12 12
 
13
-    /**
14
-     * @param array  $props_n_values          incoming values
15
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
-     *                                        used.)
17
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
-     *                                        date_format and the second value is the time format
19
-     * @return EE_Payment
20
-     * @throws \EE_Error
21
-     */
22
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
23
-    {
24
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
-    }
27
-
28
-
29
-    /**
30
-     * @param array  $props_n_values  incoming values from the database
31
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
-     *                                the website will be used.
33
-     * @return EE_Payment
34
-     * @throws \EE_Error
35
-     */
36
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
37
-    {
38
-        return new self($props_n_values, true, $timezone);
39
-    }
40
-
41
-
42
-    /**
43
-     * Set Transaction ID
44
-     *
45
-     * @access public
46
-     * @param int $TXN_ID
47
-     * @throws \EE_Error
48
-     */
49
-    public function set_transaction_id($TXN_ID = 0)
50
-    {
51
-        $this->set('TXN_ID', $TXN_ID);
52
-    }
53
-
54
-
55
-    /**
56
-     * Gets the transaction related to this payment
57
-     *
58
-     * @return EE_Transaction
59
-     * @throws \EE_Error
60
-     */
61
-    public function transaction()
62
-    {
63
-        return $this->get_first_related('Transaction');
64
-    }
65
-
66
-
67
-    /**
68
-     * Set Status
69
-     *
70
-     * @access public
71
-     * @param string $STS_ID
72
-     * @throws \EE_Error
73
-     */
74
-    public function set_status($STS_ID = '')
75
-    {
76
-        $this->set('STS_ID', $STS_ID);
77
-    }
78
-
79
-
80
-    /**
81
-     * Set Payment Timestamp
82
-     *
83
-     * @access public
84
-     * @param int $timestamp
85
-     * @throws \EE_Error
86
-     */
87
-    public function set_timestamp($timestamp = 0)
88
-    {
89
-        $this->set('PAY_timestamp', $timestamp);
90
-    }
91
-
92
-
93
-    /**
94
-     * Set Payment Method
95
-     *
96
-     * @access public
97
-     * @param string $PAY_source
98
-     * @throws \EE_Error
99
-     */
100
-    public function set_source($PAY_source = '')
101
-    {
102
-        $this->set('PAY_source', $PAY_source);
103
-    }
104
-
105
-
106
-    /**
107
-     * Set Payment Amount
108
-     *
109
-     * @access public
110
-     * @param float $amount
111
-     * @throws \EE_Error
112
-     */
113
-    public function set_amount($amount = 0.00)
114
-    {
115
-        $this->set('PAY_amount', (float) $amount);
116
-    }
117
-
118
-
119
-    /**
120
-     * Set Payment Gateway Response
121
-     *
122
-     * @access public
123
-     * @param string $gateway_response
124
-     * @throws \EE_Error
125
-     */
126
-    public function set_gateway_response($gateway_response = '')
127
-    {
128
-        $this->set('PAY_gateway_response', $gateway_response);
129
-    }
130
-
131
-
132
-    /**
133
-     * Returns the name of the payment method used on this payment (previously known merely as 'gateway')
134
-     * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method
135
-     * used on it
136
-     *
137
-     * @deprecated
138
-     * @return string
139
-     * @throws \EE_Error
140
-     */
141
-    public function gateway()
142
-    {
143
-        EE_Error::doing_it_wrong(
144
-            'EE_Payment::gateway',
145
-            esc_html__(
146
-                'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()',
147
-                'event_espresso'
148
-            ),
149
-            '4.6.0'
150
-        );
151
-        return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
152
-    }
153
-
154
-
155
-    /**
156
-     * Set Gateway Transaction ID
157
-     *
158
-     * @access public
159
-     * @param string $txn_id_chq_nmbr
160
-     * @throws \EE_Error
161
-     */
162
-    public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '')
163
-    {
164
-        $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr);
165
-    }
166
-
167
-
168
-    /**
169
-     * Set Purchase Order Number
170
-     *
171
-     * @access public
172
-     * @param string $po_number
173
-     * @throws \EE_Error
174
-     */
175
-    public function set_po_number($po_number = '')
176
-    {
177
-        $this->set('PAY_po_number', $po_number);
178
-    }
179
-
180
-
181
-    /**
182
-     * Set Extra Accounting Field
183
-     *
184
-     * @access public
185
-     * @param string $extra_accntng
186
-     * @throws \EE_Error
187
-     */
188
-    public function set_extra_accntng($extra_accntng = '')
189
-    {
190
-        $this->set('PAY_extra_accntng', $extra_accntng);
191
-    }
192
-
193
-
194
-    /**
195
-     * Set Payment made via admin flag
196
-     *
197
-     * @access public
198
-     * @param bool $via_admin
199
-     * @throws \EE_Error
200
-     */
201
-    public function set_payment_made_via_admin($via_admin = false)
202
-    {
203
-        if ($via_admin) {
204
-            $this->set('PAY_source', EEM_Payment_Method::scope_admin);
205
-        } else {
206
-            $this->set('PAY_source', EEM_Payment_Method::scope_cart);
207
-        }
208
-    }
209
-
210
-
211
-    /**
212
-     * Set Payment Details
213
-     *
214
-     * @access public
215
-     * @param string|array $details
216
-     * @throws \EE_Error
217
-     */
218
-    public function set_details($details = '')
219
-    {
220
-        if (is_array($details)) {
221
-            array_walk_recursive($details, array($this, '_strip_all_tags_within_array'));
222
-        } else {
223
-            $details = wp_strip_all_tags($details);
224
-        }
225
-        $this->set('PAY_details', $details);
226
-    }
227
-
228
-
229
-    /**
230
-     * Sets redirect_url
231
-     *
232
-     * @param string $redirect_url
233
-     * @throws \EE_Error
234
-     */
235
-    public function set_redirect_url($redirect_url)
236
-    {
237
-        $this->set('PAY_redirect_url', $redirect_url);
238
-    }
239
-
240
-
241
-    /**
242
-     * Sets redirect_args
243
-     *
244
-     * @param array $redirect_args
245
-     * @throws \EE_Error
246
-     */
247
-    public function set_redirect_args($redirect_args)
248
-    {
249
-        $this->set('PAY_redirect_args', $redirect_args);
250
-    }
251
-
252
-
253
-    /**
254
-     * get Payment Transaction ID
255
-     *
256
-     * @access public
257
-     * @throws \EE_Error
258
-     */
259
-    public function TXN_ID()
260
-    {
261
-        return $this->get('TXN_ID');
262
-    }
263
-
264
-
265
-    /**
266
-     * get Payment Status
267
-     *
268
-     * @access public
269
-     * @throws \EE_Error
270
-     */
271
-    public function status()
272
-    {
273
-        return $this->get('STS_ID');
274
-    }
275
-
276
-
277
-    /**
278
-     * get Payment Status
279
-     *
280
-     * @access public
281
-     * @throws \EE_Error
282
-     */
283
-    public function STS_ID()
284
-    {
285
-        return $this->get('STS_ID');
286
-    }
287
-
288
-
289
-    /**
290
-     * get Payment Timestamp
291
-     *
292
-     * @access public
293
-     * @param string $dt_frmt
294
-     * @param string $tm_frmt
295
-     * @return string
296
-     * @throws \EE_Error
297
-     */
298
-    public function timestamp($dt_frmt = '', $tm_frmt = '')
299
-    {
300
-        return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt));
301
-    }
302
-
303
-
304
-    /**
305
-     * get Payment Source
306
-     *
307
-     * @access public
308
-     * @throws \EE_Error
309
-     */
310
-    public function source()
311
-    {
312
-        return $this->get('PAY_source');
313
-    }
314
-
315
-
316
-    /**
317
-     * get Payment Amount
318
-     *
319
-     * @access public
320
-     * @return float
321
-     * @throws \EE_Error
322
-     */
323
-    public function amount()
324
-    {
325
-        return (float) $this->get('PAY_amount');
326
-    }
327
-
328
-
329
-    /**
330
-     * @return mixed
331
-     * @throws \EE_Error
332
-     */
333
-    public function amount_no_code()
334
-    {
335
-        return $this->get_pretty('PAY_amount', 'no_currency_code');
336
-    }
337
-
338
-
339
-    /**
340
-     * get Payment Gateway Response
341
-     *
342
-     * @access public
343
-     * @throws \EE_Error
344
-     */
345
-    public function gateway_response()
346
-    {
347
-        return $this->get('PAY_gateway_response');
348
-    }
349
-
350
-
351
-    /**
352
-     * get Payment Gateway Transaction ID
353
-     *
354
-     * @access public
355
-     * @throws \EE_Error
356
-     */
357
-    public function txn_id_chq_nmbr()
358
-    {
359
-        return $this->get('PAY_txn_id_chq_nmbr');
360
-    }
361
-
362
-
363
-    /**
364
-     * get Purchase Order Number
365
-     *
366
-     * @access public
367
-     * @throws \EE_Error
368
-     */
369
-    public function po_number()
370
-    {
371
-        return $this->get('PAY_po_number');
372
-    }
373
-
374
-
375
-    /**
376
-     * get Extra Accounting Field
377
-     *
378
-     * @access public
379
-     * @throws \EE_Error
380
-     */
381
-    public function extra_accntng()
382
-    {
383
-        return $this->get('PAY_extra_accntng');
384
-    }
385
-
386
-
387
-    /**
388
-     * get Payment made via admin source
389
-     *
390
-     * @access public
391
-     * @throws \EE_Error
392
-     */
393
-    public function payment_made_via_admin()
394
-    {
395
-        return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin);
396
-    }
397
-
398
-
399
-    /**
400
-     * get Payment Details
401
-     *
402
-     * @access public
403
-     * @throws \EE_Error
404
-     */
405
-    public function details()
406
-    {
407
-        return $this->get('PAY_details');
408
-    }
409
-
410
-
411
-    /**
412
-     * Gets redirect_url
413
-     *
414
-     * @return string
415
-     * @throws \EE_Error
416
-     */
417
-    public function redirect_url()
418
-    {
419
-        return $this->get('PAY_redirect_url');
420
-    }
421
-
422
-
423
-    /**
424
-     * Gets redirect_args
425
-     *
426
-     * @return array
427
-     * @throws \EE_Error
428
-     */
429
-    public function redirect_args()
430
-    {
431
-        return $this->get('PAY_redirect_args');
432
-    }
433
-
434
-
435
-    /**
436
-     * echoes $this->pretty_status()
437
-     *
438
-     * @param bool $show_icons
439
-     * @return void
440
-     * @throws \EE_Error
441
-     */
442
-    public function e_pretty_status($show_icons = false)
443
-    {
444
-        echo $this->pretty_status($show_icons); // already escaped
445
-    }
446
-
447
-
448
-    /**
449
-     * returns a pretty version of the status, good for displaying to users
450
-     *
451
-     * @param bool $show_icons
452
-     * @return string
453
-     * @throws \EE_Error
454
-     */
455
-    public function pretty_status($show_icons = false)
456
-    {
457
-        $status = EEM_Status::instance()->localized_status(
458
-            array($this->STS_ID() => esc_html__('unknown', 'event_espresso')),
459
-            false,
460
-            'sentence'
461
-        );
462
-        $icon = '';
463
-        switch ($this->STS_ID()) {
464
-            case EEM_Payment::status_id_approved:
465
-                $icon = $show_icons
466
-                    ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>'
467
-                    : '';
468
-                break;
469
-            case EEM_Payment::status_id_pending:
470
-                $icon = $show_icons
471
-                    ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>'
472
-                    : '';
473
-                break;
474
-            case EEM_Payment::status_id_cancelled:
475
-                $icon = $show_icons
476
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
477
-                    : '';
478
-                break;
479
-            case EEM_Payment::status_id_declined:
480
-                $icon = $show_icons
481
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
482
-                    : '';
483
-                break;
484
-        }
485
-        return $icon . $status[ $this->STS_ID() ];
486
-    }
487
-
488
-
489
-    /**
490
-     * For determining the status of the payment
491
-     *
492
-     * @return boolean whether the payment is approved or not
493
-     * @throws \EE_Error
494
-     */
495
-    public function is_approved()
496
-    {
497
-        return $this->status_is(EEM_Payment::status_id_approved);
498
-    }
499
-
500
-
501
-    /**
502
-     * Generally determines if the status of this payment equals
503
-     * the $STS_ID string
504
-     *
505
-     * @param string $STS_ID an ID from the esp_status table/
506
-     *                       one of the status_id_* on the EEM_Payment model
507
-     * @return boolean whether the status of this payment equals the status id
508
-     * @throws \EE_Error
509
-     */
510
-    protected function status_is($STS_ID)
511
-    {
512
-        return $STS_ID === $this->STS_ID() ? true : false;
513
-    }
514
-
515
-
516
-    /**
517
-     * For determining the status of the payment
518
-     *
519
-     * @return boolean whether the payment is pending or not
520
-     * @throws \EE_Error
521
-     */
522
-    public function is_pending()
523
-    {
524
-        return $this->status_is(EEM_Payment::status_id_pending);
525
-    }
526
-
527
-
528
-    /**
529
-     * For determining the status of the payment
530
-     *
531
-     * @return boolean
532
-     * @throws \EE_Error
533
-     */
534
-    public function is_cancelled()
535
-    {
536
-        return $this->status_is(EEM_Payment::status_id_cancelled);
537
-    }
538
-
539
-
540
-    /**
541
-     * For determining the status of the payment
542
-     *
543
-     * @return boolean
544
-     * @throws \EE_Error
545
-     */
546
-    public function is_declined()
547
-    {
548
-        return $this->status_is(EEM_Payment::status_id_declined);
549
-    }
550
-
551
-
552
-    /**
553
-     * For determining the status of the payment
554
-     *
555
-     * @return boolean
556
-     * @throws \EE_Error
557
-     */
558
-    public function is_failed()
559
-    {
560
-        return $this->status_is(EEM_Payment::status_id_failed);
561
-    }
562
-
563
-
564
-    /**
565
-     * For determining if the payment is actually a refund ( ie: has a negative value )
566
-     *
567
-     * @return boolean
568
-     * @throws \EE_Error
569
-     */
570
-    public function is_a_refund()
571
-    {
572
-        return $this->amount() < 0 ? true : false;
573
-    }
574
-
575
-
576
-    /**
577
-     * Get the status object of this object
578
-     *
579
-     * @return EE_Status
580
-     * @throws \EE_Error
581
-     */
582
-    public function status_obj()
583
-    {
584
-        return $this->get_first_related('Status');
585
-    }
586
-
587
-
588
-    /**
589
-     * Gets all the extra meta info on this payment
590
-     *
591
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
592
-     * @return EE_Extra_Meta
593
-     * @throws \EE_Error
594
-     */
595
-    public function extra_meta($query_params = array())
596
-    {
597
-        return $this->get_many_related('Extra_Meta', $query_params);
598
-    }
599
-
600
-
601
-    /**
602
-     * Gets the last-used payment method on this transaction
603
-     * (we COULD just use the last-made payment, but some payment methods, namely
604
-     * offline ones, dont' create payments)
605
-     *
606
-     * @return EE_Payment_Method
607
-     * @throws \EE_Error
608
-     */
609
-    public function payment_method()
610
-    {
611
-        return $this->get_first_related('Payment_Method');
612
-    }
613
-
614
-
615
-    /**
616
-     * Gets the HTML for redirecting the user to an offsite gateway
617
-     * You can pass it special content to put inside the form, or use
618
-     * the default inner content (or possibly generate this all yourself using
619
-     * redirect_url() and redirect_args() or redirect_args_as_inputs()).
620
-     * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead
621
-     * (and any querystring variables in the redirect_url are converted into html inputs
622
-     * so browsers submit them properly)
623
-     *
624
-     * @param string $inside_form_html
625
-     * @return string html
626
-     * @throws \EE_Error
627
-     */
628
-    public function redirect_form($inside_form_html = null)
629
-    {
630
-        $redirect_url = $this->redirect_url();
631
-        if (! empty($redirect_url)) {
632
-            // what ? no inner form content?
633
-            if ($inside_form_html === null) {
634
-                $inside_form_html = EEH_HTML::p(
635
-                    sprintf(
636
-                        esc_html__(
637
-                            'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s',
638
-                            'event_espresso'
639
-                        ),
640
-                        EEH_HTML::br(2),
641
-                        '<input type="submit" value="',
642
-                        '">'
643
-                    ),
644
-                    '',
645
-                    '',
646
-                    'text-align:center;'
647
-                );
648
-            }
649
-            $method = apply_filters(
650
-                'FHEE__EE_Payment__redirect_form__method',
651
-                $this->redirect_args() ? 'POST' : 'GET',
652
-                $this
653
-            );
654
-            // if it's a GET request, we need to remove all the GET params in the querystring
655
-            // and put them into the form instead
656
-            if ($method === 'GET') {
657
-                $querystring = parse_url($redirect_url, PHP_URL_QUERY);
658
-                $get_params = null;
659
-                parse_str($querystring, $get_params);
660
-                $inside_form_html .= $this->_args_as_inputs($get_params);
661
-                $redirect_url = str_replace('?' . $querystring, '', $redirect_url);
662
-            }
663
-            $form = EEH_HTML::nl(1)
664
-                    . '<form method="'
665
-                    . $method
666
-                    . '" name="gateway_form" action="'
667
-                    . $redirect_url
668
-                    . '">';
669
-            $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs();
670
-            $form .= $inside_form_html;
671
-            $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1);
672
-            return $form;
673
-        } else {
674
-            return null;
675
-        }
676
-    }
677
-
678
-
679
-    /**
680
-     * Changes all the name-value pairs of the redirect args into html inputs
681
-     * and returns the html as a string
682
-     *
683
-     * @return string
684
-     * @throws \EE_Error
685
-     */
686
-    public function redirect_args_as_inputs()
687
-    {
688
-        return $this->_args_as_inputs($this->redirect_args());
689
-    }
690
-
691
-
692
-    /**
693
-     * Converts a 2d array of key-value pairs into html hidden inputs
694
-     * and returns the string of html
695
-     *
696
-     * @param array $args key-value pairs
697
-     * @return string
698
-     */
699
-    protected function _args_as_inputs($args)
700
-    {
701
-        $html = '';
702
-        if ($args !== null && is_array($args)) {
703
-            foreach ($args as $name => $value) {
704
-                $html .= $this->generateInput($name, $value);
705
-            }
706
-        }
707
-        return $html;
708
-    }
709
-
710
-    /**
711
-     * Converts either a single name and value or array of values into html hidden inputs
712
-     * and returns the string of html
713
-     *
714
-     * @param string $name
715
-     * @param string|array $value
716
-     * @return string
717
-     */
718
-    private function generateInput($name, $value)
719
-    {
720
-        if (is_array($value)) {
721
-            $html = '';
722
-            $name = "{$name}[]";
723
-            foreach ($value as $array_value) {
724
-                $html .= $this->generateInput($name, $array_value);
725
-            }
726
-            return $html;
727
-        }
728
-        return EEH_HTML::nl()
729
-            . '<input type="hidden" name="' . $name . '"'
730
-            . ' value="' . esc_attr($value) . '"/>';
731
-    }
732
-
733
-
734
-    /**
735
-     * Returns the currency of the payment.
736
-     * (At the time of writing, this will always be the currency in the configuration;
737
-     * however in the future it is anticipated that this will be stored on the payment
738
-     * object itself)
739
-     *
740
-     * @return string for the currency code
741
-     */
742
-    public function currency_code()
743
-    {
744
-        return EE_Config::instance()->currency->code;
745
-    }
746
-
747
-
748
-    /**
749
-     * apply wp_strip_all_tags to all elements within an array
750
-     *
751
-     * @access private
752
-     * @param mixed $item
753
-     */
754
-    private function _strip_all_tags_within_array(&$item)
755
-    {
756
-        if (is_object($item)) {
757
-            $item = (array) $item;
758
-        }
759
-        if (is_array($item)) {
760
-            array_walk_recursive($item, array($this, '_strip_all_tags_within_array'));
761
-        } else {
762
-            $item = wp_strip_all_tags($item);
763
-        }
764
-    }
765
-
766
-
767
-    /**
768
-     * Returns TRUE is this payment was set to approved during this request (or
769
-     * is approved and was created during this request). False otherwise.
770
-     *
771
-     * @return boolean
772
-     * @throws \EE_Error
773
-     */
774
-    public function just_approved()
775
-    {
776
-        $original_status = EEH_Array::is_set(
777
-            $this->_props_n_values_provided_in_constructor,
778
-            'STS_ID',
779
-            $this->get_model()->field_settings_for('STS_ID')->get_default_value()
780
-        );
781
-        $current_status = $this->status();
782
-        if (
783
-            $original_status !== EEM_Payment::status_id_approved
784
-            && $current_status === EEM_Payment::status_id_approved
785
-        ) {
786
-            return true;
787
-        } else {
788
-            return false;
789
-        }
790
-    }
791
-
792
-
793
-    /**
794
-     * Overrides parents' get_pretty() function just for legacy reasons
795
-     * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420)
796
-     *
797
-     * @param string $field_name
798
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
799
-     *                                (in cases where the same property may be used for different outputs
800
-     *                                - i.e. datetime, money etc.)
801
-     * @return mixed
802
-     * @throws \EE_Error
803
-     */
804
-    public function get_pretty($field_name, $extra_cache_ref = null)
805
-    {
806
-        if ($field_name === 'PAY_gateway') {
807
-            return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
808
-        }
809
-        return $this->_get_cached_property($field_name, true, $extra_cache_ref);
810
-    }
811
-
812
-
813
-    /**
814
-     * Gets details regarding which registrations this payment was applied to
815
-     *
816
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
817
-     * @return EE_Registration_Payment[]
818
-     * @throws \EE_Error
819
-     */
820
-    public function registration_payments($query_params = array())
821
-    {
822
-        return $this->get_many_related('Registration_Payment', $query_params);
823
-    }
824
-
825
-
826
-    /**
827
-     * Gets the first event for this payment (it's possible that it could be for multiple)
828
-     *
829
-     * @return EE_Event|null
830
-     */
831
-    public function get_first_event()
832
-    {
833
-        $transaction = $this->transaction();
834
-        if ($transaction instanceof EE_Transaction) {
835
-            $primary_registrant = $transaction->primary_registration();
836
-            if ($primary_registrant instanceof EE_Registration) {
837
-                return $primary_registrant->event_obj();
838
-            }
839
-        }
840
-        return null;
841
-    }
842
-
843
-
844
-    /**
845
-     * Gets the name of the first event for which is being paid
846
-     *
847
-     * @return string
848
-     */
849
-    public function get_first_event_name()
850
-    {
851
-        $event = $this->get_first_event();
852
-        return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso');
853
-    }
854
-
855
-
856
-    /**
857
-     * Returns the payment's transaction's primary registration
858
-     *
859
-     * @return EE_Registration|null
860
-     */
861
-    public function get_primary_registration()
862
-    {
863
-        if ($this->transaction() instanceof EE_Transaction) {
864
-            return $this->transaction()->primary_registration();
865
-        }
866
-        return null;
867
-    }
868
-
869
-
870
-    /**
871
-     * Gets the payment's transaction's primary registration's attendee, or null
872
-     *
873
-     * @return EE_Attendee|null
874
-     */
875
-    public function get_primary_attendee()
876
-    {
877
-        $primary_reg = $this->get_primary_registration();
878
-        if ($primary_reg instanceof EE_Registration) {
879
-            return $primary_reg->attendee();
880
-        }
881
-        return null;
882
-    }
13
+	/**
14
+	 * @param array  $props_n_values          incoming values
15
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
+	 *                                        used.)
17
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
+	 *                                        date_format and the second value is the time format
19
+	 * @return EE_Payment
20
+	 * @throws \EE_Error
21
+	 */
22
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
23
+	{
24
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
+	}
27
+
28
+
29
+	/**
30
+	 * @param array  $props_n_values  incoming values from the database
31
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
+	 *                                the website will be used.
33
+	 * @return EE_Payment
34
+	 * @throws \EE_Error
35
+	 */
36
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
37
+	{
38
+		return new self($props_n_values, true, $timezone);
39
+	}
40
+
41
+
42
+	/**
43
+	 * Set Transaction ID
44
+	 *
45
+	 * @access public
46
+	 * @param int $TXN_ID
47
+	 * @throws \EE_Error
48
+	 */
49
+	public function set_transaction_id($TXN_ID = 0)
50
+	{
51
+		$this->set('TXN_ID', $TXN_ID);
52
+	}
53
+
54
+
55
+	/**
56
+	 * Gets the transaction related to this payment
57
+	 *
58
+	 * @return EE_Transaction
59
+	 * @throws \EE_Error
60
+	 */
61
+	public function transaction()
62
+	{
63
+		return $this->get_first_related('Transaction');
64
+	}
65
+
66
+
67
+	/**
68
+	 * Set Status
69
+	 *
70
+	 * @access public
71
+	 * @param string $STS_ID
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function set_status($STS_ID = '')
75
+	{
76
+		$this->set('STS_ID', $STS_ID);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Set Payment Timestamp
82
+	 *
83
+	 * @access public
84
+	 * @param int $timestamp
85
+	 * @throws \EE_Error
86
+	 */
87
+	public function set_timestamp($timestamp = 0)
88
+	{
89
+		$this->set('PAY_timestamp', $timestamp);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Set Payment Method
95
+	 *
96
+	 * @access public
97
+	 * @param string $PAY_source
98
+	 * @throws \EE_Error
99
+	 */
100
+	public function set_source($PAY_source = '')
101
+	{
102
+		$this->set('PAY_source', $PAY_source);
103
+	}
104
+
105
+
106
+	/**
107
+	 * Set Payment Amount
108
+	 *
109
+	 * @access public
110
+	 * @param float $amount
111
+	 * @throws \EE_Error
112
+	 */
113
+	public function set_amount($amount = 0.00)
114
+	{
115
+		$this->set('PAY_amount', (float) $amount);
116
+	}
117
+
118
+
119
+	/**
120
+	 * Set Payment Gateway Response
121
+	 *
122
+	 * @access public
123
+	 * @param string $gateway_response
124
+	 * @throws \EE_Error
125
+	 */
126
+	public function set_gateway_response($gateway_response = '')
127
+	{
128
+		$this->set('PAY_gateway_response', $gateway_response);
129
+	}
130
+
131
+
132
+	/**
133
+	 * Returns the name of the payment method used on this payment (previously known merely as 'gateway')
134
+	 * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method
135
+	 * used on it
136
+	 *
137
+	 * @deprecated
138
+	 * @return string
139
+	 * @throws \EE_Error
140
+	 */
141
+	public function gateway()
142
+	{
143
+		EE_Error::doing_it_wrong(
144
+			'EE_Payment::gateway',
145
+			esc_html__(
146
+				'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()',
147
+				'event_espresso'
148
+			),
149
+			'4.6.0'
150
+		);
151
+		return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
152
+	}
153
+
154
+
155
+	/**
156
+	 * Set Gateway Transaction ID
157
+	 *
158
+	 * @access public
159
+	 * @param string $txn_id_chq_nmbr
160
+	 * @throws \EE_Error
161
+	 */
162
+	public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '')
163
+	{
164
+		$this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr);
165
+	}
166
+
167
+
168
+	/**
169
+	 * Set Purchase Order Number
170
+	 *
171
+	 * @access public
172
+	 * @param string $po_number
173
+	 * @throws \EE_Error
174
+	 */
175
+	public function set_po_number($po_number = '')
176
+	{
177
+		$this->set('PAY_po_number', $po_number);
178
+	}
179
+
180
+
181
+	/**
182
+	 * Set Extra Accounting Field
183
+	 *
184
+	 * @access public
185
+	 * @param string $extra_accntng
186
+	 * @throws \EE_Error
187
+	 */
188
+	public function set_extra_accntng($extra_accntng = '')
189
+	{
190
+		$this->set('PAY_extra_accntng', $extra_accntng);
191
+	}
192
+
193
+
194
+	/**
195
+	 * Set Payment made via admin flag
196
+	 *
197
+	 * @access public
198
+	 * @param bool $via_admin
199
+	 * @throws \EE_Error
200
+	 */
201
+	public function set_payment_made_via_admin($via_admin = false)
202
+	{
203
+		if ($via_admin) {
204
+			$this->set('PAY_source', EEM_Payment_Method::scope_admin);
205
+		} else {
206
+			$this->set('PAY_source', EEM_Payment_Method::scope_cart);
207
+		}
208
+	}
209
+
210
+
211
+	/**
212
+	 * Set Payment Details
213
+	 *
214
+	 * @access public
215
+	 * @param string|array $details
216
+	 * @throws \EE_Error
217
+	 */
218
+	public function set_details($details = '')
219
+	{
220
+		if (is_array($details)) {
221
+			array_walk_recursive($details, array($this, '_strip_all_tags_within_array'));
222
+		} else {
223
+			$details = wp_strip_all_tags($details);
224
+		}
225
+		$this->set('PAY_details', $details);
226
+	}
227
+
228
+
229
+	/**
230
+	 * Sets redirect_url
231
+	 *
232
+	 * @param string $redirect_url
233
+	 * @throws \EE_Error
234
+	 */
235
+	public function set_redirect_url($redirect_url)
236
+	{
237
+		$this->set('PAY_redirect_url', $redirect_url);
238
+	}
239
+
240
+
241
+	/**
242
+	 * Sets redirect_args
243
+	 *
244
+	 * @param array $redirect_args
245
+	 * @throws \EE_Error
246
+	 */
247
+	public function set_redirect_args($redirect_args)
248
+	{
249
+		$this->set('PAY_redirect_args', $redirect_args);
250
+	}
251
+
252
+
253
+	/**
254
+	 * get Payment Transaction ID
255
+	 *
256
+	 * @access public
257
+	 * @throws \EE_Error
258
+	 */
259
+	public function TXN_ID()
260
+	{
261
+		return $this->get('TXN_ID');
262
+	}
263
+
264
+
265
+	/**
266
+	 * get Payment Status
267
+	 *
268
+	 * @access public
269
+	 * @throws \EE_Error
270
+	 */
271
+	public function status()
272
+	{
273
+		return $this->get('STS_ID');
274
+	}
275
+
276
+
277
+	/**
278
+	 * get Payment Status
279
+	 *
280
+	 * @access public
281
+	 * @throws \EE_Error
282
+	 */
283
+	public function STS_ID()
284
+	{
285
+		return $this->get('STS_ID');
286
+	}
287
+
288
+
289
+	/**
290
+	 * get Payment Timestamp
291
+	 *
292
+	 * @access public
293
+	 * @param string $dt_frmt
294
+	 * @param string $tm_frmt
295
+	 * @return string
296
+	 * @throws \EE_Error
297
+	 */
298
+	public function timestamp($dt_frmt = '', $tm_frmt = '')
299
+	{
300
+		return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt));
301
+	}
302
+
303
+
304
+	/**
305
+	 * get Payment Source
306
+	 *
307
+	 * @access public
308
+	 * @throws \EE_Error
309
+	 */
310
+	public function source()
311
+	{
312
+		return $this->get('PAY_source');
313
+	}
314
+
315
+
316
+	/**
317
+	 * get Payment Amount
318
+	 *
319
+	 * @access public
320
+	 * @return float
321
+	 * @throws \EE_Error
322
+	 */
323
+	public function amount()
324
+	{
325
+		return (float) $this->get('PAY_amount');
326
+	}
327
+
328
+
329
+	/**
330
+	 * @return mixed
331
+	 * @throws \EE_Error
332
+	 */
333
+	public function amount_no_code()
334
+	{
335
+		return $this->get_pretty('PAY_amount', 'no_currency_code');
336
+	}
337
+
338
+
339
+	/**
340
+	 * get Payment Gateway Response
341
+	 *
342
+	 * @access public
343
+	 * @throws \EE_Error
344
+	 */
345
+	public function gateway_response()
346
+	{
347
+		return $this->get('PAY_gateway_response');
348
+	}
349
+
350
+
351
+	/**
352
+	 * get Payment Gateway Transaction ID
353
+	 *
354
+	 * @access public
355
+	 * @throws \EE_Error
356
+	 */
357
+	public function txn_id_chq_nmbr()
358
+	{
359
+		return $this->get('PAY_txn_id_chq_nmbr');
360
+	}
361
+
362
+
363
+	/**
364
+	 * get Purchase Order Number
365
+	 *
366
+	 * @access public
367
+	 * @throws \EE_Error
368
+	 */
369
+	public function po_number()
370
+	{
371
+		return $this->get('PAY_po_number');
372
+	}
373
+
374
+
375
+	/**
376
+	 * get Extra Accounting Field
377
+	 *
378
+	 * @access public
379
+	 * @throws \EE_Error
380
+	 */
381
+	public function extra_accntng()
382
+	{
383
+		return $this->get('PAY_extra_accntng');
384
+	}
385
+
386
+
387
+	/**
388
+	 * get Payment made via admin source
389
+	 *
390
+	 * @access public
391
+	 * @throws \EE_Error
392
+	 */
393
+	public function payment_made_via_admin()
394
+	{
395
+		return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin);
396
+	}
397
+
398
+
399
+	/**
400
+	 * get Payment Details
401
+	 *
402
+	 * @access public
403
+	 * @throws \EE_Error
404
+	 */
405
+	public function details()
406
+	{
407
+		return $this->get('PAY_details');
408
+	}
409
+
410
+
411
+	/**
412
+	 * Gets redirect_url
413
+	 *
414
+	 * @return string
415
+	 * @throws \EE_Error
416
+	 */
417
+	public function redirect_url()
418
+	{
419
+		return $this->get('PAY_redirect_url');
420
+	}
421
+
422
+
423
+	/**
424
+	 * Gets redirect_args
425
+	 *
426
+	 * @return array
427
+	 * @throws \EE_Error
428
+	 */
429
+	public function redirect_args()
430
+	{
431
+		return $this->get('PAY_redirect_args');
432
+	}
433
+
434
+
435
+	/**
436
+	 * echoes $this->pretty_status()
437
+	 *
438
+	 * @param bool $show_icons
439
+	 * @return void
440
+	 * @throws \EE_Error
441
+	 */
442
+	public function e_pretty_status($show_icons = false)
443
+	{
444
+		echo $this->pretty_status($show_icons); // already escaped
445
+	}
446
+
447
+
448
+	/**
449
+	 * returns a pretty version of the status, good for displaying to users
450
+	 *
451
+	 * @param bool $show_icons
452
+	 * @return string
453
+	 * @throws \EE_Error
454
+	 */
455
+	public function pretty_status($show_icons = false)
456
+	{
457
+		$status = EEM_Status::instance()->localized_status(
458
+			array($this->STS_ID() => esc_html__('unknown', 'event_espresso')),
459
+			false,
460
+			'sentence'
461
+		);
462
+		$icon = '';
463
+		switch ($this->STS_ID()) {
464
+			case EEM_Payment::status_id_approved:
465
+				$icon = $show_icons
466
+					? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>'
467
+					: '';
468
+				break;
469
+			case EEM_Payment::status_id_pending:
470
+				$icon = $show_icons
471
+					? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>'
472
+					: '';
473
+				break;
474
+			case EEM_Payment::status_id_cancelled:
475
+				$icon = $show_icons
476
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
477
+					: '';
478
+				break;
479
+			case EEM_Payment::status_id_declined:
480
+				$icon = $show_icons
481
+					? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
482
+					: '';
483
+				break;
484
+		}
485
+		return $icon . $status[ $this->STS_ID() ];
486
+	}
487
+
488
+
489
+	/**
490
+	 * For determining the status of the payment
491
+	 *
492
+	 * @return boolean whether the payment is approved or not
493
+	 * @throws \EE_Error
494
+	 */
495
+	public function is_approved()
496
+	{
497
+		return $this->status_is(EEM_Payment::status_id_approved);
498
+	}
499
+
500
+
501
+	/**
502
+	 * Generally determines if the status of this payment equals
503
+	 * the $STS_ID string
504
+	 *
505
+	 * @param string $STS_ID an ID from the esp_status table/
506
+	 *                       one of the status_id_* on the EEM_Payment model
507
+	 * @return boolean whether the status of this payment equals the status id
508
+	 * @throws \EE_Error
509
+	 */
510
+	protected function status_is($STS_ID)
511
+	{
512
+		return $STS_ID === $this->STS_ID() ? true : false;
513
+	}
514
+
515
+
516
+	/**
517
+	 * For determining the status of the payment
518
+	 *
519
+	 * @return boolean whether the payment is pending or not
520
+	 * @throws \EE_Error
521
+	 */
522
+	public function is_pending()
523
+	{
524
+		return $this->status_is(EEM_Payment::status_id_pending);
525
+	}
526
+
527
+
528
+	/**
529
+	 * For determining the status of the payment
530
+	 *
531
+	 * @return boolean
532
+	 * @throws \EE_Error
533
+	 */
534
+	public function is_cancelled()
535
+	{
536
+		return $this->status_is(EEM_Payment::status_id_cancelled);
537
+	}
538
+
539
+
540
+	/**
541
+	 * For determining the status of the payment
542
+	 *
543
+	 * @return boolean
544
+	 * @throws \EE_Error
545
+	 */
546
+	public function is_declined()
547
+	{
548
+		return $this->status_is(EEM_Payment::status_id_declined);
549
+	}
550
+
551
+
552
+	/**
553
+	 * For determining the status of the payment
554
+	 *
555
+	 * @return boolean
556
+	 * @throws \EE_Error
557
+	 */
558
+	public function is_failed()
559
+	{
560
+		return $this->status_is(EEM_Payment::status_id_failed);
561
+	}
562
+
563
+
564
+	/**
565
+	 * For determining if the payment is actually a refund ( ie: has a negative value )
566
+	 *
567
+	 * @return boolean
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function is_a_refund()
571
+	{
572
+		return $this->amount() < 0 ? true : false;
573
+	}
574
+
575
+
576
+	/**
577
+	 * Get the status object of this object
578
+	 *
579
+	 * @return EE_Status
580
+	 * @throws \EE_Error
581
+	 */
582
+	public function status_obj()
583
+	{
584
+		return $this->get_first_related('Status');
585
+	}
586
+
587
+
588
+	/**
589
+	 * Gets all the extra meta info on this payment
590
+	 *
591
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
592
+	 * @return EE_Extra_Meta
593
+	 * @throws \EE_Error
594
+	 */
595
+	public function extra_meta($query_params = array())
596
+	{
597
+		return $this->get_many_related('Extra_Meta', $query_params);
598
+	}
599
+
600
+
601
+	/**
602
+	 * Gets the last-used payment method on this transaction
603
+	 * (we COULD just use the last-made payment, but some payment methods, namely
604
+	 * offline ones, dont' create payments)
605
+	 *
606
+	 * @return EE_Payment_Method
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function payment_method()
610
+	{
611
+		return $this->get_first_related('Payment_Method');
612
+	}
613
+
614
+
615
+	/**
616
+	 * Gets the HTML for redirecting the user to an offsite gateway
617
+	 * You can pass it special content to put inside the form, or use
618
+	 * the default inner content (or possibly generate this all yourself using
619
+	 * redirect_url() and redirect_args() or redirect_args_as_inputs()).
620
+	 * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead
621
+	 * (and any querystring variables in the redirect_url are converted into html inputs
622
+	 * so browsers submit them properly)
623
+	 *
624
+	 * @param string $inside_form_html
625
+	 * @return string html
626
+	 * @throws \EE_Error
627
+	 */
628
+	public function redirect_form($inside_form_html = null)
629
+	{
630
+		$redirect_url = $this->redirect_url();
631
+		if (! empty($redirect_url)) {
632
+			// what ? no inner form content?
633
+			if ($inside_form_html === null) {
634
+				$inside_form_html = EEH_HTML::p(
635
+					sprintf(
636
+						esc_html__(
637
+							'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s',
638
+							'event_espresso'
639
+						),
640
+						EEH_HTML::br(2),
641
+						'<input type="submit" value="',
642
+						'">'
643
+					),
644
+					'',
645
+					'',
646
+					'text-align:center;'
647
+				);
648
+			}
649
+			$method = apply_filters(
650
+				'FHEE__EE_Payment__redirect_form__method',
651
+				$this->redirect_args() ? 'POST' : 'GET',
652
+				$this
653
+			);
654
+			// if it's a GET request, we need to remove all the GET params in the querystring
655
+			// and put them into the form instead
656
+			if ($method === 'GET') {
657
+				$querystring = parse_url($redirect_url, PHP_URL_QUERY);
658
+				$get_params = null;
659
+				parse_str($querystring, $get_params);
660
+				$inside_form_html .= $this->_args_as_inputs($get_params);
661
+				$redirect_url = str_replace('?' . $querystring, '', $redirect_url);
662
+			}
663
+			$form = EEH_HTML::nl(1)
664
+					. '<form method="'
665
+					. $method
666
+					. '" name="gateway_form" action="'
667
+					. $redirect_url
668
+					. '">';
669
+			$form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs();
670
+			$form .= $inside_form_html;
671
+			$form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1);
672
+			return $form;
673
+		} else {
674
+			return null;
675
+		}
676
+	}
677
+
678
+
679
+	/**
680
+	 * Changes all the name-value pairs of the redirect args into html inputs
681
+	 * and returns the html as a string
682
+	 *
683
+	 * @return string
684
+	 * @throws \EE_Error
685
+	 */
686
+	public function redirect_args_as_inputs()
687
+	{
688
+		return $this->_args_as_inputs($this->redirect_args());
689
+	}
690
+
691
+
692
+	/**
693
+	 * Converts a 2d array of key-value pairs into html hidden inputs
694
+	 * and returns the string of html
695
+	 *
696
+	 * @param array $args key-value pairs
697
+	 * @return string
698
+	 */
699
+	protected function _args_as_inputs($args)
700
+	{
701
+		$html = '';
702
+		if ($args !== null && is_array($args)) {
703
+			foreach ($args as $name => $value) {
704
+				$html .= $this->generateInput($name, $value);
705
+			}
706
+		}
707
+		return $html;
708
+	}
709
+
710
+	/**
711
+	 * Converts either a single name and value or array of values into html hidden inputs
712
+	 * and returns the string of html
713
+	 *
714
+	 * @param string $name
715
+	 * @param string|array $value
716
+	 * @return string
717
+	 */
718
+	private function generateInput($name, $value)
719
+	{
720
+		if (is_array($value)) {
721
+			$html = '';
722
+			$name = "{$name}[]";
723
+			foreach ($value as $array_value) {
724
+				$html .= $this->generateInput($name, $array_value);
725
+			}
726
+			return $html;
727
+		}
728
+		return EEH_HTML::nl()
729
+			. '<input type="hidden" name="' . $name . '"'
730
+			. ' value="' . esc_attr($value) . '"/>';
731
+	}
732
+
733
+
734
+	/**
735
+	 * Returns the currency of the payment.
736
+	 * (At the time of writing, this will always be the currency in the configuration;
737
+	 * however in the future it is anticipated that this will be stored on the payment
738
+	 * object itself)
739
+	 *
740
+	 * @return string for the currency code
741
+	 */
742
+	public function currency_code()
743
+	{
744
+		return EE_Config::instance()->currency->code;
745
+	}
746
+
747
+
748
+	/**
749
+	 * apply wp_strip_all_tags to all elements within an array
750
+	 *
751
+	 * @access private
752
+	 * @param mixed $item
753
+	 */
754
+	private function _strip_all_tags_within_array(&$item)
755
+	{
756
+		if (is_object($item)) {
757
+			$item = (array) $item;
758
+		}
759
+		if (is_array($item)) {
760
+			array_walk_recursive($item, array($this, '_strip_all_tags_within_array'));
761
+		} else {
762
+			$item = wp_strip_all_tags($item);
763
+		}
764
+	}
765
+
766
+
767
+	/**
768
+	 * Returns TRUE is this payment was set to approved during this request (or
769
+	 * is approved and was created during this request). False otherwise.
770
+	 *
771
+	 * @return boolean
772
+	 * @throws \EE_Error
773
+	 */
774
+	public function just_approved()
775
+	{
776
+		$original_status = EEH_Array::is_set(
777
+			$this->_props_n_values_provided_in_constructor,
778
+			'STS_ID',
779
+			$this->get_model()->field_settings_for('STS_ID')->get_default_value()
780
+		);
781
+		$current_status = $this->status();
782
+		if (
783
+			$original_status !== EEM_Payment::status_id_approved
784
+			&& $current_status === EEM_Payment::status_id_approved
785
+		) {
786
+			return true;
787
+		} else {
788
+			return false;
789
+		}
790
+	}
791
+
792
+
793
+	/**
794
+	 * Overrides parents' get_pretty() function just for legacy reasons
795
+	 * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420)
796
+	 *
797
+	 * @param string $field_name
798
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
799
+	 *                                (in cases where the same property may be used for different outputs
800
+	 *                                - i.e. datetime, money etc.)
801
+	 * @return mixed
802
+	 * @throws \EE_Error
803
+	 */
804
+	public function get_pretty($field_name, $extra_cache_ref = null)
805
+	{
806
+		if ($field_name === 'PAY_gateway') {
807
+			return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso');
808
+		}
809
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
810
+	}
811
+
812
+
813
+	/**
814
+	 * Gets details regarding which registrations this payment was applied to
815
+	 *
816
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
817
+	 * @return EE_Registration_Payment[]
818
+	 * @throws \EE_Error
819
+	 */
820
+	public function registration_payments($query_params = array())
821
+	{
822
+		return $this->get_many_related('Registration_Payment', $query_params);
823
+	}
824
+
825
+
826
+	/**
827
+	 * Gets the first event for this payment (it's possible that it could be for multiple)
828
+	 *
829
+	 * @return EE_Event|null
830
+	 */
831
+	public function get_first_event()
832
+	{
833
+		$transaction = $this->transaction();
834
+		if ($transaction instanceof EE_Transaction) {
835
+			$primary_registrant = $transaction->primary_registration();
836
+			if ($primary_registrant instanceof EE_Registration) {
837
+				return $primary_registrant->event_obj();
838
+			}
839
+		}
840
+		return null;
841
+	}
842
+
843
+
844
+	/**
845
+	 * Gets the name of the first event for which is being paid
846
+	 *
847
+	 * @return string
848
+	 */
849
+	public function get_first_event_name()
850
+	{
851
+		$event = $this->get_first_event();
852
+		return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso');
853
+	}
854
+
855
+
856
+	/**
857
+	 * Returns the payment's transaction's primary registration
858
+	 *
859
+	 * @return EE_Registration|null
860
+	 */
861
+	public function get_primary_registration()
862
+	{
863
+		if ($this->transaction() instanceof EE_Transaction) {
864
+			return $this->transaction()->primary_registration();
865
+		}
866
+		return null;
867
+	}
868
+
869
+
870
+	/**
871
+	 * Gets the payment's transaction's primary registration's attendee, or null
872
+	 *
873
+	 * @return EE_Attendee|null
874
+	 */
875
+	public function get_primary_attendee()
876
+	{
877
+		$primary_reg = $this->get_primary_registration();
878
+		if ($primary_reg instanceof EE_Registration) {
879
+			return $primary_reg->attendee();
880
+		}
881
+		return null;
882
+	}
883 883
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Payment_Method.class.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
      */
446 446
     public function type_obj()
447 447
     {
448
-        if (! $this->_type_obj) {
448
+        if ( ! $this->_type_obj) {
449 449
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
450 450
             if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
451 451
                 $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
452
-                if (! class_exists($class_name)) {
452
+                if ( ! class_exists($class_name)) {
453 453
                     throw new EE_Error(
454 454
                         sprintf(
455 455
                             esc_html__(
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
                             ),
459 459
                             $class_name,
460 460
                             '<br />',
461
-                            '<a href="' . admin_url('plugins.php') . '">',
461
+                            '<a href="'.admin_url('plugins.php').'">',
462 462
                             '</a>'
463 463
                         )
464 464
                     );
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
         foreach ($fields as $key => $value) {
500 500
             if (strpos($key, 'PMD_') === 0) {
501 501
                 $key_sans_model_prefix = str_replace('PMD_', '', $key);
502
-                $combined_settings_array [ $key_sans_model_prefix ] = $value;
502
+                $combined_settings_array [$key_sans_model_prefix] = $value;
503 503
             }
504 504
         }
505 505
         $combined_settings_array = array_merge($extra_meta, $combined_settings_array);
@@ -522,14 +522,14 @@  discard block
 block discarded – undo
522 522
 		 <div id="'
523 523
                . $this->slug()
524 524
                . '-payment-option-dv" class="'
525
-               . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
525
+               . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'">
526 526
 			<a id="payment-gateway-button-' . $this->slug()
527 527
                . '" class="reg-page-payment-option-lnk" rel="'
528
-               . $this->slug() . '" href="' . $url . '" >
529
-				<img src="' . $this->button_url() . '" alt="' . sprintf(
528
+               . $this->slug().'" href="'.$url.'" >
529
+				<img src="' . $this->button_url().'" alt="'.sprintf(
530 530
                    esc_attr__('Pay using %s', 'event_espresso'),
531 531
                    $this->get_pretty('PMD_name', 'form_input')
532
-               ) . '" />
532
+               ).'" />
533 533
 			</a>
534 534
 		</div>
535 535
 ';
Please login to merge, or discard this patch.
Indentation   +572 added lines, -572 removed lines patch added patch discarded remove patch
@@ -14,582 +14,582 @@
 block discarded – undo
14 14
 class EE_Payment_Method extends EE_Base_Class
15 15
 {
16 16
 
17
-    /**
18
-     * Payment Method type object, which has all the info about this type of payment method,
19
-     * including functions for processing payments, to get settings forms, etc.
20
-     *
21
-     * @var EE_PMT_Base
22
-     */
23
-    protected $_type_obj;
24
-
25
-
26
-    /**
27
-     * @param array $props_n_values
28
-     * @return EE_Payment_Method
29
-     * @throws \EE_Error
30
-     */
31
-    public static function new_instance($props_n_values = array())
32
-    {
33
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
34
-        return $has_object ? $has_object : new self($props_n_values, false);
35
-    }
36
-
37
-
38
-    /**
39
-     * @param array $props_n_values
40
-     * @return EE_Payment_Method
41
-     * @throws \EE_Error
42
-     */
43
-    public static function new_instance_from_db($props_n_values = array())
44
-    {
45
-        return new self($props_n_values, true);
46
-    }
47
-
48
-
49
-
50
-    /**
51
-     * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname.
52
-     * Otherwise returns a normal EE_Payment_Method
53
-     *
54
-     * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically
55
-     *                              the classname minus 'EEPM_')
56
-     * @return string
57
-     */
58
-    // private static function _payment_method_type($props_n_values)
59
-    // {
60
-    //     EE_Registry::instance()->load_lib('Payment_Method_Manager');
61
-    //     $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null;
62
-    //     if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) {
63
-    //         return 'EEPM_' . $type_string;
64
-    //     } else {
65
-    //         return __CLASS__;
66
-    //     }
67
-    // }
68
-
69
-
70
-    /**
71
-     * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc)
72
-     *
73
-     * @return boolean
74
-     */
75
-    public function active()
76
-    {
77
-        return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope());
78
-    }
79
-
80
-
81
-    /**
82
-     * Sets this PM as active by making it usable within the CART scope. Offline gateways
83
-     * are also usable from the admin-scope as well. DOES NOT SAVE it
84
-     *
85
-     * @throws \EE_Error
86
-     */
87
-    public function set_active()
88
-    {
89
-        $default_scopes = array(EEM_Payment_Method::scope_cart);
90
-        if (
91
-            $this->type_obj() &&
92
-            $this->type_obj()->payment_occurs() === EE_PMT_Base::offline
93
-        ) {
94
-            $default_scopes[] = EEM_Payment_Method::scope_admin;
95
-        }
96
-        $this->set_scope($default_scopes);
97
-    }
98
-
99
-
100
-    /**
101
-     * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it.
102
-     */
103
-    public function deactivate()
104
-    {
105
-        $this->set_scope(array());
106
-    }
107
-
108
-
109
-    /**
110
-     * Gets button_url
111
-     *
112
-     * @return string
113
-     */
114
-    public function button_url()
115
-    {
116
-        return $this->get('PMD_button_url');
117
-    }
118
-
119
-
120
-    /**
121
-     * Sets button_url
122
-     *
123
-     * @param string $button_url
124
-     */
125
-    public function set_button_url($button_url)
126
-    {
127
-        $this->set('PMD_button_url', $button_url);
128
-    }
129
-
130
-
131
-    /**
132
-     * Gets debug_mode
133
-     *
134
-     * @return boolean
135
-     */
136
-    public function debug_mode()
137
-    {
138
-        return $this->get('PMD_debug_mode');
139
-    }
140
-
141
-
142
-    /**
143
-     * Sets debug_mode
144
-     *
145
-     * @param boolean $debug_mode
146
-     */
147
-    public function set_debug_mode($debug_mode)
148
-    {
149
-        $this->set('PMD_debug_mode', $debug_mode);
150
-    }
151
-
152
-
153
-    /**
154
-     * Gets description
155
-     *
156
-     * @return string
157
-     */
158
-    public function description()
159
-    {
160
-        return $this->get('PMD_desc');
161
-    }
162
-
163
-
164
-    /**
165
-     * Sets description
166
-     *
167
-     * @param string $description
168
-     */
169
-    public function set_description($description)
170
-    {
171
-        $this->set('PMD_desc', $description);
172
-    }
173
-
174
-
175
-    /**
176
-     * Gets name
177
-     *
178
-     * @return string
179
-     */
180
-    public function name()
181
-    {
182
-        return $this->get('PMD_name');
183
-    }
184
-
185
-
186
-    /**
187
-     * Sets name
188
-     *
189
-     * @param string $name
190
-     */
191
-    public function set_name($name)
192
-    {
193
-        $this->set('PMD_name', $name);
194
-    }
195
-
196
-
197
-    /**
198
-     * Gets open_by_default
199
-     *
200
-     * @return boolean
201
-     */
202
-    public function open_by_default()
203
-    {
204
-        return $this->get('PMD_open_by_default');
205
-    }
206
-
207
-
208
-    /**
209
-     * Sets open_by_default
210
-     *
211
-     * @param boolean $open_by_default
212
-     */
213
-    public function set_open_by_default($open_by_default)
214
-    {
215
-        $this->set('PMD_open_by_default', $open_by_default);
216
-    }
217
-
218
-
219
-    /**
220
-     * Gets order
221
-     *
222
-     * @return int
223
-     */
224
-    public function order()
225
-    {
226
-        return $this->get('PMD_order');
227
-    }
228
-
229
-
230
-    /**
231
-     * Sets order
232
-     *
233
-     * @param int $order
234
-     */
235
-    public function set_order($order)
236
-    {
237
-        $this->set('PMD_order', $order);
238
-    }
239
-
240
-
241
-    /**
242
-     * Gets slug
243
-     *
244
-     * @return string
245
-     */
246
-    public function slug()
247
-    {
248
-        return $this->get('PMD_slug');
249
-    }
250
-
251
-
252
-    /**
253
-     * Sets slug
254
-     *
255
-     * @param string $slug
256
-     */
257
-    public function set_slug($slug)
258
-    {
259
-        $this->set('PMD_slug', $slug);
260
-    }
261
-
262
-
263
-    /**
264
-     * Gets type
265
-     *
266
-     * @return string
267
-     */
268
-    public function type()
269
-    {
270
-        return $this->get('PMD_type');
271
-    }
272
-
273
-
274
-    /**
275
-     * Sets type
276
-     *
277
-     * @param string $type
278
-     */
279
-    public function set_type($type)
280
-    {
281
-        $this->set('PMD_type', $type);
282
-    }
283
-
284
-
285
-    /**
286
-     * Gets wp_user
287
-     *
288
-     * @return int
289
-     */
290
-    public function wp_user()
291
-    {
292
-        return $this->get('PMD_wp_user');
293
-    }
294
-
295
-
296
-    /**
297
-     * Sets wp_user
298
-     *
299
-     * @param int $wp_user_id
300
-     */
301
-    public function set_wp_user($wp_user_id)
302
-    {
303
-        $this->set('PMD_wp_user', $wp_user_id);
304
-    }
305
-
306
-    /**
307
-     * Overrides parent so when PMD_type is changed we refresh the _type_obj
308
-     *
309
-     * @param string $field_name
310
-     * @param mixed $field_value
311
-     * @param boolean $use_default
312
-     */
313
-    public function set($field_name, $field_value, $use_default = false)
314
-    {
315
-        if ($field_name === 'PMD_type') {
316
-            // the type has probably changed, so forget about its old type object
317
-            $this->_type_obj = null;
318
-        }
319
-        parent::set($field_name, $field_value, $use_default);
320
-    }
321
-
322
-
323
-    /**
324
-     * Gets admin_name
325
-     *
326
-     * @return string
327
-     */
328
-    public function admin_name()
329
-    {
330
-        return $this->get('PMD_admin_name');
331
-    }
332
-
333
-
334
-    /**
335
-     * Sets admin_name
336
-     *
337
-     * @param string $admin_name
338
-     */
339
-    public function set_admin_name($admin_name)
340
-    {
341
-        $this->set('PMD_admin_name', $admin_name);
342
-    }
343
-
344
-
345
-    /**
346
-     * Gets admin_desc
347
-     *
348
-     * @return string
349
-     */
350
-    public function admin_desc()
351
-    {
352
-        return $this->get('PMD_admin_desc');
353
-    }
354
-
355
-
356
-    /**
357
-     * Sets admin_desc
358
-     *
359
-     * @param string $admin_desc
360
-     */
361
-    public function set_admin_desc($admin_desc)
362
-    {
363
-        $this->set('PMD_admin_desc', $admin_desc);
364
-    }
365
-
366
-
367
-    /**
368
-     * Gets scope
369
-     *
370
-     * @return array
371
-     */
372
-    public function scope()
373
-    {
374
-        return $this->get('PMD_scope');
375
-    }
376
-
377
-
378
-    /**
379
-     * Sets scope
380
-     *
381
-     * @param array $scope
382
-     */
383
-    public function set_scope($scope)
384
-    {
385
-        $this->set('PMD_scope', $scope);
386
-    }
387
-
388
-
389
-    /**
390
-     * Gets the payment method type for this payment method instance
391
-     *
392
-     * @return EE_PMT_Base
393
-     * @throws EE_Error
394
-     */
395
-    public function type_obj()
396
-    {
397
-        if (! $this->_type_obj) {
398
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
399
-            if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
400
-                $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
401
-                if (! class_exists($class_name)) {
402
-                    throw new EE_Error(
403
-                        sprintf(
404
-                            esc_html__(
405
-                                'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s',
406
-                                'event_espresso'
407
-                            ),
408
-                            $class_name,
409
-                            '<br />',
410
-                            '<a href="' . admin_url('plugins.php') . '">',
411
-                            '</a>'
412
-                        )
413
-                    );
414
-                }
415
-                $r = new ReflectionClass($class_name);
416
-                $this->_type_obj = $r->newInstanceArgs(array($this));
417
-            } else {
418
-                throw new EE_Error(
419
-                    sprintf(
420
-                        esc_html__(
421
-                            'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s',
422
-                            'event_espresso'
423
-                        ),
424
-                        $this->type(),
425
-                        implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names())
426
-                    )
427
-                );
428
-            }
429
-        }
430
-        return $this->_type_obj;
431
-    }
432
-
433
-
434
-    /**
435
-     * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix)
436
-     * and the extra meta. Mostly used for passing off ot gateways.     *
437
-     *
438
-     * @return array
439
-     */
440
-    public function settings_array()
441
-    {
442
-        $fields = $this->model_field_array();
443
-        $extra_meta = $this->all_extra_meta_array();
444
-        // remove the model's prefix from the fields
445
-        $combined_settings_array = array();
446
-        foreach ($fields as $key => $value) {
447
-            if (strpos($key, 'PMD_') === 0) {
448
-                $key_sans_model_prefix = str_replace('PMD_', '', $key);
449
-                $combined_settings_array [ $key_sans_model_prefix ] = $value;
450
-            }
451
-        }
452
-        $combined_settings_array = array_merge($extra_meta, $combined_settings_array);
453
-        return $combined_settings_array;
454
-    }
455
-
456
-
457
-    /**
458
-     * Gets the HTML for displaying the payment method on a page.
459
-     *
460
-     * @param string $url
461
-     * @param string $css_class
462
-     * @return string of HTML for displaying the button
463
-     * @throws \EE_Error
464
-     */
465
-    public function button_html($url = '', $css_class = '')
466
-    {
467
-        $payment_occurs = $this->type_obj()->payment_occurs();
468
-        return '
17
+	/**
18
+	 * Payment Method type object, which has all the info about this type of payment method,
19
+	 * including functions for processing payments, to get settings forms, etc.
20
+	 *
21
+	 * @var EE_PMT_Base
22
+	 */
23
+	protected $_type_obj;
24
+
25
+
26
+	/**
27
+	 * @param array $props_n_values
28
+	 * @return EE_Payment_Method
29
+	 * @throws \EE_Error
30
+	 */
31
+	public static function new_instance($props_n_values = array())
32
+	{
33
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
34
+		return $has_object ? $has_object : new self($props_n_values, false);
35
+	}
36
+
37
+
38
+	/**
39
+	 * @param array $props_n_values
40
+	 * @return EE_Payment_Method
41
+	 * @throws \EE_Error
42
+	 */
43
+	public static function new_instance_from_db($props_n_values = array())
44
+	{
45
+		return new self($props_n_values, true);
46
+	}
47
+
48
+
49
+
50
+	/**
51
+	 * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname.
52
+	 * Otherwise returns a normal EE_Payment_Method
53
+	 *
54
+	 * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically
55
+	 *                              the classname minus 'EEPM_')
56
+	 * @return string
57
+	 */
58
+	// private static function _payment_method_type($props_n_values)
59
+	// {
60
+	//     EE_Registry::instance()->load_lib('Payment_Method_Manager');
61
+	//     $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null;
62
+	//     if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) {
63
+	//         return 'EEPM_' . $type_string;
64
+	//     } else {
65
+	//         return __CLASS__;
66
+	//     }
67
+	// }
68
+
69
+
70
+	/**
71
+	 * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc)
72
+	 *
73
+	 * @return boolean
74
+	 */
75
+	public function active()
76
+	{
77
+		return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope());
78
+	}
79
+
80
+
81
+	/**
82
+	 * Sets this PM as active by making it usable within the CART scope. Offline gateways
83
+	 * are also usable from the admin-scope as well. DOES NOT SAVE it
84
+	 *
85
+	 * @throws \EE_Error
86
+	 */
87
+	public function set_active()
88
+	{
89
+		$default_scopes = array(EEM_Payment_Method::scope_cart);
90
+		if (
91
+			$this->type_obj() &&
92
+			$this->type_obj()->payment_occurs() === EE_PMT_Base::offline
93
+		) {
94
+			$default_scopes[] = EEM_Payment_Method::scope_admin;
95
+		}
96
+		$this->set_scope($default_scopes);
97
+	}
98
+
99
+
100
+	/**
101
+	 * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it.
102
+	 */
103
+	public function deactivate()
104
+	{
105
+		$this->set_scope(array());
106
+	}
107
+
108
+
109
+	/**
110
+	 * Gets button_url
111
+	 *
112
+	 * @return string
113
+	 */
114
+	public function button_url()
115
+	{
116
+		return $this->get('PMD_button_url');
117
+	}
118
+
119
+
120
+	/**
121
+	 * Sets button_url
122
+	 *
123
+	 * @param string $button_url
124
+	 */
125
+	public function set_button_url($button_url)
126
+	{
127
+		$this->set('PMD_button_url', $button_url);
128
+	}
129
+
130
+
131
+	/**
132
+	 * Gets debug_mode
133
+	 *
134
+	 * @return boolean
135
+	 */
136
+	public function debug_mode()
137
+	{
138
+		return $this->get('PMD_debug_mode');
139
+	}
140
+
141
+
142
+	/**
143
+	 * Sets debug_mode
144
+	 *
145
+	 * @param boolean $debug_mode
146
+	 */
147
+	public function set_debug_mode($debug_mode)
148
+	{
149
+		$this->set('PMD_debug_mode', $debug_mode);
150
+	}
151
+
152
+
153
+	/**
154
+	 * Gets description
155
+	 *
156
+	 * @return string
157
+	 */
158
+	public function description()
159
+	{
160
+		return $this->get('PMD_desc');
161
+	}
162
+
163
+
164
+	/**
165
+	 * Sets description
166
+	 *
167
+	 * @param string $description
168
+	 */
169
+	public function set_description($description)
170
+	{
171
+		$this->set('PMD_desc', $description);
172
+	}
173
+
174
+
175
+	/**
176
+	 * Gets name
177
+	 *
178
+	 * @return string
179
+	 */
180
+	public function name()
181
+	{
182
+		return $this->get('PMD_name');
183
+	}
184
+
185
+
186
+	/**
187
+	 * Sets name
188
+	 *
189
+	 * @param string $name
190
+	 */
191
+	public function set_name($name)
192
+	{
193
+		$this->set('PMD_name', $name);
194
+	}
195
+
196
+
197
+	/**
198
+	 * Gets open_by_default
199
+	 *
200
+	 * @return boolean
201
+	 */
202
+	public function open_by_default()
203
+	{
204
+		return $this->get('PMD_open_by_default');
205
+	}
206
+
207
+
208
+	/**
209
+	 * Sets open_by_default
210
+	 *
211
+	 * @param boolean $open_by_default
212
+	 */
213
+	public function set_open_by_default($open_by_default)
214
+	{
215
+		$this->set('PMD_open_by_default', $open_by_default);
216
+	}
217
+
218
+
219
+	/**
220
+	 * Gets order
221
+	 *
222
+	 * @return int
223
+	 */
224
+	public function order()
225
+	{
226
+		return $this->get('PMD_order');
227
+	}
228
+
229
+
230
+	/**
231
+	 * Sets order
232
+	 *
233
+	 * @param int $order
234
+	 */
235
+	public function set_order($order)
236
+	{
237
+		$this->set('PMD_order', $order);
238
+	}
239
+
240
+
241
+	/**
242
+	 * Gets slug
243
+	 *
244
+	 * @return string
245
+	 */
246
+	public function slug()
247
+	{
248
+		return $this->get('PMD_slug');
249
+	}
250
+
251
+
252
+	/**
253
+	 * Sets slug
254
+	 *
255
+	 * @param string $slug
256
+	 */
257
+	public function set_slug($slug)
258
+	{
259
+		$this->set('PMD_slug', $slug);
260
+	}
261
+
262
+
263
+	/**
264
+	 * Gets type
265
+	 *
266
+	 * @return string
267
+	 */
268
+	public function type()
269
+	{
270
+		return $this->get('PMD_type');
271
+	}
272
+
273
+
274
+	/**
275
+	 * Sets type
276
+	 *
277
+	 * @param string $type
278
+	 */
279
+	public function set_type($type)
280
+	{
281
+		$this->set('PMD_type', $type);
282
+	}
283
+
284
+
285
+	/**
286
+	 * Gets wp_user
287
+	 *
288
+	 * @return int
289
+	 */
290
+	public function wp_user()
291
+	{
292
+		return $this->get('PMD_wp_user');
293
+	}
294
+
295
+
296
+	/**
297
+	 * Sets wp_user
298
+	 *
299
+	 * @param int $wp_user_id
300
+	 */
301
+	public function set_wp_user($wp_user_id)
302
+	{
303
+		$this->set('PMD_wp_user', $wp_user_id);
304
+	}
305
+
306
+	/**
307
+	 * Overrides parent so when PMD_type is changed we refresh the _type_obj
308
+	 *
309
+	 * @param string $field_name
310
+	 * @param mixed $field_value
311
+	 * @param boolean $use_default
312
+	 */
313
+	public function set($field_name, $field_value, $use_default = false)
314
+	{
315
+		if ($field_name === 'PMD_type') {
316
+			// the type has probably changed, so forget about its old type object
317
+			$this->_type_obj = null;
318
+		}
319
+		parent::set($field_name, $field_value, $use_default);
320
+	}
321
+
322
+
323
+	/**
324
+	 * Gets admin_name
325
+	 *
326
+	 * @return string
327
+	 */
328
+	public function admin_name()
329
+	{
330
+		return $this->get('PMD_admin_name');
331
+	}
332
+
333
+
334
+	/**
335
+	 * Sets admin_name
336
+	 *
337
+	 * @param string $admin_name
338
+	 */
339
+	public function set_admin_name($admin_name)
340
+	{
341
+		$this->set('PMD_admin_name', $admin_name);
342
+	}
343
+
344
+
345
+	/**
346
+	 * Gets admin_desc
347
+	 *
348
+	 * @return string
349
+	 */
350
+	public function admin_desc()
351
+	{
352
+		return $this->get('PMD_admin_desc');
353
+	}
354
+
355
+
356
+	/**
357
+	 * Sets admin_desc
358
+	 *
359
+	 * @param string $admin_desc
360
+	 */
361
+	public function set_admin_desc($admin_desc)
362
+	{
363
+		$this->set('PMD_admin_desc', $admin_desc);
364
+	}
365
+
366
+
367
+	/**
368
+	 * Gets scope
369
+	 *
370
+	 * @return array
371
+	 */
372
+	public function scope()
373
+	{
374
+		return $this->get('PMD_scope');
375
+	}
376
+
377
+
378
+	/**
379
+	 * Sets scope
380
+	 *
381
+	 * @param array $scope
382
+	 */
383
+	public function set_scope($scope)
384
+	{
385
+		$this->set('PMD_scope', $scope);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Gets the payment method type for this payment method instance
391
+	 *
392
+	 * @return EE_PMT_Base
393
+	 * @throws EE_Error
394
+	 */
395
+	public function type_obj()
396
+	{
397
+		if (! $this->_type_obj) {
398
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
399
+			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
400
+				$class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
401
+				if (! class_exists($class_name)) {
402
+					throw new EE_Error(
403
+						sprintf(
404
+							esc_html__(
405
+								'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s',
406
+								'event_espresso'
407
+							),
408
+							$class_name,
409
+							'<br />',
410
+							'<a href="' . admin_url('plugins.php') . '">',
411
+							'</a>'
412
+						)
413
+					);
414
+				}
415
+				$r = new ReflectionClass($class_name);
416
+				$this->_type_obj = $r->newInstanceArgs(array($this));
417
+			} else {
418
+				throw new EE_Error(
419
+					sprintf(
420
+						esc_html__(
421
+							'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s',
422
+							'event_espresso'
423
+						),
424
+						$this->type(),
425
+						implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names())
426
+					)
427
+				);
428
+			}
429
+		}
430
+		return $this->_type_obj;
431
+	}
432
+
433
+
434
+	/**
435
+	 * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix)
436
+	 * and the extra meta. Mostly used for passing off ot gateways.     *
437
+	 *
438
+	 * @return array
439
+	 */
440
+	public function settings_array()
441
+	{
442
+		$fields = $this->model_field_array();
443
+		$extra_meta = $this->all_extra_meta_array();
444
+		// remove the model's prefix from the fields
445
+		$combined_settings_array = array();
446
+		foreach ($fields as $key => $value) {
447
+			if (strpos($key, 'PMD_') === 0) {
448
+				$key_sans_model_prefix = str_replace('PMD_', '', $key);
449
+				$combined_settings_array [ $key_sans_model_prefix ] = $value;
450
+			}
451
+		}
452
+		$combined_settings_array = array_merge($extra_meta, $combined_settings_array);
453
+		return $combined_settings_array;
454
+	}
455
+
456
+
457
+	/**
458
+	 * Gets the HTML for displaying the payment method on a page.
459
+	 *
460
+	 * @param string $url
461
+	 * @param string $css_class
462
+	 * @return string of HTML for displaying the button
463
+	 * @throws \EE_Error
464
+	 */
465
+	public function button_html($url = '', $css_class = '')
466
+	{
467
+		$payment_occurs = $this->type_obj()->payment_occurs();
468
+		return '
469 469
 		 <div id="'
470
-               . $this->slug()
471
-               . '-payment-option-dv" class="'
472
-               . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
470
+			   . $this->slug()
471
+			   . '-payment-option-dv" class="'
472
+			   . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
473 473
 			<a id="payment-gateway-button-' . $this->slug()
474
-               . '" class="reg-page-payment-option-lnk" rel="'
475
-               . $this->slug() . '" href="' . $url . '" >
474
+			   . '" class="reg-page-payment-option-lnk" rel="'
475
+			   . $this->slug() . '" href="' . $url . '" >
476 476
 				<img src="' . $this->button_url() . '" alt="' . sprintf(
477
-                   esc_attr__('Pay using %s', 'event_espresso'),
478
-                   $this->get_pretty('PMD_name', 'form_input')
479
-               ) . '" />
477
+				   esc_attr__('Pay using %s', 'event_espresso'),
478
+				   $this->get_pretty('PMD_name', 'form_input')
479
+			   ) . '" />
480 480
 			</a>
481 481
 		</div>
482 482
 ';
483
-    }
484
-
485
-
486
-    /**
487
-     * Gets all the currencies which are an option for this payment method
488
-     * (as defined by the gateway and the currently active currencies)
489
-     *
490
-     * @return EE_Currency[]
491
-     * @throws \EE_Error
492
-     */
493
-    public function get_all_usable_currencies()
494
-    {
495
-        return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj());
496
-    }
497
-
498
-
499
-    /**
500
-     * Reports whether or not this payment method can be used for this payment method
501
-     *
502
-     * @param string $currency_code currency ID (code)
503
-     * @return boolean
504
-     * @throws \EE_Error
505
-     */
506
-    public function usable_for_currency($currency_code)
507
-    {
508
-        foreach ($this->get_all_usable_currencies() as $currency_obj) {
509
-            if ($currency_obj->ID() === $currency_code) {
510
-                return true;
511
-            }
512
-        }
513
-        return false;
514
-    }
515
-
516
-
517
-    /**
518
-     * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway
519
-     *
520
-     * @return bool
521
-     * @throws \EE_Error
522
-     */
523
-    public function is_on_site()
524
-    {
525
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite;
526
-    }
527
-
528
-
529
-    /**
530
-     * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway
531
-     *
532
-     * @return bool
533
-     * @throws \EE_Error
534
-     */
535
-    public function is_off_site()
536
-    {
537
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite;
538
-    }
539
-
540
-
541
-    /**
542
-     * Returns TRUE if this payment method does not utilize a gateway
543
-     *
544
-     * @return bool
545
-     * @throws \EE_Error
546
-     */
547
-    public function is_off_line()
548
-    {
549
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline;
550
-    }
551
-
552
-    /**
553
-     * Overrides default __sleep so the object type is NOT cached.
554
-     * This way we can rely on the normal EE_Payment_Method::type_obj() logic
555
-     * to load the required classes, and don't need them at the time of unserialization
556
-     *
557
-     * @return array
558
-     */
559
-    public function __sleep()
560
-    {
561
-        $properties = get_object_vars($this);
562
-        unset($properties['_type_obj']);
563
-        return array_keys($properties);
564
-    }
565
-
566
-
567
-    /**
568
-     * Overrides parent to add some logging for when payment methods get deactivated
569
-     *
570
-     * @param array $set_cols_n_values
571
-     * @return int @see EE_Base_Class::save()
572
-     * @throws \EE_Error
573
-     */
574
-    public function save($set_cols_n_values = array())
575
-    {
576
-        $results = parent::save($set_cols_n_values);
577
-        if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) {
578
-            /** @var CurrentPage $current_page */
579
-            $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
580
-            EE_Log::instance()->log(
581
-                __FILE__,
582
-                __FUNCTION__,
583
-                sprintf(
584
-                    esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'),
585
-                    $this->name(),
586
-                    serialize($this->get_original('PMD_scope')),
587
-                    serialize($this->get('PMD_scope')),
588
-                    $current_page->getPermalink()
589
-                ),
590
-                'payment_method_change'
591
-            );
592
-        }
593
-        return $results;
594
-    }
483
+	}
484
+
485
+
486
+	/**
487
+	 * Gets all the currencies which are an option for this payment method
488
+	 * (as defined by the gateway and the currently active currencies)
489
+	 *
490
+	 * @return EE_Currency[]
491
+	 * @throws \EE_Error
492
+	 */
493
+	public function get_all_usable_currencies()
494
+	{
495
+		return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj());
496
+	}
497
+
498
+
499
+	/**
500
+	 * Reports whether or not this payment method can be used for this payment method
501
+	 *
502
+	 * @param string $currency_code currency ID (code)
503
+	 * @return boolean
504
+	 * @throws \EE_Error
505
+	 */
506
+	public function usable_for_currency($currency_code)
507
+	{
508
+		foreach ($this->get_all_usable_currencies() as $currency_obj) {
509
+			if ($currency_obj->ID() === $currency_code) {
510
+				return true;
511
+			}
512
+		}
513
+		return false;
514
+	}
515
+
516
+
517
+	/**
518
+	 * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway
519
+	 *
520
+	 * @return bool
521
+	 * @throws \EE_Error
522
+	 */
523
+	public function is_on_site()
524
+	{
525
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway
531
+	 *
532
+	 * @return bool
533
+	 * @throws \EE_Error
534
+	 */
535
+	public function is_off_site()
536
+	{
537
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite;
538
+	}
539
+
540
+
541
+	/**
542
+	 * Returns TRUE if this payment method does not utilize a gateway
543
+	 *
544
+	 * @return bool
545
+	 * @throws \EE_Error
546
+	 */
547
+	public function is_off_line()
548
+	{
549
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline;
550
+	}
551
+
552
+	/**
553
+	 * Overrides default __sleep so the object type is NOT cached.
554
+	 * This way we can rely on the normal EE_Payment_Method::type_obj() logic
555
+	 * to load the required classes, and don't need them at the time of unserialization
556
+	 *
557
+	 * @return array
558
+	 */
559
+	public function __sleep()
560
+	{
561
+		$properties = get_object_vars($this);
562
+		unset($properties['_type_obj']);
563
+		return array_keys($properties);
564
+	}
565
+
566
+
567
+	/**
568
+	 * Overrides parent to add some logging for when payment methods get deactivated
569
+	 *
570
+	 * @param array $set_cols_n_values
571
+	 * @return int @see EE_Base_Class::save()
572
+	 * @throws \EE_Error
573
+	 */
574
+	public function save($set_cols_n_values = array())
575
+	{
576
+		$results = parent::save($set_cols_n_values);
577
+		if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) {
578
+			/** @var CurrentPage $current_page */
579
+			$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
580
+			EE_Log::instance()->log(
581
+				__FILE__,
582
+				__FUNCTION__,
583
+				sprintf(
584
+					esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'),
585
+					$this->name(),
586
+					serialize($this->get_original('PMD_scope')),
587
+					serialize($this->get('PMD_scope')),
588
+					$current_page->getPermalink()
589
+				),
590
+				'payment_method_change'
591
+			);
592
+		}
593
+		return $results;
594
+	}
595 595
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message.model.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
             self::priority_low    => esc_html__('low', 'event_espresso'),
127 127
         );
128 128
 
129
-        $this->_fields          = array(
129
+        $this->_fields = array(
130 130
             'Message' => array(
131 131
                 'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132 132
                 'MSG_token'          => new EE_Plain_Text_Field(
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
                         );
437 437
                         break;
438 438
                     default:
439
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
439
+                        $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value;
440 440
                         break;
441 441
                 }
442 442
             }
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
         if ($label_parts) {
500 500
             // prepend to the last element of $label_parts an "and".
501 501
             if (count($label_parts) > 1) {
502
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
503
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
502
+                $label_parts_index_to_prepend = count($label_parts) - 1;
503
+                $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend];
504 504
             }
505 505
 
506 506
             $pretty_label .= sprintf(
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
             $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
561 561
         }
562 562
 
563
-        if (! is_null($set_debug)) {
563
+        if ( ! is_null($set_debug)) {
564 564
             $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
565 565
         }
566 566
 
@@ -627,13 +627,13 @@  discard block
 block discarded – undo
627 627
             )
628 628
         );
629 629
 
630
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
630
+        if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
631 631
             global $wpdb;
632 632
             $number_deleted = $wpdb->query('
633 633
                 DELETE
634
-                FROM ' . $this->table() . '
634
+                FROM ' . $this->table().'
635 635
                 WHERE
636
-                    MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
636
+                    MSG_ID IN (' . implode(",", $message_ids_to_delete).')
637 637
             ');
638 638
         }
639 639
 
Please login to merge, or discard this patch.
Indentation   +640 added lines, -640 removed lines patch added patch discarded remove patch
@@ -13,649 +13,649 @@
 block discarded – undo
13 13
 class EEM_Message extends EEM_Base implements EEI_Query_Filter
14 14
 {
15 15
 
16
-    // private instance of the Message object
17
-    protected static $_instance = null;
18
-
19
-
20
-    /**
21
-     * This priority indicates a message should be generated and sent ASAP
22
-     *
23
-     * @type int
24
-     */
25
-    const priority_high = 10;
26
-
27
-
28
-    /**
29
-     * This priority indicates a message should be generated ASAP and queued for sending.
30
-     *
31
-     * @type
32
-     */
33
-    const priority_medium = 20;
34
-
35
-
36
-    /**
37
-     * This priority indicates a message should be queued for generating.
38
-     *
39
-     * @type int
40
-     */
41
-    const priority_low = 30;
42
-
43
-
44
-    /**
45
-     * indicates this message was sent at the time modified
46
-     */
47
-    const status_sent = 'MSN';
48
-
49
-
50
-    /**
51
-     * indicates this message is waiting to be sent
52
-     */
53
-    const status_idle = 'MID';
54
-
55
-
56
-    /**
57
-     * indicates an attempt was a made to send this message
58
-     * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
59
-     * appear to the end user.
60
-     */
61
-    const status_failed = 'MFL';
62
-
63
-
64
-    /**
65
-     * indicates the message has been flagged for resending (at the time modified).
66
-     */
67
-    const status_resend = 'MRS';
68
-
69
-
70
-    /**
71
-     * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
72
-     * this status when added to the queue.
73
-     */
74
-    const status_incomplete = 'MIC';
75
-
76
-
77
-    /**
78
-     * Indicates everything was generated fine for the message, however, the messenger was unable to send.
79
-     * This status means that its possible to retry sending the message.
80
-     */
81
-    const status_retry = 'MRT';
82
-
83
-
84
-    /**
85
-     * This is used for more informational messages that may not indicate anything is broken but still cannot be
86
-     * generated or sent correctly. An example of a message that would get flagged this way would be when a not
87
-     * approved message was queued for generation, but at time of generation, the attached registration(s) are
88
-     * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
89
-     * in the db and be viewable in the message activity list table when the messages system is in debug mode.
90
-     *
91
-     * @see EEM_Message::debug()
92
-     */
93
-    const status_debug_only = 'MDO';
94
-
95
-
96
-    /**
97
-     * This status is given to messages it is processed by the messenger send method.
98
-     * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
99
-     * indicative of a PHP timeout or memory limit issue.
100
-     */
101
-    const status_messenger_executing = 'MEX';
102
-
103
-
104
-    /**
105
-     *    Private constructor to prevent direct creation.
106
-     *
107
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
108
-     *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
109
-     *                         the date time model field objects.  Default is null (and will be assumed using the set
110
-     *                         timezone in the 'timezone_string' wp option)
111
-     * @throws EE_Error
112
-     * @throws EE_Error
113
-     * @throws EE_Error
114
-     */
115
-    protected function __construct($timezone = null)
116
-    {
117
-        $this->singular_item = esc_html__('Message', 'event_espresso');
118
-        $this->plural_item   = esc_html__('Messages', 'event_espresso');
119
-
120
-        $this->_tables = array(
121
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
122
-        );
123
-
124
-        $allowed_priority = array(
125
-            self::priority_high   => esc_html__('high', 'event_espresso'),
126
-            self::priority_medium => esc_html__('medium', 'event_espresso'),
127
-            self::priority_low    => esc_html__('low', 'event_espresso'),
128
-        );
129
-
130
-        $this->_fields          = array(
131
-            'Message' => array(
132
-                'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
133
-                'MSG_token'          => new EE_Plain_Text_Field(
134
-                    'MSG_token',
135
-                    esc_html__(
136
-                        'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
137
-                        'event_espresso'
138
-                    ),
139
-                    false,
140
-                    EEH_URL::generate_unique_token()
141
-                ),
142
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
143
-                    'GRP_ID',
144
-                    esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
145
-                    true,
146
-                    0,
147
-                    'Message_Template_Group'
148
-                ),
149
-                'TXN_ID'             => new EE_Foreign_Key_Int_Field(
150
-                    'TXN_ID',
151
-                    esc_html__(
152
-                        'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
153
-                        'event_espresso'
154
-                    ),
155
-                    true,
156
-                    0,
157
-                    'Transaction'
158
-                ),
159
-                'MSG_messenger'      => new EE_Plain_Text_Field(
160
-                    'MSG_messenger',
161
-                    esc_html__(
162
-                        'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
163
-                        'event_espresso'
164
-                    ),
165
-                    false,
166
-                    'email'
167
-                ),
168
-                'MSG_message_type'   => new EE_Plain_Text_Field(
169
-                    'MSG_message_type',
170
-                    esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
171
-                    false,
172
-                    'receipt'
173
-                ),
174
-                'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
175
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
176
-                    'MSG_recipient_ID',
177
-                    esc_html__('Recipient ID', 'event_espresso'),
178
-                    true,
179
-                    null,
180
-                    array('Registration', 'Attendee', 'WP_User')
181
-                ),
182
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
183
-                    'MSG_recipient_type',
184
-                    esc_html__('Recipient Type', 'event_espresso'),
185
-                    true,
186
-                    null,
187
-                    array('Registration', 'Attendee', 'WP_User')
188
-                ),
189
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
190
-                    'MSG_content',
191
-                    esc_html__('Content', 'event_espresso'),
192
-                    true,
193
-                    ''
194
-                ),
195
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
196
-                    'MSG_to',
197
-                    esc_html__('Address To', 'event_espresso'),
198
-                    true
199
-                ),
200
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
201
-                    'MSG_from',
202
-                    esc_html__('Address From', 'event_espresso'),
203
-                    true
204
-                ),
205
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
206
-                    'MSG_subject',
207
-                    esc_html__('Subject', 'event_espresso'),
208
-                    true,
209
-                    ''
210
-                ),
211
-                'MSG_priority'       => new EE_Enum_Integer_Field(
212
-                    'MSG_priority',
213
-                    esc_html__('Priority', 'event_espresso'),
214
-                    false,
215
-                    self::priority_low,
216
-                    $allowed_priority
217
-                ),
218
-                'STS_ID'             => new EE_Foreign_Key_String_Field(
219
-                    'STS_ID',
220
-                    esc_html__('Status', 'event_espresso'),
221
-                    false,
222
-                    self::status_incomplete,
223
-                    'Status'
224
-                ),
225
-                'MSG_created'        => new EE_Datetime_Field(
226
-                    'MSG_created',
227
-                    esc_html__('Created', 'event_espresso'),
228
-                    false,
229
-                    EE_Datetime_Field::now
230
-                ),
231
-                'MSG_modified'       => new EE_Datetime_Field(
232
-                    'MSG_modified',
233
-                    esc_html__('Modified', 'event_espresso'),
234
-                    true,
235
-                    EE_Datetime_Field::now
236
-                ),
237
-            ),
238
-        );
239
-        $this->_model_relations = array(
240
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
241
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
242
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
243
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
244
-            'Transaction'            => new EE_Belongs_To_Relation(),
245
-        );
246
-        parent::__construct($timezone);
247
-    }
248
-
249
-
250
-    /**
251
-     * @return EE_Message
252
-     * @throws EE_Error
253
-     */
254
-    public function create_default_object()
255
-    {
256
-        /** @type EE_Message $message */
257
-        $message = parent::create_default_object();
258
-        if ($message instanceof EE_Message) {
259
-            return EE_Message_Factory::set_messenger_and_message_type($message);
260
-        }
261
-        return null;
262
-    }
263
-
264
-
265
-    /**
266
-     * @param mixed $cols_n_values
267
-     * @return EE_Message
268
-     * @throws EE_Error
269
-     * @throws EE_Error
270
-     */
271
-    public function instantiate_class_from_array_or_object($cols_n_values)
272
-    {
273
-        /** @type EE_Message $message */
274
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
275
-        if ($message instanceof EE_Message) {
276
-            return EE_Message_Factory::set_messenger_and_message_type($message);
277
-        }
278
-        return null;
279
-    }
280
-
281
-
282
-    /**
283
-     * Returns whether or not a message of that type was sent for a given attendee.
284
-     *
285
-     * @param EE_Attendee|int $attendee
286
-     * @param string          $message_type the message type slug
287
-     * @return boolean
288
-     * @throws EE_Error
289
-     * @throws EE_Error
290
-     * @throws EE_Error
291
-     */
292
-    public function message_sent_for_attendee($attendee, $message_type)
293
-    {
294
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
295
-        return $this->exists(array(
296
-            array(
297
-                'Attendee.ATT_ID'  => $attendee_ID,
298
-                'MSG_message_type' => $message_type,
299
-                'STS_ID'           => array('IN', $this->stati_indicating_sent()),
300
-            ),
301
-        ));
302
-    }
303
-
304
-
305
-    /**
306
-     * Returns whether or not a message of that type was sent for a given registration
307
-     *
308
-     * @param EE_Registration|int $registration
309
-     * @param string              $message_type the message type slug
310
-     * @return boolean
311
-     * @throws EE_Error
312
-     * @throws EE_Error
313
-     * @throws EE_Error
314
-     */
315
-    public function message_sent_for_registration($registration, $message_type)
316
-    {
317
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
318
-        return $this->exists(array(
319
-            array(
320
-                'Registration.REG_ID' => $registrationID,
321
-                'MSG_message_type'    => $message_type,
322
-                'STS_ID'              => array('IN', $this->stati_indicating_sent()),
323
-            ),
324
-        ));
325
-    }
326
-
327
-
328
-    /**
329
-     * This retrieves an EE_Message object from the db matching the given token string.
330
-     *
331
-     * @param string $token
332
-     * @return EE_Message
333
-     * @throws EE_Error
334
-     */
335
-    public function get_one_by_token($token)
336
-    {
337
-        return $this->get_one(array(
338
-            array(
339
-                'MSG_token' => $token,
340
-            ),
341
-        ));
342
-    }
343
-
344
-
345
-    /**
346
-     * Returns stati that indicate the message HAS been sent
347
-     *
348
-     * @return array of strings for possible stati
349
-     */
350
-    public function stati_indicating_sent()
351
-    {
352
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
353
-    }
354
-
355
-
356
-    /**
357
-     * Returns stati that indicate the message is waiting to be sent.
358
-     *
359
-     * @return array of strings for possible stati.
360
-     */
361
-    public function stati_indicating_to_send()
362
-    {
363
-        return apply_filters(
364
-            'FHEE__EEM_Message__stati_indicating_to_send',
365
-            array(self::status_idle, self::status_resend)
366
-        );
367
-    }
368
-
369
-
370
-    /**
371
-     * Returns stati that indicate the message has failed sending
372
-     *
373
-     * @return array  array of strings for possible stati.
374
-     */
375
-    public function stati_indicating_failed_sending()
376
-    {
377
-        $failed_stati = array(
378
-            self::status_failed,
379
-            self::status_retry,
380
-            self::status_messenger_executing,
381
-        );
382
-        // if WP_DEBUG is set, then let's include debug_only fails
383
-        if (WP_DEBUG) {
384
-            $failed_stati[] = self::status_debug_only;
385
-        }
386
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
387
-    }
388
-
389
-
390
-    /**
391
-     * Returns filterable array of all EEM_Message statuses.
392
-     *
393
-     * @return array
394
-     */
395
-    public function all_statuses()
396
-    {
397
-        return apply_filters(
398
-            'FHEE__EEM_Message__all_statuses',
399
-            array(
400
-                EEM_Message::status_sent,
401
-                EEM_Message::status_incomplete,
402
-                EEM_Message::status_idle,
403
-                EEM_Message::status_resend,
404
-                EEM_Message::status_retry,
405
-                EEM_Message::status_failed,
406
-                EEM_Message::status_messenger_executing,
407
-                EEM_Message::status_debug_only,
408
-            )
409
-        );
410
-    }
411
-
412
-    /**
413
-     * Detects any specific query variables in the request and uses those to setup appropriate
414
-     * filter for any queries.
415
-     *
416
-     * @return array
417
-     */
418
-    public function filter_by_query_params()
419
-    {
420
-        /** @var RequestInterface $request */
421
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
422
-        // expected possible query_vars, the key in this array matches an expected key in the request,
423
-        // the value, matches the corresponding EEM_Base child reference.
424
-        $expected_vars   = $this->_expected_vars_for_query_inject();
425
-        $query_params[0] = array();
426
-        foreach ($expected_vars as $request_key => $model_name) {
427
-            $request_value = $request->getRequestParam($request_key);
428
-            if ($request_value) {
429
-                // special case
430
-                switch ($request_key) {
431
-                    case '_REG_ID':
432
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
433
-                            'Transaction.Registration.REG_ID' => $request_value,
434
-                        );
435
-                        break;
436
-                    case 'EVT_ID':
437
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
438
-                            'Transaction.Registration.EVT_ID' => $request_value,
439
-                        );
440
-                        break;
441
-                    default:
442
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
443
-                        break;
444
-                }
445
-            }
446
-        }
447
-        return $query_params;
448
-    }
449
-
450
-
451
-    /**
452
-     * @return string
453
-     * @throws EE_Error
454
-     * @throws ReflectionException
455
-     */
456
-    public function get_pretty_label_for_results()
457
-    {
458
-        /** @var RequestInterface $request */
459
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
460
-        $expected_vars = $this->_expected_vars_for_query_inject();
461
-        $pretty_label  = '';
462
-        $label_parts   = array();
463
-        foreach ($expected_vars as $request_key => $model_name) {
464
-            $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
465
-            $model = EEM_Base::$loader->getShared($model_name);
466
-            $model_field_value = $request->getRequestParam($request_key);
467
-            if ($model instanceof EEM_Base && $model_field_value !== '') {
468
-                switch ($request_key) {
469
-                    case '_REG_ID':
470
-                        $label_parts[] = sprintf(
471
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
472
-                            $model_field_value
473
-                        );
474
-                        break;
475
-                    case 'ATT_ID':
476
-                        /** @var EE_Attendee $attendee */
477
-                        $attendee      = $model->get_one_by_ID($model_field_value);
478
-                        $label_parts[] = $attendee instanceof EE_Attendee
479
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
480
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
481
-                        break;
482
-                    case 'ID':
483
-                        /** @var EE_WP_User $wpUser */
484
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
485
-                        $label_parts[] = $wpUser instanceof EE_WP_User
486
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
487
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
488
-                        break;
489
-                    case 'TXN_ID':
490
-                        $label_parts[] = sprintf(
491
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
492
-                            $model_field_value
493
-                        );
494
-                        break;
495
-                    case 'EVT_ID':
496
-                        /** @var EE_Event $Event */
497
-                        $Event         = $model->get_one_by_ID($model_field_value);
498
-                        $label_parts[] = $Event instanceof EE_Event
499
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
500
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
501
-                        break;
502
-                }
503
-            }
504
-        }
505
-
506
-        if ($label_parts) {
507
-            // prepend to the last element of $label_parts an "and".
508
-            if (count($label_parts) > 1) {
509
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
510
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
511
-            }
512
-
513
-            $pretty_label .= sprintf(
514
-                esc_html_x(
515
-                    'Showing messages for %s',
516
-                    'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
517
-                    'event_espresso'
518
-                ),
519
-                implode(', ', $label_parts)
520
-            );
521
-        }
522
-        return $pretty_label;
523
-    }
524
-
525
-
526
-    /**
527
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
528
-     * The array is in the format:
529
-     * array(
530
-     *  {$field_name} => {$model_name}
531
-     * );
532
-     *
533
-     * @since 4.9.0
534
-     * @return array
535
-     */
536
-    protected function _expected_vars_for_query_inject()
537
-    {
538
-        return array(
539
-            '_REG_ID' => 'Registration',
540
-            'ATT_ID'  => 'Attendee',
541
-            'ID'      => 'WP_User',
542
-            'TXN_ID'  => 'Transaction',
543
-            'EVT_ID'  => 'Event',
544
-        );
545
-    }
546
-
547
-
548
-    /**
549
-     * This returns whether EEM_Message is in debug mode or not.
550
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
551
-     * generating/sending messages. Debug mode can be set by either:
552
-     * 1. Sending in a value for the $set_debug argument
553
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
554
-     * 3. Overriding the above via the provided filter.
555
-     *
556
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
557
-     *                                  provided boolean. When no argument is provided (default null) then the debug
558
-     *                                  mode will be returned.
559
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
560
-     */
561
-    public static function debug($set_debug = null)
562
-    {
563
-        static $is_debugging = null;
564
-
565
-        // initialize (use constant if set).
566
-        if (is_null($set_debug) && is_null($is_debugging)) {
567
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
568
-        }
569
-
570
-        if (! is_null($set_debug)) {
571
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
572
-        }
573
-
574
-        // return filtered value
575
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
576
-    }
577
-
578
-
579
-    /**
580
-     * Deletes old messages meeting certain criteria for removal from the database.
581
-     * By default, this will delete messages that:
582
-     * - are older than the value of the delete_threshold in months.
583
-     * - have a STS_ID other than EEM_Message::status_idle
584
-     *
585
-     * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
586
-     *                              months.
587
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
588
-     *                              $wpdb->last_error to find out what the error was.
589
-     * @throws EE_Error
590
-     * @throws EE_Error
591
-     * @throws EE_Error
592
-     */
593
-    public function delete_old_messages($delete_threshold = 6)
594
-    {
595
-        $number_deleted = 0;
596
-        /**
597
-         * Allows code to change the boundary for what messages are kept.
598
-         * Uses the value of the `delete_threshold` variable by default.
599
-         *
600
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
601
-         * @return int
602
-         */
603
-        $time_to_leave_alone = absint(
604
-            apply_filters(
605
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
606
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
607
-            )
608
-        );
609
-
610
-
611
-        /**
612
-         * Allows code to change what message stati are ignored when deleting.
613
-         * Defaults to only ignore EEM_Message::status_idle messages.
614
-         *
615
-         * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
616
-         */
617
-        $message_stati_to_keep = (array) apply_filters(
618
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
619
-            array(
620
-                EEM_Message::status_idle
621
-            )
622
-        );
623
-
624
-        // first get all the ids of messages being deleted
625
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
626
-            array(
627
-                0 => array(
628
-                    'STS_ID' => array('NOT_IN', $message_stati_to_keep),
629
-                    'MSG_modified' => array('<', time() - $time_to_leave_alone)
630
-                ),
631
-                'limit' => apply_filters(
632
-                    'EEM_Message__delete_old_messages__limit',
633
-                    2000,
634
-                    $delete_threshold
635
-                )
636
-            )
637
-        );
638
-
639
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
640
-            global $wpdb;
641
-            $number_deleted = $wpdb->query('
16
+	// private instance of the Message object
17
+	protected static $_instance = null;
18
+
19
+
20
+	/**
21
+	 * This priority indicates a message should be generated and sent ASAP
22
+	 *
23
+	 * @type int
24
+	 */
25
+	const priority_high = 10;
26
+
27
+
28
+	/**
29
+	 * This priority indicates a message should be generated ASAP and queued for sending.
30
+	 *
31
+	 * @type
32
+	 */
33
+	const priority_medium = 20;
34
+
35
+
36
+	/**
37
+	 * This priority indicates a message should be queued for generating.
38
+	 *
39
+	 * @type int
40
+	 */
41
+	const priority_low = 30;
42
+
43
+
44
+	/**
45
+	 * indicates this message was sent at the time modified
46
+	 */
47
+	const status_sent = 'MSN';
48
+
49
+
50
+	/**
51
+	 * indicates this message is waiting to be sent
52
+	 */
53
+	const status_idle = 'MID';
54
+
55
+
56
+	/**
57
+	 * indicates an attempt was a made to send this message
58
+	 * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
59
+	 * appear to the end user.
60
+	 */
61
+	const status_failed = 'MFL';
62
+
63
+
64
+	/**
65
+	 * indicates the message has been flagged for resending (at the time modified).
66
+	 */
67
+	const status_resend = 'MRS';
68
+
69
+
70
+	/**
71
+	 * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
72
+	 * this status when added to the queue.
73
+	 */
74
+	const status_incomplete = 'MIC';
75
+
76
+
77
+	/**
78
+	 * Indicates everything was generated fine for the message, however, the messenger was unable to send.
79
+	 * This status means that its possible to retry sending the message.
80
+	 */
81
+	const status_retry = 'MRT';
82
+
83
+
84
+	/**
85
+	 * This is used for more informational messages that may not indicate anything is broken but still cannot be
86
+	 * generated or sent correctly. An example of a message that would get flagged this way would be when a not
87
+	 * approved message was queued for generation, but at time of generation, the attached registration(s) are
88
+	 * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
89
+	 * in the db and be viewable in the message activity list table when the messages system is in debug mode.
90
+	 *
91
+	 * @see EEM_Message::debug()
92
+	 */
93
+	const status_debug_only = 'MDO';
94
+
95
+
96
+	/**
97
+	 * This status is given to messages it is processed by the messenger send method.
98
+	 * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
99
+	 * indicative of a PHP timeout or memory limit issue.
100
+	 */
101
+	const status_messenger_executing = 'MEX';
102
+
103
+
104
+	/**
105
+	 *    Private constructor to prevent direct creation.
106
+	 *
107
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
108
+	 *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
109
+	 *                         the date time model field objects.  Default is null (and will be assumed using the set
110
+	 *                         timezone in the 'timezone_string' wp option)
111
+	 * @throws EE_Error
112
+	 * @throws EE_Error
113
+	 * @throws EE_Error
114
+	 */
115
+	protected function __construct($timezone = null)
116
+	{
117
+		$this->singular_item = esc_html__('Message', 'event_espresso');
118
+		$this->plural_item   = esc_html__('Messages', 'event_espresso');
119
+
120
+		$this->_tables = array(
121
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
122
+		);
123
+
124
+		$allowed_priority = array(
125
+			self::priority_high   => esc_html__('high', 'event_espresso'),
126
+			self::priority_medium => esc_html__('medium', 'event_espresso'),
127
+			self::priority_low    => esc_html__('low', 'event_espresso'),
128
+		);
129
+
130
+		$this->_fields          = array(
131
+			'Message' => array(
132
+				'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
133
+				'MSG_token'          => new EE_Plain_Text_Field(
134
+					'MSG_token',
135
+					esc_html__(
136
+						'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
137
+						'event_espresso'
138
+					),
139
+					false,
140
+					EEH_URL::generate_unique_token()
141
+				),
142
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
143
+					'GRP_ID',
144
+					esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
145
+					true,
146
+					0,
147
+					'Message_Template_Group'
148
+				),
149
+				'TXN_ID'             => new EE_Foreign_Key_Int_Field(
150
+					'TXN_ID',
151
+					esc_html__(
152
+						'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
153
+						'event_espresso'
154
+					),
155
+					true,
156
+					0,
157
+					'Transaction'
158
+				),
159
+				'MSG_messenger'      => new EE_Plain_Text_Field(
160
+					'MSG_messenger',
161
+					esc_html__(
162
+						'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
163
+						'event_espresso'
164
+					),
165
+					false,
166
+					'email'
167
+				),
168
+				'MSG_message_type'   => new EE_Plain_Text_Field(
169
+					'MSG_message_type',
170
+					esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
171
+					false,
172
+					'receipt'
173
+				),
174
+				'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
175
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
176
+					'MSG_recipient_ID',
177
+					esc_html__('Recipient ID', 'event_espresso'),
178
+					true,
179
+					null,
180
+					array('Registration', 'Attendee', 'WP_User')
181
+				),
182
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
183
+					'MSG_recipient_type',
184
+					esc_html__('Recipient Type', 'event_espresso'),
185
+					true,
186
+					null,
187
+					array('Registration', 'Attendee', 'WP_User')
188
+				),
189
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
190
+					'MSG_content',
191
+					esc_html__('Content', 'event_espresso'),
192
+					true,
193
+					''
194
+				),
195
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
196
+					'MSG_to',
197
+					esc_html__('Address To', 'event_espresso'),
198
+					true
199
+				),
200
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
201
+					'MSG_from',
202
+					esc_html__('Address From', 'event_espresso'),
203
+					true
204
+				),
205
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
206
+					'MSG_subject',
207
+					esc_html__('Subject', 'event_espresso'),
208
+					true,
209
+					''
210
+				),
211
+				'MSG_priority'       => new EE_Enum_Integer_Field(
212
+					'MSG_priority',
213
+					esc_html__('Priority', 'event_espresso'),
214
+					false,
215
+					self::priority_low,
216
+					$allowed_priority
217
+				),
218
+				'STS_ID'             => new EE_Foreign_Key_String_Field(
219
+					'STS_ID',
220
+					esc_html__('Status', 'event_espresso'),
221
+					false,
222
+					self::status_incomplete,
223
+					'Status'
224
+				),
225
+				'MSG_created'        => new EE_Datetime_Field(
226
+					'MSG_created',
227
+					esc_html__('Created', 'event_espresso'),
228
+					false,
229
+					EE_Datetime_Field::now
230
+				),
231
+				'MSG_modified'       => new EE_Datetime_Field(
232
+					'MSG_modified',
233
+					esc_html__('Modified', 'event_espresso'),
234
+					true,
235
+					EE_Datetime_Field::now
236
+				),
237
+			),
238
+		);
239
+		$this->_model_relations = array(
240
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
241
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
242
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
243
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
244
+			'Transaction'            => new EE_Belongs_To_Relation(),
245
+		);
246
+		parent::__construct($timezone);
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return EE_Message
252
+	 * @throws EE_Error
253
+	 */
254
+	public function create_default_object()
255
+	{
256
+		/** @type EE_Message $message */
257
+		$message = parent::create_default_object();
258
+		if ($message instanceof EE_Message) {
259
+			return EE_Message_Factory::set_messenger_and_message_type($message);
260
+		}
261
+		return null;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param mixed $cols_n_values
267
+	 * @return EE_Message
268
+	 * @throws EE_Error
269
+	 * @throws EE_Error
270
+	 */
271
+	public function instantiate_class_from_array_or_object($cols_n_values)
272
+	{
273
+		/** @type EE_Message $message */
274
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
275
+		if ($message instanceof EE_Message) {
276
+			return EE_Message_Factory::set_messenger_and_message_type($message);
277
+		}
278
+		return null;
279
+	}
280
+
281
+
282
+	/**
283
+	 * Returns whether or not a message of that type was sent for a given attendee.
284
+	 *
285
+	 * @param EE_Attendee|int $attendee
286
+	 * @param string          $message_type the message type slug
287
+	 * @return boolean
288
+	 * @throws EE_Error
289
+	 * @throws EE_Error
290
+	 * @throws EE_Error
291
+	 */
292
+	public function message_sent_for_attendee($attendee, $message_type)
293
+	{
294
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
295
+		return $this->exists(array(
296
+			array(
297
+				'Attendee.ATT_ID'  => $attendee_ID,
298
+				'MSG_message_type' => $message_type,
299
+				'STS_ID'           => array('IN', $this->stati_indicating_sent()),
300
+			),
301
+		));
302
+	}
303
+
304
+
305
+	/**
306
+	 * Returns whether or not a message of that type was sent for a given registration
307
+	 *
308
+	 * @param EE_Registration|int $registration
309
+	 * @param string              $message_type the message type slug
310
+	 * @return boolean
311
+	 * @throws EE_Error
312
+	 * @throws EE_Error
313
+	 * @throws EE_Error
314
+	 */
315
+	public function message_sent_for_registration($registration, $message_type)
316
+	{
317
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
318
+		return $this->exists(array(
319
+			array(
320
+				'Registration.REG_ID' => $registrationID,
321
+				'MSG_message_type'    => $message_type,
322
+				'STS_ID'              => array('IN', $this->stati_indicating_sent()),
323
+			),
324
+		));
325
+	}
326
+
327
+
328
+	/**
329
+	 * This retrieves an EE_Message object from the db matching the given token string.
330
+	 *
331
+	 * @param string $token
332
+	 * @return EE_Message
333
+	 * @throws EE_Error
334
+	 */
335
+	public function get_one_by_token($token)
336
+	{
337
+		return $this->get_one(array(
338
+			array(
339
+				'MSG_token' => $token,
340
+			),
341
+		));
342
+	}
343
+
344
+
345
+	/**
346
+	 * Returns stati that indicate the message HAS been sent
347
+	 *
348
+	 * @return array of strings for possible stati
349
+	 */
350
+	public function stati_indicating_sent()
351
+	{
352
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
353
+	}
354
+
355
+
356
+	/**
357
+	 * Returns stati that indicate the message is waiting to be sent.
358
+	 *
359
+	 * @return array of strings for possible stati.
360
+	 */
361
+	public function stati_indicating_to_send()
362
+	{
363
+		return apply_filters(
364
+			'FHEE__EEM_Message__stati_indicating_to_send',
365
+			array(self::status_idle, self::status_resend)
366
+		);
367
+	}
368
+
369
+
370
+	/**
371
+	 * Returns stati that indicate the message has failed sending
372
+	 *
373
+	 * @return array  array of strings for possible stati.
374
+	 */
375
+	public function stati_indicating_failed_sending()
376
+	{
377
+		$failed_stati = array(
378
+			self::status_failed,
379
+			self::status_retry,
380
+			self::status_messenger_executing,
381
+		);
382
+		// if WP_DEBUG is set, then let's include debug_only fails
383
+		if (WP_DEBUG) {
384
+			$failed_stati[] = self::status_debug_only;
385
+		}
386
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Returns filterable array of all EEM_Message statuses.
392
+	 *
393
+	 * @return array
394
+	 */
395
+	public function all_statuses()
396
+	{
397
+		return apply_filters(
398
+			'FHEE__EEM_Message__all_statuses',
399
+			array(
400
+				EEM_Message::status_sent,
401
+				EEM_Message::status_incomplete,
402
+				EEM_Message::status_idle,
403
+				EEM_Message::status_resend,
404
+				EEM_Message::status_retry,
405
+				EEM_Message::status_failed,
406
+				EEM_Message::status_messenger_executing,
407
+				EEM_Message::status_debug_only,
408
+			)
409
+		);
410
+	}
411
+
412
+	/**
413
+	 * Detects any specific query variables in the request and uses those to setup appropriate
414
+	 * filter for any queries.
415
+	 *
416
+	 * @return array
417
+	 */
418
+	public function filter_by_query_params()
419
+	{
420
+		/** @var RequestInterface $request */
421
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
422
+		// expected possible query_vars, the key in this array matches an expected key in the request,
423
+		// the value, matches the corresponding EEM_Base child reference.
424
+		$expected_vars   = $this->_expected_vars_for_query_inject();
425
+		$query_params[0] = array();
426
+		foreach ($expected_vars as $request_key => $model_name) {
427
+			$request_value = $request->getRequestParam($request_key);
428
+			if ($request_value) {
429
+				// special case
430
+				switch ($request_key) {
431
+					case '_REG_ID':
432
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
433
+							'Transaction.Registration.REG_ID' => $request_value,
434
+						);
435
+						break;
436
+					case 'EVT_ID':
437
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
438
+							'Transaction.Registration.EVT_ID' => $request_value,
439
+						);
440
+						break;
441
+					default:
442
+						$query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
443
+						break;
444
+				}
445
+			}
446
+		}
447
+		return $query_params;
448
+	}
449
+
450
+
451
+	/**
452
+	 * @return string
453
+	 * @throws EE_Error
454
+	 * @throws ReflectionException
455
+	 */
456
+	public function get_pretty_label_for_results()
457
+	{
458
+		/** @var RequestInterface $request */
459
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
460
+		$expected_vars = $this->_expected_vars_for_query_inject();
461
+		$pretty_label  = '';
462
+		$label_parts   = array();
463
+		foreach ($expected_vars as $request_key => $model_name) {
464
+			$model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
465
+			$model = EEM_Base::$loader->getShared($model_name);
466
+			$model_field_value = $request->getRequestParam($request_key);
467
+			if ($model instanceof EEM_Base && $model_field_value !== '') {
468
+				switch ($request_key) {
469
+					case '_REG_ID':
470
+						$label_parts[] = sprintf(
471
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
472
+							$model_field_value
473
+						);
474
+						break;
475
+					case 'ATT_ID':
476
+						/** @var EE_Attendee $attendee */
477
+						$attendee      = $model->get_one_by_ID($model_field_value);
478
+						$label_parts[] = $attendee instanceof EE_Attendee
479
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
480
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
481
+						break;
482
+					case 'ID':
483
+						/** @var EE_WP_User $wpUser */
484
+						$wpUser        = $model->get_one_by_ID($model_field_value);
485
+						$label_parts[] = $wpUser instanceof EE_WP_User
486
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
487
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
488
+						break;
489
+					case 'TXN_ID':
490
+						$label_parts[] = sprintf(
491
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
492
+							$model_field_value
493
+						);
494
+						break;
495
+					case 'EVT_ID':
496
+						/** @var EE_Event $Event */
497
+						$Event         = $model->get_one_by_ID($model_field_value);
498
+						$label_parts[] = $Event instanceof EE_Event
499
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
500
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
501
+						break;
502
+				}
503
+			}
504
+		}
505
+
506
+		if ($label_parts) {
507
+			// prepend to the last element of $label_parts an "and".
508
+			if (count($label_parts) > 1) {
509
+				$label_parts_index_to_prepend               = count($label_parts) - 1;
510
+				$label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
511
+			}
512
+
513
+			$pretty_label .= sprintf(
514
+				esc_html_x(
515
+					'Showing messages for %s',
516
+					'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
517
+					'event_espresso'
518
+				),
519
+				implode(', ', $label_parts)
520
+			);
521
+		}
522
+		return $pretty_label;
523
+	}
524
+
525
+
526
+	/**
527
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
528
+	 * The array is in the format:
529
+	 * array(
530
+	 *  {$field_name} => {$model_name}
531
+	 * );
532
+	 *
533
+	 * @since 4.9.0
534
+	 * @return array
535
+	 */
536
+	protected function _expected_vars_for_query_inject()
537
+	{
538
+		return array(
539
+			'_REG_ID' => 'Registration',
540
+			'ATT_ID'  => 'Attendee',
541
+			'ID'      => 'WP_User',
542
+			'TXN_ID'  => 'Transaction',
543
+			'EVT_ID'  => 'Event',
544
+		);
545
+	}
546
+
547
+
548
+	/**
549
+	 * This returns whether EEM_Message is in debug mode or not.
550
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
551
+	 * generating/sending messages. Debug mode can be set by either:
552
+	 * 1. Sending in a value for the $set_debug argument
553
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
554
+	 * 3. Overriding the above via the provided filter.
555
+	 *
556
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
557
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
558
+	 *                                  mode will be returned.
559
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
560
+	 */
561
+	public static function debug($set_debug = null)
562
+	{
563
+		static $is_debugging = null;
564
+
565
+		// initialize (use constant if set).
566
+		if (is_null($set_debug) && is_null($is_debugging)) {
567
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
568
+		}
569
+
570
+		if (! is_null($set_debug)) {
571
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
572
+		}
573
+
574
+		// return filtered value
575
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
576
+	}
577
+
578
+
579
+	/**
580
+	 * Deletes old messages meeting certain criteria for removal from the database.
581
+	 * By default, this will delete messages that:
582
+	 * - are older than the value of the delete_threshold in months.
583
+	 * - have a STS_ID other than EEM_Message::status_idle
584
+	 *
585
+	 * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
586
+	 *                              months.
587
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
588
+	 *                              $wpdb->last_error to find out what the error was.
589
+	 * @throws EE_Error
590
+	 * @throws EE_Error
591
+	 * @throws EE_Error
592
+	 */
593
+	public function delete_old_messages($delete_threshold = 6)
594
+	{
595
+		$number_deleted = 0;
596
+		/**
597
+		 * Allows code to change the boundary for what messages are kept.
598
+		 * Uses the value of the `delete_threshold` variable by default.
599
+		 *
600
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
601
+		 * @return int
602
+		 */
603
+		$time_to_leave_alone = absint(
604
+			apply_filters(
605
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
606
+				((int) $delete_threshold) * MONTH_IN_SECONDS
607
+			)
608
+		);
609
+
610
+
611
+		/**
612
+		 * Allows code to change what message stati are ignored when deleting.
613
+		 * Defaults to only ignore EEM_Message::status_idle messages.
614
+		 *
615
+		 * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
616
+		 */
617
+		$message_stati_to_keep = (array) apply_filters(
618
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
619
+			array(
620
+				EEM_Message::status_idle
621
+			)
622
+		);
623
+
624
+		// first get all the ids of messages being deleted
625
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
626
+			array(
627
+				0 => array(
628
+					'STS_ID' => array('NOT_IN', $message_stati_to_keep),
629
+					'MSG_modified' => array('<', time() - $time_to_leave_alone)
630
+				),
631
+				'limit' => apply_filters(
632
+					'EEM_Message__delete_old_messages__limit',
633
+					2000,
634
+					$delete_threshold
635
+				)
636
+			)
637
+		);
638
+
639
+		if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
640
+			global $wpdb;
641
+			$number_deleted = $wpdb->query('
642 642
                 DELETE
643 643
                 FROM ' . $this->table() . '
644 644
                 WHERE
645 645
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
646 646
             ');
647
-        }
648
-
649
-        /**
650
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
651
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
652
-         * below.
653
-         */
654
-        if ($number_deleted !== false) {
655
-            do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
656
-        } else {
657
-            do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
658
-        }
659
-        return $number_deleted;
660
-    }
647
+		}
648
+
649
+		/**
650
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
651
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
652
+		 * below.
653
+		 */
654
+		if ($number_deleted !== false) {
655
+			do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
656
+		} else {
657
+			do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
658
+		}
659
+		return $number_deleted;
660
+	}
661 661
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Type_Field.php.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
  */
6 6
 class EE_WP_Post_Type_Field extends EE_DB_Only_Text_Field
7 7
 {
8
-    /**
9
-     * @param string $post_type the exact string to be used for the post type
10
-     *                          of all these post type model objects/rows
11
-     */
12
-    public function __construct($post_type)
13
-    {
14
-        parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type);
15
-    }
8
+	/**
9
+	 * @param string $post_type the exact string to be used for the post type
10
+	 *                          of all these post type model objects/rows
11
+	 */
12
+	public function __construct($post_type)
13
+	{
14
+		parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type);
15
+	}
16 16
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Full_HTML_Field.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -14,57 +14,57 @@
 block discarded – undo
14 14
 class EE_Full_HTML_Field extends EE_Text_Field_Base
15 15
 {
16 16
 
17
-    /**
18
-     * @param string $table_column
19
-     * @param string $nicename
20
-     * @param bool   $nullable
21
-     * @param null   $default_value
22
-     */
23
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
24
-    {
25
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
26
-        $this->setSchemaType('object');
27
-    }
17
+	/**
18
+	 * @param string $table_column
19
+	 * @param string $nicename
20
+	 * @param bool   $nullable
21
+	 * @param null   $default_value
22
+	 */
23
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
24
+	{
25
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
26
+		$this->setSchemaType('object');
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
32
-     *
33
-     * @param type $value_on_field_to_be_outputted
34
-     * @param type $schema
35
-     * @return string
36
-     */
37
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
38
-    {
39
-        if ($schema == 'form_input') {
40
-            return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
41
-        } elseif ($schema == 'no_wpautop') {
42
-            return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
43
-        } else {
44
-            return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
45
-        }
46
-    }
30
+	/**
31
+	 * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
32
+	 *
33
+	 * @param type $value_on_field_to_be_outputted
34
+	 * @param type $schema
35
+	 * @return string
36
+	 */
37
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
38
+	{
39
+		if ($schema == 'form_input') {
40
+			return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
41
+		} elseif ($schema == 'no_wpautop') {
42
+			return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
43
+		} else {
44
+			return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
45
+		}
46
+	}
47 47
 
48 48
 
49 49
 
50
-    public function getSchemaProperties()
51
-    {
52
-        return array(
53
-            'raw' => array(
54
-                'description' =>  sprintf(
55
-                    esc_html__('%s - the value in the database.', 'event_espresso'),
56
-                    $this->get_nicename()
57
-                ),
58
-                'type' => 'string'
59
-            ),
60
-            'rendered' => array(
61
-                'description' =>  sprintf(
62
-                    esc_html__('%s - transformed for display.', 'event_espresso'),
63
-                    $this->get_nicename()
64
-                ),
65
-                'type' => 'string',
66
-                'readonly' => true
67
-            )
68
-        );
69
-    }
50
+	public function getSchemaProperties()
51
+	{
52
+		return array(
53
+			'raw' => array(
54
+				'description' =>  sprintf(
55
+					esc_html__('%s - the value in the database.', 'event_espresso'),
56
+					$this->get_nicename()
57
+				),
58
+				'type' => 'string'
59
+			),
60
+			'rendered' => array(
61
+				'description' =>  sprintf(
62
+					esc_html__('%s - transformed for display.', 'event_espresso'),
63
+					$this->get_nicename()
64
+				),
65
+				'type' => 'string',
66
+				'readonly' => true
67
+			)
68
+		);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Infinite_Integer_Field.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -10,78 +10,78 @@
 block discarded – undo
10 10
 class EE_Infinite_Integer_Field extends EE_Model_Field_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @param string $table_column
15
-     * @param string $nicename
16
-     * @param bool   $nullable
17
-     * @param null   $default_value
18
-     */
19
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
20
-    {
21
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
22
-        $this->setSchemaType(array('integer', 'null'));
23
-    }
13
+	/**
14
+	 * @param string $table_column
15
+	 * @param string $nicename
16
+	 * @param bool   $nullable
17
+	 * @param null   $default_value
18
+	 */
19
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
20
+	{
21
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
22
+		$this->setSchemaType(array('integer', 'null'));
23
+	}
24 24
 
25 25
 
26
-    public function prepare_for_use_in_db($value_of_field_on_model_object)
27
-    {
28
-        if ($value_of_field_on_model_object === EE_INF) {
29
-            return EE_INF_IN_DB;
30
-        } else {
31
-            return intval($value_of_field_on_model_object);
32
-        }
33
-    }
26
+	public function prepare_for_use_in_db($value_of_field_on_model_object)
27
+	{
28
+		if ($value_of_field_on_model_object === EE_INF) {
29
+			return EE_INF_IN_DB;
30
+		} else {
31
+			return intval($value_of_field_on_model_object);
32
+		}
33
+	}
34 34
 
35
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
36
-    {
37
-        if (
38
-            $value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
39
-            $value_inputted_for_field_on_model_object === EE_INF ||
40
-            $value_inputted_for_field_on_model_object === "EE_INF" ||
41
-            $value_inputted_for_field_on_model_object === ""
42
-        ) {
43
-            return EE_INF;
44
-        } else {
45
-            return intval($value_inputted_for_field_on_model_object);
46
-        }
47
-    }
35
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
36
+	{
37
+		if (
38
+			$value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
39
+			$value_inputted_for_field_on_model_object === EE_INF ||
40
+			$value_inputted_for_field_on_model_object === "EE_INF" ||
41
+			$value_inputted_for_field_on_model_object === ""
42
+		) {
43
+			return EE_INF;
44
+		} else {
45
+			return intval($value_inputted_for_field_on_model_object);
46
+		}
47
+	}
48 48
 
49
-    public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
50
-    {
51
-        $intval = intval($value_inputted_for_field_on_model_object);
52
-        if ($intval == EE_INF_IN_DB) {
53
-            return EE_INF;
54
-        } else {
55
-            return $intval;
56
-        }
57
-    }
49
+	public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
50
+	{
51
+		$intval = intval($value_inputted_for_field_on_model_object);
52
+		if ($intval == EE_INF_IN_DB) {
53
+			return EE_INF;
54
+		} else {
55
+			return $intval;
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * For outputting this field's value. If you want to output it into an input or something,
61
-     * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
62
-     * as it will replace EE_INF with i18n Infinite
63
-     *
64
-     * @param type   $value_on_field_to_be_outputted
65
-     * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
66
-     * @return string
67
-     */
68
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
69
-    {
70
-        if ($value_on_field_to_be_outputted === EE_INF) {
71
-            switch ($schema) {
72
-                case 'input':
73
-                case 'form_input':
74
-                    return '';
75
-                case 'symbol':
76
-                    return "&infin;";
77
-                case 'text':
78
-                case null:
79
-                    return esc_html__("Unlimited", "event_espresso");
80
-                default:
81
-                    return $schema;
82
-            }
83
-        } else {
84
-            return $value_on_field_to_be_outputted;
85
-        }
86
-    }
59
+	/**
60
+	 * For outputting this field's value. If you want to output it into an input or something,
61
+	 * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
62
+	 * as it will replace EE_INF with i18n Infinite
63
+	 *
64
+	 * @param type   $value_on_field_to_be_outputted
65
+	 * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
66
+	 * @return string
67
+	 */
68
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
69
+	{
70
+		if ($value_on_field_to_be_outputted === EE_INF) {
71
+			switch ($schema) {
72
+				case 'input':
73
+				case 'form_input':
74
+					return '';
75
+				case 'symbol':
76
+					return "&infin;";
77
+				case 'text':
78
+				case null:
79
+					return esc_html__("Unlimited", "event_espresso");
80
+				default:
81
+					return $schema;
82
+			}
83
+		} else {
84
+			return $value_on_field_to_be_outputted;
85
+		}
86
+	}
87 87
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Money_Field.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -7,92 +7,92 @@
 block discarded – undo
7 7
 class EE_Money_Field extends EE_Float_Field
8 8
 {
9 9
 
10
-    /**
11
-     * @param string $table_column
12
-     * @param string $nicename
13
-     * @param bool   $nullable
14
-     * @param null   $default_value
15
-     */
16
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
-    {
18
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
19
-        $this->setSchemaType('object');
20
-    }
10
+	/**
11
+	 * @param string $table_column
12
+	 * @param string $nicename
13
+	 * @param bool   $nullable
14
+	 * @param null   $default_value
15
+	 */
16
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
+	{
18
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
19
+		$this->setSchemaType('object');
20
+	}
21 21
 
22 22
 
23
-    /**
24
-     * Schemas:
25
-     *    'localized_float': "3,023.00"
26
-     *    'no_currency_code': "$3,023.00"
27
-     *    null: "$3,023.00<span>USD</span>"
28
-     *
29
-     * @param string $value_on_field_to_be_outputted
30
-     * @param string $schema
31
-     * @return string
32
-     */
33
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
34
-    {
35
-        $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
23
+	/**
24
+	 * Schemas:
25
+	 *    'localized_float': "3,023.00"
26
+	 *    'no_currency_code': "$3,023.00"
27
+	 *    null: "$3,023.00<span>USD</span>"
28
+	 *
29
+	 * @param string $value_on_field_to_be_outputted
30
+	 * @param string $schema
31
+	 * @return string
32
+	 */
33
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
34
+	{
35
+		$pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
36 36
 
37
-        if ($schema == 'localized_float') {
38
-            return $pretty_float;
39
-        }
40
-        if ($schema == 'no_currency_code') {
37
+		if ($schema == 'localized_float') {
38
+			return $pretty_float;
39
+		}
40
+		if ($schema == 'no_currency_code') {
41 41
 //          echo "schema no currency!";
42
-            $display_code = false;
43
-        } else {
44
-            $display_code = true;
45
-        }
46
-        // we don't use the $pretty_float because format_currency will take care of it.
47
-        return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
48
-    }
42
+			$display_code = false;
43
+		} else {
44
+			$display_code = true;
45
+		}
46
+		// we don't use the $pretty_float because format_currency will take care of it.
47
+		return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
48
+	}
49 49
 
50
-    /**
51
-     * If provided with a string, strips out money-related formatting to turn it into a proper float.
52
-     * Rounds the float to the correct number of decimal places for this country's currency.
53
-     * Also, interprets periods and commas according to the country's currency settings.
54
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
55
-     *
56
-     * @param string $value_inputted_for_field_on_model_object
57
-     * @return float
58
-     */
59
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
60
-    {
61
-        // remove any currencies etc.
50
+	/**
51
+	 * If provided with a string, strips out money-related formatting to turn it into a proper float.
52
+	 * Rounds the float to the correct number of decimal places for this country's currency.
53
+	 * Also, interprets periods and commas according to the country's currency settings.
54
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
55
+	 *
56
+	 * @param string $value_inputted_for_field_on_model_object
57
+	 * @return float
58
+	 */
59
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
60
+	{
61
+		// remove any currencies etc.
62 62
 //      if(is_string($value_inputted_for_field_on_model_object)){
63 63
 //          $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", $value_inputted_for_field_on_model_object);
64 64
 //      }
65
-        // now it's a float-style string or number
66
-        $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
67
-        // round to the correctly number of decimal places for this  currency
68
-        $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
69
-        return $rounded_value;
70
-    }
65
+		// now it's a float-style string or number
66
+		$float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
67
+		// round to the correctly number of decimal places for this  currency
68
+		$rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
69
+		return $rounded_value;
70
+	}
71 71
 
72
-    public function prepare_for_get($value_of_field_on_model_object)
73
-    {
74
-        $c = EE_Registry::instance()->CFG->currency;
75
-        return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
76
-    }
72
+	public function prepare_for_get($value_of_field_on_model_object)
73
+	{
74
+		$c = EE_Registry::instance()->CFG->currency;
75
+		return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
76
+	}
77 77
 
78
-    public function getSchemaProperties()
79
-    {
80
-        return array(
81
-            'raw' => array(
82
-                'description' =>  sprintf(
83
-                    esc_html__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
84
-                    $this->get_nicename()
85
-                ),
86
-                'type' => 'number',
87
-            ),
88
-            'pretty' => array(
89
-                'description' =>  sprintf(
90
-                    esc_html__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
91
-                    $this->get_nicename()
92
-                ),
93
-                'type' => 'string',
94
-                'format' => 'money'
95
-            )
96
-        );
97
-    }
78
+	public function getSchemaProperties()
79
+	{
80
+		return array(
81
+			'raw' => array(
82
+				'description' =>  sprintf(
83
+					esc_html__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
84
+					$this->get_nicename()
85
+				),
86
+				'type' => 'number',
87
+			),
88
+			'pretty' => array(
89
+				'description' =>  sprintf(
90
+					esc_html__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
91
+					$this->get_nicename()
92
+				),
93
+				'type' => 'string',
94
+				'format' => 'money'
95
+			)
96
+		);
97
+	}
98 98
 }
Please login to merge, or discard this patch.
core/domain/services/admin/events/data/ConfirmDeletion.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -30,86 +30,86 @@
 block discarded – undo
30 30
  */
31 31
 class ConfirmDeletion
32 32
 {
33
-    /**
34
-     * @var NodeGroupDao
35
-     */
36
-    private $dao;
33
+	/**
34
+	 * @var NodeGroupDao
35
+	 */
36
+	private $dao;
37 37
 
38
-    /**
39
-     * ConfirmDeletion constructor.
40
-     * @param NodeGroupDao $dao
41
-     */
42
-    public function __construct(
43
-        NodeGroupDao $dao
44
-    ) {
38
+	/**
39
+	 * ConfirmDeletion constructor.
40
+	 * @param NodeGroupDao $dao
41
+	 */
42
+	public function __construct(
43
+		NodeGroupDao $dao
44
+	) {
45 45
 
46
-        $this->dao = $dao;
47
-    }
46
+		$this->dao = $dao;
47
+	}
48 48
 
49
-    /**
50
-     * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
-     * preview page.
52
-     * @since 4.10.12.p
53
-     * @param $request_data
54
-     * @param $admin_base_url
55
-     * @throws EE_Error
56
-     * @throws InvalidArgumentException
57
-     * @throws InvalidDataTypeException
58
-     * @throws InvalidInterfaceException
59
-     * @throws ReflectionException
60
-     * @throws UnexpectedEntityException
61
-     */
62
-    public function handle($request_data, $admin_base_url)
63
-    {
64
-        $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
-        $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
-        $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
-        // Initialize the form from the request, and check if its valid.
68
-        $form->receive_form_submission($request_data);
69
-        if ($form->is_valid()) {
70
-            // Redirect the user to the deletion batch job.
71
-            EEH_URL::safeRedirectAndExit(
72
-                EE_Admin_Page::add_query_args_and_nonce(
73
-                    array(
74
-                        'page' => 'espresso_batch',
75
-                        'batch' => EED_Batch::batch_job,
76
-                        'deletion_job_code' => $deletion_job_code,
77
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
-                        'return_url' => urlencode(
79
-                            add_query_arg(
80
-                                [
81
-                                    'status' => 'trash'
82
-                                ],
83
-                                EVENTS_ADMIN_URL
84
-                            )
85
-                        )
86
-                    ),
87
-                    admin_url()
88
-                )
89
-            );
90
-        }
91
-        // Dont' use $form->submission_error_message() because it adds the form input's label in front
92
-        // of each validation error which ends up looking quite confusing.
93
-        $validation_errors = $form->get_validation_errors_accumulated();
94
-        foreach ($validation_errors as $validation_error) {
95
-            EE_Error::add_error(
96
-                $validation_error->getMessage(),
97
-                __FILE__,
98
-                __FUNCTION__,
99
-                __LINE__
100
-            );
101
-        }
49
+	/**
50
+	 * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
+	 * preview page.
52
+	 * @since 4.10.12.p
53
+	 * @param $request_data
54
+	 * @param $admin_base_url
55
+	 * @throws EE_Error
56
+	 * @throws InvalidArgumentException
57
+	 * @throws InvalidDataTypeException
58
+	 * @throws InvalidInterfaceException
59
+	 * @throws ReflectionException
60
+	 * @throws UnexpectedEntityException
61
+	 */
62
+	public function handle($request_data, $admin_base_url)
63
+	{
64
+		$deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
+		$models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
+		$form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
+		// Initialize the form from the request, and check if its valid.
68
+		$form->receive_form_submission($request_data);
69
+		if ($form->is_valid()) {
70
+			// Redirect the user to the deletion batch job.
71
+			EEH_URL::safeRedirectAndExit(
72
+				EE_Admin_Page::add_query_args_and_nonce(
73
+					array(
74
+						'page' => 'espresso_batch',
75
+						'batch' => EED_Batch::batch_job,
76
+						'deletion_job_code' => $deletion_job_code,
77
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
+						'return_url' => urlencode(
79
+							add_query_arg(
80
+								[
81
+									'status' => 'trash'
82
+								],
83
+								EVENTS_ADMIN_URL
84
+							)
85
+						)
86
+					),
87
+					admin_url()
88
+				)
89
+			);
90
+		}
91
+		// Dont' use $form->submission_error_message() because it adds the form input's label in front
92
+		// of each validation error which ends up looking quite confusing.
93
+		$validation_errors = $form->get_validation_errors_accumulated();
94
+		foreach ($validation_errors as $validation_error) {
95
+			EE_Error::add_error(
96
+				$validation_error->getMessage(),
97
+				__FILE__,
98
+				__FUNCTION__,
99
+				__LINE__
100
+			);
101
+		}
102 102
 
103
-        EEH_URL::safeRedirectAndExit(
104
-            EE_Admin_Page::add_query_args_and_nonce(
105
-                [
106
-                    'action' => 'preview_deletion',
107
-                    'deletion_job_code' => $deletion_job_code
108
-                ],
109
-                $admin_base_url
110
-            )
111
-        );
112
-    }
103
+		EEH_URL::safeRedirectAndExit(
104
+			EE_Admin_Page::add_query_args_and_nonce(
105
+				[
106
+					'action' => 'preview_deletion',
107
+					'deletion_job_code' => $deletion_job_code
108
+				],
109
+				$admin_base_url
110
+			)
111
+		);
112
+	}
113 113
 }
114 114
 // End of file ConfirmDeletion.php
115 115
 // Location: EventEspresso\core\domain\services\admin\events\data/ConfirmDeletion.php
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -7,151 +7,151 @@
 block discarded – undo
7 7
 abstract class EE_Table_Base
8 8
 {
9 9
 
10
-    /**
11
-     * This holds the table_name without the table prefix.
12
-     *
13
-     * @var string
14
-     */
15
-    public $_table_name;
16
-
17
-
18
-    /**
19
-     * This holds what is used as the alias for the table in queries.
20
-     *
21
-     * @var string
22
-     */
23
-    public $_table_alias;
24
-
25
-
26
-    /**
27
-     * Table's private key column
28
-     *
29
-     * @var string
30
-     */
31
-    protected $_pk_column;
32
-
33
-
34
-    /**
35
-     * Whether this table is a global table (in multisite) or specific to site.
36
-     *
37
-     * @var bool
38
-     */
39
-    protected $_global;
40
-
41
-
42
-    /**
43
-     * @param string  $table_name with or without wpdb prefix
44
-     * @param string  $pk_column
45
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
46
-     *                            install, or whether each site on a multisite install has a copy of this table
47
-     * @global wpdb   $wpdb
48
-     */
49
-    public function __construct($table_name, $pk_column, $global = false)
50
-    {
51
-        $this->_global = $global;
52
-        $prefix        = $this->get_table_prefix();
53
-        // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
54
-        if (strpos($table_name, $prefix) === 0) {
55
-            $table_name = substr_replace($table_name, '', 0, strlen($prefix));
56
-        }
57
-        $this->_table_name = $table_name;
58
-        $this->_pk_column  = $pk_column;
59
-    }
60
-
61
-
62
-    /**
63
-     * This returns the table prefix for the current model state.
64
-     *
65
-     * @return string
66
-     * @global wpdb $wpdb
67
-     */
68
-    public function get_table_prefix()
69
-    {
70
-        global $wpdb;
71
-        if ($this->_global) {
72
-            return $wpdb->base_prefix;
73
-        }
74
-        return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
75
-    }
76
-
77
-
78
-    /**
79
-     * Used to set the table_alias property
80
-     *
81
-     * @param string $table_alias
82
-     */
83
-    public function _construct_finalize_with_alias($table_alias)
84
-    {
85
-        $this->_table_alias = $table_alias;
86
-    }
87
-
88
-
89
-    /**
90
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
91
-     *
92
-     * @return string
93
-     */
94
-    public function get_table_name()
95
-    {
96
-        return $this->get_table_prefix() . $this->_table_name;
97
-    }
98
-
99
-
100
-    /**
101
-     * Provides what is currently set as the alias for the table to be used in queries.
102
-     *
103
-     * @return string
104
-     * @throws EE_Error
105
-     */
106
-    public function get_table_alias()
107
-    {
108
-        if (! $this->_table_alias) {
109
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
110
-        }
111
-        return $this->_table_alias;
112
-    }
113
-
114
-
115
-    /**
116
-     * @return string name of column of PK
117
-     */
118
-    public function get_pk_column()
119
-    {
120
-        return $this->_pk_column;
121
-    }
122
-
123
-
124
-    /**
125
-     * returns a string with the table alias, a period, and the private key's column.
126
-     *
127
-     * @return string
128
-     */
129
-    public function get_fully_qualified_pk_column()
130
-    {
131
-        return $this->get_table_alias() . "." . $this->get_pk_column();
132
-    }
133
-
134
-
135
-    /**
136
-     * returns the special sql for a inner select with a limit.
137
-     *
138
-     * @return string    SQL select
139
-     */
140
-    public function get_select_join_limit($limit)
141
-    {
142
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
143
-        return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
144
-    }
145
-
146
-
147
-    /**
148
-     * Returns whether or not htis is a global table (ie, on multisite there's
149
-     * only one of these tables, on the main blog)
150
-     *
151
-     * @return boolean
152
-     */
153
-    public function is_global()
154
-    {
155
-        return $this->_global;
156
-    }
10
+	/**
11
+	 * This holds the table_name without the table prefix.
12
+	 *
13
+	 * @var string
14
+	 */
15
+	public $_table_name;
16
+
17
+
18
+	/**
19
+	 * This holds what is used as the alias for the table in queries.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	public $_table_alias;
24
+
25
+
26
+	/**
27
+	 * Table's private key column
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $_pk_column;
32
+
33
+
34
+	/**
35
+	 * Whether this table is a global table (in multisite) or specific to site.
36
+	 *
37
+	 * @var bool
38
+	 */
39
+	protected $_global;
40
+
41
+
42
+	/**
43
+	 * @param string  $table_name with or without wpdb prefix
44
+	 * @param string  $pk_column
45
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
46
+	 *                            install, or whether each site on a multisite install has a copy of this table
47
+	 * @global wpdb   $wpdb
48
+	 */
49
+	public function __construct($table_name, $pk_column, $global = false)
50
+	{
51
+		$this->_global = $global;
52
+		$prefix        = $this->get_table_prefix();
53
+		// if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
54
+		if (strpos($table_name, $prefix) === 0) {
55
+			$table_name = substr_replace($table_name, '', 0, strlen($prefix));
56
+		}
57
+		$this->_table_name = $table_name;
58
+		$this->_pk_column  = $pk_column;
59
+	}
60
+
61
+
62
+	/**
63
+	 * This returns the table prefix for the current model state.
64
+	 *
65
+	 * @return string
66
+	 * @global wpdb $wpdb
67
+	 */
68
+	public function get_table_prefix()
69
+	{
70
+		global $wpdb;
71
+		if ($this->_global) {
72
+			return $wpdb->base_prefix;
73
+		}
74
+		return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
75
+	}
76
+
77
+
78
+	/**
79
+	 * Used to set the table_alias property
80
+	 *
81
+	 * @param string $table_alias
82
+	 */
83
+	public function _construct_finalize_with_alias($table_alias)
84
+	{
85
+		$this->_table_alias = $table_alias;
86
+	}
87
+
88
+
89
+	/**
90
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
91
+	 *
92
+	 * @return string
93
+	 */
94
+	public function get_table_name()
95
+	{
96
+		return $this->get_table_prefix() . $this->_table_name;
97
+	}
98
+
99
+
100
+	/**
101
+	 * Provides what is currently set as the alias for the table to be used in queries.
102
+	 *
103
+	 * @return string
104
+	 * @throws EE_Error
105
+	 */
106
+	public function get_table_alias()
107
+	{
108
+		if (! $this->_table_alias) {
109
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
110
+		}
111
+		return $this->_table_alias;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @return string name of column of PK
117
+	 */
118
+	public function get_pk_column()
119
+	{
120
+		return $this->_pk_column;
121
+	}
122
+
123
+
124
+	/**
125
+	 * returns a string with the table alias, a period, and the private key's column.
126
+	 *
127
+	 * @return string
128
+	 */
129
+	public function get_fully_qualified_pk_column()
130
+	{
131
+		return $this->get_table_alias() . "." . $this->get_pk_column();
132
+	}
133
+
134
+
135
+	/**
136
+	 * returns the special sql for a inner select with a limit.
137
+	 *
138
+	 * @return string    SQL select
139
+	 */
140
+	public function get_select_join_limit($limit)
141
+	{
142
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
143
+		return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
144
+	}
145
+
146
+
147
+	/**
148
+	 * Returns whether or not htis is a global table (ie, on multisite there's
149
+	 * only one of these tables, on the main blog)
150
+	 *
151
+	 * @return boolean
152
+	 */
153
+	public function is_global()
154
+	{
155
+		return $this->_global;
156
+	}
157 157
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function get_table_name()
95 95
     {
96
-        return $this->get_table_prefix() . $this->_table_name;
96
+        return $this->get_table_prefix().$this->_table_name;
97 97
     }
98 98
 
99 99
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function get_table_alias()
107 107
     {
108
-        if (! $this->_table_alias) {
108
+        if ( ! $this->_table_alias) {
109 109
             throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
110 110
         }
111 111
         return $this->_table_alias;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function get_fully_qualified_pk_column()
130 130
     {
131
-        return $this->get_table_alias() . "." . $this->get_pk_column();
131
+        return $this->get_table_alias().".".$this->get_pk_column();
132 132
     }
133 133
 
134 134
 
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function get_select_join_limit($limit)
141 141
     {
142
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
143
-        return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
142
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
143
+        return SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
144 144
     }
145 145
 
146 146
 
Please login to merge, or discard this patch.