Completed
Branch fix/escaping-2 (5dcb9a)
by
unknown
13:02 queued 10:26
created
admin_pages/transactions/EE_Admin_Transactions_List_Table.class.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     {
97 97
         $class = parent::_get_row_class($transaction);
98 98
         // add status class
99
-        $class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
99
+        $class .= ' ee-status-strip txn-status-'.$transaction->status_ID();
100 100
         if ($this->_has_checkbox_column) {
101 101
             $class .= ' has-checkbox-column';
102 102
         }
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     protected function _add_view_counts()
150 150
     {
151 151
         foreach ($this->_views as $view) {
152
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
152
+            $this->_views[$view['slug']]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
153 153
         }
154 154
     }
155 155
 
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
             ),
171 171
             TXN_ADMIN_URL
172 172
         );
173
-        $content = '<a href="' . $view_lnk_url . '"'
174
-                   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
173
+        $content = '<a href="'.$view_lnk_url.'"'
174
+                   . ' title="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">'
175 175
                    . $transaction->ID()
176 176
                    . '</a>';
177 177
 
178 178
         // txn timestamp
179
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
179
+        $content .= '  <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>';
180 180
         return $content;
181 181
     }
182 182
 
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
             ),
238 238
             TXN_ADMIN_URL
239 239
         );
240
-        $txn_date = '<a href="' . $view_lnk_url . '"'
240
+        $txn_date = '<a href="'.$view_lnk_url.'"'
241 241
                     . ' title="'
242
-                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
242
+                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">'
243 243
                     . $this->_get_txn_timestamp($transaction)
244 244
                     . '</a>';
245 245
         // status
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                    )
273 273
                    . '</span>';
274 274
         } else {
275
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
275
+            return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
276 276
         }
277 277
     }
278 278
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
             ? $payment_method->admin_name()
310 310
             : esc_html__('Unknown', 'event_espresso');
311 311
 
312
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
312
+        $content = '<span class="'.$span_class.' txn-pad-rght">'
313 313
                    . $transaction->get_pretty('TXN_paid')
314 314
                    . '</span>';
315 315
         if ($transaction_paid > 0) {
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
                 'espresso_registrations_view_registration',
352 352
                 $primary_reg->ID()
353 353
             )
354
-                ? '<a href="' . $edit_lnk_url . '"'
355
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
354
+                ? '<a href="'.$edit_lnk_url.'"'
355
+                  . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
356 356
                   . $attendee->full_name()
357 357
                   . '</a>'
358 358
                 : $attendee->full_name();
359
-            $content .= '<br>' . $attendee->email();
359
+            $content .= '<br>'.$attendee->email();
360 360
             return $content;
361 361
         }
362 362
         return $transaction->failed() || $transaction->is_abandoned()
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
     public function column_ATT_email(EE_Transaction $transaction)
379 379
     {
380 380
         $attendee = $transaction->primary_registration()->get_first_related('Attendee');
381
-        if (! empty($attendee)) {
382
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
381
+        if ( ! empty($attendee)) {
382
+            return '<a href="mailto:'.$attendee->get('ATT_email').'">'
383 383
                    . $attendee->get('ATT_email')
384 384
                    . '</a>';
385 385
         } else {
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
     {
408 408
         $actions = array();
409 409
         $event = $transaction->primary_registration()->get_first_related('Event');
410
-        if (! empty($event)) {
410
+        if ( ! empty($event)) {
411 411
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
412 412
                 array('action' => 'edit', 'post' => $event->ID()),
413 413
                 EVENTS_ADMIN_URL
@@ -429,11 +429,11 @@  discard block
 block discarded – undo
429 429
                     $event->ID()
430 430
                 )
431 431
             ) {
432
-                $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
433
-                                              . ' title="' . esc_attr__(
432
+                $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'"'
433
+                                              . ' title="'.esc_attr__(
434 434
                                                   'Filter transactions by this event',
435 435
                                                   'event_espresso'
436
-                                              ) . '">'
436
+                                              ).'">'
437 437
                                               . esc_html__('View Transactions for this event', 'event_espresso')
438 438
                                               . '</a>';
439 439
             }
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
                     'espresso_events_edit',
446 446
                     $event->ID()
447 447
                 )
448
-                    ? '<a href="' . $edit_event_url . '"'
448
+                    ? '<a href="'.$edit_event_url.'"'
449 449
                       . ' title="'
450 450
                       . sprintf(
451 451
                           esc_attr__('Edit Event: %s', 'event_espresso'),
@@ -512,8 +512,8 @@  discard block
 block discarded – undo
512 512
         );
513 513
         return '
514 514
 			<li>
515
-				<a href="' . $url . '"'
516
-               . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
515
+				<a href="' . $url.'"'
516
+               . ' title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text">
517 517
 					<span class="dashicons dashicons-cart"></span>
518 518
 				</a>
519 519
 			</li>';
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
             ) {
540 540
                 return '
541 541
                 <li>
542
-                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
543
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
542
+                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"'
543
+                       . ' target="_blank" href="'.$url.'" class="tiny-text">
544 544
                         <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
545 545
                     </a>
546 546
                 </li>';
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
             ) {
570 570
                 return '
571 571
 			<li>
572
-				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
573
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
572
+				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"'
573
+                       . ' target="_blank" href="'.$url.'" class="tiny-text">
574 574
 					<span class="dashicons dashicons-media-default ee-icon-size-18"></span>
575 575
 				</a>
576 576
 			</li>';
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
             )
609 609
                 ? '
610 610
 				<li>
611
-					<a href="' . $url . '"'
612
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
611
+					<a href="' . $url.'"'
612
+                  . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text">
613 613
 						<span class="dashicons dashicons-clipboard"></span>
614 614
 					</a>
615 615
 				</li>'
@@ -655,8 +655,8 @@  discard block
 block discarded – undo
655 655
             );
656 656
             return '
657 657
             <li>
658
-                <a href="' . $url . '"'
659
-                   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
658
+                <a href="' . $url.'"'
659
+                   . ' title="'.esc_attr__('Send Payment Reminder', 'event_espresso').'" class="tiny-text">
660 660
                     <span class="dashicons dashicons-email-alt"></span>
661 661
                 </a>
662 662
             </li>';
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
             'ee_read_global_messages',
687 687
             'view_filtered_messages'
688 688
         )
689
-            ? '<li>' . $url . '</li>'
689
+            ? '<li>'.$url.'</li>'
690 690
             : '';
691 691
     }
692 692
 
@@ -708,8 +708,8 @@  discard block
 block discarded – undo
