Completed
Branch BUG/11294/expired-cart-ticket-... (22bfe9)
by
unknown
48:53 queued 33:02
created
single_page_checkout/templates/registration_page_wrapper.template.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,39 +1,39 @@  discard block
 block discarded – undo
1 1
 <div id="ee-single-page-checkout-dv" class="">
2 2
 <?php
3
-if ( ! $empty_cart ) {
4
-	if ( apply_filters( 'FHEE__registration_page_wrapper_template__display_time_limit', false ) ) { ?>
3
+if ( ! $empty_cart) {
4
+	if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?>
5 5
 	<p id="spco-registration-time-limit-pg" class="spco-steps-pg ee-attention important-notice" style="display: none;">
6 6
 		<?php echo sprintf(
7 7
 			apply_filters(
8 8
 				'FHEE__registration_page_wrapper_template___time_limit',
9
-				__( 'You have %1$s to complete your registration.', 'event_espresso' )
9
+				__('You have %1$s to complete your registration.', 'event_espresso')
10 10
 			),
11
-			'<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>'
11
+			'<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">'.$registration_time_limit.'</span>'
12 12
 		);
13 13
 		?>
14 14
 		<span id="spco-registration-expiration-spn" class="" style="display:none;"></span>
15 15
 	</p>
16 16
 <?php }
17
-	if ( ! $revisit && apply_filters( 'FHEE__registration_page_wrapper_template__steps_display', TRUE )) {
17
+	if ( ! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', TRUE)) {
18 18
 ?>
19 19
 	<h2 id="spco-steps-big-hdr" class="spco-steps-big-hdr"><?php _e(' Steps', 'event_espresso'); ?></h2>
20 20
 
21 21
 	<div id="spco-steps-display-dv">
22 22
 	<?php
23 23
 		$step_nmbr = 1;
24
-		$total_steps = count( $reg_steps ) - 1;
25
-		foreach ( $reg_steps as $reg_step ) {
26
-			if ( $reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration' ) {
24
+		$total_steps = count($reg_steps) - 1;
25
+		foreach ($reg_steps as $reg_step) {
26
+			if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') {
27 27
 				$slug = $reg_step->slug();
28 28
 				$step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step';
29 29
 		?>
30 30
 		<div id="spco-step-<?php echo $slug; ?>-display-dv" class="spco-step-display-dv <?php echo $step_display_dv_class; ?> steps-<?php echo $total_steps; ?>">
31 31
 			<h4 id="spco-step-<?php echo $slug; ?>-display-hdr" class="spco-steps-display-hdr">
32
-				<span class="spco-step-big-nmbr"><?php echo $step_nmbr; ?></span>&nbsp;<span class="spco-step-name"><?php echo str_replace( '&nbsp;', '<br/>&nbsp;', $reg_step->name() ); ?></span>
32
+				<span class="spco-step-big-nmbr"><?php echo $step_nmbr; ?></span>&nbsp;<span class="spco-step-name"><?php echo str_replace('&nbsp;', '<br/>&nbsp;', $reg_step->name()); ?></span>
33 33
 			</h4>
34 34
 		</div>
35 35
 
36
-		<?php if ( $step_nmbr < $total_steps ) { ?>
36
+		<?php if ($step_nmbr < $total_steps) { ?>
37 37
 		<div class="spco-step-arrow-dv">&raquo;</div>
38 38
 		<?php
39 39
 				}
@@ -47,22 +47,22 @@  discard block
 block discarded – undo
47 47
 	<?php
48 48
 	}
49 49
 
50
-	do_action( 'AHEE__SPCO__before_registration_steps' );
50
+	do_action('AHEE__SPCO__before_registration_steps');
51 51
 	$step_nmbr = 1;
52
-	foreach ( $reg_steps as $reg_step ) {
53
-		if ( $reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration' ) {
52
+	foreach ($reg_steps as $reg_step) {
53
+		if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') {
54 54
 			$slug = $reg_step->slug();
55
-			do_action( 'AHEE__' . $slug . '__reg_step_start', $reg_step );
55
+			do_action('AHEE__'.$slug.'__reg_step_start', $reg_step);
56 56
 			// todo: deprecate hook AHEE__registration_page_attendee_information__start
57 57
 	?>
58 58
 		<div id="spco-<?php echo $slug; ?>-dv" class="spco-step-dv <?php echo $reg_step->div_class(); ?>">
59 59
 			<?php echo $reg_step->display_reg_form(); ?>
60
-			<?php do_action( 'AHEE__SPCO_after_reg_step_form', $slug, $next_step ); ?>
60
+			<?php do_action('AHEE__SPCO_after_reg_step_form', $slug, $next_step); ?>
61 61
 		</div>
62 62
 			<?php $step_nmbr++;
63 63
 		}
64 64
 	}
65
-	do_action( 'AHEE__SPCO__after_registration_steps' );
65
+	do_action('AHEE__SPCO__after_registration_steps');
66 66
 
67 67
 } else {
68 68
 ?>
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	<?php echo $cookies_not_set_msg; ?>
72 72
 <?php
73 73
 }
74
-do_action( 'AHEE__SPCO__reg_form_footer' );
74
+do_action('AHEE__SPCO__reg_form_footer');
75 75
 ?>
76 76
 
77 77
 </div>
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 2 patches
Indentation   +601 added lines, -601 removed lines patch added patch discarded remove patch
@@ -17,607 +17,607 @@
 block discarded – undo
17 17
 class EE_Cron_Tasks extends EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * WordPress doesn't allow duplicate crons within 10 minutes of the original,
22
-     * so we'll set our retry time for just over 10 minutes to avoid that
23
-     */
24
-    const reschedule_timeout = 605;
25
-
26
-
27
-    /**
28
-     * @var EE_Cron_Tasks
29
-     */
30
-    private static $_instance;
31
-
32
-
33
-    /**
34
-     * @return EE_Cron_Tasks
35
-     * @throws ReflectionException
36
-     * @throws EE_Error
37
-     * @throws InvalidArgumentException
38
-     * @throws InvalidInterfaceException
39
-     * @throws InvalidDataTypeException
40
-     */
41
-    public static function instance()
42
-    {
43
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
44
-            self::$_instance = new self();
45
-        }
46
-        return self::$_instance;
47
-    }
48
-
49
-
50
-    /**
51
-     * @access private
52
-     * @throws InvalidDataTypeException
53
-     * @throws InvalidInterfaceException
54
-     * @throws InvalidArgumentException
55
-     * @throws EE_Error
56
-     * @throws ReflectionException
57
-     */
58
-    private function __construct()
59
-    {
60
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
61
-        // verify that WP Cron is enabled
62
-        if (
63
-            defined('DISABLE_WP_CRON')
64
-            && DISABLE_WP_CRON
65
-            && is_admin()
66
-            && ! get_option('ee_disabled_wp_cron_check')
67
-        ) {
68
-            /**
69
-             * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
70
-             * config is loaded.
71
-             * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
72
-             * wanting to not have this functionality can just register its own action at a priority after this one to
73
-             * reverse any changes.
74
-             */
75
-            add_action(
76
-                'AHEE__EE_System__load_core_configuration__complete',
77
-                function ()
78
-                {
79
-                    EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
80
-                    EE_Registry::instance()->NET_CFG->update_config(true, false);
81
-                    add_option('ee_disabled_wp_cron_check', 1, '', false);
82
-                }
83
-            );
84
-        }
85
-        // UPDATE TRANSACTION WITH PAYMENT
86
-        add_action(
87
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
88
-            array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
89
-            10,
90
-            2
91
-        );
92
-        // ABANDONED / EXPIRED TRANSACTION CHECK
93
-        add_action(
94
-            'AHEE__EE_Cron_Tasks__expired_transaction_check',
95
-            array('EE_Cron_Tasks', 'expired_transaction_check'),
96
-            10,
97
-            1
98
-        );
99
-        // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
100
-        add_action(
101
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
102
-            array('EE_Cron_Tasks', 'clean_out_junk_transactions')
103
-        );
104
-        // logging
105
-        add_action(
106
-            'AHEE__EE_System__load_core_configuration__complete',
107
-            array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
108
-        );
109
-        EE_Registry::instance()->load_lib('Messages_Scheduler');
110
-        //clean out old gateway logs
111
-        add_action(
112
-            'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
113
-            array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * @access protected
120
-     * @return void
121
-     */
122
-    public static function log_scheduled_ee_crons()
123
-    {
124
-        $ee_crons = array(
125
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
126
-            'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
127
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
128
-        );
129
-        $crons    = (array) get_option('cron');
130
-        if (! is_array($crons)) {
131
-            return;
132
-        }
133
-        foreach ($crons as $timestamp => $cron) {
134
-            /** @var array[] $cron */
135
-            foreach ($ee_crons as $ee_cron) {
136
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
137
-                    do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
138
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
139
-                        if (! empty($ee_cron_details['args'])) {
140
-                            do_action(
141
-                                'AHEE_log',
142
-                                __CLASS__,
143
-                                __FUNCTION__,
144
-                                print_r($ee_cron_details['args'], true),
145
-                                "{$ee_cron} args"
146
-                            );
147
-                        }
148
-                    }
149
-                }
150
-            }
151
-        }
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * reschedule_cron_for_transactions_if_maintenance_mode
158
-     * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
159
-     *
160
-     * @param string $cron_task
161
-     * @param array  $TXN_IDs
162
-     * @return bool
163
-     * @throws DomainException
164
-     */
165
-    public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
166
-    {
167
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
168
-            throw new DomainException(
169
-                sprintf(
170
-                    __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
171
-                    $cron_task
172
-                )
173
-            );
174
-        }
175
-        // reschedule the cron if we can't hit the db right now
176
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
177
-            foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
178
-                // ensure $additional_vars is an array
179
-                $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
180
-                // reset cron job for the TXN
181
-                call_user_func_array(
182
-                    array('EE_Cron_Tasks', $cron_task),
183
-                    array_merge(
184
-                        array(
185
-                            time() + (10 * MINUTE_IN_SECONDS),
186
-                            $TXN_ID,
187
-                        ),
188
-                        $additional_vars
189
-                    )
190
-                );
191
-            }
192
-            return true;
193
-        }
194
-        return false;
195
-    }
196
-
197
-
198
-
199
-
200
-    /****************  UPDATE TRANSACTION WITH PAYMENT ****************/
201
-
202
-
203
-
204
-    /**
205
-     * array of TXN IDs and the payment
206
-     *
207
-     * @var array
208
-     */
209
-    protected static $_update_transactions_with_payment = array();
210
-
211
-
212
-    /**
213
-     * schedule_update_transaction_with_payment
214
-     * sets a wp_schedule_single_event() for updating any TXNs that may
215
-     * require updating due to recently received payments
216
-     *
217
-     * @param int $timestamp
218
-     * @param int $TXN_ID
219
-     * @param int $PAY_ID
220
-     */
221
-    public static function schedule_update_transaction_with_payment(
222
-        $timestamp,
223
-        $TXN_ID,
224
-        $PAY_ID
225
-    ) {
226
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
227
-        // validate $TXN_ID and $timestamp
228
-        $TXN_ID    = absint($TXN_ID);
229
-        $timestamp = absint($timestamp);
230
-        if ($TXN_ID && $timestamp) {
231
-            wp_schedule_single_event(
232
-                $timestamp,
233
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
234
-                array($TXN_ID, $PAY_ID)
235
-            );
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * setup_update_for_transaction_with_payment
242
-     * this is the callback for the action hook:
243
-     * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
244
-     * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
245
-     * The passed TXN_ID and associated payment gets added to an array, and then
246
-     * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
247
-     * 'shutdown' which will actually handle the processing of any
248
-     * transactions requiring updating, because doing so now would be too early
249
-     * and the required resources may not be available
250
-     *
251
-     * @param int $TXN_ID
252
-     * @param int $PAY_ID
253
-     */
254
-    public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
255
-    {
256
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
257
-        if (absint($TXN_ID)) {
258
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
259
-            add_action(
260
-                'shutdown',
261
-                array('EE_Cron_Tasks', 'update_transaction_with_payment'),
262
-                5
263
-            );
264
-        }
265
-    }
266
-
267
-
268
-    /**
269
-     * update_transaction_with_payment
270
-     * loops through the self::$_abandoned_transactions array
271
-     * and attempts to finalize any TXNs that have not been completed
272
-     * but have had their sessions expired, most likely due to a user not
273
-     * returning from an off-site payment gateway
274
-     *
275
-     * @throws EE_Error
276
-     * @throws DomainException
277
-     * @throws InvalidDataTypeException
278
-     * @throws InvalidInterfaceException
279
-     * @throws InvalidArgumentException
280
-     * @throws ReflectionException
281
-     * @throws RuntimeException
282
-     */
283
-    public static function update_transaction_with_payment()
284
-    {
285
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
286
-        if (
287
-            // are there any TXNs that need cleaning up ?
288
-            empty(self::$_update_transactions_with_payment)
289
-            // reschedule the cron if we can't hit the db right now
290
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
291
-                'schedule_update_transaction_with_payment',
292
-                self::$_update_transactions_with_payment
293
-            )
294
-        ) {
295
-            return;
296
-        }
297
-        /** @type EE_Payment_Processor $payment_processor */
298
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
299
-        // set revisit flag for payment processor
300
-        $payment_processor->set_revisit();
301
-        // load EEM_Transaction
302
-        EE_Registry::instance()->load_model('Transaction');
303
-        foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
304
-            // reschedule the cron if we can't hit the db right now
305
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
306
-                // reset cron job for updating the TXN
307
-                EE_Cron_Tasks::schedule_update_transaction_with_payment(
308
-                    time() + EE_Cron_Tasks::reschedule_timeout,
309
-                    $TXN_ID,
310
-                    $PAY_ID
311
-                );
312
-                continue;
313
-            }
314
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
315
-            $payment     = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
316
-            // verify transaction
317
-            if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
318
-                // now try to update the TXN with any payments
319
-                $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
320
-            }
321
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
322
-        }
323
-    }
324
-
325
-
326
-
327
-    /************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
328
-
329
-
330
-
331
-    /*****************  EXPIRED TRANSACTION CHECK *****************/
332
-
333
-
334
-
335
-    /**
336
-     * array of TXN IDs
337
-     *
338
-     * @var array
339
-     */
340
-    protected static $_expired_transactions = array();
341
-
342
-
343
-
344
-    /**
345
-     * schedule_expired_transaction_check
346
-     * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
347
-     *
348
-     * @param int $timestamp
349
-     * @param int $TXN_ID
350
-     */
351
-    public static function schedule_expired_transaction_check(
352
-        $timestamp,
353
-        $TXN_ID
354
-    ) {
355
-        // validate $TXN_ID and $timestamp
356
-        $TXN_ID    = absint($TXN_ID);
357
-        $timestamp = absint($timestamp);
358
-        if ($TXN_ID && $timestamp) {
359
-            wp_schedule_single_event(
360
-                $timestamp,
361
-                'AHEE__EE_Cron_Tasks__expired_transaction_check',
362
-                array($TXN_ID)
363
-            );
364
-        }
365
-    }
366
-
367
-
368
-
369
-    /**
370
-     * expired_transaction_check
371
-     * this is the callback for the action hook:
372
-     * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
373
-     * which is utilized by wp_schedule_single_event()
374
-     * in \EED_Single_Page_Checkout::_initialize_transaction().
375
-     * The passed TXN_ID gets added to an array, and then the
376
-     * process_expired_transactions() function is hooked into
377
-     * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
378
-     * processing of any failed transactions, because doing so now would be
379
-     * too early and the required resources may not be available
380
-     *
381
-     * @param int $TXN_ID
382
-     */
383
-    public static function expired_transaction_check($TXN_ID = 0)
384
-    {
385
-        if (absint($TXN_ID)) {
386
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
387
-            add_action(
388
-                'shutdown',
389
-                array('EE_Cron_Tasks', 'process_expired_transactions'),
390
-                5
391
-            );
392
-        }
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * process_expired_transactions
399
-     * loops through the self::$_expired_transactions array and processes any failed TXNs
400
-     *
401
-     * @throws EE_Error
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidInterfaceException
404
-     * @throws InvalidArgumentException
405
-     * @throws ReflectionException
406
-     * @throws DomainException
407
-     * @throws RuntimeException
408
-     */
409
-    public static function process_expired_transactions()
410
-    {
411
-        if (
412
-            // are there any TXNs that need cleaning up ?
413
-            empty(self::$_expired_transactions)
414
-            // reschedule the cron if we can't hit the db right now
415
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
416
-                'schedule_expired_transaction_check',
417
-                self::$_expired_transactions
418
-            )
419
-        ) {
420
-            return;
421
-        }
422
-        /** @type EE_Transaction_Processor $transaction_processor */
423
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
424
-        // set revisit flag for txn processor
425
-        $transaction_processor->set_revisit();
426
-        // load EEM_Transaction
427
-        EE_Registry::instance()->load_model('Transaction');
428
-        foreach (self::$_expired_transactions as $TXN_ID) {
429
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
430
-            // verify transaction and whether it is failed or not
431
-            if ($transaction instanceof EE_Transaction) {
432
-                switch ($transaction->status_ID()) {
433
-                    // Completed TXNs
434
-                    case EEM_Transaction::complete_status_code :
435
-                        do_action(
436
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
437
-                            $transaction
438
-                        );
439
-                        break;
440
-                    // Overpaid TXNs
441
-                    case EEM_Transaction::overpaid_status_code :
442
-                        do_action(
443
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
444
-                            $transaction
445
-                        );
446
-                        break;
447
-                    // Incomplete TXNs
448
-                    case EEM_Transaction::incomplete_status_code :
449
-                        do_action(
450
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
451
-                            $transaction
452
-                        );
453
-                        // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
454
-                        break;
455
-                    // Abandoned TXNs
456
-                    case EEM_Transaction::abandoned_status_code :
457
-                        // run hook before updating transaction, primarily so
458
-                        // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
459
-                        do_action(
460
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
461
-                            $transaction
462
-                        );
463
-                        // don't finalize the TXN if it has already been completed
464
-                        if ($transaction->all_reg_steps_completed() !== true) {
465
-                            /** @type EE_Payment_Processor $payment_processor */
466
-                            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
467
-                            // let's simulate an IPN here which will trigger any notifications that need to go out
468
-                            $payment_processor->update_txn_based_on_payment(
469
-                                $transaction,
470
-                                $transaction->last_payment(),
471
-                                true,
472
-                                true
473
-                            );
474
-                        }
475
-                        break;
476
-                    // Failed TXNs
477
-                    case EEM_Transaction::failed_status_code :
478
-                        do_action(
479
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
480
-                            $transaction
481
-                        );
482
-                        // todo : perform garbage collection here and remove clean_out_junk_transactions()
483
-                        //$registrations = $transaction->registrations();
484
-                        //if ( ! empty( $registrations ) ) {
485
-                        //	foreach ( $registrations as $registration ) {
486
-                        //		if ( $registration instanceof EE_Registration ) {
487
-                        //$delete_registration = true;
488
-                        //if ( $registration->attendee() instanceof EE_Attendee ) {
489
-                        //	$delete_registration = false;
490
-                        //}
491
-                        //if ( $delete_registration ) {
492
-                        //	$registration->delete_permanently();
493
-                        //	$registration->delete_related_permanently();
494
-                        //}
495
-                        //		}
496
-                        //	}
497
-                        //}
498
-                        break;
499
-                }
500
-            }
501
-            unset(self::$_expired_transactions[ $TXN_ID ]);
502
-        }
503
-    }
504
-
505
-
506
-
507
-    /*************  END OF EXPIRED TRANSACTION CHECK  *************/
508
-
509
-
510
-
511
-    /************* START CLEAN UP BOT TRANSACTIONS **********************/
512
-
513
-
514
-
515
-    /**
516
-     * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
517
-     * which is setup during activation to run on an hourly cron
518
-     *
519
-     * @throws EE_Error
520
-     * @throws InvalidArgumentException
521
-     * @throws InvalidDataTypeException
522
-     * @throws InvalidInterfaceException
523
-     * @throws DomainException
524
-     */
525
-    public static function clean_out_junk_transactions()
526
-    {
527
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
528
-            EED_Ticket_Sales_Monitor::reset_reservation_counts();
529
-            EEM_Transaction::instance('')->delete_junk_transactions();
530
-            EEM_Registration::instance('')->delete_registrations_with_no_transaction();
531
-            EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
532
-        }
533
-    }
534
-
535
-
536
-
537
-    /**
538
-     * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
539
-     *
540
-     * @throws EE_Error
541
-     * @throws InvalidDataTypeException
542
-     * @throws InvalidInterfaceException
543
-     * @throws InvalidArgumentException
544
-     */
545
-    public static function clean_out_old_gateway_logs()
546
-    {
547
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
548
-            $time_diff_for_comparison = apply_filters(
549
-                'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
550
-                '-1 week'
551
-            );
552
-            EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
553
-        }
554
-    }
555
-
556
-
557
-    /*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
558
-
559
-
560
-
561
-    /**
562
-     * @var array
563
-     */
564
-    protected static $_abandoned_transactions = array();
565
-
566
-
567
-    /**
568
-     * @deprecated
569
-     * @param int $timestamp
570
-     * @param int $TXN_ID
571
-     */
572
-    public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
573
-    {
574
-        EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
575
-    }
576
-
577
-
578
-    /**
579
-     * @deprecated
580
-     * @param int $TXN_ID
581
-     */
582
-    public static function check_for_abandoned_transactions($TXN_ID = 0)
583
-    {
584
-        EE_Cron_Tasks::expired_transaction_check($TXN_ID);
585
-    }
586
-
587
-
588
-    /**
589
-     * @deprecated
590
-     * @throws EE_Error
591
-     * @throws DomainException
592
-     * @throws InvalidDataTypeException
593
-     * @throws InvalidInterfaceException
594
-     * @throws InvalidArgumentException
595
-     * @throws ReflectionException
596
-     * @throws RuntimeException
597
-     */
598
-    public static function finalize_abandoned_transactions()
599
-    {
600
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
601
-        if (
602
-            // are there any TXNs that need cleaning up ?
603
-            empty(self::$_abandoned_transactions)
604
-            // reschedule the cron if we can't hit the db right now
605
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
606
-                'schedule_expired_transaction_check',
607
-                self::$_abandoned_transactions
608
-            )
609
-        ) {
610
-            return;
611
-        }
612
-        // combine our arrays of transaction IDs
613
-        self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
614
-        // and deal with abandoned transactions here now...
615
-        EE_Cron_Tasks::process_expired_transactions();
616
-    }
617
-
618
-
619
-
620
-    /*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
20
+	/**
21
+	 * WordPress doesn't allow duplicate crons within 10 minutes of the original,
22
+	 * so we'll set our retry time for just over 10 minutes to avoid that
23
+	 */
24
+	const reschedule_timeout = 605;
25
+
26
+
27
+	/**
28
+	 * @var EE_Cron_Tasks
29
+	 */
30
+	private static $_instance;
31
+
32
+
33
+	/**
34
+	 * @return EE_Cron_Tasks
35
+	 * @throws ReflectionException
36
+	 * @throws EE_Error
37
+	 * @throws InvalidArgumentException
38
+	 * @throws InvalidInterfaceException
39
+	 * @throws InvalidDataTypeException
40
+	 */
41
+	public static function instance()
42
+	{
43
+		if (! self::$_instance instanceof EE_Cron_Tasks) {
44
+			self::$_instance = new self();
45
+		}
46
+		return self::$_instance;
47
+	}
48
+
49
+
50
+	/**
51
+	 * @access private
52
+	 * @throws InvalidDataTypeException
53
+	 * @throws InvalidInterfaceException
54
+	 * @throws InvalidArgumentException
55
+	 * @throws EE_Error
56
+	 * @throws ReflectionException
57
+	 */
58
+	private function __construct()
59
+	{
60
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
61
+		// verify that WP Cron is enabled
62
+		if (
63
+			defined('DISABLE_WP_CRON')
64
+			&& DISABLE_WP_CRON
65
+			&& is_admin()
66
+			&& ! get_option('ee_disabled_wp_cron_check')
67
+		) {
68
+			/**
69
+			 * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
70
+			 * config is loaded.
71
+			 * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
72
+			 * wanting to not have this functionality can just register its own action at a priority after this one to
73
+			 * reverse any changes.
74
+			 */
75
+			add_action(
76
+				'AHEE__EE_System__load_core_configuration__complete',
77
+				function ()
78
+				{
79
+					EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
80
+					EE_Registry::instance()->NET_CFG->update_config(true, false);
81
+					add_option('ee_disabled_wp_cron_check', 1, '', false);
82
+				}
83
+			);
84
+		}
85
+		// UPDATE TRANSACTION WITH PAYMENT
86
+		add_action(
87
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
88
+			array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
89
+			10,
90
+			2
91
+		);
92
+		// ABANDONED / EXPIRED TRANSACTION CHECK
93
+		add_action(
94
+			'AHEE__EE_Cron_Tasks__expired_transaction_check',
95
+			array('EE_Cron_Tasks', 'expired_transaction_check'),
96
+			10,
97
+			1
98
+		);
99
+		// CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
100
+		add_action(
101
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
102
+			array('EE_Cron_Tasks', 'clean_out_junk_transactions')
103
+		);
104
+		// logging
105
+		add_action(
106
+			'AHEE__EE_System__load_core_configuration__complete',
107
+			array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
108
+		);
109
+		EE_Registry::instance()->load_lib('Messages_Scheduler');
110
+		//clean out old gateway logs
111
+		add_action(
112
+			'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
113
+			array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @access protected
120
+	 * @return void
121
+	 */
122
+	public static function log_scheduled_ee_crons()
123
+	{
124
+		$ee_crons = array(
125
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
126
+			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
127
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
128
+		);
129
+		$crons    = (array) get_option('cron');
130
+		if (! is_array($crons)) {
131
+			return;
132
+		}
133
+		foreach ($crons as $timestamp => $cron) {
134
+			/** @var array[] $cron */
135
+			foreach ($ee_crons as $ee_cron) {
136
+				if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
137
+					do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
138
+					foreach ($cron[ $ee_cron ] as $ee_cron_details) {
139
+						if (! empty($ee_cron_details['args'])) {
140
+							do_action(
141
+								'AHEE_log',
142
+								__CLASS__,
143
+								__FUNCTION__,
144
+								print_r($ee_cron_details['args'], true),
145
+								"{$ee_cron} args"
146
+							);
147
+						}
148
+					}
149
+				}
150
+			}
151
+		}
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * reschedule_cron_for_transactions_if_maintenance_mode
158
+	 * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
159
+	 *
160
+	 * @param string $cron_task
161
+	 * @param array  $TXN_IDs
162
+	 * @return bool
163
+	 * @throws DomainException
164
+	 */
165
+	public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
166
+	{
167
+		if (! method_exists('EE_Cron_Tasks', $cron_task)) {
168
+			throw new DomainException(
169
+				sprintf(
170
+					__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
171
+					$cron_task
172
+				)
173
+			);
174
+		}
175
+		// reschedule the cron if we can't hit the db right now
176
+		if (! EE_Maintenance_Mode::instance()->models_can_query()) {
177
+			foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
178
+				// ensure $additional_vars is an array
179
+				$additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
180
+				// reset cron job for the TXN
181
+				call_user_func_array(
182
+					array('EE_Cron_Tasks', $cron_task),
183
+					array_merge(
184
+						array(
185
+							time() + (10 * MINUTE_IN_SECONDS),
186
+							$TXN_ID,
187
+						),
188
+						$additional_vars
189
+					)
190
+				);
191
+			}
192
+			return true;
193
+		}
194
+		return false;
195
+	}
196
+
197
+
198
+
199
+
200
+	/****************  UPDATE TRANSACTION WITH PAYMENT ****************/
201
+
202
+
203
+
204
+	/**
205
+	 * array of TXN IDs and the payment
206
+	 *
207
+	 * @var array
208
+	 */
209
+	protected static $_update_transactions_with_payment = array();
210
+
211
+
212
+	/**
213
+	 * schedule_update_transaction_with_payment
214
+	 * sets a wp_schedule_single_event() for updating any TXNs that may
215
+	 * require updating due to recently received payments
216
+	 *
217
+	 * @param int $timestamp
218
+	 * @param int $TXN_ID
219
+	 * @param int $PAY_ID
220
+	 */
221
+	public static function schedule_update_transaction_with_payment(
222
+		$timestamp,
223
+		$TXN_ID,
224
+		$PAY_ID
225
+	) {
226
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
227
+		// validate $TXN_ID and $timestamp
228
+		$TXN_ID    = absint($TXN_ID);
229
+		$timestamp = absint($timestamp);
230
+		if ($TXN_ID && $timestamp) {
231
+			wp_schedule_single_event(
232
+				$timestamp,
233
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
234
+				array($TXN_ID, $PAY_ID)
235
+			);
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * setup_update_for_transaction_with_payment
242
+	 * this is the callback for the action hook:
243
+	 * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
244
+	 * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
245
+	 * The passed TXN_ID and associated payment gets added to an array, and then
246
+	 * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
247
+	 * 'shutdown' which will actually handle the processing of any
248
+	 * transactions requiring updating, because doing so now would be too early
249
+	 * and the required resources may not be available
250
+	 *
251
+	 * @param int $TXN_ID
252
+	 * @param int $PAY_ID
253
+	 */
254
+	public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
255
+	{
256
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
257
+		if (absint($TXN_ID)) {
258
+			self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
259
+			add_action(
260
+				'shutdown',
261
+				array('EE_Cron_Tasks', 'update_transaction_with_payment'),
262
+				5
263
+			);
264
+		}
265
+	}
266
+
267
+
268
+	/**
269
+	 * update_transaction_with_payment
270
+	 * loops through the self::$_abandoned_transactions array
271
+	 * and attempts to finalize any TXNs that have not been completed
272
+	 * but have had their sessions expired, most likely due to a user not
273
+	 * returning from an off-site payment gateway
274
+	 *
275
+	 * @throws EE_Error
276
+	 * @throws DomainException
277
+	 * @throws InvalidDataTypeException
278
+	 * @throws InvalidInterfaceException
279
+	 * @throws InvalidArgumentException
280
+	 * @throws ReflectionException
281
+	 * @throws RuntimeException
282
+	 */
283
+	public static function update_transaction_with_payment()
284
+	{
285
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
286
+		if (
287
+			// are there any TXNs that need cleaning up ?
288
+			empty(self::$_update_transactions_with_payment)
289
+			// reschedule the cron if we can't hit the db right now
290
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
291
+				'schedule_update_transaction_with_payment',
292
+				self::$_update_transactions_with_payment
293
+			)
294
+		) {
295
+			return;
296
+		}
297
+		/** @type EE_Payment_Processor $payment_processor */
298
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
299
+		// set revisit flag for payment processor
300
+		$payment_processor->set_revisit();
301
+		// load EEM_Transaction
302
+		EE_Registry::instance()->load_model('Transaction');
303
+		foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
304
+			// reschedule the cron if we can't hit the db right now
305
+			if (! EE_Maintenance_Mode::instance()->models_can_query()) {
306
+				// reset cron job for updating the TXN
307
+				EE_Cron_Tasks::schedule_update_transaction_with_payment(
308
+					time() + EE_Cron_Tasks::reschedule_timeout,
309
+					$TXN_ID,
310
+					$PAY_ID
311
+				);
312
+				continue;
313
+			}
314
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
315
+			$payment     = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
316
+			// verify transaction
317
+			if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
318
+				// now try to update the TXN with any payments
319
+				$payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
320
+			}
321
+			unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
322
+		}
323
+	}
324
+
325
+
326
+
327
+	/************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
328
+
329
+
330
+
331
+	/*****************  EXPIRED TRANSACTION CHECK *****************/
332
+
333
+
334
+
335
+	/**
336
+	 * array of TXN IDs
337
+	 *
338
+	 * @var array
339
+	 */
340
+	protected static $_expired_transactions = array();
341
+
342
+
343
+
344
+	/**
345
+	 * schedule_expired_transaction_check
346
+	 * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
347
+	 *
348
+	 * @param int $timestamp
349
+	 * @param int $TXN_ID
350
+	 */
351
+	public static function schedule_expired_transaction_check(
352
+		$timestamp,
353
+		$TXN_ID
354
+	) {
355
+		// validate $TXN_ID and $timestamp
356
+		$TXN_ID    = absint($TXN_ID);
357
+		$timestamp = absint($timestamp);
358
+		if ($TXN_ID && $timestamp) {
359
+			wp_schedule_single_event(
360
+				$timestamp,
361
+				'AHEE__EE_Cron_Tasks__expired_transaction_check',
362
+				array($TXN_ID)
363
+			);
364
+		}
365
+	}
366
+
367
+
368
+
369
+	/**
370
+	 * expired_transaction_check
371
+	 * this is the callback for the action hook:
372
+	 * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
373
+	 * which is utilized by wp_schedule_single_event()
374
+	 * in \EED_Single_Page_Checkout::_initialize_transaction().
375
+	 * The passed TXN_ID gets added to an array, and then the
376
+	 * process_expired_transactions() function is hooked into
377
+	 * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
378
+	 * processing of any failed transactions, because doing so now would be
379
+	 * too early and the required resources may not be available
380
+	 *
381
+	 * @param int $TXN_ID
382
+	 */
383
+	public static function expired_transaction_check($TXN_ID = 0)
384
+	{
385
+		if (absint($TXN_ID)) {
386
+			self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
387
+			add_action(
388
+				'shutdown',
389
+				array('EE_Cron_Tasks', 'process_expired_transactions'),
390
+				5
391
+			);
392
+		}
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * process_expired_transactions
399
+	 * loops through the self::$_expired_transactions array and processes any failed TXNs
400
+	 *
401
+	 * @throws EE_Error
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidInterfaceException
404
+	 * @throws InvalidArgumentException
405
+	 * @throws ReflectionException
406
+	 * @throws DomainException
407
+	 * @throws RuntimeException
408
+	 */
409
+	public static function process_expired_transactions()
410
+	{
411
+		if (
412
+			// are there any TXNs that need cleaning up ?
413
+			empty(self::$_expired_transactions)
414
+			// reschedule the cron if we can't hit the db right now
415
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
416
+				'schedule_expired_transaction_check',
417
+				self::$_expired_transactions
418
+			)
419
+		) {
420
+			return;
421
+		}
422
+		/** @type EE_Transaction_Processor $transaction_processor */
423
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
424
+		// set revisit flag for txn processor
425
+		$transaction_processor->set_revisit();
426
+		// load EEM_Transaction
427
+		EE_Registry::instance()->load_model('Transaction');
428
+		foreach (self::$_expired_transactions as $TXN_ID) {
429
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
430
+			// verify transaction and whether it is failed or not
431
+			if ($transaction instanceof EE_Transaction) {
432
+				switch ($transaction->status_ID()) {
433
+					// Completed TXNs
434
+					case EEM_Transaction::complete_status_code :
435
+						do_action(
436
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
437
+							$transaction
438
+						);
439
+						break;
440
+					// Overpaid TXNs
441
+					case EEM_Transaction::overpaid_status_code :
442
+						do_action(
443
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
444
+							$transaction
445
+						);
446
+						break;
447
+					// Incomplete TXNs
448
+					case EEM_Transaction::incomplete_status_code :
449
+						do_action(
450
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
451
+							$transaction
452
+						);
453
+						// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
454
+						break;
455
+					// Abandoned TXNs
456
+					case EEM_Transaction::abandoned_status_code :
457
+						// run hook before updating transaction, primarily so
458
+						// EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
459
+						do_action(
460
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
461
+							$transaction
462
+						);
463
+						// don't finalize the TXN if it has already been completed
464
+						if ($transaction->all_reg_steps_completed() !== true) {
465
+							/** @type EE_Payment_Processor $payment_processor */
466
+							$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
467
+							// let's simulate an IPN here which will trigger any notifications that need to go out
468
+							$payment_processor->update_txn_based_on_payment(
469
+								$transaction,
470
+								$transaction->last_payment(),
471
+								true,
472
+								true
473
+							);
474
+						}
475
+						break;
476
+					// Failed TXNs
477
+					case EEM_Transaction::failed_status_code :
478
+						do_action(
479
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
480
+							$transaction
481
+						);
482
+						// todo : perform garbage collection here and remove clean_out_junk_transactions()
483
+						//$registrations = $transaction->registrations();
484
+						//if ( ! empty( $registrations ) ) {
485
+						//	foreach ( $registrations as $registration ) {
486
+						//		if ( $registration instanceof EE_Registration ) {
487
+						//$delete_registration = true;
488
+						//if ( $registration->attendee() instanceof EE_Attendee ) {
489
+						//	$delete_registration = false;
490
+						//}
491
+						//if ( $delete_registration ) {
492
+						//	$registration->delete_permanently();
493
+						//	$registration->delete_related_permanently();
494
+						//}
495
+						//		}
496
+						//	}
497
+						//}
498
+						break;
499
+				}
500
+			}
501
+			unset(self::$_expired_transactions[ $TXN_ID ]);
502
+		}
503
+	}
504
+
505
+
506
+
507
+	/*************  END OF EXPIRED TRANSACTION CHECK  *************/
508
+
509
+
510
+
511
+	/************* START CLEAN UP BOT TRANSACTIONS **********************/
512
+
513
+
514
+
515
+	/**
516
+	 * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
517
+	 * which is setup during activation to run on an hourly cron
518
+	 *
519
+	 * @throws EE_Error
520
+	 * @throws InvalidArgumentException
521
+	 * @throws InvalidDataTypeException
522
+	 * @throws InvalidInterfaceException
523
+	 * @throws DomainException
524
+	 */
525
+	public static function clean_out_junk_transactions()
526
+	{
527
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
528
+			EED_Ticket_Sales_Monitor::reset_reservation_counts();
529
+			EEM_Transaction::instance('')->delete_junk_transactions();
530
+			EEM_Registration::instance('')->delete_registrations_with_no_transaction();
531
+			EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
532
+		}
533
+	}
534
+
535
+
536
+
537
+	/**
538
+	 * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
539
+	 *
540
+	 * @throws EE_Error
541
+	 * @throws InvalidDataTypeException
542
+	 * @throws InvalidInterfaceException
543
+	 * @throws InvalidArgumentException
544
+	 */
545
+	public static function clean_out_old_gateway_logs()
546
+	{
547
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
548
+			$time_diff_for_comparison = apply_filters(
549
+				'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
550
+				'-1 week'
551
+			);
552
+			EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
553
+		}
554
+	}
555
+
556
+
557
+	/*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
558
+
559
+
560
+
561
+	/**
562
+	 * @var array
563
+	 */
564
+	protected static $_abandoned_transactions = array();
565
+
566
+
567
+	/**
568
+	 * @deprecated
569
+	 * @param int $timestamp
570
+	 * @param int $TXN_ID
571
+	 */
572
+	public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
573
+	{
574
+		EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
575
+	}
576
+
577
+
578
+	/**
579
+	 * @deprecated
580
+	 * @param int $TXN_ID
581
+	 */
582
+	public static function check_for_abandoned_transactions($TXN_ID = 0)
583
+	{
584
+		EE_Cron_Tasks::expired_transaction_check($TXN_ID);
585
+	}
586
+
587
+
588
+	/**
589
+	 * @deprecated
590
+	 * @throws EE_Error
591
+	 * @throws DomainException
592
+	 * @throws InvalidDataTypeException
593
+	 * @throws InvalidInterfaceException
594
+	 * @throws InvalidArgumentException
595
+	 * @throws ReflectionException
596
+	 * @throws RuntimeException
597
+	 */
598
+	public static function finalize_abandoned_transactions()
599
+	{
600
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
601
+		if (
602
+			// are there any TXNs that need cleaning up ?
603
+			empty(self::$_abandoned_transactions)
604
+			// reschedule the cron if we can't hit the db right now
605
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
606
+				'schedule_expired_transaction_check',
607
+				self::$_abandoned_transactions
608
+			)
609
+		) {
610
+			return;
611
+		}
612
+		// combine our arrays of transaction IDs
613
+		self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
614
+		// and deal with abandoned transactions here now...
615
+		EE_Cron_Tasks::process_expired_transactions();
616
+	}
617
+
618
+
619
+
620
+	/*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
621 621
 }
622 622
 // End of file EE_Cron_Tasks.core.php
623 623
 // Location: /EE_Cron_Tasks.core.php
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public static function instance()
42 42
     {
43
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
43
+        if ( ! self::$_instance instanceof EE_Cron_Tasks) {
44 44
             self::$_instance = new self();
45 45
         }
46 46
         return self::$_instance;
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
              */