708 708
         ) {
709 709
             return '
710 710
             <li>
711
-                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
712
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
711
+                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"'
712
+                   . ' target="_blank" href="'.$registration->payment_overview_url(true).'"'
713 713
                    . ' class="tiny-text">
714 714
                     <span class="dashicons dashicons-money ee-icon-size-18"></span>
715 715
                 </a>
Please login to merge, or discard this patch.
Indentation   +665 added lines, -665 removed lines patch added patch discarded remove patch
@@ -15,121 +15,121 @@  discard block
 block discarded – undo
15 15
 class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @var SessionLifespan $session_lifespan
20
-     */
21
-    private $session_lifespan;
22
-
23
-    private $_status;
24
-
25
-
26
-    /**
27
-     * @param \Transactions_Admin_Page $admin_page
28
-     * @param SessionLifespan          $lifespan
29
-     */
30
-    public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
31
-    {
32
-        parent::__construct($admin_page);
33
-        $this->session_lifespan = $lifespan;
34
-        $this->_status = $this->_admin_page->get_transaction_status_array();
35
-    }
36
-
37
-
38
-    /**
39
-     *_setup_data
40
-     */
41
-    protected function _setup_data()
42
-    {
43
-        $this->_data = $this->_admin_page->get_transactions($this->_per_page);
44
-        $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
45
-        $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
46
-    }
47
-
48
-
49
-    /**
50
-     *_set_properties
51
-     */
52
-    protected function _set_properties()
53
-    {
54
-        $this->_wp_list_args = array(
55
-            'singular' => esc_html__('transaction', 'event_espresso'),
56
-            'plural'   => esc_html__('transactions', 'event_espresso'),
57
-            'ajax'     => true,
58
-            'screen'   => $this->_admin_page->get_current_screen()->id,
59
-        );
60
-        $ID_column_name = esc_html__('ID', 'event_espresso');
61
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
62
-        $ID_column_name .= esc_html__('Transaction Date', 'event_espresso');
63
-        $ID_column_name .= '</span> ';
64
-        $this->_columns = array(
65
-            'TXN_ID'        => $ID_column_name,
66
-            'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
67
-            'TXN_total'     => esc_html__('Total', 'event_espresso'),
68
-            'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
69
-            'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
70
-            'event_name'    => esc_html__('Event', 'event_espresso'),
71
-            'actions'       => esc_html__('Actions', 'event_espresso'),
72
-        );
73
-
74
-        $this->_sortable_columns = array(
75
-            'TXN_ID'        => array('TXN_ID' => false),
76
-            'event_name'    => array('event_name' => false),
77
-            'ATT_fname'     => array('ATT_fname' => false),
78
-            'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
79
-        );
80
-
81
-        $this->_primary_column = 'TXN_ID';
82
-
83
-        $this->_hidden_columns = array();
84
-    }
85
-
86
-
87
-    /**
88
-     * This simply sets up the row class for the table rows.
89
-     * Allows for easier overriding of child methods for setting up sorting.
90
-     *
91
-     * @param  EE_Transaction $transaction the current item
92
-     * @return string
93
-     * @throws \EE_Error
94
-     */
95
-    protected function _get_row_class($transaction)
96
-    {
97
-        $class = parent::_get_row_class($transaction);
98
-        // add status class
99
-        $class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
100
-        if ($this->_has_checkbox_column) {
101
-            $class .= ' has-checkbox-column';
102
-        }
103
-        return $class;
104
-    }
105
-
106
-
107
-    /**
108
-     * _get_table_filters
109
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
110
-     * get's shown in the table.
111
-     *
112
-     * @abstract
113
-     * @access protected
114
-     * @return array
115
-     */
116
-    protected function _get_table_filters()
117
-    {
118
-        $filters = array();
119
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
120
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
121
-            : date(
122
-                'm/d/Y',
123
-                strtotime('-10 year')
124
-            );
125
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
126
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
127
-            : date(
128
-                'm/d/Y',
129
-                current_time('timestamp')
130
-            );
131
-        ob_start();
132
-        ?>
18
+	/**
19
+	 * @var SessionLifespan $session_lifespan
20
+	 */
21
+	private $session_lifespan;
22
+
23
+	private $_status;
24
+
25
+
26
+	/**
27
+	 * @param \Transactions_Admin_Page $admin_page
28
+	 * @param SessionLifespan          $lifespan
29
+	 */
30
+	public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
31
+	{
32
+		parent::__construct($admin_page);
33
+		$this->session_lifespan = $lifespan;
34
+		$this->_status = $this->_admin_page->get_transaction_status_array();
35
+	}
36
+
37
+
38
+	/**
39
+	 *_setup_data
40
+	 */
41
+	protected function _setup_data()
42
+	{
43
+		$this->_data = $this->_admin_page->get_transactions($this->_per_page);
44
+		$status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
45
+		$this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
46
+	}
47
+
48
+
49
+	/**
50
+	 *_set_properties
51
+	 */
52
+	protected function _set_properties()
53
+	{
54
+		$this->_wp_list_args = array(
55
+			'singular' => esc_html__('transaction', 'event_espresso'),
56
+			'plural'   => esc_html__('transactions', 'event_espresso'),
57
+			'ajax'     => true,
58
+			'screen'   => $this->_admin_page->get_current_screen()->id,
59
+		);
60
+		$ID_column_name = esc_html__('ID', 'event_espresso');
61
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
62
+		$ID_column_name .= esc_html__('Transaction Date', 'event_espresso');
63
+		$ID_column_name .= '</span> ';
64
+		$this->_columns = array(
65
+			'TXN_ID'        => $ID_column_name,
66
+			'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
67
+			'TXN_total'     => esc_html__('Total', 'event_espresso'),
68
+			'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
69
+			'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
70
+			'event_name'    => esc_html__('Event', 'event_espresso'),
71
+			'actions'       => esc_html__('Actions', 'event_espresso'),
72
+		);
73
+
74
+		$this->_sortable_columns = array(
75
+			'TXN_ID'        => array('TXN_ID' => false),
76
+			'event_name'    => array('event_name' => false),
77
+			'ATT_fname'     => array('ATT_fname' => false),
78
+			'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
79
+		);
80
+
81
+		$this->_primary_column = 'TXN_ID';
82
+
83
+		$this->_hidden_columns = array();
84
+	}
85
+
86
+
87
+	/**
88
+	 * This simply sets up the row class for the table rows.
89
+	 * Allows for easier overriding of child methods for setting up sorting.
90
+	 *
91
+	 * @param  EE_Transaction $transaction the current item
92
+	 * @return string
93
+	 * @throws \EE_Error
94
+	 */
95
+	protected function _get_row_class($transaction)
96
+	{
97
+		$class = parent::_get_row_class($transaction);
98
+		// add status class
99
+		$class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
100
+		if ($this->_has_checkbox_column) {
101
+			$class .= ' has-checkbox-column';
102
+		}
103
+		return $class;
104
+	}
105
+
106
+
107
+	/**
108
+	 * _get_table_filters
109
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
110
+	 * get's shown in the table.
111
+	 *
112
+	 * @abstract
113
+	 * @access protected
114
+	 * @return array
115
+	 */
116
+	protected function _get_table_filters()
117
+	{
118
+		$filters = array();
119
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
120
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
121
+			: date(
122
+				'm/d/Y',
123
+				strtotime('-10 year')
124
+			);
125
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
126
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
127
+			: date(
128
+				'm/d/Y',
129
+				current_time('timestamp')
130
+			);
131
+		ob_start();
132
+		?>
133 133
         <label for="txn-filter-start-date">Display Transactions from </label>
134 134
         <input class="datepicker"
135 135
                id="txn-filter-start-date"
@@ -147,585 +147,585 @@  discard block
 block discarded – undo
147 147
                value="<?php echo esc_html($end_date); ?>"
148 148
         />
149 149
         <?php
150
-        $filters[] = ob_get_contents();
151
-        ob_end_clean();
152
-        return $filters;
153
-    }
154
-
155
-
156
-    /**
157
-     *_add_view_counts
158
-     */
159
-    protected function _add_view_counts()
160
-    {
161
-        foreach ($this->_views as $view) {
162
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
163
-        }
164
-    }
165
-
166
-
167
-    /**
168
-     *    column TXN_ID
169
-     *
170
-     * @param \EE_Transaction $transaction
171
-     * @return string
172
-     * @throws \EE_Error
173
-     */
174
-    public function column_TXN_ID(EE_Transaction $transaction)
175
-    {
176
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
177
-            array(
178
-                'action' => 'view_transaction',
179
-                'TXN_ID' => $transaction->ID(),
180
-            ),
181
-            TXN_ADMIN_URL
182
-        );
183
-        $content = '<a href="' . $view_lnk_url . '"'
184
-                   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
185
-                   . $transaction->ID()
186
-                   . '</a>';
187
-
188
-        // txn timestamp
189
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
190
-        return $content;
191
-    }
192
-
193
-
194
-    /**
195
-     * @param \EE_Transaction $transaction
196
-     * @return string
197
-     * @throws EE_Error
198
-     * @throws InvalidArgumentException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     */
202
-    protected function _get_txn_timestamp(EE_Transaction $transaction)
203
-    {
204
-        // is TXN less than 2 hours old ?
205
-        if (
206
-            ($transaction->failed() || $transaction->is_abandoned())
207
-            && $this->session_lifespan->expiration() < $transaction->datetime(false, true)
208
-        ) {
209
-            $timestamp = esc_html__('TXN in progress...', 'event_espresso');
210
-        } else {
211
-            $timestamp = $transaction->get_i18n_datetime('TXN_timestamp');
212
-        }
213
-        return $timestamp;
214
-    }
215
-
216
-
217
-    /**
218
-     *    column_cb
219
-     *
220
-     * @param \EE_Transaction $transaction
221
-     * @return string
222
-     * @throws \EE_Error
223
-     */
224
-    public function column_cb($transaction)
225
-    {
226
-        return sprintf(
227
-            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
228
-            $this->_wp_list_args['singular'],
229
-            $transaction->ID()
230
-        );
231
-    }
232
-
233
-
234
-    /**
235
-     *    column_TXN_timestamp
236
-     *
237
-     * @param \EE_Transaction $transaction
238
-     * @return string
239
-     * @throws \EE_Error
240
-     */
241
-    public function column_TXN_timestamp(EE_Transaction $transaction)
242
-    {
243
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
244
-            array(
245
-                'action' => 'view_transaction',
246
-                'TXN_ID' => $transaction->ID(),
247
-            ),
248
-            TXN_ADMIN_URL
249
-        );
250
-        $txn_date = '<a href="' . $view_lnk_url . '"'
251
-                    . ' title="'
252
-                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
253
-                    . $this->_get_txn_timestamp($transaction)
254
-                    . '</a>';
255
-        // status
256
-        $txn_date .= '<br><span class="ee-status-text-small">'
257
-                    . EEH_Template::pretty_status(
258
-                        $transaction->status_ID(),
259
-                        false,
260
-                        'sentence'
261
-                    )
262
-                     . '</span>';
263
-        return $txn_date;
264
-    }
265
-
266
-
267
-    /**
268
-     *    column_TXN_total
269
-     *
270
-     * @param \EE_Transaction $transaction
271
-     * @return string
272
-     * @throws \EE_Error
273
-     */
274
-    public function column_TXN_total(EE_Transaction $transaction)
275
-    {
276
-        if ($transaction->get('TXN_total') > 0) {
277
-            return '<span class="txn-pad-rght">'
278
-                   . apply_filters(
279
-                       'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
280
-                       $transaction->get_pretty('TXN_total'),
281
-                       $transaction
282
-                   )
283
-                   . '</span>';
284
-        } else {
285
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
286
-        }
287
-    }
288
-
289
-
290
-    /**
291
-     *    column_TXN_paid
292
-     *
293
-     * @param \EE_Transaction $transaction
294
-     * @return mixed|string
295
-     * @throws \EE_Error
296
-     */
297
-    public function column_TXN_paid(EE_Transaction $transaction)
298
-    {
299
-        $transaction_total = $transaction->get('TXN_total');
300
-        $transaction_paid = $transaction->get('TXN_paid');
301
-
302
-        if (\EEH_Money::compare_floats($transaction_total, 0, '>')) {
303
-            // monies owing
304
-            $span_class = 'txn-overview-part-payment-spn';
305
-            if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
306
-                // paid in full
307
-                $span_class = 'txn-overview-full-payment-spn';
308
-            } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) {
309
-                // no payments made
310
-                $span_class = 'txn-overview-no-payment-spn';
311
-            }
312
-        } else {
313
-            // transaction_total == 0 so this is a free event
314
-            $span_class = 'txn-overview-free-event-spn';
315
-        }
316
-
317
-        $payment_method = $transaction->payment_method();
318
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
319
-            ? $payment_method->admin_name()
320
-            : esc_html__('Unknown', 'event_espresso');
321
-
322
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
323
-                   . $transaction->get_pretty('TXN_paid')
324
-                   . '</span>';
325
-        if ($transaction_paid > 0) {
326
-            $content .= '<br><span class="ee-status-text-small">'
327
-                        . sprintf(
328
-                            esc_html__('...via %s', 'event_espresso'),
329
-                            $payment_method_name
330
-                        )
331
-                        . '</span>';
332
-        }
333
-        return $content;
334
-    }
335
-
336
-
337
-    /**
338
-     *    column_ATT_fname
339
-     *
340
-     * @param \EE_Transaction $transaction
341
-     * @return string
342
-     * @throws EE_Error
343
-     * @throws InvalidArgumentException
344
-     * @throws InvalidDataTypeException
345
-     * @throws InvalidInterfaceException
346
-     */
347
-    public function column_ATT_fname(EE_Transaction $transaction)
348
-    {
349
-        $primary_reg = $transaction->primary_registration();
350
-        $attendee = $primary_reg->get_first_related('Attendee');
351
-        if ($attendee instanceof EE_Attendee) {
352
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
353
-                array(
354
-                    'action'  => 'view_registration',
355
-                    '_REG_ID' => $primary_reg->ID(),
356
-                ),
357
-                REG_ADMIN_URL
358
-            );
359
-            $content = EE_Registry::instance()->CAP->current_user_can(
360
-                'ee_read_registration',
361
-                'espresso_registrations_view_registration',
362
-                $primary_reg->ID()
363
-            )
364
-                ? '<a href="' . $edit_lnk_url . '"'
365
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
366
-                  . $attendee->full_name()
367
-                  . '</a>'
368
-                : $attendee->full_name();
369
-            $content .= '<br>' . $attendee->email();
370
-            return $content;
371
-        }
372
-        return $transaction->failed() || $transaction->is_abandoned()
373
-            ? esc_html__('no contact record.', 'event_espresso')
374
-            : esc_html__(
375
-                'No contact record, because the transaction was abandoned or the registration process failed.',
376
-                'event_espresso'
377
-            );
378
-    }
379
-
380
-
381
-    /**
382
-     *    column_ATT_email
383
-     *
384
-     * @param \EE_Transaction $transaction
385
-     * @return string
386
-     * @throws \EE_Error
387
-     */
388
-    public function column_ATT_email(EE_Transaction $transaction)
389
-    {
390
-        $attendee = $transaction->primary_registration()->get_first_related('Attendee');
391
-        if (! empty($attendee)) {
392
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
393
-                   . $attendee->get('ATT_email')
394
-                   . '</a>';
395
-        } else {
396
-            return $transaction->failed() || $transaction->is_abandoned()
397
-                ? esc_html__('no contact record.', 'event_espresso')
398
-                : esc_html__(
399
-                    'No contact record, because the transaction was abandoned or the registration process failed.',
400
-                    'event_espresso'
401
-                );
402
-        }
403
-    }
404
-
405
-
406
-    /**
407
-     *    column_event_name
408
-     *
409
-     * @param \EE_Transaction $transaction
410
-     * @return string
411
-     * @throws EE_Error
412
-     * @throws InvalidArgumentException
413
-     * @throws InvalidDataTypeException
414
-     * @throws InvalidInterfaceException
415
-     */
416
-    public function column_event_name(EE_Transaction $transaction)
417
-    {
418
-        $actions = array();
419
-        $event = $transaction->primary_registration()->get_first_related('Event');
420
-        if (! empty($event)) {
421
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
422
-                array('action' => 'edit', 'post' => $event->ID()),
423
-                EVENTS_ADMIN_URL
424
-            );
425
-            $event_name = $event->get('EVT_name');
426
-
427
-            // filter this view by transactions for this event
428
-            $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
429
-                array(
430
-                    'action' => 'default',
431
-                    'EVT_ID' => $event->ID(),
432
-                )
433
-            );
434
-            if (
435
-                empty($this->_req_data['EVT_ID'])
436
-                && EE_Registry::instance()->CAP->current_user_can(
437
-                    'ee_edit_event',
438
-                    'espresso_events_edit',
439
-                    $event->ID()
440
-                )
441
-            ) {
442
-                $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
443
-                                              . ' title="' . esc_attr__(
444
-                                                  'Filter transactions by this event',
445
-                                                  'event_espresso'
446
-                                              ) . '">'
447
-                                              . esc_html__('View Transactions for this event', 'event_espresso')
448
-                                              . '</a>';
449
-            }
450
-
451
-            return sprintf(
452
-                '%1$s %2$s',
453
-                EE_Registry::instance()->CAP->current_user_can(
454
-                    'ee_edit_event',
455
-                    'espresso_events_edit',
456
-                    $event->ID()
457
-                )
458
-                    ? '<a href="' . $edit_event_url . '"'
459
-                      . ' title="'
460
-                      . sprintf(
461
-                          esc_attr__('Edit Event: %s', 'event_espresso'),
462
-                          $event->get('EVT_name')
463
-                      )
464
-                      . '">'
465
-                      . wp_trim_words(
466
-                          $event_name,
467
-                          30,
468
-                          '...'
469
-                      )
470
-                      . '</a>'
471
-                    : wp_trim_words($event_name, 30, '...'),
472
-                $this->row_actions($actions)
473
-            );
474
-        } else {
475
-            return esc_html__(
476
-                'The event associated with this transaction via the primary registration cannot be retrieved.',
477
-                'event_espresso'
478
-            );
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     *    column_actions
485
-     *
486
-     * @param \EE_Transaction $transaction
487
-     * @return string
488
-     * @throws \EE_Error
489
-     */
490
-    public function column_actions(EE_Transaction $transaction)
491
-    {
492
-        return $this->_action_string(
493
-            $this->get_transaction_details_link($transaction)
494
-            . $this->get_invoice_link($transaction)
495
-            . $this->get_receipt_link($transaction)
496
-            . $this->get_primary_registration_details_link($transaction)
497
-            . $this->get_send_payment_reminder_trigger_link($transaction)
498
-            . $this->get_payment_overview_link($transaction)
499
-            . $this->get_related_messages_link($transaction),
500
-            $transaction,
501
-            'ul',
502
-            'txn-overview-actions-ul'
503
-        );
504
-    }
505
-
506
-
507
-    /**
508
-     * Get the transaction details link.
509
-     *
510
-     * @param EE_Transaction $transaction
511
-     * @return string
512
-     * @throws EE_Error
513
-     */
514
-    protected function get_transaction_details_link(EE_Transaction $transaction)
515
-    {
516
-        $url = EE_Admin_Page::add_query_args_and_nonce(
517
-            array(
518
-                'action' => 'view_transaction',
519
-                'TXN_ID' => $transaction->ID(),
520
-            ),
521
-            TXN_ADMIN_URL
522
-        );
523
-        return '
150
+		$filters[] = ob_get_contents();
151
+		ob_end_clean();
152
+		return $filters;
153
+	}
154
+
155
+
156
+	/**
157
+	 *_add_view_counts
158
+	 */
159
+	protected function _add_view_counts()
160
+	{
161
+		foreach ($this->_views as $view) {
162
+			$this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
163
+		}
164
+	}
165
+
166
+
167
+	/**
168
+	 *    column TXN_ID
169
+	 *
170
+	 * @param \EE_Transaction $transaction
171
+	 * @return string
172
+	 * @throws \EE_Error
173
+	 */
174
+	public function column_TXN_ID(EE_Transaction $transaction)
175
+	{
176
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
177
+			array(
178
+				'action' => 'view_transaction',
179
+				'TXN_ID' => $transaction->ID(),
180
+			),
181
+			TXN_ADMIN_URL
182
+		);
183
+		$content = '<a href="' . $view_lnk_url . '"'
184
+				   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
185
+				   . $transaction->ID()
186
+				   . '</a>';
187
+
188
+		// txn timestamp
189
+		$content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
190
+		return $content;
191
+	}
192
+
193
+
194
+	/**
195
+	 * @param \EE_Transaction $transaction
196
+	 * @return string
197
+	 * @throws EE_Error
198
+	 * @throws InvalidArgumentException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 */
202
+	protected function _get_txn_timestamp(EE_Transaction $transaction)
203
+	{
204
+		// is TXN less than 2 hours old ?
205
+		if (
206
+			($transaction->failed() || $transaction->is_abandoned())
207
+			&& $this->session_lifespan->expiration() < $transaction->datetime(false, true)
208
+		) {
209
+			$timestamp = esc_html__('TXN in progress...', 'event_espresso');
210
+		} else {
211
+			$timestamp = $transaction->get_i18n_datetime('TXN_timestamp');
212
+		}
213
+		return $timestamp;
214
+	}
215
+
216
+
217
+	/**
218
+	 *    column_cb
219
+	 *
220
+	 * @param \EE_Transaction $transaction
221
+	 * @return string
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function column_cb($transaction)
225
+	{
226
+		return sprintf(
227
+			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
228
+			$this->_wp_list_args['singular'],
229
+			$transaction->ID()
230
+		);
231
+	}
232
+
233
+
234
+	/**
235
+	 *    column_TXN_timestamp
236
+	 *
237
+	 * @param \EE_Transaction $transaction
238
+	 * @return string
239
+	 * @throws \EE_Error
240
+	 */
241
+	public function column_TXN_timestamp(EE_Transaction $transaction)
242
+	{
243
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
244
+			array(
245
+				'action' => 'view_transaction',
246
+				'TXN_ID' => $transaction->ID(),
247
+			),
248
+			TXN_ADMIN_URL
249
+		);
250
+		$txn_date = '<a href="' . $view_lnk_url . '"'
251
+					. ' title="'
252
+					. esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
253
+					. $this->_get_txn_timestamp($transaction)
254
+					. '</a>';
255
+		// status
256
+		$txn_date .= '<br><span class="ee-status-text-small">'
257
+					. EEH_Template::pretty_status(
258
+						$transaction->status_ID(),
259
+						false,
260
+						'sentence'
261
+					)
262
+					 . '</span>';
263
+		return $txn_date;
264
+	}
265
+
266
+
267
+	/**
268
+	 *    column_TXN_total
269
+	 *
270
+	 * @param \EE_Transaction $transaction
271
+	 * @return string
272
+	 * @throws \EE_Error
273
+	 */
274
+	public function column_TXN_total(EE_Transaction $transaction)
275
+	{
276
+		if ($transaction->get('TXN_total') > 0) {
277
+			return '<span class="txn-pad-rght">'
278
+				   . apply_filters(
279
+					   'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
280
+					   $transaction->get_pretty('TXN_total'),
281
+					   $transaction
282
+				   )
283
+				   . '</span>';
284
+		} else {
285
+			return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
286
+		}
287
+	}
288
+
289
+
290
+	/**
291
+	 *    column_TXN_paid
292
+	 *
293
+	 * @param \EE_Transaction $transaction
294
+	 * @return mixed|string
295
+	 * @throws \EE_Error
296
+	 */
297
+	public function column_TXN_paid(EE_Transaction $transaction)
298
+	{
299
+		$transaction_total = $transaction->get('TXN_total');
300
+		$transaction_paid = $transaction->get('TXN_paid');
301
+
302
+		if (\EEH_Money::compare_floats($transaction_total, 0, '>')) {
303
+			// monies owing
304
+			$span_class = 'txn-overview-part-payment-spn';
305
+			if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
306
+				// paid in full
307
+				$span_class = 'txn-overview-full-payment-spn';
308
+			} elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) {
309
+				// no payments made
310
+				$span_class = 'txn-overview-no-payment-spn';
311
+			}
312
+		} else {
313
+			// transaction_total == 0 so this is a free event
314
+			$span_class = 'txn-overview-free-event-spn';
315
+		}
316
+
317
+		$payment_method = $transaction->payment_method();
318
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
319
+			? $payment_method->admin_name()
320
+			: esc_html__('Unknown', 'event_espresso');
321
+
322
+		$content = '<span class="' . $span_class . ' txn-pad-rght">'
323
+				   . $transaction->get_pretty('TXN_paid')
324
+				   . '</span>';
325
+		if ($transaction_paid > 0) {
326
+			$content .= '<br><span class="ee-status-text-small">'
327
+						. sprintf(
328
+							esc_html__('...via %s', 'event_espresso'),
329
+							$payment_method_name
330
+						)
331
+						. '</span>';
332
+		}
333
+		return $content;
334
+	}
335
+
336
+
337
+	/**
338
+	 *    column_ATT_fname
339
+	 *
340
+	 * @param \EE_Transaction $transaction
341
+	 * @return string
342
+	 * @throws EE_Error
343
+	 * @throws InvalidArgumentException
344
+	 * @throws InvalidDataTypeException
345
+	 * @throws InvalidInterfaceException
346
+	 */
347
+	public function column_ATT_fname(EE_Transaction $transaction)
348
+	{
349
+		$primary_reg = $transaction->primary_registration();
350
+		$attendee = $primary_reg->get_first_related('Attendee');
351
+		if ($attendee instanceof EE_Attendee) {
352
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
353
+				array(
354
+					'action'  => 'view_registration',
355
+					'_REG_ID' => $primary_reg->ID(),
356
+				),
357
+				REG_ADMIN_URL
358
+			);
359
+			$content = EE_Registry::instance()->CAP->current_user_can(
360
+				'ee_read_registration',
361
+				'espresso_registrations_view_registration',
362
+				$primary_reg->ID()
363
+			)
364
+				? '<a href="' . $edit_lnk_url . '"'
365
+				  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
366
+				  . $attendee->full_name()
367
+				  . '</a>'
368
+				: $attendee->full_name();
369
+			$content .= '<br>' . $attendee->email();
370
+			return $content;
371
+		}
372
+		return $transaction->failed() || $transaction->is_abandoned()
373
+			? esc_html__('no contact record.', 'event_espresso')
374
+			: esc_html__(
375
+				'No contact record, because the transaction was abandoned or the registration process failed.',
376
+				'event_espresso'
377
+			);
378
+	}
379
+
380
+
381
+	/**
382
+	 *    column_ATT_email
383
+	 *
384
+	 * @param \EE_Transaction $transaction
385
+	 * @return string
386
+	 * @throws \EE_Error
387
+	 */
388
+	public function column_ATT_email(EE_Transaction $transaction)
389
+	{
390
+		$attendee = $transaction->primary_registration()->get_first_related('Attendee');
391
+		if (! empty($attendee)) {
392
+			return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
393
+				   . $attendee->get('ATT_email')
394
+				   . '</a>';
395
+		} else {
396
+			return $transaction->failed() || $transaction->is_abandoned()
397
+				? esc_html__('no contact record.', 'event_espresso')
398
+				: esc_html__(
399
+					'No contact record, because the transaction was abandoned or the registration process failed.',
400
+					'event_espresso'
401
+				);
402
+		}
403
+	}
404
+
405
+
406
+	/**
407
+	 *    column_event_name
408
+	 *
409
+	 * @param \EE_Transaction $transaction
410
+	 * @return string
411
+	 * @throws EE_Error
412
+	 * @throws InvalidArgumentException
413
+	 * @throws InvalidDataTypeException
414
+	 * @throws InvalidInterfaceException
415
+	 */
416
+	public function column_event_name(EE_Transaction $transaction)
417
+	{
418
+		$actions = array();
419
+		$event = $transaction->primary_registration()->get_first_related('Event');
420
+		if (! empty($event)) {
421
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
422
+				array('action' => 'edit', 'post' => $event->ID()),
423
+				EVENTS_ADMIN_URL
424
+			);
425
+			$event_name = $event->get('EVT_name');
426
+
427
+			// filter this view by transactions for this event
428
+			$txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
429
+				array(
430
+					'action' => 'default',
431
+					'EVT_ID' => $event->ID(),
432
+				)
433
+			);
434
+			if (
435
+				empty($this->_req_data['EVT_ID'])
436
+				&& EE_Registry::instance()->CAP->current_user_can(
437
+					'ee_edit_event',
438
+					'espresso_events_edit',
439
+					$event->ID()
440
+				)
441
+			) {
442
+				$actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
443
+											  . ' title="' . esc_attr__(
444
+												  'Filter transactions by this event',
445
+												  'event_espresso'
446
+											  ) . '">'
447
+											  . esc_html__('View Transactions for this event', 'event_espresso')
448
+											  . '</a>';
449
+			}
450
+
451
+			return sprintf(
452
+				'%1$s %2$s',
453
+				EE_Registry::instance()->CAP->current_user_can(
454
+					'ee_edit_event',
455
+					'espresso_events_edit',
456
+					$event->ID()
457
+				)
458
+					? '<a href="' . $edit_event_url . '"'
459
+					  . ' title="'
460
+					  . sprintf(
461
+						  esc_attr__('Edit Event: %s', 'event_espresso'),
462
+						  $event->get('EVT_name')
463
+					  )
464
+					  . '">'
465
+					  . wp_trim_words(
466
+						  $event_name,
467
+						  30,
468
+						  '...'
469
+					  )
470
+					  . '</a>'
471
+					: wp_trim_words($event_name, 30, '...'),
472
+				$this->row_actions($actions)
473
+			);
474
+		} else {
475
+			return esc_html__(
476
+				'The event associated with this transaction via the primary registration cannot be retrieved.',
477
+				'event_espresso'
478
+			);
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 *    column_actions
485
+	 *
486
+	 * @param \EE_Transaction $transaction
487
+	 * @return string
488
+	 * @throws \EE_Error
489
+	 */
490
+	public function column_actions(EE_Transaction $transaction)
491
+	{
492
+		return $this->_action_string(
493
+			$this->get_transaction_details_link($transaction)
494
+			. $this->get_invoice_link($transaction)
495
+			. $this->get_receipt_link($transaction)
496
+			. $this->get_primary_registration_details_link($transaction)
497
+			. $this->get_send_payment_reminder_trigger_link($transaction)
498
+			. $this->get_payment_overview_link($transaction)
499
+			. $this->get_related_messages_link($transaction),
500
+			$transaction,
501
+			'ul',
502
+			'txn-overview-actions-ul'
503
+		);
504
+	}
505
+
506
+
507
+	/**
508
+	 * Get the transaction details link.
509
+	 *
510
+	 * @param EE_Transaction $transaction
511
+	 * @return string
512
+	 * @throws EE_Error
513
+	 */
514
+	protected function get_transaction_details_link(EE_Transaction $transaction)
515
+	{
516
+		$url = EE_Admin_Page::add_query_args_and_nonce(
517
+			array(
518
+				'action' => 'view_transaction',
519
+				'TXN_ID' => $transaction->ID(),
520
+			),
521
+			TXN_ADMIN_URL
522
+		);
523
+		return '
524 524
 			<li>
525 525
 				<a href="' . $url . '"'
526
-               . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
526
+			   . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
527 527
 					<span class="dashicons dashicons-cart"></span>
528 528
 				</a>
529 529
 			</li>';
530
-    }
531
-
532
-
533
-    /**
534
-     * Get the invoice link for the given registration.
535
-     *
536
-     * @param EE_Transaction $transaction
537
-     * @return string
538
-     * @throws EE_Error
539
-     */
540
-    protected function get_invoice_link(EE_Transaction $transaction)
541
-    {
542
-        $registration = $transaction->primary_registration();
543
-        if ($registration instanceof EE_Registration) {
544
-            $url = $registration->invoice_url();
545
-            // only show invoice link if message type is active.
546
-            if (
547
-                $registration->attendee() instanceof EE_Attendee
548
-                && EEH_MSG_Template::is_mt_active('invoice')
549
-            ) {
550
-                return '
530
+	}
531
+
532
+
533
+	/**
534
+	 * Get the invoice link for the given registration.
535
+	 *
536
+	 * @param EE_Transaction $transaction
537
+	 * @return string
538
+	 * @throws EE_Error
539
+	 */
540
+	protected function get_invoice_link(EE_Transaction $transaction)
541
+	{
542
+		$registration = $transaction->primary_registration();
543
+		if ($registration instanceof EE_Registration) {
544
+			$url = $registration->invoice_url();
545
+			// only show invoice link if message type is active.
546
+			if (
547
+				$registration->attendee() instanceof EE_Attendee
548
+				&& EEH_MSG_Template::is_mt_active('invoice')
549
+			) {
550
+				return '
551 551
                 <li>
552 552
                     <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
553
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
553
+					   . ' target="_blank" href="' . $url . '" class="tiny-text">
554 554
                         <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
555 555
                     </a>
556 556
                 </li>';
557
-            }
558
-        }
559
-        return '';
560
-    }
561
-
562
-
563
-    /**
564
-     * Get the receipt link for the transaction.
565
-     *
566
-     * @param EE_Transaction $transaction
567
-     * @return string
568
-     * @throws EE_Error
569
-     */
570
-    protected function get_receipt_link(EE_Transaction $transaction)
571
-    {
572
-        $registration = $transaction->primary_registration();
573
-        if ($registration instanceof EE_Registration) {
574
-            $url = $registration->receipt_url();
575
-            // only show receipt link if message type is active.
576
-            if (
577
-                $registration->attendee() instanceof EE_Attendee
578
-                && EEH_MSG_Template::is_mt_active('receipt')
579
-            ) {
580
-                return '
557
+			}
558
+		}
559
+		return '';
560
+	}
561
+
562
+
563
+	/**
564
+	 * Get the receipt link for the transaction.
565
+	 *
566
+	 * @param EE_Transaction $transaction
567
+	 * @return string
568
+	 * @throws EE_Error
569
+	 */
570
+	protected function get_receipt_link(EE_Transaction $transaction)
571
+	{
572
+		$registration = $transaction->primary_registration();
573
+		if ($registration instanceof EE_Registration) {
574
+			$url = $registration->receipt_url();
575
+			// only show receipt link if message type is active.
576
+			if (
577
+				$registration->attendee() instanceof EE_Attendee
578
+				&& EEH_MSG_Template::is_mt_active('receipt')
579
+			) {
580
+				return '
581 581
 			<li>
582 582
 				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
583
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
583
+					   . ' target="_blank" href="' . $url . '" class="tiny-text">
584 584
 					<span class="dashicons dashicons-media-default ee-icon-size-18"></span>
585 585
 				</a>
586 586
 			</li>';
587
-            }
588
-        }
589
-        return '';
590
-    }
591
-
592
-
593
-    /**
594
-     * Get the link to view the details for the primary registration.
595
-     *
596
-     * @param EE_Transaction $transaction
597
-     * @return string
598
-     * @throws EE_Error
599
-     * @throws InvalidArgumentException
600
-     * @throws InvalidDataTypeException
601
-     * @throws InvalidInterfaceException
602
-     */
603
-    protected function get_primary_registration_details_link(EE_Transaction $transaction)
604
-    {
605
-        $registration = $transaction->primary_registration();
606
-        if ($registration instanceof EE_Registration) {
607
-            $url = EE_Admin_Page::add_query_args_and_nonce(
608
-                array(
609
-                    'action'  => 'view_registration',
610
-                    '_REG_ID' => $registration->ID(),
611
-                ),
612
-                REG_ADMIN_URL
613
-            );
614
-            return EE_Registry::instance()->CAP->current_user_can(
615
-                'ee_read_registration',
616
-                'espresso_registrations_view_registration',
617
-                $registration->ID()
618
-            )
619
-                ? '
587
+			}
588
+		}
589
+		return '';
590
+	}
591
+
592
+
593
+	/**
594
+	 * Get the link to view the details for the primary registration.
595
+	 *
596
+	 * @param EE_Transaction $transaction
597
+	 * @return string
598
+	 * @throws EE_Error
599
+	 * @throws InvalidArgumentException
600
+	 * @throws InvalidDataTypeException
601
+	 * @throws InvalidInterfaceException
602
+	 */
603
+	protected function get_primary_registration_details_link(EE_Transaction $transaction)
604
+	{
605
+		$registration = $transaction->primary_registration();
606
+		if ($registration instanceof EE_Registration) {
607
+			$url = EE_Admin_Page::add_query_args_and_nonce(
608
+				array(
609
+					'action'  => 'view_registration',
610
+					'_REG_ID' => $registration->ID(),
611
+				),
612
+				REG_ADMIN_URL
613
+			);
614
+			return EE_Registry::instance()->CAP->current_user_can(
615
+				'ee_read_registration',
616
+				'espresso_registrations_view_registration',
617
+				$registration->ID()
618
+			)
619
+				? '
620 620
 				<li>
621 621
 					<a href="' . $url . '"'
622
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
622
+				  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
623 623
 						<span class="dashicons dashicons-clipboard"></span>
624 624
 					</a>
625 625
 				</li>'
626
-                : '';
627
-        }
628
-        return '';
629
-    }
630
-
631
-
632
-    /**
633
-     * Get send payment reminder trigger link
634
-     *
635
-     * @param EE_Transaction $transaction
636
-     * @return string
637
-     * @throws EE_Error
638
-     * @throws InvalidArgumentException
639
-     * @throws InvalidDataTypeException
640
-     * @throws InvalidInterfaceException
641
-     */
642
-    protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
643
-    {
644
-        $registration = $transaction->primary_registration();
645
-        if (
646
-            $registration instanceof EE_Registration
647
-            && $registration->attendee() instanceof EE_Attendee
648
-            && EEH_MSG_Template::is_mt_active('payment_reminder')
649
-            && ! in_array(
650
-                $transaction->status_ID(),
651
-                array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
652
-                true
653
-            )
654
-            && EE_Registry::instance()->CAP->current_user_can(
655
-                'ee_send_message',
656
-                'espresso_transactions_send_payment_reminder'
657
-            )
658
-        ) {
659
-            $url = EE_Admin_Page::add_query_args_and_nonce(
660
-                array(
661
-                    'action' => 'send_payment_reminder',
662
-                    'TXN_ID' => $transaction->ID(),
663
-                ),
664
-                TXN_ADMIN_URL
665
-            );
666
-            return '
626
+				: '';
627
+		}
628
+		return '';
629
+	}
630
+
631
+
632
+	/**
633
+	 * Get send payment reminder trigger link
634
+	 *
635
+	 * @param EE_Transaction $transaction
636
+	 * @return string
637
+	 * @throws EE_Error
638
+	 * @throws InvalidArgumentException
639
+	 * @throws InvalidDataTypeException
640
+	 * @throws InvalidInterfaceException
641
+	 */
642
+	protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
643
+	{
644
+		$registration = $transaction->primary_registration();
645
+		if (
646
+			$registration instanceof EE_Registration
647
+			&& $registration->attendee() instanceof EE_Attendee
648
+			&& EEH_MSG_Template::is_mt_active('payment_reminder')
649
+			&& ! in_array(
650
+				$transaction->status_ID(),
651
+				array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
652
+				true
653
+			)
654
+			&& EE_Registry::instance()->CAP->current_user_can(
655
+				'ee_send_message',
656
+				'espresso_transactions_send_payment_reminder'
657
+			)
658
+		) {
659
+			$url = EE_Admin_Page::add_query_args_and_nonce(
660
+				array(
661
+					'action' => 'send_payment_reminder',
662
+					'TXN_ID' => $transaction->ID(),
663
+				),
664
+				TXN_ADMIN_URL
665
+			);
666
+			return '
667 667
             <li>
668 668
                 <a href="' . $url . '"'
669
-                   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
669
+				   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
670 670
                     <span class="dashicons dashicons-email-alt"></span>
671 671
                 </a>
672 672
             </li>';
673
-        }
674
-        return '';
675
-    }
676
-
677
-
678
-    /**
679
-     * Get link to filtered view in the message activity list table of messages for this transaction.
680
-     *
681
-     * @param EE_Transaction $transaction
682
-     * @return string
683
-     * @throws EE_Error
684
-     * @throws InvalidArgumentException
685
-     * @throws InvalidDataTypeException
686
-     * @throws InvalidInterfaceException
687
-     */
688
-    protected function get_related_messages_link(EE_Transaction $transaction)
689
-    {
690
-        $url = EEH_MSG_Template::get_message_action_link(
691
-            'see_notifications_for',
692
-            null,
693
-            array('TXN_ID' => $transaction->ID())
694
-        );
695
-        return EE_Registry::instance()->CAP->current_user_can(
696
-            'ee_read_global_messages',
697
-            'view_filtered_messages'
698
-        )
699
-            ? '<li>' . $url . '</li>'
700
-            : '';
701
-    }
702
-
703
-
704
-    /**
705
-     * Return the link to make a payment on the frontend
706
-     *
707
-     * @param EE_Transaction $transaction
708
-     * @return string
709
-     * @throws EE_Error
710
-     */
711
-    protected function get_payment_overview_link(EE_Transaction $transaction)
712
-    {
713
-        $registration = $transaction->primary_registration();
714
-        if (
715
-            $registration instanceof EE_Registration
716
-            && $transaction->status_ID() !== EEM_Transaction::complete_status_code
717
-            && $registration->owes_monies_and_can_pay()
718
-        ) {
719
-            return '
673
+		}
674
+		return '';
675
+	}
676
+
677
+
678
+	/**
679
+	 * Get link to filtered view in the message activity list table of messages for this transaction.
680
+	 *
681
+	 * @param EE_Transaction $transaction
682
+	 * @return string
683
+	 * @throws EE_Error
684
+	 * @throws InvalidArgumentException
685
+	 * @throws InvalidDataTypeException
686
+	 * @throws InvalidInterfaceException
687
+	 */
688
+	protected function get_related_messages_link(EE_Transaction $transaction)
689
+	{
690
+		$url = EEH_MSG_Template::get_message_action_link(
691
+			'see_notifications_for',
692
+			null,
693
+			array('TXN_ID' => $transaction->ID())
694
+		);
695
+		return EE_Registry::instance()->CAP->current_user_can(
696
+			'ee_read_global_messages',
697
+			'view_filtered_messages'
698
+		)
699
+			? '<li>' . $url . '</li>'
700
+			: '';
701
+	}
702
+
703
+
704
+	/**
705
+	 * Return the link to make a payment on the frontend
706
+	 *
707
+	 * @param EE_Transaction $transaction
708
+	 * @return string
709
+	 * @throws EE_Error
710
+	 */
711
+	protected function get_payment_overview_link(EE_Transaction $transaction)
712
+	{
713
+		$registration = $transaction->primary_registration();
714
+		if (
715
+			$registration instanceof EE_Registration
716
+			&& $transaction->status_ID() !== EEM_Transaction::complete_status_code
717
+			&& $registration->owes_monies_and_can_pay()
718
+		) {
719
+			return '
720 720
             <li>
721 721
                 <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
722
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
723
-                   . ' class="tiny-text">
722
+				   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
723
+				   . ' class="tiny-text">
724 724
                     <span class="dashicons dashicons-money ee-icon-size-18"></span>
725 725
                 </a>
726 726
             </li>
727 727
             ';
728
-        }
729
-        return '';
730
-    }
728
+		}
729
+		return '';
730
+	}
731 731
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_List_Table.class.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $class = parent::_get_row_class($item);
115 115
         // add status class
116 116
         $class .= $item instanceof EE_Event
117
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
117
+            ? ' ee-status-strip event-status-'.$item->get_active_status()
118 118
             : '';
119 119
         if ($this->_has_checkbox_column) {
120 120
             $class .= ' has-checkbox-column';
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function column_cb($item)
145 145
     {
146
-        if (! $item instanceof EE_Event) {
146
+        if ( ! $item instanceof EE_Event) {
147 147
             return '';
148 148
         }
149 149
         $this->_dtt = $item->primary_datetime(); // set this for use in other columns
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     public function column_id(EE_Event $item)
167 167
     {
168 168
         $content = $item->ID();
169
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
169
+        $content .= '  <span class="show-on-mobile-view-only">'.$item->name().'</span>';
170 170
         return $content;
171 171
     }
172 172
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         $actions = $this->_column_name_action_setup($item);
190 190
         $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
191 191
         $content = '<strong><a class="row-title" href="'
192
-                   . $edit_link . '">'
192
+                   . $edit_link.'">'
193 193
                    . $item->name()
194 194
                    . '</a></strong>'
195 195
                    . $status;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
     protected function _column_name_action_setup(EE_Event $item)
219 219
     {
220 220
         // todo: remove when attendees is active
221
-        if (! defined('REG_ADMIN_URL')) {
221
+        if ( ! defined('REG_ADMIN_URL')) {
222 222
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
223 223
         }
224 224
         $actions = array();
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
                 'post'   => $item->ID(),
238 238
             );
239 239
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
240
-            $actions['edit'] = '<a href="' . $edit_link . '"'
241
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
240
+            $actions['edit'] = '<a href="'.$edit_link.'"'
241
+                               . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
242 242
                                . esc_html__('Edit', 'event_espresso')
243 243
                                . '</a>';
244 244
         }
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
                 'event_id' => $item->ID(),
259 259
             );
260 260
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
261
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
262
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
261
+            $actions['attendees'] = '<a href="'.$attendees_link.'"'
262
+                                    . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">'
263 263
                                     . esc_html__('Registrations', 'event_espresso')
264 264
                                     . '</a>';
265 265
         }
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
             );