75 75
             add_action(
76 76
                 'AHEE__EE_System__load_core_configuration__complete',
77
-                function ()
77
+                function()
78 78
                 {
79 79
                     EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
80 80
                     EE_Registry::instance()->NET_CFG->update_config(true, false);
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
             'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
127 127
             'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
128 128
         );
129
-        $crons    = (array) get_option('cron');
130
-        if (! is_array($crons)) {
129
+        $crons = (array) get_option('cron');
130
+        if ( ! is_array($crons)) {
131 131
             return;
132 132
         }
133 133
         foreach ($crons as $timestamp => $cron) {
134 134
             /** @var array[] $cron */
135 135
             foreach ($ee_crons as $ee_cron) {
136
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
136
+                if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) {
137 137
                     do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
138
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
139
-                        if (! empty($ee_cron_details['args'])) {
138
+                    foreach ($cron[$ee_cron] as $ee_cron_details) {
139
+                        if ( ! empty($ee_cron_details['args'])) {
140 140
                             do_action(
141 141
                                 'AHEE_log',
142 142
                                 __CLASS__,
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      */
165 165
     public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
166 166
     {
167
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
167
+        if ( ! method_exists('EE_Cron_Tasks', $cron_task)) {
168 168
             throw new DomainException(
169 169
                 sprintf(
170 170
                     __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
             );
174 174
         }
175 175
         // reschedule the cron if we can't hit the db right now
176
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
176
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
177 177
             foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
178 178
                 // ensure $additional_vars is an array
179 179
                 $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     {
256 256
         do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
257 257
         if (absint($TXN_ID)) {
258
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
258
+            self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID;
259 259
             add_action(
260 260
                 'shutdown',
261 261
                 array('EE_Cron_Tasks', 'update_transaction_with_payment'),
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
         EE_Registry::instance()->load_model('Transaction');
303 303
         foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
304 304
             // reschedule the cron if we can't hit the db right now
305
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
305
+            if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
306 306
                 // reset cron job for updating the TXN
307 307
                 EE_Cron_Tasks::schedule_update_transaction_with_payment(
308 308
                     time() + EE_Cron_Tasks::reschedule_timeout,
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
                 // now try to update the TXN with any payments
319 319
                 $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
320 320
             }
321
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
321
+            unset(self::$_update_transactions_with_payment[$TXN_ID]);
322 322
         }
323 323
     }
324 324
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
     public static function expired_transaction_check($TXN_ID = 0)
384 384
     {
385 385
         if (absint($TXN_ID)) {
386
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
386
+            self::$_expired_transactions[$TXN_ID] = $TXN_ID;
387 387
             add_action(
388 388
                 'shutdown',
389 389
                 array('EE_Cron_Tasks', 'process_expired_transactions'),
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
                         break;
499 499
                 }
500 500
             }
501
-            unset(self::$_expired_transactions[ $TXN_ID ]);
501
+            unset(self::$_expired_transactions[$TXN_ID]);
502 502
         }
503 503
     }
504 504
 
Please login to merge, or discard this patch.
core/db_models/EEM_Transaction.model.php 1 patch
Indentation   +401 added lines, -401 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 require_once(EE_MODELS . 'EEM_Base.model.php');
10 10
 
@@ -20,193 +20,193 @@  discard block
 block discarded – undo
20 20
 class EEM_Transaction extends EEM_Base
21 21
 {
22 22
 
23
-    // private instance of the Transaction object
24
-    protected static $_instance;
25
-
26
-    /**
27
-     * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
28
-     * but payment is pending. This is the state for transactions where payment is promised
29
-     * from an offline gateway.
30
-     */
31
-    //	const open_status_code = 'TPN';
32
-
33
-    /**
34
-     * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
35
-     * either due to a technical reason (server or computer crash during registration),
36
-     *  or some other reason that prevent the collection of any useful contact information from any of the registrants
37
-     */
38
-    const failed_status_code = 'TFL';
39
-
40
-    /**
41
-     * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
42
-     * either due to a technical reason (server or computer crash during registration),
43
-     * or due to an abandoned cart after registrant chose not to complete the registration process
44
-     * HOWEVER...
45
-     * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
46
-     * registrant
47
-     */
48
-    const abandoned_status_code = 'TAB';
49
-
50
-    /**
51
-     * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
52
-     * meaning that monies are still owing: TXN_paid < TXN_total
53
-     */
54
-    const incomplete_status_code = 'TIN';
55
-
56
-    /**
57
-     * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
58
-     * meaning that NO monies are owing: TXN_paid == TXN_total
59
-     */
60
-    const complete_status_code = 'TCM';
61
-
62
-    /**
63
-     *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
64
-     *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
65
-     */
66
-    const overpaid_status_code = 'TOP';
67
-
68
-
69
-    /**
70
-     *    private constructor to prevent direct creation
71
-     *
72
-     * @Constructor
73
-     * @access protected
74
-     *
75
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
76
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
77
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
78
-     *                         timezone in the 'timezone_string' wp option)
79
-     *
80
-     * @return EEM_Transaction
81
-     * @throws \EE_Error
82
-     */
83
-    protected function __construct($timezone)
84
-    {
85
-        $this->singular_item = __('Transaction', 'event_espresso');
86
-        $this->plural_item   = __('Transactions', 'event_espresso');
87
-
88
-        $this->_tables                 = array(
89
-            'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
90
-        );
91
-        $this->_fields                 = array(
92
-            'TransactionTable' => array(
93
-                'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
94
-                'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
95
-                    __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
96
-                    $timezone),
97
-                'TXN_total'        => new EE_Money_Field('TXN_total',
98
-                    __('Total value of Transaction', 'event_espresso'), false, 0),
99
-                'TXN_paid'         => new EE_Money_Field('TXN_paid',
100
-                    __('Amount paid towards transaction to date', 'event_espresso'), false, 0),
101
-                'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
102
-                    false, EEM_Transaction::failed_status_code, 'Status'),
103
-                'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
104
-                    __('Serialized session data', 'event_espresso'), true, ''),
105
-                'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
106
-                    __('Transaction Hash Salt', 'event_espresso'), true, ''),
107
-                'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
108
-                    __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
109
-                'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
110
-                    __('Registration Steps', 'event_espresso'), false, array()),
111
-            )
112
-        );
113
-        $this->_model_relations        = array(
114
-            'Registration'   => new EE_Has_Many_Relation(),
115
-            'Payment'        => new EE_Has_Many_Relation(),
116
-            'Status'         => new EE_Belongs_To_Relation(),
117
-            'Line_Item'      => new EE_Has_Many_Relation(false),
118
-            //you can delete a transaction without needing to delete its line items
119
-            'Payment_Method' => new EE_Belongs_To_Relation(),
120
-            'Message'        => new EE_Has_Many_Relation()
121
-        );
122
-        $this->_model_chain_to_wp_user = 'Registration.Event';
123
-        parent::__construct($timezone);
124
-
125
-    }
126
-
127
-
128
-    /**
129
-     *    txn_status_array
130
-     * get list of transaction statuses
131
-     *
132
-     * @access public
133
-     * @return array
134
-     */
135
-    public static function txn_status_array()
136
-    {
137
-        return apply_filters(
138
-            'FHEE__EEM_Transaction__txn_status_array',
139
-            array(
140
-                EEM_Transaction::overpaid_status_code,
141
-                EEM_Transaction::complete_status_code,
142
-                EEM_Transaction::incomplete_status_code,
143
-                EEM_Transaction::abandoned_status_code,
144
-                EEM_Transaction::failed_status_code,
145
-            )
146
-        );
147
-    }
148
-
149
-    /**
150
-     *        get the revenue per day  for the Transaction Admin page Reports Tab
151
-     *
152
-     * @access        public
153
-     *
154
-     * @param string $period
155
-     *
156
-     * @return \stdClass[]
157
-     */
158
-    public function get_revenue_per_day_report($period = '-1 month')
159
-    {
160
-        $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
161
-            'Y-m-d H:i:s', 'UTC');
162
-
163
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
164
-
165
-        return $this->_get_all_wpdb_results(
166
-            array(
167
-                array(
168
-                    'TXN_timestamp' => array('>=', $sql_date)
169
-                ),
170
-                'group_by' => 'txnDate',
171
-                'order_by' => array('TXN_timestamp' => 'ASC')
172
-            ),
173
-            OBJECT,
174
-            array(
175
-                'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
176
-                'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
177
-            )
178
-        );
179
-    }
180
-
181
-
182
-    /**
183
-     *        get the revenue per event  for the Transaction Admin page Reports Tab
184
-     *
185
-     * @access        public
186
-     *
187
-     * @param string $period
188
-     *
189
-     * @throws \EE_Error
190
-     * @return mixed
191
-     */
192
-    public function get_revenue_per_event_report($period = '-1 month')
193
-    {
194
-        global $wpdb;
195
-        $transaction_table          = $wpdb->prefix . 'esp_transaction';
196
-        $registration_table         = $wpdb->prefix . 'esp_registration';
197
-        $registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
198
-        $event_table                = $wpdb->posts;
199
-        $payment_table              = $wpdb->prefix . 'esp_payment';
200
-        $sql_date                   = date('Y-m-d H:i:s', strtotime($period));
201
-        $approved_payment_status    = EEM_Payment::status_id_approved;
202
-        $extra_event_on_join        = '';
203
-        //exclude events not authored by user if permissions in effect
204
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
205
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
206
-        }
207
-
208
-        return $wpdb->get_results(
209
-            "SELECT
23
+	// private instance of the Transaction object
24
+	protected static $_instance;
25
+
26
+	/**
27
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
28
+	 * but payment is pending. This is the state for transactions where payment is promised
29
+	 * from an offline gateway.
30
+	 */
31
+	//	const open_status_code = 'TPN';
32
+
33
+	/**
34
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
35
+	 * either due to a technical reason (server or computer crash during registration),
36
+	 *  or some other reason that prevent the collection of any useful contact information from any of the registrants
37
+	 */
38
+	const failed_status_code = 'TFL';
39
+
40
+	/**
41
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
42
+	 * either due to a technical reason (server or computer crash during registration),
43
+	 * or due to an abandoned cart after registrant chose not to complete the registration process
44
+	 * HOWEVER...
45
+	 * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
46
+	 * registrant
47
+	 */
48
+	const abandoned_status_code = 'TAB';
49
+
50
+	/**
51
+	 * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
52
+	 * meaning that monies are still owing: TXN_paid < TXN_total
53
+	 */
54
+	const incomplete_status_code = 'TIN';
55
+
56
+	/**
57
+	 * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
58
+	 * meaning that NO monies are owing: TXN_paid == TXN_total
59
+	 */
60
+	const complete_status_code = 'TCM';
61
+
62
+	/**
63
+	 *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
64
+	 *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
65
+	 */
66
+	const overpaid_status_code = 'TOP';
67
+
68
+
69
+	/**
70
+	 *    private constructor to prevent direct creation
71
+	 *
72
+	 * @Constructor
73
+	 * @access protected
74
+	 *
75
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
76
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
77
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
78
+	 *                         timezone in the 'timezone_string' wp option)
79
+	 *
80
+	 * @return EEM_Transaction
81
+	 * @throws \EE_Error
82
+	 */
83
+	protected function __construct($timezone)
84
+	{
85
+		$this->singular_item = __('Transaction', 'event_espresso');
86
+		$this->plural_item   = __('Transactions', 'event_espresso');
87
+
88
+		$this->_tables                 = array(
89
+			'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
90
+		);
91
+		$this->_fields                 = array(
92
+			'TransactionTable' => array(
93
+				'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
94
+				'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
95
+					__('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
96
+					$timezone),
97
+				'TXN_total'        => new EE_Money_Field('TXN_total',
98
+					__('Total value of Transaction', 'event_espresso'), false, 0),
99
+				'TXN_paid'         => new EE_Money_Field('TXN_paid',
100
+					__('Amount paid towards transaction to date', 'event_espresso'), false, 0),
101
+				'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
102
+					false, EEM_Transaction::failed_status_code, 'Status'),
103
+				'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
104
+					__('Serialized session data', 'event_espresso'), true, ''),
105
+				'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
106
+					__('Transaction Hash Salt', 'event_espresso'), true, ''),
107
+				'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
108
+					__("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
109
+				'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
110
+					__('Registration Steps', 'event_espresso'), false, array()),
111
+			)
112
+		);
113
+		$this->_model_relations        = array(
114
+			'Registration'   => new EE_Has_Many_Relation(),
115
+			'Payment'        => new EE_Has_Many_Relation(),
116
+			'Status'         => new EE_Belongs_To_Relation(),
117
+			'Line_Item'      => new EE_Has_Many_Relation(false),
118
+			//you can delete a transaction without needing to delete its line items
119
+			'Payment_Method' => new EE_Belongs_To_Relation(),
120
+			'Message'        => new EE_Has_Many_Relation()
121
+		);
122
+		$this->_model_chain_to_wp_user = 'Registration.Event';
123
+		parent::__construct($timezone);
124
+
125
+	}
126
+
127
+
128
+	/**
129
+	 *    txn_status_array
130
+	 * get list of transaction statuses
131
+	 *
132
+	 * @access public
133
+	 * @return array
134
+	 */
135
+	public static function txn_status_array()
136
+	{
137
+		return apply_filters(
138
+			'FHEE__EEM_Transaction__txn_status_array',
139
+			array(
140
+				EEM_Transaction::overpaid_status_code,
141
+				EEM_Transaction::complete_status_code,
142
+				EEM_Transaction::incomplete_status_code,
143
+				EEM_Transaction::abandoned_status_code,
144
+				EEM_Transaction::failed_status_code,
145
+			)
146
+		);
147
+	}
148
+
149
+	/**
150
+	 *        get the revenue per day  for the Transaction Admin page Reports Tab
151
+	 *
152
+	 * @access        public
153
+	 *
154
+	 * @param string $period
155
+	 *
156
+	 * @return \stdClass[]
157
+	 */
158
+	public function get_revenue_per_day_report($period = '-1 month')
159
+	{
160
+		$sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
161
+			'Y-m-d H:i:s', 'UTC');
162
+
163
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
164
+
165
+		return $this->_get_all_wpdb_results(
166
+			array(
167
+				array(
168
+					'TXN_timestamp' => array('>=', $sql_date)
169
+				),
170
+				'group_by' => 'txnDate',
171
+				'order_by' => array('TXN_timestamp' => 'ASC')
172
+			),
173
+			OBJECT,
174
+			array(
175
+				'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
176
+				'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
177
+			)
178
+		);
179
+	}
180
+
181
+
182
+	/**
183
+	 *        get the revenue per event  for the Transaction Admin page Reports Tab
184
+	 *
185
+	 * @access        public
186
+	 *
187
+	 * @param string $period
188
+	 *
189
+	 * @throws \EE_Error
190
+	 * @return mixed
191
+	 */
192
+	public function get_revenue_per_event_report($period = '-1 month')
193
+	{
194
+		global $wpdb;
195
+		$transaction_table          = $wpdb->prefix . 'esp_transaction';
196
+		$registration_table         = $wpdb->prefix . 'esp_registration';
197
+		$registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
198
+		$event_table                = $wpdb->posts;
199
+		$payment_table              = $wpdb->prefix . 'esp_payment';
200
+		$sql_date                   = date('Y-m-d H:i:s', strtotime($period));
201
+		$approved_payment_status    = EEM_Payment::status_id_approved;
202
+		$extra_event_on_join        = '';
203
+		//exclude events not authored by user if permissions in effect
204
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
205
+			$extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
206
+		}
207
+
208
+		return $wpdb->get_results(
209
+			"SELECT
210 210
 			Transaction_Event.event_name AS event_name,
211 211
 			SUM(Transaction_Event.paid) AS revenue
212 212
 			FROM
@@ -234,223 +234,223 @@  discard block
 block discarded – undo
234 234
 					$extra_event_on_join
235 235
 				) AS Transaction_Event
236 236
 			GROUP BY event_name",
237
-            OBJECT
238
-        );
239
-    }
240
-
241
-
242
-    /**
243
-     * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
244
-     * $_REQUEST global variable. Either way, tries to find the current transaction (through
245
-     * the registration pointed to by reg_url_link), if not returns null
246
-     *
247
-     * @param string $reg_url_link
248
-     *
249
-     * @return EE_Transaction
250
-     */
251
-    public function get_transaction_from_reg_url_link($reg_url_link = '')
252
-    {
253
-        return $this->get_one(array(
254
-            array(
255
-                'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
256
-                    '')
257
-            )
258
-        ));
259
-    }
260
-
261
-
262
-    /**
263
-     * Updates the provided EE_Transaction with all the applicable payments
264
-     * (or fetch the EE_Transaction from its ID)
265
-     *
266
-     * @deprecated
267
-     *
268
-     * @param EE_Transaction|int $transaction_obj_or_id
269
-     * @param boolean            $save_txn whether or not to save the transaction during this function call
270
-     *
271
-     * @return boolean
272
-     * @throws \EE_Error
273
-     */
274
-    public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
275
-    {
276
-        EE_Error::doing_it_wrong(
277
-            __CLASS__ . '::' . __FUNCTION__,
278
-            sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
279
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
280
-            '4.6.0'
281
-        );
282
-        /** @type EE_Transaction_Processor $transaction_processor */
283
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
284
-
285
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
286
-            $this->ensure_is_obj($transaction_obj_or_id)
287
-        );
288
-    }
289
-
290
-    /**
291
-     * Deletes "junk" transactions that were probably added by bots. There might be TONS
292
-     * of these, so we are very careful to NOT select (which the models do even when deleting),
293
-     * and so we only use wpdb directly and only do minimal joins.
294
-     * Transactions are considered "junk" if they're failed for longer than a week.
295
-     * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
296
-     * it, it's probably not junk (regardless of what status it has).
297
-     * The downside to this approach is that is addons are listening for object deletions
298
-     * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
299
-     * to catch these types of deletions.
300
-     *
301
-     * @global WPDB $wpdb
302
-     * @return mixed
303
-     */
304
-    public function delete_junk_transactions()
305
-    {
306
-        /** @type WPDB $wpdb */
307
-        global $wpdb;
308
-        $deleted             = false;
309
-        $time_to_leave_alone = apply_filters(
310
-            'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
311
-            , WEEK_IN_SECONDS
312
-        );
313
-
314
-
315
-        /**
316
-         * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
317
-         * Useful for plugins that want to exclude transactions matching certain query parameters.
318
-         * The query parameters should be in the format accepted by the EEM_Base model queries.
319
-         */
320
-        $ids_query = apply_filters(
321
-            'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
322
-            array(
323
-                0 => array(
324
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
325
-                    'Payment.PAY_ID' => array( 'IS NULL' ),
326
-                    'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
327
-                )
328
-            ),
329
-            $time_to_leave_alone
330
-        );
331
-
332
-
333
-        /**
334
-         * This filter is for when code needs to filter the list of transaction ids that represent transactions
335
-         * about to be deleted based on some other criteria that isn't easily done via the query args filter.
336
-         */
337
-        $txn_ids = apply_filters(
338
-            'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
339
-            EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
340
-            $time_to_leave_alone
341
-        );
342
-        //now that we have the ids to delete
343
-        if (! empty($txn_ids) && is_array($txn_ids)) {
344
-            // first, make sure these TXN's are removed the "ee_locked_transactions" array
345
-            EEM_Transaction::unset_locked_transactions($txn_ids);
346
-            // let's get deletin'...
347
-            // Why no wpdb->prepare?  Because the data is trusted.
348
-            // We got the ids from the original query to get them FROM
349
-            // the db (which is sanitized) so no need to prepare them again.
350
-            $query   = '
237
+			OBJECT
238
+		);
239
+	}
240
+
241
+
242
+	/**
243
+	 * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
244
+	 * $_REQUEST global variable. Either way, tries to find the current transaction (through
245
+	 * the registration pointed to by reg_url_link), if not returns null
246
+	 *
247
+	 * @param string $reg_url_link
248
+	 *
249
+	 * @return EE_Transaction
250
+	 */
251
+	public function get_transaction_from_reg_url_link($reg_url_link = '')
252
+	{
253
+		return $this->get_one(array(
254
+			array(
255
+				'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
256
+					'')
257
+			)
258
+		));
259
+	}
260
+
261
+
262
+	/**
263
+	 * Updates the provided EE_Transaction with all the applicable payments
264
+	 * (or fetch the EE_Transaction from its ID)
265
+	 *
266
+	 * @deprecated
267
+	 *
268
+	 * @param EE_Transaction|int $transaction_obj_or_id
269
+	 * @param boolean            $save_txn whether or not to save the transaction during this function call
270
+	 *
271
+	 * @return boolean
272
+	 * @throws \EE_Error
273
+	 */
274
+	public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
275
+	{
276
+		EE_Error::doing_it_wrong(
277
+			__CLASS__ . '::' . __FUNCTION__,
278
+			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
279
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
280
+			'4.6.0'
281
+		);
282
+		/** @type EE_Transaction_Processor $transaction_processor */
283
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
284
+
285
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
286
+			$this->ensure_is_obj($transaction_obj_or_id)
287
+		);
288
+	}
289
+
290
+	/**
291
+	 * Deletes "junk" transactions that were probably added by bots. There might be TONS
292
+	 * of these, so we are very careful to NOT select (which the models do even when deleting),
293
+	 * and so we only use wpdb directly and only do minimal joins.
294
+	 * Transactions are considered "junk" if they're failed for longer than a week.
295
+	 * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
296
+	 * it, it's probably not junk (regardless of what status it has).
297
+	 * The downside to this approach is that is addons are listening for object deletions
298
+	 * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
299
+	 * to catch these types of deletions.
300
+	 *
301
+	 * @global WPDB $wpdb
302
+	 * @return mixed
303
+	 */
304
+	public function delete_junk_transactions()
305
+	{
306
+		/** @type WPDB $wpdb */
307
+		global $wpdb;
308
+		$deleted             = false;
309
+		$time_to_leave_alone = apply_filters(
310
+			'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
311
+			, WEEK_IN_SECONDS
312
+		);
313
+
314
+
315
+		/**
316
+		 * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
317
+		 * Useful for plugins that want to exclude transactions matching certain query parameters.
318
+		 * The query parameters should be in the format accepted by the EEM_Base model queries.
319
+		 */
320
+		$ids_query = apply_filters(
321
+			'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
322
+			array(
323
+				0 => array(
324
+					'STS_ID'        => EEM_Transaction::failed_status_code,
325
+					'Payment.PAY_ID' => array( 'IS NULL' ),
326
+					'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
327
+				)
328
+			),
329
+			$time_to_leave_alone
330
+		);
331
+
332
+
333
+		/**
334
+		 * This filter is for when code needs to filter the list of transaction ids that represent transactions
335
+		 * about to be deleted based on some other criteria that isn't easily done via the query args filter.
336
+		 */
337
+		$txn_ids = apply_filters(
338
+			'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
339
+			EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
340
+			$time_to_leave_alone
341
+		);
342
+		//now that we have the ids to delete
343
+		if (! empty($txn_ids) && is_array($txn_ids)) {
344
+			// first, make sure these TXN's are removed the "ee_locked_transactions" array
345
+			EEM_Transaction::unset_locked_transactions($txn_ids);
346
+			// let's get deletin'...
347
+			// Why no wpdb->prepare?  Because the data is trusted.
348
+			// We got the ids from the original query to get them FROM
349
+			// the db (which is sanitized) so no need to prepare them again.
350
+			$query   = '
351 351
 				DELETE
352 352
 				FROM ' . $this->table() . '
353 353
 				WHERE
354 354
 					TXN_ID IN ( ' . implode(",", $txn_ids) . ')';
355
-            $deleted = $wpdb->query($query);
356
-        }
357
-        if ($deleted) {
358
-            /**
359
-             * Allows code to do something after the transactions have been deleted.
360
-             */
361
-            do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
362
-        }
363
-
364
-        return $deleted;
365
-    }
366
-
367
-
368
-    /**
369
-     * @param array $transaction_IDs
370
-     *
371
-     * @return bool
372
-     */
373
-    public static function unset_locked_transactions(array $transaction_IDs)
374
-    {
375
-        $locked_transactions = get_option('ee_locked_transactions', array());
376
-        $update              = false;
377
-        foreach ($transaction_IDs as $TXN_ID) {
378
-            if (isset($locked_transactions[$TXN_ID])) {
379
-                unset($locked_transactions[$TXN_ID]);
380
-                $update = true;
381
-            }
382
-        }
383
-        if ($update) {
384
-            update_option('ee_locked_transactions', $locked_transactions);
385
-        }
386
-
387
-        return $update;
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * returns an array of EE_Transaction objects whose timestamp is greater than
394
-     * the current time minus the session lifespan, which defaults to 60 minutes
395
-     *
396
-     * @return EE_Base_Class[]|EE_Transaction[]
397
-     * @throws EE_Error
398
-     * @throws InvalidArgumentException
399
-     * @throws InvalidDataTypeException
400
-     * @throws InvalidInterfaceException
401
-     */
402
-    public function get_transactions_in_progress()
403
-    {
404
-        return $this->_get_transactions_in_progress();
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * returns an array of EE_Transaction objects whose timestamp is less than
411
-     * the current time minus the session lifespan, which defaults to 60 minutes
412
-     *
413
-     * @return EE_Base_Class[]|EE_Transaction[]
414
-     * @throws EE_Error
415
-     * @throws InvalidArgumentException
416
-     * @throws InvalidDataTypeException
417
-     * @throws InvalidInterfaceException
418
-     */
419
-    public function get_transactions_not_in_progress()
420
-    {
421
-        return $this->_get_transactions_in_progress('<=');
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * @param string $comparison
428
-     * @return EE_Base_Class[]|EE_Transaction[]
429
-     * @throws EE_Error
430
-     * @throws InvalidArgumentException
431
-     * @throws InvalidDataTypeException
432
-     * @throws InvalidInterfaceException
433
-     */
434
-    private function _get_transactions_in_progress($comparison = '>=')
435
-    {
436
-        $comparison = $comparison === '>=' || $comparison === '<='
437
-            ? $comparison
438
-            : '>=';
439
-        return $this->get_all(
440
-            array(
441
-                array(
442
-                    'TXN_timestamp' => array(
443
-                        $comparison,
444
-                        time() - EE_Registry::instance()->SSN->lifespan()
445
-                    ),
446
-                    'STS_ID' => array(
447
-                        '!=',
448
-                        EEM_Transaction::complete_status_code
449
-                    ),
450
-                )
451
-            )
452
-        );
453
-    }
355
+			$deleted = $wpdb->query($query);
356
+		}
357
+		if ($deleted) {
358
+			/**
359
+			 * Allows code to do something after the transactions have been deleted.
360
+			 */
361
+			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
362
+		}
363
+
364
+		return $deleted;
365
+	}
366
+
367
+
368
+	/**
369
+	 * @param array $transaction_IDs
370
+	 *
371
+	 * @return bool
372
+	 */
373
+	public static function unset_locked_transactions(array $transaction_IDs)
374
+	{
375
+		$locked_transactions = get_option('ee_locked_transactions', array());
376
+		$update              = false;
377
+		foreach ($transaction_IDs as $TXN_ID) {
378
+			if (isset($locked_transactions[$TXN_ID])) {
379
+				unset($locked_transactions[$TXN_ID]);
380
+				$update = true;
381
+			}
382
+		}
383
+		if ($update) {
384
+			update_option('ee_locked_transactions', $locked_transactions);
385
+		}
386
+
387
+		return $update;
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * returns an array of EE_Transaction objects whose timestamp is greater than
394
+	 * the current time minus the session lifespan, which defaults to 60 minutes
395
+	 *
396
+	 * @return EE_Base_Class[]|EE_Transaction[]
397
+	 * @throws EE_Error
398
+	 * @throws InvalidArgumentException
399
+	 * @throws InvalidDataTypeException
400
+	 * @throws InvalidInterfaceException
401
+	 */
402
+	public function get_transactions_in_progress()
403
+	{
404
+		return $this->_get_transactions_in_progress();
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * returns an array of EE_Transaction objects whose timestamp is less than
411
+	 * the current time minus the session lifespan, which defaults to 60 minutes
412
+	 *
413
+	 * @return EE_Base_Class[]|EE_Transaction[]
414
+	 * @throws EE_Error
415
+	 * @throws InvalidArgumentException
416
+	 * @throws InvalidDataTypeException
417
+	 * @throws InvalidInterfaceException
418
+	 */
419
+	public function get_transactions_not_in_progress()
420
+	{
421
+		return $this->_get_transactions_in_progress('<=');
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * @param string $comparison
428
+	 * @return EE_Base_Class[]|EE_Transaction[]
429
+	 * @throws EE_Error
430
+	 * @throws InvalidArgumentException
431
+	 * @throws InvalidDataTypeException
432
+	 * @throws InvalidInterfaceException
433
+	 */
434
+	private function _get_transactions_in_progress($comparison = '>=')
435
+	{
436
+		$comparison = $comparison === '>=' || $comparison === '<='
437
+			? $comparison
438
+			: '>=';
439
+		return $this->get_all(
440
+			array(
441
+				array(
442
+					'TXN_timestamp' => array(
443
+						$comparison,
444
+						time() - EE_Registry::instance()->SSN->lifespan()
445
+					),
446
+					'STS_ID' => array(
447
+						'!=',
448
+						EEM_Transaction::complete_status_code
449
+					),
450
+				)
451
+			)
452
+		);
453
+	}
454 454
 
455 455
 
456 456
 }
Please login to merge, or discard this patch.
core/domain/entities/contexts/RequestTypeContext.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
     public function __construct($slug, $description)
92 92
     {
93 93
         parent::__construct($slug, $description);
94
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
94
+        if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) {
95 95
             throw new InvalidArgumentException(
96 96
                 sprintf(
97 97
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -20,139 +20,139 @@
 block discarded – undo
20 20
 class RequestTypeContext extends Context
21 21
 {
22 22
 
23
-    /**
24
-     * indicates that the current request involves some form of activation
25
-     */
26
-    const ACTIVATION = 'activation-request';
27
-
28
-    /**
29
-     * indicates that the current request is for the admin but is not being made via AJAX
30
-     */
31
-    const ADMIN = 'non-ajax-admin-request';
32
-
33
-    /**
34
-     * indicates that the current request is for the admin AND is being made via AJAX
35
-     */
36
-    const AJAX_ADMIN = 'admin-ajax-request';
37
-
38
-    /**
39
-     * indicates that the current request is for the frontend AND is being made via AJAX
40
-     */
41
-    const AJAX_FRONT = 'frontend-ajax-request';
42
-
43
-    /**
44
-     * indicates that the current request is being made via AJAX, but is NOT for EE
45
-     */
46
-    const AJAX_OTHER = 'other-ajax-request';
47
-
48
-    /**
49
-     * indicates that the current request is for the EE REST API
50
-     */
51
-    const API = 'rest-api';
52
-
53
-    /**
54
-     * indicates that the current request is from the command line
55
-     */
56
-    const CLI = 'command-line';
57
-
58
-    /**
59
-     * indicates that the current request is for a WP_Cron
60
-     */
61
-    const CRON = 'wp-cron';
62
-
63
-    /**
64
-     * indicates that the current request is for a feed (ie: RSS)
65
-     */
66
-    const FEED = 'feed-request';
67
-
68
-    /**
69
-     * indicates that the current request is for the frontend but is not being made via AJAX
70
-     */
71
-    const FRONTEND = 'non-ajax-frontend-request';
72
-
73
-    /**
74
-     * indicates that the current request is for content that is to be displayed within an iframe
75
-     */
76
-    const IFRAME = 'iframe-request';
77
-
78
-    /**
79
-     * @var boolean $is_activation
80
-     */
81
-    private $is_activation = false;
82
-
83
-    /**
84
-     * @var array $valid_request_types
85
-     */
86
-    private $valid_request_types = array();
87
-
88
-
89
-    /**
90
-     * RequestTypeContext constructor.
91
-     *
92
-     * @param string $slug
93
-     * @param string $description
94
-     * @throws InvalidArgumentException
95
-     */
96
-    public function __construct($slug, $description)
97
-    {
98
-        parent::__construct($slug, $description);
99
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
100
-            throw new InvalidArgumentException(
101
-                sprintf(
102
-                    esc_html__(
103
-                        'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
104
-                        'event_espresso'
105
-                    ),
106
-                    var_export($this->validRequestTypes(), true)
107
-                )
108
-            );
109
-        }
110
-    }
111
-
112
-
113
-    /**
114
-     * @return array
115
-     */
116
-    public function validRequestTypes()
117
-    {
118
-        if (empty($this->valid_request_types)) {
119
-            $this->valid_request_types = apply_filters(
120
-                'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
121
-                array(
122
-                    RequestTypeContext::ACTIVATION,
123
-                    RequestTypeContext::ADMIN,
124
-                    RequestTypeContext::AJAX_ADMIN,
125
-                    RequestTypeContext::AJAX_FRONT,
126
-                    RequestTypeContext::AJAX_OTHER,
127
-                    RequestTypeContext::API,
128
-                    RequestTypeContext::CLI,
129
-                    RequestTypeContext::CRON,
130
-                    RequestTypeContext::FEED,
131
-                    RequestTypeContext::FRONTEND,
132
-                    RequestTypeContext::IFRAME,
133
-                )
134
-            );
135
-        }
136
-        return $this->valid_request_types;
137
-    }
138
-
139
-
140
-    /**
141
-     * @return bool
142
-     */
143
-    public function isActivation()
144
-    {
145
-        return $this->is_activation;
146
-    }
147
-
148
-
149
-    /**
150
-     * @param bool $is_activation
151
-     */
152
-    public function setIsActivation($is_activation)
153
-    {
154
-        $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
155
-    }
23
+	/**
24
+	 * indicates that the current request involves some form of activation
25
+	 */
26
+	const ACTIVATION = 'activation-request';
27
+
28
+	/**
29
+	 * indicates that the current request is for the admin but is not being made via AJAX
30
+	 */
31
+	const ADMIN = 'non-ajax-admin-request';
32
+
33
+	/**
34
+	 * indicates that the current request is for the admin AND is being made via AJAX
35
+	 */
36
+	const AJAX_ADMIN = 'admin-ajax-request';
37
+
38
+	/**
39
+	 * indicates that the current request is for the frontend AND is being made via AJAX
40
+	 */
41
+	const AJAX_FRONT = 'frontend-ajax-request';
42
+
43
+	/**
44
+	 * indicates that the current request is being made via AJAX, but is NOT for EE
45
+	 */
46
+	const AJAX_OTHER = 'other-ajax-request';
47
+
48
+	/**
49
+	 * indicates that the current request is for the EE REST API
50
+	 */
51
+	const API = 'rest-api';
52
+
53
+	/**
54
+	 * indicates that the current request is from the command line
55
+	 */
56
+	const CLI = 'command-line';
57
+
58
+	/**
59
+	 * indicates that the current request is for a WP_Cron
60
+	 */
61
+	const CRON = 'wp-cron';
62
+
63
+	/**
64
+	 * indicates that the current request is for a feed (ie: RSS)
65
+	 */
66
+	const FEED = 'feed-request';
67
+
68
+	/**
69
+	 * indicates that the current request is for the frontend but is not being made via AJAX
70
+	 */
71
+	const FRONTEND = 'non-ajax-frontend-request';
72
+
73
+	/**
74
+	 * indicates that the current request is for content that is to be displayed within an iframe
75
+	 */
76
+	const IFRAME = 'iframe-request';
77
+
78
+	/**
79
+	 * @var boolean $is_activation
80
+	 */
81
+	private $is_activation = false;
82
+
83
+	/**
84
+	 * @var array $valid_request_types
85
+	 */
86
+	private $valid_request_types = array();
87
+
88
+
89
+	/**
90
+	 * RequestTypeContext constructor.
91
+	 *
92
+	 * @param string $slug
93
+	 * @param string $description
94
+	 * @throws InvalidArgumentException
95
+	 */
96
+	public function __construct($slug, $description)
97
+	{
98
+		parent::__construct($slug, $description);
99
+		if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
100
+			throw new InvalidArgumentException(
101
+				sprintf(
102
+					esc_html__(
103
+						'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
104
+						'event_espresso'
105
+					),
106
+					var_export($this->validRequestTypes(), true)
107
+				)
108
+			);
109
+		}
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return array
115
+	 */
116
+	public function validRequestTypes()
117
+	{
118
+		if (empty($this->valid_request_types)) {
119
+			$this->valid_request_types = apply_filters(
120
+				'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
121
+				array(
122
+					RequestTypeContext::ACTIVATION,
123
+					RequestTypeContext::ADMIN,
124
+					RequestTypeContext::AJAX_ADMIN,
125
+					RequestTypeContext::AJAX_FRONT,
126
+					RequestTypeContext::AJAX_OTHER,
127
+					RequestTypeContext::API,
128
+					RequestTypeContext::CLI,
129
+					RequestTypeContext::CRON,
130
+					RequestTypeContext::FEED,
131
+					RequestTypeContext::FRONTEND,
132
+					RequestTypeContext::IFRAME,
133
+				)
134
+			);
135
+		}
136
+		return $this->valid_request_types;
137
+	}
138
+
139
+
140
+	/**
141
+	 * @return bool
142
+	 */
143
+	public function isActivation()
144
+	{
145
+		return $this->is_activation;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @param bool $is_activation
151
+	 */
152
+	public function setIsActivation($is_activation)
153
+	{
154
+		$this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
155
+	}
156 156
 
157 157
 
158 158
 
Please login to merge, or discard this patch.
core/domain/Domain.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,18 +16,18 @@
 block discarded – undo
16 16
 class Domain extends DomainBase
17 17
 {
18 18
 
19
-    /**
20
-     * URL path component used to denote an API request
21
-     */
22
-    const API_NAMESPACE = 'ee/v';
19
+	/**
20
+	 * URL path component used to denote an API request
21
+	 */
22
+	const API_NAMESPACE = 'ee/v';
23 23
 
24
-    /**
25
-     * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
26
-     * Page ui.
27
-     */
28
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
29
-        = 'manual_registration_status_change_from_registration_admin';
24
+	/**
25
+	 * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
26
+	 * Page ui.
27
+	 */
28
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
29
+		= 'manual_registration_status_change_from_registration_admin';
30 30
 
31
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
32
-        = 'manual_registration_status_change_from_registration_admin_and_notify';
31
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
32
+		= 'manual_registration_status_change_from_registration_admin_and_notify';
33 33
 }
Please login to merge, or discard this patch.
core/EE_Psr4AutoloaderInit.core.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,20 +31,20 @@
 block discarded – undo
31 31
 	 * @return \EventEspresso\core\Psr4Autoloader
32 32
 	 */
33 33
 	public function initializeAutoloader() {
34
-        static $initialized = false;
35
-        if ( ! $initialized) {
36
-            // instantiate PSR4 autoloader
34
+		static $initialized = false;
35
+		if ( ! $initialized) {
36
+			// instantiate PSR4 autoloader
37 37
 			espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' );
38
-            EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
39
-            // register the autoloader
40
-            EE_Psr4AutoloaderInit::$psr4_loader->register();
41
-            // register the base directories for the namespace prefix
42
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
43
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
44
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
45
-            $initialized = true;
46
-        }
47
-    }
38
+			EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
39
+			// register the autoloader
40
+			EE_Psr4AutoloaderInit::$psr4_loader->register();
41
+			// register the base directories for the namespace prefix
42
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
43
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
44
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
45
+			$initialized = true;
46
+		}
47
+	}
48 48
 
49 49
 
50 50
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@
 block discarded – undo
34 34
         static $initialized = false;
35 35
         if ( ! $initialized) {
36 36
             // instantiate PSR4 autoloader
37
-			espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' );
37
+			espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php');
38 38
             EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
39 39
             // register the autoloader
40 40
             EE_Psr4AutoloaderInit::$psr4_loader->register();
41 41
             // register the base directories for the namespace prefix
42 42
             EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
43
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
43
+            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch');
44 44
             EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
45 45
             $initialized = true;
46 46
         }
Please login to merge, or discard this patch.
core/services/container/DependencyInjector.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@
 block discarded – undo
182 182
                 is_string($param_name) && isset($ingredients[$param_name])
183 183
             ) {
184 184
                 // attempt to inject the dependency
185
-                $resolved_parameters[$index] = $ingredients[ $param_name ];
185
+                $resolved_parameters[$index] = $ingredients[$param_name];
186 186
             } else if (
187 187
                 // param is specified in the list of ingredients for this Recipe
188 188
                 isset($ingredients[$param_class])
Please login to merge, or discard this patch.
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use UnexpectedValueException;
9 9
 
10 10
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -26,225 +26,225 @@  discard block
 block discarded – undo
26 26
 class DependencyInjector implements InjectorInterface
27 27
 {
28 28
 
29
-    /**
30
-     * @var CoffeePotInterface $coffee_pot
31
-     */
32
-    private $coffee_pot;
33
-
34
-    /**
35
-     * @var EEH_Array $array_helper
36
-     */
37
-    private $array_helper;
38
-
39
-    /**
40
-     * @var ReflectionClass[] $reflectors
41
-     */
42
-    private $reflectors;
43
-
44
-    /**
45
-     * @var ReflectionMethod[] $constructors
46
-     */
47
-    private $constructors;
48
-
49
-    /**
50
-     * @var ReflectionParameter[] $parameters
51
-     */
52
-    private $parameters;
53
-
54
-
55
-
56
-    /**
57
-     * DependencyInjector constructor
58
-     *
59
-     * @param CoffeePotInterface $coffee_pot
60
-     * @param EEH_Array         $array_helper
61
-     */
62
-    public function __construct(CoffeePotInterface $coffee_pot, EEH_Array $array_helper)
63
-    {
64
-        $this->coffee_pot = $coffee_pot;
65
-        $this->array_helper = $array_helper;
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * getReflectionClass
72
-     * checks if a ReflectionClass object has already been generated for a class
73
-     * and returns that instead of creating a new one
74
-     *
75
-     * @param string $class_name
76
-     * @return ReflectionClass
77
-     */
78
-    public function getReflectionClass($class_name)
79
-    {
80
-        if (
81
-            ! isset($this->reflectors[$class_name])
82
-            || ! $this->reflectors[$class_name] instanceof ReflectionClass
83
-        ) {
84
-            $this->reflectors[$class_name] = new ReflectionClass($class_name);
85
-        }
86
-        return $this->reflectors[$class_name];
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     * getConstructor
93
-     * checks if a ReflectionMethod object has already been generated for the class constructor
94
-     * and returns that instead of creating a new one
95
-     *
96
-     * @param ReflectionClass $reflector
97
-     * @return ReflectionMethod
98
-     */
99
-    protected function getConstructor(ReflectionClass $reflector)
100
-    {
101
-        if (
102
-            ! isset($this->constructors[$reflector->getName()])
103
-            || ! $this->constructors[$reflector->getName()] instanceof ReflectionMethod
104
-        ) {
105
-            $this->constructors[$reflector->getName()] = $reflector->getConstructor();
106
-        }
107
-        return $this->constructors[$reflector->getName()];
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * getParameters
114
-     * checks if an array of ReflectionParameter objects has already been generated for the class constructor
115
-     * and returns that instead of creating a new one
116
-     *
117
-     * @param ReflectionMethod $constructor
118
-     * @return ReflectionParameter[]
119
-     */
120
-    protected function getParameters(ReflectionMethod $constructor)
121
-    {
122
-        if ( ! isset($this->parameters[$constructor->class])) {
123
-            $this->parameters[$constructor->class] = $constructor->getParameters();
124
-        }
125
-        return $this->parameters[$constructor->class];
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * resolveDependencies
132
-     * examines the constructor for the requested class to determine
133
-     * if any dependencies exist, and if they can be injected.
134
-     * If so, then those classes will be added to the array of arguments passed to the constructor
135
-     * PLZ NOTE: this is achieved by type hinting the constructor params
136
-     * For example:
137
-     *        if attempting to load a class "Foo" with the following constructor:
138
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
139
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
140
-     *        but only IF they are NOT already present in the incoming arguments array,
141
-     *        and the correct classes can be loaded
142
-     *
143
-     * @param RecipeInterface  $recipe
144
-     * @param ReflectionClass $reflector
145
-     * @param array            $arguments
146
-     * @return array
147
-     * @throws UnexpectedValueException
148
-     */
149
-    public function resolveDependencies(RecipeInterface $recipe, ReflectionClass $reflector, $arguments = array())
150
-    {
151
-        // if arguments array is numerically and sequentially indexed, then we want it to remain as is,
152
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
153
-        $arguments = $this->array_helper->is_array_numerically_and_sequentially_indexed($arguments)
154
-            ? $arguments
155
-            : array($arguments);
156
-        $resolved_parameters = array();
157
-        // let's examine the constructor
158
-        // let's examine the constructor
159
-        $constructor = $this->getConstructor($reflector);
160
-        // whu? huh? nothing?
161
-        if ( ! $constructor) {
162
-            return $arguments;
163
-        }
164
-        // get constructor parameters
165
-        $params = $this->getParameters($constructor);
166
-        if (empty($params)) {
167
-            return $resolved_parameters;
168
-        }
169
-        $ingredients = $recipe->ingredients();
170
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
171
-        $argument_keys = array_keys($arguments);
172
-        // now loop thru all of the constructors expected parameters
173
-        foreach ($params as $index => $param) {
174
-            if ( ! $param instanceof ReflectionParameter) {
175
-                continue;
176
-            }
177
-            // is this a dependency for a specific class ?
178
-            $param_class = $param->getClass() ? $param->getClass()->name : '';
179
-            $param_name = $param->getName() ? $param->getName() : '';
180
-            if (
181
-                // param is not a class but is specified in the list of ingredients for this Recipe
182
-                is_string($param_name) && isset($ingredients[$param_name])
183
-            ) {
184
-                // attempt to inject the dependency
185
-                $resolved_parameters[$index] = $ingredients[ $param_name ];
186
-            } else if (
187
-                // param is specified in the list of ingredients for this Recipe
188
-                isset($ingredients[$param_class])
189
-            ) {
190
-                // attempt to inject the dependency
191
-                $resolved_parameters[$index] = $this->injectDependency($reflector, $ingredients[$param_class]);
192
-            } else if (
193
-                // param is not even a class
194
-                empty($param_class)
195
-                // and something already exists in the incoming arguments for this param
196
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
197
-            ) {
198
-                // add parameter from incoming arguments
199
-                $resolved_parameters[$index] = $arguments[$argument_keys[$index]];
200
-            } else if (
201
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
202
-                ! empty($param_class)
203
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
204
-                && $arguments[$argument_keys[$index]] instanceof $param_class
205
-            ) {
206
-                // add parameter from incoming arguments
207
-                $resolved_parameters[$index] = $arguments[$argument_keys[$index]];
208
-            } else if (
209
-                // parameter is type hinted as a class, and should be injected
210
-                ! empty($param_class)
211
-            ) {
212
-                // attempt to inject the dependency
213
-                $resolved_parameters[$index] = $this->injectDependency($reflector, $param_class);
214
-            } else if ($param->isOptional()) {
215
-                $resolved_parameters[$index] = $param->getDefaultValue();
216
-            } else {
217
-                $resolved_parameters[$index] = null;
218
-            }
219
-        }
220
-        return $resolved_parameters;
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * @param ReflectionClass $reflector
227
-     * @param string          $param_class
228
-     * @return mixed
229
-     * @throws UnexpectedValueException
230
-     */
231
-    private function injectDependency(ReflectionClass $reflector, $param_class)
232
-    {
233
-        $dependency = $this->coffee_pot->brew($param_class);
234
-        if ( ! $dependency instanceof $param_class) {
235
-            throw new UnexpectedValueException(
236
-                sprintf(
237
-                    esc_html__(
238
-                        'Could not resolve dependency for "%1$s" for the "%2$s" class constructor.',
239
-                        'event_espresso'
240
-                    ),
241
-                    $param_class,
242
-                    $reflector->getName()
243
-                )
244
-            );
245
-        }
246
-        return $dependency;
247
-    }
29
+	/**
30
+	 * @var CoffeePotInterface $coffee_pot
31
+	 */
32
+	private $coffee_pot;
33
+
34
+	/**
35
+	 * @var EEH_Array $array_helper
36
+	 */
37
+	private $array_helper;
38
+
39
+	/**
40
+	 * @var ReflectionClass[] $reflectors
41
+	 */
42
+	private $reflectors;
43
+
44
+	/**
45
+	 * @var ReflectionMethod[] $constructors
46
+	 */
47
+	private $constructors;
48
+
49
+	/**
50
+	 * @var ReflectionParameter[] $parameters
51
+	 */
52
+	private $parameters;
53
+
54
+
55
+
56
+	/**
57
+	 * DependencyInjector constructor
58
+	 *
59
+	 * @param CoffeePotInterface $coffee_pot
60
+	 * @param EEH_Array         $array_helper
61
+	 */
62
+	public function __construct(CoffeePotInterface $coffee_pot, EEH_Array $array_helper)
63
+	{
64
+		$this->coffee_pot = $coffee_pot;
65
+		$this->array_helper = $array_helper;
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * getReflectionClass
72
+	 * checks if a ReflectionClass object has already been generated for a class
73
+	 * and returns that instead of creating a new one
74
+	 *
75
+	 * @param string $class_name
76
+	 * @return ReflectionClass
77
+	 */
78
+	public function getReflectionClass($class_name)
79
+	{
80
+		if (
81
+			! isset($this->reflectors[$class_name])
82
+			|| ! $this->reflectors[$class_name] instanceof ReflectionClass
83
+		) {
84
+			$this->reflectors[$class_name] = new ReflectionClass($class_name);
85
+		}
86
+		return $this->reflectors[$class_name];
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 * getConstructor
93
+	 * checks if a ReflectionMethod object has already been generated for the class constructor
94
+	 * and returns that instead of creating a new one
95
+	 *
96
+	 * @param ReflectionClass $reflector
97
+	 * @return ReflectionMethod
98
+	 */
99
+	protected function getConstructor(ReflectionClass $reflector)
100
+	{
101
+		if (
102
+			! isset($this->constructors[$reflector->getName()])
103
+			|| ! $this->constructors[$reflector->getName()] instanceof ReflectionMethod
104
+		) {
105
+			$this->constructors[$reflector->getName()] = $reflector->getConstructor();
106
+		}
107
+		return $this->constructors[$reflector->getName()];
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * getParameters
114
+	 * checks if an array of ReflectionParameter objects has already been generated for the class constructor
115
+	 * and returns that instead of creating a new one
116
+	 *
117
+	 * @param ReflectionMethod $constructor
118
+	 * @return ReflectionParameter[]
119
+	 */
120
+	protected function getParameters(ReflectionMethod $constructor)
121
+	{
122
+		if ( ! isset($this->parameters[$constructor->class])) {
123
+			$this->parameters[$constructor->class] = $constructor->getParameters();
124
+		}
125
+		return $this->parameters[$constructor->class];
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * resolveDependencies
132
+	 * examines the constructor for the requested class to determine
133
+	 * if any dependencies exist, and if they can be injected.
134
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
135
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
136
+	 * For example:
137
+	 *        if attempting to load a class "Foo" with the following constructor:
138
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
139
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
140
+	 *        but only IF they are NOT already present in the incoming arguments array,
141
+	 *        and the correct classes can be loaded
142
+	 *
143
+	 * @param RecipeInterface  $recipe
144
+	 * @param ReflectionClass $reflector
145
+	 * @param array            $arguments
146
+	 * @return array
147
+	 * @throws UnexpectedValueException
148
+	 */
149
+	public function resolveDependencies(RecipeInterface $recipe, ReflectionClass $reflector, $arguments = array())
150
+	{
151
+		// if arguments array is numerically and sequentially indexed, then we want it to remain as is,
152
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
153
+		$arguments = $this->array_helper->is_array_numerically_and_sequentially_indexed($arguments)
154
+			? $arguments
155
+			: array($arguments);
156
+		$resolved_parameters = array();
157
+		// let's examine the constructor
158
+		// let's examine the constructor
159
+		$constructor = $this->getConstructor($reflector);
160
+		// whu? huh? nothing?
161
+		if ( ! $constructor) {
162
+			return $arguments;
163
+		}
164
+		// get constructor parameters
165
+		$params = $this->getParameters($constructor);
166
+		if (empty($params)) {
167
+			return $resolved_parameters;
168
+		}
169
+		$ingredients = $recipe->ingredients();
170
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
171
+		$argument_keys = array_keys($arguments);
172
+		// now loop thru all of the constructors expected parameters
173
+		foreach ($params as $index => $param) {
174
+			if ( ! $param instanceof ReflectionParameter) {
175
+				continue;
176
+			}
177
+			// is this a dependency for a specific class ?
178
+			$param_class = $param->getClass() ? $param->getClass()->name : '';
179
+			$param_name = $param->getName() ? $param->getName() : '';
180
+			if (
181
+				// param is not a class but is specified in the list of ingredients for this Recipe
182
+				is_string($param_name) && isset($ingredients[$param_name])
183
+			) {
184
+				// attempt to inject the dependency
185
+				$resolved_parameters[$index] = $ingredients[ $param_name ];
186
+			} else if (
187
+				// param is specified in the list of ingredients for this Recipe
188
+				isset($ingredients[$param_class])
189
+			) {
190
+				// attempt to inject the dependency
191
+				$resolved_parameters[$index] = $this->injectDependency($reflector, $ingredients[$param_class]);
192
+			} else if (
193
+				// param is not even a class
194
+				empty($param_class)
195
+				// and something already exists in the incoming arguments for this param
196
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
197
+			) {
198
+				// add parameter from incoming arguments
199
+				$resolved_parameters[$index] = $arguments[$argument_keys[$index]];
200
+			} else if (
201
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
202
+				! empty($param_class)
203
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
204
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
205
+			) {
206
+				// add parameter from incoming arguments
207
+				$resolved_parameters[$index] = $arguments[$argument_keys[$index]];
208
+			} else if (
209
+				// parameter is type hinted as a class, and should be injected
210
+				! empty($param_class)
211
+			) {
212
+				// attempt to inject the dependency
213
+				$resolved_parameters[$index] = $this->injectDependency($reflector, $param_class);
214
+			} else if ($param->isOptional()) {
215
+				$resolved_parameters[$index] = $param->getDefaultValue();
216
+			} else {
217
+				$resolved_parameters[$index] = null;
218
+			}
219
+		}
220
+		return $resolved_parameters;
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * @param ReflectionClass $reflector
227
+	 * @param string          $param_class
228
+	 * @return mixed
229
+	 * @throws UnexpectedValueException
230
+	 */
231
+	private function injectDependency(ReflectionClass $reflector, $param_class)
232
+	{
233
+		$dependency = $this->coffee_pot->brew($param_class);
234
+		if ( ! $dependency instanceof $param_class) {
235
+			throw new UnexpectedValueException(
236
+				sprintf(
237
+					esc_html__(
238
+						'Could not resolve dependency for "%1$s" for the "%2$s" class constructor.',
239
+						'event_espresso'
240
+					),
241
+					$param_class,
242
+					$reflector->getName()
243
+				)
244
+			);
245
+		}
246
+		return $dependency;
247
+	}
248 248
 
249 249
 }
250 250
 // End of file DependencyInjector.php
Please login to merge, or discard this patch.
core/services/container/Recipe.php 2 patches
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use RuntimeException;
9 9
 
10 10
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -24,326 +24,326 @@  discard block
 block discarded – undo
24 24
 class Recipe implements RecipeInterface
25 25
 {
26 26
 
27
-    /**
28
-     * A default Recipe to use if none is specified for a class
29
-     */
30
-    const DEFAULT_ID = '*';
31
-
32
-    /**
33
-     * Identifier for the entity class to be constructed.
34
-     * Typically a Fully Qualified Class Name
35
-     *
36
-     * @var string $identifier
37
-     */
38
-    private $identifier;
39
-
40
-    /**
41
-     * Fully Qualified Class Name
42
-     *
43
-     * @var string $fqcn
44
-     */
45
-    private $fqcn;
46
-
47
-    /**
48
-     * a dependency class map array
49
-     * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
50
-     * and that class type hints for an interface, then this property allows you to configure what dependencies
51
-     * get used when instantiating the class.
52
-     * For example:
53
-     *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
54
-     *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
55
-     *  We want one Coffee object to use HonduranBean for its BeanInterface,
56
-     *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
57
-     *  To do this, we need to create two Recipes:
58
-     *      one with an identifier of 'HonduranCoffee' using the following ingredients :
59
-     *          array('BeanInterface' => 'HonduranBean')
60
-     *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
61
-     *          array('BeanInterface' => 'KenyanBean')
62
-     *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
63
-     *  an instance of HonduranBean will get injected for the BeanInterface dependency,
64
-     *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
65
-     *  an instance of KenyanBean will get injected for the BeanInterface dependency
66
-     *
67
-     * @var array $ingredients
68
-     */
69
-    private $ingredients = array();
70
-
71
-    /**
72
-     * one of the class constants from CoffeeShop:
73
-     *  CoffeeMaker::BREW_NEW - creates a new instance
74
-     *  CoffeeMaker::BREW_SHARED - creates a shared instance
75
-     *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
76
-     *
77
-     * @var string $type
78
-     */
79
-    private $type;
80
-
81
-    /**
82
-     * class name aliases - typically a Fully Qualified Interface that the class implements
83
-     * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
84
-     *
85
-     * @var array $filters
86
-     */
87
-    private $filters = array();
88
-
89
-    /**
90
-     * array of full server filepaths to files that may contain the class
91
-     *
92
-     * @var array $paths
93
-     */
94
-    private $paths = array();
95
-
96
-
97
-
98
-    /**
99
-     * Recipe constructor.
100
-     *
101
-     * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
102
-     * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
103
-     * @param array  $ingredients   array of dependencies that can not be resolved automatically,
104
-     *                              used for resolving concrete classes for type hinted interfaces
105
-     *                              for the dependencies of THIS class
106
-     * @param string $type          recipe type: one of the class constants on
107
-     *                              \EventEspresso\core\services\container\CoffeeMaker
108
-     * @param array  $filters       array of class aliases, or class interfaces
109
-     *                              this works somewhat opposite to the $ingredients array above,
110
-     *                              in that this array specifies interfaces or aliases
111
-     *                              that this Recipe can be used for when resolving OTHER class's dependencies
112
-     * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
113
-     *                              then supply a filepath, or array of filepaths, so that it can be included
114
-     * @throws InvalidIdentifierException
115
-     * @throws RuntimeException
116
-     * @throws InvalidInterfaceException
117
-     * @throws InvalidClassException
118
-     * @throws InvalidDataTypeException
119
-     */
120
-    public function __construct(
121
-	    $identifier,
122
-        $fqcn = '',
123
-        array $filters = array(),
124
-        array $ingredients = array(),
125
-	    $type = CoffeeMaker::BREW_NEW,
126
-        array $paths = array()
127
-    )
128
-    {
129
-        $this->setIdentifier($identifier);
130
-        $this->setFilters($filters);
131
-        $this->setIngredients($ingredients);
132
-        $this->setType($type);
133
-        $this->setPaths($paths);
134
-        $this->setFqcn($fqcn);
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * @return string
141
-     */
142
-    public function identifier()
143
-    {
144
-        return $this->identifier;
145
-    }
146
-
147
-
148
-
149
-    /**
150
-     * @return string
151
-     */
152
-    public function fqcn()
153
-    {
154
-        return $this->fqcn;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * @return array
161
-     */
162
-    public function filters()
163
-    {
164
-        return $this->filters;
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * @return array
171
-     */
172
-    public function ingredients()
173
-    {
174
-        return $this->ingredients;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * @return string
181
-     */
182
-    public function type()
183
-    {
184
-        return $this->type;
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * @return array
191
-     */
192
-    public function paths()
193
-    {
194
-        return $this->paths;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * @param  string $identifier Identifier for the entity class that the Recipe applies to
201
-     *                            Typically a Fully Qualified Class Name
202
-     * @throws InvalidIdentifierException
203
-     */
204
-    public function setIdentifier($identifier)
205
-    {
206
-        if ( ! is_string($identifier) || empty($identifier)) {
207
-            throw new InvalidIdentifierException(
208
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
209
-                __('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
210
-            );
211
-        }
212
-        $this->identifier = $identifier;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * Ensures incoming string is a valid Fully Qualified Class Name,
219
-     * except if this is the default wildcard Recipe ( * ),
220
-     * or it's NOT an actual FQCN because the Recipe is using filepaths
221
-     * for classes that are not PSR-4 compatible
222
-     * PLZ NOTE:
223
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
224
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
225
-     *
226
-     * @param string $fqcn
227
-     * @throws InvalidDataTypeException
228
-     * @throws InvalidClassException
229
-     * @throws InvalidInterfaceException
230
-     */
231
-    public function setFqcn($fqcn)
232
-    {
233
-	    $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
234
-        if ( ! is_string($fqcn)) {
235
-            throw new InvalidDataTypeException(
236
-                '$fqcn',
237
-                is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
238
-                __('string (Fully\Qualified\ClassName)', 'event_espresso')
239
-            );
240
-        }
241
-        $fqcn = ltrim($fqcn, '\\');
242
-        if (
243
-            $fqcn !== Recipe::DEFAULT_ID
244
-            && ! empty($fqcn)
245
-            && empty($this->paths)
246
-            && ! (class_exists($fqcn) || interface_exists($fqcn))
247
-        ) {
248
-            throw new InvalidClassException($fqcn);
249
-        }
250
-        $this->fqcn = $fqcn;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
257
-     *                              example:
258
-     *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
259
-     * @throws InvalidDataTypeException
260
-     */
261
-    public function setIngredients(array $ingredients)
262
-    {
263
-        if (empty($ingredients)) {
264
-            return;
265
-        }
266
-        if ( ! is_array($ingredients)) {
267
-            throw new InvalidDataTypeException(
268
-                '$ingredients',
269
-                is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
270
-                __('array of class dependencies', 'event_espresso')
271
-            );
272
-        }
273
-        $this->ingredients = array_merge($this->ingredients, $ingredients);
274
-    }
275
-
276
-
277
-    /**
278
-     * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
279
-     * @throws InvalidIdentifierException
280
-     */
281
-    public function setType($type = CoffeeMaker::BREW_NEW)
282
-    {
283
-        $this->type = CoffeeMaker::validateType($type);
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * @param array $filters    an array of filters where keys are the aliases and values are the FQCNs
290
-     *                          example:
291
-     *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
292
-     * @throws InvalidDataTypeException
293
-     */
294
-    public function setFilters(array $filters)
295
-    {
296
-        if (empty($filters)) {
297
-            return;
298
-        }
299
-        if ( ! is_array($filters)) {
300
-            throw new InvalidDataTypeException(
301
-                '$filters',
302
-                is_object($filters) ? get_class($filters) : gettype($filters),
303
-                __('array of class aliases', 'event_espresso')
304
-            );
305
-        }
306
-        $this->filters = array_merge($this->filters, $filters);
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * Ensures incoming paths is a valid filepath, or array of valid filepaths,
313
-     * and merges them in with any existing filepaths
314
-     * PLZ NOTE:
315
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
316
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
317
-     *
318
-     * @param string|array $paths
319
-     * @throws RuntimeException
320
-     * @throws InvalidDataTypeException
321
-     */
322
-    public function setPaths($paths = array())
323
-    {
324
-        if (empty($paths)) {
325
-            return;
326
-        }
327
-        if ( ! (is_string($paths) || is_array($paths))) {
328
-            throw new InvalidDataTypeException(
329
-                '$path',
330
-                is_object($paths) ? get_class($paths) : gettype($paths),
331
-                __('string or array of strings (full server filepath(s))', 'event_espresso')
332
-            );
333
-        }
334
-        $paths = (array)$paths;
335
-        foreach ($paths as $path) {
336
-            if (strpos($path, '*') === false && ! is_readable($path)) {
337
-                throw new RuntimeException(
338
-                    sprintf(
339
-                        __('The following filepath is not readable: "%1$s"', 'event_espresso'),
340
-                        $path
341
-                    )
342
-                );
343
-            }
344
-        }
345
-        $this->paths = array_merge($this->paths, $paths);
346
-    }
27
+	/**
28
+	 * A default Recipe to use if none is specified for a class
29
+	 */
30
+	const DEFAULT_ID = '*';
31
+
32
+	/**
33
+	 * Identifier for the entity class to be constructed.
34
+	 * Typically a Fully Qualified Class Name
35
+	 *
36
+	 * @var string $identifier
37
+	 */
38
+	private $identifier;
39
+
40
+	/**
41
+	 * Fully Qualified Class Name
42
+	 *
43
+	 * @var string $fqcn
44
+	 */
45
+	private $fqcn;
46
+
47
+	/**
48
+	 * a dependency class map array
49
+	 * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
50
+	 * and that class type hints for an interface, then this property allows you to configure what dependencies
51
+	 * get used when instantiating the class.
52
+	 * For example:
53
+	 *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
54
+	 *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
55
+	 *  We want one Coffee object to use HonduranBean for its BeanInterface,
56
+	 *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
57
+	 *  To do this, we need to create two Recipes:
58
+	 *      one with an identifier of 'HonduranCoffee' using the following ingredients :
59
+	 *          array('BeanInterface' => 'HonduranBean')
60
+	 *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
61
+	 *          array('BeanInterface' => 'KenyanBean')
62
+	 *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
63
+	 *  an instance of HonduranBean will get injected for the BeanInterface dependency,
64
+	 *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
65
+	 *  an instance of KenyanBean will get injected for the BeanInterface dependency
66
+	 *
67
+	 * @var array $ingredients
68
+	 */
69
+	private $ingredients = array();
70
+
71
+	/**
72
+	 * one of the class constants from CoffeeShop:
73
+	 *  CoffeeMaker::BREW_NEW - creates a new instance
74
+	 *  CoffeeMaker::BREW_SHARED - creates a shared instance
75
+	 *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
76
+	 *
77
+	 * @var string $type
78
+	 */
79
+	private $type;
80
+
81
+	/**
82
+	 * class name aliases - typically a Fully Qualified Interface that the class implements
83
+	 * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
84
+	 *
85
+	 * @var array $filters
86
+	 */
87
+	private $filters = array();
88
+
89
+	/**
90
+	 * array of full server filepaths to files that may contain the class
91
+	 *
92
+	 * @var array $paths
93
+	 */
94
+	private $paths = array();
95
+
96
+
97
+
98
+	/**
99
+	 * Recipe constructor.
100
+	 *
101
+	 * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
102
+	 * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
103
+	 * @param array  $ingredients   array of dependencies that can not be resolved automatically,
104
+	 *                              used for resolving concrete classes for type hinted interfaces
105
+	 *                              for the dependencies of THIS class
106
+	 * @param string $type          recipe type: one of the class constants on
107
+	 *                              \EventEspresso\core\services\container\CoffeeMaker
108
+	 * @param array  $filters       array of class aliases, or class interfaces
109
+	 *                              this works somewhat opposite to the $ingredients array above,
110
+	 *                              in that this array specifies interfaces or aliases
111
+	 *                              that this Recipe can be used for when resolving OTHER class's dependencies
112
+	 * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
113
+	 *                              then supply a filepath, or array of filepaths, so that it can be included
114
+	 * @throws InvalidIdentifierException
115
+	 * @throws RuntimeException
116
+	 * @throws InvalidInterfaceException
117
+	 * @throws InvalidClassException
118
+	 * @throws InvalidDataTypeException
119
+	 */
120
+	public function __construct(
121
+		$identifier,
122
+		$fqcn = '',
123
+		array $filters = array(),
124
+		array $ingredients = array(),
125
+		$type = CoffeeMaker::BREW_NEW,
126
+		array $paths = array()
127
+	)
128
+	{
129
+		$this->setIdentifier($identifier);
130
+		$this->setFilters($filters);
131
+		$this->setIngredients($ingredients);
132
+		$this->setType($type);
133
+		$this->setPaths($paths);
134
+		$this->setFqcn($fqcn);
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * @return string
141
+	 */
142
+	public function identifier()
143
+	{
144
+		return $this->identifier;
145
+	}
146
+
147
+
148
+
149
+	/**
150
+	 * @return string
151
+	 */
152
+	public function fqcn()
153
+	{
154
+		return $this->fqcn;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * @return array
161
+	 */
162
+	public function filters()
163
+	{
164
+		return $this->filters;
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * @return array
171
+	 */
172
+	public function ingredients()
173
+	{
174
+		return $this->ingredients;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * @return string
181
+	 */
182
+	public function type()
183
+	{
184
+		return $this->type;
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 * @return array
191
+	 */
192
+	public function paths()
193
+	{
194
+		return $this->paths;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * @param  string $identifier Identifier for the entity class that the Recipe applies to
201
+	 *                            Typically a Fully Qualified Class Name
202
+	 * @throws InvalidIdentifierException
203
+	 */
204
+	public function setIdentifier($identifier)
205
+	{
206
+		if ( ! is_string($identifier) || empty($identifier)) {
207
+			throw new InvalidIdentifierException(
208
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
209
+				__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
210
+			);
211
+		}
212
+		$this->identifier = $identifier;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * Ensures incoming string is a valid Fully Qualified Class Name,
219
+	 * except if this is the default wildcard Recipe ( * ),
220
+	 * or it's NOT an actual FQCN because the Recipe is using filepaths
221
+	 * for classes that are not PSR-4 compatible
222
+	 * PLZ NOTE:
223
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
224
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
225
+	 *
226
+	 * @param string $fqcn
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws InvalidClassException
229
+	 * @throws InvalidInterfaceException
230
+	 */
231
+	public function setFqcn($fqcn)
232
+	{
233
+		$fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
234
+		if ( ! is_string($fqcn)) {
235
+			throw new InvalidDataTypeException(
236
+				'$fqcn',
237
+				is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
238
+				__('string (Fully\Qualified\ClassName)', 'event_espresso')
239
+			);
240
+		}
241
+		$fqcn = ltrim($fqcn, '\\');
242
+		if (
243
+			$fqcn !== Recipe::DEFAULT_ID
244
+			&& ! empty($fqcn)
245
+			&& empty($this->paths)
246
+			&& ! (class_exists($fqcn) || interface_exists($fqcn))
247
+		) {
248
+			throw new InvalidClassException($fqcn);
249
+		}
250
+		$this->fqcn = $fqcn;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
257
+	 *                              example:
258
+	 *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
259
+	 * @throws InvalidDataTypeException
260
+	 */
261
+	public function setIngredients(array $ingredients)
262
+	{
263
+		if (empty($ingredients)) {
264
+			return;
265
+		}
266
+		if ( ! is_array($ingredients)) {
267
+			throw new InvalidDataTypeException(
268
+				'$ingredients',
269
+				is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
270
+				__('array of class dependencies', 'event_espresso')
271
+			);
272
+		}
273
+		$this->ingredients = array_merge($this->ingredients, $ingredients);
274
+	}
275
+
276
+
277
+	/**
278
+	 * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
279
+	 * @throws InvalidIdentifierException
280
+	 */
281
+	public function setType($type = CoffeeMaker::BREW_NEW)
282
+	{
283
+		$this->type = CoffeeMaker::validateType($type);
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * @param array $filters    an array of filters where keys are the aliases and values are the FQCNs
290
+	 *                          example:
291
+	 *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
292
+	 * @throws InvalidDataTypeException
293
+	 */
294
+	public function setFilters(array $filters)
295
+	{
296
+		if (empty($filters)) {
297
+			return;
298
+		}
299
+		if ( ! is_array($filters)) {
300
+			throw new InvalidDataTypeException(
301
+				'$filters',
302
+				is_object($filters) ? get_class($filters) : gettype($filters),
303
+				__('array of class aliases', 'event_espresso')
304
+			);
305
+		}
306
+		$this->filters = array_merge($this->filters, $filters);
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * Ensures incoming paths is a valid filepath, or array of valid filepaths,
313
+	 * and merges them in with any existing filepaths
314
+	 * PLZ NOTE:
315
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
316
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
317
+	 *
318
+	 * @param string|array $paths
319
+	 * @throws RuntimeException
320
+	 * @throws InvalidDataTypeException
321
+	 */
322
+	public function setPaths($paths = array())
323
+	{
324
+		if (empty($paths)) {
325
+			return;
326
+		}
327
+		if ( ! (is_string($paths) || is_array($paths))) {
328
+			throw new InvalidDataTypeException(
329
+				'$path',
330
+				is_object($paths) ? get_class($paths) : gettype($paths),
331
+				__('string or array of strings (full server filepath(s))', 'event_espresso')
332
+			);
333
+		}
334
+		$paths = (array)$paths;
335
+		foreach ($paths as $path) {
336
+			if (strpos($path, '*') === false && ! is_readable($path)) {
337
+				throw new RuntimeException(
338
+					sprintf(
339
+						__('The following filepath is not readable: "%1$s"', 'event_espresso'),
340
+						$path
341
+					)
342
+				);
343
+			}
344
+		}
345
+		$this->paths = array_merge($this->paths, $paths);
346
+	}
347 347
 
348 348
 
349 349
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -331,7 +331,7 @@
 block discarded – undo
331 331
                 __('string or array of strings (full server filepath(s))', 'event_espresso')
332 332
             );
333 333
         }
334
-        $paths = (array)$paths;
334
+        $paths = (array) $paths;
335 335
         foreach ($paths as $path) {
336 336
             if (strpos($path, '*') === false && ! is_readable($path)) {
337 337
                 throw new RuntimeException(
Please login to merge, or discard this patch.
core/db_classes/EE_Attendee.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
     /**
604 604
      * returns any events attached to this attendee ($_Event property);
605 605
      *
606
-     * @return array
606
+     * @return EE_Base_Class[]
607 607
      * @throws EE_Error
608 608
      */
609 609
     public function events()
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
      * used to save the billing info
619 619
      *
620 620
      * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
621
-     * @return EE_Form_Section_Proper|null
621
+     * @return null|EE_Billing_Info_Form
622 622
      * @throws EE_Error
623 623
      */
624 624
     public function billing_info_for_payment_method($payment_method)
Please login to merge, or discard this patch.
Indentation   +730 added lines, -730 removed lines patch added patch discarded remove patch
@@ -27,734 +27,734 @@
 block discarded – undo
27 27
 class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee
28 28
 {
29 29
 
30
-    /**
31
-     * Sets some dynamic defaults
32
-     *
33
-     * @param array  $fieldValues
34
-     * @param bool   $bydb
35
-     * @param string $timezone
36
-     * @param array  $date_formats
37
-     * @throws EE_Error
38
-     */
39
-    protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
40
-    {
41
-        if (! isset($fieldValues['ATT_full_name'])) {
42
-            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
43
-            $lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
44
-            $fieldValues['ATT_full_name'] = $fname . $lname;
45
-        }
46
-        if (! isset($fieldValues['ATT_slug'])) {
47
-            //			$fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
48
-            $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
49
-        }
50
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
51
-            $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
52
-        }
53
-        parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
54
-    }
55
-
56
-
57
-    /**
58
-     * @param array  $props_n_values          incoming values
59
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
60
-     *                                        used.)
61
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
62
-     *                                        date_format and the second value is the time format
63
-     * @return EE_Attendee
64
-     * @throws EE_Error
65
-     */
66
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
67
-    {
68
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
69
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
70
-    }
71
-
72
-
73
-    /**
74
-     * @param array  $props_n_values  incoming values from the database
75
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
76
-     *                                the website will be used.
77
-     * @return EE_Attendee
78
-     */
79
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
80
-    {
81
-        return new self($props_n_values, true, $timezone);
82
-    }
83
-
84
-
85
-    /**
86
-     *        Set Attendee First Name
87
-     *
88
-     * @access        public
89
-     * @param string $fname
90
-     * @throws EE_Error
91
-     */
92
-    public function set_fname($fname = '')
93
-    {
94
-        $this->set('ATT_fname', $fname);
95
-    }
96
-
97
-
98
-    /**
99
-     *        Set Attendee Last Name
100
-     *
101
-     * @access        public
102
-     * @param string $lname
103
-     * @throws EE_Error
104
-     */
105
-    public function set_lname($lname = '')
106
-    {
107
-        $this->set('ATT_lname', $lname);
108
-    }
109
-
110
-
111
-    /**
112
-     *        Set Attendee Address
113
-     *
114
-     * @access        public
115
-     * @param string $address
116
-     * @throws EE_Error
117
-     */
118
-    public function set_address($address = '')
119
-    {
120
-        $this->set('ATT_address', $address);
121
-    }
122
-
123
-
124
-    /**
125
-     *        Set Attendee Address2
126
-     *
127
-     * @access        public
128
-     * @param        string $address2
129
-     * @throws EE_Error
130
-     */
131
-    public function set_address2($address2 = '')
132
-    {
133
-        $this->set('ATT_address2', $address2);
134
-    }
135
-
136
-
137
-    /**
138
-     *        Set Attendee City
139
-     *
140
-     * @access        public
141
-     * @param        string $city
142
-     * @throws EE_Error
143
-     */
144
-    public function set_city($city = '')
145
-    {
146
-        $this->set('ATT_city', $city);
147
-    }
148
-
149
-
150
-    /**
151
-     *        Set Attendee State ID
152
-     *
153
-     * @access        public
154
-     * @param        int $STA_ID
155
-     * @throws EE_Error
156
-     */
157
-    public function set_state($STA_ID = 0)
158
-    {
159
-        $this->set('STA_ID', $STA_ID);
160
-    }
161
-
162
-
163
-    /**
164
-     *        Set Attendee Country ISO Code
165
-     *
166
-     * @access        public
167
-     * @param        string $CNT_ISO
168
-     * @throws EE_Error
169
-     */
170
-    public function set_country($CNT_ISO = '')
171
-    {
172
-        $this->set('CNT_ISO', $CNT_ISO);
173
-    }
174
-
175
-
176
-    /**
177
-     *        Set Attendee Zip/Postal Code
178
-     *
179
-     * @access        public
180
-     * @param        string $zip
181
-     * @throws EE_Error
182
-     */
183
-    public function set_zip($zip = '')
184
-    {
185
-        $this->set('ATT_zip', $zip);
186
-    }
187
-
188
-
189
-    /**
190
-     *        Set Attendee Email Address
191
-     *
192
-     * @access        public
193
-     * @param        string $email
194
-     * @throws EE_Error
195
-     */
196
-    public function set_email($email = '')
197
-    {
198
-        $this->set('ATT_email', $email);
199
-    }
200
-
201
-
202
-    /**
203
-     *        Set Attendee Phone
204
-     *
205
-     * @access        public
206
-     * @param        string $phone
207
-     * @throws EE_Error
208
-     */
209
-    public function set_phone($phone = '')
210
-    {
211
-        $this->set('ATT_phone', $phone);
212
-    }
213
-
214
-
215
-    /**
216
-     *        set deleted
217
-     *
218
-     * @access        public
219
-     * @param        bool $ATT_deleted
220
-     * @throws EE_Error
221
-     */
222
-    public function set_deleted($ATT_deleted = false)
223
-    {
224
-        $this->set('ATT_deleted', $ATT_deleted);
225
-    }
226
-
227
-
228
-    /**
229
-     * Returns the value for the post_author id saved with the cpt
230
-     *
231
-     * @since 4.5.0
232
-     * @return int
233
-     * @throws EE_Error
234
-     */
235
-    public function wp_user()
236
-    {
237
-        return $this->get('ATT_author');
238
-    }
239
-
240
-
241
-    /**
242
-     *        get Attendee First Name
243
-     *
244
-     * @access        public
245
-     * @return string
246
-     * @throws EE_Error
247
-     */
248
-    public function fname()
249
-    {
250
-        return $this->get('ATT_fname');
251
-    }
252
-
253
-
254
-    /**
255
-     * echoes out the attendee's first name
256
-     *
257
-     * @return void
258
-     * @throws EE_Error
259
-     */
260
-    public function e_full_name()
261
-    {
262
-        echo $this->full_name();
263
-    }
264
-
265
-
266
-    /**
267
-     * Returns the first and last name concatenated together with a space.
268
-     *
269
-     * @param bool $apply_html_entities
270
-     * @return string
271
-     * @throws EE_Error
272
-     */
273
-    public function full_name($apply_html_entities = false)
274
-    {
275
-        $full_name = array(
276
-            $this->fname(),
277
-            $this->lname(),
278
-        );
279
-        $full_name = array_filter($full_name);
280
-        $full_name = implode(' ', $full_name);
281
-        return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name;
282
-    }
283
-
284
-
285
-    /**
286
-     * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless
287
-     * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this
288
-     * attendee.
289
-     *
290
-     * @param bool $apply_html_entities
291
-     * @return string
292
-     * @throws EE_Error
293
-     */
294
-    public function ATT_full_name($apply_html_entities = false)
295
-    {
296
-        return $apply_html_entities
297
-            ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8')
298
-            : $this->get('ATT_full_name');
299
-    }
300
-
301
-
302
-    /**
303
-     *        get Attendee Last Name
304
-     *
305
-     * @access        public
306
-     * @return string
307
-     * @throws EE_Error
308
-     */
309
-    public function lname()
310
-    {
311
-        return $this->get('ATT_lname');
312
-    }
313
-
314
-
315
-    /**
316
-     * Gets the attendee's full address as an array so client code can decide hwo to display it
317
-     *
318
-     * @return array numerically indexed, with each part of the address that is known.
319
-     * Eg, if the user only responded to state and country,
320
-     * it would be array(0=>'Alabama',1=>'USA')
321
-     * @return array
322
-     * @throws EE_Error
323
-     */
324
-    public function full_address_as_array()
325
-    {
326
-        $full_address_array     = array();
327
-        $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
328
-        foreach ($initial_address_fields as $address_field_name) {
329
-            $address_fields_value = $this->get($address_field_name);
330
-            if (! empty($address_fields_value)) {
331
-                $full_address_array[] = $address_fields_value;
332
-            }
333
-        }
334
-        //now handle state and country
335
-        $state_obj = $this->state_obj();
336
-        if ($state_obj instanceof EE_State) {
337
-            $full_address_array[] = $state_obj->name();
338
-        }
339
-        $country_obj = $this->country_obj();
340
-        if ($country_obj instanceof EE_Country) {
341
-            $full_address_array[] = $country_obj->name();
342
-        }
343
-        //lastly get the xip
344
-        $zip_value = $this->zip();
345
-        if (! empty($zip_value)) {
346
-            $full_address_array[] = $zip_value;
347
-        }
348
-        return $full_address_array;
349
-    }
350
-
351
-
352
-    /**
353
-     *        get Attendee Address
354
-     *
355
-     * @return string
356
-     * @throws EE_Error
357
-     */
358
-    public function address()
359
-    {
360
-        return $this->get('ATT_address');
361
-    }
362
-
363
-
364
-    /**
365
-     *        get Attendee Address2
366
-     *
367
-     * @return string
368
-     * @throws EE_Error
369
-     */
370
-    public function address2()
371
-    {
372
-        return $this->get('ATT_address2');
373
-    }
374
-
375
-
376
-    /**
377
-     *        get Attendee City
378
-     *
379
-     * @return string
380
-     * @throws EE_Error
381
-     */
382
-    public function city()
383
-    {
384
-        return $this->get('ATT_city');
385
-    }
386
-
387
-
388
-    /**
389
-     *        get Attendee State ID
390
-     *
391
-     * @return string
392
-     * @throws EE_Error
393
-     */
394
-    public function state_ID()
395
-    {
396
-        return $this->get('STA_ID');
397
-    }
398
-
399
-
400
-    /**
401
-     * @return string
402
-     * @throws EE_Error
403
-     */
404
-    public function state_abbrev()
405
-    {
406
-        return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
407
-    }
408
-
409
-
410
-    /**
411
-     * Gets the state set to this attendee
412
-     *
413
-     * @return EE_State
414
-     * @throws EE_Error
415
-     */
416
-    public function state_obj()
417
-    {
418
-        return $this->get_first_related('State');
419
-    }
420
-
421
-
422
-    /**
423
-     * Returns the state's name, otherwise 'Unknown'
424
-     *
425
-     * @return string
426
-     * @throws EE_Error
427
-     */
428
-    public function state_name()
429
-    {
430
-        if ($this->state_obj()) {
431
-            return $this->state_obj()->name();
432
-        } else {
433
-            return '';
434
-        }
435
-    }
436
-
437
-
438
-    /**
439
-     * either displays the state abbreviation or the state name, as determined
440
-     * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
441
-     * defaults to abbreviation
442
-     *
443
-     * @return string
444
-     * @throws EE_Error
445
-     */
446
-    public function state()
447
-    {
448
-        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
449
-            return $this->state_abbrev();
450
-        }
451
-        return $this->state_name();
452
-    }
453
-
454
-
455
-    /**
456
-     *    get Attendee Country ISO Code
457
-     *
458
-     * @return string
459
-     * @throws EE_Error
460
-     */
461
-    public function country_ID()
462
-    {
463
-        return $this->get('CNT_ISO');
464
-    }
465
-
466
-
467
-    /**
468
-     * Gets country set for this attendee
469
-     *
470
-     * @return EE_Country
471
-     * @throws EE_Error
472
-     */
473
-    public function country_obj()
474
-    {
475
-        return $this->get_first_related('Country');
476
-    }
477
-
478
-
479
-    /**
480
-     * Returns the country's name if known, otherwise 'Unknown'
481
-     *
482
-     * @return string
483
-     * @throws EE_Error
484
-     */
485
-    public function country_name()
486
-    {
487
-        if ($this->country_obj()) {
488
-            return $this->country_obj()->name();
489
-        }
490
-        return '';
491
-    }
492
-
493
-
494
-    /**
495
-     * either displays the country ISO2 code or the country name, as determined
496
-     * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
497
-     * defaults to abbreviation
498
-     *
499
-     * @return string
500
-     * @throws EE_Error
501
-     */
502
-    public function country()
503
-    {
504
-        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
505
-            return $this->country_ID();
506
-        }
507
-        return $this->country_name();
508
-    }
509
-
510
-
511
-    /**
512
-     *        get Attendee Zip/Postal Code
513
-     *
514
-     * @return string
515
-     * @throws EE_Error
516
-     */
517
-    public function zip()
518
-    {
519
-        return $this->get('ATT_zip');
520
-    }
521
-
522
-
523
-    /**
524
-     *        get Attendee Email Address
525
-     *
526
-     * @return string
527
-     * @throws EE_Error
528
-     */
529
-    public function email()
530
-    {
531
-        return $this->get('ATT_email');
532
-    }
533
-
534
-
535
-    /**
536
-     *        get Attendee Phone #
537
-     *
538
-     * @return string
539
-     * @throws EE_Error
540
-     */
541
-    public function phone()
542
-    {
543
-        return $this->get('ATT_phone');
544
-    }
545
-
546
-
547
-    /**
548
-     *    get deleted
549
-     *
550
-     * @return        bool
551
-     * @throws EE_Error
552
-     */
553
-    public function deleted()
554
-    {
555
-        return $this->get('ATT_deleted');
556
-    }
557
-
558
-
559
-    /**
560
-     * Gets registrations of this attendee
561
-     *
562
-     * @param array $query_params
563
-     * @return EE_Registration[]
564
-     * @throws EE_Error
565
-     */
566
-    public function get_registrations($query_params = array())
567
-    {
568
-        return $this->get_many_related('Registration', $query_params);
569
-    }
570
-
571
-
572
-    /**
573
-     * Gets the most recent registration of this attendee
574
-     *
575
-     * @return EE_Registration
576
-     * @throws EE_Error
577
-     */
578
-    public function get_most_recent_registration()
579
-    {
580
-        return $this->get_first_related(
581
-            'Registration',
582
-            array('order_by' => array('REG_date' => 'DESC'))
583
-        ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K');
584
-    }
585
-
586
-
587
-    /**
588
-     * Gets the most recent registration for this attend at this event
589
-     *
590
-     * @param int $event_id
591
-     * @return EE_Registration
592
-     * @throws EE_Error
593
-     */
594
-    public function get_most_recent_registration_for_event($event_id)
595
-    {
596
-        return $this->get_first_related(
597
-            'Registration',
598
-            array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))
599
-        );
600
-    }
601
-
602
-
603
-    /**
604
-     * returns any events attached to this attendee ($_Event property);
605
-     *
606
-     * @return array
607
-     * @throws EE_Error
608
-     */
609
-    public function events()
610
-    {
611
-        return $this->get_many_related('Event');
612
-    }
613
-
614
-
615
-    /**
616
-     * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
617
-     * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
618
-     * used to save the billing info
619
-     *
620
-     * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
621
-     * @return EE_Form_Section_Proper|null
622
-     * @throws EE_Error
623
-     */
624
-    public function billing_info_for_payment_method($payment_method)
625
-    {
626
-        $pm_type = $payment_method->type_obj();
627
-        if (! $pm_type instanceof EE_PMT_Base) {
628
-            return null;
629
-        }
630
-        $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
631
-        if (! $billing_info) {
632
-            return null;
633
-        }
634
-        $billing_form = $pm_type->billing_form();
635
-        if ($billing_form instanceof EE_Form_Section_Proper) {
636
-            $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false);
637
-        }
638
-        return $billing_form;
639
-    }
640
-
641
-
642
-    /**
643
-     * Gets the postmeta key that holds this attendee's billing info for the
644
-     * specified payment method
645
-     *
646
-     * @param EE_Payment_Method $payment_method
647
-     * @return string
648
-     * @throws EE_Error
649
-     */
650
-    public function get_billing_info_postmeta_name($payment_method)
651
-    {
652
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
653
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
654
-        }
655
-        return null;
656
-    }
657
-
658
-
659
-    /**
660
-     * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to
661
-     * retrieve it
662
-     *
663
-     * @param EE_Billing_Attendee_Info_Form $billing_form
664
-     * @param EE_Payment_Method             $payment_method
665
-     * @return boolean
666
-     * @throws EE_Error
667
-     */
668
-    public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
669
-    {
670
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
671
-            EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso'));
672
-            return false;
673
-        }
674
-        $billing_form->clean_sensitive_data();
675
-        return update_post_meta(
676
-            $this->ID(),
677
-            $this->get_billing_info_postmeta_name($payment_method),
678
-            $billing_form->input_values(true)
679
-        );
680
-    }
681
-
682
-
683
-    /**
684
-     * Return the link to the admin details for the object.
685
-     *
686
-     * @return string
687
-     * @throws EE_Error
688
-     * @throws InvalidArgumentException
689
-     * @throws InvalidDataTypeException
690
-     * @throws InvalidInterfaceException
691
-     * @throws ReflectionException
692
-     */
693
-    public function get_admin_details_link()
694
-    {
695
-        return $this->get_admin_edit_link();
696
-    }
697
-
698
-
699
-    /**
700
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
701
-     *
702
-     * @return string
703
-     * @throws EE_Error
704
-     * @throws InvalidArgumentException
705
-     * @throws ReflectionException
706
-     * @throws InvalidDataTypeException
707
-     * @throws InvalidInterfaceException
708
-     */
709
-    public function get_admin_edit_link()
710
-    {
711
-        EE_Registry::instance()->load_helper('URL');
712
-        return EEH_URL::add_query_args_and_nonce(
713
-            array(
714
-                'page'   => 'espresso_registrations',
715
-                'action' => 'edit_attendee',
716
-                'post'   => $this->ID(),
717
-            ),
718
-            admin_url('admin.php')
719
-        );
720
-    }
721
-
722
-
723
-    /**
724
-     * Returns the link to a settings page for the object.
725
-     *
726
-     * @return string
727
-     * @throws EE_Error
728
-     * @throws InvalidArgumentException
729
-     * @throws InvalidDataTypeException
730
-     * @throws InvalidInterfaceException
731
-     * @throws ReflectionException
732
-     */
733
-    public function get_admin_settings_link()
734
-    {
735
-        return $this->get_admin_edit_link();
736
-    }
737
-
738
-
739
-    /**
740
-     * Returns the link to the "overview" for the object (typically the "list table" view).
741
-     *
742
-     * @return string
743
-     * @throws EE_Error
744
-     * @throws InvalidArgumentException
745
-     * @throws ReflectionException
746
-     * @throws InvalidDataTypeException
747
-     * @throws InvalidInterfaceException
748
-     */
749
-    public function get_admin_overview_link()
750
-    {
751
-        EE_Registry::instance()->load_helper('URL');
752
-        return EEH_URL::add_query_args_and_nonce(
753
-            array(
754
-                'page'   => 'espresso_registrations',
755
-                'action' => 'contact_list',
756
-            ),
757
-            admin_url('admin.php')
758
-        );
759
-    }
30
+	/**
31
+	 * Sets some dynamic defaults
32
+	 *
33
+	 * @param array  $fieldValues
34
+	 * @param bool   $bydb
35
+	 * @param string $timezone
36
+	 * @param array  $date_formats
37
+	 * @throws EE_Error
38
+	 */
39
+	protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
40
+	{
41
+		if (! isset($fieldValues['ATT_full_name'])) {
42
+			$fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
43
+			$lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
44
+			$fieldValues['ATT_full_name'] = $fname . $lname;
45
+		}
46
+		if (! isset($fieldValues['ATT_slug'])) {
47
+			//			$fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
48
+			$fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
49
+		}
50
+		if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
51
+			$fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
52
+		}
53
+		parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
54
+	}
55
+
56
+
57
+	/**
58
+	 * @param array  $props_n_values          incoming values
59
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
60
+	 *                                        used.)
61
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
62
+	 *                                        date_format and the second value is the time format
63
+	 * @return EE_Attendee
64
+	 * @throws EE_Error
65
+	 */
66
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
67
+	{
68
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
69
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @param array  $props_n_values  incoming values from the database
75
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
76
+	 *                                the website will be used.
77
+	 * @return EE_Attendee
78
+	 */
79
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
80
+	{
81
+		return new self($props_n_values, true, $timezone);
82
+	}
83
+
84
+
85
+	/**
86
+	 *        Set Attendee First Name
87
+	 *
88
+	 * @access        public
89
+	 * @param string $fname
90
+	 * @throws EE_Error
91
+	 */
92
+	public function set_fname($fname = '')
93
+	{
94
+		$this->set('ATT_fname', $fname);
95
+	}
96
+
97
+
98
+	/**
99
+	 *        Set Attendee Last Name
100
+	 *
101
+	 * @access        public
102
+	 * @param string $lname
103
+	 * @throws EE_Error
104
+	 */
105
+	public function set_lname($lname = '')
106
+	{
107
+		$this->set('ATT_lname', $lname);
108
+	}
109
+
110
+
111
+	/**
112
+	 *        Set Attendee Address
113
+	 *
114
+	 * @access        public
115
+	 * @param string $address
116
+	 * @throws EE_Error
117
+	 */
118
+	public function set_address($address = '')
119
+	{
120
+		$this->set('ATT_address', $address);
121
+	}
122
+
123
+
124
+	/**
125
+	 *        Set Attendee Address2
126
+	 *
127
+	 * @access        public
128
+	 * @param        string $address2
129
+	 * @throws EE_Error
130
+	 */
131
+	public function set_address2($address2 = '')
132
+	{
133
+		$this->set('ATT_address2', $address2);
134
+	}
135
+
136
+
137
+	/**
138
+	 *        Set Attendee City
139
+	 *
140
+	 * @access        public
141
+	 * @param        string $city
142
+	 * @throws EE_Error
143
+	 */
144
+	public function set_city($city = '')
145
+	{
146
+		$this->set('ATT_city', $city);
147
+	}
148
+
149
+
150
+	/**
151
+	 *        Set Attendee State ID
152
+	 *
153
+	 * @access        public
154
+	 * @param        int $STA_ID
155
+	 * @throws EE_Error
156
+	 */
157
+	public function set_state($STA_ID = 0)
158
+	{
159
+		$this->set('STA_ID', $STA_ID);
160
+	}
161
+
162
+
163
+	/**
164
+	 *        Set Attendee Country ISO Code
165
+	 *
166
+	 * @access        public
167
+	 * @param        string $CNT_ISO
168
+	 * @throws EE_Error
169
+	 */
170
+	public function set_country($CNT_ISO = '')
171
+	{
172
+		$this->set('CNT_ISO', $CNT_ISO);
173
+	}
174
+
175
+
176
+	/**
177
+	 *        Set Attendee Zip/Postal Code
178
+	 *
179
+	 * @access        public
180
+	 * @param        string $zip
181
+	 * @throws EE_Error
182
+	 */
183
+	public function set_zip($zip = '')
184
+	{
185
+		$this->set('ATT_zip', $zip);
186
+	}
187
+
188
+
189
+	/**
190
+	 *        Set Attendee Email Address
191
+	 *
192
+	 * @access        public
193
+	 * @param        string $email
194
+	 * @throws EE_Error
195
+	 */
196
+	public function set_email($email = '')
197
+	{
198
+		$this->set('ATT_email', $email);
199
+	}
200
+
201
+
202
+	/**
203
+	 *        Set Attendee Phone
204
+	 *
205
+	 * @access        public
206
+	 * @param        string $phone
207
+	 * @throws EE_Error
208
+	 */
209
+	public function set_phone($phone = '')
210
+	{
211
+		$this->set('ATT_phone', $phone);
212
+	}
213
+
214
+
215
+	/**
216
+	 *        set deleted
217
+	 *
218
+	 * @access        public
219
+	 * @param        bool $ATT_deleted
220
+	 * @throws EE_Error
221
+	 */
222
+	public function set_deleted($ATT_deleted = false)
223
+	{
224
+		$this->set('ATT_deleted', $ATT_deleted);
225
+	}
226
+
227
+
228
+	/**
229
+	 * Returns the value for the post_author id saved with the cpt
230
+	 *
231
+	 * @since 4.5.0
232
+	 * @return int
233
+	 * @throws EE_Error
234
+	 */
235
+	public function wp_user()
236
+	{
237
+		return $this->get('ATT_author');
238
+	}
239
+
240
+
241
+	/**
242
+	 *        get Attendee First Name
243
+	 *
244
+	 * @access        public
245
+	 * @return string
246
+	 * @throws EE_Error
247
+	 */
248
+	public function fname()
249
+	{
250
+		return $this->get('ATT_fname');
251
+	}
252
+
253
+
254
+	/**
255
+	 * echoes out the attendee's first name
256
+	 *
257
+	 * @return void
258
+	 * @throws EE_Error
259
+	 */
260
+	public function e_full_name()
261
+	{
262
+		echo $this->full_name();
263
+	}
264
+
265
+
266
+	/**
267
+	 * Returns the first and last name concatenated together with a space.
268
+	 *
269
+	 * @param bool $apply_html_entities
270
+	 * @return string
271
+	 * @throws EE_Error
272
+	 */
273
+	public function full_name($apply_html_entities = false)
274
+	{
275
+		$full_name = array(
276
+			$this->fname(),
277
+			$this->lname(),
278
+		);
279
+		$full_name = array_filter($full_name);
280
+		$full_name = implode(' ', $full_name);
281
+		return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name;
282
+	}
283
+
284
+
285
+	/**
286
+	 * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless
287
+	 * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this
288
+	 * attendee.
289
+	 *
290
+	 * @param bool $apply_html_entities
291
+	 * @return string
292
+	 * @throws EE_Error
293
+	 */
294
+	public function ATT_full_name($apply_html_entities = false)
295
+	{
296
+		return $apply_html_entities
297
+			? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8')
298
+			: $this->get('ATT_full_name');
299
+	}
300
+
301
+
302
+	/**
303
+	 *        get Attendee Last Name
304
+	 *
305
+	 * @access        public
306
+	 * @return string
307
+	 * @throws EE_Error
308
+	 */
309
+	public function lname()
310
+	{
311
+		return $this->get('ATT_lname');
312
+	}
313
+
314
+
315
+	/**
316
+	 * Gets the attendee's full address as an array so client code can decide hwo to display it
317
+	 *
318
+	 * @return array numerically indexed, with each part of the address that is known.
319
+	 * Eg, if the user only responded to state and country,
320
+	 * it would be array(0=>'Alabama',1=>'USA')
321
+	 * @return array
322
+	 * @throws EE_Error
323
+	 */
324
+	public function full_address_as_array()
325
+	{
326
+		$full_address_array     = array();
327
+		$initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
328
+		foreach ($initial_address_fields as $address_field_name) {
329
+			$address_fields_value = $this->get($address_field_name);
330
+			if (! empty($address_fields_value)) {
331
+				$full_address_array[] = $address_fields_value;
332
+			}
333
+		}
334
+		//now handle state and country
335
+		$state_obj = $this->state_obj();
336
+		if ($state_obj instanceof EE_State) {
337
+			$full_address_array[] = $state_obj->name();
338
+		}
339
+		$country_obj = $this->country_obj();
340
+		if ($country_obj instanceof EE_Country) {
341
+			$full_address_array[] = $country_obj->name();
342
+		}
343
+		//lastly get the xip
344
+		$zip_value = $this->zip();
345
+		if (! empty($zip_value)) {
346
+			$full_address_array[] = $zip_value;
347
+		}
348
+		return $full_address_array;
349
+	}
350
+
351
+
352
+	/**
353
+	 *        get Attendee Address
354
+	 *
355
+	 * @return string
356
+	 * @throws EE_Error
357
+	 */
358
+	public function address()
359
+	{
360
+		return $this->get('ATT_address');
361
+	}
362
+
363
+
364
+	/**
365
+	 *        get Attendee Address2
366
+	 *
367
+	 * @return string
368
+	 * @throws EE_Error
369
+	 */
370
+	public function address2()
371
+	{
372
+		return $this->get('ATT_address2');
373
+	}
374
+
375
+
376
+	/**
377
+	 *        get Attendee City
378
+	 *
379
+	 * @return string
380
+	 * @throws EE_Error
381
+	 */
382
+	public function city()
383
+	{
384
+		return $this->get('ATT_city');
385
+	}
386
+
387
+
388
+	/**
389
+	 *        get Attendee State ID
390
+	 *
391
+	 * @return string
392
+	 * @throws EE_Error
393
+	 */
394
+	public function state_ID()
395
+	{
396
+		return $this->get('STA_ID');
397
+	}
398
+
399
+
400
+	/**
401
+	 * @return string
402
+	 * @throws EE_Error
403
+	 */
404
+	public function state_abbrev()
405
+	{
406
+		return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
407
+	}
408
+
409
+
410
+	/**
411
+	 * Gets the state set to this attendee
412
+	 *
413
+	 * @return EE_State
414
+	 * @throws EE_Error
415
+	 */
416
+	public function state_obj()
417
+	{
418
+		return $this->get_first_related('State');
419
+	}
420
+
421
+
422
+	/**
423
+	 * Returns the state's name, otherwise 'Unknown'
424
+	 *
425
+	 * @return string
426
+	 * @throws EE_Error
427
+	 */
428
+	public function state_name()
429
+	{
430
+		if ($this->state_obj()) {
431
+			return $this->state_obj()->name();
432
+		} else {
433
+			return '';
434
+		}
435
+	}
436
+
437
+
438
+	/**
439
+	 * either displays the state abbreviation or the state name, as determined
440
+	 * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
441
+	 * defaults to abbreviation
442
+	 *
443
+	 * @return string
444
+	 * @throws EE_Error
445
+	 */
446
+	public function state()
447
+	{
448
+		if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
449
+			return $this->state_abbrev();
450
+		}
451
+		return $this->state_name();
452
+	}
453
+
454
+
455
+	/**
456
+	 *    get Attendee Country ISO Code
457
+	 *
458
+	 * @return string
459
+	 * @throws EE_Error
460
+	 */
461
+	public function country_ID()
462
+	{
463
+		return $this->get('CNT_ISO');
464
+	}
465
+
466
+
467
+	/**
468
+	 * Gets country set for this attendee
469
+	 *
470
+	 * @return EE_Country
471
+	 * @throws EE_Error
472
+	 */
473
+	public function country_obj()
474
+	{
475
+		return $this->get_first_related('Country');
476
+	}
477
+
478
+
479
+	/**
480
+	 * Returns the country's name if known, otherwise 'Unknown'
481
+	 *
482
+	 * @return string
483
+	 * @throws EE_Error
484
+	 */
485
+	public function country_name()
486
+	{
487
+		if ($this->country_obj()) {
488
+			return $this->country_obj()->name();
489
+		}
490
+		return '';
491
+	}
492
+
493
+
494
+	/**
495
+	 * either displays the country ISO2 code or the country name, as determined
496
+	 * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
497
+	 * defaults to abbreviation
498
+	 *
499
+	 * @return string
500
+	 * @throws EE_Error
501
+	 */
502
+	public function country()
503
+	{
504
+		if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
505
+			return $this->country_ID();
506
+		}
507
+		return $this->country_name();
508
+	}
509
+
510
+
511
+	/**
512
+	 *        get Attendee Zip/Postal Code
513
+	 *
514
+	 * @return string
515
+	 * @throws EE_Error
516
+	 */
517
+	public function zip()
518
+	{
519
+		return $this->get('ATT_zip');
520
+	}
521
+
522
+
523
+	/**
524
+	 *        get Attendee Email Address
525
+	 *
526
+	 * @return string
527
+	 * @throws EE_Error
528
+	 */
529
+	public function email()
530
+	{
531
+		return $this->get('ATT_email');
532
+	}
533
+
534
+
535
+	/**
536
+	 *        get Attendee Phone #
537
+	 *
538
+	 * @return string
539
+	 * @throws EE_Error
540
+	 */
541
+	public function phone()
542
+	{
543
+		return $this->get('ATT_phone');
544
+	}
545
+
546
+
547
+	/**
548
+	 *    get deleted
549
+	 *
550
+	 * @return        bool
551
+	 * @throws EE_Error
552
+	 */
553
+	public function deleted()
554
+	{
555
+		return $this->get('ATT_deleted');
556
+	}
557
+
558
+
559
+	/**
560
+	 * Gets registrations of this attendee
561
+	 *
562
+	 * @param array $query_params
563
+	 * @return EE_Registration[]
564
+	 * @throws EE_Error
565
+	 */
566
+	public function get_registrations($query_params = array())
567
+	{
568
+		return $this->get_many_related('Registration', $query_params);
569
+	}
570
+
571
+
572
+	/**
573
+	 * Gets the most recent registration of this attendee
574
+	 *
575
+	 * @return EE_Registration
576
+	 * @throws EE_Error
577
+	 */
578
+	public function get_most_recent_registration()
579
+	{
580
+		return $this->get_first_related(
581
+			'Registration',
582
+			array('order_by' => array('REG_date' => 'DESC'))
583
+		); //null, 'REG_date', 'DESC', '=', 'OBJECT_K');
584
+	}
585
+
586
+
587
+	/**
588
+	 * Gets the most recent registration for this attend at this event
589
+	 *
590
+	 * @param int $event_id
591
+	 * @return EE_Registration
592
+	 * @throws EE_Error
593
+	 */
594
+	public function get_most_recent_registration_for_event($event_id)
595
+	{
596
+		return $this->get_first_related(
597
+			'Registration',
598
+			array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))
599
+		);
600
+	}
601
+
602
+
603
+	/**
604
+	 * returns any events attached to this attendee ($_Event property);
605
+	 *
606
+	 * @return array
607
+	 * @throws EE_Error
608
+	 */
609
+	public function events()
610
+	{
611
+		return $this->get_many_related('Event');
612
+	}
613
+
614
+
615
+	/**
616
+	 * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
617
+	 * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
618
+	 * used to save the billing info
619
+	 *
620
+	 * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
621
+	 * @return EE_Form_Section_Proper|null
622
+	 * @throws EE_Error
623
+	 */
624
+	public function billing_info_for_payment_method($payment_method)
625
+	{
626
+		$pm_type = $payment_method->type_obj();
627
+		if (! $pm_type instanceof EE_PMT_Base) {
628
+			return null;
629
+		}
630
+		$billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
631
+		if (! $billing_info) {
632
+			return null;
633
+		}
634
+		$billing_form = $pm_type->billing_form();
635
+		if ($billing_form instanceof EE_Form_Section_Proper) {
636
+			$billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false);
637
+		}
638
+		return $billing_form;
639
+	}
640
+
641
+
642
+	/**
643
+	 * Gets the postmeta key that holds this attendee's billing info for the
644
+	 * specified payment method
645
+	 *
646
+	 * @param EE_Payment_Method $payment_method
647
+	 * @return string
648
+	 * @throws EE_Error
649
+	 */
650
+	public function get_billing_info_postmeta_name($payment_method)
651
+	{
652
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
653
+			return 'billing_info_' . $payment_method->type_obj()->system_name();
654
+		}
655
+		return null;
656
+	}
657
+
658
+
659
+	/**
660
+	 * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to
661
+	 * retrieve it
662
+	 *
663
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
664
+	 * @param EE_Payment_Method             $payment_method
665
+	 * @return boolean
666
+	 * @throws EE_Error
667
+	 */
668
+	public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
669
+	{
670
+		if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
671
+			EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso'));
672
+			return false;
673
+		}
674
+		$billing_form->clean_sensitive_data();
675
+		return update_post_meta(
676
+			$this->ID(),
677
+			$this->get_billing_info_postmeta_name($payment_method),
678
+			$billing_form->input_values(true)
679
+		);
680
+	}
681
+
682
+
683
+	/**
684
+	 * Return the link to the admin details for the object.
685
+	 *
686
+	 * @return string
687
+	 * @throws EE_Error
688
+	 * @throws InvalidArgumentException
689
+	 * @throws InvalidDataTypeException
690
+	 * @throws InvalidInterfaceException
691
+	 * @throws ReflectionException
692
+	 */
693
+	public function get_admin_details_link()
694
+	{
695
+		return $this->get_admin_edit_link();
696
+	}
697
+
698
+
699
+	/**
700
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
701
+	 *
702
+	 * @return string
703
+	 * @throws EE_Error
704
+	 * @throws InvalidArgumentException
705
+	 * @throws ReflectionException
706
+	 * @throws InvalidDataTypeException
707
+	 * @throws InvalidInterfaceException
708
+	 */
709
+	public function get_admin_edit_link()
710
+	{
711
+		EE_Registry::instance()->load_helper('URL');
712
+		return EEH_URL::add_query_args_and_nonce(
713
+			array(
714
+				'page'   => 'espresso_registrations',
715
+				'action' => 'edit_attendee',
716
+				'post'   => $this->ID(),
717
+			),
718
+			admin_url('admin.php')
719
+		);
720
+	}
721
+
722
+
723
+	/**
724
+	 * Returns the link to a settings page for the object.
725
+	 *
726
+	 * @return string
727
+	 * @throws EE_Error
728
+	 * @throws InvalidArgumentException
729
+	 * @throws InvalidDataTypeException
730
+	 * @throws InvalidInterfaceException
731
+	 * @throws ReflectionException
732
+	 */
733
+	public function get_admin_settings_link()
734
+	{
735
+		return $this->get_admin_edit_link();
736
+	}
737
+
738
+
739
+	/**
740
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
741
+	 *
742
+	 * @return string
743
+	 * @throws EE_Error
744
+	 * @throws InvalidArgumentException
745
+	 * @throws ReflectionException
746
+	 * @throws InvalidDataTypeException
747
+	 * @throws InvalidInterfaceException
748
+	 */
749
+	public function get_admin_overview_link()
750
+	{
751
+		EE_Registry::instance()->load_helper('URL');
752
+		return EEH_URL::add_query_args_and_nonce(
753
+			array(
754
+				'page'   => 'espresso_registrations',
755
+				'action' => 'contact_list',
756
+			),
757
+			admin_url('admin.php')
758
+		);
759
+	}
760 760
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
      */
39 39
     protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
40 40
     {
41
-        if (! isset($fieldValues['ATT_full_name'])) {
42
-            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
41
+        if ( ! isset($fieldValues['ATT_full_name'])) {
42
+            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : '';
43 43
             $lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
44
-            $fieldValues['ATT_full_name'] = $fname . $lname;
44
+            $fieldValues['ATT_full_name'] = $fname.$lname;
45 45
         }
46
-        if (! isset($fieldValues['ATT_slug'])) {
46
+        if ( ! isset($fieldValues['ATT_slug'])) {
47 47
             //			$fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
48 48
             $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
49 49
         }
50
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
50
+        if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
51 51
             $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
52 52
         }
53 53
         parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
328 328
         foreach ($initial_address_fields as $address_field_name) {
329 329
             $address_fields_value = $this->get($address_field_name);
330
-            if (! empty($address_fields_value)) {
330
+            if ( ! empty($address_fields_value)) {
331 331
                 $full_address_array[] = $address_fields_value;
332 332
             }
333 333
         }
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
         }
343 343
         //lastly get the xip
344 344
         $zip_value = $this->zip();
345
-        if (! empty($zip_value)) {
345
+        if ( ! empty($zip_value)) {
346 346
             $full_address_array[] = $zip_value;
347 347
         }
348 348
         return $full_address_array;
@@ -624,11 +624,11 @@  discard block
 block discarded – undo
624 624
     public function billing_info_for_payment_method($payment_method)
625 625
     {
626 626
         $pm_type = $payment_method->type_obj();
627
-        if (! $pm_type instanceof EE_PMT_Base) {
627
+        if ( ! $pm_type instanceof EE_PMT_Base) {
628 628
             return null;
629 629
         }
630 630
         $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
631
-        if (! $billing_info) {
631
+        if ( ! $billing_info) {
632 632
             return null;
633 633
         }
634 634
         $billing_form = $pm_type->billing_form();
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
     public function get_billing_info_postmeta_name($payment_method)
651 651
     {
652 652
         if ($payment_method->type_obj() instanceof EE_PMT_Base) {
653
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
653
+            return 'billing_info_'.$payment_method->type_obj()->system_name();
654 654
         }
655 655
         return null;
656 656
     }
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
      */
668 668
     public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
669 669
     {
670
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
670
+        if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
671 671
             EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso'));
672 672
             return false;
673 673
         }
Please login to merge, or discard this patch.