313 313
         }
314 314
         $view_link = get_permalink($item->ID());
315
-        $actions['view'] = '<a href="' . $view_link . '"'
316
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
315
+        $actions['view'] = '<a href="'.$view_link.'"'
316
+                           . ' title="'.esc_attr__('View Event', 'event_espresso').'">'
317 317
                            . esc_html__('View', 'event_espresso')
318 318
                            . '</a>';
319 319
         if ($item->get('status') === 'trash') {
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     $item->ID()
325 325
                 )
326 326
             ) {
327
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
328
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
327
+                $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"'
328
+                                                 . ' title="'.esc_attr__('Restore from Trash', 'event_espresso')
329 329
                                                  . '">'
330 330
                                                  . esc_html__('Restore from Trash', 'event_espresso')
331 331
                                                  . '</a>';
@@ -338,8 +338,8 @@  discard block
 block discarded – undo
338 338
                     $item->ID()
339 339
                 )
340 340
             ) {
341
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
342
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
341
+                $actions['delete'] = '<a href="'.$delete_event_link.'"'
342
+                                     . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">'
343 343
                                      . esc_html__('Delete Permanently', 'event_espresso')
344 344
                                      . '</a>';
345 345
             }
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
                     $item->ID()
352 352
                 )
353 353
             ) {
354
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
355
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
354
+                $actions['move to trash'] = '<a href="'.$trash_event_link.'"'
355
+                                            . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">'
356 356
                                             . esc_html__('Trash', 'event_espresso')
357 357
                                             . '</a>';
358 358
             }
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
             'EVT_wp_user' => $item->wp_user(),
378 378
         );
379 379
         $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
380
-        return $gravatar . '  <a href="' . $filter_url . '"'
381
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
380
+        return $gravatar.'  <a href="'.$filter_url.'"'
381
+               . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">'
382 382
                . $event_author->display_name
383 383
                . '</a>';
384 384
     }
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
         return implode(
396 396
             ', ',
397 397
             array_map(
398
-                function (EE_Term $category) {
398
+                function(EE_Term $category) {
399 399
                     return $category->name();
400 400
                 },
401 401
                 $event_categories
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
                    'ee_read_registrations',
471 471
                    'espresso_registrations_view_registration'
472 472
                )
473
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
473
+            ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>'
474 474
             : $registered_attendees;
475 475
     }
476 476
 
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
     public function column_actions(EE_Event $item)
501 501
     {
502 502
         // todo: remove when attendees is active
503
-        if (! defined('REG_ADMIN_URL')) {
503
+        if ( ! defined('REG_ADMIN_URL')) {
504 504
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
505 505
         }
506 506
         $action_links = array();
507 507
         $view_link = get_permalink($item->ID());
508
-        $action_links[] = '<a href="' . $view_link . '"'
509
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
508
+        $action_links[] = '<a href="'.$view_link.'"'
509
+                          . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">';
510 510
         $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
511 511
         if (
512 512
             EE_Registry::instance()->CAP->current_user_can(
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
                 'post'   => $item->ID(),
521 521
             );
522 522
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
523
-            $action_links[] = '<a href="' . $edit_link . '"'
524
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
523
+            $action_links[] = '<a href="'.$edit_link.'"'
524
+                              . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
525 525
                               . '<div class="ee-icon ee-icon-calendar-edit"></div>'
526 526
                               . '</a>';
527 527
         }
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
                 'event_id' => $item->ID(),
541 541
             );
542 542
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
543
-            $action_links[] = '<a href="' . $attendees_link . '"'
544
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
543
+            $action_links[] = '<a href="'.$attendees_link.'"'
544
+                              . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">'
545 545
                               . '<div class="dashicons dashicons-groups"></div>'
546 546
                               . '</a>';
547 547
         }
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
         }
577 577
         $column_array = [];
578 578
         foreach ($this->_columns as $column => $column_label) {
579
-            $column_array[ $column ] = $column_label;
579
+            $column_array[$column] = $column_label;
580 580
             if ($column === 'venue') {
581 581
                 $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
582 582
             }
Please login to merge, or discard this patch.
Indentation   +563 added lines, -563 removed lines patch added patch discarded remove patch
@@ -15,567 +15,567 @@
 block discarded – undo
15 15
 class Events_Admin_List_Table extends EE_Admin_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Datetime
20
-     */
21
-    private $_dtt;
22
-
23
-
24
-    /**
25
-     * Initial setup of data properties for the list table.
26
-     */
27
-    protected function _setup_data()
28
-    {
29
-        $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
-        $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * Set up of additional properties for the list table.
36
-     */
37
-    protected function _set_properties()
38
-    {
39
-        $this->_wp_list_args = array(
40
-            'singular' => esc_html__('event', 'event_espresso'),
41
-            'plural'   => esc_html__('events', 'event_espresso'),
42
-            'ajax'     => true, // for now
43
-            'screen'   => $this->_admin_page->get_current_screen()->id,
44
-        );
45
-        $this->_columns = array(
46
-            'cb'              => '<input type="checkbox" />',
47
-            'id'              => esc_html__('ID', 'event_espresso'),
48
-            'name'            => esc_html__('Name', 'event_espresso'),
49
-            'author'          => esc_html__('Author', 'event_espresso'),
50
-            'venue'           => esc_html__('Venue', 'event_espresso'),
51
-            'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
-            'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
-            'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
-                                 . '<span class="screen-reader-text">'
55
-                                 . esc_html__('Approved Registrations', 'event_espresso')
56
-                                 . '</span>'
57
-                                 . '</span>',
58
-            // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
-            'actions'         => esc_html__('Actions', 'event_espresso'),
60
-        );
61
-        $this->addConditionalColumns();
62
-        $this->_sortable_columns = array(
63
-            'id'              => array('EVT_ID' => true),
64
-            'name'            => array('EVT_name' => false),
65
-            'author'          => array('EVT_wp_user' => false),
66
-            'venue'           => array('Venue.VNU_name' => false),
67
-            'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
-            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
-        );
70
-
71
-        $this->_primary_column = 'id';
72
-        $this->_hidden_columns = array('author', 'event_category');
73
-    }
74
-
75
-
76
-    /**
77
-     * @return array
78
-     */
79
-    protected function _get_table_filters()
80
-    {
81
-        return array(); // no filters with decaf
82
-    }
83
-
84
-
85
-    /**
86
-     * Setup of views properties.
87
-     *
88
-     * @throws InvalidDataTypeException
89
-     * @throws InvalidInterfaceException
90
-     * @throws InvalidArgumentException
91
-     */
92
-    protected function _add_view_counts()
93
-    {
94
-        $this->_views['all']['count'] = $this->_admin_page->total_events();
95
-        $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
-        if (
97
-            EE_Registry::instance()->CAP->current_user_can(
98
-                'ee_delete_events',
99
-                'espresso_events_trash_events'
100
-            )
101
-        ) {
102
-            $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
103
-        }
104
-    }
105
-
106
-
107
-    /**
108
-     * @param EE_Event $item
109
-     * @return string
110
-     * @throws EE_Error
111
-     */
112
-    protected function _get_row_class($item)
113
-    {
114
-        $class = parent::_get_row_class($item);
115
-        // add status class
116
-        $class .= $item instanceof EE_Event
117
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
118
-            : '';
119
-        if ($this->_has_checkbox_column) {
120
-            $class .= ' has-checkbox-column';
121
-        }
122
-        return $class;
123
-    }
124
-
125
-
126
-    /**
127
-     * @param EE_Event $item
128
-     * @return string
129
-     * @throws EE_Error
130
-     */
131
-    public function column_status(EE_Event $item)
132
-    {
133
-        return '<span class="ee-status-strip ee-status-strip-td event-status-'
134
-               . $item->get_active_status()
135
-               . '"></span>';
136
-    }
137
-
138
-
139
-    /**
140
-     * @param  EE_Event $item
141
-     * @return string
142
-     * @throws EE_Error
143
-     */
144
-    public function column_cb($item)
145
-    {
146
-        if (! $item instanceof EE_Event) {
147
-            return '';
148
-        }
149
-        $this->_dtt = $item->primary_datetime(); // set this for use in other columns
150
-        return sprintf(
151
-            '<input type="checkbox" name="EVT_IDs[]" value="%s" />',
152
-            $item->ID()
153
-        );
154
-    }
155
-
156
-
157
-    /**
158
-     * @param EE_Event $item
159
-     * @return mixed|string
160
-     * @throws EE_Error
161
-     */
162
-    public function column_id(EE_Event $item)
163
-    {
164
-        $content = $item->ID();
165
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
166
-        return $content;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param EE_Event $item
172
-     * @return string
173
-     * @throws EE_Error
174
-     * @throws InvalidArgumentException
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     */
178
-    public function column_name(EE_Event $item)
179
-    {
180
-        $edit_query_args = array(
181
-            'action' => 'edit',
182
-            'post'   => $item->ID(),
183
-        );
184
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
185
-        $actions = $this->_column_name_action_setup($item);
186
-        $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
187
-        $content = '<strong><a class="row-title" href="'
188
-                   . $edit_link . '">'
189
-                   . $item->name()
190
-                   . '</a></strong>'
191
-                   . $status;
192
-        $content .= '<br><span class="ee-status-text-small">'
193
-                    . EEH_Template::pretty_status(
194
-                        $item->get_active_status(),
195
-                        false,
196
-                        'sentence'
197
-                    )
198
-                    . '</span>';
199
-        $content .= $this->row_actions($actions);
200
-        return $content;
201
-    }
202
-
203
-
204
-    /**
205
-     * Just a method for setting up the actions for the name column
206
-     *
207
-     * @param EE_Event $item
208
-     * @return array array of actions
209
-     * @throws EE_Error
210
-     * @throws InvalidArgumentException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidInterfaceException
213
-     */
214
-    protected function _column_name_action_setup(EE_Event $item)
215
-    {
216
-        // todo: remove when attendees is active
217
-        if (! defined('REG_ADMIN_URL')) {
218
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
219
-        }
220
-        $actions = array();
221
-        $restore_event_link = '';
222
-        $delete_event_link = '';
223
-        $trash_event_link = '';
224
-        if (
225
-            EE_Registry::instance()->CAP->current_user_can(
226
-                'ee_edit_event',
227
-                'espresso_events_edit',
228
-                $item->ID()
229
-            )
230
-        ) {
231
-            $edit_query_args = array(
232
-                'action' => 'edit',
233
-                'post'   => $item->ID(),
234
-            );
235
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
-            $actions['edit'] = '<a href="' . $edit_link . '"'
237
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
238
-                               . esc_html__('Edit', 'event_espresso')
239
-                               . '</a>';
240
-        }
241
-        if (
242
-            EE_Registry::instance()->CAP->current_user_can(
243
-                'ee_read_registrations',
244
-                'espresso_registrations_view_registration'
245
-            )
246
-            && EE_Registry::instance()->CAP->current_user_can(
247
-                'ee_read_event',
248
-                'espresso_registrations_view_registration',
249
-                $item->ID()
250
-            )
251
-        ) {
252
-            $attendees_query_args = array(
253
-                'action'   => 'default',
254
-                'event_id' => $item->ID(),
255
-            );
256
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
257
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
258
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
259
-                                    . esc_html__('Registrations', 'event_espresso')
260
-                                    . '</a>';
261
-        }
262
-        if (
263
-            EE_Registry::instance()->CAP->current_user_can(
264
-                'ee_delete_event',
265
-                'espresso_events_trash_event',
266
-                $item->ID()
267
-            )
268
-        ) {
269
-            $trash_event_query_args = array(
270
-                'action' => 'trash_event',
271
-                'EVT_ID' => $item->ID(),
272
-            );
273
-            $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
274
-                $trash_event_query_args,
275
-                EVENTS_ADMIN_URL
276
-            );
277
-        }
278
-        if (
279
-            EE_Registry::instance()->CAP->current_user_can(
280
-                'ee_delete_event',
281
-                'espresso_events_restore_event',
282
-                $item->ID()
283
-            )
284
-        ) {
285
-            $restore_event_query_args = array(
286
-                'action' => 'restore_event',
287
-                'EVT_ID' => $item->ID(),
288
-            );
289
-            $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
290
-                $restore_event_query_args,
291
-                EVENTS_ADMIN_URL
292
-            );
293
-        }
294
-        if (
295
-            EE_Registry::instance()->CAP->current_user_can(
296
-                'ee_delete_event',
297
-                'espresso_events_delete_event',
298
-                $item->ID()
299
-            )
300
-        ) {
301
-            $delete_event_query_args = array(
302
-                'action' => 'delete_event',
303
-                'EVT_ID' => $item->ID(),
304
-            );
305
-            $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
306
-                $delete_event_query_args,
307
-                EVENTS_ADMIN_URL
308
-            );
309
-        }
310
-        $view_link = get_permalink($item->ID());
311
-        $actions['view'] = '<a href="' . $view_link . '"'
312
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
313
-                           . esc_html__('View', 'event_espresso')
314
-                           . '</a>';
315
-        if ($item->get('status') === 'trash') {
316
-            if (
317
-                EE_Registry::instance()->CAP->current_user_can(
318
-                    'ee_delete_event',
319
-                    'espresso_events_restore_event',
320
-                    $item->ID()
321
-                )
322
-            ) {
323
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
324
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
325
-                                                 . '">'
326
-                                                 . esc_html__('Restore from Trash', 'event_espresso')
327
-                                                 . '</a>';
328
-            }
329
-            if (
330
-                EE_Registry::instance()->CAP->current_user_can(
331
-                    'ee_delete_event',
332
-                    'espresso_events_delete_event',
333
-                    $item->ID()
334
-                )
335
-            ) {
336
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
337
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
338
-                                     . esc_html__('Delete Permanently', 'event_espresso')
339
-                                     . '</a>';
340
-            }
341
-        } else {
342
-            if (
343
-                EE_Registry::instance()->CAP->current_user_can(
344
-                    'ee_delete_event',
345
-                    'espresso_events_trash_event',
346
-                    $item->ID()
347
-                )
348
-            ) {
349
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
350
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
351
-                                            . esc_html__('Trash', 'event_espresso')
352
-                                            . '</a>';
353
-            }
354
-        }
355
-        return $actions;
356
-    }
357
-
358
-
359
-    /**
360
-     * @param EE_Event $item
361
-     * @return string
362
-     * @throws EE_Error
363
-     */
364
-    public function column_author(EE_Event $item)
365
-    {
366
-        // user author info
367
-        $event_author = get_userdata($item->wp_user());
368
-        $gravatar = get_avatar($item->wp_user(), '15');
369
-        // filter link
370
-        $query_args = array(
371
-            'action'      => 'default',
372
-            'EVT_wp_user' => $item->wp_user(),
373
-        );
374
-        $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
375
-        return $gravatar . '  <a href="' . $filter_url . '"'
376
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
377
-               . $event_author->display_name
378
-               . '</a>';
379
-    }
380
-
381
-
382
-    /**
383
-     * @param EE_Event $event
384
-     * @return string
385
-     * @throws EE_Error
386
-     */
387
-    public function column_event_category(EE_Event $event)
388
-    {
389
-        $event_categories = $event->get_all_event_categories();
390
-        return implode(
391
-            ', ',
392
-            array_map(
393
-                function (EE_Term $category) {
394
-                    return $category->name();
395
-                },
396
-                $event_categories
397
-            )
398
-        );
399
-    }
400
-
401
-
402
-    /**
403
-     * @param EE_Event $item
404
-     * @return string
405
-     * @throws EE_Error
406
-     */
407
-    public function column_venue(EE_Event $item)
408
-    {
409
-        $venue = $item->get_first_related('Venue');
410
-        return ! empty($venue)
411
-            ? $venue->name()
412
-            : '';
413
-    }
414
-
415
-
416
-    /**
417
-     * @param EE_Event $item
418
-     * @return string
419
-     * @throws EE_Error
420
-     */
421
-    public function column_start_date_time(EE_Event $item)
422
-    {
423
-        return $this->_dtt instanceof EE_Datetime
424
-            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
425
-            : esc_html__('No Date was saved for this Event', 'event_espresso');
426
-    }
427
-
428
-
429
-    /**
430
-     * @param EE_Event $item
431
-     * @return string
432
-     * @throws EE_Error
433
-     */
434
-    public function column_reg_begins(EE_Event $item)
435
-    {
436
-        $reg_start = $item->get_ticket_with_earliest_start_time();
437
-        return $reg_start instanceof EE_Ticket
438
-            ? $reg_start->get_i18n_datetime('TKT_start_date')
439
-            : esc_html__('No Tickets have been setup for this Event', 'event_espresso');
440
-    }
441
-
442
-
443
-    /**
444
-     * @param EE_Event $item
445
-     * @return int|string
446
-     * @throws EE_Error
447
-     * @throws InvalidArgumentException
448
-     * @throws InvalidDataTypeException
449
-     * @throws InvalidInterfaceException
450
-     */
451
-    public function column_attendees(EE_Event $item)
452
-    {
453
-        $attendees_query_args = array(
454
-            'action'   => 'default',
455
-            'event_id' => $item->ID(),
456
-        );
457
-        $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
458
-        $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
459
-        return EE_Registry::instance()->CAP->current_user_can(
460
-            'ee_read_event',
461
-            'espresso_registrations_view_registration',
462
-            $item->ID()
463
-        )
464
-               && EE_Registry::instance()->CAP->current_user_can(
465
-                   'ee_read_registrations',
466
-                   'espresso_registrations_view_registration'
467
-               )
468
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
469
-            : $registered_attendees;
470
-    }
471
-
472
-
473
-    /**
474
-     * @param EE_Event $item
475
-     * @return float
476
-     * @throws EE_Error
477
-     * @throws InvalidArgumentException
478
-     * @throws InvalidDataTypeException
479
-     * @throws InvalidInterfaceException
480
-     */
481
-    public function column_tkts_sold(EE_Event $item)
482
-    {
483
-        return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
484
-    }
485
-
486
-
487
-    /**
488
-     * @param EE_Event $item
489
-     * @return string
490
-     * @throws EE_Error
491
-     * @throws InvalidArgumentException
492
-     * @throws InvalidDataTypeException
493
-     * @throws InvalidInterfaceException
494
-     */
495
-    public function column_actions(EE_Event $item)
496
-    {
497
-        // todo: remove when attendees is active
498
-        if (! defined('REG_ADMIN_URL')) {
499
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
500
-        }
501
-        $action_links = array();
502
-        $view_link = get_permalink($item->ID());
503
-        $action_links[] = '<a href="' . $view_link . '"'
504
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
505
-        $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
506
-        if (
507
-            EE_Registry::instance()->CAP->current_user_can(
508
-                'ee_edit_event',
509
-                'espresso_events_edit',
510
-                $item->ID()
511
-            )
512
-        ) {
513
-            $edit_query_args = array(
514
-                'action' => 'edit',
515
-                'post'   => $item->ID(),
516
-            );
517
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
518
-            $action_links[] = '<a href="' . $edit_link . '"'
519
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
520
-                              . '<div class="ee-icon ee-icon-calendar-edit"></div>'
521
-                              . '</a>';
522
-        }
523
-        if (
524
-            EE_Registry::instance()->CAP->current_user_can(
525
-                'ee_read_registrations',
526
-                'espresso_registrations_view_registration'
527
-            ) && EE_Registry::instance()->CAP->current_user_can(
528
-                'ee_read_event',
529
-                'espresso_registrations_view_registration',
530
-                $item->ID()
531
-            )
532
-        ) {
533
-            $attendees_query_args = array(
534
-                'action'   => 'default',
535
-                'event_id' => $item->ID(),
536
-            );
537
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
538
-            $action_links[] = '<a href="' . $attendees_link . '"'
539
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
540
-                              . '<div class="dashicons dashicons-groups"></div>'
541
-                              . '</a>';
542
-        }
543
-        $action_links = apply_filters(
544
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
545
-            $action_links,
546
-            $item
547
-        );
548
-        return $this->_action_string(
549
-            implode("\n\t", $action_links),
550
-            $item,
551
-            'div'
552
-        );
553
-    }
554
-
555
-
556
-    /**
557
-     * Helper for adding columns conditionally
558
-     *
559
-     * @throws EE_Error
560
-     * @throws InvalidArgumentException
561
-     * @throws InvalidDataTypeException
562
-     * @throws InvalidInterfaceException
563
-     */
564
-    private function addConditionalColumns()
565
-    {
566
-        $event_category_count = EEM_Term::instance()->count(
567
-            [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
568
-        );
569
-        if ($event_category_count === 0) {
570
-            return;
571
-        }
572
-        $column_array = [];
573
-        foreach ($this->_columns as $column => $column_label) {
574
-            $column_array[ $column ] = $column_label;
575
-            if ($column === 'venue') {
576
-                $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
577
-            }
578
-        }
579
-        $this->_columns = $column_array;
580
-    }
18
+	/**
19
+	 * @var EE_Datetime
20
+	 */
21
+	private $_dtt;
22
+
23
+
24
+	/**
25
+	 * Initial setup of data properties for the list table.
26
+	 */
27
+	protected function _setup_data()
28
+	{
29
+		$this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
+		$this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Set up of additional properties for the list table.
36
+	 */
37
+	protected function _set_properties()
38
+	{
39
+		$this->_wp_list_args = array(
40
+			'singular' => esc_html__('event', 'event_espresso'),
41
+			'plural'   => esc_html__('events', 'event_espresso'),
42
+			'ajax'     => true, // for now
43
+			'screen'   => $this->_admin_page->get_current_screen()->id,
44
+		);
45
+		$this->_columns = array(
46
+			'cb'              => '<input type="checkbox" />',
47
+			'id'              => esc_html__('ID', 'event_espresso'),
48
+			'name'            => esc_html__('Name', 'event_espresso'),
49
+			'author'          => esc_html__('Author', 'event_espresso'),
50
+			'venue'           => esc_html__('Venue', 'event_espresso'),
51
+			'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
+			'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
+			'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
+								 . '<span class="screen-reader-text">'
55
+								 . esc_html__('Approved Registrations', 'event_espresso')
56
+								 . '</span>'
57
+								 . '</span>',
58
+			// 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
+			'actions'         => esc_html__('Actions', 'event_espresso'),
60
+		);
61
+		$this->addConditionalColumns();
62
+		$this->_sortable_columns = array(
63
+			'id'              => array('EVT_ID' => true),
64
+			'name'            => array('EVT_name' => false),
65
+			'author'          => array('EVT_wp_user' => false),
66
+			'venue'           => array('Venue.VNU_name' => false),
67
+			'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
+			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
+		);
70
+
71
+		$this->_primary_column = 'id';
72
+		$this->_hidden_columns = array('author', 'event_category');
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return array
78
+	 */
79
+	protected function _get_table_filters()
80
+	{
81
+		return array(); // no filters with decaf
82
+	}
83
+
84
+
85
+	/**
86
+	 * Setup of views properties.
87
+	 *
88
+	 * @throws InvalidDataTypeException
89
+	 * @throws InvalidInterfaceException
90
+	 * @throws InvalidArgumentException
91
+	 */
92
+	protected function _add_view_counts()
93
+	{
94
+		$this->_views['all']['count'] = $this->_admin_page->total_events();
95
+		$this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
+		if (
97
+			EE_Registry::instance()->CAP->current_user_can(
98
+				'ee_delete_events',
99
+				'espresso_events_trash_events'
100
+			)
101
+		) {
102
+			$this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
103
+		}
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param EE_Event $item
109
+	 * @return string
110
+	 * @throws EE_Error
111
+	 */
112
+	protected function _get_row_class($item)
113
+	{
114
+		$class = parent::_get_row_class($item);
115
+		// add status class
116
+		$class .= $item instanceof EE_Event
117
+			? ' ee-status-strip event-status-' . $item->get_active_status()
118
+			: '';
119
+		if ($this->_has_checkbox_column) {
120
+			$class .= ' has-checkbox-column';
121
+		}
122
+		return $class;
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param EE_Event $item
128
+	 * @return string
129
+	 * @throws EE_Error
130
+	 */
131
+	public function column_status(EE_Event $item)
132
+	{
133
+		return '<span class="ee-status-strip ee-status-strip-td event-status-'
134
+			   . $item->get_active_status()
135
+			   . '"></span>';
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param  EE_Event $item
141
+	 * @return string
142
+	 * @throws EE_Error
143
+	 */
144
+	public function column_cb($item)
145
+	{
146
+		if (! $item instanceof EE_Event) {
147
+			return '';
148
+		}
149
+		$this->_dtt = $item->primary_datetime(); // set this for use in other columns
150
+		return sprintf(
151
+			'<input type="checkbox" name="EVT_IDs[]" value="%s" />',
152
+			$item->ID()
153
+		);
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param EE_Event $item
159
+	 * @return mixed|string
160
+	 * @throws EE_Error
161
+	 */
162
+	public function column_id(EE_Event $item)
163
+	{
164
+		$content = $item->ID();
165
+		$content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
166
+		return $content;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param EE_Event $item
172
+	 * @return string
173
+	 * @throws EE_Error
174
+	 * @throws InvalidArgumentException
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 */
178
+	public function column_name(EE_Event $item)
179
+	{
180
+		$edit_query_args = array(
181
+			'action' => 'edit',
182
+			'post'   => $item->ID(),
183
+		);
184
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
185
+		$actions = $this->_column_name_action_setup($item);
186
+		$status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
187
+		$content = '<strong><a class="row-title" href="'
188
+				   . $edit_link . '">'
189
+				   . $item->name()
190
+				   . '</a></strong>'
191
+				   . $status;
192
+		$content .= '<br><span class="ee-status-text-small">'
193
+					. EEH_Template::pretty_status(
194
+						$item->get_active_status(),
195
+						false,
196
+						'sentence'
197
+					)
198
+					. '</span>';
199
+		$content .= $this->row_actions($actions);
200
+		return $content;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Just a method for setting up the actions for the name column
206
+	 *
207
+	 * @param EE_Event $item
208
+	 * @return array array of actions
209
+	 * @throws EE_Error
210
+	 * @throws InvalidArgumentException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidInterfaceException
213
+	 */
214
+	protected function _column_name_action_setup(EE_Event $item)
215
+	{
216
+		// todo: remove when attendees is active
217
+		if (! defined('REG_ADMIN_URL')) {
218
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
219
+		}
220
+		$actions = array();
221
+		$restore_event_link = '';
222
+		$delete_event_link = '';
223
+		$trash_event_link = '';
224
+		if (
225
+			EE_Registry::instance()->CAP->current_user_can(
226
+				'ee_edit_event',
227
+				'espresso_events_edit',
228
+				$item->ID()
229
+			)
230
+		) {
231
+			$edit_query_args = array(
232
+				'action' => 'edit',
233
+				'post'   => $item->ID(),
234
+			);
235
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
+			$actions['edit'] = '<a href="' . $edit_link . '"'
237
+							   . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
238
+							   . esc_html__('Edit', 'event_espresso')
239
+							   . '</a>';
240
+		}
241
+		if (
242
+			EE_Registry::instance()->CAP->current_user_can(
243
+				'ee_read_registrations',
244
+				'espresso_registrations_view_registration'
245
+			)
246
+			&& EE_Registry::instance()->CAP->current_user_can(
247
+				'ee_read_event',
248
+				'espresso_registrations_view_registration',
249
+				$item->ID()
250
+			)
251
+		) {
252
+			$attendees_query_args = array(
253
+				'action'   => 'default',
254
+				'event_id' => $item->ID(),
255
+			);
256
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
257
+			$actions['attendees'] = '<a href="' . $attendees_link . '"'
258
+									. ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
259
+									. esc_html__('Registrations', 'event_espresso')
260
+									. '</a>';
261
+		}
262
+		if (
263
+			EE_Registry::instance()->CAP->current_user_can(
264
+				'ee_delete_event',
265
+				'espresso_events_trash_event',
266
+				$item->ID()
267
+			)
268
+		) {
269
+			$trash_event_query_args = array(
270
+				'action' => 'trash_event',
271
+				'EVT_ID' => $item->ID(),
272
+			);
273
+			$trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
274
+				$trash_event_query_args,
275
+				EVENTS_ADMIN_URL
276
+			);
277
+		}
278
+		if (
279
+			EE_Registry::instance()->CAP->current_user_can(
280
+				'ee_delete_event',
281
+				'espresso_events_restore_event',
282
+				$item->ID()
283
+			)
284
+		) {
285
+			$restore_event_query_args = array(
286
+				'action' => 'restore_event',
287
+				'EVT_ID' => $item->ID(),
288
+			);
289
+			$restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
290
+				$restore_event_query_args,
291
+				EVENTS_ADMIN_URL
292
+			);
293
+		}
294
+		if (
295
+			EE_Registry::instance()->CAP->current_user_can(
296
+				'ee_delete_event',
297
+				'espresso_events_delete_event',
298
+				$item->ID()
299
+			)
300
+		) {
301
+			$delete_event_query_args = array(
302
+				'action' => 'delete_event',
303
+				'EVT_ID' => $item->ID(),
304
+			);
305
+			$delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
306
+				$delete_event_query_args,
307
+				EVENTS_ADMIN_URL
308
+			);
309
+		}
310
+		$view_link = get_permalink($item->ID());
311
+		$actions['view'] = '<a href="' . $view_link . '"'
312
+						   . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
313
+						   . esc_html__('View', 'event_espresso')
314
+						   . '</a>';
315
+		if ($item->get('status') === 'trash') {
316
+			if (
317
+				EE_Registry::instance()->CAP->current_user_can(
318
+					'ee_delete_event',
319
+					'espresso_events_restore_event',
320
+					$item->ID()
321
+				)
322
+			) {
323
+				$actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
324
+												 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
325
+												 . '">'
326
+												 . esc_html__('Restore from Trash', 'event_espresso')
327
+												 . '</a>';
328
+			}
329
+			if (
330
+				EE_Registry::instance()->CAP->current_user_can(
331
+					'ee_delete_event',
332
+					'espresso_events_delete_event',
333
+					$item->ID()
334
+				)
335
+			) {
336
+				$actions['delete'] = '<a href="' . $delete_event_link . '"'
337
+									 . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
338
+									 . esc_html__('Delete Permanently', 'event_espresso')
339
+									 . '</a>';
340
+			}
341
+		} else {
342
+			if (
343
+				EE_Registry::instance()->CAP->current_user_can(
344
+					'ee_delete_event',
345
+					'espresso_events_trash_event',
346
+					$item->ID()
347
+				)
348
+			) {
349
+				$actions['move to trash'] = '<a href="' . $trash_event_link . '"'
350
+											. ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
351
+											. esc_html__('Trash', 'event_espresso')
352
+											. '</a>';
353
+			}
354
+		}
355
+		return $actions;
356
+	}
357
+
358
+
359
+	/**
360
+	 * @param EE_Event $item
361
+	 * @return string
362
+	 * @throws EE_Error
363
+	 */
364
+	public function column_author(EE_Event $item)
365
+	{
366
+		// user author info
367
+		$event_author = get_userdata($item->wp_user());
368
+		$gravatar = get_avatar($item->wp_user(), '15');
369
+		// filter link
370
+		$query_args = array(
371
+			'action'      => 'default',
372
+			'EVT_wp_user' => $item->wp_user(),
373
+		);
374
+		$filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
375
+		return $gravatar . '  <a href="' . $filter_url . '"'
376
+			   . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
377
+			   . $event_author->display_name
378
+			   . '</a>';
379
+	}
380
+
381
+
382
+	/**
383
+	 * @param EE_Event $event
384
+	 * @return string
385
+	 * @throws EE_Error
386
+	 */
387
+	public function column_event_category(EE_Event $event)
388
+	{
389
+		$event_categories = $event->get_all_event_categories();
390
+		return implode(
391
+			', ',
392
+			array_map(
393
+				function (EE_Term $category) {
394
+					return $category->name();
395
+				},
396
+				$event_categories
397
+			)
398
+		);
399
+	}
400
+
401
+
402
+	/**
403
+	 * @param EE_Event $item
404
+	 * @return string
405
+	 * @throws EE_Error
406
+	 */
407
+	public function column_venue(EE_Event $item)
408
+	{
409
+		$venue = $item->get_first_related('Venue');
410
+		return ! empty($venue)
411
+			? $venue->name()
412
+			: '';
413
+	}
414
+
415
+
416
+	/**
417
+	 * @param EE_Event $item
418
+	 * @return string
419
+	 * @throws EE_Error
420
+	 */
421
+	public function column_start_date_time(EE_Event $item)
422
+	{
423
+		return $this->_dtt instanceof EE_Datetime
424
+			? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
425
+			: esc_html__('No Date was saved for this Event', 'event_espresso');
426
+	}
427
+
428
+
429
+	/**
430
+	 * @param EE_Event $item
431
+	 * @return string
432
+	 * @throws EE_Error
433
+	 */
434
+	public function column_reg_begins(EE_Event $item)
435
+	{
436
+		$reg_start = $item->get_ticket_with_earliest_start_time();
437
+		return $reg_start instanceof EE_Ticket
438
+			? $reg_start->get_i18n_datetime('TKT_start_date')
439
+			: esc_html__('No Tickets have been setup for this Event', 'event_espresso');
440
+	}
441
+
442
+
443
+	/**
444
+	 * @param EE_Event $item
445
+	 * @return int|string
446
+	 * @throws EE_Error
447
+	 * @throws InvalidArgumentException
448
+	 * @throws InvalidDataTypeException
449
+	 * @throws InvalidInterfaceException
450
+	 */
451
+	public function column_attendees(EE_Event $item)
452
+	{
453
+		$attendees_query_args = array(
454
+			'action'   => 'default',
455
+			'event_id' => $item->ID(),
456
+		);
457
+		$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
458
+		$registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
459
+		return EE_Registry::instance()->CAP->current_user_can(
460
+			'ee_read_event',
461
+			'espresso_registrations_view_registration',
462
+			$item->ID()
463
+		)
464
+			   && EE_Registry::instance()->CAP->current_user_can(
465
+				   'ee_read_registrations',
466
+				   'espresso_registrations_view_registration'
467
+			   )
468
+			? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
469
+			: $registered_attendees;
470
+	}
471
+
472
+
473
+	/**
474
+	 * @param EE_Event $item
475
+	 * @return float
476
+	 * @throws EE_Error
477
+	 * @throws InvalidArgumentException
478
+	 * @throws InvalidDataTypeException
479
+	 * @throws InvalidInterfaceException
480
+	 */
481
+	public function column_tkts_sold(EE_Event $item)
482
+	{
483
+		return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
484
+	}
485
+
486
+
487
+	/**
488
+	 * @param EE_Event $item
489
+	 * @return string
490
+	 * @throws EE_Error
491
+	 * @throws InvalidArgumentException
492
+	 * @throws InvalidDataTypeException
493
+	 * @throws InvalidInterfaceException
494
+	 */
495
+	public function column_actions(EE_Event $item)
496
+	{
497
+		// todo: remove when attendees is active
498
+		if (! defined('REG_ADMIN_URL')) {
499
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
500
+		}
501
+		$action_links = array();
502
+		$view_link = get_permalink($item->ID());
503
+		$action_links[] = '<a href="' . $view_link . '"'
504
+						  . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
505
+		$action_links[] = '<div class="dashicons dashicons-search"></div></a>';
506
+		if (
507
+			EE_Registry::instance()->CAP->current_user_can(
508
+				'ee_edit_event',
509
+				'espresso_events_edit',
510
+				$item->ID()
511
+			)
512
+		) {
513
+			$edit_query_args = array(
514
+				'action' => 'edit',
515
+				'post'   => $item->ID(),
516
+			);
517
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
518
+			$action_links[] = '<a href="' . $edit_link . '"'
519
+							  . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
520
+							  . '<div class="ee-icon ee-icon-calendar-edit"></div>'
521
+							  . '</a>';
522
+		}
523
+		if (
524
+			EE_Registry::instance()->CAP->current_user_can(
525
+				'ee_read_registrations',
526
+				'espresso_registrations_view_registration'
527
+			) && EE_Registry::instance()->CAP->current_user_can(
528
+				'ee_read_event',
529
+				'espresso_registrations_view_registration',
530
+				$item->ID()
531
+			)
532
+		) {
533
+			$attendees_query_args = array(
534
+				'action'   => 'default',
535
+				'event_id' => $item->ID(),
536
+			);
537
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
538
+			$action_links[] = '<a href="' . $attendees_link . '"'
539
+							  . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
540
+							  . '<div class="dashicons dashicons-groups"></div>'
541
+							  . '</a>';
542
+		}
543
+		$action_links = apply_filters(
544
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
545
+			$action_links,
546
+			$item
547
+		);
548
+		return $this->_action_string(
549
+			implode("\n\t", $action_links),
550
+			$item,
551
+			'div'
552
+		);
553
+	}
554
+
555
+
556
+	/**
557
+	 * Helper for adding columns conditionally
558
+	 *
559
+	 * @throws EE_Error
560
+	 * @throws InvalidArgumentException
561
+	 * @throws InvalidDataTypeException
562
+	 * @throws InvalidInterfaceException
563
+	 */
564
+	private function addConditionalColumns()
565
+	{
566
+		$event_category_count = EEM_Term::instance()->count(
567
+			[['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
568
+		);
569
+		if ($event_category_count === 0) {
570
+			return;
571
+		}
572
+		$column_array = [];
573
+		foreach ($this->_columns as $column => $column_label) {
574
+			$column_array[ $column ] = $column_label;
575
+			if ($column === 'venue') {
576
+				$column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
577
+			}
578
+		}
579
+		$this->_columns = $column_array;
580
+	}
581 581
 }
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Attendee_Contact_List_Table.class.php 2 patches
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -12,382 +12,382 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Attendee_Contact_List_Table extends EE_Admin_List_Table
14 14
 {
15
-    /**
16
-     * Initial setup of data (called by parent).
17
-     */
18
-    protected function _setup_data()
19
-    {
20
-        $this->_data = $this->_view !== 'trash'
21
-            ? $this->_admin_page->get_attendees($this->_per_page)
22
-            : $this->_admin_page->get_attendees($this->_per_page, false, true);
23
-        $this->_all_data_count = $this->_view !== 'trash'
24
-            ? $this->_admin_page->get_attendees($this->_per_page, true)
25
-            : $this->_admin_page->get_attendees($this->_per_page, true, true);
26
-    }
27
-
28
-
29
-    /**
30
-     * Initial setup of properties.
31
-     */
32
-    protected function _set_properties()
33
-    {
34
-        $this->_wp_list_args = array(
35
-            'singular' => esc_html__('attendee', 'event_espresso'),
36
-            'plural'   => esc_html__('attendees', 'event_espresso'),
37
-            'ajax'     => true,
38
-            'screen'   => $this->_admin_page->get_current_screen()->id,
39
-        );
40
-
41
-        $this->_columns = array(
42
-            'cb'                 => '<input type="checkbox" />', // Render a checkbox instead of text
43
-            'ATT_ID'             => esc_html__('ID', 'event_espresso'),
44
-            'ATT_fname'          => esc_html__('First Name', 'event_espresso'),
45
-            'ATT_lname'          => esc_html__('Last Name', 'event_espresso'),
46
-            'ATT_email'          => esc_html__('Email Address', 'event_espresso'),
47
-            'Registration_Count' => esc_html__('# Registrations', 'event_espresso'),
48
-            'ATT_phone'          => esc_html__('Phone', 'event_espresso'),
49
-            'ATT_address'        => esc_html__('Address', 'event_espresso'),
50
-            'ATT_city'           => esc_html__('City', 'event_espresso'),
51
-            'STA_ID'             => esc_html__('State/Province', 'event_espresso'),
52
-            'CNT_ISO'            => esc_html__('Country', 'event_espresso'),
53
-        );
54
-
55
-        $this->_sortable_columns = array(
56
-            'ATT_ID'             => array('ATT_ID' => false),
57
-            'ATT_lname'          => array('ATT_lname' => true), // true means its already sorted
58
-            'ATT_fname'          => array('ATT_fname' => false),
59
-            'ATT_email'          => array('ATT_email' => false),
60
-            'Registration_Count' => array('Registration_Count' => false),
61
-            'ATT_city'           => array('ATT_city' => false),
62
-            'STA_ID'             => array('STA_ID' => false),
63
-            'CNT_ISO'            => array('CNT_ISO' => false),
64
-        );
65
-
66
-        $this->_hidden_columns = array(
67
-            'ATT_phone',
68
-            'ATT_address',
69
-            'ATT_city',
70
-            'STA_ID',
71
-            'CNT_ISO',
72
-        );
73
-    }
74
-
75
-
76
-    /**
77
-     * Initial setup of filters
78
-     *
79
-     * @return array
80
-     */
81
-    protected function _get_table_filters()
82
-    {
83
-        return array();
84
-    }
85
-
86
-
87
-    /**
88
-     * Initial setup of counts for views
89
-     *
90
-     * @throws InvalidArgumentException
91
-     * @throws InvalidDataTypeException
92
-     * @throws InvalidInterfaceException
93
-     */
94
-    protected function _add_view_counts()
95
-    {
96
-        $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
97
-        if (
98
-            EE_Registry::instance()->CAP->current_user_can(
99
-                'ee_delete_contacts',
100
-                'espresso_registrations_delete_registration'
101
-            )
102
-        ) {
103
-            $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
104
-        }
105
-    }
106
-
107
-
108
-    /**
109
-     * Get count of attendees.
110
-     *
111
-     * @return int
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    protected function _get_attendees_count()
118
-    {
119
-        return EEM_Attendee::instance()->count();
120
-    }
121
-
122
-
123
-    /**
124
-     * Checkbox column
125
-     *
126
-     * @param EE_Attendee $attendee Unable to typehint this method because overrides parent.
127
-     * @return string
128
-     * @throws EE_Error
129
-     */
130
-    public function column_cb($attendee)
131
-    {
132
-        if (! $attendee instanceof EE_Attendee) {
133
-            return '';
134
-        }
135
-        return sprintf(
136
-            '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
137
-            $attendee->ID()
138
-        );
139
-    }
140
-
141
-
142
-    /**
143
-     * ATT_ID column
144
-     *
145
-     * @param EE_Attendee $attendee
146
-     * @return string
147
-     * @throws EE_Error
148
-     */
149
-    public function column_ATT_ID(EE_Attendee $attendee)
150
-    {
151
-        $content = $attendee->ID();
152
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
153
-        $content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
154
-        return $content;
155
-    }
156
-
157
-
158
-    /**
159
-     * ATT_lname column
160
-     *
161
-     * @param EE_Attendee $attendee
162
-     * @return string
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidInterfaceException
166
-     * @throws EE_Error
167
-     */
168
-    public function column_ATT_lname(EE_Attendee $attendee)
169
-    {
170
-        // edit attendee link
171
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
172
-            array(
173
-                'action' => 'edit_attendee',
174
-                'post'   => $attendee->ID(),
175
-            ),
176
-            REG_ADMIN_URL
177
-        );
178
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
179
-            'ee_edit_contacts',
180
-            'espresso_registrations_edit_attendee'
181
-        )
182
-            ? '<a href="' . $edit_lnk_url . '" title="'
183
-              . esc_attr__('Edit Contact', 'event_espresso') . '">'
184
-              . $attendee->lname() . '</a>'
185
-            : $attendee->lname();
186
-        return $name_link;
187
-    }
188
-
189
-
190
-    /**
191
-     * ATT_fname column
192
-     *
193
-     * @param EE_Attendee $attendee
194
-     * @return string
195
-     * @throws InvalidArgumentException
196
-     * @throws InvalidDataTypeException
197
-     * @throws InvalidInterfaceException
198
-     * @throws EE_Error
199
-     */
200
-    public function column_ATT_fname(EE_Attendee $attendee)
201
-    {
202
-        // Build row actions
203
-        $actions = array();
204
-        // edit attendee link
205
-        if (
206
-            EE_Registry::instance()->CAP->current_user_can(
207
-                'ee_edit_contacts',
208
-                'espresso_registrations_edit_attendee'
209
-            )
210
-        ) {
211
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
212
-                array(
213
-                    'action' => 'edit_attendee',
214
-                    'post'   => $attendee->ID(),
215
-                ),
216
-                REG_ADMIN_URL
217
-            );
218
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
219
-                               . esc_attr__('Edit Contact', 'event_espresso') . '">'
220
-                               . esc_html__('Edit', 'event_espresso') . '</a>';
221
-        }
222
-
223
-        if ($this->_view === 'in_use') {
224
-            // trash attendee link
225
-            if (
226
-                EE_Registry::instance()->CAP->current_user_can(
227
-                    'ee_delete_contacts',
228
-                    'espresso_registrations_trash_attendees'
229
-                )
230
-            ) {
231
-                $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
232
-                    array(
233
-                        'action' => 'trash_attendee',
234
-                        'ATT_ID' => $attendee->ID(),
235
-                    ),
236
-                    REG_ADMIN_URL
237
-                );
238
-                $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
239
-                                    . esc_attr__('Move Contact to Trash', 'event_espresso')
240
-                                    . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
241
-            }
242
-        } else {
243
-            if (
244
-                EE_Registry::instance()->CAP->current_user_can(
245
-                    'ee_delete_contacts',
246
-                    'espresso_registrations_restore_attendees'
247
-                )
248
-            ) {
249
-                // restore attendee link
250
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
251
-                    array(
252
-                        'action' => 'restore_attendees',
253
-                        'ATT_ID' => $attendee->ID(),
254
-                    ),
255
-                    REG_ADMIN_URL
256
-                );
257
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
258
-                                      . esc_attr__('Restore Contact', 'event_espresso') . '">'
259
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
260
-            }
261
-        }
262
-
263
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
264
-            array(
265
-                'action' => 'edit_attendee',
266
-                'post'   => $attendee->ID(),
267
-            ),
268
-            REG_ADMIN_URL
269
-        );
270
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
271
-            'ee_edit_contacts',
272
-            'espresso_registrations_edit_attendee'
273
-        )
274
-            ? '<a href="' . $edit_lnk_url . '" title="'
275
-              . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
276
-            : $attendee->fname();
277
-
278
-        // Return the name contents
279
-        return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
280
-    }
281
-
282
-
283
-    /**
284
-     * Email Column
285
-     *
286
-     * @param EE_Attendee $attendee
287
-     * @return string
288
-     * @throws EE_Error
289
-     */
290
-    public function column_ATT_email(EE_Attendee $attendee)
291
-    {
292
-        return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
293
-    }
294
-
295
-
296
-    /**
297
-     * Column displaying count of registrations attached to Attendee.
298
-     *
299
-     * @param EE_Attendee $attendee
300
-     * @return string
301
-     * @throws EE_Error
302
-     */
303
-    public function column_Registration_Count(EE_Attendee $attendee)
304
-    {
305
-        $link = EEH_URL::add_query_args_and_nonce(
306
-            array(
307
-                'action' => 'default',
308
-                'ATT_ID' => $attendee->ID(),
309
-            ),
310
-            REG_ADMIN_URL
311
-        );
312
-        return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
313
-    }
314
-
315
-
316
-    /**
317
-     * ATT_address column
318
-     *
319
-     * @param EE_Attendee $attendee
320
-     * @return mixed
321
-     * @throws EE_Error
322
-     */
323
-    public function column_ATT_address(EE_Attendee $attendee)
324
-    {
325
-        return $attendee->address();
326
-    }
327
-
328
-
329
-    /**
330
-     * ATT_city column
331
-     *
332
-     * @param EE_Attendee $attendee
333
-     * @return mixed
334
-     * @throws EE_Error
335
-     */
336
-    public function column_ATT_city(EE_Attendee $attendee)
337
-    {
338
-        return $attendee->city();
339
-    }
340
-
341
-
342
-    /**
343
-     * State Column
344
-     *
345
-     * @param EE_Attendee $attendee
346
-     * @return string
347
-     * @throws EE_Error
348
-     * @throws InvalidArgumentException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidInterfaceException
351
-     */
352
-    public function column_STA_ID(EE_Attendee $attendee)
353
-    {
354
-        $states = EEM_State::instance()->get_all_states();
355
-        $state = isset($states[ $attendee->state_ID() ])
356
-            ? $states[ $attendee->state_ID() ]->get('STA_name')
357
-            : $attendee->state_ID();
358
-        return ! is_numeric($state) ? $state : '';
359
-    }
360
-
361
-
362
-    /**
363
-     * Country Column
364
-     *
365
-     * @param EE_Attendee $attendee
366
-     * @return string
367
-     * @throws EE_Error
368
-     * @throws InvalidArgumentException
369
-     * @throws InvalidDataTypeException
370
-     * @throws InvalidInterfaceException
371
-     */
372
-    public function column_CNT_ISO(EE_Attendee $attendee)
373
-    {
374
-        $countries = EEM_Country::instance()->get_all_countries();
375
-        $country = isset($countries[ $attendee->country_ID() ])
376
-            ? $countries[ $attendee->country_ID() ]->get('CNT_name')
377
-            : $attendee->country_ID();
378
-        return ! is_numeric($country) ? $country : '';
379
-    }
380
-
381
-
382
-    /**
383
-     * Phone Number column
384
-     *
385
-     * @param EE_Attendee $attendee
386
-     * @return mixed
387
-     * @throws EE_Error
388
-     */
389
-    public function column_ATT_phone(EE_Attendee $attendee)
390
-    {
391
-        return $attendee->phone();
392
-    }
15
+	/**
16
+	 * Initial setup of data (called by parent).
17
+	 */
18
+	protected function _setup_data()
19
+	{
20
+		$this->_data = $this->_view !== 'trash'
21
+			? $this->_admin_page->get_attendees($this->_per_page)
22
+			: $this->_admin_page->get_attendees($this->_per_page, false, true);
23
+		$this->_all_data_count = $this->_view !== 'trash'
24
+			? $this->_admin_page->get_attendees($this->_per_page, true)
25
+			: $this->_admin_page->get_attendees($this->_per_page, true, true);
26
+	}
27
+
28
+
29
+	/**
30
+	 * Initial setup of properties.
31
+	 */
32
+	protected function _set_properties()
33
+	{
34
+		$this->_wp_list_args = array(
35
+			'singular' => esc_html__('attendee', 'event_espresso'),
36
+			'plural'   => esc_html__('attendees', 'event_espresso'),
37
+			'ajax'     => true,
38
+			'screen'   => $this->_admin_page->get_current_screen()->id,
39
+		);
40
+
41
+		$this->_columns = array(
42
+			'cb'                 => '<input type="checkbox" />', // Render a checkbox instead of text
43
+			'ATT_ID'             => esc_html__('ID', 'event_espresso'),
44
+			'ATT_fname'          => esc_html__('First Name', 'event_espresso'),
45
+			'ATT_lname'          => esc_html__('Last Name', 'event_espresso'),
46
+			'ATT_email'          => esc_html__('Email Address', 'event_espresso'),
47
+			'Registration_Count' => esc_html__('# Registrations', 'event_espresso'),
48
+			'ATT_phone'          => esc_html__('Phone', 'event_espresso'),
49
+			'ATT_address'        => esc_html__('Address', 'event_espresso'),
50
+			'ATT_city'           => esc_html__('City', 'event_espresso'),
51
+			'STA_ID'             => esc_html__('State/Province', 'event_espresso'),
52
+			'CNT_ISO'            => esc_html__('Country', 'event_espresso'),
53
+		);
54
+
55
+		$this->_sortable_columns = array(
56
+			'ATT_ID'             => array('ATT_ID' => false),
57
+			'ATT_lname'          => array('ATT_lname' => true), // true means its already sorted
58
+			'ATT_fname'          => array('ATT_fname' => false),
59
+			'ATT_email'          => array('ATT_email' => false),
60
+			'Registration_Count' => array('Registration_Count' => false),
61
+			'ATT_city'           => array('ATT_city' => false),
62
+			'STA_ID'             => array('STA_ID' => false),
63
+			'CNT_ISO'            => array('CNT_ISO' => false),
64
+		);
65
+
66
+		$this->_hidden_columns = array(
67
+			'ATT_phone',
68
+			'ATT_address',
69
+			'ATT_city',
70
+			'STA_ID',
71
+			'CNT_ISO',
72
+		);
73
+	}
74
+
75
+
76
+	/**
77
+	 * Initial setup of filters
78
+	 *
79
+	 * @return array
80
+	 */
81
+	protected function _get_table_filters()
82
+	{
83
+		return array();
84
+	}
85
+
86
+
87
+	/**
88
+	 * Initial setup of counts for views
89
+	 *
90
+	 * @throws InvalidArgumentException
91
+	 * @throws InvalidDataTypeException
92
+	 * @throws InvalidInterfaceException
93
+	 */
94
+	protected function _add_view_counts()
95
+	{
96
+		$this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
97
+		if (
98
+			EE_Registry::instance()->CAP->current_user_can(
99
+				'ee_delete_contacts',
100
+				'espresso_registrations_delete_registration'
101
+			)
102
+		) {
103
+			$this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
104
+		}
105
+	}
106
+
107
+
108
+	/**
109
+	 * Get count of attendees.
110
+	 *
111
+	 * @return int
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	protected function _get_attendees_count()
118
+	{
119
+		return EEM_Attendee::instance()->count();
120
+	}
121
+
122
+
123
+	/**
124
+	 * Checkbox column
125
+	 *
126
+	 * @param EE_Attendee $attendee Unable to typehint this method because overrides parent.
127
+	 * @return string
128
+	 * @throws EE_Error
129
+	 */
130
+	public function column_cb($attendee)
131
+	{
132
+		if (! $attendee instanceof EE_Attendee) {
133
+			return '';
134
+		}
135
+		return sprintf(
136
+			'<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
137
+			$attendee->ID()
138
+		);
139
+	}
140
+
141
+
142
+	/**
143
+	 * ATT_ID column
144
+	 *
145
+	 * @param EE_Attendee $attendee
146
+	 * @return string
147
+	 * @throws EE_Error
148
+	 */
149
+	public function column_ATT_ID(EE_Attendee $attendee)
150
+	{
151
+		$content = $attendee->ID();
152
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
153
+		$content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
154
+		return $content;
155
+	}
156
+
157
+
158
+	/**
159
+	 * ATT_lname column
160
+	 *
161
+	 * @param EE_Attendee $attendee
162
+	 * @return string
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidInterfaceException
166
+	 * @throws EE_Error
167
+	 */
168
+	public function column_ATT_lname(EE_Attendee $attendee)
169
+	{
170
+		// edit attendee link
171
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
172
+			array(
173
+				'action' => 'edit_attendee',
174
+				'post'   => $attendee->ID(),
175
+			),
176
+			REG_ADMIN_URL
177
+		);
178
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
179
+			'ee_edit_contacts',
180
+			'espresso_registrations_edit_attendee'
181
+		)
182
+			? '<a href="' . $edit_lnk_url . '" title="'
183
+			  . esc_attr__('Edit Contact', 'event_espresso') . '">'
184
+			  . $attendee->lname() . '</a>'
185
+			: $attendee->lname();
186
+		return $name_link;
187
+	}
188
+
189
+
190
+	/**
191
+	 * ATT_fname column
192
+	 *
193
+	 * @param EE_Attendee $attendee
194
+	 * @return string
195
+	 * @throws InvalidArgumentException
196
+	 * @throws InvalidDataTypeException
197
+	 * @throws InvalidInterfaceException
198
+	 * @throws EE_Error
199
+	 */
200
+	public function column_ATT_fname(EE_Attendee $attendee)
201
+	{
202
+		// Build row actions
203
+		$actions = array();
204
+		// edit attendee link
205
+		if (
206
+			EE_Registry::instance()->CAP->current_user_can(
207
+				'ee_edit_contacts',
208
+				'espresso_registrations_edit_attendee'
209
+			)
210
+		) {
211
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
212
+				array(
213
+					'action' => 'edit_attendee',
214
+					'post'   => $attendee->ID(),
215
+				),
216
+				REG_ADMIN_URL
217
+			);
218
+			$actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
219
+							   . esc_attr__('Edit Contact', 'event_espresso') . '">'
220
+							   . esc_html__('Edit', 'event_espresso') . '</a>';
221
+		}
222
+
223
+		if ($this->_view === 'in_use') {
224
+			// trash attendee link
225
+			if (
226
+				EE_Registry::instance()->CAP->current_user_can(
227
+					'ee_delete_contacts',
228
+					'espresso_registrations_trash_attendees'
229
+				)
230
+			) {
231
+				$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
232
+					array(
233
+						'action' => 'trash_attendee',
234
+						'ATT_ID' => $attendee->ID(),
235
+					),
236
+					REG_ADMIN_URL
237
+				);
238
+				$actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
239
+									. esc_attr__('Move Contact to Trash', 'event_espresso')
240
+									. '">' . esc_html__('Trash', 'event_espresso') . '</a>';
241
+			}
242
+		} else {
243
+			if (
244
+				EE_Registry::instance()->CAP->current_user_can(
245
+					'ee_delete_contacts',
246
+					'espresso_registrations_restore_attendees'
247
+				)
248
+			) {
249
+				// restore attendee link
250
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
251
+					array(
252
+						'action' => 'restore_attendees',
253
+						'ATT_ID' => $attendee->ID(),
254
+					),
255
+					REG_ADMIN_URL
256
+				);
257
+				$actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
258
+									  . esc_attr__('Restore Contact', 'event_espresso') . '">'
259
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
260
+			}
261
+		}
262
+
263
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
264
+			array(
265
+				'action' => 'edit_attendee',
266
+				'post'   => $attendee->ID(),
267
+			),
268
+			REG_ADMIN_URL
269
+		);
270
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
271
+			'ee_edit_contacts',
272
+			'espresso_registrations_edit_attendee'
273
+		)
274
+			? '<a href="' . $edit_lnk_url . '" title="'
275
+			  . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
276
+			: $attendee->fname();
277
+
278
+		// Return the name contents
279
+		return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
280
+	}
281
+
282
+
283
+	/**
284
+	 * Email Column
285
+	 *
286
+	 * @param EE_Attendee $attendee
287
+	 * @return string
288
+	 * @throws EE_Error
289
+	 */
290
+	public function column_ATT_email(EE_Attendee $attendee)
291
+	{
292
+		return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
293
+	}
294
+
295
+
296
+	/**
297
+	 * Column displaying count of registrations attached to Attendee.
298
+	 *
299
+	 * @param EE_Attendee $attendee
300
+	 * @return string
301
+	 * @throws EE_Error
302
+	 */
303
+	public function column_Registration_Count(EE_Attendee $attendee)
304
+	{
305
+		$link = EEH_URL::add_query_args_and_nonce(
306
+			array(
307
+				'action' => 'default',
308
+				'ATT_ID' => $attendee->ID(),
309
+			),
310
+			REG_ADMIN_URL
311
+		);
312
+		return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
313
+	}
314
+
315
+
316
+	/**
317
+	 * ATT_address column
318
+	 *
319
+	 * @param EE_Attendee $attendee
320
+	 * @return mixed
321
+	 * @throws EE_Error
322
+	 */
323
+	public function column_ATT_address(EE_Attendee $attendee)
324
+	{
325
+		return $attendee->address();
326
+	}
327
+
328
+
329
+	/**
330
+	 * ATT_city column
331
+	 *
332
+	 * @param EE_Attendee $attendee
333
+	 * @return mixed
334
+	 * @throws EE_Error
335
+	 */
336
+	public function column_ATT_city(EE_Attendee $attendee)
337
+	{
338
+		return $attendee->city();
339
+	}
340
+
341
+
342
+	/**
343
+	 * State Column
344
+	 *
345
+	 * @param EE_Attendee $attendee
346
+	 * @return string
347
+	 * @throws EE_Error
348
+	 * @throws InvalidArgumentException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidInterfaceException
351
+	 */
352
+	public function column_STA_ID(EE_Attendee $attendee)
353
+	{
354
+		$states = EEM_State::instance()->get_all_states();
355
+		$state = isset($states[ $attendee->state_ID() ])
356
+			? $states[ $attendee->state_ID() ]->get('STA_name')
357
+			: $attendee->state_ID();
358
+		return ! is_numeric($state) ? $state : '';
359
+	}
360
+
361
+
362
+	/**
363
+	 * Country Column
364
+	 *
365
+	 * @param EE_Attendee $attendee
366
+	 * @return string
367
+	 * @throws EE_Error
368
+	 * @throws InvalidArgumentException
369
+	 * @throws InvalidDataTypeException
370
+	 * @throws InvalidInterfaceException
371
+	 */
372
+	public function column_CNT_ISO(EE_Attendee $attendee)
373
+	{
374
+		$countries = EEM_Country::instance()->get_all_countries();
375
+		$country = isset($countries[ $attendee->country_ID() ])
376
+			? $countries[ $attendee->country_ID() ]->get('CNT_name')
377
+			: $attendee->country_ID();
378
+		return ! is_numeric($country) ? $country : '';
379
+	}
380
+
381
+
382
+	/**
383
+	 * Phone Number column
384
+	 *
385
+	 * @param EE_Attendee $attendee
386
+	 * @return mixed
387
+	 * @throws EE_Error
388
+	 */
389
+	public function column_ATT_phone(EE_Attendee $attendee)
390
+	{
391
+		return $attendee->phone();
392
+	}
393 393
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function column_cb($attendee)
131 131
     {
132
-        if (! $attendee instanceof EE_Attendee) {
132
+        if ( ! $attendee instanceof EE_Attendee) {
133 133
             return '';
134 134
         }
135 135
         return sprintf(
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     {
151 151
         $content = $attendee->ID();
152 152
         $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
153
-        $content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
153
+        $content .= '  <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
154 154
         return $content;
155 155
     }
156 156
 
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
             'ee_edit_contacts',
180 180
             'espresso_registrations_edit_attendee'
181 181
         )
182
-            ? '<a href="' . $edit_lnk_url . '" title="'
183
-              . esc_attr__('Edit Contact', 'event_espresso') . '">'
184
-              . $attendee->lname() . '</a>'
182
+            ? '<a href="'.$edit_lnk_url.'" title="'
183
+              . esc_attr__('Edit Contact', 'event_espresso').'">'
184
+              . $attendee->lname().'</a>'
185 185
             : $attendee->lname();
186 186
         return $name_link;
187 187
     }
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
                 ),
216 216
                 REG_ADMIN_URL
217 217
             );
218
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
219
-                               . esc_attr__('Edit Contact', 'event_espresso') . '">'
220
-                               . esc_html__('Edit', 'event_espresso') . '</a>';
218
+            $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="'
219
+                               . esc_attr__('Edit Contact', 'event_espresso').'">'
220
+                               . esc_html__('Edit', 'event_espresso').'</a>';
221 221
         }
222 222
 
223 223
         if ($this->_view === 'in_use') {
@@ -235,9 +235,9 @@  discard block
 block discarded – undo
235 235
                     ),
236 236
                     REG_ADMIN_URL
237 237
                 );
238
-                $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
238
+                $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'
239 239
                                     . esc_attr__('Move Contact to Trash', 'event_espresso')
240
-                                    . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
240
+                                    . '">'.esc_html__('Trash', 'event_espresso').'</a>';
241 241
             }
242 242
         } else {
243 243
             if (
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
                     ),
255 255
                     REG_ADMIN_URL
256 256
                 );
257
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
258
-                                      . esc_attr__('Restore Contact', 'event_espresso') . '">'
259
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
257
+                $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'
258
+                                      . esc_attr__('Restore Contact', 'event_espresso').'">'
259
+                                      . esc_html__('Restore', 'event_espresso').'</a>';
260 260
             }
261 261
         }
262 262
 
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
             'ee_edit_contacts',
272 272
             'espresso_registrations_edit_attendee'
273 273
         )
274
-            ? '<a href="' . $edit_lnk_url . '" title="'
275
-              . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
274
+            ? '<a href="'.$edit_lnk_url.'" title="'
275
+              . esc_attr__('Edit Contact', 'event_espresso').'">'.$attendee->fname().'</a>'
276 276
             : $attendee->fname();
277 277
 
278 278
         // Return the name contents
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      */
290 290
     public function column_ATT_email(EE_Attendee $attendee)
291 291
     {
292
-        return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
292
+        return '<a href="mailto:'.$attendee->email().'">'.$attendee->email().'</a>';
293 293
     }
294 294
 
295 295
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
             ),
310 310
             REG_ADMIN_URL
311 311
         );
312
-        return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
312
+        return '<a href="'.$link.'">'.$attendee->getCustomSelect('Registration_Count').'</a>';
313 313
     }
314 314
 
315 315
 
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
     public function column_STA_ID(EE_Attendee $attendee)
353 353
     {
354 354
         $states = EEM_State::instance()->get_all_states();
355
-        $state = isset($states[ $attendee->state_ID() ])
356
-            ? $states[ $attendee->state_ID() ]->get('STA_name')
355
+        $state = isset($states[$attendee->state_ID()])
356
+            ? $states[$attendee->state_ID()]->get('STA_name')
357 357
             : $attendee->state_ID();
358 358
         return ! is_numeric($state) ? $state : '';
359 359
     }
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
     public function column_CNT_ISO(EE_Attendee $attendee)
373 373
     {
374 374
         $countries = EEM_Country::instance()->get_all_countries();
375
-        $country = isset($countries[ $attendee->country_ID() ])
376
-            ? $countries[ $attendee->country_ID() ]->get('CNT_name')
375
+        $country = isset($countries[$attendee->country_ID()])
376
+            ? $countries[$attendee->country_ID()]->get('CNT_name')
377 377
             : $attendee->country_ID();
378 378
         return ! is_numeric($country) ? $country : '';
379 379
     }
Please login to merge, or discard this patch.
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.