Completed
Branch FET-10816-display-form-wide-er... (d4675c)
by
unknown
93:01 queued 83:00
created
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1860 added lines, -1860 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1865 +20,1865 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
-            __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
237
-                'event_espresso'),
238
-            '<h4 class="important-notice">',
239
-            '</h4>',
240
-            '<br />',
241
-            '<p>',
242
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
243
-            '">',
244
-            '</a>',
245
-            '</p>'
246
-        );
247
-    }
248
-
249
-
250
-
251
-    /**
252
-     * load_reg_steps
253
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
254
-     *
255
-     * @access    private
256
-     * @throws EE_Error
257
-     */
258
-    public static function load_reg_steps()
259
-    {
260
-        static $reg_steps_loaded = false;
261
-        if ($reg_steps_loaded) {
262
-            return;
263
-        }
264
-        // filter list of reg_steps
265
-        $reg_steps_to_load = (array)apply_filters(
266
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
267
-            EED_Single_Page_Checkout::get_reg_steps()
268
-        );
269
-        // sort by key (order)
270
-        ksort($reg_steps_to_load);
271
-        // loop through folders
272
-        foreach ($reg_steps_to_load as $order => $reg_step) {
273
-            // we need a
274
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
275
-                // copy over to the reg_steps_array
276
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
277
-                // register custom key route for each reg step
278
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
279
-                EE_Config::register_route(
280
-                    $reg_step['slug'],
281
-                    'EED_Single_Page_Checkout',
282
-                    'run',
283
-                    'step'
284
-                );
285
-                // add AJAX or other hooks
286
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
287
-                    // setup autoloaders if necessary
288
-                    if ( ! class_exists($reg_step['class_name'])) {
289
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
290
-                            $reg_step['file_path'],
291
-                            true
292
-                        );
293
-                    }
294
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
295
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
296
-                    }
297
-                }
298
-            }
299
-        }
300
-        $reg_steps_loaded = true;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     *    get_reg_steps
307
-     *
308
-     * @access    public
309
-     * @return    array
310
-     */
311
-    public static function get_reg_steps()
312
-    {
313
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
314
-        if (empty($reg_steps)) {
315
-            $reg_steps = array(
316
-                10  => array(
317
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
318
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
319
-                    'slug'       => 'attendee_information',
320
-                    'has_hooks'  => false,
321
-                ),
322
-                20  => array(
323
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
324
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
325
-                    'slug'       => 'registration_confirmation',
326
-                    'has_hooks'  => false,
327
-                ),
328
-                30  => array(
329
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
330
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
331
-                    'slug'       => 'payment_options',
332
-                    'has_hooks'  => true,
333
-                ),
334
-                999 => array(
335
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
336
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
337
-                    'slug'       => 'finalize_registration',
338
-                    'has_hooks'  => false,
339
-                ),
340
-            );
341
-        }
342
-        return $reg_steps;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     *    registration_checkout_for_admin
349
-     *
350
-     * @access    public
351
-     * @return    string
352
-     * @throws EE_Error
353
-     */
354
-    public static function registration_checkout_for_admin()
355
-    {
356
-        EED_Single_Page_Checkout::load_request_handler();
357
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
358
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
359
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
360
-        EED_Single_Page_Checkout::instance()->_initialize();
361
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
362
-        return EE_Registry::instance()->REQ->get_output();
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     * process_registration_from_admin
369
-     *
370
-     * @access public
371
-     * @return \EE_Transaction
372
-     * @throws EE_Error
373
-     */
374
-    public static function process_registration_from_admin()
375
-    {
376
-        EED_Single_Page_Checkout::load_request_handler();
377
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
378
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
379
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
380
-        EED_Single_Page_Checkout::instance()->_initialize();
381
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
382
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
383
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
384
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
385
-                if ($final_reg_step->process_reg_step()) {
386
-                    $final_reg_step->set_completed();
387
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
388
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
389
-                }
390
-            }
391
-        }
392
-        return null;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     *    run
399
-     *
400
-     * @access    public
401
-     * @param WP_Query $WP_Query
402
-     * @return    void
403
-     * @throws EE_Error
404
-     */
405
-    public function run($WP_Query)
406
-    {
407
-        if (
408
-            $WP_Query instanceof WP_Query
409
-            && $WP_Query->is_main_query()
410
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
411
-            && $this->_is_reg_checkout()
412
-        ) {
413
-            $this->_initialize();
414
-        }
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * determines whether current url matches reg page url
421
-     *
422
-     * @return bool
423
-     */
424
-    protected function _is_reg_checkout()
425
-    {
426
-        // get current permalink for reg page without any extra query args
427
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
428
-        // get request URI for current request, but without the scheme or host
429
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
430
-        $current_request_uri = html_entity_decode($current_request_uri);
431
-        // get array of query args from the current request URI
432
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
433
-        // grab page id if it is set
434
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
435
-        // and remove the page id from the query args (we will re-add it later)
436
-        unset($query_args['page_id']);
437
-        // now strip all query args from current request URI
438
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
439
-        // and re-add the page id if it was set
440
-        if ($page_id) {
441
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
442
-        }
443
-        // remove slashes and ?
444
-        $current_request_uri = trim($current_request_uri, '?/');
445
-        // is current request URI part of the known full reg page URL ?
446
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * @param WP_Query $wp_query
453
-     * @return    void
454
-     * @throws EE_Error
455
-     */
456
-    public static function init($wp_query)
457
-    {
458
-        EED_Single_Page_Checkout::instance()->run($wp_query);
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     *    _initialize - initial module setup
465
-     *
466
-     * @access    private
467
-     * @throws EE_Error
468
-     * @return    void
469
-     */
470
-    private function _initialize()
471
-    {
472
-        // ensure SPCO doesn't run twice
473
-        if (EED_Single_Page_Checkout::$_initialized) {
474
-            return;
475
-        }
476
-        try {
477
-            EED_Single_Page_Checkout::load_reg_steps();
478
-            $this->_verify_session();
479
-            // setup the EE_Checkout object
480
-            $this->checkout = $this->_initialize_checkout();
481
-            // filter checkout
482
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
483
-            // get the $_GET
484
-            $this->_get_request_vars();
485
-            if ($this->_block_bots()) {
486
-                return;
487
-            }
488
-            // filter continue_reg
489
-            $this->checkout->continue_reg = apply_filters(
490
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
491
-                true,
492
-                $this->checkout
493
-            );
494
-            // load the reg steps array
495
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
496
-                EED_Single_Page_Checkout::$_initialized = true;
497
-                return;
498
-            }
499
-            // set the current step
500
-            $this->checkout->set_current_step($this->checkout->step);
501
-            // and the next step
502
-            $this->checkout->set_next_step();
503
-            // verify that everything has been setup correctly
504
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
505
-                EED_Single_Page_Checkout::$_initialized = true;
506
-                return;
507
-            }
508
-            // lock the transaction
509
-            $this->checkout->transaction->lock();
510
-            // make sure all of our cached objects are added to their respective model entity mappers
511
-            $this->checkout->refresh_all_entities();
512
-            // set amount owing
513
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
514
-            // initialize each reg step, which gives them the chance to potentially alter the process
515
-            $this->_initialize_reg_steps();
516
-            // DEBUG LOG
517
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
518
-            // get reg form
519
-            if( ! $this->_check_form_submission()) {
520
-                EED_Single_Page_Checkout::$_initialized = true;
521
-                return;
522
-            }
523
-            // checkout the action!!!
524
-            $this->_process_form_action();
525
-            // add some style and make it dance
526
-            $this->add_styles_and_scripts();
527
-            // kk... SPCO has successfully run
528
-            EED_Single_Page_Checkout::$_initialized = true;
529
-            // set no cache headers and constants
530
-            EE_System::do_not_cache();
531
-            // add anchor
532
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
533
-            // remove transaction lock
534
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
535
-        } catch (Exception $e) {
536
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
-        }
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     *    _verify_session
544
-     * checks that the session is valid and not expired
545
-     *
546
-     * @access    private
547
-     * @throws EE_Error
548
-     */
549
-    private function _verify_session()
550
-    {
551
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
552
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
553
-        }
554
-        $clear_session_requested = filter_var(
555
-            EE_Registry::instance()->REQ->get('clear_session', false),
556
-            FILTER_VALIDATE_BOOLEAN
557
-        );
558
-        // is session still valid ?
559
-        if ($clear_session_requested
560
-            || ( EE_Registry::instance()->SSN->expired()
561
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
562
-            )
563
-        ) {
564
-            $this->checkout = new EE_Checkout();
565
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
566
-            // EE_Registry::instance()->SSN->reset_cart();
567
-            // EE_Registry::instance()->SSN->reset_checkout();
568
-            // EE_Registry::instance()->SSN->reset_transaction();
569
-            if (! $clear_session_requested) {
570
-                EE_Error::add_attention(
571
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
572
-                    __FILE__, __FUNCTION__, __LINE__
573
-                );
574
-            }
575
-            // EE_Registry::instance()->SSN->reset_expired();
576
-        }
577
-    }
578
-
579
-
580
-
581
-    /**
582
-     *    _initialize_checkout
583
-     * loads and instantiates EE_Checkout
584
-     *
585
-     * @access    private
586
-     * @throws EE_Error
587
-     * @return EE_Checkout
588
-     */
589
-    private function _initialize_checkout()
590
-    {
591
-        // look in session for existing checkout
592
-        /** @type EE_Checkout $checkout */
593
-        $checkout = EE_Registry::instance()->SSN->checkout();
594
-        // verify
595
-        if ( ! $checkout instanceof EE_Checkout) {
596
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
597
-            $checkout = EE_Registry::instance()->load_file(
598
-                SPCO_INC_PATH,
599
-                'EE_Checkout',
600
-                'class', array(),
601
-                false
602
-            );
603
-        } else {
604
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
605
-                $this->unlock_transaction();
606
-                wp_safe_redirect($checkout->redirect_url);
607
-                exit();
608
-            }
609
-        }
610
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
611
-        // verify again
612
-        if ( ! $checkout instanceof EE_Checkout) {
613
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
614
-        }
615
-        // reset anything that needs a clean slate for each request
616
-        $checkout->reset_for_current_request();
617
-        return $checkout;
618
-    }
619
-
620
-
621
-
622
-    /**
623
-     *    _get_request_vars
624
-     *
625
-     * @access    private
626
-     * @return    void
627
-     * @throws EE_Error
628
-     */
629
-    private function _get_request_vars()
630
-    {
631
-        // load classes
632
-        EED_Single_Page_Checkout::load_request_handler();
633
-        //make sure this request is marked as belonging to EE
634
-        EE_Registry::instance()->REQ->set_espresso_page(true);
635
-        // which step is being requested ?
636
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
637
-        // which step is being edited ?
638
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
639
-        // and what we're doing on the current step
640
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
641
-        // timestamp
642
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
643
-        // returning to edit ?
644
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
645
-        // add reg url link to registration query params
646
-        if ($this->checkout->reg_url_link) {
647
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
648
-        }
649
-        // or some other kind of revisit ?
650
-        $this->checkout->revisit = filter_var(
651
-            EE_Registry::instance()->REQ->get('revisit', false),
652
-            FILTER_VALIDATE_BOOLEAN
653
-        );
654
-        // and whether or not to generate a reg form for this request
655
-        $this->checkout->generate_reg_form = filter_var(
656
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
657
-            FILTER_VALIDATE_BOOLEAN
658
-        );
659
-        // and whether or not to process a reg form submission for this request
660
-        $this->checkout->process_form_submission = filter_var(
661
-            EE_Registry::instance()->REQ->get(
662
-                'process_form_submission',
663
-                $this->checkout->action === 'process_reg_step'
664
-            ),
665
-            FILTER_VALIDATE_BOOLEAN
666
-        );
667
-        $this->checkout->process_form_submission = filter_var(
668
-            $this->checkout->action !== 'display_spco_reg_step'
669
-                ? $this->checkout->process_form_submission
670
-                : false,
671
-            FILTER_VALIDATE_BOOLEAN
672
-        );
673
-        // $this->_display_request_vars();
674
-    }
675
-
676
-
677
-
678
-    /**
679
-     *  _display_request_vars
680
-     *
681
-     * @access    protected
682
-     * @return    void
683
-     */
684
-    protected function _display_request_vars()
685
-    {
686
-        if ( ! WP_DEBUG) {
687
-            return;
688
-        }
689
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
690
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
691
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
692
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
693
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
694
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
695
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
696
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * _block_bots
703
-     * checks that the incoming request has either of the following set:
704
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
705
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
706
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
707
-     * then where you coming from man?
708
-     *
709
-     * @return boolean
710
-     */
711
-    private function _block_bots()
712
-    {
713
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
714
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
715
-            return true;
716
-        }
717
-        return false;
718
-    }
719
-
720
-
721
-
722
-    /**
723
-     *    _get_first_step
724
-     *  gets slug for first step in $_reg_steps_array
725
-     *
726
-     * @access    private
727
-     * @throws EE_Error
728
-     * @return    string
729
-     */
730
-    private function _get_first_step()
731
-    {
732
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
733
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
734
-    }
735
-
736
-
737
-
738
-    /**
739
-     *    _load_and_instantiate_reg_steps
740
-     *  instantiates each reg step based on the loaded reg_steps array
741
-     *
742
-     * @access    private
743
-     * @throws EE_Error
744
-     * @return    bool
745
-     */
746
-    private function _load_and_instantiate_reg_steps()
747
-    {
748
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
749
-        // have reg_steps already been instantiated ?
750
-        if (
751
-            empty($this->checkout->reg_steps)
752
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
753
-        ) {
754
-            // if not, then loop through raw reg steps array
755
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
756
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
757
-                    return false;
758
-                }
759
-            }
760
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
761
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
762
-            // skip the registration_confirmation page ?
763
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
764
-                // just remove it from the reg steps array
765
-                $this->checkout->remove_reg_step('registration_confirmation', false);
766
-            } else if (
767
-                isset($this->checkout->reg_steps['registration_confirmation'])
768
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
769
-            ) {
770
-                // set the order to something big like 100
771
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
772
-            }
773
-            // filter the array for good luck
774
-            $this->checkout->reg_steps = apply_filters(
775
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
776
-                $this->checkout->reg_steps
777
-            );
778
-            // finally re-sort based on the reg step class order properties
779
-            $this->checkout->sort_reg_steps();
780
-        } else {
781
-            foreach ($this->checkout->reg_steps as $reg_step) {
782
-                // set all current step stati to FALSE
783
-                $reg_step->set_is_current_step(false);
784
-            }
785
-        }
786
-        if (empty($this->checkout->reg_steps)) {
787
-            EE_Error::add_error(
788
-                __('No Reg Steps were loaded..', 'event_espresso'),
789
-                __FILE__, __FUNCTION__, __LINE__
790
-            );
791
-            return false;
792
-        }
793
-        // make reg step details available to JS
794
-        $this->checkout->set_reg_step_JSON_info();
795
-        return true;
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     *     _load_and_instantiate_reg_step
802
-     *
803
-     * @access    private
804
-     * @param array $reg_step
805
-     * @param int   $order
806
-     * @return bool
807
-     */
808
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
809
-    {
810
-        // we need a file_path, class_name, and slug to add a reg step
811
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
812
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
813
-            if (
814
-                $this->checkout->reg_url_link
815
-                && $this->checkout->step !== $reg_step['slug']
816
-                && $reg_step['slug'] !== 'finalize_registration'
817
-                // normally at this point we would NOT load the reg step, but this filter can change that
818
-                && apply_filters(
819
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
820
-                    true,
821
-                    $reg_step,
822
-                    $this->checkout
823
-                )
824
-            ) {
825
-                return true;
826
-            }
827
-            // instantiate step class using file path and class name
828
-            $reg_step_obj = EE_Registry::instance()->load_file(
829
-                $reg_step['file_path'],
830
-                $reg_step['class_name'],
831
-                'class',
832
-                $this->checkout,
833
-                false
834
-            );
835
-            // did we gets the goods ?
836
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
837
-                // set reg step order based on config
838
-                $reg_step_obj->set_order($order);
839
-                // add instantiated reg step object to the master reg steps array
840
-                $this->checkout->add_reg_step($reg_step_obj);
841
-            } else {
842
-                EE_Error::add_error(
843
-                    __('The current step could not be set.', 'event_espresso'),
844
-                    __FILE__, __FUNCTION__, __LINE__
845
-                );
846
-                return false;
847
-            }
848
-        } else {
849
-            if (WP_DEBUG) {
850
-                EE_Error::add_error(
851
-                    sprintf(
852
-                        __(
853
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
854
-                            'event_espresso'
855
-                        ),
856
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
857
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
858
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
859
-                        '<ul>',
860
-                        '<li>',
861
-                        '</li>',
862
-                        '</ul>'
863
-                    ),
864
-                    __FILE__, __FUNCTION__, __LINE__
865
-                );
866
-            }
867
-            return false;
868
-        }
869
-        return true;
870
-    }
871
-
872
-
873
-    /**
874
-     * _verify_transaction_and_get_registrations
875
-     *
876
-     * @access private
877
-     * @return bool
878
-     * @throws InvalidDataTypeException
879
-     * @throws InvalidEntityException
880
-     * @throws EE_Error
881
-     */
882
-    private function _verify_transaction_and_get_registrations()
883
-    {
884
-        // was there already a valid transaction in the checkout from the session ?
885
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
886
-            // get transaction from db or session
887
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
888
-                ? $this->_get_transaction_and_cart_for_previous_visit()
889
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
890
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
891
-                EE_Error::add_error(
892
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
893
-                        'event_espresso'),
894
-                    __FILE__, __FUNCTION__, __LINE__
895
-                );
896
-                $this->checkout->transaction = EE_Transaction::new_instance();
897
-                // add some style and make it dance
898
-                $this->add_styles_and_scripts();
899
-                EED_Single_Page_Checkout::$_initialized = true;
900
-                return false;
901
-            }
902
-            // and the registrations for the transaction
903
-            $this->_get_registrations($this->checkout->transaction);
904
-        }
905
-        return true;
906
-    }
907
-
908
-
909
-
910
-    /**
911
-     * _get_transaction_and_cart_for_previous_visit
912
-     *
913
-     * @access private
914
-     * @return mixed EE_Transaction|NULL
915
-     */
916
-    private function _get_transaction_and_cart_for_previous_visit()
917
-    {
918
-        /** @var $TXN_model EEM_Transaction */
919
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
920
-        // because the reg_url_link is present in the request,
921
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
922
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
923
-        // verify transaction
924
-        if ($transaction instanceof EE_Transaction) {
925
-            // and get the cart that was used for that transaction
926
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
927
-            return $transaction;
928
-        }
929
-        EE_Error::add_error(
930
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
931
-            __FILE__, __FUNCTION__, __LINE__
932
-        );
933
-        return null;
934
-
935
-    }
936
-
937
-
938
-
939
-    /**
940
-     * _get_cart_for_transaction
941
-     *
942
-     * @access private
943
-     * @param EE_Transaction $transaction
944
-     * @return EE_Cart
945
-     */
946
-    private function _get_cart_for_transaction($transaction)
947
-    {
948
-        return $this->checkout->get_cart_for_transaction($transaction);
949
-    }
950
-
951
-
952
-
953
-    /**
954
-     * get_cart_for_transaction
955
-     *
956
-     * @access public
957
-     * @param EE_Transaction $transaction
958
-     * @return EE_Cart
959
-     */
960
-    public function get_cart_for_transaction(EE_Transaction $transaction)
961
-    {
962
-        return $this->checkout->get_cart_for_transaction($transaction);
963
-    }
964
-
965
-
966
-
967
-    /**
968
-     * _get_transaction_and_cart_for_current_session
969
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
970
-     *
971
-     * @access private
972
-     * @return EE_Transaction
973
-     * @throws EE_Error
974
-     */
975
-    private function _get_cart_for_current_session_and_setup_new_transaction()
976
-    {
977
-        //  if there's no transaction, then this is the FIRST visit to SPCO
978
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
979
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
980
-        // and then create a new transaction
981
-        $transaction = $this->_initialize_transaction();
982
-        // verify transaction
983
-        if ($transaction instanceof EE_Transaction) {
984
-            // save it so that we have an ID for other objects to use
985
-            $transaction->save();
986
-            // and save TXN data to the cart
987
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
988
-        } else {
989
-            EE_Error::add_error(
990
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
991
-                __FILE__, __FUNCTION__, __LINE__
992
-            );
993
-        }
994
-        return $transaction;
995
-    }
996
-
997
-
998
-
999
-    /**
1000
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
1001
-     *
1002
-     * @access private
1003
-     * @return mixed EE_Transaction|NULL
1004
-     */
1005
-    private function _initialize_transaction()
1006
-    {
1007
-        try {
1008
-            // ensure cart totals have been calculated
1009
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
1010
-            // grab the cart grand total
1011
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1012
-            // create new TXN
1013
-            $transaction = EE_Transaction::new_instance(
1014
-                array(
1015
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1016
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1017
-                    'TXN_paid'      => 0,
1018
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1019
-                )
1020
-            );
1021
-            // save it so that we have an ID for other objects to use
1022
-            $transaction->save();
1023
-            // set cron job for following up on TXNs after their session has expired
1024
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1025
-                EE_Registry::instance()->SSN->expiration() + 1,
1026
-                $transaction->ID()
1027
-            );
1028
-            return $transaction;
1029
-        } catch (Exception $e) {
1030
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1031
-        }
1032
-        return null;
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * _get_registrations
1038
-     *
1039
-     * @access private
1040
-     * @param EE_Transaction $transaction
1041
-     * @return void
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidEntityException
1044
-     * @throws EE_Error
1045
-     */
1046
-    private function _get_registrations(EE_Transaction $transaction)
1047
-    {
1048
-        // first step: grab the registrants  { : o
1049
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
1050
-        $this->checkout->total_ticket_count = count($registrations);
1051
-        // verify registrations have been set
1052
-        if (empty($registrations)) {
1053
-            // if no cached registrations, then check the db
1054
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1055
-            // still nothing ? well as long as this isn't a revisit
1056
-            if (empty($registrations) && ! $this->checkout->revisit) {
1057
-                // generate new registrations from scratch
1058
-                $registrations = $this->_initialize_registrations($transaction);
1059
-            }
1060
-        }
1061
-        // sort by their original registration order
1062
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1063
-        // then loop thru the array
1064
-        foreach ($registrations as $registration) {
1065
-            // verify each registration
1066
-            if ($registration instanceof EE_Registration) {
1067
-                // we display all attendee info for the primary registrant
1068
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1069
-                    && $registration->is_primary_registrant()
1070
-                ) {
1071
-                    $this->checkout->primary_revisit = true;
1072
-                    break;
1073
-                }
1074
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1075
-                    // but hide info if it doesn't belong to you
1076
-                    $transaction->clear_cache('Registration', $registration->ID());
1077
-                    $this->checkout->total_ticket_count--;
1078
-                }
1079
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1080
-            }
1081
-        }
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1087
-     *
1088
-     * @access private
1089
-     * @param EE_Transaction $transaction
1090
-     * @return    array
1091
-     * @throws InvalidDataTypeException
1092
-     * @throws InvalidEntityException
1093
-     * @throws EE_Error
1094
-     */
1095
-    private function _initialize_registrations(EE_Transaction $transaction)
1096
-    {
1097
-        $att_nmbr = 0;
1098
-        $registrations = array();
1099
-        if ($transaction instanceof EE_Transaction) {
1100
-            /** @type EE_Registration_Processor $registration_processor */
1101
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1102
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1103
-            // now let's add the cart items to the $transaction
1104
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1105
-                //do the following for each ticket of this type they selected
1106
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1107
-                    $att_nmbr++;
1108
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1109
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1110
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1111
-                        array(
1112
-                            $transaction,
1113
-                            $line_item,
1114
-                            $att_nmbr,
1115
-                            $this->checkout->total_ticket_count,
1116
-                        )
1117
-                    );
1118
-                    // override capabilities for frontend registrations
1119
-                    if ( ! is_admin()) {
1120
-                        $CreateRegistrationCommand->setCapCheck(
1121
-                            new PublicCapabilities('', 'create_new_registration')
1122
-                        );
1123
-                    }
1124
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1125
-                    if ( ! $registration instanceof EE_Registration) {
1126
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1127
-                    }
1128
-                    $registrations[ $registration->ID() ] = $registration;
1129
-                }
1130
-            }
1131
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1132
-        }
1133
-        return $registrations;
1134
-    }
1135
-
1136
-
1137
-
1138
-    /**
1139
-     * sorts registrations by REG_count
1140
-     *
1141
-     * @access public
1142
-     * @param EE_Registration $reg_A
1143
-     * @param EE_Registration $reg_B
1144
-     * @return int
1145
-     */
1146
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1147
-    {
1148
-        // this shouldn't ever happen within the same TXN, but oh well
1149
-        if ($reg_A->count() === $reg_B->count()) {
1150
-            return 0;
1151
-        }
1152
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     *    _final_verifications
1159
-     * just makes sure that everything is set up correctly before proceeding
1160
-     *
1161
-     * @access    private
1162
-     * @return    bool
1163
-     * @throws EE_Error
1164
-     */
1165
-    private function _final_verifications()
1166
-    {
1167
-        // filter checkout
1168
-        $this->checkout = apply_filters(
1169
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1170
-            $this->checkout
1171
-        );
1172
-        //verify that current step is still set correctly
1173
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1174
-            EE_Error::add_error(
1175
-                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1176
-                __FILE__,
1177
-                __FUNCTION__,
1178
-                __LINE__
1179
-            );
1180
-            return false;
1181
-        }
1182
-        // if returning to SPCO, then verify that primary registrant is set
1183
-        if ( ! empty($this->checkout->reg_url_link)) {
1184
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1185
-            if ( ! $valid_registrant instanceof EE_Registration) {
1186
-                EE_Error::add_error(
1187
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1188
-                    __FILE__,
1189
-                    __FUNCTION__,
1190
-                    __LINE__
1191
-                );
1192
-                return false;
1193
-            }
1194
-            $valid_registrant = null;
1195
-            foreach (
1196
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1197
-            ) {
1198
-                if (
1199
-                    $registration instanceof EE_Registration
1200
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1201
-                ) {
1202
-                    $valid_registrant = $registration;
1203
-                }
1204
-            }
1205
-            if ( ! $valid_registrant instanceof EE_Registration) {
1206
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1207
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1208
-                    // clear the session, mark the checkout as unverified, and try again
1209
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1210
-                    EED_Single_Page_Checkout::$_initialized = false;
1211
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1212
-                    $this->_initialize();
1213
-                    EE_Error::reset_notices();
1214
-                    return false;
1215
-                }
1216
-                EE_Error::add_error(
1217
-                    __(
1218
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1219
-                        'event_espresso'
1220
-                    ),
1221
-                    __FILE__,
1222
-                    __FUNCTION__,
1223
-                    __LINE__
1224
-                );
1225
-                return false;
1226
-            }
1227
-        }
1228
-        // now that things have been kinda sufficiently verified,
1229
-        // let's add the checkout to the session so that it's available to other systems
1230
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1231
-        return true;
1232
-    }
1233
-
1234
-
1235
-
1236
-    /**
1237
-     *    _initialize_reg_steps
1238
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1239
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1240
-     *
1241
-     * @access    private
1242
-     * @param bool $reinitializing
1243
-     * @throws EE_Error
1244
-     */
1245
-    private function _initialize_reg_steps($reinitializing = false)
1246
-    {
1247
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1248
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1249
-        foreach ($this->checkout->reg_steps as $reg_step) {
1250
-            if ( ! $reg_step->initialize_reg_step()) {
1251
-                // if not initialized then maybe this step is being removed...
1252
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1253
-                    // if it was the current step, then we need to start over here
1254
-                    $this->_initialize_reg_steps(true);
1255
-                    return;
1256
-                }
1257
-                continue;
1258
-            }
1259
-            // add css and JS for current step
1260
-            $reg_step->enqueue_styles_and_scripts();
1261
-            // i18n
1262
-            $reg_step->translate_js_strings();
1263
-            if ($reg_step->is_current_step()) {
1264
-                // the text that appears on the reg step form submit button
1265
-                $reg_step->set_submit_button_text();
1266
-            }
1267
-        }
1268
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1269
-        do_action(
1270
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1271
-            $this->checkout->current_step
1272
-        );
1273
-    }
1274
-
1275
-
1276
-
1277
-    /**
1278
-     * _check_form_submission
1279
-     *
1280
-     * @access private
1281
-     * @return boolean
1282
-     */
1283
-    private function _check_form_submission()
1284
-    {
1285
-        //does this request require the reg form to be generated ?
1286
-        if ($this->checkout->generate_reg_form) {
1287
-            // ever heard that song by Blue Rodeo ?
1288
-            try {
1289
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1290
-                // if not displaying a form, then check for form submission
1291
-                if (
1292
-                    $this->checkout->process_form_submission
1293
-                    && $this->checkout->current_step->reg_form->was_submitted()
1294
-                ) {
1295
-                    // clear out any old data in case this step is being run again
1296
-                    $this->checkout->current_step->set_valid_data(array());
1297
-                    // capture submitted form data
1298
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1299
-                        apply_filters(
1300
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1301
-                            EE_Registry::instance()->REQ->params(),
1302
-                            $this->checkout
1303
-                        )
1304
-                    );
1305
-                    // validate submitted form data
1306
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1307
-                        // thou shall not pass !!!
1308
-                        $this->checkout->continue_reg = false;
1309
-                        // any form validation errors?
1310
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1311
-                            $submission_error_messages = array();
1312
-                            // bad, bad, bad registrant
1313
-                            foreach (
1314
-                                $this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1315
-                                as $validation_error
1316
-                            ) {
1317
-                                if ($validation_error instanceof EE_Validation_Error) {
1318
-                                    $submission_error_messages[] = sprintf(
1319
-                                        __('%s : %s', 'event_espresso'),
1320
-                                        $validation_error->get_form_section()->html_label_text(),
1321
-                                        $validation_error->getMessage()
1322
-                                    );
1323
-                                }
1324
-                            }
1325
-                            EE_Error::add_error(
1326
-                                implode('<br />', $submission_error_messages),
1327
-                                __FILE__, __FUNCTION__, __LINE__
1328
-                            );
1329
-                        }
1330
-                        // well not really... what will happen is
1331
-                        // we'll just get redirected back to redo the current step
1332
-                        $this->go_to_next_step();
1333
-                        return false;
1334
-                    }
1335
-                }
1336
-            } catch (EE_Error $e) {
1337
-                $e->get_error();
1338
-            }
1339
-        }
1340
-        return true;
1341
-    }
1342
-
1343
-
1344
-
1345
-    /**
1346
-     * _process_action
1347
-     *
1348
-     * @access private
1349
-     * @return void
1350
-     * @throws EE_Error
1351
-     */
1352
-    private function _process_form_action()
1353
-    {
1354
-        // what cha wanna do?
1355
-        switch ($this->checkout->action) {
1356
-            // AJAX next step reg form
1357
-            case 'display_spco_reg_step' :
1358
-                $this->checkout->redirect = false;
1359
-                if (EE_Registry::instance()->REQ->ajax) {
1360
-                    $this->checkout->json_response->set_reg_step_html(
1361
-                        $this->checkout->current_step->display_reg_form()
1362
-                    );
1363
-                }
1364
-                break;
1365
-            default :
1366
-                // meh... do one of those other steps first
1367
-                if (
1368
-                    ! empty($this->checkout->action)
1369
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1370
-                ) {
1371
-                    // dynamically creates hook point like:
1372
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1373
-                    do_action(
1374
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1375
-                        $this->checkout->current_step
1376
-                    );
1377
-                    // call action on current step
1378
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1379
-                        // good registrant, you get to proceed
1380
-                        if (
1381
-                            $this->checkout->current_step->success_message() !== ''
1382
-                            && apply_filters(
1383
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1384
-                                false
1385
-                            )
1386
-                        ) {
1387
-                            EE_Error::add_success(
1388
-                                $this->checkout->current_step->success_message()
1389
-                                . '<br />' . $this->checkout->next_step->_instructions()
1390
-                            );
1391
-                        }
1392
-                        // pack it up, pack it in...
1393
-                        $this->_setup_redirect();
1394
-                    }
1395
-                    // dynamically creates hook point like:
1396
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1397
-                    do_action(
1398
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1399
-                        $this->checkout->current_step
1400
-                    );
1401
-                } else {
1402
-                    EE_Error::add_error(
1403
-                        sprintf(
1404
-                            __(
1405
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1406
-                                'event_espresso'
1407
-                            ),
1408
-                            $this->checkout->action,
1409
-                            $this->checkout->current_step->name()
1410
-                        ),
1411
-                        __FILE__,
1412
-                        __FUNCTION__,
1413
-                        __LINE__
1414
-                    );
1415
-                }
1416
-            // end default
1417
-        }
1418
-        // store our progress so far
1419
-        $this->checkout->stash_transaction_and_checkout();
1420
-        // advance to the next step! If you pass GO, collect $200
1421
-        $this->go_to_next_step();
1422
-    }
1423
-
1424
-
1425
-
1426
-    /**
1427
-     *        add_styles_and_scripts
1428
-     *
1429
-     * @access        public
1430
-     * @return        void
1431
-     */
1432
-    public function add_styles_and_scripts()
1433
-    {
1434
-        // i18n
1435
-        $this->translate_js_strings();
1436
-        if ($this->checkout->admin_request) {
1437
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1438
-        } else {
1439
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1440
-        }
1441
-    }
1442
-
1443
-
1444
-
1445
-    /**
1446
-     *        translate_js_strings
1447
-     *
1448
-     * @access        public
1449
-     * @return        void
1450
-     */
1451
-    public function translate_js_strings()
1452
-    {
1453
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1454
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1455
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1456
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1457
-            'event_espresso'
1458
-        );
1459
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1460
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1461
-            'event_espresso'
1462
-        );
1463
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1464
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1465
-            'event_espresso'
1466
-        );
1467
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1468
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1469
-            'event_espresso'
1470
-        );
1471
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1472
-            'This registration step could not be completed. Please refresh the page and try again.',
1473
-            'event_espresso'
1474
-        );
1475
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1476
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1477
-            'event_espresso'
1478
-        );
1479
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1480
-            __(
1481
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1482
-                'event_espresso'
1483
-            ),
1484
-            '<br/>',
1485
-            '<br/>'
1486
-        );
1487
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1488
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1489
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1490
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1491
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1492
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1493
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1494
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1495
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1496
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1497
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1498
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1499
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1500
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1501
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1502
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1503
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1504
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1505
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1506
-            __(
1507
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1508
-                'event_espresso'
1509
-            ),
1510
-            '<h4 class="important-notice">',
1511
-            '</h4>',
1512
-            '<br />',
1513
-            '<p>',
1514
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1515
-            '">',
1516
-            '</a>',
1517
-            '</p>'
1518
-        );
1519
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1520
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1521
-            true
1522
-        );
1523
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1524
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1525
-        );
1526
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1527
-            'M d, Y H:i:s',
1528
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1529
-        );
1530
-    }
1531
-
1532
-
1533
-
1534
-    /**
1535
-     *    enqueue_styles_and_scripts
1536
-     *
1537
-     * @access        public
1538
-     * @return        void
1539
-     * @throws EE_Error
1540
-     */
1541
-    public function enqueue_styles_and_scripts()
1542
-    {
1543
-        // load css
1544
-        wp_register_style(
1545
-            'single_page_checkout',
1546
-            SPCO_CSS_URL . 'single_page_checkout.css',
1547
-            array('espresso_default'),
1548
-            EVENT_ESPRESSO_VERSION
1549
-        );
1550
-        wp_enqueue_style('single_page_checkout');
1551
-        // load JS
1552
-        wp_register_script(
1553
-            'jquery_plugin',
1554
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1555
-            array('jquery'),
1556
-            '1.0.1',
1557
-            true
1558
-        );
1559
-        wp_register_script(
1560
-            'jquery_countdown',
1561
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1562
-            array('jquery_plugin'),
1563
-            '2.0.2',
1564
-            true
1565
-        );
1566
-        wp_register_script(
1567
-            'single_page_checkout',
1568
-            SPCO_JS_URL . 'single_page_checkout.js',
1569
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1570
-            EVENT_ESPRESSO_VERSION,
1571
-            true
1572
-        );
1573
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1574
-            $this->checkout->registration_form->enqueue_js();
1575
-        }
1576
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1577
-            $this->checkout->current_step->reg_form->enqueue_js();
1578
-        }
1579
-        wp_enqueue_script('single_page_checkout');
1580
-        /**
1581
-         * global action hook for enqueueing styles and scripts with
1582
-         * spco calls.
1583
-         */
1584
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1585
-        /**
1586
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1587
-         * The hook will end up being something like:
1588
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1589
-         */
1590
-        do_action(
1591
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1592
-            $this
1593
-        );
1594
-    }
1595
-
1596
-
1597
-
1598
-    /**
1599
-     *    display the Registration Single Page Checkout Form
1600
-     *
1601
-     * @access    private
1602
-     * @return    void
1603
-     * @throws EE_Error
1604
-     */
1605
-    private function _display_spco_reg_form()
1606
-    {
1607
-        // if registering via the admin, just display the reg form for the current step
1608
-        if ($this->checkout->admin_request) {
1609
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1610
-        } else {
1611
-            // add powered by EE msg
1612
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1613
-            $empty_cart = count(
1614
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1615
-            ) < 1;
1616
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1617
-            $cookies_not_set_msg = '';
1618
-            if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1619
-                $cookies_not_set_msg = apply_filters(
1620
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1621
-                    sprintf(
1622
-                        __(
1623
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1624
-                            'event_espresso'
1625
-                        ),
1626
-                        '<div class="ee-attention">',
1627
-                        '</div>',
1628
-                        '<h6 class="important-notice">',
1629
-                        '</h6>',
1630
-                        '<p>',
1631
-                        '</p>',
1632
-                        '<br />',
1633
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1634
-                        '</a>'
1635
-                    )
1636
-                );
1637
-            }
1638
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1639
-                array(
1640
-                    'name'            => 'single-page-checkout',
1641
-                    'html_id'         => 'ee-single-page-checkout-dv',
1642
-                    'layout_strategy' =>
1643
-                        new EE_Template_Layout(
1644
-                            array(
1645
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1646
-                                'template_args'        => array(
1647
-                                    'empty_cart'              => $empty_cart,
1648
-                                    'revisit'                 => $this->checkout->revisit,
1649
-                                    'reg_steps'               => $this->checkout->reg_steps,
1650
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1651
-                                        ? $this->checkout->next_step->slug()
1652
-                                        : '',
1653
-                                    'cancel_page_url'         => $this->checkout->cancel_page_url,
1654
-                                    'empty_msg'               => apply_filters(
1655
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1656
-                                        sprintf(
1657
-                                            __(
1658
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1659
-                                                'event_espresso'
1660
-                                            ),
1661
-                                            '<a href="'
1662
-                                            . get_post_type_archive_link('espresso_events')
1663
-                                            . '" title="',
1664
-                                            '">',
1665
-                                            '</a>'
1666
-                                        )
1667
-                                    ),
1668
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1669
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1670
-                                    'session_expiration'      => gmdate(
1671
-                                        'M d, Y H:i:s',
1672
-                                        EE_Registry::instance()->SSN->expiration()
1673
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1674
-                                    ),
1675
-                                ),
1676
-                            )
1677
-                        ),
1678
-                )
1679
-            );
1680
-            // load template and add to output sent that gets filtered into the_content()
1681
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1682
-        }
1683
-    }
1684
-
1685
-
1686
-
1687
-    /**
1688
-     *    add_extra_finalize_registration_inputs
1689
-     *
1690
-     * @access    public
1691
-     * @param $next_step
1692
-     * @internal  param string $label
1693
-     * @return void
1694
-     */
1695
-    public function add_extra_finalize_registration_inputs($next_step)
1696
-    {
1697
-        if ($next_step === 'finalize_registration') {
1698
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1699
-        }
1700
-    }
1701
-
1702
-
1703
-
1704
-    /**
1705
-     *    display_registration_footer
1706
-     *
1707
-     * @access    public
1708
-     * @return    string
1709
-     */
1710
-    public static function display_registration_footer()
1711
-    {
1712
-        if (
1713
-        apply_filters(
1714
-            'FHEE__EE_Front__Controller__show_reg_footer',
1715
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1716
-        )
1717
-        ) {
1718
-            add_filter(
1719
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1720
-                function ($url) {
1721
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1722
-                }
1723
-            );
1724
-            echo apply_filters(
1725
-                'FHEE__EE_Front_Controller__display_registration_footer',
1726
-                \EEH_Template::powered_by_event_espresso(
1727
-                    '',
1728
-                    'espresso-registration-footer-dv',
1729
-                    array('utm_content' => 'registration_checkout')
1730
-                )
1731
-            );
1732
-        }
1733
-        return '';
1734
-    }
1735
-
1736
-
1737
-
1738
-    /**
1739
-     *    unlock_transaction
1740
-     *
1741
-     * @access    public
1742
-     * @return    void
1743
-     * @throws EE_Error
1744
-     */
1745
-    public function unlock_transaction()
1746
-    {
1747
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1748
-            $this->checkout->transaction->unlock();
1749
-        }
1750
-    }
1751
-
1752
-
1753
-
1754
-    /**
1755
-     *        _setup_redirect
1756
-     *
1757
-     * @access    private
1758
-     * @return void
1759
-     */
1760
-    private function _setup_redirect()
1761
-    {
1762
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1763
-            $this->checkout->redirect = true;
1764
-            if (empty($this->checkout->redirect_url)) {
1765
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1766
-            }
1767
-            $this->checkout->redirect_url = apply_filters(
1768
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1769
-                $this->checkout->redirect_url,
1770
-                $this->checkout
1771
-            );
1772
-        }
1773
-    }
1774
-
1775
-
1776
-
1777
-    /**
1778
-     *   handle ajax message responses and redirects
1779
-     *
1780
-     * @access public
1781
-     * @return void
1782
-     * @throws EE_Error
1783
-     */
1784
-    public function go_to_next_step()
1785
-    {
1786
-        if (EE_Registry::instance()->REQ->ajax) {
1787
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1788
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1789
-        }
1790
-        $this->unlock_transaction();
1791
-        // just return for these conditions
1792
-        if (
1793
-            $this->checkout->admin_request
1794
-            || $this->checkout->action === 'redirect_form'
1795
-            || $this->checkout->action === 'update_checkout'
1796
-        ) {
1797
-            return;
1798
-        }
1799
-        // AJAX response
1800
-        $this->_handle_json_response();
1801
-        // redirect to next step or the Thank You page
1802
-        $this->_handle_html_redirects();
1803
-        // hmmm... must be something wrong, so let's just display the form again !
1804
-        $this->_display_spco_reg_form();
1805
-    }
1806
-
1807
-
1808
-
1809
-    /**
1810
-     *   _handle_json_response
1811
-     *
1812
-     * @access protected
1813
-     * @return void
1814
-     */
1815
-    protected function _handle_json_response()
1816
-    {
1817
-        // if this is an ajax request
1818
-        if (EE_Registry::instance()->REQ->ajax) {
1819
-            // DEBUG LOG
1820
-            //$this->checkout->log(
1821
-            //	__CLASS__, __FUNCTION__, __LINE__,
1822
-            //	array(
1823
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1824
-            //		'redirect'                   => $this->checkout->redirect,
1825
-            //		'continue_reg'               => $this->checkout->continue_reg,
1826
-            //	)
1827
-            //);
1828
-            $this->checkout->json_response->set_registration_time_limit(
1829
-                $this->checkout->get_registration_time_limit()
1830
-            );
1831
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1832
-            // just send the ajax (
1833
-            $json_response = apply_filters(
1834
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1835
-                $this->checkout->json_response
1836
-            );
1837
-            echo $json_response;
1838
-            exit();
1839
-        }
1840
-    }
1841
-
1842
-
1843
-
1844
-    /**
1845
-     *   _handle_redirects
1846
-     *
1847
-     * @access protected
1848
-     * @return void
1849
-     */
1850
-    protected function _handle_html_redirects()
1851
-    {
1852
-        // going somewhere ?
1853
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1854
-            // store notices in a transient
1855
-            EE_Error::get_notices(false, true, true);
1856
-            // DEBUG LOG
1857
-            //$this->checkout->log(
1858
-            //	__CLASS__, __FUNCTION__, __LINE__,
1859
-            //	array(
1860
-            //		'headers_sent' => headers_sent(),
1861
-            //		'redirect_url'     => $this->checkout->redirect_url,
1862
-            //		'headers_list'    => headers_list(),
1863
-            //	)
1864
-            //);
1865
-            wp_safe_redirect($this->checkout->redirect_url);
1866
-            exit();
1867
-        }
1868
-    }
1869
-
1870
-
1871
-
1872
-    /**
1873
-     *   set_checkout_anchor
1874
-     *
1875
-     * @access public
1876
-     * @return void
1877
-     */
1878
-    public function set_checkout_anchor()
1879
-    {
1880
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1881
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
+			__('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
237
+				'event_espresso'),
238
+			'<h4 class="important-notice">',
239
+			'</h4>',
240
+			'<br />',
241
+			'<p>',
242
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
243
+			'">',
244
+			'</a>',
245
+			'</p>'
246
+		);
247
+	}
248
+
249
+
250
+
251
+	/**
252
+	 * load_reg_steps
253
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
254
+	 *
255
+	 * @access    private
256
+	 * @throws EE_Error
257
+	 */
258
+	public static function load_reg_steps()
259
+	{
260
+		static $reg_steps_loaded = false;
261
+		if ($reg_steps_loaded) {
262
+			return;
263
+		}
264
+		// filter list of reg_steps
265
+		$reg_steps_to_load = (array)apply_filters(
266
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
267
+			EED_Single_Page_Checkout::get_reg_steps()
268
+		);
269
+		// sort by key (order)
270
+		ksort($reg_steps_to_load);
271
+		// loop through folders
272
+		foreach ($reg_steps_to_load as $order => $reg_step) {
273
+			// we need a
274
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
275
+				// copy over to the reg_steps_array
276
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
277
+				// register custom key route for each reg step
278
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
279
+				EE_Config::register_route(
280
+					$reg_step['slug'],
281
+					'EED_Single_Page_Checkout',
282
+					'run',
283
+					'step'
284
+				);
285
+				// add AJAX or other hooks
286
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
287
+					// setup autoloaders if necessary
288
+					if ( ! class_exists($reg_step['class_name'])) {
289
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
290
+							$reg_step['file_path'],
291
+							true
292
+						);
293
+					}
294
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
295
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
296
+					}
297
+				}
298
+			}
299
+		}
300
+		$reg_steps_loaded = true;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 *    get_reg_steps
307
+	 *
308
+	 * @access    public
309
+	 * @return    array
310
+	 */
311
+	public static function get_reg_steps()
312
+	{
313
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
314
+		if (empty($reg_steps)) {
315
+			$reg_steps = array(
316
+				10  => array(
317
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
318
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
319
+					'slug'       => 'attendee_information',
320
+					'has_hooks'  => false,
321
+				),
322
+				20  => array(
323
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
324
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
325
+					'slug'       => 'registration_confirmation',
326
+					'has_hooks'  => false,
327
+				),
328
+				30  => array(
329
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
330
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
331
+					'slug'       => 'payment_options',
332
+					'has_hooks'  => true,
333
+				),
334
+				999 => array(
335
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
336
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
337
+					'slug'       => 'finalize_registration',
338
+					'has_hooks'  => false,
339
+				),
340
+			);
341
+		}
342
+		return $reg_steps;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 *    registration_checkout_for_admin
349
+	 *
350
+	 * @access    public
351
+	 * @return    string
352
+	 * @throws EE_Error
353
+	 */
354
+	public static function registration_checkout_for_admin()
355
+	{
356
+		EED_Single_Page_Checkout::load_request_handler();
357
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
358
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
359
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
360
+		EED_Single_Page_Checkout::instance()->_initialize();
361
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
362
+		return EE_Registry::instance()->REQ->get_output();
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 * process_registration_from_admin
369
+	 *
370
+	 * @access public
371
+	 * @return \EE_Transaction
372
+	 * @throws EE_Error
373
+	 */
374
+	public static function process_registration_from_admin()
375
+	{
376
+		EED_Single_Page_Checkout::load_request_handler();
377
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
378
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
379
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
380
+		EED_Single_Page_Checkout::instance()->_initialize();
381
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
382
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
383
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
384
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
385
+				if ($final_reg_step->process_reg_step()) {
386
+					$final_reg_step->set_completed();
387
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
388
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
389
+				}
390
+			}
391
+		}
392
+		return null;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 *    run
399
+	 *
400
+	 * @access    public
401
+	 * @param WP_Query $WP_Query
402
+	 * @return    void
403
+	 * @throws EE_Error
404
+	 */
405
+	public function run($WP_Query)
406
+	{
407
+		if (
408
+			$WP_Query instanceof WP_Query
409
+			&& $WP_Query->is_main_query()
410
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
411
+			&& $this->_is_reg_checkout()
412
+		) {
413
+			$this->_initialize();
414
+		}
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * determines whether current url matches reg page url
421
+	 *
422
+	 * @return bool
423
+	 */
424
+	protected function _is_reg_checkout()
425
+	{
426
+		// get current permalink for reg page without any extra query args
427
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
428
+		// get request URI for current request, but without the scheme or host
429
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
430
+		$current_request_uri = html_entity_decode($current_request_uri);
431
+		// get array of query args from the current request URI
432
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
433
+		// grab page id if it is set
434
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
435
+		// and remove the page id from the query args (we will re-add it later)
436
+		unset($query_args['page_id']);
437
+		// now strip all query args from current request URI
438
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
439
+		// and re-add the page id if it was set
440
+		if ($page_id) {
441
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
442
+		}
443
+		// remove slashes and ?
444
+		$current_request_uri = trim($current_request_uri, '?/');
445
+		// is current request URI part of the known full reg page URL ?
446
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * @param WP_Query $wp_query
453
+	 * @return    void
454
+	 * @throws EE_Error
455
+	 */
456
+	public static function init($wp_query)
457
+	{
458
+		EED_Single_Page_Checkout::instance()->run($wp_query);
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 *    _initialize - initial module setup
465
+	 *
466
+	 * @access    private
467
+	 * @throws EE_Error
468
+	 * @return    void
469
+	 */
470
+	private function _initialize()
471
+	{
472
+		// ensure SPCO doesn't run twice
473
+		if (EED_Single_Page_Checkout::$_initialized) {
474
+			return;
475
+		}
476
+		try {
477
+			EED_Single_Page_Checkout::load_reg_steps();
478
+			$this->_verify_session();
479
+			// setup the EE_Checkout object
480
+			$this->checkout = $this->_initialize_checkout();
481
+			// filter checkout
482
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
483
+			// get the $_GET
484
+			$this->_get_request_vars();
485
+			if ($this->_block_bots()) {
486
+				return;
487
+			}
488
+			// filter continue_reg
489
+			$this->checkout->continue_reg = apply_filters(
490
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
491
+				true,
492
+				$this->checkout
493
+			);
494
+			// load the reg steps array
495
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
496
+				EED_Single_Page_Checkout::$_initialized = true;
497
+				return;
498
+			}
499
+			// set the current step
500
+			$this->checkout->set_current_step($this->checkout->step);
501
+			// and the next step
502
+			$this->checkout->set_next_step();
503
+			// verify that everything has been setup correctly
504
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
505
+				EED_Single_Page_Checkout::$_initialized = true;
506
+				return;
507
+			}
508
+			// lock the transaction
509
+			$this->checkout->transaction->lock();
510
+			// make sure all of our cached objects are added to their respective model entity mappers
511
+			$this->checkout->refresh_all_entities();
512
+			// set amount owing
513
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
514
+			// initialize each reg step, which gives them the chance to potentially alter the process
515
+			$this->_initialize_reg_steps();
516
+			// DEBUG LOG
517
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
518
+			// get reg form
519
+			if( ! $this->_check_form_submission()) {
520
+				EED_Single_Page_Checkout::$_initialized = true;
521
+				return;
522
+			}
523
+			// checkout the action!!!
524
+			$this->_process_form_action();
525
+			// add some style and make it dance
526
+			$this->add_styles_and_scripts();
527
+			// kk... SPCO has successfully run
528
+			EED_Single_Page_Checkout::$_initialized = true;
529
+			// set no cache headers and constants
530
+			EE_System::do_not_cache();
531
+			// add anchor
532
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
533
+			// remove transaction lock
534
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
535
+		} catch (Exception $e) {
536
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
+		}
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 *    _verify_session
544
+	 * checks that the session is valid and not expired
545
+	 *
546
+	 * @access    private
547
+	 * @throws EE_Error
548
+	 */
549
+	private function _verify_session()
550
+	{
551
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
552
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
553
+		}
554
+		$clear_session_requested = filter_var(
555
+			EE_Registry::instance()->REQ->get('clear_session', false),
556
+			FILTER_VALIDATE_BOOLEAN
557
+		);
558
+		// is session still valid ?
559
+		if ($clear_session_requested
560
+			|| ( EE_Registry::instance()->SSN->expired()
561
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
562
+			)
563
+		) {
564
+			$this->checkout = new EE_Checkout();
565
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
566
+			// EE_Registry::instance()->SSN->reset_cart();
567
+			// EE_Registry::instance()->SSN->reset_checkout();
568
+			// EE_Registry::instance()->SSN->reset_transaction();
569
+			if (! $clear_session_requested) {
570
+				EE_Error::add_attention(
571
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
572
+					__FILE__, __FUNCTION__, __LINE__
573
+				);
574
+			}
575
+			// EE_Registry::instance()->SSN->reset_expired();
576
+		}
577
+	}
578
+
579
+
580
+
581
+	/**
582
+	 *    _initialize_checkout
583
+	 * loads and instantiates EE_Checkout
584
+	 *
585
+	 * @access    private
586
+	 * @throws EE_Error
587
+	 * @return EE_Checkout
588
+	 */
589
+	private function _initialize_checkout()
590
+	{
591
+		// look in session for existing checkout
592
+		/** @type EE_Checkout $checkout */
593
+		$checkout = EE_Registry::instance()->SSN->checkout();
594
+		// verify
595
+		if ( ! $checkout instanceof EE_Checkout) {
596
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
597
+			$checkout = EE_Registry::instance()->load_file(
598
+				SPCO_INC_PATH,
599
+				'EE_Checkout',
600
+				'class', array(),
601
+				false
602
+			);
603
+		} else {
604
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
605
+				$this->unlock_transaction();
606
+				wp_safe_redirect($checkout->redirect_url);
607
+				exit();
608
+			}
609
+		}
610
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
611
+		// verify again
612
+		if ( ! $checkout instanceof EE_Checkout) {
613
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
614
+		}
615
+		// reset anything that needs a clean slate for each request
616
+		$checkout->reset_for_current_request();
617
+		return $checkout;
618
+	}
619
+
620
+
621
+
622
+	/**
623
+	 *    _get_request_vars
624
+	 *
625
+	 * @access    private
626
+	 * @return    void
627
+	 * @throws EE_Error
628
+	 */
629
+	private function _get_request_vars()
630
+	{
631
+		// load classes
632
+		EED_Single_Page_Checkout::load_request_handler();
633
+		//make sure this request is marked as belonging to EE
634
+		EE_Registry::instance()->REQ->set_espresso_page(true);
635
+		// which step is being requested ?
636
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
637
+		// which step is being edited ?
638
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
639
+		// and what we're doing on the current step
640
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
641
+		// timestamp
642
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
643
+		// returning to edit ?
644
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
645
+		// add reg url link to registration query params
646
+		if ($this->checkout->reg_url_link) {
647
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
648
+		}
649
+		// or some other kind of revisit ?
650
+		$this->checkout->revisit = filter_var(
651
+			EE_Registry::instance()->REQ->get('revisit', false),
652
+			FILTER_VALIDATE_BOOLEAN
653
+		);
654
+		// and whether or not to generate a reg form for this request
655
+		$this->checkout->generate_reg_form = filter_var(
656
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
657
+			FILTER_VALIDATE_BOOLEAN
658
+		);
659
+		// and whether or not to process a reg form submission for this request
660
+		$this->checkout->process_form_submission = filter_var(
661
+			EE_Registry::instance()->REQ->get(
662
+				'process_form_submission',
663
+				$this->checkout->action === 'process_reg_step'
664
+			),
665
+			FILTER_VALIDATE_BOOLEAN
666
+		);
667
+		$this->checkout->process_form_submission = filter_var(
668
+			$this->checkout->action !== 'display_spco_reg_step'
669
+				? $this->checkout->process_form_submission
670
+				: false,
671
+			FILTER_VALIDATE_BOOLEAN
672
+		);
673
+		// $this->_display_request_vars();
674
+	}
675
+
676
+
677
+
678
+	/**
679
+	 *  _display_request_vars
680
+	 *
681
+	 * @access    protected
682
+	 * @return    void
683
+	 */
684
+	protected function _display_request_vars()
685
+	{
686
+		if ( ! WP_DEBUG) {
687
+			return;
688
+		}
689
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
690
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
691
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
692
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
693
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
694
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
695
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
696
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * _block_bots
703
+	 * checks that the incoming request has either of the following set:
704
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
705
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
706
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
707
+	 * then where you coming from man?
708
+	 *
709
+	 * @return boolean
710
+	 */
711
+	private function _block_bots()
712
+	{
713
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
714
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
715
+			return true;
716
+		}
717
+		return false;
718
+	}
719
+
720
+
721
+
722
+	/**
723
+	 *    _get_first_step
724
+	 *  gets slug for first step in $_reg_steps_array
725
+	 *
726
+	 * @access    private
727
+	 * @throws EE_Error
728
+	 * @return    string
729
+	 */
730
+	private function _get_first_step()
731
+	{
732
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
733
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
734
+	}
735
+
736
+
737
+
738
+	/**
739
+	 *    _load_and_instantiate_reg_steps
740
+	 *  instantiates each reg step based on the loaded reg_steps array
741
+	 *
742
+	 * @access    private
743
+	 * @throws EE_Error
744
+	 * @return    bool
745
+	 */
746
+	private function _load_and_instantiate_reg_steps()
747
+	{
748
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
749
+		// have reg_steps already been instantiated ?
750
+		if (
751
+			empty($this->checkout->reg_steps)
752
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
753
+		) {
754
+			// if not, then loop through raw reg steps array
755
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
756
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
757
+					return false;
758
+				}
759
+			}
760
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
761
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
762
+			// skip the registration_confirmation page ?
763
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
764
+				// just remove it from the reg steps array
765
+				$this->checkout->remove_reg_step('registration_confirmation', false);
766
+			} else if (
767
+				isset($this->checkout->reg_steps['registration_confirmation'])
768
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
769
+			) {
770
+				// set the order to something big like 100
771
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
772
+			}
773
+			// filter the array for good luck
774
+			$this->checkout->reg_steps = apply_filters(
775
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
776
+				$this->checkout->reg_steps
777
+			);
778
+			// finally re-sort based on the reg step class order properties
779
+			$this->checkout->sort_reg_steps();
780
+		} else {
781
+			foreach ($this->checkout->reg_steps as $reg_step) {
782
+				// set all current step stati to FALSE
783
+				$reg_step->set_is_current_step(false);
784
+			}
785
+		}
786
+		if (empty($this->checkout->reg_steps)) {
787
+			EE_Error::add_error(
788
+				__('No Reg Steps were loaded..', 'event_espresso'),
789
+				__FILE__, __FUNCTION__, __LINE__
790
+			);
791
+			return false;
792
+		}
793
+		// make reg step details available to JS
794
+		$this->checkout->set_reg_step_JSON_info();
795
+		return true;
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 *     _load_and_instantiate_reg_step
802
+	 *
803
+	 * @access    private
804
+	 * @param array $reg_step
805
+	 * @param int   $order
806
+	 * @return bool
807
+	 */
808
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
809
+	{
810
+		// we need a file_path, class_name, and slug to add a reg step
811
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
812
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
813
+			if (
814
+				$this->checkout->reg_url_link
815
+				&& $this->checkout->step !== $reg_step['slug']
816
+				&& $reg_step['slug'] !== 'finalize_registration'
817
+				// normally at this point we would NOT load the reg step, but this filter can change that
818
+				&& apply_filters(
819
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
820
+					true,
821
+					$reg_step,
822
+					$this->checkout
823
+				)
824
+			) {
825
+				return true;
826
+			}
827
+			// instantiate step class using file path and class name
828
+			$reg_step_obj = EE_Registry::instance()->load_file(
829
+				$reg_step['file_path'],
830
+				$reg_step['class_name'],
831
+				'class',
832
+				$this->checkout,
833
+				false
834
+			);
835
+			// did we gets the goods ?
836
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
837
+				// set reg step order based on config
838
+				$reg_step_obj->set_order($order);
839
+				// add instantiated reg step object to the master reg steps array
840
+				$this->checkout->add_reg_step($reg_step_obj);
841
+			} else {
842
+				EE_Error::add_error(
843
+					__('The current step could not be set.', 'event_espresso'),
844
+					__FILE__, __FUNCTION__, __LINE__
845
+				);
846
+				return false;
847
+			}
848
+		} else {
849
+			if (WP_DEBUG) {
850
+				EE_Error::add_error(
851
+					sprintf(
852
+						__(
853
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
854
+							'event_espresso'
855
+						),
856
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
857
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
858
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
859
+						'<ul>',
860
+						'<li>',
861
+						'</li>',
862
+						'</ul>'
863
+					),
864
+					__FILE__, __FUNCTION__, __LINE__
865
+				);
866
+			}
867
+			return false;
868
+		}
869
+		return true;
870
+	}
871
+
872
+
873
+	/**
874
+	 * _verify_transaction_and_get_registrations
875
+	 *
876
+	 * @access private
877
+	 * @return bool
878
+	 * @throws InvalidDataTypeException
879
+	 * @throws InvalidEntityException
880
+	 * @throws EE_Error
881
+	 */
882
+	private function _verify_transaction_and_get_registrations()
883
+	{
884
+		// was there already a valid transaction in the checkout from the session ?
885
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
886
+			// get transaction from db or session
887
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
888
+				? $this->_get_transaction_and_cart_for_previous_visit()
889
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
890
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
891
+				EE_Error::add_error(
892
+					__('Your Registration and Transaction information could not be retrieved from the db.',
893
+						'event_espresso'),
894
+					__FILE__, __FUNCTION__, __LINE__
895
+				);
896
+				$this->checkout->transaction = EE_Transaction::new_instance();
897
+				// add some style and make it dance
898
+				$this->add_styles_and_scripts();
899
+				EED_Single_Page_Checkout::$_initialized = true;
900
+				return false;
901
+			}
902
+			// and the registrations for the transaction
903
+			$this->_get_registrations($this->checkout->transaction);
904
+		}
905
+		return true;
906
+	}
907
+
908
+
909
+
910
+	/**
911
+	 * _get_transaction_and_cart_for_previous_visit
912
+	 *
913
+	 * @access private
914
+	 * @return mixed EE_Transaction|NULL
915
+	 */
916
+	private function _get_transaction_and_cart_for_previous_visit()
917
+	{
918
+		/** @var $TXN_model EEM_Transaction */
919
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
920
+		// because the reg_url_link is present in the request,
921
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
922
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
923
+		// verify transaction
924
+		if ($transaction instanceof EE_Transaction) {
925
+			// and get the cart that was used for that transaction
926
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
927
+			return $transaction;
928
+		}
929
+		EE_Error::add_error(
930
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
931
+			__FILE__, __FUNCTION__, __LINE__
932
+		);
933
+		return null;
934
+
935
+	}
936
+
937
+
938
+
939
+	/**
940
+	 * _get_cart_for_transaction
941
+	 *
942
+	 * @access private
943
+	 * @param EE_Transaction $transaction
944
+	 * @return EE_Cart
945
+	 */
946
+	private function _get_cart_for_transaction($transaction)
947
+	{
948
+		return $this->checkout->get_cart_for_transaction($transaction);
949
+	}
950
+
951
+
952
+
953
+	/**
954
+	 * get_cart_for_transaction
955
+	 *
956
+	 * @access public
957
+	 * @param EE_Transaction $transaction
958
+	 * @return EE_Cart
959
+	 */
960
+	public function get_cart_for_transaction(EE_Transaction $transaction)
961
+	{
962
+		return $this->checkout->get_cart_for_transaction($transaction);
963
+	}
964
+
965
+
966
+
967
+	/**
968
+	 * _get_transaction_and_cart_for_current_session
969
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
970
+	 *
971
+	 * @access private
972
+	 * @return EE_Transaction
973
+	 * @throws EE_Error
974
+	 */
975
+	private function _get_cart_for_current_session_and_setup_new_transaction()
976
+	{
977
+		//  if there's no transaction, then this is the FIRST visit to SPCO
978
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
979
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
980
+		// and then create a new transaction
981
+		$transaction = $this->_initialize_transaction();
982
+		// verify transaction
983
+		if ($transaction instanceof EE_Transaction) {
984
+			// save it so that we have an ID for other objects to use
985
+			$transaction->save();
986
+			// and save TXN data to the cart
987
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
988
+		} else {
989
+			EE_Error::add_error(
990
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
991
+				__FILE__, __FUNCTION__, __LINE__
992
+			);
993
+		}
994
+		return $transaction;
995
+	}
996
+
997
+
998
+
999
+	/**
1000
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
1001
+	 *
1002
+	 * @access private
1003
+	 * @return mixed EE_Transaction|NULL
1004
+	 */
1005
+	private function _initialize_transaction()
1006
+	{
1007
+		try {
1008
+			// ensure cart totals have been calculated
1009
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
1010
+			// grab the cart grand total
1011
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1012
+			// create new TXN
1013
+			$transaction = EE_Transaction::new_instance(
1014
+				array(
1015
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1016
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1017
+					'TXN_paid'      => 0,
1018
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1019
+				)
1020
+			);
1021
+			// save it so that we have an ID for other objects to use
1022
+			$transaction->save();
1023
+			// set cron job for following up on TXNs after their session has expired
1024
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1025
+				EE_Registry::instance()->SSN->expiration() + 1,
1026
+				$transaction->ID()
1027
+			);
1028
+			return $transaction;
1029
+		} catch (Exception $e) {
1030
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1031
+		}
1032
+		return null;
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * _get_registrations
1038
+	 *
1039
+	 * @access private
1040
+	 * @param EE_Transaction $transaction
1041
+	 * @return void
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidEntityException
1044
+	 * @throws EE_Error
1045
+	 */
1046
+	private function _get_registrations(EE_Transaction $transaction)
1047
+	{
1048
+		// first step: grab the registrants  { : o
1049
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
1050
+		$this->checkout->total_ticket_count = count($registrations);
1051
+		// verify registrations have been set
1052
+		if (empty($registrations)) {
1053
+			// if no cached registrations, then check the db
1054
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1055
+			// still nothing ? well as long as this isn't a revisit
1056
+			if (empty($registrations) && ! $this->checkout->revisit) {
1057
+				// generate new registrations from scratch
1058
+				$registrations = $this->_initialize_registrations($transaction);
1059
+			}
1060
+		}
1061
+		// sort by their original registration order
1062
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1063
+		// then loop thru the array
1064
+		foreach ($registrations as $registration) {
1065
+			// verify each registration
1066
+			if ($registration instanceof EE_Registration) {
1067
+				// we display all attendee info for the primary registrant
1068
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1069
+					&& $registration->is_primary_registrant()
1070
+				) {
1071
+					$this->checkout->primary_revisit = true;
1072
+					break;
1073
+				}
1074
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1075
+					// but hide info if it doesn't belong to you
1076
+					$transaction->clear_cache('Registration', $registration->ID());
1077
+					$this->checkout->total_ticket_count--;
1078
+				}
1079
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1080
+			}
1081
+		}
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1087
+	 *
1088
+	 * @access private
1089
+	 * @param EE_Transaction $transaction
1090
+	 * @return    array
1091
+	 * @throws InvalidDataTypeException
1092
+	 * @throws InvalidEntityException
1093
+	 * @throws EE_Error
1094
+	 */
1095
+	private function _initialize_registrations(EE_Transaction $transaction)
1096
+	{
1097
+		$att_nmbr = 0;
1098
+		$registrations = array();
1099
+		if ($transaction instanceof EE_Transaction) {
1100
+			/** @type EE_Registration_Processor $registration_processor */
1101
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1102
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1103
+			// now let's add the cart items to the $transaction
1104
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1105
+				//do the following for each ticket of this type they selected
1106
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1107
+					$att_nmbr++;
1108
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1109
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1110
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1111
+						array(
1112
+							$transaction,
1113
+							$line_item,
1114
+							$att_nmbr,
1115
+							$this->checkout->total_ticket_count,
1116
+						)
1117
+					);
1118
+					// override capabilities for frontend registrations
1119
+					if ( ! is_admin()) {
1120
+						$CreateRegistrationCommand->setCapCheck(
1121
+							new PublicCapabilities('', 'create_new_registration')
1122
+						);
1123
+					}
1124
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1125
+					if ( ! $registration instanceof EE_Registration) {
1126
+						throw new InvalidEntityException($registration, 'EE_Registration');
1127
+					}
1128
+					$registrations[ $registration->ID() ] = $registration;
1129
+				}
1130
+			}
1131
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1132
+		}
1133
+		return $registrations;
1134
+	}
1135
+
1136
+
1137
+
1138
+	/**
1139
+	 * sorts registrations by REG_count
1140
+	 *
1141
+	 * @access public
1142
+	 * @param EE_Registration $reg_A
1143
+	 * @param EE_Registration $reg_B
1144
+	 * @return int
1145
+	 */
1146
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1147
+	{
1148
+		// this shouldn't ever happen within the same TXN, but oh well
1149
+		if ($reg_A->count() === $reg_B->count()) {
1150
+			return 0;
1151
+		}
1152
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 *    _final_verifications
1159
+	 * just makes sure that everything is set up correctly before proceeding
1160
+	 *
1161
+	 * @access    private
1162
+	 * @return    bool
1163
+	 * @throws EE_Error
1164
+	 */
1165
+	private function _final_verifications()
1166
+	{
1167
+		// filter checkout
1168
+		$this->checkout = apply_filters(
1169
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1170
+			$this->checkout
1171
+		);
1172
+		//verify that current step is still set correctly
1173
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1174
+			EE_Error::add_error(
1175
+				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1176
+				__FILE__,
1177
+				__FUNCTION__,
1178
+				__LINE__
1179
+			);
1180
+			return false;
1181
+		}
1182
+		// if returning to SPCO, then verify that primary registrant is set
1183
+		if ( ! empty($this->checkout->reg_url_link)) {
1184
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1185
+			if ( ! $valid_registrant instanceof EE_Registration) {
1186
+				EE_Error::add_error(
1187
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1188
+					__FILE__,
1189
+					__FUNCTION__,
1190
+					__LINE__
1191
+				);
1192
+				return false;
1193
+			}
1194
+			$valid_registrant = null;
1195
+			foreach (
1196
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1197
+			) {
1198
+				if (
1199
+					$registration instanceof EE_Registration
1200
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1201
+				) {
1202
+					$valid_registrant = $registration;
1203
+				}
1204
+			}
1205
+			if ( ! $valid_registrant instanceof EE_Registration) {
1206
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1207
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1208
+					// clear the session, mark the checkout as unverified, and try again
1209
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1210
+					EED_Single_Page_Checkout::$_initialized = false;
1211
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1212
+					$this->_initialize();
1213
+					EE_Error::reset_notices();
1214
+					return false;
1215
+				}
1216
+				EE_Error::add_error(
1217
+					__(
1218
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1219
+						'event_espresso'
1220
+					),
1221
+					__FILE__,
1222
+					__FUNCTION__,
1223
+					__LINE__
1224
+				);
1225
+				return false;
1226
+			}
1227
+		}
1228
+		// now that things have been kinda sufficiently verified,
1229
+		// let's add the checkout to the session so that it's available to other systems
1230
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1231
+		return true;
1232
+	}
1233
+
1234
+
1235
+
1236
+	/**
1237
+	 *    _initialize_reg_steps
1238
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1239
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1240
+	 *
1241
+	 * @access    private
1242
+	 * @param bool $reinitializing
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	private function _initialize_reg_steps($reinitializing = false)
1246
+	{
1247
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1248
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1249
+		foreach ($this->checkout->reg_steps as $reg_step) {
1250
+			if ( ! $reg_step->initialize_reg_step()) {
1251
+				// if not initialized then maybe this step is being removed...
1252
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1253
+					// if it was the current step, then we need to start over here
1254
+					$this->_initialize_reg_steps(true);
1255
+					return;
1256
+				}
1257
+				continue;
1258
+			}
1259
+			// add css and JS for current step
1260
+			$reg_step->enqueue_styles_and_scripts();
1261
+			// i18n
1262
+			$reg_step->translate_js_strings();
1263
+			if ($reg_step->is_current_step()) {
1264
+				// the text that appears on the reg step form submit button
1265
+				$reg_step->set_submit_button_text();
1266
+			}
1267
+		}
1268
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1269
+		do_action(
1270
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1271
+			$this->checkout->current_step
1272
+		);
1273
+	}
1274
+
1275
+
1276
+
1277
+	/**
1278
+	 * _check_form_submission
1279
+	 *
1280
+	 * @access private
1281
+	 * @return boolean
1282
+	 */
1283
+	private function _check_form_submission()
1284
+	{
1285
+		//does this request require the reg form to be generated ?
1286
+		if ($this->checkout->generate_reg_form) {
1287
+			// ever heard that song by Blue Rodeo ?
1288
+			try {
1289
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1290
+				// if not displaying a form, then check for form submission
1291
+				if (
1292
+					$this->checkout->process_form_submission
1293
+					&& $this->checkout->current_step->reg_form->was_submitted()
1294
+				) {
1295
+					// clear out any old data in case this step is being run again
1296
+					$this->checkout->current_step->set_valid_data(array());
1297
+					// capture submitted form data
1298
+					$this->checkout->current_step->reg_form->receive_form_submission(
1299
+						apply_filters(
1300
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1301
+							EE_Registry::instance()->REQ->params(),
1302
+							$this->checkout
1303
+						)
1304
+					);
1305
+					// validate submitted form data
1306
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1307
+						// thou shall not pass !!!
1308
+						$this->checkout->continue_reg = false;
1309
+						// any form validation errors?
1310
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1311
+							$submission_error_messages = array();
1312
+							// bad, bad, bad registrant
1313
+							foreach (
1314
+								$this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1315
+								as $validation_error
1316
+							) {
1317
+								if ($validation_error instanceof EE_Validation_Error) {
1318
+									$submission_error_messages[] = sprintf(
1319
+										__('%s : %s', 'event_espresso'),
1320
+										$validation_error->get_form_section()->html_label_text(),
1321
+										$validation_error->getMessage()
1322
+									);
1323
+								}
1324
+							}
1325
+							EE_Error::add_error(
1326
+								implode('<br />', $submission_error_messages),
1327
+								__FILE__, __FUNCTION__, __LINE__
1328
+							);
1329
+						}
1330
+						// well not really... what will happen is
1331
+						// we'll just get redirected back to redo the current step
1332
+						$this->go_to_next_step();
1333
+						return false;
1334
+					}
1335
+				}
1336
+			} catch (EE_Error $e) {
1337
+				$e->get_error();
1338
+			}
1339
+		}
1340
+		return true;
1341
+	}
1342
+
1343
+
1344
+
1345
+	/**
1346
+	 * _process_action
1347
+	 *
1348
+	 * @access private
1349
+	 * @return void
1350
+	 * @throws EE_Error
1351
+	 */
1352
+	private function _process_form_action()
1353
+	{
1354
+		// what cha wanna do?
1355
+		switch ($this->checkout->action) {
1356
+			// AJAX next step reg form
1357
+			case 'display_spco_reg_step' :
1358
+				$this->checkout->redirect = false;
1359
+				if (EE_Registry::instance()->REQ->ajax) {
1360
+					$this->checkout->json_response->set_reg_step_html(
1361
+						$this->checkout->current_step->display_reg_form()
1362
+					);
1363
+				}
1364
+				break;
1365
+			default :
1366
+				// meh... do one of those other steps first
1367
+				if (
1368
+					! empty($this->checkout->action)
1369
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1370
+				) {
1371
+					// dynamically creates hook point like:
1372
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1373
+					do_action(
1374
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1375
+						$this->checkout->current_step
1376
+					);
1377
+					// call action on current step
1378
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1379
+						// good registrant, you get to proceed
1380
+						if (
1381
+							$this->checkout->current_step->success_message() !== ''
1382
+							&& apply_filters(
1383
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1384
+								false
1385
+							)
1386
+						) {
1387
+							EE_Error::add_success(
1388
+								$this->checkout->current_step->success_message()
1389
+								. '<br />' . $this->checkout->next_step->_instructions()
1390
+							);
1391
+						}
1392
+						// pack it up, pack it in...
1393
+						$this->_setup_redirect();
1394
+					}
1395
+					// dynamically creates hook point like:
1396
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1397
+					do_action(
1398
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1399
+						$this->checkout->current_step
1400
+					);
1401
+				} else {
1402
+					EE_Error::add_error(
1403
+						sprintf(
1404
+							__(
1405
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1406
+								'event_espresso'
1407
+							),
1408
+							$this->checkout->action,
1409
+							$this->checkout->current_step->name()
1410
+						),
1411
+						__FILE__,
1412
+						__FUNCTION__,
1413
+						__LINE__
1414
+					);
1415
+				}
1416
+			// end default
1417
+		}
1418
+		// store our progress so far
1419
+		$this->checkout->stash_transaction_and_checkout();
1420
+		// advance to the next step! If you pass GO, collect $200
1421
+		$this->go_to_next_step();
1422
+	}
1423
+
1424
+
1425
+
1426
+	/**
1427
+	 *        add_styles_and_scripts
1428
+	 *
1429
+	 * @access        public
1430
+	 * @return        void
1431
+	 */
1432
+	public function add_styles_and_scripts()
1433
+	{
1434
+		// i18n
1435
+		$this->translate_js_strings();
1436
+		if ($this->checkout->admin_request) {
1437
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1438
+		} else {
1439
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1440
+		}
1441
+	}
1442
+
1443
+
1444
+
1445
+	/**
1446
+	 *        translate_js_strings
1447
+	 *
1448
+	 * @access        public
1449
+	 * @return        void
1450
+	 */
1451
+	public function translate_js_strings()
1452
+	{
1453
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1454
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1455
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1456
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1457
+			'event_espresso'
1458
+		);
1459
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1460
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1461
+			'event_espresso'
1462
+		);
1463
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1464
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1465
+			'event_espresso'
1466
+		);
1467
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1468
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1469
+			'event_espresso'
1470
+		);
1471
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1472
+			'This registration step could not be completed. Please refresh the page and try again.',
1473
+			'event_espresso'
1474
+		);
1475
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1476
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1477
+			'event_espresso'
1478
+		);
1479
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1480
+			__(
1481
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1482
+				'event_espresso'
1483
+			),
1484
+			'<br/>',
1485
+			'<br/>'
1486
+		);
1487
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1488
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1489
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1490
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1491
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1492
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1493
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1494
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1495
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1496
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1497
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1498
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1499
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1500
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1501
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1502
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1503
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1504
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1505
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1506
+			__(
1507
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1508
+				'event_espresso'
1509
+			),
1510
+			'<h4 class="important-notice">',
1511
+			'</h4>',
1512
+			'<br />',
1513
+			'<p>',
1514
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1515
+			'">',
1516
+			'</a>',
1517
+			'</p>'
1518
+		);
1519
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1520
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1521
+			true
1522
+		);
1523
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1524
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1525
+		);
1526
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1527
+			'M d, Y H:i:s',
1528
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1529
+		);
1530
+	}
1531
+
1532
+
1533
+
1534
+	/**
1535
+	 *    enqueue_styles_and_scripts
1536
+	 *
1537
+	 * @access        public
1538
+	 * @return        void
1539
+	 * @throws EE_Error
1540
+	 */
1541
+	public function enqueue_styles_and_scripts()
1542
+	{
1543
+		// load css
1544
+		wp_register_style(
1545
+			'single_page_checkout',
1546
+			SPCO_CSS_URL . 'single_page_checkout.css',
1547
+			array('espresso_default'),
1548
+			EVENT_ESPRESSO_VERSION
1549
+		);
1550
+		wp_enqueue_style('single_page_checkout');
1551
+		// load JS
1552
+		wp_register_script(
1553
+			'jquery_plugin',
1554
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1555
+			array('jquery'),
1556
+			'1.0.1',
1557
+			true
1558
+		);
1559
+		wp_register_script(
1560
+			'jquery_countdown',
1561
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1562
+			array('jquery_plugin'),
1563
+			'2.0.2',
1564
+			true
1565
+		);
1566
+		wp_register_script(
1567
+			'single_page_checkout',
1568
+			SPCO_JS_URL . 'single_page_checkout.js',
1569
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1570
+			EVENT_ESPRESSO_VERSION,
1571
+			true
1572
+		);
1573
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1574
+			$this->checkout->registration_form->enqueue_js();
1575
+		}
1576
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1577
+			$this->checkout->current_step->reg_form->enqueue_js();
1578
+		}
1579
+		wp_enqueue_script('single_page_checkout');
1580
+		/**
1581
+		 * global action hook for enqueueing styles and scripts with
1582
+		 * spco calls.
1583
+		 */
1584
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1585
+		/**
1586
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1587
+		 * The hook will end up being something like:
1588
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1589
+		 */
1590
+		do_action(
1591
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1592
+			$this
1593
+		);
1594
+	}
1595
+
1596
+
1597
+
1598
+	/**
1599
+	 *    display the Registration Single Page Checkout Form
1600
+	 *
1601
+	 * @access    private
1602
+	 * @return    void
1603
+	 * @throws EE_Error
1604
+	 */
1605
+	private function _display_spco_reg_form()
1606
+	{
1607
+		// if registering via the admin, just display the reg form for the current step
1608
+		if ($this->checkout->admin_request) {
1609
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1610
+		} else {
1611
+			// add powered by EE msg
1612
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1613
+			$empty_cart = count(
1614
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1615
+			) < 1;
1616
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1617
+			$cookies_not_set_msg = '';
1618
+			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1619
+				$cookies_not_set_msg = apply_filters(
1620
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1621
+					sprintf(
1622
+						__(
1623
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1624
+							'event_espresso'
1625
+						),
1626
+						'<div class="ee-attention">',
1627
+						'</div>',
1628
+						'<h6 class="important-notice">',
1629
+						'</h6>',
1630
+						'<p>',
1631
+						'</p>',
1632
+						'<br />',
1633
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1634
+						'</a>'
1635
+					)
1636
+				);
1637
+			}
1638
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1639
+				array(
1640
+					'name'            => 'single-page-checkout',
1641
+					'html_id'         => 'ee-single-page-checkout-dv',
1642
+					'layout_strategy' =>
1643
+						new EE_Template_Layout(
1644
+							array(
1645
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1646
+								'template_args'        => array(
1647
+									'empty_cart'              => $empty_cart,
1648
+									'revisit'                 => $this->checkout->revisit,
1649
+									'reg_steps'               => $this->checkout->reg_steps,
1650
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1651
+										? $this->checkout->next_step->slug()
1652
+										: '',
1653
+									'cancel_page_url'         => $this->checkout->cancel_page_url,
1654
+									'empty_msg'               => apply_filters(
1655
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1656
+										sprintf(
1657
+											__(
1658
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1659
+												'event_espresso'
1660
+											),
1661
+											'<a href="'
1662
+											. get_post_type_archive_link('espresso_events')
1663
+											. '" title="',
1664
+											'">',
1665
+											'</a>'
1666
+										)
1667
+									),
1668
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1669
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1670
+									'session_expiration'      => gmdate(
1671
+										'M d, Y H:i:s',
1672
+										EE_Registry::instance()->SSN->expiration()
1673
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1674
+									),
1675
+								),
1676
+							)
1677
+						),
1678
+				)
1679
+			);
1680
+			// load template and add to output sent that gets filtered into the_content()
1681
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1682
+		}
1683
+	}
1684
+
1685
+
1686
+
1687
+	/**
1688
+	 *    add_extra_finalize_registration_inputs
1689
+	 *
1690
+	 * @access    public
1691
+	 * @param $next_step
1692
+	 * @internal  param string $label
1693
+	 * @return void
1694
+	 */
1695
+	public function add_extra_finalize_registration_inputs($next_step)
1696
+	{
1697
+		if ($next_step === 'finalize_registration') {
1698
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1699
+		}
1700
+	}
1701
+
1702
+
1703
+
1704
+	/**
1705
+	 *    display_registration_footer
1706
+	 *
1707
+	 * @access    public
1708
+	 * @return    string
1709
+	 */
1710
+	public static function display_registration_footer()
1711
+	{
1712
+		if (
1713
+		apply_filters(
1714
+			'FHEE__EE_Front__Controller__show_reg_footer',
1715
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1716
+		)
1717
+		) {
1718
+			add_filter(
1719
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1720
+				function ($url) {
1721
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1722
+				}
1723
+			);
1724
+			echo apply_filters(
1725
+				'FHEE__EE_Front_Controller__display_registration_footer',
1726
+				\EEH_Template::powered_by_event_espresso(
1727
+					'',
1728
+					'espresso-registration-footer-dv',
1729
+					array('utm_content' => 'registration_checkout')
1730
+				)
1731
+			);
1732
+		}
1733
+		return '';
1734
+	}
1735
+
1736
+
1737
+
1738
+	/**
1739
+	 *    unlock_transaction
1740
+	 *
1741
+	 * @access    public
1742
+	 * @return    void
1743
+	 * @throws EE_Error
1744
+	 */
1745
+	public function unlock_transaction()
1746
+	{
1747
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1748
+			$this->checkout->transaction->unlock();
1749
+		}
1750
+	}
1751
+
1752
+
1753
+
1754
+	/**
1755
+	 *        _setup_redirect
1756
+	 *
1757
+	 * @access    private
1758
+	 * @return void
1759
+	 */
1760
+	private function _setup_redirect()
1761
+	{
1762
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1763
+			$this->checkout->redirect = true;
1764
+			if (empty($this->checkout->redirect_url)) {
1765
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1766
+			}
1767
+			$this->checkout->redirect_url = apply_filters(
1768
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1769
+				$this->checkout->redirect_url,
1770
+				$this->checkout
1771
+			);
1772
+		}
1773
+	}
1774
+
1775
+
1776
+
1777
+	/**
1778
+	 *   handle ajax message responses and redirects
1779
+	 *
1780
+	 * @access public
1781
+	 * @return void
1782
+	 * @throws EE_Error
1783
+	 */
1784
+	public function go_to_next_step()
1785
+	{
1786
+		if (EE_Registry::instance()->REQ->ajax) {
1787
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1788
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1789
+		}
1790
+		$this->unlock_transaction();
1791
+		// just return for these conditions
1792
+		if (
1793
+			$this->checkout->admin_request
1794
+			|| $this->checkout->action === 'redirect_form'
1795
+			|| $this->checkout->action === 'update_checkout'
1796
+		) {
1797
+			return;
1798
+		}
1799
+		// AJAX response
1800
+		$this->_handle_json_response();
1801
+		// redirect to next step or the Thank You page
1802
+		$this->_handle_html_redirects();
1803
+		// hmmm... must be something wrong, so let's just display the form again !
1804
+		$this->_display_spco_reg_form();
1805
+	}
1806
+
1807
+
1808
+
1809
+	/**
1810
+	 *   _handle_json_response
1811
+	 *
1812
+	 * @access protected
1813
+	 * @return void
1814
+	 */
1815
+	protected function _handle_json_response()
1816
+	{
1817
+		// if this is an ajax request
1818
+		if (EE_Registry::instance()->REQ->ajax) {
1819
+			// DEBUG LOG
1820
+			//$this->checkout->log(
1821
+			//	__CLASS__, __FUNCTION__, __LINE__,
1822
+			//	array(
1823
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1824
+			//		'redirect'                   => $this->checkout->redirect,
1825
+			//		'continue_reg'               => $this->checkout->continue_reg,
1826
+			//	)
1827
+			//);
1828
+			$this->checkout->json_response->set_registration_time_limit(
1829
+				$this->checkout->get_registration_time_limit()
1830
+			);
1831
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1832
+			// just send the ajax (
1833
+			$json_response = apply_filters(
1834
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1835
+				$this->checkout->json_response
1836
+			);
1837
+			echo $json_response;
1838
+			exit();
1839
+		}
1840
+	}
1841
+
1842
+
1843
+
1844
+	/**
1845
+	 *   _handle_redirects
1846
+	 *
1847
+	 * @access protected
1848
+	 * @return void
1849
+	 */
1850
+	protected function _handle_html_redirects()
1851
+	{
1852
+		// going somewhere ?
1853
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1854
+			// store notices in a transient
1855
+			EE_Error::get_notices(false, true, true);
1856
+			// DEBUG LOG
1857
+			//$this->checkout->log(
1858
+			//	__CLASS__, __FUNCTION__, __LINE__,
1859
+			//	array(
1860
+			//		'headers_sent' => headers_sent(),
1861
+			//		'redirect_url'     => $this->checkout->redirect_url,
1862
+			//		'headers_list'    => headers_list(),
1863
+			//	)
1864
+			//);
1865
+			wp_safe_redirect($this->checkout->redirect_url);
1866
+			exit();
1867
+		}
1868
+	}
1869
+
1870
+
1871
+
1872
+	/**
1873
+	 *   set_checkout_anchor
1874
+	 *
1875
+	 * @access public
1876
+	 * @return void
1877
+	 */
1878
+	public function set_checkout_anchor()
1879
+	{
1880
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1881
+	}
1882 1882
 
1883 1883
 
1884 1884
 
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_Checkout.class.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2 2
  /**
3
- *
4
- * Class EE_Checkout
5
- *
6
- * Description
7
- *
8
- * @package 			Event Espresso
9
- * @subpackage    core
10
- * @author				Brent Christensen
11
- * @since 				4.5.0
12
- *
13
- */
3
+  *
4
+  * Class EE_Checkout
5
+  *
6
+  * Description
7
+  *
8
+  * @package 			Event Espresso
9
+  * @subpackage    core
10
+  * @author				Brent Christensen
11
+  * @since 				4.5.0
12
+  *
13
+  */
14 14
 class EE_Checkout {
15 15
 
16 16
 	/**
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 		$this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE );
251 251
 		$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax;
252 252
 		$this->reg_cache_where_params = array(
253
-		    0 => array( 'REG_deleted' => false ),
254
-		    'order_by' => array( 'REG_count' => 'ASC' )
255
-        );
253
+			0 => array( 'REG_deleted' => false ),
254
+			'order_by' => array( 'REG_count' => 'ASC' )
255
+		);
256 256
 	}
257 257
 
258 258
 
@@ -807,10 +807,10 @@  discard block
 block discarded – undo
807 807
 	 */
808 808
 	public function visit_allows_processing_of_this_registration( EE_Registration $registration ) {
809 809
 		return ! $this->revisit
810
-		       || $this->primary_revisit
811
-		       || (
812
-			       $this->revisit && $this->reg_url_link === $registration->reg_url_link()
813
-		       )
810
+			   || $this->primary_revisit
811
+			   || (
812
+				   $this->revisit && $this->reg_url_link === $registration->reg_url_link()
813
+			   )
814 814
 			? true
815 815
 			: false;
816 816
 	}
@@ -1202,16 +1202,16 @@  discard block
 block discarded – undo
1202 1202
 	 * @return array
1203 1203
 	 * @throws \EE_Error
1204 1204
 	 */
1205
-    public function __sleep()
1206
-    {
1207
-	    if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) {
1208
-		    $this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1209
-	    }        // remove the reg form and the checkout
1210
-	    if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1211
-		    $this->transaction = $this->transaction->ID();
1212
-	    }        // remove the reg form and the checkout
1213
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) );
1214
-    }
1205
+	public function __sleep()
1206
+	{
1207
+		if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) {
1208
+			$this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1209
+		}        // remove the reg form and the checkout
1210
+		if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1211
+			$this->transaction = $this->transaction->ID();
1212
+		}        // remove the reg form and the checkout
1213
+		return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) );
1214
+	}
1215 1215
 
1216 1216
 
1217 1217
 	/**
Please login to merge, or discard this patch.
Spacing   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
 		$this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url();
248 248
 		$this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url();
249 249
 		$this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url();
250
-		$this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE );
250
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', TRUE);
251 251
 		$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax;
252 252
 		$this->reg_cache_where_params = array(
253
-		    0 => array( 'REG_deleted' => false ),
254
-		    'order_by' => array( 'REG_count' => 'ASC' )
253
+		    0 => array('REG_deleted' => false),
254
+		    'order_by' => array('REG_count' => 'ASC')
255 255
         );
256 256
 	}
257 257
 
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	 * @return boolean
264 264
 	 */
265 265
 	public function any_reg_status_updated() {
266
-		foreach ( $this->reg_status_updated as $reg_status ) {
267
-			if ( $reg_status ) {
266
+		foreach ($this->reg_status_updated as $reg_status) {
267
+			if ($reg_status) {
268 268
 				return true;
269 269
 			}
270 270
 		}
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 * @param $REG_ID
278 278
 	 * @return boolean
279 279
 	 */
280
-	public function reg_status_updated( $REG_ID ) {
281
-		return isset( $this->reg_status_updated[ $REG_ID ] ) ? $this->reg_status_updated[ $REG_ID ] : false;
280
+	public function reg_status_updated($REG_ID) {
281
+		return isset($this->reg_status_updated[$REG_ID]) ? $this->reg_status_updated[$REG_ID] : false;
282 282
 	}
283 283
 
284 284
 
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 	 * @param $REG_ID
288 288
 	 * @param $reg_status
289 289
 	 */
290
-	public function set_reg_status_updated( $REG_ID, $reg_status ) {
291
-		$this->reg_status_updated[ $REG_ID ] = filter_var( $reg_status, FILTER_VALIDATE_BOOLEAN );
290
+	public function set_reg_status_updated($REG_ID, $reg_status) {
291
+		$this->reg_status_updated[$REG_ID] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
292 292
 	}
293 293
 
294 294
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * can ONLY be set by the  Finalize_Registration reg step
310 310
 	 */
311 311
 	public function set_exit_spco() {
312
-		if ( $this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) {
312
+		if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
313 313
 			$this->exit_spco = true;
314 314
 		}
315 315
 	}
@@ -326,12 +326,12 @@  discard block
 block discarded – undo
326 326
 	 */
327 327
 	public function reset_for_current_request() {
328 328
 		$this->process_form_submission = FALSE;
329
-		$this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', true );
329
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
330 330
 		$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax;
331 331
 		$this->continue_reg = true;
332 332
 		$this->redirect = false;
333 333
 		// don't reset the cached redirect form if we're about to be asked to display it !!!
334
-		if ( EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ) !== 'redirect_form' ) {
334
+		if (EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step') !== 'redirect_form') {
335 335
 			$this->redirect_form = '';
336 336
 		}
337 337
 		$this->redirect_url = '';
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 	 * @param EE_SPCO_Reg_Step $reg_step_obj
349 349
 	 * @return    void
350 350
 	 */
351
-	public function add_reg_step( EE_SPCO_Reg_Step $reg_step_obj ) {
352
-		$this->reg_steps[ $reg_step_obj->slug()  ] = $reg_step_obj;
351
+	public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) {
352
+		$this->reg_steps[$reg_step_obj->slug()] = $reg_step_obj;
353 353
 	}
354 354
 
355 355
 
@@ -365,22 +365,22 @@  discard block
 block discarded – undo
365 365
 	 * @return    void
366 366
 	 * @throws \EE_Error
367 367
 	 */
368
-	public function skip_reg_step( $reg_step_slug = '' ) {
369
-		$step_to_skip = $this->find_reg_step( $reg_step_slug );
370
-		if ( $step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step() ) {
371
-			$step_to_skip->set_is_current_step( false );
368
+	public function skip_reg_step($reg_step_slug = '') {
369
+		$step_to_skip = $this->find_reg_step($reg_step_slug);
370
+		if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) {
371
+			$step_to_skip->set_is_current_step(false);
372 372
 			$step_to_skip->set_completed();
373 373
 			// advance to the next step
374
-			$this->set_current_step( $this->next_step->slug() );
374
+			$this->set_current_step($this->next_step->slug());
375 375
 			// also reset the step param in the request in case any other code references that directly
376
-			EE_Registry::instance()->REQ->set( 'step', $this->current_step->slug() );
376
+			EE_Registry::instance()->REQ->set('step', $this->current_step->slug());
377 377
 			// since we are skipping a step and setting the current step to be what was previously the next step,
378 378
 			// we need to check that the next step is now correct, and not still set to the current step.
379
-			if ( $this->current_step->slug() === $this->next_step->slug() ) {
379
+			if ($this->current_step->slug() === $this->next_step->slug()) {
380 380
 				// correctly setup the next step
381 381
 				$this->set_next_step();
382 382
 			}
383
-			$this->set_reg_step_initiated( $this->current_step );
383
+			$this->set_reg_step_initiated($this->current_step);
384 384
 		}
385 385
 	}
386 386
 
@@ -394,14 +394,14 @@  discard block
 block discarded – undo
394 394
 	 * @param bool   $reset whether to reset reg steps after removal
395 395
 	 * @throws EE_Error
396 396
 	 */
397
-	public function remove_reg_step( $reg_step_slug = '', $reset = true ) {
398
-		unset( $this->reg_steps[ $reg_step_slug  ] );
399
-		if ( $this->transaction instanceof EE_Transaction ) {
397
+	public function remove_reg_step($reg_step_slug = '', $reset = true) {
398
+		unset($this->reg_steps[$reg_step_slug]);
399
+		if ($this->transaction instanceof EE_Transaction) {
400 400
 			// now remove reg step from TXN and save
401
-			$this->transaction->remove_reg_step( $reg_step_slug );
401
+			$this->transaction->remove_reg_step($reg_step_slug);
402 402
 			$this->transaction->save();
403 403
 		}
404
-		if ( $reset ) {
404
+		if ($reset) {
405 405
 			$this->reset_reg_steps();
406 406
 		}
407 407
 	}
@@ -416,9 +416,9 @@  discard block
 block discarded – undo
416 416
 	 * @param int    $order
417 417
 	 * @return    void
418 418
 	 */
419
-	public function set_reg_step_order( $reg_step_slug = '', $order = 100 ) {
420
-		if ( isset( $this->reg_steps[ $reg_step_slug  ] )) {
421
-			$this->reg_steps[ $reg_step_slug ]->set_order( $order );
419
+	public function set_reg_step_order($reg_step_slug = '', $order = 100) {
420
+		if (isset($this->reg_steps[$reg_step_slug])) {
421
+			$this->reg_steps[$reg_step_slug]->set_order($order);
422 422
 		}
423 423
 	}
424 424
 
@@ -431,25 +431,25 @@  discard block
 block discarded – undo
431 431
 	 * @param string $current_step
432 432
 	 * @return    void
433 433
 	 */
434
-	public function set_current_step( $current_step ) {
434
+	public function set_current_step($current_step) {
435 435
 		// grab what step we're on
436
-		$this->current_step = isset( $this->reg_steps[ $current_step ] ) ? $this->reg_steps[ $current_step ] : reset( $this->reg_steps );
436
+		$this->current_step = isset($this->reg_steps[$current_step]) ? $this->reg_steps[$current_step] : reset($this->reg_steps);
437 437
 		// verify instance
438
-		if ( $this->current_step instanceof EE_SPCO_Reg_Step ) {
438
+		if ($this->current_step instanceof EE_SPCO_Reg_Step) {
439 439
 			// we don't want to repeat completed steps if this is the first time through SPCO
440
-			if ( $this->continue_reg && ! $this->revisit && $this->current_step->completed() ) {
440
+			if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) {
441 441
 				// so advance to the next step
442 442
 				$this->set_next_step();
443
-				if ( $this->next_step instanceof EE_SPCO_Reg_Step ) {
443
+				if ($this->next_step instanceof EE_SPCO_Reg_Step) {
444 444
 					// and attempt to set it as the current step
445
-					$this->set_current_step( $this->next_step->slug() );
445
+					$this->set_current_step($this->next_step->slug());
446 446
 				}
447 447
 				return;
448 448
 			}
449
-			$this->current_step->set_is_current_step( TRUE );
449
+			$this->current_step->set_is_current_step(TRUE);
450 450
 		} else {
451 451
 			EE_Error::add_error(
452
-				__( 'The current step could not be set.', 'event_espresso' ),
452
+				__('The current step could not be set.', 'event_espresso'),
453 453
 				__FILE__, __FUNCTION__, __LINE__
454 454
 			);
455 455
 		}
@@ -466,20 +466,20 @@  discard block
 block discarded – undo
466 466
 	 */
467 467
 	public function set_next_step() {
468 468
 		// set pointer to start of array
469
-		reset( $this->reg_steps );
469
+		reset($this->reg_steps);
470 470
 		// if there is more than one step
471
-		if ( count( $this->reg_steps ) > 1 ) {
471
+		if (count($this->reg_steps) > 1) {
472 472
 			// advance to the current step and set pointer
473
-			while ( key( $this->reg_steps ) !== $this->current_step->slug() && key( $this->reg_steps ) !== '' ) {
474
-				next( $this->reg_steps );
473
+			while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') {
474
+				next($this->reg_steps);
475 475
 			}
476 476
 		}
477 477
 		// advance one more spot ( if it exists )
478
-		$this->next_step = next( $this->reg_steps );
478
+		$this->next_step = next($this->reg_steps);
479 479
 		// verify instance
480
-		$this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step  : NULL;
480
+		$this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL;
481 481
 		// then back to current step to reset
482
-		prev( $this->reg_steps );
482
+		prev($this->reg_steps);
483 483
 	}
484 484
 
485 485
 
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 *  @return 	EE_SPCO_Reg_Step | null
494 494
 	 */
495 495
 	public function get_next_reg_step() {
496
-		$next = next( $this->reg_steps );
497
-		prev( $this->reg_steps );
496
+		$next = next($this->reg_steps);
497
+		prev($this->reg_steps);
498 498
 		return $next instanceof EE_SPCO_Reg_Step ? $next : null;
499 499
 	}
500 500
 
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
 	 *  @return 	EE_SPCO_Reg_Step | null
510 510
 	 */
511 511
 	public function get_prev_reg_step() {
512
-		$prev = prev( $this->reg_steps );
513
-		next( $this->reg_steps );
512
+		$prev = prev($this->reg_steps);
513
+		next($this->reg_steps);
514 514
 		return $prev instanceof EE_SPCO_Reg_Step ? $prev : null;
515 515
 	}
516 516
 
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
 	 * @return void
524 524
 	 */
525 525
 	public function sort_reg_steps() {
526
-		$reg_step_sorting_callback = apply_filters( 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback' );
527
-		uasort( $this->reg_steps, array( $this, $reg_step_sorting_callback ));
526
+		$reg_step_sorting_callback = apply_filters('FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback');
527
+		uasort($this->reg_steps, array($this, $reg_step_sorting_callback));
528 528
 	}
529 529
 
530 530
 
@@ -537,19 +537,19 @@  discard block
 block discarded – undo
537 537
 	 * @param string $reg_step_slug
538 538
 	 * @return EE_SPCO_Reg_Step|null
539 539
 	 */
540
-	public function find_reg_step( $reg_step_slug = '' ) {
541
-		if ( ! empty( $reg_step_slug ) ) {
540
+	public function find_reg_step($reg_step_slug = '') {
541
+		if ( ! empty($reg_step_slug)) {
542 542
 			// copy reg step array
543 543
 			$reg_steps = $this->reg_steps;
544 544
 			// set pointer to start of array
545
-			reset( $reg_steps );
545
+			reset($reg_steps);
546 546
 			// if there is more than one step
547
-			if ( count( $reg_steps ) > 1 ) {
547
+			if (count($reg_steps) > 1) {
548 548
 				// advance to the current step and set pointer
549
-				while ( key( $reg_steps ) !== $reg_step_slug && key( $reg_steps ) !== '' ) {
550
-					next( $reg_steps );
549
+				while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') {
550
+					next($reg_steps);
551 551
 				}
552
-				return current( $reg_steps );
552
+				return current($reg_steps);
553 553
 			}
554 554
 		}
555 555
 		return null;
@@ -565,17 +565,17 @@  discard block
 block discarded – undo
565 565
 	 * @param EE_SPCO_Reg_Step $reg_step_B
566 566
 	 * @return int
567 567
 	 */
568
-	public function reg_step_sorting_callback( EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B ) {
568
+	public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B) {
569 569
 		// send finalize_registration step to the end of the array
570
-		if ( $reg_step_A->slug() === 'finalize_registration' ) {
570
+		if ($reg_step_A->slug() === 'finalize_registration') {
571 571
 			return 1;
572
-		} else if ( $reg_step_B->slug() === 'finalize_registration' ) {
572
+		} else if ($reg_step_B->slug() === 'finalize_registration') {
573 573
 			return -1;
574 574
 		}
575
-		if ( $reg_step_A->order() === $reg_step_B->order() ) {
575
+		if ($reg_step_A->order() === $reg_step_B->order()) {
576 576
 			return 0;
577 577
 		}
578
-		return ( $reg_step_A->order() > $reg_step_B->order() ) ? 1 : -1;
578
+		return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1;
579 579
 	}
580 580
 
581 581
 
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 	 * @param    EE_SPCO_Reg_Step $reg_step
588 588
 	 * @throws \EE_Error
589 589
 	 */
590
-	public function set_reg_step_initiated( EE_SPCO_Reg_Step $reg_step ) {
590
+	public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step) {
591 591
 		// call set_reg_step_initiated ???
592 592
 		if (
593 593
 			// first time visiting SPCO ?
@@ -600,11 +600,11 @@  discard block
 block discarded – undo
600 600
 			)
601 601
 		) {
602 602
 			// set the start time for this reg step
603
-			if ( ! $this->transaction->set_reg_step_initiated( $reg_step->slug() ) ) {
604
-				if ( WP_DEBUG ) {
603
+			if ( ! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
604
+				if (WP_DEBUG) {
605 605
 					EE_Error::add_error(
606 606
 						sprintf(
607
-							__( 'The "%1$s" registration step was not initialized properly.', 'event_espresso' ),
607
+							__('The "%1$s" registration step was not initialized properly.', 'event_espresso'),
608 608
 							$reg_step->name()
609 609
 						),
610 610
 						__FILE__, __FUNCTION__, __LINE__
@@ -623,10 +623,10 @@  discard block
 block discarded – undo
623 623
 	 * 	@return 	void
624 624
 	 */
625 625
 	public function set_reg_step_JSON_info() {
626
-		EE_Registry::$i18n_js_strings[ 'reg_steps' ] = array();
626
+		EE_Registry::$i18n_js_strings['reg_steps'] = array();
627 627
 		// pass basic reg step data to JS
628
-		foreach ( $this->reg_steps as $reg_step ) {
629
-			EE_Registry::$i18n_js_strings[ 'reg_steps' ][] = $reg_step->slug();
628
+		foreach ($this->reg_steps as $reg_step) {
629
+			EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug();
630 630
 		}
631 631
 		// reset reg step html
632 632
 //		$this->json_response->set_reg_step_html( '' );
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 	 */
643 643
 	public function reset_reg_steps() {
644 644
 		$this->sort_reg_steps();
645
-		$this->set_current_step( EE_Registry::instance()->REQ->get( 'step' ));
645
+		$this->set_current_step(EE_Registry::instance()->REQ->get('step'));
646 646
 		$this->set_next_step();
647 647
 		// the text that appears on the reg step form submit button
648 648
 		$this->current_step->set_submit_button_text();
@@ -659,9 +659,9 @@  discard block
 block discarded – undo
659 659
 	 */
660 660
 	public function get_registration_time_limit() {
661 661
 
662
-		$registration_time_limit = (float)( EE_Registry::instance()	->SSN->expiration() - time() );
662
+		$registration_time_limit = (float) (EE_Registry::instance()	->SSN->expiration() - time());
663 663
 		$time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s';
664
-		$registration_time_limit = date( $time_limit_format, $registration_time_limit );
664
+		$registration_time_limit = date($time_limit_format, $registration_time_limit);
665 665
 		return apply_filters(
666 666
 			'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit',
667 667
 			$registration_time_limit
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 		//		overpaid TXN
682 682
 		//		free TXN ( total = 0.00 )
683 683
 		// then payment required is TRUE
684
-		return ! ( $this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free() ) ? TRUE : FALSE;
684
+		return ! ($this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free()) ? TRUE : FALSE;
685 685
 	}
686 686
 
687 687
 
@@ -693,12 +693,12 @@  discard block
 block discarded – undo
693 693
 	 * @param EE_Transaction $transaction
694 694
 	 * @return EE_Cart
695 695
 	 */
696
-	public function get_cart_for_transaction( $transaction ) {
697
-		$session = EE_Registry::instance()->load_core( 'Session' );
698
-		$cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn( $transaction, $session ) : null;
696
+	public function get_cart_for_transaction($transaction) {
697
+		$session = EE_Registry::instance()->load_core('Session');
698
+		$cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null;
699 699
 		// verify cart
700
-		if ( ! $cart instanceof EE_Cart ) {
701
-			$cart = EE_Registry::instance()->load_core( 'Cart' );
700
+		if ( ! $cart instanceof EE_Cart) {
701
+			$cart = EE_Registry::instance()->load_core('Cart');
702 702
 		}
703 703
 
704 704
 		return $cart;
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
 	 */
715 715
 	public function initialize_txn_reg_steps_array() {
716 716
 		$txn_reg_steps_array = array();
717
-		foreach ( $this->reg_steps as $reg_step ) {
718
-			$txn_reg_steps_array[ $reg_step->slug() ] = FALSE;
717
+		foreach ($this->reg_steps as $reg_step) {
718
+			$txn_reg_steps_array[$reg_step->slug()] = FALSE;
719 719
 		}
720 720
 		return $txn_reg_steps_array;
721 721
 	}
@@ -731,14 +731,14 @@  discard block
 block discarded – undo
731 731
 	 */
732 732
 	public function update_txn_reg_steps_array() {
733 733
 		$updated = false;
734
-		foreach ( $this->reg_steps as $reg_step ) {
735
-			if ( $reg_step->completed() ) {
736
-				$updated = $this->transaction->set_reg_step_completed( $reg_step->slug() )
734
+		foreach ($this->reg_steps as $reg_step) {
735
+			if ($reg_step->completed()) {
736
+				$updated = $this->transaction->set_reg_step_completed($reg_step->slug())
737 737
 					? true
738 738
 					: $updated;
739 739
 			}
740 740
 		}
741
-		if ( $updated ) {
741
+		if ($updated) {
742 742
 			$this->transaction->save();
743 743
 		}
744 744
 		return $updated;
@@ -754,14 +754,14 @@  discard block
 block discarded – undo
754 754
 	 * @throws \EE_Error
755 755
 	 */
756 756
 	public function stash_transaction_and_checkout() {
757
-		if ( ! $this->revisit ) {
757
+		if ( ! $this->revisit) {
758 758
 			$this->update_txn_reg_steps_array();
759 759
 		}
760 760
 		$this->track_transaction_and_registration_status_updates();
761 761
 		// save all data to the db, but suppress errors
762 762
 		//$this->save_all_data( FALSE );
763 763
 		// cache the checkout in the session
764
-		EE_Registry::instance()->SSN->set_checkout( $this );
764
+		EE_Registry::instance()->SSN->set_checkout($this);
765 765
 	}
766 766
 
767 767
 
@@ -776,15 +776,15 @@  discard block
 block discarded – undo
776 776
 	 */
777 777
 	public function track_transaction_and_registration_status_updates() {
778 778
 		// verify the transaction
779
-		if ( $this->transaction instanceof EE_Transaction ) {
779
+		if ($this->transaction instanceof EE_Transaction) {
780 780
 			// has there been a TXN status change during this checkout?
781 781
 			$this->txn_status_updated = $this->transaction->txn_status_updated();
782 782
 			/** @type EE_Registration_Processor $registration_processor */
783
-			$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
783
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
784 784
 			// grab the saved registrations from the transaction
785
-			foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) {
786
-				if ( $registration_processor->reg_status_updated( $registration->ID() ) ) {
787
-					$this->set_reg_status_updated( $registration->ID(), true );
785
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
786
+				if ($registration_processor->reg_status_updated($registration->ID())) {
787
+					$this->set_reg_status_updated($registration->ID(), true);
788 788
 				}
789 789
 			}
790 790
 		}
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 	 * @return    bool
806 806
 	 * @throws \EE_Error
807 807
 	 */
808
-	public function visit_allows_processing_of_this_registration( EE_Registration $registration ) {
808
+	public function visit_allows_processing_of_this_registration(EE_Registration $registration) {
809 809
 		return ! $this->revisit
810 810
 		       || $this->primary_revisit
811 811
 		       || (
@@ -838,18 +838,18 @@  discard block
 block discarded – undo
838 838
 	 * @return bool
839 839
 	 * @throws \EE_Error
840 840
 	 */
841
-	public function save_all_data( $show_errors = TRUE ) {
841
+	public function save_all_data($show_errors = TRUE) {
842 842
 		// verify the transaction
843
-		if ( $this->transaction instanceof EE_Transaction ) {
843
+		if ($this->transaction instanceof EE_Transaction) {
844 844
 			// save to ensure that TXN has ID
845 845
 			$this->transaction->save();
846 846
 			// grab the saved registrations from the transaction
847
-			foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as  $registration ) {
848
-				$this->_save_registration( $registration, $show_errors );
847
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as  $registration) {
848
+				$this->_save_registration($registration, $show_errors);
849 849
 			}
850 850
 		} else {
851
-			if ( $show_errors ) {
852
-				EE_Error::add_error( __( 'A valid Transaction was not found when attempting to save your registration information.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
851
+			if ($show_errors) {
852
+				EE_Error::add_error(__('A valid Transaction was not found when attempting to save your registration information.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
853 853
 			}
854 854
 			return FALSE;
855 855
 		}
@@ -866,32 +866,32 @@  discard block
 block discarded – undo
866 866
 	 * @return void
867 867
 	 * @throws \EE_Error
868 868
 	 */
869
-	private function _save_registration( $registration, $show_errors = TRUE  ) {
869
+	private function _save_registration($registration, $show_errors = TRUE) {
870 870
 		// verify object
871
-		if ( $registration instanceof EE_Registration ) {
871
+		if ($registration instanceof EE_Registration) {
872 872
 			// should this registration be processed during this visit ?
873
-			if ( $this->visit_allows_processing_of_this_registration( $registration ) ) {
873
+			if ($this->visit_allows_processing_of_this_registration($registration)) {
874 874
 				//set TXN ID
875
-				if ( ! $registration->transaction_ID() ) {
876
-					$registration->set_transaction_id( $this->transaction->ID() );
875
+				if ( ! $registration->transaction_ID()) {
876
+					$registration->set_transaction_id($this->transaction->ID());
877 877
 				}
878 878
 				// verify and save the attendee
879
-				$this->_save_registration_attendee( $registration, $show_errors );
879
+				$this->_save_registration_attendee($registration, $show_errors);
880 880
 				// save answers to reg form questions
881
-				$this->_save_registration_answers( $registration, $show_errors );
881
+				$this->_save_registration_answers($registration, $show_errors);
882 882
 				// save changes
883 883
 				$registration->save();
884 884
 				// update txn cache
885
-				if ( ! $this->transaction->update_cache_after_object_save( 'Registration', $registration )) {
886
-					if ( $show_errors ) {
887
-						EE_Error::add_error( __( 'The newly saved Registration object could not be cached on the Transaction.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
885
+				if ( ! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
886
+					if ($show_errors) {
887
+						EE_Error::add_error(__('The newly saved Registration object could not be cached on the Transaction.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
888 888
 					}
889 889
 				}
890 890
 			}
891 891
 		} else {
892
-			if ( $show_errors ) {
892
+			if ($show_errors) {
893 893
 				EE_Error::add_error(
894
-					__( 'An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso' ),
894
+					__('An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso'),
895 895
 					__FILE__, __FUNCTION__, __LINE__
896 896
 				);
897 897
 			}
@@ -908,25 +908,25 @@  discard block
 block discarded – undo
908 908
 	 * @return void
909 909
 	 * @throws \EE_Error
910 910
 	 */
911
-	private function _save_registration_attendee( $registration, $show_errors = TRUE ) {
912
-		if ( $registration->attendee() instanceof EE_Attendee ) {
911
+	private function _save_registration_attendee($registration, $show_errors = TRUE) {
912
+		if ($registration->attendee() instanceof EE_Attendee) {
913 913
 			// save so that ATT has ID
914 914
 			$registration->attendee()->save();
915
-			if ( ! $registration->update_cache_after_object_save( 'Attendee', $registration->attendee() ) ) {
916
-				if ( $show_errors ) {
915
+			if ( ! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
916
+				if ($show_errors) {
917 917
 					EE_Error::add_error(
918
-						__( 'The newly saved Attendee object could not be cached on the registration.', 'event_espresso' ),
918
+						__('The newly saved Attendee object could not be cached on the registration.', 'event_espresso'),
919 919
 						__FILE__, __FUNCTION__, __LINE__
920 920
 					);
921 921
 				}
922 922
 			}
923 923
 		} else {
924
-			if ( $show_errors ) {
924
+			if ($show_errors) {
925 925
 				EE_Error::add_error(
926 926
 					sprintf(
927 927
 						'%1$s||%1$s $attendee = %2$s',
928
-						__( 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso' ),
929
-						var_export( $registration->attendee(), true )
928
+						__('Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso'),
929
+						var_export($registration->attendee(), true)
930 930
 					),
931 931
 					__FILE__, __FUNCTION__, __LINE__
932 932
 				);
@@ -944,25 +944,25 @@  discard block
 block discarded – undo
944 944
 	 * @return void
945 945
 	 * @throws \EE_Error
946 946
 	 */
947
-	private function _save_registration_answers( $registration, $show_errors = TRUE ) {
947
+	private function _save_registration_answers($registration, $show_errors = TRUE) {
948 948
 		// now save the answers
949
-		foreach ( $registration->answers() as $cache_key => $answer ) {
949
+		foreach ($registration->answers() as $cache_key => $answer) {
950 950
 			// verify object
951
-			if ( $answer instanceof EE_Answer ) {
952
-				$answer->set_registration( $registration->ID() );
951
+			if ($answer instanceof EE_Answer) {
952
+				$answer->set_registration($registration->ID());
953 953
 				$answer->save();
954
-				if ( ! $registration->update_cache_after_object_save( 'Answer', $answer, $cache_key )) {
955
-					if ( $show_errors ) {
954
+				if ( ! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
955
+					if ($show_errors) {
956 956
 						EE_Error::add_error(
957
-							__( 'The newly saved Answer object could not be cached on the registration.', 'event_espresso' ),
957
+							__('The newly saved Answer object could not be cached on the registration.', 'event_espresso'),
958 958
 							__FILE__, __FUNCTION__, __LINE__
959 959
 						);
960 960
 					}
961 961
 				}
962 962
 			} else {
963
-				if ( $show_errors ) {
963
+				if ($show_errors) {
964 964
 					EE_Error::add_error(
965
-						__( 'An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso' ),
965
+						__('An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso'),
966 966
 						__FILE__, __FUNCTION__, __LINE__
967 967
 					);
968 968
 				}
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
 	 * @return bool
982 982
 	 * @throws \EE_Error
983 983
 	 */
984
-	public function refresh_all_entities( $from_db = false ) {
984
+	public function refresh_all_entities($from_db = false) {
985 985
 		$from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response'
986 986
 			? true
987 987
 			: $from_db;
@@ -1005,11 +1005,11 @@  discard block
 block discarded – undo
1005 1005
 	 */
1006 1006
 	protected function refresh_from_db() {
1007 1007
 		// verify the transaction
1008
-		if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1008
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1009 1009
 			// pull fresh TXN data from the db
1010
-			$this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db( $this->transaction->ID() );
1010
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID());
1011 1011
 			// update EE_Checkout's cached primary_attendee object
1012
-			$this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db( $this->transaction );
1012
+			$this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction);
1013 1013
 			// update EE_Checkout's cached payment object
1014 1014
 			$payment = $this->transaction->last_payment();
1015 1015
 			$this->payment = $payment instanceof EE_Payment ? $payment : $this->payment;
@@ -1017,9 +1017,9 @@  discard block
 block discarded – undo
1017 1017
 			$payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null;
1018 1018
 			$this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method : $this->payment_method;
1019 1019
 			//now refresh the cart, based on the TXN
1020
-			$this->cart = $this->get_cart_for_transaction( $this->transaction );
1020
+			$this->cart = $this->get_cart_for_transaction($this->transaction);
1021 1021
 		} else {
1022
-			EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
1022
+			EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1023 1023
 			return FALSE;
1024 1024
 		}
1025 1025
 		return TRUE;
@@ -1034,21 +1034,21 @@  discard block
 block discarded – undo
1034 1034
 	 * @return  EE_Attendee | null
1035 1035
 	 * @throws \EE_Error
1036 1036
 	 */
1037
-	protected function _refresh_primary_attendee_obj_from_db( EE_Transaction $transaction ) {
1037
+	protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction) {
1038 1038
 
1039 1039
 		$primary_attendee_obj = null;
1040 1040
 		// grab the saved registrations from the transaction
1041
-		foreach ( $transaction->registrations( $this->reg_cache_where_params, true ) as $registration ) {
1041
+		foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) {
1042 1042
 			// verify object
1043
-			if ( $registration instanceof EE_Registration ) {
1043
+			if ($registration instanceof EE_Registration) {
1044 1044
 				$attendee = $registration->attendee();
1045 1045
 				// verify object && maybe cache primary_attendee_obj ?
1046
-				if ( $attendee instanceof EE_Attendee&& $registration->is_primary_registrant() ) {
1046
+				if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) {
1047 1047
 					$primary_attendee_obj = $attendee;
1048 1048
 				}
1049 1049
 			} else {
1050 1050
 				EE_Error::add_error(
1051
-						__( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ),
1051
+						__('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'),
1052 1052
 						__FILE__, __FUNCTION__, __LINE__
1053 1053
 				);
1054 1054
 			}
@@ -1069,43 +1069,43 @@  discard block
 block discarded – undo
1069 1069
 	 */
1070 1070
 	protected function refresh_entity_map() {
1071 1071
 		// verify the transaction
1072
-		if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1072
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1073 1073
 			// never cache payment info
1074
-			$this->transaction->clear_cache( 'Payment' );
1074
+			$this->transaction->clear_cache('Payment');
1075 1075
 			// is the Payment Options Reg Step completed ?
1076
-			if ( $this->transaction->reg_step_completed( 'payment_options' ) ) {
1076
+			if ($this->transaction->reg_step_completed('payment_options')) {
1077 1077
 				// then check for payments and update TXN accordingly
1078 1078
 				/** @type EE_Transaction_Payments $transaction_payments */
1079
-				$transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' );
1080
-				$transaction_payments->calculate_total_payments_and_update_status( $this->transaction );
1079
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1080
+				$transaction_payments->calculate_total_payments_and_update_status($this->transaction);
1081 1081
 			}
1082 1082
 			// grab the saved registrations from the transaction
1083 1083
 			foreach (
1084
-				$this->transaction->registrations( $this->reg_cache_where_params ) as $reg_cache_ID => $registration
1084
+				$this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration
1085 1085
 			) {
1086
-				$this->_refresh_registration( $reg_cache_ID, $registration );
1086
+				$this->_refresh_registration($reg_cache_ID, $registration);
1087 1087
 			}
1088 1088
 			// make sure our cached TXN is added to the model entity mapper
1089
-			$this->transaction = $this->transaction->get_model()->refresh_entity_map_with( $this->transaction->ID(), $this->transaction );
1089
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_with($this->transaction->ID(), $this->transaction);
1090 1090
 
1091 1091
 		} else {
1092
-			EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
1092
+			EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1093 1093
 			return FALSE;
1094 1094
 		}
1095 1095
 		// verify and update the cart because inaccurate totals are not so much fun
1096
-		if ( $this->cart instanceof EE_Cart ) {
1096
+		if ($this->cart instanceof EE_Cart) {
1097 1097
 			$grand_total = $this->cart->get_grand_total();
1098
-			if ( $grand_total instanceof EE_Line_Item && $grand_total->ID() ) {
1098
+			if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) {
1099 1099
 				$grand_total->recalculate_total_including_taxes();
1100 1100
 				$grand_total = $grand_total->get_model()->refresh_entity_map_with(
1101 1101
 					$this->cart->get_grand_total()->ID(),
1102 1102
 					$this->cart->get_grand_total()
1103 1103
 				);
1104 1104
 			}
1105
-			if ( $grand_total instanceof EE_Line_Item ) {
1106
-				$this->cart = EE_Cart::instance( $grand_total );
1105
+			if ($grand_total instanceof EE_Line_Item) {
1106
+				$this->cart = EE_Cart::instance($grand_total);
1107 1107
 			} else {
1108
-				EE_Error::add_error( __( 'A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1108
+				EE_Error::add_error(__('A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1109 1109
 				return false;
1110 1110
 			}
1111 1111
 		}
@@ -1122,19 +1122,19 @@  discard block
 block discarded – undo
1122 1122
 	 * @return void
1123 1123
 	 * @throws \EE_Error
1124 1124
 	 */
1125
-	protected function _refresh_registration( $reg_cache_ID, $registration ) {
1125
+	protected function _refresh_registration($reg_cache_ID, $registration) {
1126 1126
 
1127 1127
 		// verify object
1128
-		if ( $registration instanceof EE_Registration ) {
1128
+		if ($registration instanceof EE_Registration) {
1129 1129
 			// update the entity mapper attendee
1130
-			$this->_refresh_registration_attendee( $registration );
1130
+			$this->_refresh_registration_attendee($registration);
1131 1131
 			// update the entity mapper answers for reg form questions
1132
-			$this->_refresh_registration_answers( $registration );
1132
+			$this->_refresh_registration_answers($registration);
1133 1133
 			// make sure the cached registration is added to the model entity mapper
1134
-			$registration->get_model()->refresh_entity_map_with( $reg_cache_ID, $registration );
1134
+			$registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration);
1135 1135
 		} else {
1136 1136
 			EE_Error::add_error(
1137
-				__( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ),
1137
+				__('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'),
1138 1138
 				__FILE__, __FUNCTION__, __LINE__
1139 1139
 			);
1140 1140
 		}
@@ -1149,15 +1149,15 @@  discard block
 block discarded – undo
1149 1149
 	 * @return void
1150 1150
 	 * @throws \EE_Error
1151 1151
 	 */
1152
-	protected function _refresh_registration_attendee( $registration ) {
1152
+	protected function _refresh_registration_attendee($registration) {
1153 1153
 
1154 1154
 		$attendee = $registration->attendee();
1155 1155
 		// verify object
1156
-		if ( $attendee instanceof EE_Attendee && $attendee->ID() ) {
1156
+		if ($attendee instanceof EE_Attendee && $attendee->ID()) {
1157 1157
 			// make sure the cached attendee is added to the model entity mapper
1158
-			$registration->attendee()->get_model()->refresh_entity_map_with( $attendee->ID(), $attendee );
1158
+			$registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee);
1159 1159
 			// maybe cache primary_attendee_obj ?
1160
-			if ( $registration->is_primary_registrant() ) {
1160
+			if ($registration->is_primary_registrant()) {
1161 1161
 				$this->primary_attendee_obj = $attendee;
1162 1162
 			}
1163 1163
 		}
@@ -1172,19 +1172,19 @@  discard block
 block discarded – undo
1172 1172
 	 * @return void
1173 1173
 	 * @throws \EE_Error
1174 1174
 	 */
1175
-	protected function _refresh_registration_answers( $registration ) {
1175
+	protected function _refresh_registration_answers($registration) {
1176 1176
 
1177 1177
 		// now update the answers
1178
-		foreach ( $registration->answers() as $cache_key => $answer ) {
1178
+		foreach ($registration->answers() as $cache_key => $answer) {
1179 1179
 			// verify object
1180
-			if ( $answer instanceof EE_Answer ) {
1181
-				if ( $answer->ID() ) {
1180
+			if ($answer instanceof EE_Answer) {
1181
+				if ($answer->ID()) {
1182 1182
 					// make sure the cached answer is added to the model entity mapper
1183
-					$answer->get_model()->refresh_entity_map_with( $answer->ID(), $answer );
1183
+					$answer->get_model()->refresh_entity_map_with($answer->ID(), $answer);
1184 1184
 				}
1185 1185
 			} else {
1186 1186
 				EE_Error::add_error(
1187
-					__( 'An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso' ),
1187
+					__('An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso'),
1188 1188
 					__FILE__, __FUNCTION__, __LINE__
1189 1189
 				);
1190 1190
 			}
@@ -1204,13 +1204,13 @@  discard block
 block discarded – undo
1204 1204
 	 */
1205 1205
     public function __sleep()
1206 1206
     {
1207
-	    if ( $this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID() ) {
1207
+	    if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) {
1208 1208
 		    $this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1209 1209
 	    }        // remove the reg form and the checkout
1210
-	    if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) {
1210
+	    if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1211 1211
 		    $this->transaction = $this->transaction->ID();
1212 1212
 	    }        // remove the reg form and the checkout
1213
-        return array_diff( array_keys( get_object_vars( $this ) ), array( 'billing_form', 'registration_form' ) );
1213
+        return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form'));
1214 1214
     }
1215 1215
 
1216 1216
 
@@ -1220,15 +1220,15 @@  discard block
 block discarded – undo
1220 1220
 	 * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object
1221 1221
 	 */
1222 1222
 	public function __wakeup() {
1223
-		if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint( $this->primary_attendee_obj ) !== 0 ) {
1223
+		if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1224 1224
 			// $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db
1225
-			$this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID( $this->primary_attendee_obj );
1225
+			$this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj);
1226 1226
 		}
1227
-		if ( ! $this->transaction instanceof EE_Transaction && absint( $this->transaction ) !== 0 ) {
1227
+		if ( ! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1228 1228
 			// $this->transaction is actually just an ID, so use it to get the object from the db
1229
-			$this->transaction = EEM_Transaction::instance()->get_one_by_ID( $this->transaction );
1229
+			$this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction);
1230 1230
 		}
1231
-		foreach ( $this->reg_steps as $reg_step ) {
1231
+		foreach ($this->reg_steps as $reg_step) {
1232 1232
 			$reg_step->checkout = $this;
1233 1233
 		}
1234 1234
 	}
@@ -1245,12 +1245,12 @@  discard block
 block discarded – undo
1245 1245
 	 * @param bool   $display_request
1246 1246
 	 * @throws \EE_Error
1247 1247
 	 */
1248
-	public function log( $class = '', $func = '', $line = '', $info = array(), $display_request = false ) {
1248
+	public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false) {
1249 1249
 		$disabled = true;
1250
-		if ( WP_DEBUG && ! $disabled ) {
1251
-			$debug_data = get_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array() );
1250
+		if (WP_DEBUG && ! $disabled) {
1251
+			$debug_data = get_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), array());
1252 1252
 			$default_data = array(
1253
-				$class 		=> $func . '() : ' . $line,
1253
+				$class 		=> $func.'() : '.$line,
1254 1254
 				'request->step' 		=> $this->step,
1255 1255
 				'request->action' 	=> $this->action,
1256 1256
 				'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ?
@@ -1262,24 +1262,24 @@  discard block
 block discarded – undo
1262 1262
 				'reg_url_link' => $this->reg_url_link,
1263 1263
 				'REQ' => $display_request ? $_REQUEST : '',
1264 1264
 			);
1265
-			if ( $this->transaction instanceof EE_Transaction ) {
1266
-				$default_data[ 'TXN_status' ] 		= $this->transaction->status_ID();
1267
-				$default_data[ 'TXN_reg_steps' ] 	= $this->transaction->reg_steps();
1268
-				foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $REG_ID => $registration ) {
1269
-					$default_data[ 'registrations' ][ $REG_ID ] = $registration->status_ID();
1265
+			if ($this->transaction instanceof EE_Transaction) {
1266
+				$default_data['TXN_status'] = $this->transaction->status_ID();
1267
+				$default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
1268
+				foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
1269
+					$default_data['registrations'][$REG_ID] = $registration->status_ID();
1270 1270
 				}
1271
-				if ( $this->transaction->ID() ) {
1272
-					$TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
1271
+				if ($this->transaction->ID()) {
1272
+					$TXN_ID = 'EE_Transaction: '.$this->transaction->ID();
1273 1273
 					// don't serialize objects
1274
-					$info = $this->_strip_objects( $info );
1275
-					if ( ! isset( $debug_data[ $TXN_ID ] ) ) {
1276
-						$debug_data[ $TXN_ID ] = array();
1274
+					$info = $this->_strip_objects($info);
1275
+					if ( ! isset($debug_data[$TXN_ID])) {
1276
+						$debug_data[$TXN_ID] = array();
1277 1277
 					}
1278
-					$debug_data[ $TXN_ID ][ microtime() ] = array_merge(
1278
+					$debug_data[$TXN_ID][microtime()] = array_merge(
1279 1279
 						$default_data,
1280 1280
 						$info
1281 1281
 					);
1282
-					update_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data );
1282
+					update_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), $debug_data);
1283 1283
 				}
1284 1284
 			}
1285 1285
 		}
@@ -1292,23 +1292,23 @@  discard block
 block discarded – undo
1292 1292
 	 * @param array $info
1293 1293
 	 * @return array
1294 1294
 	 */
1295
-	public function _strip_objects( $info = array() ) {
1296
-		foreach ( (array)$info as $key => $value ) {
1297
-			if ( is_array( $value )) {
1298
-				$info[ $key ] = $this->_strip_objects( $value );
1299
-			} else if ( is_object( $value ) ) {
1300
-				$object_class = get_class( $value );
1301
-				$info[ $object_class ] = array();
1302
-				$info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : 0;
1303
-				if ( method_exists( $value, 'status' ) ) {
1304
-					$info[ $object_class ][ 'status' ] = $value->status();
1305
-				} else if ( method_exists( $value, 'status_ID' ) ) {
1306
-					$info[ $object_class ][ 'status' ] = $value->status_ID();
1295
+	public function _strip_objects($info = array()) {
1296
+		foreach ((array) $info as $key => $value) {
1297
+			if (is_array($value)) {
1298
+				$info[$key] = $this->_strip_objects($value);
1299
+			} else if (is_object($value)) {
1300
+				$object_class = get_class($value);
1301
+				$info[$object_class] = array();
1302
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1303
+				if (method_exists($value, 'status')) {
1304
+					$info[$object_class]['status'] = $value->status();
1305
+				} else if (method_exists($value, 'status_ID')) {
1306
+					$info[$object_class]['status'] = $value->status_ID();
1307 1307
 				}
1308
-				unset( $info[ $key ] );
1308
+				unset($info[$key]);
1309 1309
 			}
1310 1310
 		}
1311
-		return (array)$info;
1311
+		return (array) $info;
1312 1312
 	}
1313 1313
 
1314 1314
 
Please login to merge, or discard this patch.
core/domain/services/registration/UpdateRegistrationService.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\domain\services\DomainService;
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
 
10 10
 
@@ -20,25 +20,25 @@  discard block
 block discarded – undo
20 20
 class UpdateRegistrationService extends DomainService
21 21
 {
22 22
 
23
-    /**
24
-     * @param \EE_Registration $registration
25
-     * @return bool
26
-     */
27
-    public function updateRegistrationAndTransaction(\EE_Registration $registration)
28
-    {
29
-        $transaction = $registration->transaction();
30
-        // reset transaction status back to incomplete
31
-        $transaction->set_status(\EEM_Transaction::incomplete_status_code);
32
-        // update transaction and all line item totals and subtotals
33
-        $transaction->total_line_item()->recalculate_total_including_taxes();
34
-        // maybe update status, but don't save transaction just yet
35
-        $transaction->update_status_based_on_total_paid();
36
-        /** @type \EE_Registration_Processor $registration_processor */
37
-        $registration_processor = \EE_Registry::instance()->load_class('Registration_Processor');
38
-        $registration_processor->update_registration_final_prices($transaction);
39
-        $registration_processor->update_registration_status_and_trigger_notifications($registration);
40
-        return true;
41
-    }
23
+	/**
24
+	 * @param \EE_Registration $registration
25
+	 * @return bool
26
+	 */
27
+	public function updateRegistrationAndTransaction(\EE_Registration $registration)
28
+	{
29
+		$transaction = $registration->transaction();
30
+		// reset transaction status back to incomplete
31
+		$transaction->set_status(\EEM_Transaction::incomplete_status_code);
32
+		// update transaction and all line item totals and subtotals
33
+		$transaction->total_line_item()->recalculate_total_including_taxes();
34
+		// maybe update status, but don't save transaction just yet
35
+		$transaction->update_status_based_on_total_paid();
36
+		/** @type \EE_Registration_Processor $registration_processor */
37
+		$registration_processor = \EE_Registry::instance()->load_class('Registration_Processor');
38
+		$registration_processor->update_registration_final_prices($transaction);
39
+		$registration_processor->update_registration_status_and_trigger_notifications($registration);
40
+		return true;
41
+	}
42 42
 
43 43
 }
44 44
 // End of file UpdateRegistrationService.php
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         // when adding a new registration...
74 74
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
75 75
             EE_System::do_not_cache();
76
-            if (! isset($this->_req_data['processing_registration'])
76
+            if ( ! isset($this->_req_data['processing_registration'])
77 77
                  || absint($this->_req_data['processing_registration']) !== 1
78 78
             ) {
79 79
                 // and it's NOT the attendee information reg step
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     public function _set_page_routes()
169 169
     {
170 170
         $this->_get_registration_status_array();
171
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
171
+        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
172 172
             ? $this->_req_data['_REG_ID'] : 0;
173 173
         $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
174 174
             ? $this->_req_data['reg_status_change_form']['REG_ID']
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
         //style
659 659
         wp_register_style(
660 660
             'espresso_reg',
661
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
661
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
662 662
             array('ee-admin-css'),
663 663
             EVENT_ESPRESSO_VERSION
664 664
         );
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
         //script
667 667
         wp_register_script(
668 668
             'espresso_reg',
669
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
669
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
670 670
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671 671
             EVENT_ESPRESSO_VERSION,
672 672
             true
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         wp_deregister_style('espresso_reg');
705 705
         wp_register_style(
706 706
             'espresso_att',
707
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
707
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
708 708
             array('ee-admin-css'),
709 709
             EVENT_ESPRESSO_VERSION
710 710
         );
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     {
717 717
         wp_register_script(
718 718
             'ee-spco-for-admin',
719
-            REG_ASSETS_URL . 'spco_for_admin.js',
719
+            REG_ASSETS_URL.'spco_for_admin.js',
720 720
             array('underscore', 'jquery'),
721 721
             EVENT_ESPRESSO_VERSION,
722 722
             true
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
850 850
                 ),
851 851
             );
852
-            $this->_views['trash']      = array(
852
+            $this->_views['trash'] = array(
853 853
                 'slug'        => 'trash',
854 854
                 'label'       => esc_html__('Trash', 'event_espresso'),
855 855
                 'count'       => 0,
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
         }
939 939
         $sc_items = array(
940 940
             'approved_status'   => array(
941
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
941
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
942 942
                 'desc'  => EEH_Template::pretty_status(
943 943
                     EEM_Registration::status_id_approved,
944 944
                     false,
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
                 ),
947 947
             ),
948 948
             'pending_status'    => array(
949
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
949
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
950 950
                 'desc'  => EEH_Template::pretty_status(
951 951
                     EEM_Registration::status_id_pending_payment,
952 952
                     false,
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
                 ),
955 955
             ),
956 956
             'wait_list'         => array(
957
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
957
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
958 958
                 'desc'  => EEH_Template::pretty_status(
959 959
                     EEM_Registration::status_id_wait_list,
960 960
                     false,
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
                 ),
963 963
             ),
964 964
             'incomplete_status' => array(
965
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
965
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
966 966
                 'desc'  => EEH_Template::pretty_status(
967 967
                     EEM_Registration::status_id_incomplete,
968 968
                     false,
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
                 ),
971 971
             ),
972 972
             'not_approved'      => array(
973
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
973
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
974 974
                 'desc'  => EEH_Template::pretty_status(
975 975
                     EEM_Registration::status_id_not_approved,
976 976
                     false,
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
                 ),
979 979
             ),
980 980
             'declined_status'   => array(
981
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
981
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
982 982
                 'desc'  => EEH_Template::pretty_status(
983 983
                     EEM_Registration::status_id_declined,
984 984
                     false,
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
                 ),
987 987
             ),
988 988
             'cancelled_status'  => array(
989
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
989
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
990 990
                 'desc'  => EEH_Template::pretty_status(
991 991
                     EEM_Registration::status_id_cancelled,
992 992
                     false,
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
                 'espresso_registrations_new_registration',
1016 1016
                 $EVT_ID
1017 1017
             )) {
1018
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1018
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1019 1019
                     'new_registration',
1020 1020
                     'add-registrant',
1021 1021
                     array('event_id' => $EVT_ID),
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1056 1056
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1057 1057
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1058
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1058
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1059 1059
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1060 1060
             }
1061 1061
         }
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
             'caps'                     => EEM_Registration::caps_read_admin,
1156 1156
             'default_where_conditions' => 'this_model_only',
1157 1157
         );
1158
-        if (! $count) {
1158
+        if ( ! $count) {
1159 1159
             $query_params = array_merge(
1160 1160
                 $query_params,
1161 1161
                 $this->_get_orderby_for_registrations_query(),
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
     protected function _add_event_id_to_where_conditions(array $request)
1177 1177
     {
1178 1178
         $where = array();
1179
-        if (! empty($request['event_id'])) {
1179
+        if ( ! empty($request['event_id'])) {
1180 1180
             $where['EVT_ID'] = absint($request['event_id']);
1181 1181
         }
1182 1182
         return $where;
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
     protected function _add_category_id_to_where_conditions(array $request)
1193 1193
     {
1194 1194
         $where = array();
1195
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1195
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1196 1196
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1197 1197
         }
1198 1198
         return $where;
@@ -1208,10 +1208,10 @@  discard block
 block discarded – undo
1208 1208
     protected function _add_datetime_id_to_where_conditions(array $request)
1209 1209
     {
1210 1210
         $where = array();
1211
-        if (! empty($request['datetime_id'])) {
1211
+        if ( ! empty($request['datetime_id'])) {
1212 1212
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1213 1213
         }
1214
-        if (! empty($request['DTT_ID'])) {
1214
+        if ( ! empty($request['DTT_ID'])) {
1215 1215
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1216 1216
         }
1217 1217
         return $where;
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1238 1238
          * UNLESS viewing trashed registrations.
1239 1239
          */
1240
-        if (! empty($registration_status)) {
1240
+        if ( ! empty($registration_status)) {
1241 1241
             $where['STS_ID'] = $registration_status;
1242 1242
         } else {
1243 1243
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1277,12 +1277,12 @@  discard block
 block discarded – undo
1277 1277
                 array(
1278 1278
                     EEM_Registration::instance()->convert_datetime_for_query(
1279 1279
                         'REG_date',
1280
-                        $now . ' 00:00:00',
1280
+                        $now.' 00:00:00',
1281 1281
                         'Y-m-d H:i:s'
1282 1282
                     ),
1283 1283
                     EEM_Registration::instance()->convert_datetime_for_query(
1284 1284
                         'REG_date',
1285
-                        $now . ' 23:59:59',
1285
+                        $now.' 23:59:59',
1286 1286
                         'Y-m-d H:i:s'
1287 1287
                     ),
1288 1288
                 ),
@@ -1295,12 +1295,12 @@  discard block
 block discarded – undo
1295 1295
                 array(
1296 1296
                     EEM_Registration::instance()->convert_datetime_for_query(
1297 1297
                         'REG_date',
1298
-                        $current_year_and_month . '-01 00:00:00',
1298
+                        $current_year_and_month.'-01 00:00:00',
1299 1299
                         'Y-m-d H:i:s'
1300 1300
                     ),
1301 1301
                     EEM_Registration::instance()->convert_datetime_for_query(
1302 1302
                         'REG_date',
1303
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1303
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1304 1304
                         'Y-m-d H:i:s'
1305 1305
                     ),
1306 1306
                 ),
@@ -1315,18 +1315,18 @@  discard block
 block discarded – undo
1315 1315
                 : '';
1316 1316
             //if there is not a month or year then we can't go further
1317 1317
             if ($month_requested && $year_requested) {
1318
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1318
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1319 1319
                 $where['REG_date'] = array(
1320 1320
                     'BETWEEN',
1321 1321
                     array(
1322 1322
                         EEM_Registration::instance()->convert_datetime_for_query(
1323 1323
                             'REG_date',
1324
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1324
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1325 1325
                             'Y-m-d H:i:s'
1326 1326
                         ),
1327 1327
                         EEM_Registration::instance()->convert_datetime_for_query(
1328 1328
                             'REG_date',
1329
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1329
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1330 1330
                             'Y-m-d H:i:s'
1331 1331
                         ),
1332 1332
                     ),
@@ -1346,8 +1346,8 @@  discard block
 block discarded – undo
1346 1346
     protected function _add_search_to_where_conditions(array $request)
1347 1347
     {
1348 1348
         $where = array();
1349
-        if (! empty($request['s'])) {
1350
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1349
+        if ( ! empty($request['s'])) {
1350
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1351 1351
             $where['OR*search_conditions'] = array(
1352 1352
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1353 1353
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
             : $per_page;
1461 1461
 
1462 1462
         //-1 means return all results so get out if that's set.
1463
-        if ((int)$per_page === -1) {
1463
+        if ((int) $per_page === -1) {
1464 1464
             return array();
1465 1465
         }
1466 1466
         $per_page = absint($per_page);
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
                 ),
1514 1514
                 REG_ADMIN_URL
1515 1515
             );
1516
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1516
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1517 1517
                 array(
1518 1518
                     'action' => 'default',
1519 1519
                     'EVT_ID' => $event_id,
@@ -1521,7 +1521,7 @@  discard block
 block discarded – undo
1521 1521
                 ),
1522 1522
                 admin_url('admin.php')
1523 1523
             );
1524
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1524
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1525 1525
                 array(
1526 1526
                     'page'   => 'espresso_events',
1527 1527
                     'action' => 'edit',
@@ -1530,12 +1530,12 @@  discard block
 block discarded – undo
1530 1530
                 admin_url('admin.php')
1531 1531
             );
1532 1532
             //next and previous links
1533
-            $next_reg                                      = $this->_registration->next(
1533
+            $next_reg = $this->_registration->next(
1534 1534
                 null,
1535 1535
                 array(),
1536 1536
                 'REG_ID'
1537 1537
             );
1538
-            $this->_template_args['next_registration']     = $next_reg
1538
+            $this->_template_args['next_registration'] = $next_reg
1539 1539
                 ? $this->_next_link(
1540 1540
                     EE_Admin_Page::add_query_args_and_nonce(
1541 1541
                         array(
@@ -1547,7 +1547,7 @@  discard block
 block discarded – undo
1547 1547
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1548 1548
                 )
1549 1549
                 : '';
1550
-            $previous_reg                                  = $this->_registration->previous(
1550
+            $previous_reg = $this->_registration->previous(
1551 1551
                 null,
1552 1552
                 array(),
1553 1553
                 'REG_ID'
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
                 )
1566 1566
                 : '';
1567 1567
             // grab header
1568
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1568
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1569 1569
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1570 1570
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1571 1571
                 $template_path,
@@ -1682,7 +1682,7 @@  discard block
 block discarded – undo
1682 1682
                             EEH_HTML::strong(
1683 1683
                                 $this->_registration->pretty_status(),
1684 1684
                                 '',
1685
-                                'status-' . $this->_registration->status_ID(),
1685
+                                'status-'.$this->_registration->status_ID(),
1686 1686
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1687 1687
                             )
1688 1688
                         )
@@ -1758,11 +1758,11 @@  discard block
 block discarded – undo
1758 1758
     {
1759 1759
         if (isset($this->_req_data['reg_status_change_form'])) {
1760 1760
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1761
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1761
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1762 1762
                 : array();
1763 1763
         } else {
1764 1764
             $REG_IDs = isset($this->_req_data['_REG_ID'])
1765
-                ? (array)$this->_req_data['_REG_ID']
1765
+                ? (array) $this->_req_data['_REG_ID']
1766 1766
                 : array();
1767 1767
         }
1768 1768
         // sanitize $REG_IDs
@@ -1807,7 +1807,7 @@  discard block
 block discarded – undo
1807 1807
     {
1808 1808
         $success = false;
1809 1809
         // typecast $REG_IDs
1810
-        $REG_IDs = (array)$REG_IDs;
1810
+        $REG_IDs = (array) $REG_IDs;
1811 1811
         if ( ! empty($REG_IDs)) {
1812 1812
             $success = true;
1813 1813
             // set default status if none is passed
@@ -1944,7 +1944,7 @@  discard block
 block discarded – undo
1944 1944
             $action,
1945 1945
             $notify
1946 1946
         );
1947
-        $method = $action . '_registration';
1947
+        $method = $action.'_registration';
1948 1948
         if (method_exists($this, $method)) {
1949 1949
             $this->$method($notify);
1950 1950
         }
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
             $filtered_line_item_tree,
2059 2059
             array('EE_Registration' => $this->_registration)
2060 2060
         );
2061
-        $attendee                                = $this->_registration->attendee();
2061
+        $attendee = $this->_registration->attendee();
2062 2062
         if (EE_Registry::instance()->CAP->current_user_can(
2063 2063
             'ee_read_transaction',
2064 2064
             'espresso_transactions_view_transaction'
@@ -2137,7 +2137,7 @@  discard block
 block discarded – undo
2137 2137
                 'Payment method response',
2138 2138
                 'event_espresso'
2139 2139
             );
2140
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2140
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2141 2141
         }
2142 2142
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2143 2143
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2165,7 +2165,7 @@  discard block
 block discarded – undo
2165 2165
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2166 2166
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2167 2167
         $template_path                                                        =
2168
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2168
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2169 2169
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2170 2170
     }
2171 2171
 
@@ -2194,7 +2194,7 @@  discard block
 block discarded – undo
2194 2194
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2195 2195
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2196 2196
             $template_path                                     =
2197
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2197
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2198 2198
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2199 2199
         }
2200 2200
     }
@@ -2211,7 +2211,7 @@  discard block
 block discarded – undo
2211 2211
     public function form_before_question_group($output)
2212 2212
     {
2213 2213
         EE_Error::doing_it_wrong(
2214
-            __CLASS__ . '::' . __FUNCTION__,
2214
+            __CLASS__.'::'.__FUNCTION__,
2215 2215
             esc_html__(
2216 2216
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2217 2217
                 'event_espresso'
@@ -2236,7 +2236,7 @@  discard block
 block discarded – undo
2236 2236
     public function form_after_question_group($output)
2237 2237
     {
2238 2238
         EE_Error::doing_it_wrong(
2239
-            __CLASS__ . '::' . __FUNCTION__,
2239
+            __CLASS__.'::'.__FUNCTION__,
2240 2240
             esc_html__(
2241 2241
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2242 2242
                 'event_espresso'
@@ -2274,7 +2274,7 @@  discard block
 block discarded – undo
2274 2274
     public function form_form_field_label_wrap($label)
2275 2275
     {
2276 2276
         EE_Error::doing_it_wrong(
2277
-            __CLASS__ . '::' . __FUNCTION__,
2277
+            __CLASS__.'::'.__FUNCTION__,
2278 2278
             esc_html__(
2279 2279
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2280 2280
                 'event_espresso'
@@ -2284,7 +2284,7 @@  discard block
 block discarded – undo
2284 2284
         return '
2285 2285
 			<tr>
2286 2286
 				<th>
2287
-					' . $label . '
2287
+					' . $label.'
2288 2288
 				</th>';
2289 2289
     }
2290 2290
 
@@ -2300,7 +2300,7 @@  discard block
 block discarded – undo
2300 2300
     public function form_form_field_input__wrap($input)
2301 2301
     {
2302 2302
         EE_Error::doing_it_wrong(
2303
-            __CLASS__ . '::' . __FUNCTION__,
2303
+            __CLASS__.'::'.__FUNCTION__,
2304 2304
             esc_html__(
2305 2305
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2306 2306
                 'event_espresso'
@@ -2309,7 +2309,7 @@  discard block
 block discarded – undo
2309 2309
         );
2310 2310
         return '
2311 2311
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2312
-					' . $input . '
2312
+					' . $input.'
2313 2313
 				</td>
2314 2314
 			</tr>';
2315 2315
     }
@@ -2351,7 +2351,7 @@  discard block
 block discarded – undo
2351 2351
     protected function _get_reg_custom_questions_form($REG_ID)
2352 2352
     {
2353 2353
         if ( ! $this->_reg_custom_questions_form) {
2354
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2354
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2355 2355
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2356 2356
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2357 2357
             );
@@ -2384,7 +2384,7 @@  discard block
 block discarded – undo
2384 2384
         if ($form->is_valid()) {
2385 2385
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2386 2386
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2387
-                    $where_conditions    = array(
2387
+                    $where_conditions = array(
2388 2388
                         'QST_ID' => $question_id,
2389 2389
                         'REG_ID' => $REG_ID,
2390 2390
                     );
@@ -2422,7 +2422,7 @@  discard block
 block discarded – undo
2422 2422
         $REG = EEM_Registration::instance();
2423 2423
         //get all other registrations on this transaction, and cache
2424 2424
         //the attendees for them so we don't have to run another query using force_join
2425
-        $registrations                           = $REG->get_all(array(
2425
+        $registrations = $REG->get_all(array(
2426 2426
             array(
2427 2427
                 'TXN_ID' => $this->_registration->transaction_ID(),
2428 2428
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2446,7 +2446,7 @@  discard block
 block discarded – undo
2446 2446
             $att_nmbr = 1;
2447 2447
             foreach ($registrations as $registration) {
2448 2448
                 /* @var $registration EE_Registration */
2449
-                $attendee                                                    = $registration->attendee()
2449
+                $attendee = $registration->attendee()
2450 2450
                     ? $registration->attendee()
2451 2451
                     : EEM_Attendee::instance()
2452 2452
                                   ->create_default_object();
@@ -2459,19 +2459,19 @@  discard block
 block discarded – undo
2459 2459
                     ', ',
2460 2460
                     $attendee->full_address_as_array()
2461 2461
                 );
2462
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2462
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2463 2463
                     array(
2464 2464
                         'action' => 'edit_attendee',
2465 2465
                         'post'   => $attendee->ID(),
2466 2466
                     ),
2467 2467
                     REG_ADMIN_URL
2468 2468
                 );
2469
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2469
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2470 2470
                 $att_nmbr++;
2471 2471
             }
2472 2472
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2473 2473
         }
2474
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2474
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2475 2475
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2476 2476
     }
2477 2477
 
@@ -2511,20 +2511,20 @@  discard block
 block discarded – undo
2511 2511
         $this->_template_args['phone']             = $attendee->phone();
2512 2512
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2513 2513
         //edit link
2514
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2514
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2515 2515
             'action' => 'edit_attendee',
2516 2516
             'post'   => $attendee->ID(),
2517 2517
         ), REG_ADMIN_URL);
2518 2518
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2519 2519
         //create link
2520
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2520
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2521 2521
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2522 2522
                 'action'  => 'duplicate_attendee',
2523 2523
                 '_REG_ID' => $this->_registration->ID(),
2524 2524
             ), REG_ADMIN_URL) : '';
2525 2525
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2526 2526
         $this->_template_args['att_check']    = $att_check;
2527
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2527
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2528 2528
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2529 2529
     }
2530 2530
 
@@ -2566,7 +2566,7 @@  discard block
 block discarded – undo
2566 2566
             /** @var EE_Registration $REG */
2567 2567
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2568 2568
             $payments = $REG->registration_payments();
2569
-            if (! empty($payments)) {
2569
+            if ( ! empty($payments)) {
2570 2570
                 $name = $REG->attendee() instanceof EE_Attendee
2571 2571
                     ? $REG->attendee()->full_name()
2572 2572
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2759,7 +2759,7 @@  discard block
 block discarded – undo
2759 2759
                 'action' => 'edit',
2760 2760
                 'post'   => $this->_reg_event->ID(),
2761 2761
             ), EVENTS_ADMIN_URL);
2762
-            $edit_event_lnk                     = '<a href="'
2762
+            $edit_event_lnk = '<a href="'
2763 2763
                                                   . $edit_event_url
2764 2764
                                                   . '" title="'
2765 2765
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2777,7 +2777,7 @@  discard block
 block discarded – undo
2777 2777
         }
2778 2778
         // grab header
2779 2779
         $template_path                              =
2780
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2780
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2781 2781
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2782 2782
             $this->_template_args, true);
2783 2783
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2812,7 +2812,7 @@  discard block
 block discarded – undo
2812 2812
                 '</b>'
2813 2813
             );
2814 2814
             return '
2815
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2815
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2816 2816
 	<script >
2817 2817
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2818 2818
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2880,7 +2880,7 @@  discard block
 block discarded – undo
2880 2880
         //we come back to the process_registration_step route.
2881 2881
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2882 2882
         return EEH_Template::display_template(
2883
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2883
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2884 2884
             $template_args,
2885 2885
             true
2886 2886
         );
@@ -2899,7 +2899,7 @@  discard block
 block discarded – undo
2899 2899
         if (is_object($this->_reg_event)) {
2900 2900
             return true;
2901 2901
         }
2902
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2902
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2903 2903
         if ( ! $EVT_ID) {
2904 2904
             return false;
2905 2905
         }
@@ -2965,7 +2965,7 @@  discard block
 block discarded – undo
2965 2965
                 }
2966 2966
                 break;
2967 2967
             case 'questions' :
2968
-                if (! isset(
2968
+                if ( ! isset(
2969 2969
                     $this->_req_data['txn_reg_status_change'],
2970 2970
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
2971 2971
                 ) {
@@ -3079,7 +3079,7 @@  discard block
 block discarded – undo
3079 3079
     public function get_attendees($per_page, $count = false, $trash = false)
3080 3080
     {
3081 3081
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3082
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3082
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3083 3083
         $ATT_MDL                    = EEM_Attendee::instance();
3084 3084
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3085 3085
         switch ($this->_req_data['orderby']) {
@@ -3116,7 +3116,7 @@  discard block
 block discarded – undo
3116 3116
             : $per_page;
3117 3117
         $_where       = array();
3118 3118
         if ( ! empty($this->_req_data['s'])) {
3119
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3119
+            $sstr         = '%'.$this->_req_data['s'].'%';
3120 3120
             $_where['OR'] = array(
3121 3121
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3122 3122
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3192,9 +3192,9 @@  discard block
 block discarded – undo
3192 3192
      *                                                     the query parameters from the request
3193 3193
      * @return void ends the request with a redirect or download
3194 3194
      */
3195
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3195
+    public function _registrations_report_base($method_name_for_getting_query_params)
3196 3196
     {
3197
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3197
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3198 3198
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3199 3199
                 array(
3200 3200
                     'page'        => 'espresso_batch',
@@ -3203,7 +3203,7 @@  discard block
 block discarded – undo
3203 3203
                     'filters'     => urlencode(
3204 3204
                         serialize(
3205 3205
                             call_user_func(
3206
-                                array( $this, $method_name_for_getting_query_params ),
3206
+                                array($this, $method_name_for_getting_query_params),
3207 3207
                                 EEH_Array::is_set(
3208 3208
                                     $this->_req_data,
3209 3209
                                     'filters',
@@ -3223,8 +3223,8 @@  discard block
 block discarded – undo
3223 3223
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3224 3224
             );
3225 3225
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3226
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3227
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3226
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3227
+                require_once(EE_CLASSES.'EE_Export.class.php');
3228 3228
                 $EE_Export = EE_Export::instance($this->_req_data);
3229 3229
                 $EE_Export->export();
3230 3230
             }
@@ -3245,8 +3245,8 @@  discard block
 block discarded – undo
3245 3245
 
3246 3246
     public function _contact_list_export()
3247 3247
     {
3248
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3249
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3248
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3249
+            require_once(EE_CLASSES.'EE_Export.class.php');
3250 3250
             $EE_Export = EE_Export::instance($this->_req_data);
3251 3251
             $EE_Export->export_attendees();
3252 3252
         }
@@ -3263,8 +3263,8 @@  discard block
 block discarded – undo
3263 3263
                 'return_url'  => urlencode($this->_req_data['return_url']),
3264 3264
             )));
3265 3265
         } else {
3266
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3267
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3266
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3267
+                require_once(EE_CLASSES.'EE_Export.class.php');
3268 3268
                 $EE_Export = EE_Export::instance($this->_req_data);
3269 3269
                 $EE_Export->report_attendees();
3270 3270
             }
@@ -3330,7 +3330,7 @@  discard block
 block discarded – undo
3330 3330
             $updated_fields = array(
3331 3331
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3332 3332
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3333
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3333
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3334 3334
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3335 3335
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3336 3336
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3463,7 +3463,7 @@  discard block
 block discarded – undo
3463 3463
     {
3464 3464
         //get attendee object ( should already have it )
3465 3465
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3466
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3466
+        $template                         = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php';
3467 3467
         EEH_Template::display_template($template, $this->_template_args);
3468 3468
     }
3469 3469
 
@@ -3525,8 +3525,8 @@  discard block
 block discarded – undo
3525 3525
                 )
3526 3526
             )
3527 3527
         );
3528
-        $template                             =
3529
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3528
+        $template =
3529
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3530 3530
         EEH_Template::display_template($template, $this->_template_args);
3531 3531
     }
3532 3532
 
@@ -3545,7 +3545,7 @@  discard block
 block discarded – undo
3545 3545
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3546 3546
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3547 3547
         $template                              =
3548
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3548
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3549 3549
         EEH_Template::display_template($template, $this->_template_args);
3550 3550
     }
3551 3551
 
@@ -3560,7 +3560,7 @@  discard block
 block discarded – undo
3560 3560
     public function after_title_form_fields($post)
3561 3561
     {
3562 3562
         if ($post->post_type == 'espresso_attendees') {
3563
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3563
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3564 3564
             $template_args['attendee'] = $this->_cpt_model_obj;
3565 3565
             EEH_Template::display_template($template, $template_args);
3566 3566
         }
Please login to merge, or discard this patch.
Indentation   +3582 added lines, -3582 removed lines patch added patch discarded remove patch
@@ -30,2269 +30,2269 @@  discard block
 block discarded – undo
30 30
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
31 31
 {
32 32
 
33
-    /**
34
-     * @var EE_Registration
35
-     */
36
-    private $_registration;
37
-
38
-    /**
39
-     * @var EE_Event
40
-     */
41
-    private $_reg_event;
42
-
43
-    /**
44
-     * @var EE_Session
45
-     */
46
-    private $_session;
47
-
48
-    private static $_reg_status;
49
-
50
-    /**
51
-     * Form for displaying the custom questions for this registration.
52
-     * This gets used a few times throughout the request so its best to cache it
53
-     *
54
-     * @var EE_Registration_Custom_Questions_Form
55
-     */
56
-    protected $_reg_custom_questions_form = null;
57
-
58
-
59
-    /**
60
-     *        constructor
61
-     *
62
-     * @Constructor
63
-     * @access public
64
-     * @param bool $routing
65
-     * @return Registrations_Admin_Page
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        parent::__construct($routing);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'));
71
-    }
72
-
73
-
74
-    public function wp_loaded()
75
-    {
76
-        // when adding a new registration...
77
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
-            EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
80
-                 || absint($this->_req_data['processing_registration']) !== 1
81
-            ) {
82
-                // and it's NOT the attendee information reg step
83
-                // force cookie expiration by setting time to last week
84
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
-                // and update the global
86
-                $_COOKIE['ee_registration_added'] = 0;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-    protected function _init_page_props()
93
-    {
94
-        $this->page_slug        = REG_PG_SLUG;
95
-        $this->_admin_base_url  = REG_ADMIN_URL;
96
-        $this->_admin_base_path = REG_ADMIN;
97
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
98
-        $this->_cpt_routes      = array(
99
-            'add_new_attendee' => 'espresso_attendees',
100
-            'edit_attendee'    => 'espresso_attendees',
101
-            'insert_attendee'  => 'espresso_attendees',
102
-            'update_attendee'  => 'espresso_attendees',
103
-        );
104
-        $this->_cpt_model_names = array(
105
-            'add_new_attendee' => 'EEM_Attendee',
106
-            'edit_attendee'    => 'EEM_Attendee',
107
-        );
108
-        $this->_cpt_edit_routes = array(
109
-            'espresso_attendees' => 'edit_attendee',
110
-        );
111
-        $this->_pagenow_map     = array(
112
-            'add_new_attendee' => 'post-new.php',
113
-            'edit_attendee'    => 'post.php',
114
-            'trash'            => 'post.php',
115
-        );
116
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
-        //add filters so that the comment urls don't take users to a confusing 404 page
118
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
-    }
120
-
121
-
122
-    public function clear_comment_link($link, $comment, $args)
123
-    {
124
-        //gotta make sure this only happens on this route
125
-        $post_type = get_post_type($comment->comment_post_ID);
126
-        if ($post_type === 'espresso_attendees') {
127
-            return '#commentsdiv';
128
-        }
129
-        return $link;
130
-    }
131
-
132
-
133
-    protected function _ajax_hooks()
134
-    {
135
-        //todo: all hooks for registrations ajax goes in here
136
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
-    }
138
-
139
-
140
-    protected function _define_page_props()
141
-    {
142
-        $this->_admin_page_title = $this->page_label;
143
-        $this->_labels           = array(
144
-            'buttons'                      => array(
145
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
-            ),
154
-            'publishbox'                   => array(
155
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
-            ),
158
-            'hide_add_button_on_cpt_route' => array(
159
-                'edit_attendee' => true,
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     *        grab url requests and route them
167
-     *
168
-     * @access private
169
-     * @return void
170
-     */
171
-    public function _set_page_routes()
172
-    {
173
-        $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
-            ? $this->_req_data['_REG_ID'] : 0;
176
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
178
-            : $reg_id;
179
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
-            ? $this->_req_data['ATT_ID'] : 0;
181
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
-            ? $this->_req_data['post']
183
-            : $att_id;
184
-        $this->_page_routes = array(
185
-            'default'                            => array(
186
-                'func'       => '_registrations_overview_list_table',
187
-                'capability' => 'ee_read_registrations',
188
-            ),
189
-            'view_registration'                  => array(
190
-                'func'       => '_registration_details',
191
-                'capability' => 'ee_read_registration',
192
-                'obj_id'     => $reg_id,
193
-            ),
194
-            'edit_registration'                  => array(
195
-                'func'               => '_update_attendee_registration_form',
196
-                'noheader'           => true,
197
-                'headers_sent_route' => 'view_registration',
198
-                'capability'         => 'ee_edit_registration',
199
-                'obj_id'             => $reg_id,
200
-                '_REG_ID'            => $reg_id,
201
-            ),
202
-            'trash_registrations'                => array(
203
-                'func'       => '_trash_or_restore_registrations',
204
-                'args'       => array('trash' => true),
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'restore_registrations'              => array(
209
-                'func'       => '_trash_or_restore_registrations',
210
-                'args'       => array('trash' => false),
211
-                'noheader'   => true,
212
-                'capability' => 'ee_delete_registrations',
213
-            ),
214
-            'delete_registrations'               => array(
215
-                'func'       => '_delete_registrations',
216
-                'noheader'   => true,
217
-                'capability' => 'ee_delete_registrations',
218
-            ),
219
-            'new_registration'                   => array(
220
-                'func'       => 'new_registration',
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'process_reg_step'                   => array(
224
-                'func'       => 'process_reg_step',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registrations',
227
-            ),
228
-            'redirect_to_txn'                    => array(
229
-                'func'       => 'redirect_to_txn',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registrations',
232
-            ),
233
-            'change_reg_status'                  => array(
234
-                'func'       => '_change_reg_status',
235
-                'noheader'   => true,
236
-                'capability' => 'ee_edit_registration',
237
-                'obj_id'     => $reg_id,
238
-            ),
239
-            'approve_registration'               => array(
240
-                'func'       => 'approve_registration',
241
-                'noheader'   => true,
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_and_notify_registration'    => array(
246
-                'func'       => 'approve_registration',
247
-                'noheader'   => true,
248
-                'args'       => array(true),
249
-                'capability' => 'ee_edit_registration',
250
-                'obj_id'     => $reg_id,
251
-            ),
252
-            'approve_registrations'               => array(
253
-                'func'       => 'bulk_action_on_registrations',
254
-                'noheader'   => true,
255
-                'capability' => 'ee_edit_registrations',
256
-                'args' => array('approve')
257
-            ),
258
-            'approve_and_notify_registrations'               => array(
259
-                'func'       => 'bulk_action_on_registrations',
260
-                'noheader'   => true,
261
-                'capability' => 'ee_edit_registrations',
262
-                'args' => array('approve', true)
263
-            ),
264
-            'decline_registration'               => array(
265
-                'func'       => 'decline_registration',
266
-                'noheader'   => true,
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_and_notify_registration'    => array(
271
-                'func'       => 'decline_registration',
272
-                'noheader'   => true,
273
-                'args'       => array(true),
274
-                'capability' => 'ee_edit_registration',
275
-                'obj_id'     => $reg_id,
276
-            ),
277
-            'decline_registrations'               => array(
278
-                'func'       => 'bulk_action_on_registrations',
279
-                'noheader'   => true,
280
-                'capability' => 'ee_edit_registrations',
281
-                'args' => array('decline')
282
-            ),
283
-            'decline_and_notify_registrations'    => array(
284
-                'func'       => 'bulk_action_on_registrations',
285
-                'noheader'   => true,
286
-                'capability' => 'ee_edit_registrations',
287
-                'args' => array('decline', true)
288
-            ),
289
-            'pending_registration'               => array(
290
-                'func'       => 'pending_registration',
291
-                'noheader'   => true,
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_and_notify_registration'    => array(
296
-                'func'       => 'pending_registration',
297
-                'noheader'   => true,
298
-                'args'       => array(true),
299
-                'capability' => 'ee_edit_registration',
300
-                'obj_id'     => $reg_id,
301
-            ),
302
-            'pending_registrations'               => array(
303
-                'func'       => 'bulk_action_on_registrations',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-                'args' => array('pending')
307
-            ),
308
-            'pending_and_notify_registrations'    => array(
309
-                'func'       => 'bulk_action_on_registrations',
310
-                'noheader'   => true,
311
-                'capability' => 'ee_edit_registrations',
312
-                'args' => array('pending', true)
313
-            ),
314
-            'no_approve_registration'            => array(
315
-                'func'       => 'not_approve_registration',
316
-                'noheader'   => true,
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_and_notify_registration' => array(
321
-                'func'       => 'not_approve_registration',
322
-                'noheader'   => true,
323
-                'args'       => array(true),
324
-                'capability' => 'ee_edit_registration',
325
-                'obj_id'     => $reg_id,
326
-            ),
327
-            'no_approve_registrations'            => array(
328
-                'func'       => 'bulk_action_on_registrations',
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_registrations',
331
-                'args' => array('not_approve')
332
-            ),
333
-            'no_approve_and_notify_registrations' => array(
334
-                'func'       => 'bulk_action_on_registrations',
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_registrations',
337
-                'args' => array('not_approve', true)
338
-            ),
339
-            'cancel_registration'                => array(
340
-                'func'       => 'cancel_registration',
341
-                'noheader'   => true,
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_and_notify_registration'     => array(
346
-                'func'       => 'cancel_registration',
347
-                'noheader'   => true,
348
-                'args'       => array(true),
349
-                'capability' => 'ee_edit_registration',
350
-                'obj_id'     => $reg_id,
351
-            ),
352
-            'cancel_registrations'                => array(
353
-                'func'       => 'bulk_action_on_registrations',
354
-                'noheader'   => true,
355
-                'capability' => 'ee_edit_registrations',
356
-                'args' => array('cancel')
357
-            ),
358
-            'cancel_and_notify_registrations'     => array(
359
-                'func'       => 'bulk_action_on_registrations',
360
-                'noheader'   => true,
361
-                'capability' => 'ee_edit_registrations',
362
-                'args' => array('cancel', true)
363
-            ),
364
-            'wait_list_registration' => array(
365
-                'func'       => 'wait_list_registration',
366
-                'noheader'   => true,
367
-                'capability' => 'ee_edit_registration',
368
-                'obj_id'     => $reg_id,
369
-            ),
370
-            'contact_list'                       => array(
371
-                'func'       => '_attendee_contact_list_table',
372
-                'capability' => 'ee_read_contacts',
373
-            ),
374
-            'add_new_attendee'                   => array(
375
-                'func' => '_create_new_cpt_item',
376
-                'args' => array(
377
-                    'new_attendee' => true,
378
-                    'capability'   => 'ee_edit_contacts',
379
-                ),
380
-            ),
381
-            'edit_attendee'                      => array(
382
-                'func'       => '_edit_cpt_item',
383
-                'capability' => 'ee_edit_contacts',
384
-                'obj_id'     => $att_id,
385
-            ),
386
-            'duplicate_attendee'                 => array(
387
-                'func'       => '_duplicate_attendee',
388
-                'noheader'   => true,
389
-                'capability' => 'ee_edit_contacts',
390
-                'obj_id'     => $att_id,
391
-            ),
392
-            'insert_attendee'                    => array(
393
-                'func'       => '_insert_or_update_attendee',
394
-                'args'       => array(
395
-                    'new_attendee' => true,
396
-                ),
397
-                'noheader'   => true,
398
-                'capability' => 'ee_edit_contacts',
399
-            ),
400
-            'update_attendee'                    => array(
401
-                'func'       => '_insert_or_update_attendee',
402
-                'args'       => array(
403
-                    'new_attendee' => false,
404
-                ),
405
-                'noheader'   => true,
406
-                'capability' => 'ee_edit_contacts',
407
-                'obj_id'     => $att_id,
408
-            ),
409
-            'trash_attendees' => array(
410
-                'func' => '_trash_or_restore_attendees',
411
-                'args' => array(
412
-                    'trash' => 'true'
413
-                ),
414
-                'noheader' => true,
415
-                'capability' => 'ee_delete_contacts'
416
-            ),
417
-            'trash_attendee'                    => array(
418
-                'func'       => '_trash_or_restore_attendees',
419
-                'args'       => array(
420
-                    'trash' => true,
421
-                ),
422
-                'noheader'   => true,
423
-                'capability' => 'ee_delete_contacts',
424
-                'obj_id'     => $att_id,
425
-            ),
426
-            'restore_attendees'                  => array(
427
-                'func'       => '_trash_or_restore_attendees',
428
-                'args'       => array(
429
-                    'trash' => false,
430
-                ),
431
-                'noheader'   => true,
432
-                'capability' => 'ee_delete_contacts',
433
-                'obj_id'     => $att_id,
434
-            ),
435
-            'resend_registration'                => array(
436
-                'func'       => '_resend_registration',
437
-                'noheader'   => true,
438
-                'capability' => 'ee_send_message',
439
-            ),
440
-            'registrations_report'               => array(
441
-                'func'       => '_registrations_report',
442
-                'noheader'   => true,
443
-                'capability' => 'ee_read_registrations',
444
-            ),
445
-            'contact_list_export'                => array(
446
-                'func'       => '_contact_list_export',
447
-                'noheader'   => true,
448
-                'capability' => 'export',
449
-            ),
450
-            'contact_list_report'                => array(
451
-                'func'       => '_contact_list_report',
452
-                'noheader'   => true,
453
-                'capability' => 'ee_read_contacts',
454
-            ),
455
-        );
456
-    }
457
-
458
-
459
-    protected function _set_page_config()
460
-    {
461
-        $this->_page_config = array(
462
-            'default'           => array(
463
-                'nav'           => array(
464
-                    'label' => esc_html__('Overview', 'event_espresso'),
465
-                    'order' => 5,
466
-                ),
467
-                'help_tabs'     => array(
468
-                    'registrations_overview_help_tab'                       => array(
469
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
470
-                        'filename' => 'registrations_overview',
471
-                    ),
472
-                    'registrations_overview_table_column_headings_help_tab' => array(
473
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
474
-                        'filename' => 'registrations_overview_table_column_headings',
475
-                    ),
476
-                    'registrations_overview_filters_help_tab'               => array(
477
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
478
-                        'filename' => 'registrations_overview_filters',
479
-                    ),
480
-                    'registrations_overview_views_help_tab'                 => array(
481
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
482
-                        'filename' => 'registrations_overview_views',
483
-                    ),
484
-                    'registrations_regoverview_other_help_tab'              => array(
485
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
486
-                        'filename' => 'registrations_overview_other',
487
-                    ),
488
-                ),
489
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
490
-                'qtips'         => array('Registration_List_Table_Tips'),
491
-                'list_table'    => 'EE_Registrations_List_Table',
492
-                'require_nonce' => false,
493
-            ),
494
-            'view_registration' => array(
495
-                'nav'           => array(
496
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
497
-                    'order'      => 15,
498
-                    'url'        => isset($this->_req_data['_REG_ID'])
499
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
500
-                        : $this->_admin_base_url,
501
-                    'persistent' => false,
502
-                ),
503
-                'help_tabs'     => array(
504
-                    'registrations_details_help_tab'                    => array(
505
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
506
-                        'filename' => 'registrations_details',
507
-                    ),
508
-                    'registrations_details_table_help_tab'              => array(
509
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
510
-                        'filename' => 'registrations_details_table',
511
-                    ),
512
-                    'registrations_details_form_answers_help_tab'       => array(
513
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
514
-                        'filename' => 'registrations_details_form_answers',
515
-                    ),
516
-                    'registrations_details_registrant_details_help_tab' => array(
517
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
518
-                        'filename' => 'registrations_details_registrant_details',
519
-                    ),
520
-                ),
521
-                'help_tour'     => array('Registration_Details_Help_Tour'),
522
-                'metaboxes'     => array_merge(
523
-                    $this->_default_espresso_metaboxes,
524
-                    array('_registration_details_metaboxes')
525
-                ),
526
-                'require_nonce' => false,
527
-            ),
528
-            'new_registration'  => array(
529
-                'nav'           => array(
530
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
531
-                    'url'        => '#',
532
-                    'order'      => 15,
533
-                    'persistent' => false,
534
-                ),
535
-                'metaboxes'     => $this->_default_espresso_metaboxes,
536
-                'labels'        => array(
537
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
538
-                ),
539
-                'require_nonce' => false,
540
-            ),
541
-            'add_new_attendee'  => array(
542
-                'nav'           => array(
543
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
544
-                    'order'      => 15,
545
-                    'persistent' => false,
546
-                ),
547
-                'metaboxes'     => array_merge(
548
-                    $this->_default_espresso_metaboxes,
549
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
550
-                ),
551
-                'require_nonce' => false,
552
-            ),
553
-            'edit_attendee'     => array(
554
-                'nav'           => array(
555
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
556
-                    'order'      => 15,
557
-                    'persistent' => false,
558
-                    'url'        => isset($this->_req_data['ATT_ID'])
559
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
560
-                        : $this->_admin_base_url,
561
-                ),
562
-                'metaboxes'     => array('attendee_editor_metaboxes'),
563
-                'require_nonce' => false,
564
-            ),
565
-            'contact_list'      => array(
566
-                'nav'           => array(
567
-                    'label' => esc_html__('Contact List', 'event_espresso'),
568
-                    'order' => 20,
569
-                ),
570
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
571
-                'help_tabs'     => array(
572
-                    'registrations_contact_list_help_tab'                       => array(
573
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
574
-                        'filename' => 'registrations_contact_list',
575
-                    ),
576
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
577
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
578
-                        'filename' => 'registrations_contact_list_table_column_headings',
579
-                    ),
580
-                    'registrations_contact_list_views_help_tab'                 => array(
581
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
582
-                        'filename' => 'registrations_contact_list_views',
583
-                    ),
584
-                    'registrations_contact_list_other_help_tab'                 => array(
585
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
586
-                        'filename' => 'registrations_contact_list_other',
587
-                    ),
588
-                ),
589
-                'help_tour'     => array('Contact_List_Help_Tour'),
590
-                'metaboxes'     => array(),
591
-                'require_nonce' => false,
592
-            ),
593
-            //override default cpt routes
594
-            'create_new'        => '',
595
-            'edit'              => '',
596
-        );
597
-    }
598
-
599
-
600
-    /**
601
-     * The below methods aren't used by this class currently
602
-     */
603
-    protected function _add_screen_options()
604
-    {
605
-    }
606
-
607
-
608
-    protected function _add_feature_pointers()
609
-    {
610
-    }
611
-
612
-
613
-    public function admin_init()
614
-    {
615
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
616
-            'click "Update Registration Questions" to save your changes',
617
-            'event_espresso'
618
-        );
619
-    }
620
-
621
-
622
-    public function admin_notices()
623
-    {
624
-    }
625
-
626
-
627
-    public function admin_footer_scripts()
628
-    {
629
-    }
630
-
631
-
632
-    /**
633
-     *        get list of registration statuses
634
-     *
635
-     * @access private
636
-     * @return void
637
-     */
638
-    private function _get_registration_status_array()
639
-    {
640
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
641
-    }
642
-
643
-
644
-    protected function _add_screen_options_default()
645
-    {
646
-        $this->_per_page_screen_option();
647
-    }
648
-
649
-
650
-    protected function _add_screen_options_contact_list()
651
-    {
652
-        $page_title              = $this->_admin_page_title;
653
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
654
-        $this->_per_page_screen_option();
655
-        $this->_admin_page_title = $page_title;
656
-    }
657
-
658
-
659
-    public function load_scripts_styles()
660
-    {
661
-        //style
662
-        wp_register_style(
663
-            'espresso_reg',
664
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
665
-            array('ee-admin-css'),
666
-            EVENT_ESPRESSO_VERSION
667
-        );
668
-        wp_enqueue_style('espresso_reg');
669
-        //script
670
-        wp_register_script(
671
-            'espresso_reg',
672
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
673
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
674
-            EVENT_ESPRESSO_VERSION,
675
-            true
676
-        );
677
-        wp_enqueue_script('espresso_reg');
678
-    }
679
-
680
-
681
-    public function load_scripts_styles_edit_attendee()
682
-    {
683
-        //stuff to only show up on our attendee edit details page.
684
-        $attendee_details_translations = array(
685
-            'att_publish_text' => sprintf(
686
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
687
-                $this->_cpt_model_obj->get_datetime('ATT_created')
688
-            ),
689
-        );
690
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
691
-        wp_enqueue_script('jquery-validate');
692
-    }
693
-
694
-
695
-    public function load_scripts_styles_view_registration()
696
-    {
697
-        //styles
698
-        wp_enqueue_style('espresso-ui-theme');
699
-        //scripts
700
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
701
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
702
-    }
703
-
704
-
705
-    public function load_scripts_styles_contact_list()
706
-    {
707
-        wp_deregister_style('espresso_reg');
708
-        wp_register_style(
709
-            'espresso_att',
710
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
711
-            array('ee-admin-css'),
712
-            EVENT_ESPRESSO_VERSION
713
-        );
714
-        wp_enqueue_style('espresso_att');
715
-    }
716
-
717
-
718
-    public function load_scripts_styles_new_registration()
719
-    {
720
-        wp_register_script(
721
-            'ee-spco-for-admin',
722
-            REG_ASSETS_URL . 'spco_for_admin.js',
723
-            array('underscore', 'jquery'),
724
-            EVENT_ESPRESSO_VERSION,
725
-            true
726
-        );
727
-        wp_enqueue_script('ee-spco-for-admin');
728
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
729
-        EE_Form_Section_Proper::wp_enqueue_scripts();
730
-        EED_Ticket_Selector::load_tckt_slctr_assets();
731
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
732
-    }
733
-
734
-
735
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
736
-    {
737
-        add_filter('FHEE_load_EE_messages', '__return_true');
738
-    }
739
-
740
-
741
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
742
-    {
743
-        add_filter('FHEE_load_EE_messages', '__return_true');
744
-    }
745
-
746
-
747
-    protected function _set_list_table_views_default()
748
-    {
749
-        //for notification related bulk actions we need to make sure only active messengers have an option.
750
-        EED_Messages::set_autoloaders();
751
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
752
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
753
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
754
-        //key= bulk_action_slug, value= message type.
755
-        $match_array = array(
756
-            'approve_registrations'    => 'registration',
757
-            'decline_registrations'    => 'declined_registration',
758
-            'pending_registrations'    => 'pending_approval',
759
-            'no_approve_registrations' => 'not_approved_registration',
760
-            'cancel_registrations'     => 'cancelled_registration',
761
-        );
762
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
763
-            'ee_send_message',
764
-            'batch_send_messages'
765
-        );
766
-        /** setup reg status bulk actions **/
767
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
768
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
769
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
770
-                    'Approve and Notify Registrations',
771
-                    'event_espresso'
772
-                );
773
-        }
774
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
775
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
776
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
777
-                    'Decline and Notify Registrations',
778
-                    'event_espresso'
779
-                );
780
-        }
781
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
782
-            'Set Registrations to Pending Payment',
783
-            'event_espresso'
784
-        );
785
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
786
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
787
-                    'Set Registrations to Pending Payment and Notify',
788
-                    'event_espresso'
789
-                );
790
-        }
791
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
792
-            'Set Registrations to Not Approved',
793
-            'event_espresso'
794
-        );
795
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
796
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
797
-                    'Set Registrations to Not Approved and Notify',
798
-                    'event_espresso'
799
-                );
800
-        }
801
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
802
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
803
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
804
-                    'Cancel Registrations and Notify',
805
-                    'event_espresso'
806
-                );
807
-        }
808
-        $def_reg_status_actions = apply_filters(
809
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
810
-            $def_reg_status_actions,
811
-            $active_mts,
812
-            $can_send
813
-        );
814
-
815
-        $this->_views = array(
816
-            'all'   => array(
817
-                'slug'        => 'all',
818
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
819
-                'count'       => 0,
820
-                'bulk_action' => array_merge($def_reg_status_actions, array(
821
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
822
-                )),
823
-            ),
824
-            'month' => array(
825
-                'slug'        => 'month',
826
-                'label'       => esc_html__('This Month', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => array_merge($def_reg_status_actions, array(
829
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
-                )),
831
-            ),
832
-            'today' => array(
833
-                'slug'        => 'today',
834
-                'label'       => sprintf(
835
-                    esc_html__('Today - %s', 'event_espresso'),
836
-                    date('M d, Y', current_time('timestamp'))
837
-                ),
838
-                'count'       => 0,
839
-                'bulk_action' => array_merge($def_reg_status_actions, array(
840
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
841
-                )),
842
-            ),
843
-        );
844
-        if (EE_Registry::instance()->CAP->current_user_can(
845
-            'ee_delete_registrations',
846
-            'espresso_registrations_delete_registration'
847
-        )) {
848
-            $this->_views['incomplete'] = array(
849
-                'slug'        => 'incomplete',
850
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
851
-                'count'       => 0,
852
-                'bulk_action' => array(
853
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
854
-                ),
855
-            );
856
-            $this->_views['trash']      = array(
857
-                'slug'        => 'trash',
858
-                'label'       => esc_html__('Trash', 'event_espresso'),
859
-                'count'       => 0,
860
-                'bulk_action' => array(
861
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
862
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
863
-                ),
864
-            );
865
-        }
866
-    }
867
-
868
-
869
-    protected function _set_list_table_views_contact_list()
870
-    {
871
-        $this->_views = array(
872
-            'in_use' => array(
873
-                'slug'        => 'in_use',
874
-                'label'       => esc_html__('In Use', 'event_espresso'),
875
-                'count'       => 0,
876
-                'bulk_action' => array(
877
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
878
-                ),
879
-            ),
880
-        );
881
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
882
-            'espresso_registrations_trash_attendees')
883
-        ) {
884
-            $this->_views['trash'] = array(
885
-                'slug'        => 'trash',
886
-                'label'       => esc_html__('Trash', 'event_espresso'),
887
-                'count'       => 0,
888
-                'bulk_action' => array(
889
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
890
-                ),
891
-            );
892
-        }
893
-    }
894
-
895
-
896
-    protected function _registration_legend_items()
897
-    {
898
-        $fc_items = array(
899
-            'star-icon'        => array(
900
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
901
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
902
-            ),
903
-            'view_details'     => array(
904
-                'class' => 'dashicons dashicons-clipboard',
905
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
906
-            ),
907
-            'edit_attendee'    => array(
908
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
909
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
910
-            ),
911
-            'view_transaction' => array(
912
-                'class' => 'dashicons dashicons-cart',
913
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
914
-            ),
915
-            'view_invoice'     => array(
916
-                'class' => 'dashicons dashicons-media-spreadsheet',
917
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
918
-            ),
919
-        );
920
-        if (EE_Registry::instance()->CAP->current_user_can(
921
-            'ee_send_message',
922
-            'espresso_registrations_resend_registration'
923
-        )) {
924
-            $fc_items['resend_registration'] = array(
925
-                'class' => 'dashicons dashicons-email-alt',
926
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
927
-            );
928
-        } else {
929
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
930
-        }
931
-        if (EE_Registry::instance()->CAP->current_user_can(
932
-            'ee_read_global_messages',
933
-            'view_filtered_messages'
934
-        )) {
935
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
936
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
937
-                $fc_items['view_related_messages'] = array(
938
-                    'class' => $related_for_icon['css_class'],
939
-                    'desc'  => $related_for_icon['label'],
940
-                );
941
-            }
942
-        }
943
-        $sc_items = array(
944
-            'approved_status'   => array(
945
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
946
-                'desc'  => EEH_Template::pretty_status(
947
-                    EEM_Registration::status_id_approved,
948
-                    false,
949
-                    'sentence'
950
-                ),
951
-            ),
952
-            'pending_status'    => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_pending_payment,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'wait_list'         => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_wait_list,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'incomplete_status' => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_incomplete,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'not_approved'      => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_not_approved,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'declined_status'   => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_declined,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-            'cancelled_status'  => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
994
-                'desc'  => EEH_Template::pretty_status(
995
-                    EEM_Registration::status_id_cancelled,
996
-                    false,
997
-                    'sentence'
998
-                ),
999
-            ),
1000
-        );
1001
-        return array_merge($fc_items, $sc_items);
1002
-    }
1003
-
1004
-
1005
-
1006
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1007
-    /**
1008
-     * @throws \EE_Error
1009
-     */
1010
-    protected function _registrations_overview_list_table()
1011
-    {
1012
-        $this->_template_args['admin_page_header'] = '';
1013
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1014
-            ? absint($this->_req_data['event_id'])
1015
-            : 0;
1016
-        if ($EVT_ID) {
1017
-            if (EE_Registry::instance()->CAP->current_user_can(
1018
-                'ee_edit_registrations',
1019
-                'espresso_registrations_new_registration',
1020
-                $EVT_ID
1021
-            )) {
1022
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1023
-                    'new_registration',
1024
-                    'add-registrant',
1025
-                    array('event_id' => $EVT_ID),
1026
-                    'add-new-h2'
1027
-                );
1028
-            }
1029
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1030
-            if ($event instanceof EE_Event) {
1031
-                $this->_template_args['admin_page_header'] = sprintf(
1032
-                    esc_html__(
1033
-                        '%s Viewing registrations for the event: %s%s',
1034
-                        'event_espresso'
1035
-                    ),
1036
-                    '<h3 style="line-height:1.5em;">',
1037
-                    '<br /><a href="'
1038
-                        . EE_Admin_Page::add_query_args_and_nonce(
1039
-                            array(
1040
-                                'action' => 'edit',
1041
-                                'post'   => $event->ID(),
1042
-                            ),
1043
-                            EVENTS_ADMIN_URL
1044
-                        )
1045
-                        . '">&nbsp;'
1046
-                        . $event->get('EVT_name')
1047
-                        . '&nbsp;</a>&nbsp;',
1048
-                    '</h3>'
1049
-                );
1050
-            }
1051
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1052
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1053
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1054
-                $this->_template_args['admin_page_header'] = substr(
1055
-                    $this->_template_args['admin_page_header'],
1056
-                    0,
1057
-                    -5
1058
-                );
1059
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1060
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1061
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1062
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1063
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1064
-            }
1065
-        }
1066
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1067
-        $this->display_admin_list_table_page_with_no_sidebar();
1068
-    }
1069
-
1070
-
1071
-    /**
1072
-     * This sets the _registration property for the registration details screen
1073
-     *
1074
-     * @access private
1075
-     * @return bool
1076
-     */
1077
-    private function _set_registration_object()
1078
-    {
1079
-        //get out if we've already set the object
1080
-        if ($this->_registration instanceof EE_Registration) {
1081
-            return true;
1082
-        }
1083
-        $REG    = EEM_Registration::instance();
1084
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1085
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1086
-            return true;
1087
-        } else {
1088
-            $error_msg = sprintf(
1089
-                esc_html__(
1090
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1091
-                    'event_espresso'
1092
-                ),
1093
-                $REG_ID
1094
-            );
1095
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1096
-            $this->_registration = null;
1097
-            return false;
1098
-        }
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * Used to retrieve registrations for the list table.
1104
-     *
1105
-     * @param int  $per_page
1106
-     * @param bool $count
1107
-     * @param bool $this_month
1108
-     * @param bool $today
1109
-     * @return EE_Registration[]|int
1110
-     * @throws EE_Error
1111
-     */
1112
-    public function get_registrations(
1113
-        $per_page = 10,
1114
-        $count = false,
1115
-        $this_month = false,
1116
-        $today = false
1117
-    ) {
1118
-        if ($this_month) {
1119
-            $this->_req_data['status'] = 'month';
1120
-        }
1121
-        if ($today) {
1122
-            $this->_req_data['status'] = 'today';
1123
-        }
1124
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1125
-        /**
1126
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1127
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1128
-         * @see EEM_Base::get_all()
1129
-         */
1130
-        $query_params['group_by'] = '';
1131
-
1132
-        return $count
1133
-            ? EEM_Registration::instance()->count($query_params)
1134
-            /** @type EE_Registration[] */
1135
-            : EEM_Registration::instance()->get_all($query_params);
1136
-    }
1137
-
1138
-
1139
-
1140
-    /**
1141
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1142
-     * Note: this listens to values on the request for some of the query parameters.
1143
-     *
1144
-     * @param array $request
1145
-     * @param int    $per_page
1146
-     * @param bool   $count
1147
-     * @return array
1148
-     */
1149
-    protected function _get_registration_query_parameters(
1150
-        $request = array(),
1151
-        $per_page = 10,
1152
-        $count = false
1153
-    ) {
1154
-
1155
-        $query_params = array(
1156
-            0                          => $this->_get_where_conditions_for_registrations_query(
1157
-                $request
1158
-            ),
1159
-            'caps'                     => EEM_Registration::caps_read_admin,
1160
-            'default_where_conditions' => 'this_model_only',
1161
-        );
1162
-        if (! $count) {
1163
-            $query_params = array_merge(
1164
-                $query_params,
1165
-                $this->_get_orderby_for_registrations_query(),
1166
-                $this->_get_limit($per_page)
1167
-            );
1168
-        }
1169
-
1170
-        return $query_params;
1171
-    }
1172
-
1173
-
1174
-    /**
1175
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1176
-     *
1177
-     * @param array $request usually the same as $this->_req_data but not necessarily
1178
-     * @return array
1179
-     */
1180
-    protected function _add_event_id_to_where_conditions(array $request)
1181
-    {
1182
-        $where = array();
1183
-        if (! empty($request['event_id'])) {
1184
-            $where['EVT_ID'] = absint($request['event_id']);
1185
-        }
1186
-        return $where;
1187
-    }
1188
-
1189
-
1190
-    /**
1191
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1192
-     *
1193
-     * @param array $request usually the same as $this->_req_data but not necessarily
1194
-     * @return array
1195
-     */
1196
-    protected function _add_category_id_to_where_conditions(array $request)
1197
-    {
1198
-        $where = array();
1199
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1200
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1201
-        }
1202
-        return $where;
1203
-    }
1204
-
1205
-
1206
-    /**
1207
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1208
-     *
1209
-     * @param array $request usually the same as $this->_req_data but not necessarily
1210
-     * @return array
1211
-     */
1212
-    protected function _add_datetime_id_to_where_conditions(array $request)
1213
-    {
1214
-        $where = array();
1215
-        if (! empty($request['datetime_id'])) {
1216
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1217
-        }
1218
-        if (! empty($request['DTT_ID'])) {
1219
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1220
-        }
1221
-        return $where;
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * Adds the correct registration status to the where conditions for the registrations query.
1227
-     *
1228
-     * @param array $request usually the same as $this->_req_data but not necessarily
1229
-     * @return array
1230
-     */
1231
-    protected function _add_registration_status_to_where_conditions(array $request)
1232
-    {
1233
-        $where = array();
1234
-        $view = EEH_Array::is_set($request, 'status', '');
1235
-        $registration_status = ! empty($request['_reg_status'])
1236
-            ? sanitize_text_field($request['_reg_status'])
1237
-            : '';
1238
-
1239
-        /*
33
+	/**
34
+	 * @var EE_Registration
35
+	 */
36
+	private $_registration;
37
+
38
+	/**
39
+	 * @var EE_Event
40
+	 */
41
+	private $_reg_event;
42
+
43
+	/**
44
+	 * @var EE_Session
45
+	 */
46
+	private $_session;
47
+
48
+	private static $_reg_status;
49
+
50
+	/**
51
+	 * Form for displaying the custom questions for this registration.
52
+	 * This gets used a few times throughout the request so its best to cache it
53
+	 *
54
+	 * @var EE_Registration_Custom_Questions_Form
55
+	 */
56
+	protected $_reg_custom_questions_form = null;
57
+
58
+
59
+	/**
60
+	 *        constructor
61
+	 *
62
+	 * @Constructor
63
+	 * @access public
64
+	 * @param bool $routing
65
+	 * @return Registrations_Admin_Page
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		parent::__construct($routing);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'));
71
+	}
72
+
73
+
74
+	public function wp_loaded()
75
+	{
76
+		// when adding a new registration...
77
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
+			EE_System::do_not_cache();
79
+			if (! isset($this->_req_data['processing_registration'])
80
+				 || absint($this->_req_data['processing_registration']) !== 1
81
+			) {
82
+				// and it's NOT the attendee information reg step
83
+				// force cookie expiration by setting time to last week
84
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
+				// and update the global
86
+				$_COOKIE['ee_registration_added'] = 0;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+	protected function _init_page_props()
93
+	{
94
+		$this->page_slug        = REG_PG_SLUG;
95
+		$this->_admin_base_url  = REG_ADMIN_URL;
96
+		$this->_admin_base_path = REG_ADMIN;
97
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
98
+		$this->_cpt_routes      = array(
99
+			'add_new_attendee' => 'espresso_attendees',
100
+			'edit_attendee'    => 'espresso_attendees',
101
+			'insert_attendee'  => 'espresso_attendees',
102
+			'update_attendee'  => 'espresso_attendees',
103
+		);
104
+		$this->_cpt_model_names = array(
105
+			'add_new_attendee' => 'EEM_Attendee',
106
+			'edit_attendee'    => 'EEM_Attendee',
107
+		);
108
+		$this->_cpt_edit_routes = array(
109
+			'espresso_attendees' => 'edit_attendee',
110
+		);
111
+		$this->_pagenow_map     = array(
112
+			'add_new_attendee' => 'post-new.php',
113
+			'edit_attendee'    => 'post.php',
114
+			'trash'            => 'post.php',
115
+		);
116
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
+		//add filters so that the comment urls don't take users to a confusing 404 page
118
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
+	}
120
+
121
+
122
+	public function clear_comment_link($link, $comment, $args)
123
+	{
124
+		//gotta make sure this only happens on this route
125
+		$post_type = get_post_type($comment->comment_post_ID);
126
+		if ($post_type === 'espresso_attendees') {
127
+			return '#commentsdiv';
128
+		}
129
+		return $link;
130
+	}
131
+
132
+
133
+	protected function _ajax_hooks()
134
+	{
135
+		//todo: all hooks for registrations ajax goes in here
136
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
+	}
138
+
139
+
140
+	protected function _define_page_props()
141
+	{
142
+		$this->_admin_page_title = $this->page_label;
143
+		$this->_labels           = array(
144
+			'buttons'                      => array(
145
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
+			),
154
+			'publishbox'                   => array(
155
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
+			),
158
+			'hide_add_button_on_cpt_route' => array(
159
+				'edit_attendee' => true,
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 *        grab url requests and route them
167
+	 *
168
+	 * @access private
169
+	 * @return void
170
+	 */
171
+	public function _set_page_routes()
172
+	{
173
+		$this->_get_registration_status_array();
174
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
+			? $this->_req_data['_REG_ID'] : 0;
176
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
+			? $this->_req_data['reg_status_change_form']['REG_ID']
178
+			: $reg_id;
179
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
+			? $this->_req_data['ATT_ID'] : 0;
181
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
+			? $this->_req_data['post']
183
+			: $att_id;
184
+		$this->_page_routes = array(
185
+			'default'                            => array(
186
+				'func'       => '_registrations_overview_list_table',
187
+				'capability' => 'ee_read_registrations',
188
+			),
189
+			'view_registration'                  => array(
190
+				'func'       => '_registration_details',
191
+				'capability' => 'ee_read_registration',
192
+				'obj_id'     => $reg_id,
193
+			),
194
+			'edit_registration'                  => array(
195
+				'func'               => '_update_attendee_registration_form',
196
+				'noheader'           => true,
197
+				'headers_sent_route' => 'view_registration',
198
+				'capability'         => 'ee_edit_registration',
199
+				'obj_id'             => $reg_id,
200
+				'_REG_ID'            => $reg_id,
201
+			),
202
+			'trash_registrations'                => array(
203
+				'func'       => '_trash_or_restore_registrations',
204
+				'args'       => array('trash' => true),
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'restore_registrations'              => array(
209
+				'func'       => '_trash_or_restore_registrations',
210
+				'args'       => array('trash' => false),
211
+				'noheader'   => true,
212
+				'capability' => 'ee_delete_registrations',
213
+			),
214
+			'delete_registrations'               => array(
215
+				'func'       => '_delete_registrations',
216
+				'noheader'   => true,
217
+				'capability' => 'ee_delete_registrations',
218
+			),
219
+			'new_registration'                   => array(
220
+				'func'       => 'new_registration',
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'process_reg_step'                   => array(
224
+				'func'       => 'process_reg_step',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registrations',
227
+			),
228
+			'redirect_to_txn'                    => array(
229
+				'func'       => 'redirect_to_txn',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registrations',
232
+			),
233
+			'change_reg_status'                  => array(
234
+				'func'       => '_change_reg_status',
235
+				'noheader'   => true,
236
+				'capability' => 'ee_edit_registration',
237
+				'obj_id'     => $reg_id,
238
+			),
239
+			'approve_registration'               => array(
240
+				'func'       => 'approve_registration',
241
+				'noheader'   => true,
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_and_notify_registration'    => array(
246
+				'func'       => 'approve_registration',
247
+				'noheader'   => true,
248
+				'args'       => array(true),
249
+				'capability' => 'ee_edit_registration',
250
+				'obj_id'     => $reg_id,
251
+			),
252
+			'approve_registrations'               => array(
253
+				'func'       => 'bulk_action_on_registrations',
254
+				'noheader'   => true,
255
+				'capability' => 'ee_edit_registrations',
256
+				'args' => array('approve')
257
+			),
258
+			'approve_and_notify_registrations'               => array(
259
+				'func'       => 'bulk_action_on_registrations',
260
+				'noheader'   => true,
261
+				'capability' => 'ee_edit_registrations',
262
+				'args' => array('approve', true)
263
+			),
264
+			'decline_registration'               => array(
265
+				'func'       => 'decline_registration',
266
+				'noheader'   => true,
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_and_notify_registration'    => array(
271
+				'func'       => 'decline_registration',
272
+				'noheader'   => true,
273
+				'args'       => array(true),
274
+				'capability' => 'ee_edit_registration',
275
+				'obj_id'     => $reg_id,
276
+			),
277
+			'decline_registrations'               => array(
278
+				'func'       => 'bulk_action_on_registrations',
279
+				'noheader'   => true,
280
+				'capability' => 'ee_edit_registrations',
281
+				'args' => array('decline')
282
+			),
283
+			'decline_and_notify_registrations'    => array(
284
+				'func'       => 'bulk_action_on_registrations',
285
+				'noheader'   => true,
286
+				'capability' => 'ee_edit_registrations',
287
+				'args' => array('decline', true)
288
+			),
289
+			'pending_registration'               => array(
290
+				'func'       => 'pending_registration',
291
+				'noheader'   => true,
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_and_notify_registration'    => array(
296
+				'func'       => 'pending_registration',
297
+				'noheader'   => true,
298
+				'args'       => array(true),
299
+				'capability' => 'ee_edit_registration',
300
+				'obj_id'     => $reg_id,
301
+			),
302
+			'pending_registrations'               => array(
303
+				'func'       => 'bulk_action_on_registrations',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+				'args' => array('pending')
307
+			),
308
+			'pending_and_notify_registrations'    => array(
309
+				'func'       => 'bulk_action_on_registrations',
310
+				'noheader'   => true,
311
+				'capability' => 'ee_edit_registrations',
312
+				'args' => array('pending', true)
313
+			),
314
+			'no_approve_registration'            => array(
315
+				'func'       => 'not_approve_registration',
316
+				'noheader'   => true,
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_and_notify_registration' => array(
321
+				'func'       => 'not_approve_registration',
322
+				'noheader'   => true,
323
+				'args'       => array(true),
324
+				'capability' => 'ee_edit_registration',
325
+				'obj_id'     => $reg_id,
326
+			),
327
+			'no_approve_registrations'            => array(
328
+				'func'       => 'bulk_action_on_registrations',
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_registrations',
331
+				'args' => array('not_approve')
332
+			),
333
+			'no_approve_and_notify_registrations' => array(
334
+				'func'       => 'bulk_action_on_registrations',
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_registrations',
337
+				'args' => array('not_approve', true)
338
+			),
339
+			'cancel_registration'                => array(
340
+				'func'       => 'cancel_registration',
341
+				'noheader'   => true,
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_and_notify_registration'     => array(
346
+				'func'       => 'cancel_registration',
347
+				'noheader'   => true,
348
+				'args'       => array(true),
349
+				'capability' => 'ee_edit_registration',
350
+				'obj_id'     => $reg_id,
351
+			),
352
+			'cancel_registrations'                => array(
353
+				'func'       => 'bulk_action_on_registrations',
354
+				'noheader'   => true,
355
+				'capability' => 'ee_edit_registrations',
356
+				'args' => array('cancel')
357
+			),
358
+			'cancel_and_notify_registrations'     => array(
359
+				'func'       => 'bulk_action_on_registrations',
360
+				'noheader'   => true,
361
+				'capability' => 'ee_edit_registrations',
362
+				'args' => array('cancel', true)
363
+			),
364
+			'wait_list_registration' => array(
365
+				'func'       => 'wait_list_registration',
366
+				'noheader'   => true,
367
+				'capability' => 'ee_edit_registration',
368
+				'obj_id'     => $reg_id,
369
+			),
370
+			'contact_list'                       => array(
371
+				'func'       => '_attendee_contact_list_table',
372
+				'capability' => 'ee_read_contacts',
373
+			),
374
+			'add_new_attendee'                   => array(
375
+				'func' => '_create_new_cpt_item',
376
+				'args' => array(
377
+					'new_attendee' => true,
378
+					'capability'   => 'ee_edit_contacts',
379
+				),
380
+			),
381
+			'edit_attendee'                      => array(
382
+				'func'       => '_edit_cpt_item',
383
+				'capability' => 'ee_edit_contacts',
384
+				'obj_id'     => $att_id,
385
+			),
386
+			'duplicate_attendee'                 => array(
387
+				'func'       => '_duplicate_attendee',
388
+				'noheader'   => true,
389
+				'capability' => 'ee_edit_contacts',
390
+				'obj_id'     => $att_id,
391
+			),
392
+			'insert_attendee'                    => array(
393
+				'func'       => '_insert_or_update_attendee',
394
+				'args'       => array(
395
+					'new_attendee' => true,
396
+				),
397
+				'noheader'   => true,
398
+				'capability' => 'ee_edit_contacts',
399
+			),
400
+			'update_attendee'                    => array(
401
+				'func'       => '_insert_or_update_attendee',
402
+				'args'       => array(
403
+					'new_attendee' => false,
404
+				),
405
+				'noheader'   => true,
406
+				'capability' => 'ee_edit_contacts',
407
+				'obj_id'     => $att_id,
408
+			),
409
+			'trash_attendees' => array(
410
+				'func' => '_trash_or_restore_attendees',
411
+				'args' => array(
412
+					'trash' => 'true'
413
+				),
414
+				'noheader' => true,
415
+				'capability' => 'ee_delete_contacts'
416
+			),
417
+			'trash_attendee'                    => array(
418
+				'func'       => '_trash_or_restore_attendees',
419
+				'args'       => array(
420
+					'trash' => true,
421
+				),
422
+				'noheader'   => true,
423
+				'capability' => 'ee_delete_contacts',
424
+				'obj_id'     => $att_id,
425
+			),
426
+			'restore_attendees'                  => array(
427
+				'func'       => '_trash_or_restore_attendees',
428
+				'args'       => array(
429
+					'trash' => false,
430
+				),
431
+				'noheader'   => true,
432
+				'capability' => 'ee_delete_contacts',
433
+				'obj_id'     => $att_id,
434
+			),
435
+			'resend_registration'                => array(
436
+				'func'       => '_resend_registration',
437
+				'noheader'   => true,
438
+				'capability' => 'ee_send_message',
439
+			),
440
+			'registrations_report'               => array(
441
+				'func'       => '_registrations_report',
442
+				'noheader'   => true,
443
+				'capability' => 'ee_read_registrations',
444
+			),
445
+			'contact_list_export'                => array(
446
+				'func'       => '_contact_list_export',
447
+				'noheader'   => true,
448
+				'capability' => 'export',
449
+			),
450
+			'contact_list_report'                => array(
451
+				'func'       => '_contact_list_report',
452
+				'noheader'   => true,
453
+				'capability' => 'ee_read_contacts',
454
+			),
455
+		);
456
+	}
457
+
458
+
459
+	protected function _set_page_config()
460
+	{
461
+		$this->_page_config = array(
462
+			'default'           => array(
463
+				'nav'           => array(
464
+					'label' => esc_html__('Overview', 'event_espresso'),
465
+					'order' => 5,
466
+				),
467
+				'help_tabs'     => array(
468
+					'registrations_overview_help_tab'                       => array(
469
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
470
+						'filename' => 'registrations_overview',
471
+					),
472
+					'registrations_overview_table_column_headings_help_tab' => array(
473
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
474
+						'filename' => 'registrations_overview_table_column_headings',
475
+					),
476
+					'registrations_overview_filters_help_tab'               => array(
477
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
478
+						'filename' => 'registrations_overview_filters',
479
+					),
480
+					'registrations_overview_views_help_tab'                 => array(
481
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
482
+						'filename' => 'registrations_overview_views',
483
+					),
484
+					'registrations_regoverview_other_help_tab'              => array(
485
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
486
+						'filename' => 'registrations_overview_other',
487
+					),
488
+				),
489
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
490
+				'qtips'         => array('Registration_List_Table_Tips'),
491
+				'list_table'    => 'EE_Registrations_List_Table',
492
+				'require_nonce' => false,
493
+			),
494
+			'view_registration' => array(
495
+				'nav'           => array(
496
+					'label'      => esc_html__('REG Details', 'event_espresso'),
497
+					'order'      => 15,
498
+					'url'        => isset($this->_req_data['_REG_ID'])
499
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
500
+						: $this->_admin_base_url,
501
+					'persistent' => false,
502
+				),
503
+				'help_tabs'     => array(
504
+					'registrations_details_help_tab'                    => array(
505
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
506
+						'filename' => 'registrations_details',
507
+					),
508
+					'registrations_details_table_help_tab'              => array(
509
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
510
+						'filename' => 'registrations_details_table',
511
+					),
512
+					'registrations_details_form_answers_help_tab'       => array(
513
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
514
+						'filename' => 'registrations_details_form_answers',
515
+					),
516
+					'registrations_details_registrant_details_help_tab' => array(
517
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
518
+						'filename' => 'registrations_details_registrant_details',
519
+					),
520
+				),
521
+				'help_tour'     => array('Registration_Details_Help_Tour'),
522
+				'metaboxes'     => array_merge(
523
+					$this->_default_espresso_metaboxes,
524
+					array('_registration_details_metaboxes')
525
+				),
526
+				'require_nonce' => false,
527
+			),
528
+			'new_registration'  => array(
529
+				'nav'           => array(
530
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
531
+					'url'        => '#',
532
+					'order'      => 15,
533
+					'persistent' => false,
534
+				),
535
+				'metaboxes'     => $this->_default_espresso_metaboxes,
536
+				'labels'        => array(
537
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
538
+				),
539
+				'require_nonce' => false,
540
+			),
541
+			'add_new_attendee'  => array(
542
+				'nav'           => array(
543
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
544
+					'order'      => 15,
545
+					'persistent' => false,
546
+				),
547
+				'metaboxes'     => array_merge(
548
+					$this->_default_espresso_metaboxes,
549
+					array('_publish_post_box', 'attendee_editor_metaboxes')
550
+				),
551
+				'require_nonce' => false,
552
+			),
553
+			'edit_attendee'     => array(
554
+				'nav'           => array(
555
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
556
+					'order'      => 15,
557
+					'persistent' => false,
558
+					'url'        => isset($this->_req_data['ATT_ID'])
559
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
560
+						: $this->_admin_base_url,
561
+				),
562
+				'metaboxes'     => array('attendee_editor_metaboxes'),
563
+				'require_nonce' => false,
564
+			),
565
+			'contact_list'      => array(
566
+				'nav'           => array(
567
+					'label' => esc_html__('Contact List', 'event_espresso'),
568
+					'order' => 20,
569
+				),
570
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
571
+				'help_tabs'     => array(
572
+					'registrations_contact_list_help_tab'                       => array(
573
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
574
+						'filename' => 'registrations_contact_list',
575
+					),
576
+					'registrations_contact-list_table_column_headings_help_tab' => array(
577
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
578
+						'filename' => 'registrations_contact_list_table_column_headings',
579
+					),
580
+					'registrations_contact_list_views_help_tab'                 => array(
581
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
582
+						'filename' => 'registrations_contact_list_views',
583
+					),
584
+					'registrations_contact_list_other_help_tab'                 => array(
585
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
586
+						'filename' => 'registrations_contact_list_other',
587
+					),
588
+				),
589
+				'help_tour'     => array('Contact_List_Help_Tour'),
590
+				'metaboxes'     => array(),
591
+				'require_nonce' => false,
592
+			),
593
+			//override default cpt routes
594
+			'create_new'        => '',
595
+			'edit'              => '',
596
+		);
597
+	}
598
+
599
+
600
+	/**
601
+	 * The below methods aren't used by this class currently
602
+	 */
603
+	protected function _add_screen_options()
604
+	{
605
+	}
606
+
607
+
608
+	protected function _add_feature_pointers()
609
+	{
610
+	}
611
+
612
+
613
+	public function admin_init()
614
+	{
615
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
616
+			'click "Update Registration Questions" to save your changes',
617
+			'event_espresso'
618
+		);
619
+	}
620
+
621
+
622
+	public function admin_notices()
623
+	{
624
+	}
625
+
626
+
627
+	public function admin_footer_scripts()
628
+	{
629
+	}
630
+
631
+
632
+	/**
633
+	 *        get list of registration statuses
634
+	 *
635
+	 * @access private
636
+	 * @return void
637
+	 */
638
+	private function _get_registration_status_array()
639
+	{
640
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
641
+	}
642
+
643
+
644
+	protected function _add_screen_options_default()
645
+	{
646
+		$this->_per_page_screen_option();
647
+	}
648
+
649
+
650
+	protected function _add_screen_options_contact_list()
651
+	{
652
+		$page_title              = $this->_admin_page_title;
653
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
654
+		$this->_per_page_screen_option();
655
+		$this->_admin_page_title = $page_title;
656
+	}
657
+
658
+
659
+	public function load_scripts_styles()
660
+	{
661
+		//style
662
+		wp_register_style(
663
+			'espresso_reg',
664
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
665
+			array('ee-admin-css'),
666
+			EVENT_ESPRESSO_VERSION
667
+		);
668
+		wp_enqueue_style('espresso_reg');
669
+		//script
670
+		wp_register_script(
671
+			'espresso_reg',
672
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
673
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
674
+			EVENT_ESPRESSO_VERSION,
675
+			true
676
+		);
677
+		wp_enqueue_script('espresso_reg');
678
+	}
679
+
680
+
681
+	public function load_scripts_styles_edit_attendee()
682
+	{
683
+		//stuff to only show up on our attendee edit details page.
684
+		$attendee_details_translations = array(
685
+			'att_publish_text' => sprintf(
686
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
687
+				$this->_cpt_model_obj->get_datetime('ATT_created')
688
+			),
689
+		);
690
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
691
+		wp_enqueue_script('jquery-validate');
692
+	}
693
+
694
+
695
+	public function load_scripts_styles_view_registration()
696
+	{
697
+		//styles
698
+		wp_enqueue_style('espresso-ui-theme');
699
+		//scripts
700
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
701
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
702
+	}
703
+
704
+
705
+	public function load_scripts_styles_contact_list()
706
+	{
707
+		wp_deregister_style('espresso_reg');
708
+		wp_register_style(
709
+			'espresso_att',
710
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
711
+			array('ee-admin-css'),
712
+			EVENT_ESPRESSO_VERSION
713
+		);
714
+		wp_enqueue_style('espresso_att');
715
+	}
716
+
717
+
718
+	public function load_scripts_styles_new_registration()
719
+	{
720
+		wp_register_script(
721
+			'ee-spco-for-admin',
722
+			REG_ASSETS_URL . 'spco_for_admin.js',
723
+			array('underscore', 'jquery'),
724
+			EVENT_ESPRESSO_VERSION,
725
+			true
726
+		);
727
+		wp_enqueue_script('ee-spco-for-admin');
728
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
729
+		EE_Form_Section_Proper::wp_enqueue_scripts();
730
+		EED_Ticket_Selector::load_tckt_slctr_assets();
731
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
732
+	}
733
+
734
+
735
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
736
+	{
737
+		add_filter('FHEE_load_EE_messages', '__return_true');
738
+	}
739
+
740
+
741
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
742
+	{
743
+		add_filter('FHEE_load_EE_messages', '__return_true');
744
+	}
745
+
746
+
747
+	protected function _set_list_table_views_default()
748
+	{
749
+		//for notification related bulk actions we need to make sure only active messengers have an option.
750
+		EED_Messages::set_autoloaders();
751
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
752
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
753
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
754
+		//key= bulk_action_slug, value= message type.
755
+		$match_array = array(
756
+			'approve_registrations'    => 'registration',
757
+			'decline_registrations'    => 'declined_registration',
758
+			'pending_registrations'    => 'pending_approval',
759
+			'no_approve_registrations' => 'not_approved_registration',
760
+			'cancel_registrations'     => 'cancelled_registration',
761
+		);
762
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
763
+			'ee_send_message',
764
+			'batch_send_messages'
765
+		);
766
+		/** setup reg status bulk actions **/
767
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
768
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
769
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
770
+					'Approve and Notify Registrations',
771
+					'event_espresso'
772
+				);
773
+		}
774
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
775
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
776
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
777
+					'Decline and Notify Registrations',
778
+					'event_espresso'
779
+				);
780
+		}
781
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
782
+			'Set Registrations to Pending Payment',
783
+			'event_espresso'
784
+		);
785
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
786
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
787
+					'Set Registrations to Pending Payment and Notify',
788
+					'event_espresso'
789
+				);
790
+		}
791
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
792
+			'Set Registrations to Not Approved',
793
+			'event_espresso'
794
+		);
795
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
796
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
797
+					'Set Registrations to Not Approved and Notify',
798
+					'event_espresso'
799
+				);
800
+		}
801
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
802
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
803
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
804
+					'Cancel Registrations and Notify',
805
+					'event_espresso'
806
+				);
807
+		}
808
+		$def_reg_status_actions = apply_filters(
809
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
810
+			$def_reg_status_actions,
811
+			$active_mts,
812
+			$can_send
813
+		);
814
+
815
+		$this->_views = array(
816
+			'all'   => array(
817
+				'slug'        => 'all',
818
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
819
+				'count'       => 0,
820
+				'bulk_action' => array_merge($def_reg_status_actions, array(
821
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
822
+				)),
823
+			),
824
+			'month' => array(
825
+				'slug'        => 'month',
826
+				'label'       => esc_html__('This Month', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => array_merge($def_reg_status_actions, array(
829
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
+				)),
831
+			),
832
+			'today' => array(
833
+				'slug'        => 'today',
834
+				'label'       => sprintf(
835
+					esc_html__('Today - %s', 'event_espresso'),
836
+					date('M d, Y', current_time('timestamp'))
837
+				),
838
+				'count'       => 0,
839
+				'bulk_action' => array_merge($def_reg_status_actions, array(
840
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
841
+				)),
842
+			),
843
+		);
844
+		if (EE_Registry::instance()->CAP->current_user_can(
845
+			'ee_delete_registrations',
846
+			'espresso_registrations_delete_registration'
847
+		)) {
848
+			$this->_views['incomplete'] = array(
849
+				'slug'        => 'incomplete',
850
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
851
+				'count'       => 0,
852
+				'bulk_action' => array(
853
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
854
+				),
855
+			);
856
+			$this->_views['trash']      = array(
857
+				'slug'        => 'trash',
858
+				'label'       => esc_html__('Trash', 'event_espresso'),
859
+				'count'       => 0,
860
+				'bulk_action' => array(
861
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
862
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
863
+				),
864
+			);
865
+		}
866
+	}
867
+
868
+
869
+	protected function _set_list_table_views_contact_list()
870
+	{
871
+		$this->_views = array(
872
+			'in_use' => array(
873
+				'slug'        => 'in_use',
874
+				'label'       => esc_html__('In Use', 'event_espresso'),
875
+				'count'       => 0,
876
+				'bulk_action' => array(
877
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
878
+				),
879
+			),
880
+		);
881
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
882
+			'espresso_registrations_trash_attendees')
883
+		) {
884
+			$this->_views['trash'] = array(
885
+				'slug'        => 'trash',
886
+				'label'       => esc_html__('Trash', 'event_espresso'),
887
+				'count'       => 0,
888
+				'bulk_action' => array(
889
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
890
+				),
891
+			);
892
+		}
893
+	}
894
+
895
+
896
+	protected function _registration_legend_items()
897
+	{
898
+		$fc_items = array(
899
+			'star-icon'        => array(
900
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
901
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
902
+			),
903
+			'view_details'     => array(
904
+				'class' => 'dashicons dashicons-clipboard',
905
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
906
+			),
907
+			'edit_attendee'    => array(
908
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
909
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
910
+			),
911
+			'view_transaction' => array(
912
+				'class' => 'dashicons dashicons-cart',
913
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
914
+			),
915
+			'view_invoice'     => array(
916
+				'class' => 'dashicons dashicons-media-spreadsheet',
917
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
918
+			),
919
+		);
920
+		if (EE_Registry::instance()->CAP->current_user_can(
921
+			'ee_send_message',
922
+			'espresso_registrations_resend_registration'
923
+		)) {
924
+			$fc_items['resend_registration'] = array(
925
+				'class' => 'dashicons dashicons-email-alt',
926
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
927
+			);
928
+		} else {
929
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
930
+		}
931
+		if (EE_Registry::instance()->CAP->current_user_can(
932
+			'ee_read_global_messages',
933
+			'view_filtered_messages'
934
+		)) {
935
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
936
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
937
+				$fc_items['view_related_messages'] = array(
938
+					'class' => $related_for_icon['css_class'],
939
+					'desc'  => $related_for_icon['label'],
940
+				);
941
+			}
942
+		}
943
+		$sc_items = array(
944
+			'approved_status'   => array(
945
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
946
+				'desc'  => EEH_Template::pretty_status(
947
+					EEM_Registration::status_id_approved,
948
+					false,
949
+					'sentence'
950
+				),
951
+			),
952
+			'pending_status'    => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_pending_payment,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'wait_list'         => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_wait_list,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'incomplete_status' => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_incomplete,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'not_approved'      => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_not_approved,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'declined_status'   => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_declined,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+			'cancelled_status'  => array(
993
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
994
+				'desc'  => EEH_Template::pretty_status(
995
+					EEM_Registration::status_id_cancelled,
996
+					false,
997
+					'sentence'
998
+				),
999
+			),
1000
+		);
1001
+		return array_merge($fc_items, $sc_items);
1002
+	}
1003
+
1004
+
1005
+
1006
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1007
+	/**
1008
+	 * @throws \EE_Error
1009
+	 */
1010
+	protected function _registrations_overview_list_table()
1011
+	{
1012
+		$this->_template_args['admin_page_header'] = '';
1013
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1014
+			? absint($this->_req_data['event_id'])
1015
+			: 0;
1016
+		if ($EVT_ID) {
1017
+			if (EE_Registry::instance()->CAP->current_user_can(
1018
+				'ee_edit_registrations',
1019
+				'espresso_registrations_new_registration',
1020
+				$EVT_ID
1021
+			)) {
1022
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1023
+					'new_registration',
1024
+					'add-registrant',
1025
+					array('event_id' => $EVT_ID),
1026
+					'add-new-h2'
1027
+				);
1028
+			}
1029
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1030
+			if ($event instanceof EE_Event) {
1031
+				$this->_template_args['admin_page_header'] = sprintf(
1032
+					esc_html__(
1033
+						'%s Viewing registrations for the event: %s%s',
1034
+						'event_espresso'
1035
+					),
1036
+					'<h3 style="line-height:1.5em;">',
1037
+					'<br /><a href="'
1038
+						. EE_Admin_Page::add_query_args_and_nonce(
1039
+							array(
1040
+								'action' => 'edit',
1041
+								'post'   => $event->ID(),
1042
+							),
1043
+							EVENTS_ADMIN_URL
1044
+						)
1045
+						. '">&nbsp;'
1046
+						. $event->get('EVT_name')
1047
+						. '&nbsp;</a>&nbsp;',
1048
+					'</h3>'
1049
+				);
1050
+			}
1051
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1052
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1053
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1054
+				$this->_template_args['admin_page_header'] = substr(
1055
+					$this->_template_args['admin_page_header'],
1056
+					0,
1057
+					-5
1058
+				);
1059
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1060
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1061
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1062
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1063
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1064
+			}
1065
+		}
1066
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1067
+		$this->display_admin_list_table_page_with_no_sidebar();
1068
+	}
1069
+
1070
+
1071
+	/**
1072
+	 * This sets the _registration property for the registration details screen
1073
+	 *
1074
+	 * @access private
1075
+	 * @return bool
1076
+	 */
1077
+	private function _set_registration_object()
1078
+	{
1079
+		//get out if we've already set the object
1080
+		if ($this->_registration instanceof EE_Registration) {
1081
+			return true;
1082
+		}
1083
+		$REG    = EEM_Registration::instance();
1084
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1085
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1086
+			return true;
1087
+		} else {
1088
+			$error_msg = sprintf(
1089
+				esc_html__(
1090
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1091
+					'event_espresso'
1092
+				),
1093
+				$REG_ID
1094
+			);
1095
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1096
+			$this->_registration = null;
1097
+			return false;
1098
+		}
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * Used to retrieve registrations for the list table.
1104
+	 *
1105
+	 * @param int  $per_page
1106
+	 * @param bool $count
1107
+	 * @param bool $this_month
1108
+	 * @param bool $today
1109
+	 * @return EE_Registration[]|int
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	public function get_registrations(
1113
+		$per_page = 10,
1114
+		$count = false,
1115
+		$this_month = false,
1116
+		$today = false
1117
+	) {
1118
+		if ($this_month) {
1119
+			$this->_req_data['status'] = 'month';
1120
+		}
1121
+		if ($today) {
1122
+			$this->_req_data['status'] = 'today';
1123
+		}
1124
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1125
+		/**
1126
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1127
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1128
+		 * @see EEM_Base::get_all()
1129
+		 */
1130
+		$query_params['group_by'] = '';
1131
+
1132
+		return $count
1133
+			? EEM_Registration::instance()->count($query_params)
1134
+			/** @type EE_Registration[] */
1135
+			: EEM_Registration::instance()->get_all($query_params);
1136
+	}
1137
+
1138
+
1139
+
1140
+	/**
1141
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1142
+	 * Note: this listens to values on the request for some of the query parameters.
1143
+	 *
1144
+	 * @param array $request
1145
+	 * @param int    $per_page
1146
+	 * @param bool   $count
1147
+	 * @return array
1148
+	 */
1149
+	protected function _get_registration_query_parameters(
1150
+		$request = array(),
1151
+		$per_page = 10,
1152
+		$count = false
1153
+	) {
1154
+
1155
+		$query_params = array(
1156
+			0                          => $this->_get_where_conditions_for_registrations_query(
1157
+				$request
1158
+			),
1159
+			'caps'                     => EEM_Registration::caps_read_admin,
1160
+			'default_where_conditions' => 'this_model_only',
1161
+		);
1162
+		if (! $count) {
1163
+			$query_params = array_merge(
1164
+				$query_params,
1165
+				$this->_get_orderby_for_registrations_query(),
1166
+				$this->_get_limit($per_page)
1167
+			);
1168
+		}
1169
+
1170
+		return $query_params;
1171
+	}
1172
+
1173
+
1174
+	/**
1175
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1176
+	 *
1177
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1178
+	 * @return array
1179
+	 */
1180
+	protected function _add_event_id_to_where_conditions(array $request)
1181
+	{
1182
+		$where = array();
1183
+		if (! empty($request['event_id'])) {
1184
+			$where['EVT_ID'] = absint($request['event_id']);
1185
+		}
1186
+		return $where;
1187
+	}
1188
+
1189
+
1190
+	/**
1191
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1192
+	 *
1193
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1194
+	 * @return array
1195
+	 */
1196
+	protected function _add_category_id_to_where_conditions(array $request)
1197
+	{
1198
+		$where = array();
1199
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1200
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1201
+		}
1202
+		return $where;
1203
+	}
1204
+
1205
+
1206
+	/**
1207
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1208
+	 *
1209
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1210
+	 * @return array
1211
+	 */
1212
+	protected function _add_datetime_id_to_where_conditions(array $request)
1213
+	{
1214
+		$where = array();
1215
+		if (! empty($request['datetime_id'])) {
1216
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1217
+		}
1218
+		if (! empty($request['DTT_ID'])) {
1219
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1220
+		}
1221
+		return $where;
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * Adds the correct registration status to the where conditions for the registrations query.
1227
+	 *
1228
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1229
+	 * @return array
1230
+	 */
1231
+	protected function _add_registration_status_to_where_conditions(array $request)
1232
+	{
1233
+		$where = array();
1234
+		$view = EEH_Array::is_set($request, 'status', '');
1235
+		$registration_status = ! empty($request['_reg_status'])
1236
+			? sanitize_text_field($request['_reg_status'])
1237
+			: '';
1238
+
1239
+		/*
1240 1240
          * If filtering by registration status, then we show registrations matching that status.
1241 1241
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1242 1242
          * UNLESS viewing trashed registrations.
1243 1243
          */
1244
-        if (! empty($registration_status)) {
1245
-            $where['STS_ID'] = $registration_status;
1246
-        } else {
1247
-            //make sure we exclude incomplete registrations, but only if not trashed.
1248
-            if ($view === 'trash') {
1249
-                $where['REG_deleted'] = true;
1250
-            } elseif ($view === 'incomplete') {
1251
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1252
-            } else {
1253
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1254
-            }
1255
-        }
1256
-        return $where;
1257
-    }
1258
-
1259
-
1260
-    /**
1261
-     * Adds any provided date restraints to the where conditions for the registrations query.
1262
-     *
1263
-     * @param array $request usually the same as $this->_req_data but not necessarily
1264
-     * @return array
1265
-     * @throws EE_Error
1266
-     */
1267
-    protected function _add_date_to_where_conditions(array $request)
1268
-    {
1269
-        $where = array();
1270
-        $view = EEH_Array::is_set($request, 'status', '');
1271
-        $month_range             = ! empty($request['month_range'])
1272
-            ? sanitize_text_field($request['month_range'])
1273
-            : '';
1274
-        $retrieve_for_today      = $view === 'today';
1275
-        $retrieve_for_this_month = $view === 'month';
1276
-
1277
-        if ($retrieve_for_today) {
1278
-            $now               = date('Y-m-d', current_time('timestamp'));
1279
-            $where['REG_date'] = array(
1280
-                'BETWEEN',
1281
-                array(
1282
-                    EEM_Registration::instance()->convert_datetime_for_query(
1283
-                        'REG_date',
1284
-                        $now . ' 00:00:00',
1285
-                        'Y-m-d H:i:s'
1286
-                    ),
1287
-                    EEM_Registration::instance()->convert_datetime_for_query(
1288
-                        'REG_date',
1289
-                        $now . ' 23:59:59',
1290
-                        'Y-m-d H:i:s'
1291
-                    ),
1292
-                ),
1293
-            );
1294
-        } elseif ($retrieve_for_this_month) {
1295
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1296
-            $days_this_month        = date('t', current_time('timestamp'));
1297
-            $where['REG_date']      = array(
1298
-                'BETWEEN',
1299
-                array(
1300
-                    EEM_Registration::instance()->convert_datetime_for_query(
1301
-                        'REG_date',
1302
-                        $current_year_and_month . '-01 00:00:00',
1303
-                        'Y-m-d H:i:s'
1304
-                    ),
1305
-                    EEM_Registration::instance()->convert_datetime_for_query(
1306
-                        'REG_date',
1307
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1308
-                        'Y-m-d H:i:s'
1309
-                    ),
1310
-                ),
1311
-            );
1312
-        } elseif ($month_range) {
1313
-            $pieces          = explode(' ', $month_range, 3);
1314
-            $month_requested = ! empty($pieces[0])
1315
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1316
-                : '';
1317
-            $year_requested  = ! empty($pieces[1])
1318
-                ? $pieces[1]
1319
-                : '';
1320
-            //if there is not a month or year then we can't go further
1321
-            if ($month_requested && $year_requested) {
1322
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1323
-                $where['REG_date'] = array(
1324
-                    'BETWEEN',
1325
-                    array(
1326
-                        EEM_Registration::instance()->convert_datetime_for_query(
1327
-                            'REG_date',
1328
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1329
-                            'Y-m-d H:i:s'
1330
-                        ),
1331
-                        EEM_Registration::instance()->convert_datetime_for_query(
1332
-                            'REG_date',
1333
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1334
-                            'Y-m-d H:i:s'
1335
-                        ),
1336
-                    ),
1337
-                );
1338
-            }
1339
-        }
1340
-        return $where;
1341
-    }
1342
-
1343
-
1344
-    /**
1345
-     * Adds any provided search restraints to the where conditions for the registrations query
1346
-     *
1347
-     * @param array $request usually the same as $this->_req_data but not necessarily
1348
-     * @return array
1349
-     */
1350
-    protected function _add_search_to_where_conditions(array $request)
1351
-    {
1352
-        $where = array();
1353
-        if (! empty($request['s'])) {
1354
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1355
-            $where['OR*search_conditions'] = array(
1356
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1357
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1358
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1359
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1360
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1361
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1362
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1363
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1364
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1365
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1366
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1367
-                'REG_final_price'                         => array('LIKE', $search_string),
1368
-                'REG_code'                                => array('LIKE', $search_string),
1369
-                'REG_count'                               => array('LIKE', $search_string),
1370
-                'REG_group_size'                          => array('LIKE', $search_string),
1371
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1372
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1373
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1374
-            );
1375
-        }
1376
-        return $where;
1377
-    }
1378
-
1379
-
1380
-    /**
1381
-     * Sets up the where conditions for the registrations query.
1382
-     *
1383
-     * @param array $request
1384
-     * @return array
1385
-     * @throws EE_Error
1386
-     */
1387
-    protected function _get_where_conditions_for_registrations_query($request)
1388
-    {
1389
-        return apply_filters(
1390
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1391
-            array_merge(
1392
-                $this->_add_event_id_to_where_conditions($request),
1393
-                $this->_add_category_id_to_where_conditions($request),
1394
-                $this->_add_datetime_id_to_where_conditions($request),
1395
-                $this->_add_registration_status_to_where_conditions($request),
1396
-                $this->_add_date_to_where_conditions($request),
1397
-                $this->_add_search_to_where_conditions($request)
1398
-            ),
1399
-            $request
1400
-        );
1401
-    }
1402
-
1403
-
1404
-    /**
1405
-     * Sets up the orderby for the registrations query.
1406
-     *
1407
-     * @return array
1408
-     */
1409
-    protected function _get_orderby_for_registrations_query()
1410
-    {
1411
-        $orderby_field = ! empty($this->_req_data['orderby'])
1412
-            ? sanitize_text_field($this->_req_data['orderby'])
1413
-            : '';
1414
-        switch ($orderby_field) {
1415
-            case '_REG_ID':
1416
-                $orderby_field = 'REG_ID';
1417
-                break;
1418
-            case '_Reg_status':
1419
-                $orderby_field = 'STS_ID';
1420
-                break;
1421
-            case 'ATT_fname':
1422
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1423
-                break;
1424
-            case 'ATT_lname':
1425
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1426
-                break;
1427
-            case 'event_name':
1428
-                $orderby_field = 'Event.EVT_name';
1429
-                break;
1430
-            case 'DTT_EVT_start':
1431
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1432
-                break;
1433
-            default: //'REG_date'
1434
-                $orderby_field = 'REG_date';
1435
-        }
1436
-
1437
-        //order
1438
-        $order = ! empty($this->_req_data['order'])
1439
-            ? sanitize_text_field($this->_req_data['order'])
1440
-            : 'DESC';
1441
-
1442
-        //mutate orderby_field
1443
-        $orderby_field = array_combine(
1444
-            (array) $orderby_field,
1445
-            array_fill(0, count($orderby_field), $order)
1446
-        );
1447
-        //because there are many registrations with the same date, define
1448
-        //a secondary way to order them, otherwise MySQL seems to be a bit random
1449
-        if (empty($order['REG_ID'])) {
1450
-            $orderby_field['REG_ID'] = $order;
1451
-        }
1452
-        return array('order_by' => $orderby_field);
1453
-    }
1454
-
1455
-
1456
-    /**
1457
-     * Sets up the limit for the registrations query.
1458
-     *
1459
-     * @param $per_page
1460
-     * @return array
1461
-     */
1462
-    protected function _get_limit($per_page)
1463
-    {
1464
-        $current_page = ! empty($this->_req_data['paged'])
1465
-            ? absint($this->_req_data['paged'])
1466
-            : 1;
1467
-        $per_page     = ! empty($this->_req_data['perpage'])
1468
-            ? $this->_req_data['perpage']
1469
-            : $per_page;
1470
-
1471
-        //-1 means return all results so get out if that's set.
1472
-        if ((int)$per_page === -1) {
1473
-            return array();
1474
-        }
1475
-        $per_page = absint($per_page);
1476
-        $offset   = ($current_page - 1) * $per_page;
1477
-        return array('limit' => array($offset, $per_page));
1478
-    }
1479
-
1480
-
1481
-    public function get_registration_status_array()
1482
-    {
1483
-        return self::$_reg_status;
1484
-    }
1485
-
1486
-
1487
-
1488
-
1489
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1490
-    /**
1491
-     *        generates HTML for the View Registration Details Admin page
1492
-     *
1493
-     * @access protected
1494
-     * @return void
1495
-     * @throws DomainException
1496
-     * @throws EE_Error
1497
-     * @throws EntityNotFoundException
1498
-     */
1499
-    protected function _registration_details()
1500
-    {
1501
-        $this->_template_args = array();
1502
-        $this->_set_registration_object();
1503
-        if (is_object($this->_registration)) {
1504
-            $transaction                                   = $this->_registration->transaction()
1505
-                ? $this->_registration->transaction()
1506
-                : EE_Transaction::new_instance();
1507
-            $this->_session                                = $transaction->session_data();
1508
-            $event_id                                      = $this->_registration->event_ID();
1509
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1510
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1511
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1512
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1513
-            $this->_template_args['grand_total']           = $transaction->total();
1514
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1515
-            // link back to overview
1516
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1517
-            $this->_template_args['registration']                = $this->_registration;
1518
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1519
-                array(
1520
-                    'action'   => 'default',
1521
-                    'event_id' => $event_id,
1522
-                ),
1523
-                REG_ADMIN_URL
1524
-            );
1525
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1526
-                array(
1527
-                    'action' => 'default',
1528
-                    'EVT_ID' => $event_id,
1529
-                    'page'   => 'espresso_transactions',
1530
-                ),
1531
-                admin_url('admin.php')
1532
-            );
1533
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1534
-                array(
1535
-                    'page'   => 'espresso_events',
1536
-                    'action' => 'edit',
1537
-                    'post'   => $event_id,
1538
-                ),
1539
-                admin_url('admin.php')
1540
-            );
1541
-            //next and previous links
1542
-            $next_reg                                      = $this->_registration->next(
1543
-                null,
1544
-                array(),
1545
-                'REG_ID'
1546
-            );
1547
-            $this->_template_args['next_registration']     = $next_reg
1548
-                ? $this->_next_link(
1549
-                    EE_Admin_Page::add_query_args_and_nonce(
1550
-                        array(
1551
-                            'action'  => 'view_registration',
1552
-                            '_REG_ID' => $next_reg['REG_ID'],
1553
-                        ),
1554
-                        REG_ADMIN_URL
1555
-                    ),
1556
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1557
-                )
1558
-                : '';
1559
-            $previous_reg                                  = $this->_registration->previous(
1560
-                null,
1561
-                array(),
1562
-                'REG_ID'
1563
-            );
1564
-            $this->_template_args['previous_registration'] = $previous_reg
1565
-                ? $this->_previous_link(
1566
-                    EE_Admin_Page::add_query_args_and_nonce(
1567
-                        array(
1568
-                            'action'  => 'view_registration',
1569
-                            '_REG_ID' => $previous_reg['REG_ID'],
1570
-                        ),
1571
-                        REG_ADMIN_URL
1572
-                    ),
1573
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1574
-                )
1575
-                : '';
1576
-            // grab header
1577
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1578
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1579
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1580
-                $template_path,
1581
-                $this->_template_args,
1582
-                true
1583
-            );
1584
-        } else {
1585
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1586
-        }
1587
-        // the details template wrapper
1588
-        $this->display_admin_page_with_sidebar();
1589
-    }
1590
-
1591
-
1592
-    protected function _registration_details_metaboxes()
1593
-    {
1594
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1595
-        $this->_set_registration_object();
1596
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1597
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1598
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1599
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1600
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1601
-        if ($attendee instanceof EE_Attendee
1602
-            && EE_Registry::instance()->CAP->current_user_can(
1603
-                'ee_edit_registration',
1604
-                'edit-reg-questions-mbox',
1605
-                $this->_registration->ID()
1606
-            )
1607
-        ) {
1608
-            add_meta_box(
1609
-                'edit-reg-questions-mbox',
1610
-                esc_html__('Registration Form Answers', 'event_espresso'),
1611
-                array($this, '_reg_questions_meta_box'),
1612
-                $this->wp_page_slug,
1613
-                'normal',
1614
-                'high'
1615
-            );
1616
-        }
1617
-        add_meta_box(
1618
-            'edit-reg-registrant-mbox',
1619
-            esc_html__('Contact Details', 'event_espresso'),
1620
-            array($this, '_reg_registrant_side_meta_box'),
1621
-            $this->wp_page_slug,
1622
-            'side',
1623
-            'high'
1624
-        );
1625
-        if ($this->_registration->group_size() > 1) {
1626
-            add_meta_box(
1627
-                'edit-reg-attendees-mbox',
1628
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1629
-                array($this, '_reg_attendees_meta_box'),
1630
-                $this->wp_page_slug,
1631
-                'normal',
1632
-                'high'
1633
-            );
1634
-        }
1635
-    }
1636
-
1637
-
1638
-    /**
1639
-     * set_reg_status_buttons_metabox
1640
-     *
1641
-     * @access protected
1642
-     * @return string
1643
-     * @throws \EE_Error
1644
-     */
1645
-    public function set_reg_status_buttons_metabox()
1646
-    {
1647
-        $this->_set_registration_object();
1648
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1649
-        echo $change_reg_status_form->form_open(
1650
-            self::add_query_args_and_nonce(
1651
-                array(
1652
-                    'action' => 'change_reg_status',
1653
-                ),
1654
-                REG_ADMIN_URL
1655
-            )
1656
-        );
1657
-        echo $change_reg_status_form->get_html();
1658
-        echo $change_reg_status_form->form_close();
1659
-    }
1660
-
1661
-
1662
-
1663
-    /**
1664
-     * @return EE_Form_Section_Proper
1665
-     * @throws EE_Error
1666
-     */
1667
-    protected function _generate_reg_status_change_form()
1668
-    {
1669
-        return new EE_Form_Section_Proper(array(
1670
-            'name'            => 'reg_status_change_form',
1671
-            'html_id'         => 'reg-status-change-form',
1672
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1673
-            'subsections'     => array(
1674
-                'return'             => new EE_Hidden_Input(array(
1675
-                    'name'    => 'return',
1676
-                    'default' => 'view_registration',
1677
-                )),
1678
-                'REG_ID'             => new EE_Hidden_Input(array(
1679
-                    'name'    => 'REG_ID',
1680
-                    'default' => $this->_registration->ID(),
1681
-                )),
1682
-                'current_status'     => new EE_Form_Section_HTML(
1683
-                    EEH_HTML::tr(
1684
-                        EEH_HTML::th(
1685
-                            EEH_HTML::label(
1686
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1687
-                                )
1688
-                            )
1689
-                        )
1690
-                        . EEH_HTML::td(
1691
-                            EEH_HTML::strong(
1692
-                                $this->_registration->pretty_status(),
1693
-                                '',
1694
-                                'status-' . $this->_registration->status_ID(),
1695
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1696
-                            )
1697
-                        )
1698
-                    )
1699
-                ),
1700
-                'reg_status'         => new EE_Select_Input(
1701
-                    $this->_get_reg_statuses(),
1702
-                    array(
1703
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1704
-                        'default'         => $this->_registration->status_ID(),
1705
-                    )
1706
-                ),
1707
-                'send_notifications' => new EE_Yes_No_Input(
1708
-                    array(
1709
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1710
-                        'default'         => false,
1711
-                        'html_help_text'  => esc_html__(
1712
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1713
-                            'event_espresso'
1714
-                        ),
1715
-                    )
1716
-                ),
1717
-                'submit'             => new EE_Submit_Input(
1718
-                    array(
1719
-                        'html_class'      => 'button-primary',
1720
-                        'html_label_text' => '&nbsp;',
1721
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1722
-                    )
1723
-                ),
1724
-            ),
1725
-        ));
1726
-    }
1727
-
1728
-
1729
-    /**
1730
-     * Returns an array of all the buttons for the various statuses and switch status actions
1731
-     *
1732
-     * @return array
1733
-     * @throws EE_Error
1734
-     * @throws EntityNotFoundException
1735
-     */
1736
-    protected function _get_reg_statuses()
1737
-    {
1738
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1739
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1740
-        // get current reg status
1741
-        $current_status = $this->_registration->status_ID();
1742
-        // is registration for free event? This will determine whether to display the pending payment option
1743
-        if (
1744
-            $current_status !== EEM_Registration::status_id_pending_payment
1745
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1746
-        ) {
1747
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1748
-        }
1749
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1750
-    }
1751
-
1752
-
1753
-    /**
1754
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1755
-     *
1756
-     * @param bool $status REG status given for changing registrations to.
1757
-     * @param bool $notify Whether to send messages notifications or not.
1758
-     * @return array (array with reg_id(s) updated and whether update was successful.
1759
-     * @throws EE_Error
1760
-     * @throws InvalidArgumentException
1761
-     * @throws InvalidDataTypeException
1762
-     * @throws InvalidInterfaceException
1763
-     * @throws ReflectionException
1764
-     * @throws RuntimeException
1765
-     * @throws EntityNotFoundException
1766
-     */
1767
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1768
-    {
1769
-        if (isset($this->_req_data['reg_status_change_form'])) {
1770
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1771
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1772
-                : array();
1773
-        } else {
1774
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1775
-                ? (array)$this->_req_data['_REG_ID']
1776
-                : array();
1777
-        }
1778
-        // sanitize $REG_IDs
1779
-        $REG_IDs = array_map('absint', $REG_IDs);
1780
-        // and remove empty entries
1781
-        $REG_IDs = array_filter($REG_IDs);
1782
-
1783
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1784
-
1785
-        /**
1786
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1787
-         * Currently this value is used downstream by the _process_resend_registration method.
1788
-         *
1789
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1790
-         * @param bool                     $status           The status registrations were changed to.
1791
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1792
-         * @param Registrations_Admin_Page $admin_page_object
1793
-         */
1794
-        $this->_req_data['_REG_ID'] = apply_filters(
1795
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1796
-            $result['REG_ID'],
1797
-            $status,
1798
-            $result['success'],
1799
-            $this
1800
-        );
1801
-
1802
-        //notify?
1803
-        if ($notify
1804
-            && $result['success']
1805
-            && ! empty($this->_req_data['_REG_ID'])
1806
-            && EE_Registry::instance()->CAP->current_user_can(
1807
-                'ee_send_message',
1808
-                'espresso_registrations_resend_registration'
1809
-            )
1810
-        ) {
1811
-            $this->_process_resend_registration();
1812
-        }
1813
-        return $result;
1814
-    }
1815
-
1816
-
1817
-    /**
1818
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1819
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1820
-     *
1821
-     * @param array  $REG_IDs
1822
-     * @param string $status
1823
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1824
-     *                        slug sent with setting the registration status.
1825
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1826
-     * @throws EE_Error
1827
-     * @throws InvalidArgumentException
1828
-     * @throws InvalidDataTypeException
1829
-     * @throws InvalidInterfaceException
1830
-     * @throws ReflectionException
1831
-     * @throws RuntimeException
1832
-     * @throws EntityNotFoundException
1833
-     */
1834
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1835
-    {
1836
-        $success = false;
1837
-        // typecast $REG_IDs
1838
-        $REG_IDs = (array)$REG_IDs;
1839
-        if ( ! empty($REG_IDs)) {
1840
-            $success = true;
1841
-            // set default status if none is passed
1842
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1843
-            $status_context = $notify
1844
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1845
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1846
-            //loop through REG_ID's and change status
1847
-            foreach ($REG_IDs as $REG_ID) {
1848
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1849
-                if ($registration instanceof EE_Registration) {
1850
-                    $registration->set_status(
1851
-                        $status,
1852
-                        false,
1853
-                        new Context(
1854
-                            $status_context,
1855
-                            esc_html__(
1856
-                                'Manually triggered status change on a Registration Admin Page route.',
1857
-                                'event_espresso'
1858
-                            )
1859
-                        )
1860
-                    );
1861
-                    $result = $registration->save();
1862
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1863
-                    $success = $result !== false ? $success : false;
1864
-                }
1865
-            }
1866
-        }
1867
-
1868
-        //return $success and processed registrations
1869
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1870
-    }
1871
-
1872
-
1873
-    /**
1874
-     * Common logic for setting up success message and redirecting to appropriate route
1875
-     *
1876
-     * @param  string $STS_ID status id for the registration changed to
1877
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1878
-     * @return void
1879
-     */
1880
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1881
-    {
1882
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1883
-            : array('success' => false);
1884
-        $success = isset($result['success']) && $result['success'];
1885
-        //setup success message
1886
-        if ($success) {
1887
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1888
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1889
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1890
-            } else {
1891
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1892
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1893
-            }
1894
-            EE_Error::add_success($msg);
1895
-        } else {
1896
-            EE_Error::add_error(
1897
-                esc_html__(
1898
-                    'Something went wrong, and the status was not changed',
1899
-                    'event_espresso'
1900
-                ), __FILE__, __LINE__, __FUNCTION__
1901
-            );
1902
-        }
1903
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1904
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1905
-        } else {
1906
-            $route = array('action' => 'default');
1907
-        }
1908
-        //unset nonces
1909
-        foreach ($this->_req_data as $ref => $value) {
1910
-            if (strpos($ref, 'nonce') !== false) {
1911
-                unset($this->_req_data[$ref]);
1912
-                continue;
1913
-            }
1914
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1915
-            $this->_req_data[$ref] = $value;
1916
-        }
1917
-        //merge request vars so that the reloaded list table contains any existing filter query params
1918
-        $route = array_merge($this->_req_data, $route);
1919
-        $this->_redirect_after_action($success, '', '', $route, true);
1920
-    }
1921
-
1922
-
1923
-    /**
1924
-     * incoming reg status change from reg details page.
1925
-     *
1926
-     * @return void
1927
-     */
1928
-    protected function _change_reg_status()
1929
-    {
1930
-        $this->_req_data['return'] = 'view_registration';
1931
-        //set notify based on whether the send notifications toggle is set or not
1932
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1933
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1934
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1935
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1936
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1937
-            case EEM_Registration::status_id_approved :
1938
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1939
-                $this->approve_registration($notify);
1940
-                break;
1941
-            case EEM_Registration::status_id_pending_payment :
1942
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1943
-                $this->pending_registration($notify);
1944
-                break;
1945
-            case EEM_Registration::status_id_not_approved :
1946
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1947
-                $this->not_approve_registration($notify);
1948
-                break;
1949
-            case EEM_Registration::status_id_declined :
1950
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1951
-                $this->decline_registration($notify);
1952
-                break;
1953
-            case EEM_Registration::status_id_cancelled :
1954
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1955
-                $this->cancel_registration($notify);
1956
-                break;
1957
-            case EEM_Registration::status_id_wait_list :
1958
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1959
-                $this->wait_list_registration($notify);
1960
-                break;
1961
-            case EEM_Registration::status_id_incomplete :
1962
-            default :
1963
-                $result['success'] = false;
1964
-                unset($this->_req_data['return']);
1965
-                $this->_reg_status_change_return('', false);
1966
-                break;
1967
-        }
1968
-    }
1969
-
1970
-
1971
-    /**
1972
-     * Callback for bulk action routes.
1973
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1974
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1975
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1976
-     * when an action is happening on just a single registration).
1977
-     * @param      $action
1978
-     * @param bool $notify
1979
-     */
1980
-    protected function bulk_action_on_registrations($action, $notify = false) {
1981
-        do_action(
1982
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1983
-            $this,
1984
-            $action,
1985
-            $notify
1986
-        );
1987
-        $method = $action . '_registration';
1988
-        if (method_exists($this, $method)) {
1989
-            $this->$method($notify);
1990
-        }
1991
-    }
1992
-
1993
-
1994
-    /**
1995
-     * approve_registration
1996
-     *
1997
-     * @access protected
1998
-     * @param bool $notify whether or not to notify the registrant about their approval.
1999
-     * @return void
2000
-     */
2001
-    protected function approve_registration($notify = false)
2002
-    {
2003
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2004
-    }
2005
-
2006
-
2007
-    /**
2008
-     *        decline_registration
2009
-     *
2010
-     * @access protected
2011
-     * @param bool $notify whether or not to notify the registrant about their status change.
2012
-     * @return void
2013
-     */
2014
-    protected function decline_registration($notify = false)
2015
-    {
2016
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2017
-    }
2018
-
2019
-
2020
-    /**
2021
-     *        cancel_registration
2022
-     *
2023
-     * @access protected
2024
-     * @param bool $notify whether or not to notify the registrant about their status change.
2025
-     * @return void
2026
-     */
2027
-    protected function cancel_registration($notify = false)
2028
-    {
2029
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2030
-    }
2031
-
2032
-
2033
-    /**
2034
-     *        not_approve_registration
2035
-     *
2036
-     * @access protected
2037
-     * @param bool $notify whether or not to notify the registrant about their status change.
2038
-     * @return void
2039
-     */
2040
-    protected function not_approve_registration($notify = false)
2041
-    {
2042
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2043
-    }
2044
-
2045
-
2046
-    /**
2047
-     *        decline_registration
2048
-     *
2049
-     * @access protected
2050
-     * @param bool $notify whether or not to notify the registrant about their status change.
2051
-     * @return void
2052
-     */
2053
-    protected function pending_registration($notify = false)
2054
-    {
2055
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2056
-    }
2057
-
2058
-
2059
-    /**
2060
-     * waitlist_registration
2061
-     *
2062
-     * @access protected
2063
-     * @param bool $notify whether or not to notify the registrant about their status change.
2064
-     * @return void
2065
-     */
2066
-    protected function wait_list_registration($notify = false)
2067
-    {
2068
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2069
-    }
2070
-
2071
-
2072
-    /**
2073
-     *        generates HTML for the Registration main meta box
2074
-     *
2075
-     * @access public
2076
-     * @return void
2077
-     * @throws DomainException
2078
-     * @throws EE_Error
2079
-     * @throws EntityNotFoundException
2080
-     */
2081
-    public function _reg_details_meta_box()
2082
-    {
2083
-        EEH_Autoloader::register_line_item_display_autoloaders();
2084
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2085
-        EE_Registry::instance()->load_helper('Line_Item');
2086
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2087
-            : EE_Transaction::new_instance();
2088
-        $this->_session = $transaction->session_data();
2089
-        $filters        = new EE_Line_Item_Filter_Collection();
2090
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2091
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2092
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2093
-            $transaction->total_line_item());
2094
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2095
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2096
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2097
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2098
-            $filtered_line_item_tree,
2099
-            array('EE_Registration' => $this->_registration)
2100
-        );
2101
-        $attendee                                = $this->_registration->attendee();
2102
-        if (EE_Registry::instance()->CAP->current_user_can(
2103
-            'ee_read_transaction',
2104
-            'espresso_transactions_view_transaction'
2105
-        )) {
2106
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2107
-                EE_Admin_Page::add_query_args_and_nonce(
2108
-                    array(
2109
-                        'action' => 'view_transaction',
2110
-                        'TXN_ID' => $transaction->ID(),
2111
-                    ),
2112
-                    TXN_ADMIN_URL
2113
-                ),
2114
-                esc_html__(' View Transaction', 'event_espresso'),
2115
-                'button secondary-button right',
2116
-                'dashicons dashicons-cart'
2117
-            );
2118
-        } else {
2119
-            $this->_template_args['view_transaction_button'] = '';
2120
-        }
2121
-        if ($attendee instanceof EE_Attendee
2122
-            && EE_Registry::instance()->CAP->current_user_can(
2123
-                'ee_send_message',
2124
-                'espresso_registrations_resend_registration'
2125
-            )
2126
-        ) {
2127
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2128
-                EE_Admin_Page::add_query_args_and_nonce(
2129
-                    array(
2130
-                        'action'      => 'resend_registration',
2131
-                        '_REG_ID'     => $this->_registration->ID(),
2132
-                        'redirect_to' => 'view_registration',
2133
-                    ),
2134
-                    REG_ADMIN_URL
2135
-                ),
2136
-                esc_html__(' Resend Registration', 'event_espresso'),
2137
-                'button secondary-button right',
2138
-                'dashicons dashicons-email-alt'
2139
-            );
2140
-        } else {
2141
-            $this->_template_args['resend_registration_button'] = '';
2142
-        }
2143
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2144
-        $payment                               = $transaction->get_first_related('Payment');
2145
-        $payment                               = ! $payment instanceof EE_Payment
2146
-            ? EE_Payment::new_instance()
2147
-            : $payment;
2148
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2149
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2150
-            ? EE_Payment_Method::new_instance()
2151
-            : $payment_method;
2152
-        $reg_details                           = array(
2153
-            'payment_method'       => $payment_method->name(),
2154
-            'response_msg'         => $payment->gateway_response(),
2155
-            'registration_id'      => $this->_registration->get('REG_code'),
2156
-            'registration_session' => $this->_registration->session_ID(),
2157
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2158
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2159
-        );
2160
-        if (isset($reg_details['registration_id'])) {
2161
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2162
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2163
-                'Registration ID',
2164
-                'event_espresso'
2165
-            );
2166
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2167
-        }
2168
-        if (isset($reg_details['payment_method'])) {
2169
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2170
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2171
-                'Most Recent Payment Method',
2172
-                'event_espresso'
2173
-            );
2174
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2175
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2176
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2177
-                'Payment method response',
2178
-                'event_espresso'
2179
-            );
2180
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2181
-        }
2182
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2183
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2184
-            'Registration Session',
2185
-            'event_espresso'
2186
-        );
2187
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2188
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2189
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2190
-            'Registration placed from IP',
2191
-            'event_espresso'
2192
-        );
2193
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2194
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2195
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2196
-            'event_espresso');
2197
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2198
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2199
-            array(
2200
-                'action'   => 'default',
2201
-                'event_id' => $this->_registration->event_ID(),
2202
-            ),
2203
-            REG_ADMIN_URL
2204
-        );
2205
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2206
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2207
-        $template_path                                                        =
2208
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2209
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2210
-    }
2211
-
2212
-
2213
-    /**
2214
-     * generates HTML for the Registration Questions meta box.
2215
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2216
-     * otherwise uses new forms system
2217
-     *
2218
-     * @access public
2219
-     * @return void
2220
-     * @throws DomainException
2221
-     * @throws EE_Error
2222
-     */
2223
-    public function _reg_questions_meta_box()
2224
-    {
2225
-        //allow someone to override this method entirely
2226
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2227
-            $this->_registration)) {
2228
-            $form                                              = $this->_get_reg_custom_questions_form(
2229
-                $this->_registration->ID()
2230
-            );
2231
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2232
-                ? $form->get_html_and_js()
2233
-                : '';
2234
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2235
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2236
-            $template_path                                     =
2237
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2238
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2239
-        }
2240
-    }
2241
-
2242
-
2243
-    /**
2244
-     * form_before_question_group
2245
-     *
2246
-     * @deprecated    as of 4.8.32.rc.000
2247
-     * @access        public
2248
-     * @param        string $output
2249
-     * @return        string
2250
-     */
2251
-    public function form_before_question_group($output)
2252
-    {
2253
-        EE_Error::doing_it_wrong(
2254
-            __CLASS__ . '::' . __FUNCTION__,
2255
-            esc_html__(
2256
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2257
-                'event_espresso'
2258
-            ),
2259
-            '4.8.32.rc.000'
2260
-        );
2261
-        return '
1244
+		if (! empty($registration_status)) {
1245
+			$where['STS_ID'] = $registration_status;
1246
+		} else {
1247
+			//make sure we exclude incomplete registrations, but only if not trashed.
1248
+			if ($view === 'trash') {
1249
+				$where['REG_deleted'] = true;
1250
+			} elseif ($view === 'incomplete') {
1251
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1252
+			} else {
1253
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1254
+			}
1255
+		}
1256
+		return $where;
1257
+	}
1258
+
1259
+
1260
+	/**
1261
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1262
+	 *
1263
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1264
+	 * @return array
1265
+	 * @throws EE_Error
1266
+	 */
1267
+	protected function _add_date_to_where_conditions(array $request)
1268
+	{
1269
+		$where = array();
1270
+		$view = EEH_Array::is_set($request, 'status', '');
1271
+		$month_range             = ! empty($request['month_range'])
1272
+			? sanitize_text_field($request['month_range'])
1273
+			: '';
1274
+		$retrieve_for_today      = $view === 'today';
1275
+		$retrieve_for_this_month = $view === 'month';
1276
+
1277
+		if ($retrieve_for_today) {
1278
+			$now               = date('Y-m-d', current_time('timestamp'));
1279
+			$where['REG_date'] = array(
1280
+				'BETWEEN',
1281
+				array(
1282
+					EEM_Registration::instance()->convert_datetime_for_query(
1283
+						'REG_date',
1284
+						$now . ' 00:00:00',
1285
+						'Y-m-d H:i:s'
1286
+					),
1287
+					EEM_Registration::instance()->convert_datetime_for_query(
1288
+						'REG_date',
1289
+						$now . ' 23:59:59',
1290
+						'Y-m-d H:i:s'
1291
+					),
1292
+				),
1293
+			);
1294
+		} elseif ($retrieve_for_this_month) {
1295
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1296
+			$days_this_month        = date('t', current_time('timestamp'));
1297
+			$where['REG_date']      = array(
1298
+				'BETWEEN',
1299
+				array(
1300
+					EEM_Registration::instance()->convert_datetime_for_query(
1301
+						'REG_date',
1302
+						$current_year_and_month . '-01 00:00:00',
1303
+						'Y-m-d H:i:s'
1304
+					),
1305
+					EEM_Registration::instance()->convert_datetime_for_query(
1306
+						'REG_date',
1307
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1308
+						'Y-m-d H:i:s'
1309
+					),
1310
+				),
1311
+			);
1312
+		} elseif ($month_range) {
1313
+			$pieces          = explode(' ', $month_range, 3);
1314
+			$month_requested = ! empty($pieces[0])
1315
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1316
+				: '';
1317
+			$year_requested  = ! empty($pieces[1])
1318
+				? $pieces[1]
1319
+				: '';
1320
+			//if there is not a month or year then we can't go further
1321
+			if ($month_requested && $year_requested) {
1322
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1323
+				$where['REG_date'] = array(
1324
+					'BETWEEN',
1325
+					array(
1326
+						EEM_Registration::instance()->convert_datetime_for_query(
1327
+							'REG_date',
1328
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1329
+							'Y-m-d H:i:s'
1330
+						),
1331
+						EEM_Registration::instance()->convert_datetime_for_query(
1332
+							'REG_date',
1333
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1334
+							'Y-m-d H:i:s'
1335
+						),
1336
+					),
1337
+				);
1338
+			}
1339
+		}
1340
+		return $where;
1341
+	}
1342
+
1343
+
1344
+	/**
1345
+	 * Adds any provided search restraints to the where conditions for the registrations query
1346
+	 *
1347
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1348
+	 * @return array
1349
+	 */
1350
+	protected function _add_search_to_where_conditions(array $request)
1351
+	{
1352
+		$where = array();
1353
+		if (! empty($request['s'])) {
1354
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1355
+			$where['OR*search_conditions'] = array(
1356
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1357
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1358
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1359
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1360
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1361
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1362
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1363
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1364
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1365
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1366
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1367
+				'REG_final_price'                         => array('LIKE', $search_string),
1368
+				'REG_code'                                => array('LIKE', $search_string),
1369
+				'REG_count'                               => array('LIKE', $search_string),
1370
+				'REG_group_size'                          => array('LIKE', $search_string),
1371
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1372
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1373
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1374
+			);
1375
+		}
1376
+		return $where;
1377
+	}
1378
+
1379
+
1380
+	/**
1381
+	 * Sets up the where conditions for the registrations query.
1382
+	 *
1383
+	 * @param array $request
1384
+	 * @return array
1385
+	 * @throws EE_Error
1386
+	 */
1387
+	protected function _get_where_conditions_for_registrations_query($request)
1388
+	{
1389
+		return apply_filters(
1390
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1391
+			array_merge(
1392
+				$this->_add_event_id_to_where_conditions($request),
1393
+				$this->_add_category_id_to_where_conditions($request),
1394
+				$this->_add_datetime_id_to_where_conditions($request),
1395
+				$this->_add_registration_status_to_where_conditions($request),
1396
+				$this->_add_date_to_where_conditions($request),
1397
+				$this->_add_search_to_where_conditions($request)
1398
+			),
1399
+			$request
1400
+		);
1401
+	}
1402
+
1403
+
1404
+	/**
1405
+	 * Sets up the orderby for the registrations query.
1406
+	 *
1407
+	 * @return array
1408
+	 */
1409
+	protected function _get_orderby_for_registrations_query()
1410
+	{
1411
+		$orderby_field = ! empty($this->_req_data['orderby'])
1412
+			? sanitize_text_field($this->_req_data['orderby'])
1413
+			: '';
1414
+		switch ($orderby_field) {
1415
+			case '_REG_ID':
1416
+				$orderby_field = 'REG_ID';
1417
+				break;
1418
+			case '_Reg_status':
1419
+				$orderby_field = 'STS_ID';
1420
+				break;
1421
+			case 'ATT_fname':
1422
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1423
+				break;
1424
+			case 'ATT_lname':
1425
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1426
+				break;
1427
+			case 'event_name':
1428
+				$orderby_field = 'Event.EVT_name';
1429
+				break;
1430
+			case 'DTT_EVT_start':
1431
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1432
+				break;
1433
+			default: //'REG_date'
1434
+				$orderby_field = 'REG_date';
1435
+		}
1436
+
1437
+		//order
1438
+		$order = ! empty($this->_req_data['order'])
1439
+			? sanitize_text_field($this->_req_data['order'])
1440
+			: 'DESC';
1441
+
1442
+		//mutate orderby_field
1443
+		$orderby_field = array_combine(
1444
+			(array) $orderby_field,
1445
+			array_fill(0, count($orderby_field), $order)
1446
+		);
1447
+		//because there are many registrations with the same date, define
1448
+		//a secondary way to order them, otherwise MySQL seems to be a bit random
1449
+		if (empty($order['REG_ID'])) {
1450
+			$orderby_field['REG_ID'] = $order;
1451
+		}
1452
+		return array('order_by' => $orderby_field);
1453
+	}
1454
+
1455
+
1456
+	/**
1457
+	 * Sets up the limit for the registrations query.
1458
+	 *
1459
+	 * @param $per_page
1460
+	 * @return array
1461
+	 */
1462
+	protected function _get_limit($per_page)
1463
+	{
1464
+		$current_page = ! empty($this->_req_data['paged'])
1465
+			? absint($this->_req_data['paged'])
1466
+			: 1;
1467
+		$per_page     = ! empty($this->_req_data['perpage'])
1468
+			? $this->_req_data['perpage']
1469
+			: $per_page;
1470
+
1471
+		//-1 means return all results so get out if that's set.
1472
+		if ((int)$per_page === -1) {
1473
+			return array();
1474
+		}
1475
+		$per_page = absint($per_page);
1476
+		$offset   = ($current_page - 1) * $per_page;
1477
+		return array('limit' => array($offset, $per_page));
1478
+	}
1479
+
1480
+
1481
+	public function get_registration_status_array()
1482
+	{
1483
+		return self::$_reg_status;
1484
+	}
1485
+
1486
+
1487
+
1488
+
1489
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1490
+	/**
1491
+	 *        generates HTML for the View Registration Details Admin page
1492
+	 *
1493
+	 * @access protected
1494
+	 * @return void
1495
+	 * @throws DomainException
1496
+	 * @throws EE_Error
1497
+	 * @throws EntityNotFoundException
1498
+	 */
1499
+	protected function _registration_details()
1500
+	{
1501
+		$this->_template_args = array();
1502
+		$this->_set_registration_object();
1503
+		if (is_object($this->_registration)) {
1504
+			$transaction                                   = $this->_registration->transaction()
1505
+				? $this->_registration->transaction()
1506
+				: EE_Transaction::new_instance();
1507
+			$this->_session                                = $transaction->session_data();
1508
+			$event_id                                      = $this->_registration->event_ID();
1509
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1510
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1511
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1512
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1513
+			$this->_template_args['grand_total']           = $transaction->total();
1514
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1515
+			// link back to overview
1516
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1517
+			$this->_template_args['registration']                = $this->_registration;
1518
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1519
+				array(
1520
+					'action'   => 'default',
1521
+					'event_id' => $event_id,
1522
+				),
1523
+				REG_ADMIN_URL
1524
+			);
1525
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1526
+				array(
1527
+					'action' => 'default',
1528
+					'EVT_ID' => $event_id,
1529
+					'page'   => 'espresso_transactions',
1530
+				),
1531
+				admin_url('admin.php')
1532
+			);
1533
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1534
+				array(
1535
+					'page'   => 'espresso_events',
1536
+					'action' => 'edit',
1537
+					'post'   => $event_id,
1538
+				),
1539
+				admin_url('admin.php')
1540
+			);
1541
+			//next and previous links
1542
+			$next_reg                                      = $this->_registration->next(
1543
+				null,
1544
+				array(),
1545
+				'REG_ID'
1546
+			);
1547
+			$this->_template_args['next_registration']     = $next_reg
1548
+				? $this->_next_link(
1549
+					EE_Admin_Page::add_query_args_and_nonce(
1550
+						array(
1551
+							'action'  => 'view_registration',
1552
+							'_REG_ID' => $next_reg['REG_ID'],
1553
+						),
1554
+						REG_ADMIN_URL
1555
+					),
1556
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1557
+				)
1558
+				: '';
1559
+			$previous_reg                                  = $this->_registration->previous(
1560
+				null,
1561
+				array(),
1562
+				'REG_ID'
1563
+			);
1564
+			$this->_template_args['previous_registration'] = $previous_reg
1565
+				? $this->_previous_link(
1566
+					EE_Admin_Page::add_query_args_and_nonce(
1567
+						array(
1568
+							'action'  => 'view_registration',
1569
+							'_REG_ID' => $previous_reg['REG_ID'],
1570
+						),
1571
+						REG_ADMIN_URL
1572
+					),
1573
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1574
+				)
1575
+				: '';
1576
+			// grab header
1577
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1578
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1579
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1580
+				$template_path,
1581
+				$this->_template_args,
1582
+				true
1583
+			);
1584
+		} else {
1585
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1586
+		}
1587
+		// the details template wrapper
1588
+		$this->display_admin_page_with_sidebar();
1589
+	}
1590
+
1591
+
1592
+	protected function _registration_details_metaboxes()
1593
+	{
1594
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1595
+		$this->_set_registration_object();
1596
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1597
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1598
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1599
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1600
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1601
+		if ($attendee instanceof EE_Attendee
1602
+			&& EE_Registry::instance()->CAP->current_user_can(
1603
+				'ee_edit_registration',
1604
+				'edit-reg-questions-mbox',
1605
+				$this->_registration->ID()
1606
+			)
1607
+		) {
1608
+			add_meta_box(
1609
+				'edit-reg-questions-mbox',
1610
+				esc_html__('Registration Form Answers', 'event_espresso'),
1611
+				array($this, '_reg_questions_meta_box'),
1612
+				$this->wp_page_slug,
1613
+				'normal',
1614
+				'high'
1615
+			);
1616
+		}
1617
+		add_meta_box(
1618
+			'edit-reg-registrant-mbox',
1619
+			esc_html__('Contact Details', 'event_espresso'),
1620
+			array($this, '_reg_registrant_side_meta_box'),
1621
+			$this->wp_page_slug,
1622
+			'side',
1623
+			'high'
1624
+		);
1625
+		if ($this->_registration->group_size() > 1) {
1626
+			add_meta_box(
1627
+				'edit-reg-attendees-mbox',
1628
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1629
+				array($this, '_reg_attendees_meta_box'),
1630
+				$this->wp_page_slug,
1631
+				'normal',
1632
+				'high'
1633
+			);
1634
+		}
1635
+	}
1636
+
1637
+
1638
+	/**
1639
+	 * set_reg_status_buttons_metabox
1640
+	 *
1641
+	 * @access protected
1642
+	 * @return string
1643
+	 * @throws \EE_Error
1644
+	 */
1645
+	public function set_reg_status_buttons_metabox()
1646
+	{
1647
+		$this->_set_registration_object();
1648
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1649
+		echo $change_reg_status_form->form_open(
1650
+			self::add_query_args_and_nonce(
1651
+				array(
1652
+					'action' => 'change_reg_status',
1653
+				),
1654
+				REG_ADMIN_URL
1655
+			)
1656
+		);
1657
+		echo $change_reg_status_form->get_html();
1658
+		echo $change_reg_status_form->form_close();
1659
+	}
1660
+
1661
+
1662
+
1663
+	/**
1664
+	 * @return EE_Form_Section_Proper
1665
+	 * @throws EE_Error
1666
+	 */
1667
+	protected function _generate_reg_status_change_form()
1668
+	{
1669
+		return new EE_Form_Section_Proper(array(
1670
+			'name'            => 'reg_status_change_form',
1671
+			'html_id'         => 'reg-status-change-form',
1672
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1673
+			'subsections'     => array(
1674
+				'return'             => new EE_Hidden_Input(array(
1675
+					'name'    => 'return',
1676
+					'default' => 'view_registration',
1677
+				)),
1678
+				'REG_ID'             => new EE_Hidden_Input(array(
1679
+					'name'    => 'REG_ID',
1680
+					'default' => $this->_registration->ID(),
1681
+				)),
1682
+				'current_status'     => new EE_Form_Section_HTML(
1683
+					EEH_HTML::tr(
1684
+						EEH_HTML::th(
1685
+							EEH_HTML::label(
1686
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1687
+								)
1688
+							)
1689
+						)
1690
+						. EEH_HTML::td(
1691
+							EEH_HTML::strong(
1692
+								$this->_registration->pretty_status(),
1693
+								'',
1694
+								'status-' . $this->_registration->status_ID(),
1695
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1696
+							)
1697
+						)
1698
+					)
1699
+				),
1700
+				'reg_status'         => new EE_Select_Input(
1701
+					$this->_get_reg_statuses(),
1702
+					array(
1703
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1704
+						'default'         => $this->_registration->status_ID(),
1705
+					)
1706
+				),
1707
+				'send_notifications' => new EE_Yes_No_Input(
1708
+					array(
1709
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1710
+						'default'         => false,
1711
+						'html_help_text'  => esc_html__(
1712
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1713
+							'event_espresso'
1714
+						),
1715
+					)
1716
+				),
1717
+				'submit'             => new EE_Submit_Input(
1718
+					array(
1719
+						'html_class'      => 'button-primary',
1720
+						'html_label_text' => '&nbsp;',
1721
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1722
+					)
1723
+				),
1724
+			),
1725
+		));
1726
+	}
1727
+
1728
+
1729
+	/**
1730
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1731
+	 *
1732
+	 * @return array
1733
+	 * @throws EE_Error
1734
+	 * @throws EntityNotFoundException
1735
+	 */
1736
+	protected function _get_reg_statuses()
1737
+	{
1738
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1739
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1740
+		// get current reg status
1741
+		$current_status = $this->_registration->status_ID();
1742
+		// is registration for free event? This will determine whether to display the pending payment option
1743
+		if (
1744
+			$current_status !== EEM_Registration::status_id_pending_payment
1745
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1746
+		) {
1747
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1748
+		}
1749
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1750
+	}
1751
+
1752
+
1753
+	/**
1754
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1755
+	 *
1756
+	 * @param bool $status REG status given for changing registrations to.
1757
+	 * @param bool $notify Whether to send messages notifications or not.
1758
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1759
+	 * @throws EE_Error
1760
+	 * @throws InvalidArgumentException
1761
+	 * @throws InvalidDataTypeException
1762
+	 * @throws InvalidInterfaceException
1763
+	 * @throws ReflectionException
1764
+	 * @throws RuntimeException
1765
+	 * @throws EntityNotFoundException
1766
+	 */
1767
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1768
+	{
1769
+		if (isset($this->_req_data['reg_status_change_form'])) {
1770
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1771
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1772
+				: array();
1773
+		} else {
1774
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1775
+				? (array)$this->_req_data['_REG_ID']
1776
+				: array();
1777
+		}
1778
+		// sanitize $REG_IDs
1779
+		$REG_IDs = array_map('absint', $REG_IDs);
1780
+		// and remove empty entries
1781
+		$REG_IDs = array_filter($REG_IDs);
1782
+
1783
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1784
+
1785
+		/**
1786
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1787
+		 * Currently this value is used downstream by the _process_resend_registration method.
1788
+		 *
1789
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1790
+		 * @param bool                     $status           The status registrations were changed to.
1791
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1792
+		 * @param Registrations_Admin_Page $admin_page_object
1793
+		 */
1794
+		$this->_req_data['_REG_ID'] = apply_filters(
1795
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1796
+			$result['REG_ID'],
1797
+			$status,
1798
+			$result['success'],
1799
+			$this
1800
+		);
1801
+
1802
+		//notify?
1803
+		if ($notify
1804
+			&& $result['success']
1805
+			&& ! empty($this->_req_data['_REG_ID'])
1806
+			&& EE_Registry::instance()->CAP->current_user_can(
1807
+				'ee_send_message',
1808
+				'espresso_registrations_resend_registration'
1809
+			)
1810
+		) {
1811
+			$this->_process_resend_registration();
1812
+		}
1813
+		return $result;
1814
+	}
1815
+
1816
+
1817
+	/**
1818
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1819
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1820
+	 *
1821
+	 * @param array  $REG_IDs
1822
+	 * @param string $status
1823
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1824
+	 *                        slug sent with setting the registration status.
1825
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1826
+	 * @throws EE_Error
1827
+	 * @throws InvalidArgumentException
1828
+	 * @throws InvalidDataTypeException
1829
+	 * @throws InvalidInterfaceException
1830
+	 * @throws ReflectionException
1831
+	 * @throws RuntimeException
1832
+	 * @throws EntityNotFoundException
1833
+	 */
1834
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1835
+	{
1836
+		$success = false;
1837
+		// typecast $REG_IDs
1838
+		$REG_IDs = (array)$REG_IDs;
1839
+		if ( ! empty($REG_IDs)) {
1840
+			$success = true;
1841
+			// set default status if none is passed
1842
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1843
+			$status_context = $notify
1844
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1845
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1846
+			//loop through REG_ID's and change status
1847
+			foreach ($REG_IDs as $REG_ID) {
1848
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1849
+				if ($registration instanceof EE_Registration) {
1850
+					$registration->set_status(
1851
+						$status,
1852
+						false,
1853
+						new Context(
1854
+							$status_context,
1855
+							esc_html__(
1856
+								'Manually triggered status change on a Registration Admin Page route.',
1857
+								'event_espresso'
1858
+							)
1859
+						)
1860
+					);
1861
+					$result = $registration->save();
1862
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1863
+					$success = $result !== false ? $success : false;
1864
+				}
1865
+			}
1866
+		}
1867
+
1868
+		//return $success and processed registrations
1869
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1870
+	}
1871
+
1872
+
1873
+	/**
1874
+	 * Common logic for setting up success message and redirecting to appropriate route
1875
+	 *
1876
+	 * @param  string $STS_ID status id for the registration changed to
1877
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1878
+	 * @return void
1879
+	 */
1880
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1881
+	{
1882
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1883
+			: array('success' => false);
1884
+		$success = isset($result['success']) && $result['success'];
1885
+		//setup success message
1886
+		if ($success) {
1887
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1888
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1889
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1890
+			} else {
1891
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1892
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1893
+			}
1894
+			EE_Error::add_success($msg);
1895
+		} else {
1896
+			EE_Error::add_error(
1897
+				esc_html__(
1898
+					'Something went wrong, and the status was not changed',
1899
+					'event_espresso'
1900
+				), __FILE__, __LINE__, __FUNCTION__
1901
+			);
1902
+		}
1903
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1904
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1905
+		} else {
1906
+			$route = array('action' => 'default');
1907
+		}
1908
+		//unset nonces
1909
+		foreach ($this->_req_data as $ref => $value) {
1910
+			if (strpos($ref, 'nonce') !== false) {
1911
+				unset($this->_req_data[$ref]);
1912
+				continue;
1913
+			}
1914
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1915
+			$this->_req_data[$ref] = $value;
1916
+		}
1917
+		//merge request vars so that the reloaded list table contains any existing filter query params
1918
+		$route = array_merge($this->_req_data, $route);
1919
+		$this->_redirect_after_action($success, '', '', $route, true);
1920
+	}
1921
+
1922
+
1923
+	/**
1924
+	 * incoming reg status change from reg details page.
1925
+	 *
1926
+	 * @return void
1927
+	 */
1928
+	protected function _change_reg_status()
1929
+	{
1930
+		$this->_req_data['return'] = 'view_registration';
1931
+		//set notify based on whether the send notifications toggle is set or not
1932
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1933
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1934
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1935
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1936
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1937
+			case EEM_Registration::status_id_approved :
1938
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1939
+				$this->approve_registration($notify);
1940
+				break;
1941
+			case EEM_Registration::status_id_pending_payment :
1942
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1943
+				$this->pending_registration($notify);
1944
+				break;
1945
+			case EEM_Registration::status_id_not_approved :
1946
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1947
+				$this->not_approve_registration($notify);
1948
+				break;
1949
+			case EEM_Registration::status_id_declined :
1950
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1951
+				$this->decline_registration($notify);
1952
+				break;
1953
+			case EEM_Registration::status_id_cancelled :
1954
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1955
+				$this->cancel_registration($notify);
1956
+				break;
1957
+			case EEM_Registration::status_id_wait_list :
1958
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1959
+				$this->wait_list_registration($notify);
1960
+				break;
1961
+			case EEM_Registration::status_id_incomplete :
1962
+			default :
1963
+				$result['success'] = false;
1964
+				unset($this->_req_data['return']);
1965
+				$this->_reg_status_change_return('', false);
1966
+				break;
1967
+		}
1968
+	}
1969
+
1970
+
1971
+	/**
1972
+	 * Callback for bulk action routes.
1973
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1974
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1975
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1976
+	 * when an action is happening on just a single registration).
1977
+	 * @param      $action
1978
+	 * @param bool $notify
1979
+	 */
1980
+	protected function bulk_action_on_registrations($action, $notify = false) {
1981
+		do_action(
1982
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1983
+			$this,
1984
+			$action,
1985
+			$notify
1986
+		);
1987
+		$method = $action . '_registration';
1988
+		if (method_exists($this, $method)) {
1989
+			$this->$method($notify);
1990
+		}
1991
+	}
1992
+
1993
+
1994
+	/**
1995
+	 * approve_registration
1996
+	 *
1997
+	 * @access protected
1998
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1999
+	 * @return void
2000
+	 */
2001
+	protected function approve_registration($notify = false)
2002
+	{
2003
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2004
+	}
2005
+
2006
+
2007
+	/**
2008
+	 *        decline_registration
2009
+	 *
2010
+	 * @access protected
2011
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2012
+	 * @return void
2013
+	 */
2014
+	protected function decline_registration($notify = false)
2015
+	{
2016
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2017
+	}
2018
+
2019
+
2020
+	/**
2021
+	 *        cancel_registration
2022
+	 *
2023
+	 * @access protected
2024
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2025
+	 * @return void
2026
+	 */
2027
+	protected function cancel_registration($notify = false)
2028
+	{
2029
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2030
+	}
2031
+
2032
+
2033
+	/**
2034
+	 *        not_approve_registration
2035
+	 *
2036
+	 * @access protected
2037
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2038
+	 * @return void
2039
+	 */
2040
+	protected function not_approve_registration($notify = false)
2041
+	{
2042
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2043
+	}
2044
+
2045
+
2046
+	/**
2047
+	 *        decline_registration
2048
+	 *
2049
+	 * @access protected
2050
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2051
+	 * @return void
2052
+	 */
2053
+	protected function pending_registration($notify = false)
2054
+	{
2055
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2056
+	}
2057
+
2058
+
2059
+	/**
2060
+	 * waitlist_registration
2061
+	 *
2062
+	 * @access protected
2063
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2064
+	 * @return void
2065
+	 */
2066
+	protected function wait_list_registration($notify = false)
2067
+	{
2068
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2069
+	}
2070
+
2071
+
2072
+	/**
2073
+	 *        generates HTML for the Registration main meta box
2074
+	 *
2075
+	 * @access public
2076
+	 * @return void
2077
+	 * @throws DomainException
2078
+	 * @throws EE_Error
2079
+	 * @throws EntityNotFoundException
2080
+	 */
2081
+	public function _reg_details_meta_box()
2082
+	{
2083
+		EEH_Autoloader::register_line_item_display_autoloaders();
2084
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2085
+		EE_Registry::instance()->load_helper('Line_Item');
2086
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2087
+			: EE_Transaction::new_instance();
2088
+		$this->_session = $transaction->session_data();
2089
+		$filters        = new EE_Line_Item_Filter_Collection();
2090
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2091
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2092
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2093
+			$transaction->total_line_item());
2094
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2095
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2096
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2097
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2098
+			$filtered_line_item_tree,
2099
+			array('EE_Registration' => $this->_registration)
2100
+		);
2101
+		$attendee                                = $this->_registration->attendee();
2102
+		if (EE_Registry::instance()->CAP->current_user_can(
2103
+			'ee_read_transaction',
2104
+			'espresso_transactions_view_transaction'
2105
+		)) {
2106
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2107
+				EE_Admin_Page::add_query_args_and_nonce(
2108
+					array(
2109
+						'action' => 'view_transaction',
2110
+						'TXN_ID' => $transaction->ID(),
2111
+					),
2112
+					TXN_ADMIN_URL
2113
+				),
2114
+				esc_html__(' View Transaction', 'event_espresso'),
2115
+				'button secondary-button right',
2116
+				'dashicons dashicons-cart'
2117
+			);
2118
+		} else {
2119
+			$this->_template_args['view_transaction_button'] = '';
2120
+		}
2121
+		if ($attendee instanceof EE_Attendee
2122
+			&& EE_Registry::instance()->CAP->current_user_can(
2123
+				'ee_send_message',
2124
+				'espresso_registrations_resend_registration'
2125
+			)
2126
+		) {
2127
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2128
+				EE_Admin_Page::add_query_args_and_nonce(
2129
+					array(
2130
+						'action'      => 'resend_registration',
2131
+						'_REG_ID'     => $this->_registration->ID(),
2132
+						'redirect_to' => 'view_registration',
2133
+					),
2134
+					REG_ADMIN_URL
2135
+				),
2136
+				esc_html__(' Resend Registration', 'event_espresso'),
2137
+				'button secondary-button right',
2138
+				'dashicons dashicons-email-alt'
2139
+			);
2140
+		} else {
2141
+			$this->_template_args['resend_registration_button'] = '';
2142
+		}
2143
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2144
+		$payment                               = $transaction->get_first_related('Payment');
2145
+		$payment                               = ! $payment instanceof EE_Payment
2146
+			? EE_Payment::new_instance()
2147
+			: $payment;
2148
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2149
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2150
+			? EE_Payment_Method::new_instance()
2151
+			: $payment_method;
2152
+		$reg_details                           = array(
2153
+			'payment_method'       => $payment_method->name(),
2154
+			'response_msg'         => $payment->gateway_response(),
2155
+			'registration_id'      => $this->_registration->get('REG_code'),
2156
+			'registration_session' => $this->_registration->session_ID(),
2157
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2158
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2159
+		);
2160
+		if (isset($reg_details['registration_id'])) {
2161
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2162
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2163
+				'Registration ID',
2164
+				'event_espresso'
2165
+			);
2166
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2167
+		}
2168
+		if (isset($reg_details['payment_method'])) {
2169
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2170
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2171
+				'Most Recent Payment Method',
2172
+				'event_espresso'
2173
+			);
2174
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2175
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2176
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2177
+				'Payment method response',
2178
+				'event_espresso'
2179
+			);
2180
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2181
+		}
2182
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2183
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2184
+			'Registration Session',
2185
+			'event_espresso'
2186
+		);
2187
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2188
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2189
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2190
+			'Registration placed from IP',
2191
+			'event_espresso'
2192
+		);
2193
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2194
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2195
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2196
+			'event_espresso');
2197
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2198
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2199
+			array(
2200
+				'action'   => 'default',
2201
+				'event_id' => $this->_registration->event_ID(),
2202
+			),
2203
+			REG_ADMIN_URL
2204
+		);
2205
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2206
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2207
+		$template_path                                                        =
2208
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2209
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2210
+	}
2211
+
2212
+
2213
+	/**
2214
+	 * generates HTML for the Registration Questions meta box.
2215
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2216
+	 * otherwise uses new forms system
2217
+	 *
2218
+	 * @access public
2219
+	 * @return void
2220
+	 * @throws DomainException
2221
+	 * @throws EE_Error
2222
+	 */
2223
+	public function _reg_questions_meta_box()
2224
+	{
2225
+		//allow someone to override this method entirely
2226
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2227
+			$this->_registration)) {
2228
+			$form                                              = $this->_get_reg_custom_questions_form(
2229
+				$this->_registration->ID()
2230
+			);
2231
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2232
+				? $form->get_html_and_js()
2233
+				: '';
2234
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2235
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2236
+			$template_path                                     =
2237
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2238
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2239
+		}
2240
+	}
2241
+
2242
+
2243
+	/**
2244
+	 * form_before_question_group
2245
+	 *
2246
+	 * @deprecated    as of 4.8.32.rc.000
2247
+	 * @access        public
2248
+	 * @param        string $output
2249
+	 * @return        string
2250
+	 */
2251
+	public function form_before_question_group($output)
2252
+	{
2253
+		EE_Error::doing_it_wrong(
2254
+			__CLASS__ . '::' . __FUNCTION__,
2255
+			esc_html__(
2256
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2257
+				'event_espresso'
2258
+			),
2259
+			'4.8.32.rc.000'
2260
+		);
2261
+		return '
2262 2262
 	<table class="form-table ee-width-100">
2263 2263
 		<tbody>
2264 2264
 			';
2265
-    }
2266
-
2267
-
2268
-    /**
2269
-     * form_after_question_group
2270
-     *
2271
-     * @deprecated    as of 4.8.32.rc.000
2272
-     * @access        public
2273
-     * @param        string $output
2274
-     * @return        string
2275
-     */
2276
-    public function form_after_question_group($output)
2277
-    {
2278
-        EE_Error::doing_it_wrong(
2279
-            __CLASS__ . '::' . __FUNCTION__,
2280
-            esc_html__(
2281
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2282
-                'event_espresso'
2283
-            ),
2284
-            '4.8.32.rc.000'
2285
-        );
2286
-        return '
2265
+	}
2266
+
2267
+
2268
+	/**
2269
+	 * form_after_question_group
2270
+	 *
2271
+	 * @deprecated    as of 4.8.32.rc.000
2272
+	 * @access        public
2273
+	 * @param        string $output
2274
+	 * @return        string
2275
+	 */
2276
+	public function form_after_question_group($output)
2277
+	{
2278
+		EE_Error::doing_it_wrong(
2279
+			__CLASS__ . '::' . __FUNCTION__,
2280
+			esc_html__(
2281
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2282
+				'event_espresso'
2283
+			),
2284
+			'4.8.32.rc.000'
2285
+		);
2286
+		return '
2287 2287
 			<tr class="hide-if-no-js">
2288 2288
 				<th> </th>
2289 2289
 				<td class="reg-admin-edit-attendee-question-td">
2290 2290
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2291
-               . esc_attr__('click to edit question', 'event_espresso')
2292
-               . '">
2291
+			   . esc_attr__('click to edit question', 'event_espresso')
2292
+			   . '">
2293 2293
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2294
-               . esc_html__('edit the above question group', 'event_espresso')
2295
-               . '</span>
2294
+			   . esc_html__('edit the above question group', 'event_espresso')
2295
+			   . '</span>
2296 2296
 						<div class="dashicons dashicons-edit"></div>
2297 2297
 					</a>
2298 2298
 				</td>
@@ -2300,558 +2300,558 @@  discard block
 block discarded – undo
2300 2300
 		</tbody>
2301 2301
 	</table>
2302 2302
 ';
2303
-    }
2304
-
2305
-
2306
-    /**
2307
-     * form_form_field_label_wrap
2308
-     *
2309
-     * @deprecated    as of 4.8.32.rc.000
2310
-     * @access        public
2311
-     * @param        string $label
2312
-     * @return        string
2313
-     */
2314
-    public function form_form_field_label_wrap($label)
2315
-    {
2316
-        EE_Error::doing_it_wrong(
2317
-            __CLASS__ . '::' . __FUNCTION__,
2318
-            esc_html__(
2319
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2320
-                'event_espresso'
2321
-            ),
2322
-            '4.8.32.rc.000'
2323
-        );
2324
-        return '
2303
+	}
2304
+
2305
+
2306
+	/**
2307
+	 * form_form_field_label_wrap
2308
+	 *
2309
+	 * @deprecated    as of 4.8.32.rc.000
2310
+	 * @access        public
2311
+	 * @param        string $label
2312
+	 * @return        string
2313
+	 */
2314
+	public function form_form_field_label_wrap($label)
2315
+	{
2316
+		EE_Error::doing_it_wrong(
2317
+			__CLASS__ . '::' . __FUNCTION__,
2318
+			esc_html__(
2319
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2320
+				'event_espresso'
2321
+			),
2322
+			'4.8.32.rc.000'
2323
+		);
2324
+		return '
2325 2325
 			<tr>
2326 2326
 				<th>
2327 2327
 					' . $label . '
2328 2328
 				</th>';
2329
-    }
2330
-
2331
-
2332
-    /**
2333
-     * form_form_field_input__wrap
2334
-     *
2335
-     * @deprecated    as of 4.8.32.rc.000
2336
-     * @access        public
2337
-     * @param        string $input
2338
-     * @return        string
2339
-     */
2340
-    public function form_form_field_input__wrap($input)
2341
-    {
2342
-        EE_Error::doing_it_wrong(
2343
-            __CLASS__ . '::' . __FUNCTION__,
2344
-            esc_html__(
2345
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2346
-                'event_espresso'
2347
-            ),
2348
-            '4.8.32.rc.000'
2349
-        );
2350
-        return '
2329
+	}
2330
+
2331
+
2332
+	/**
2333
+	 * form_form_field_input__wrap
2334
+	 *
2335
+	 * @deprecated    as of 4.8.32.rc.000
2336
+	 * @access        public
2337
+	 * @param        string $input
2338
+	 * @return        string
2339
+	 */
2340
+	public function form_form_field_input__wrap($input)
2341
+	{
2342
+		EE_Error::doing_it_wrong(
2343
+			__CLASS__ . '::' . __FUNCTION__,
2344
+			esc_html__(
2345
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2346
+				'event_espresso'
2347
+			),
2348
+			'4.8.32.rc.000'
2349
+		);
2350
+		return '
2351 2351
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2352 2352
 					' . $input . '
2353 2353
 				</td>
2354 2354
 			</tr>';
2355
-    }
2356
-
2357
-
2358
-    /**
2359
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2360
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2361
-     * to display the page
2362
-     *
2363
-     * @access protected
2364
-     * @return void
2365
-     * @throws EE_Error
2366
-     */
2367
-    protected function _update_attendee_registration_form()
2368
-    {
2369
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2370
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2371
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2372
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2373
-            if ($success) {
2374
-                $what  = esc_html__('Registration Form', 'event_espresso');
2375
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2376
-                    : array('action' => 'default');
2377
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2378
-            }
2379
-        }
2380
-    }
2381
-
2382
-
2383
-    /**
2384
-     * Gets the form for saving registrations custom questions (if done
2385
-     * previously retrieves the cached form object, which may have validation errors in it)
2386
-     *
2387
-     * @param int $REG_ID
2388
-     * @return EE_Registration_Custom_Questions_Form
2389
-     * @throws EE_Error
2390
-     */
2391
-    protected function _get_reg_custom_questions_form($REG_ID)
2392
-    {
2393
-        if ( ! $this->_reg_custom_questions_form) {
2394
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2395
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2396
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2397
-            );
2398
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2399
-        }
2400
-        return $this->_reg_custom_questions_form;
2401
-    }
2402
-
2403
-
2404
-    /**
2405
-     * Saves
2406
-     *
2407
-     * @access private
2408
-     * @param bool $REG_ID
2409
-     * @return bool
2410
-     * @throws EE_Error
2411
-     */
2412
-    private function _save_reg_custom_questions_form($REG_ID = false)
2413
-    {
2414
-        if ( ! $REG_ID) {
2415
-            EE_Error::add_error(
2416
-                esc_html__(
2417
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2418
-                __FILE__, __FUNCTION__, __LINE__
2419
-            );
2420
-        }
2421
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2422
-        $form->receive_form_submission($this->_req_data);
2423
-        $success = false;
2424
-        if ($form->is_valid()) {
2425
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2426
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2427
-                    $where_conditions    = array(
2428
-                        'QST_ID' => $question_id,
2429
-                        'REG_ID' => $REG_ID,
2430
-                    );
2431
-                    $possibly_new_values = array(
2432
-                        'ANS_value' => $input->normalized_value(),
2433
-                    );
2434
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2435
-                    if ($answer instanceof EE_Answer) {
2436
-                        $success = $answer->save($possibly_new_values);
2437
-                    } else {
2438
-                        //insert it then
2439
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2440
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2441
-                        $success     = $answer->save();
2442
-                    }
2443
-                }
2444
-            }
2445
-        } else {
2446
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2447
-        }
2448
-        return $success;
2449
-    }
2450
-
2451
-
2452
-    /**
2453
-     *        generates HTML for the Registration main meta box
2454
-     *
2455
-     * @access public
2456
-     * @return void
2457
-     * @throws DomainException
2458
-     * @throws EE_Error
2459
-     */
2460
-    public function _reg_attendees_meta_box()
2461
-    {
2462
-        $REG = EEM_Registration::instance();
2463
-        //get all other registrations on this transaction, and cache
2464
-        //the attendees for them so we don't have to run another query using force_join
2465
-        $registrations                           = $REG->get_all(array(
2466
-            array(
2467
-                'TXN_ID' => $this->_registration->transaction_ID(),
2468
-                'REG_ID' => array('!=', $this->_registration->ID()),
2469
-            ),
2470
-            'force_join' => array('Attendee'),
2471
-        ));
2472
-        $this->_template_args['attendees']       = array();
2473
-        $this->_template_args['attendee_notice'] = '';
2474
-        if (empty($registrations)
2475
-            || (is_array($registrations)
2476
-                && ! EEH_Array::get_one_item_from_array($registrations))
2477
-        ) {
2478
-            EE_Error::add_error(
2479
-                esc_html__(
2480
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2481
-                    'event_espresso'
2482
-                ), __FILE__, __FUNCTION__, __LINE__
2483
-            );
2484
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2485
-        } else {
2486
-            $att_nmbr = 1;
2487
-            foreach ($registrations as $registration) {
2488
-                /* @var $registration EE_Registration */
2489
-                $attendee                                                    = $registration->attendee()
2490
-                    ? $registration->attendee()
2491
-                    : EEM_Attendee::instance()
2492
-                                  ->create_default_object();
2493
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2494
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2495
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2496
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2497
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2498
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2499
-                    ', ',
2500
-                    $attendee->full_address_as_array()
2501
-                );
2502
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2503
-                    array(
2504
-                        'action' => 'edit_attendee',
2505
-                        'post'   => $attendee->ID(),
2506
-                    ),
2507
-                    REG_ADMIN_URL
2508
-                );
2509
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2510
-                $att_nmbr++;
2511
-            }
2512
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2513
-        }
2514
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2515
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2516
-    }
2517
-
2518
-
2519
-    /**
2520
-     *        generates HTML for the Edit Registration side meta box
2521
-     *
2522
-     * @access public
2523
-     * @return void
2524
-     * @throws DomainException
2525
-     * @throws EE_Error
2526
-     */
2527
-    public function _reg_registrant_side_meta_box()
2528
-    {
2529
-        /*@var $attendee EE_Attendee */
2530
-        $att_check = $this->_registration->attendee();
2531
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2532
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2533
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2534
-        //primary registration object (that way we know if we need to show create button or not)
2535
-        if ( ! $this->_registration->is_primary_registrant()) {
2536
-            $primary_registration = $this->_registration->get_primary_registration();
2537
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2538
-                : null;
2539
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2540
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2541
-                //custom attendee object so let's not worry about the primary reg.
2542
-                $primary_registration = null;
2543
-            }
2544
-        } else {
2545
-            $primary_registration = null;
2546
-        }
2547
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2548
-        $this->_template_args['fname']             = $attendee->fname();
2549
-        $this->_template_args['lname']             = $attendee->lname();
2550
-        $this->_template_args['email']             = $attendee->email();
2551
-        $this->_template_args['phone']             = $attendee->phone();
2552
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2553
-        //edit link
2554
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2555
-            'action' => 'edit_attendee',
2556
-            'post'   => $attendee->ID(),
2557
-        ), REG_ADMIN_URL);
2558
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2559
-        //create link
2560
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2561
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2562
-                'action'  => 'duplicate_attendee',
2563
-                '_REG_ID' => $this->_registration->ID(),
2564
-            ), REG_ADMIN_URL) : '';
2565
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2566
-        $this->_template_args['att_check']    = $att_check;
2567
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2568
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2569
-    }
2570
-
2571
-
2572
-    /**
2573
-     * trash or restore registrations
2574
-     *
2575
-     * @param  boolean $trash whether to archive or restore
2576
-     * @return void
2577
-     * @throws EE_Error
2578
-     * @throws RuntimeException
2579
-     * @access protected
2580
-     */
2581
-    protected function _trash_or_restore_registrations($trash = true)
2582
-    {
2583
-        //if empty _REG_ID then get out because there's nothing to do
2584
-        if (empty($this->_req_data['_REG_ID'])) {
2585
-            EE_Error::add_error(
2586
-                sprintf(
2587
-                    esc_html__(
2588
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2589
-                        'event_espresso'
2590
-                    ),
2591
-                    $trash ? 'trash' : 'restore'
2592
-                ),
2593
-                __FILE__, __LINE__, __FUNCTION__
2594
-            );
2595
-            $this->_redirect_after_action(false, '', '', array(), true);
2596
-        }
2597
-        $success = 0;
2598
-        $overwrite_msgs = false;
2599
-        //Checkboxes
2600
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2601
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2602
-        }
2603
-        $reg_count = count($this->_req_data['_REG_ID']);
2604
-        // cycle thru checkboxes
2605
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2606
-            /** @var EE_Registration $REG */
2607
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2608
-            $payments = $REG->registration_payments();
2609
-            if (! empty($payments)) {
2610
-                $name = $REG->attendee() instanceof EE_Attendee
2611
-                    ? $REG->attendee()->full_name()
2612
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2613
-                $overwrite_msgs = true;
2614
-                EE_Error::add_error(
2615
-                    sprintf(
2616
-                        esc_html__(
2617
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2618
-                            'event_espresso'
2619
-                        ),
2620
-                        $name
2621
-                    ),
2622
-                    __FILE__, __FUNCTION__, __LINE__
2623
-                );
2624
-                //can't trash this registration because it has payments.
2625
-                continue;
2626
-            }
2627
-            $updated = $trash ? $REG->delete() : $REG->restore();
2628
-            if ($updated) {
2629
-                $success++;
2630
-            }
2631
-        }
2632
-        $this->_redirect_after_action(
2633
-            $success === $reg_count, // were ALL registrations affected?
2634
-            $success > 1
2635
-                ? esc_html__('Registrations', 'event_espresso')
2636
-                : esc_html__('Registration', 'event_espresso'),
2637
-            $trash
2638
-                ? esc_html__('moved to the trash', 'event_espresso')
2639
-                : esc_html__('restored', 'event_espresso'),
2640
-            array('action' => 'default'),
2641
-            $overwrite_msgs
2642
-        );
2643
-    }
2644
-
2645
-
2646
-    /**
2647
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2648
-     * registration but also.
2649
-     * 1. Removing relations to EE_Attendee
2650
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2651
-     * ALSO trashed.
2652
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2653
-     * 4. Removing relationships between all tickets and the related registrations
2654
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2655
-     * 6. Deleting permanently any related Checkins.
2656
-     *
2657
-     * @return void
2658
-     * @throws EE_Error
2659
-     */
2660
-    protected function _delete_registrations()
2661
-    {
2662
-        $REG_MDL = EEM_Registration::instance();
2663
-        $success = 1;
2664
-        //Checkboxes
2665
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2666
-            // if array has more than one element than success message should be plural
2667
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2668
-            // cycle thru checkboxes
2669
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2670
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2671
-                if ( ! $REG instanceof EE_Registration) {
2672
-                    continue;
2673
-                }
2674
-                $deleted = $this->_delete_registration($REG);
2675
-                if ( ! $deleted) {
2676
-                    $success = 0;
2677
-                }
2678
-            }
2679
-        } else {
2680
-            // grab single id and delete
2681
-            $REG_ID  = $this->_req_data['_REG_ID'];
2682
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2683
-            $deleted = $this->_delete_registration($REG);
2684
-            if ( ! $deleted) {
2685
-                $success = 0;
2686
-            }
2687
-        }
2688
-        $what        = $success > 1
2689
-            ? esc_html__('Registrations', 'event_espresso')
2690
-            : esc_html__('Registration', 'event_espresso');
2691
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2692
-        $this->_redirect_after_action(
2693
-            $success,
2694
-            $what,
2695
-            $action_desc,
2696
-            array('action' => 'default'),
2697
-            true
2698
-        );
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2704
-     * models get affected.
2705
-     *
2706
-     * @param  EE_Registration $REG registration to be deleted permenantly
2707
-     * @return bool true = successful deletion, false = fail.
2708
-     * @throws EE_Error
2709
-     */
2710
-    protected function _delete_registration(EE_Registration $REG)
2711
-    {
2712
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2713
-        //registrations on the transaction that are NOT trashed.
2714
-        $TXN         = $REG->get_first_related('Transaction');
2715
-        $REGS        = $TXN->get_many_related('Registration');
2716
-        $all_trashed = true;
2717
-        foreach ($REGS as $registration) {
2718
-            if ( ! $registration->get('REG_deleted')) {
2719
-                $all_trashed = false;
2720
-            }
2721
-        }
2722
-        if ( ! $all_trashed) {
2723
-            EE_Error::add_error(
2724
-                esc_html__(
2725
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2726
-                    'event_espresso'
2727
-                ),
2728
-                __FILE__, __FUNCTION__, __LINE__
2729
-            );
2730
-            return false;
2731
-        }
2732
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2733
-        //separately from THIS one).
2734
-        foreach ($REGS as $registration) {
2735
-            //delete related answers
2736
-            $registration->delete_related_permanently('Answer');
2737
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2738
-            $attendee = $registration->get_first_related('Attendee');
2739
-            if ($attendee instanceof EE_Attendee) {
2740
-                $registration->_remove_relation_to($attendee, 'Attendee');
2741
-            }
2742
-            //now remove relationships to tickets on this registration.
2743
-            $registration->_remove_relations('Ticket');
2744
-            //now delete permanently the checkins related to this registration.
2745
-            $registration->delete_related_permanently('Checkin');
2746
-            if ($registration->ID() === $REG->ID()) {
2747
-                continue;
2748
-            } //we don't want to delete permanently the existing registration just yet.
2749
-            //remove relation to transaction for these registrations if NOT the existing registrations
2750
-            $registration->_remove_relations('Transaction');
2751
-            //delete permanently any related messages.
2752
-            $registration->delete_related_permanently('Message');
2753
-            //now delete this registration permanently
2754
-            $registration->delete_permanently();
2755
-        }
2756
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2757
-        // (the transaction and line items should be all that's left).
2758
-        // delete the line items related to the transaction for this registration.
2759
-        $TXN->delete_related_permanently('Line_Item');
2760
-        //we need to remove all the relationships on the transaction
2761
-        $TXN->delete_related_permanently('Payment');
2762
-        $TXN->delete_related_permanently('Extra_Meta');
2763
-        $TXN->delete_related_permanently('Message');
2764
-        //now we can delete this REG permanently (and the transaction of course)
2765
-        $REG->delete_related_permanently('Transaction');
2766
-        return $REG->delete_permanently();
2767
-    }
2768
-
2769
-
2770
-    /**
2771
-     *    generates HTML for the Register New Attendee Admin page
2772
-     *
2773
-     * @access private
2774
-     * @throws DomainException
2775
-     * @throws EE_Error
2776
-     */
2777
-    public function new_registration()
2778
-    {
2779
-        if ( ! $this->_set_reg_event()) {
2780
-            throw new EE_Error(
2781
-                esc_html__(
2782
-                    'Unable to continue with registering because there is no Event ID in the request',
2783
-                    'event_espresso'
2784
-                )
2785
-            );
2786
-        }
2787
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2788
-        // gotta start with a clean slate if we're not coming here via ajax
2789
-        if ( ! defined('DOING_AJAX')
2790
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2791
-        ) {
2792
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2793
-        }
2794
-        $this->_template_args['event_name'] = '';
2795
-        // event name
2796
-        if ($this->_reg_event) {
2797
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2798
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2799
-                'action' => 'edit',
2800
-                'post'   => $this->_reg_event->ID(),
2801
-            ), EVENTS_ADMIN_URL);
2802
-            $edit_event_lnk                     = '<a href="'
2803
-                                                  . $edit_event_url
2804
-                                                  . '" title="'
2805
-                                                  . esc_attr__('Edit ', 'event_espresso')
2806
-                                                  . $this->_reg_event->name()
2807
-                                                  . '">'
2808
-                                                  . esc_html__('Edit Event', 'event_espresso')
2809
-                                                  . '</a>';
2810
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2811
-                                                   . $edit_event_lnk
2812
-                                                   . '</span>';
2813
-        }
2814
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2815
-        if (defined('DOING_AJAX')) {
2816
-            $this->_return_json();
2817
-        }
2818
-        // grab header
2819
-        $template_path                              =
2820
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2821
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2822
-            $this->_template_args, true);
2823
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2824
-        // the details template wrapper
2825
-        $this->display_admin_page_with_sidebar();
2826
-    }
2827
-
2828
-
2829
-    /**
2830
-     * This returns the content for a registration step
2831
-     *
2832
-     * @access protected
2833
-     * @return string html
2834
-     * @throws DomainException
2835
-     * @throws EE_Error
2836
-     */
2837
-    protected function _get_registration_step_content()
2838
-    {
2839
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2840
-            $warning_msg = sprintf(
2841
-                esc_html__(
2842
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2843
-                    'event_espresso'
2844
-                ),
2845
-                '<br />',
2846
-                '<h3 class="important-notice">',
2847
-                '</h3>',
2848
-                '<div class="float-right">',
2849
-                '<span id="redirect_timer" class="important-notice">30</span>',
2850
-                '</div>',
2851
-                '<b>',
2852
-                '</b>'
2853
-            );
2854
-            return '
2355
+	}
2356
+
2357
+
2358
+	/**
2359
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2360
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2361
+	 * to display the page
2362
+	 *
2363
+	 * @access protected
2364
+	 * @return void
2365
+	 * @throws EE_Error
2366
+	 */
2367
+	protected function _update_attendee_registration_form()
2368
+	{
2369
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2370
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2371
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2372
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2373
+			if ($success) {
2374
+				$what  = esc_html__('Registration Form', 'event_espresso');
2375
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2376
+					: array('action' => 'default');
2377
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2378
+			}
2379
+		}
2380
+	}
2381
+
2382
+
2383
+	/**
2384
+	 * Gets the form for saving registrations custom questions (if done
2385
+	 * previously retrieves the cached form object, which may have validation errors in it)
2386
+	 *
2387
+	 * @param int $REG_ID
2388
+	 * @return EE_Registration_Custom_Questions_Form
2389
+	 * @throws EE_Error
2390
+	 */
2391
+	protected function _get_reg_custom_questions_form($REG_ID)
2392
+	{
2393
+		if ( ! $this->_reg_custom_questions_form) {
2394
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2395
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2396
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2397
+			);
2398
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2399
+		}
2400
+		return $this->_reg_custom_questions_form;
2401
+	}
2402
+
2403
+
2404
+	/**
2405
+	 * Saves
2406
+	 *
2407
+	 * @access private
2408
+	 * @param bool $REG_ID
2409
+	 * @return bool
2410
+	 * @throws EE_Error
2411
+	 */
2412
+	private function _save_reg_custom_questions_form($REG_ID = false)
2413
+	{
2414
+		if ( ! $REG_ID) {
2415
+			EE_Error::add_error(
2416
+				esc_html__(
2417
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2418
+				__FILE__, __FUNCTION__, __LINE__
2419
+			);
2420
+		}
2421
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2422
+		$form->receive_form_submission($this->_req_data);
2423
+		$success = false;
2424
+		if ($form->is_valid()) {
2425
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2426
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2427
+					$where_conditions    = array(
2428
+						'QST_ID' => $question_id,
2429
+						'REG_ID' => $REG_ID,
2430
+					);
2431
+					$possibly_new_values = array(
2432
+						'ANS_value' => $input->normalized_value(),
2433
+					);
2434
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2435
+					if ($answer instanceof EE_Answer) {
2436
+						$success = $answer->save($possibly_new_values);
2437
+					} else {
2438
+						//insert it then
2439
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2440
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2441
+						$success     = $answer->save();
2442
+					}
2443
+				}
2444
+			}
2445
+		} else {
2446
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2447
+		}
2448
+		return $success;
2449
+	}
2450
+
2451
+
2452
+	/**
2453
+	 *        generates HTML for the Registration main meta box
2454
+	 *
2455
+	 * @access public
2456
+	 * @return void
2457
+	 * @throws DomainException
2458
+	 * @throws EE_Error
2459
+	 */
2460
+	public function _reg_attendees_meta_box()
2461
+	{
2462
+		$REG = EEM_Registration::instance();
2463
+		//get all other registrations on this transaction, and cache
2464
+		//the attendees for them so we don't have to run another query using force_join
2465
+		$registrations                           = $REG->get_all(array(
2466
+			array(
2467
+				'TXN_ID' => $this->_registration->transaction_ID(),
2468
+				'REG_ID' => array('!=', $this->_registration->ID()),
2469
+			),
2470
+			'force_join' => array('Attendee'),
2471
+		));
2472
+		$this->_template_args['attendees']       = array();
2473
+		$this->_template_args['attendee_notice'] = '';
2474
+		if (empty($registrations)
2475
+			|| (is_array($registrations)
2476
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2477
+		) {
2478
+			EE_Error::add_error(
2479
+				esc_html__(
2480
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2481
+					'event_espresso'
2482
+				), __FILE__, __FUNCTION__, __LINE__
2483
+			);
2484
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2485
+		} else {
2486
+			$att_nmbr = 1;
2487
+			foreach ($registrations as $registration) {
2488
+				/* @var $registration EE_Registration */
2489
+				$attendee                                                    = $registration->attendee()
2490
+					? $registration->attendee()
2491
+					: EEM_Attendee::instance()
2492
+								  ->create_default_object();
2493
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2494
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2495
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2496
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2497
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2498
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2499
+					', ',
2500
+					$attendee->full_address_as_array()
2501
+				);
2502
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2503
+					array(
2504
+						'action' => 'edit_attendee',
2505
+						'post'   => $attendee->ID(),
2506
+					),
2507
+					REG_ADMIN_URL
2508
+				);
2509
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2510
+				$att_nmbr++;
2511
+			}
2512
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2513
+		}
2514
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2515
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2516
+	}
2517
+
2518
+
2519
+	/**
2520
+	 *        generates HTML for the Edit Registration side meta box
2521
+	 *
2522
+	 * @access public
2523
+	 * @return void
2524
+	 * @throws DomainException
2525
+	 * @throws EE_Error
2526
+	 */
2527
+	public function _reg_registrant_side_meta_box()
2528
+	{
2529
+		/*@var $attendee EE_Attendee */
2530
+		$att_check = $this->_registration->attendee();
2531
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2532
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2533
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2534
+		//primary registration object (that way we know if we need to show create button or not)
2535
+		if ( ! $this->_registration->is_primary_registrant()) {
2536
+			$primary_registration = $this->_registration->get_primary_registration();
2537
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2538
+				: null;
2539
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2540
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2541
+				//custom attendee object so let's not worry about the primary reg.
2542
+				$primary_registration = null;
2543
+			}
2544
+		} else {
2545
+			$primary_registration = null;
2546
+		}
2547
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2548
+		$this->_template_args['fname']             = $attendee->fname();
2549
+		$this->_template_args['lname']             = $attendee->lname();
2550
+		$this->_template_args['email']             = $attendee->email();
2551
+		$this->_template_args['phone']             = $attendee->phone();
2552
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2553
+		//edit link
2554
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2555
+			'action' => 'edit_attendee',
2556
+			'post'   => $attendee->ID(),
2557
+		), REG_ADMIN_URL);
2558
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2559
+		//create link
2560
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2561
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2562
+				'action'  => 'duplicate_attendee',
2563
+				'_REG_ID' => $this->_registration->ID(),
2564
+			), REG_ADMIN_URL) : '';
2565
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2566
+		$this->_template_args['att_check']    = $att_check;
2567
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2568
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2569
+	}
2570
+
2571
+
2572
+	/**
2573
+	 * trash or restore registrations
2574
+	 *
2575
+	 * @param  boolean $trash whether to archive or restore
2576
+	 * @return void
2577
+	 * @throws EE_Error
2578
+	 * @throws RuntimeException
2579
+	 * @access protected
2580
+	 */
2581
+	protected function _trash_or_restore_registrations($trash = true)
2582
+	{
2583
+		//if empty _REG_ID then get out because there's nothing to do
2584
+		if (empty($this->_req_data['_REG_ID'])) {
2585
+			EE_Error::add_error(
2586
+				sprintf(
2587
+					esc_html__(
2588
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2589
+						'event_espresso'
2590
+					),
2591
+					$trash ? 'trash' : 'restore'
2592
+				),
2593
+				__FILE__, __LINE__, __FUNCTION__
2594
+			);
2595
+			$this->_redirect_after_action(false, '', '', array(), true);
2596
+		}
2597
+		$success = 0;
2598
+		$overwrite_msgs = false;
2599
+		//Checkboxes
2600
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2601
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2602
+		}
2603
+		$reg_count = count($this->_req_data['_REG_ID']);
2604
+		// cycle thru checkboxes
2605
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2606
+			/** @var EE_Registration $REG */
2607
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2608
+			$payments = $REG->registration_payments();
2609
+			if (! empty($payments)) {
2610
+				$name = $REG->attendee() instanceof EE_Attendee
2611
+					? $REG->attendee()->full_name()
2612
+					: esc_html__('Unknown Attendee', 'event_espresso');
2613
+				$overwrite_msgs = true;
2614
+				EE_Error::add_error(
2615
+					sprintf(
2616
+						esc_html__(
2617
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2618
+							'event_espresso'
2619
+						),
2620
+						$name
2621
+					),
2622
+					__FILE__, __FUNCTION__, __LINE__
2623
+				);
2624
+				//can't trash this registration because it has payments.
2625
+				continue;
2626
+			}
2627
+			$updated = $trash ? $REG->delete() : $REG->restore();
2628
+			if ($updated) {
2629
+				$success++;
2630
+			}
2631
+		}
2632
+		$this->_redirect_after_action(
2633
+			$success === $reg_count, // were ALL registrations affected?
2634
+			$success > 1
2635
+				? esc_html__('Registrations', 'event_espresso')
2636
+				: esc_html__('Registration', 'event_espresso'),
2637
+			$trash
2638
+				? esc_html__('moved to the trash', 'event_espresso')
2639
+				: esc_html__('restored', 'event_espresso'),
2640
+			array('action' => 'default'),
2641
+			$overwrite_msgs
2642
+		);
2643
+	}
2644
+
2645
+
2646
+	/**
2647
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2648
+	 * registration but also.
2649
+	 * 1. Removing relations to EE_Attendee
2650
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2651
+	 * ALSO trashed.
2652
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2653
+	 * 4. Removing relationships between all tickets and the related registrations
2654
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2655
+	 * 6. Deleting permanently any related Checkins.
2656
+	 *
2657
+	 * @return void
2658
+	 * @throws EE_Error
2659
+	 */
2660
+	protected function _delete_registrations()
2661
+	{
2662
+		$REG_MDL = EEM_Registration::instance();
2663
+		$success = 1;
2664
+		//Checkboxes
2665
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2666
+			// if array has more than one element than success message should be plural
2667
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2668
+			// cycle thru checkboxes
2669
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2670
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2671
+				if ( ! $REG instanceof EE_Registration) {
2672
+					continue;
2673
+				}
2674
+				$deleted = $this->_delete_registration($REG);
2675
+				if ( ! $deleted) {
2676
+					$success = 0;
2677
+				}
2678
+			}
2679
+		} else {
2680
+			// grab single id and delete
2681
+			$REG_ID  = $this->_req_data['_REG_ID'];
2682
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2683
+			$deleted = $this->_delete_registration($REG);
2684
+			if ( ! $deleted) {
2685
+				$success = 0;
2686
+			}
2687
+		}
2688
+		$what        = $success > 1
2689
+			? esc_html__('Registrations', 'event_espresso')
2690
+			: esc_html__('Registration', 'event_espresso');
2691
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2692
+		$this->_redirect_after_action(
2693
+			$success,
2694
+			$what,
2695
+			$action_desc,
2696
+			array('action' => 'default'),
2697
+			true
2698
+		);
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2704
+	 * models get affected.
2705
+	 *
2706
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2707
+	 * @return bool true = successful deletion, false = fail.
2708
+	 * @throws EE_Error
2709
+	 */
2710
+	protected function _delete_registration(EE_Registration $REG)
2711
+	{
2712
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2713
+		//registrations on the transaction that are NOT trashed.
2714
+		$TXN         = $REG->get_first_related('Transaction');
2715
+		$REGS        = $TXN->get_many_related('Registration');
2716
+		$all_trashed = true;
2717
+		foreach ($REGS as $registration) {
2718
+			if ( ! $registration->get('REG_deleted')) {
2719
+				$all_trashed = false;
2720
+			}
2721
+		}
2722
+		if ( ! $all_trashed) {
2723
+			EE_Error::add_error(
2724
+				esc_html__(
2725
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2726
+					'event_espresso'
2727
+				),
2728
+				__FILE__, __FUNCTION__, __LINE__
2729
+			);
2730
+			return false;
2731
+		}
2732
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2733
+		//separately from THIS one).
2734
+		foreach ($REGS as $registration) {
2735
+			//delete related answers
2736
+			$registration->delete_related_permanently('Answer');
2737
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2738
+			$attendee = $registration->get_first_related('Attendee');
2739
+			if ($attendee instanceof EE_Attendee) {
2740
+				$registration->_remove_relation_to($attendee, 'Attendee');
2741
+			}
2742
+			//now remove relationships to tickets on this registration.
2743
+			$registration->_remove_relations('Ticket');
2744
+			//now delete permanently the checkins related to this registration.
2745
+			$registration->delete_related_permanently('Checkin');
2746
+			if ($registration->ID() === $REG->ID()) {
2747
+				continue;
2748
+			} //we don't want to delete permanently the existing registration just yet.
2749
+			//remove relation to transaction for these registrations if NOT the existing registrations
2750
+			$registration->_remove_relations('Transaction');
2751
+			//delete permanently any related messages.
2752
+			$registration->delete_related_permanently('Message');
2753
+			//now delete this registration permanently
2754
+			$registration->delete_permanently();
2755
+		}
2756
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2757
+		// (the transaction and line items should be all that's left).
2758
+		// delete the line items related to the transaction for this registration.
2759
+		$TXN->delete_related_permanently('Line_Item');
2760
+		//we need to remove all the relationships on the transaction
2761
+		$TXN->delete_related_permanently('Payment');
2762
+		$TXN->delete_related_permanently('Extra_Meta');
2763
+		$TXN->delete_related_permanently('Message');
2764
+		//now we can delete this REG permanently (and the transaction of course)
2765
+		$REG->delete_related_permanently('Transaction');
2766
+		return $REG->delete_permanently();
2767
+	}
2768
+
2769
+
2770
+	/**
2771
+	 *    generates HTML for the Register New Attendee Admin page
2772
+	 *
2773
+	 * @access private
2774
+	 * @throws DomainException
2775
+	 * @throws EE_Error
2776
+	 */
2777
+	public function new_registration()
2778
+	{
2779
+		if ( ! $this->_set_reg_event()) {
2780
+			throw new EE_Error(
2781
+				esc_html__(
2782
+					'Unable to continue with registering because there is no Event ID in the request',
2783
+					'event_espresso'
2784
+				)
2785
+			);
2786
+		}
2787
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2788
+		// gotta start with a clean slate if we're not coming here via ajax
2789
+		if ( ! defined('DOING_AJAX')
2790
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2791
+		) {
2792
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2793
+		}
2794
+		$this->_template_args['event_name'] = '';
2795
+		// event name
2796
+		if ($this->_reg_event) {
2797
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2798
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2799
+				'action' => 'edit',
2800
+				'post'   => $this->_reg_event->ID(),
2801
+			), EVENTS_ADMIN_URL);
2802
+			$edit_event_lnk                     = '<a href="'
2803
+												  . $edit_event_url
2804
+												  . '" title="'
2805
+												  . esc_attr__('Edit ', 'event_espresso')
2806
+												  . $this->_reg_event->name()
2807
+												  . '">'
2808
+												  . esc_html__('Edit Event', 'event_espresso')
2809
+												  . '</a>';
2810
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2811
+												   . $edit_event_lnk
2812
+												   . '</span>';
2813
+		}
2814
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2815
+		if (defined('DOING_AJAX')) {
2816
+			$this->_return_json();
2817
+		}
2818
+		// grab header
2819
+		$template_path                              =
2820
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2821
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2822
+			$this->_template_args, true);
2823
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2824
+		// the details template wrapper
2825
+		$this->display_admin_page_with_sidebar();
2826
+	}
2827
+
2828
+
2829
+	/**
2830
+	 * This returns the content for a registration step
2831
+	 *
2832
+	 * @access protected
2833
+	 * @return string html
2834
+	 * @throws DomainException
2835
+	 * @throws EE_Error
2836
+	 */
2837
+	protected function _get_registration_step_content()
2838
+	{
2839
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2840
+			$warning_msg = sprintf(
2841
+				esc_html__(
2842
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2843
+					'event_espresso'
2844
+				),
2845
+				'<br />',
2846
+				'<h3 class="important-notice">',
2847
+				'</h3>',
2848
+				'<div class="float-right">',
2849
+				'<span id="redirect_timer" class="important-notice">30</span>',
2850
+				'</div>',
2851
+				'<b>',
2852
+				'</b>'
2853
+			);
2854
+			return '
2855 2855
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2856 2856
 	<script >
2857 2857
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2864,792 +2864,792 @@  discard block
 block discarded – undo
2864 2864
 	        }
2865 2865
 	    }, 800 );
2866 2866
 	</script >';
2867
-        }
2868
-        $template_args = array(
2869
-            'title'                    => '',
2870
-            'content'                  => '',
2871
-            'step_button_text'         => '',
2872
-            'show_notification_toggle' => false,
2873
-        );
2874
-        //to indicate we're processing a new registration
2875
-        $hidden_fields = array(
2876
-            'processing_registration' => array(
2877
-                'type'  => 'hidden',
2878
-                'value' => 0,
2879
-            ),
2880
-            'event_id'                => array(
2881
-                'type'  => 'hidden',
2882
-                'value' => $this->_reg_event->ID(),
2883
-            ),
2884
-        );
2885
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2886
-        $cart = EE_Registry::instance()->SSN->cart();
2887
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2888
-        switch ($step) {
2889
-            case 'ticket' :
2890
-                $hidden_fields['processing_registration']['value'] = 1;
2891
-                $template_args['title']                            = esc_html__(
2892
-                    'Step One: Select the Ticket for this registration',
2893
-                    'event_espresso'
2894
-                );
2895
-                $template_args['content']                          =
2896
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2897
-                $template_args['step_button_text']                 = esc_html__(
2898
-                    'Add Tickets and Continue to Registrant Details',
2899
-                    'event_espresso'
2900
-                );
2901
-                $template_args['show_notification_toggle']         = false;
2902
-                break;
2903
-            case 'questions' :
2904
-                $hidden_fields['processing_registration']['value'] = 2;
2905
-                $template_args['title']                            = esc_html__(
2906
-                    'Step Two: Add Registrant Details for this Registration',
2907
-                    'event_espresso'
2908
-                );
2909
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2910
-                // properly by the first process_reg_step run.
2911
-                $template_args['content']                  =
2912
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2913
-                $template_args['step_button_text']         = esc_html__(
2914
-                    'Save Registration and Continue to Details',
2915
-                    'event_espresso'
2916
-                );
2917
-                $template_args['show_notification_toggle'] = true;
2918
-                break;
2919
-        }
2920
-        //we come back to the process_registration_step route.
2921
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2922
-        return EEH_Template::display_template(
2923
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2924
-            $template_args,
2925
-            true
2926
-        );
2927
-    }
2928
-
2929
-
2930
-    /**
2931
-     *        set_reg_event
2932
-     *
2933
-     * @access private
2934
-     * @return bool
2935
-     * @throws EE_Error
2936
-     */
2937
-    private function _set_reg_event()
2938
-    {
2939
-        if (is_object($this->_reg_event)) {
2940
-            return true;
2941
-        }
2942
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2943
-        if ( ! $EVT_ID) {
2944
-            return false;
2945
-        }
2946
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2947
-        return true;
2948
-    }
2949
-
2950
-
2951
-    /**
2952
-     * process_reg_step
2953
-     *
2954
-     * @access        public
2955
-     * @return string
2956
-     * @throws DomainException
2957
-     * @throws EE_Error
2958
-     * @throws RuntimeException
2959
-     */
2960
-    public function process_reg_step()
2961
-    {
2962
-        EE_System::do_not_cache();
2963
-        $this->_set_reg_event();
2964
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2965
-        EE_Registry::instance()->REQ->set('uts', time());
2966
-        //what step are we on?
2967
-        $cart = EE_Registry::instance()->SSN->cart();
2968
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2969
-        //if doing ajax then we need to verify the nonce
2970
-        if (defined('DOING_AJAX')) {
2971
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2972
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2973
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2974
-        }
2975
-        switch ($step) {
2976
-            case 'ticket' :
2977
-                //process ticket selection
2978
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2979
-                if ($success) {
2980
-                    EE_Error::add_success(
2981
-                        esc_html__(
2982
-                            'Tickets Selected. Now complete the registration.',
2983
-                            'event_espresso'
2984
-                        )
2985
-                    );
2986
-                } else {
2987
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2988
-                }
2989
-                if (defined('DOING_AJAX')) {
2990
-                    $this->new_registration(); //display next step
2991
-                } else {
2992
-                    $query_args = array(
2993
-                        'action'                  => 'new_registration',
2994
-                        'processing_registration' => 1,
2995
-                        'event_id'                => $this->_reg_event->ID(),
2996
-                        'uts'                     => time(),
2997
-                    );
2998
-                    $this->_redirect_after_action(
2999
-                        false,
3000
-                        '',
3001
-                        '',
3002
-                        $query_args,
3003
-                        true
3004
-                    );
3005
-                }
3006
-                break;
3007
-            case 'questions' :
3008
-                if (! isset(
3009
-                    $this->_req_data['txn_reg_status_change'],
3010
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
3011
-                ) {
3012
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3013
-                }
3014
-                //process registration
3015
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3016
-                if ($cart instanceof EE_Cart) {
3017
-                    $grand_total = $cart->get_cart_grand_total();
3018
-                    if ($grand_total instanceof EE_Line_Item) {
3019
-                        $grand_total->save_this_and_descendants_to_txn();
3020
-                    }
3021
-                }
3022
-                if ( ! $transaction instanceof EE_Transaction) {
3023
-                    $query_args = array(
3024
-                        'action'                  => 'new_registration',
3025
-                        'processing_registration' => 2,
3026
-                        'event_id'                => $this->_reg_event->ID(),
3027
-                        'uts'                     => time(),
3028
-                    );
3029
-                    if (defined('DOING_AJAX')) {
3030
-                        //display registration form again because there are errors (maybe validation?)
3031
-                        $this->new_registration();
3032
-                        return;
3033
-                    } else {
3034
-                        $this->_redirect_after_action(
3035
-                            false,
3036
-                            '',
3037
-                            '',
3038
-                            $query_args,
3039
-                            true
3040
-                        );
3041
-                        return;
3042
-                    }
3043
-                }
3044
-                // maybe update status, and make sure to save transaction if not done already
3045
-                if ( ! $transaction->update_status_based_on_total_paid()) {
3046
-                    $transaction->save();
3047
-                }
3048
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3049
-                $this->_req_data = array();
3050
-                $query_args      = array(
3051
-                    'action'        => 'redirect_to_txn',
3052
-                    'TXN_ID'        => $transaction->ID(),
3053
-                    'EVT_ID'        => $this->_reg_event->ID(),
3054
-                    'event_name'    => urlencode($this->_reg_event->name()),
3055
-                    'redirect_from' => 'new_registration',
3056
-                );
3057
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3058
-                break;
3059
-        }
3060
-        //what are you looking here for?  Should be nothing to do at this point.
3061
-    }
3062
-
3063
-
3064
-    /**
3065
-     * redirect_to_txn
3066
-     *
3067
-     * @access public
3068
-     * @return void
3069
-     * @throws EE_Error
3070
-     */
3071
-    public function redirect_to_txn()
3072
-    {
3073
-        EE_System::do_not_cache();
3074
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3075
-        $query_args = array(
3076
-            'action' => 'view_transaction',
3077
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3078
-            'page'   => 'espresso_transactions',
3079
-        );
3080
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3081
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3082
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3083
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3084
-        }
3085
-        EE_Error::add_success(
3086
-            esc_html__(
3087
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3088
-                'event_espresso'
3089
-            )
3090
-        );
3091
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3092
-    }
3093
-
3094
-
3095
-    /**
3096
-     *        generates HTML for the Attendee Contact List
3097
-     *
3098
-     * @access protected
3099
-     * @return void
3100
-     */
3101
-    protected function _attendee_contact_list_table()
3102
-    {
3103
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3104
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3105
-        $this->display_admin_list_table_page_with_no_sidebar();
3106
-    }
3107
-
3108
-
3109
-    /**
3110
-     *        get_attendees
3111
-     *
3112
-     * @param      $per_page
3113
-     * @param bool $count whether to return count or data.
3114
-     * @param bool $trash
3115
-     * @return array
3116
-     * @throws EE_Error
3117
-     * @access public
3118
-     */
3119
-    public function get_attendees($per_page, $count = false, $trash = false)
3120
-    {
3121
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3122
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3123
-        $ATT_MDL                    = EEM_Attendee::instance();
3124
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3125
-        switch ($this->_req_data['orderby']) {
3126
-            case 'ATT_ID':
3127
-                $orderby = 'ATT_ID';
3128
-                break;
3129
-            case 'ATT_fname':
3130
-                $orderby = 'ATT_fname';
3131
-                break;
3132
-            case 'ATT_email':
3133
-                $orderby = 'ATT_email';
3134
-                break;
3135
-            case 'ATT_city':
3136
-                $orderby = 'ATT_city';
3137
-                break;
3138
-            case 'STA_ID':
3139
-                $orderby = 'STA_ID';
3140
-                break;
3141
-            case 'CNT_ID':
3142
-                $orderby = 'CNT_ID';
3143
-                break;
3144
-            default:
3145
-                $orderby = 'ATT_lname';
3146
-        }
3147
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3148
-            ? $this->_req_data['order']
3149
-            : 'ASC';
3150
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3151
-            ? $this->_req_data['paged']
3152
-            : 1;
3153
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3154
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3155
-            ? $this->_req_data['perpage']
3156
-            : $per_page;
3157
-        $_where       = array();
3158
-        if ( ! empty($this->_req_data['s'])) {
3159
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3160
-            $_where['OR'] = array(
3161
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3162
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3163
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3164
-                'ATT_fname'                         => array('LIKE', $sstr),
3165
-                'ATT_lname'                         => array('LIKE', $sstr),
3166
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3167
-                'ATT_email'                         => array('LIKE', $sstr),
3168
-                'ATT_address'                       => array('LIKE', $sstr),
3169
-                'ATT_address2'                      => array('LIKE', $sstr),
3170
-                'ATT_city'                          => array('LIKE', $sstr),
3171
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3172
-                'State.STA_name'                    => array('LIKE', $sstr),
3173
-                'ATT_phone'                         => array('LIKE', $sstr),
3174
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3175
-                'Registration.REG_code'             => array('LIKE', $sstr),
3176
-                'Registration.REG_count'            => array('LIKE', $sstr),
3177
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3178
-            );
3179
-        }
3180
-        $offset = ($current_page - 1) * $per_page;
3181
-        $limit  = $count ? null : array($offset, $per_page);
3182
-        if ($trash) {
3183
-            $_where['status'] = array('!=', 'publish');
3184
-            $all_attendees    = $count
3185
-                ? $ATT_MDL->count(array(
3186
-                    $_where,
3187
-                    'order_by' => array($orderby => $sort),
3188
-                    'limit'    => $limit,
3189
-                ), 'ATT_ID', true)
3190
-                : $ATT_MDL->get_all(array(
3191
-                    $_where,
3192
-                    'order_by' => array($orderby => $sort),
3193
-                    'limit'    => $limit,
3194
-                ));
3195
-        } else {
3196
-            $_where['status'] = array('IN', array('publish'));
3197
-            $all_attendees    = $count
3198
-                ? $ATT_MDL->count(array(
3199
-                    $_where,
3200
-                    'order_by' => array($orderby => $sort),
3201
-                    'limit'    => $limit,
3202
-                ), 'ATT_ID', true)
3203
-                : $ATT_MDL->get_all(array(
3204
-                    $_where,
3205
-                    'order_by' => array($orderby => $sort),
3206
-                    'limit'    => $limit,
3207
-                ));
3208
-        }
3209
-        return $all_attendees;
3210
-    }
3211
-
3212
-
3213
-    /**
3214
-     * This is just taking care of resending the registration confirmation
3215
-     *
3216
-     * @access protected
3217
-     * @return void
3218
-     */
3219
-    protected function _resend_registration()
3220
-    {
3221
-        $this->_process_resend_registration();
3222
-        $query_args = isset($this->_req_data['redirect_to'])
3223
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3224
-            : array('action' => 'default');
3225
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3226
-    }
3227
-
3228
-    /**
3229
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3230
-     * to use when selecting registrations
3231
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3232
-     *                                                     the query parameters from the request
3233
-     * @return void ends the request with a redirect or download
3234
-     */
3235
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3236
-    {
3237
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3238
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3239
-                array(
3240
-                    'page'        => 'espresso_batch',
3241
-                    'batch'       => 'file',
3242
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3243
-                    'filters'     => urlencode(
3244
-                        serialize(
3245
-                            call_user_func(
3246
-                                array( $this, $method_name_for_getting_query_params ),
3247
-                                EEH_Array::is_set(
3248
-                                    $this->_req_data,
3249
-                                    'filters',
3250
-                                    array()
3251
-                                )
3252
-                            )
3253
-                        )
3254
-                ),
3255
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3256
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3257
-                'return_url'  => urlencode($this->_req_data['return_url']),
3258
-            )));
3259
-        } else {
3260
-            $new_request_args = array(
3261
-                'export' => 'report',
3262
-                'action' => 'registrations_report_for_event',
3263
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3264
-            );
3265
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3266
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3267
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3268
-                $EE_Export = EE_Export::instance($this->_req_data);
3269
-                $EE_Export->export();
3270
-            }
3271
-        }
3272
-    }
3273
-
3274
-
3275
-
3276
-    /**
3277
-     * Creates a registration report using only query parameters in the request
3278
-     * @return void
3279
-     */
3280
-    public function _registrations_report()
3281
-    {
3282
-        $this->_registrations_report_base('_get_registration_query_parameters');
3283
-    }
3284
-
3285
-
3286
-    public function _contact_list_export()
3287
-    {
3288
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3289
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3290
-            $EE_Export = EE_Export::instance($this->_req_data);
3291
-            $EE_Export->export_attendees();
3292
-        }
3293
-    }
3294
-
3295
-
3296
-    public function _contact_list_report()
3297
-    {
3298
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3299
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3300
-                'page'        => 'espresso_batch',
3301
-                'batch'       => 'file',
3302
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3303
-                'return_url'  => urlencode($this->_req_data['return_url']),
3304
-            )));
3305
-        } else {
3306
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3307
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3308
-                $EE_Export = EE_Export::instance($this->_req_data);
3309
-                $EE_Export->report_attendees();
3310
-            }
3311
-        }
3312
-    }
3313
-
3314
-
3315
-
3316
-
3317
-
3318
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3319
-    /**
3320
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3321
-     *
3322
-     * @return void
3323
-     * @throws EE_Error
3324
-     */
3325
-    protected function _duplicate_attendee()
3326
-    {
3327
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3328
-        //verify we have necessary info
3329
-        if (empty($this->_req_data['_REG_ID'])) {
3330
-            EE_Error::add_error(
3331
-                esc_html__(
3332
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3333
-                    'event_espresso'
3334
-                ), __FILE__, __LINE__, __FUNCTION__
3335
-            );
3336
-            $query_args = array('action' => $action);
3337
-            $this->_redirect_after_action('', '', '', $query_args, true);
3338
-        }
3339
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3340
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3341
-        $attendee     = $registration->attendee();
3342
-        //remove relation of existing attendee on registration
3343
-        $registration->_remove_relation_to($attendee, 'Attendee');
3344
-        //new attendee
3345
-        $new_attendee = clone $attendee;
3346
-        $new_attendee->set('ATT_ID', 0);
3347
-        $new_attendee->save();
3348
-        //add new attendee to reg
3349
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3350
-        EE_Error::add_success(
3351
-            esc_html__(
3352
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3353
-                'event_espresso'
3354
-            )
3355
-        );
3356
-        //redirect to edit page for attendee
3357
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3358
-        $this->_redirect_after_action('', '', '', $query_args, true);
3359
-    }
3360
-
3361
-
3362
-    //related to cpt routes
3363
-    protected function _insert_update_cpt_item($post_id, $post)
3364
-    {
3365
-        $success  = true;
3366
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3367
-        //for attendee updates
3368
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3369
-            //note we should only be UPDATING attendees at this point.
3370
-            $updated_fields = array(
3371
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3372
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3373
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3374
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3375
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3376
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3377
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3378
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3379
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3380
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3381
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3382
-            );
3383
-            foreach ($updated_fields as $field => $value) {
3384
-                $attendee->set($field, $value);
3385
-            }
3386
-            $success                   = $attendee->save();
3387
-            $attendee_update_callbacks = apply_filters(
3388
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3389
-                array()
3390
-            );
3391
-            foreach ($attendee_update_callbacks as $a_callback) {
3392
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3393
-                    throw new EE_Error(
3394
-                        sprintf(
3395
-                            esc_html__(
3396
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3397
-                                'event_espresso'
3398
-                            ),
3399
-                            $a_callback
3400
-                        )
3401
-                    );
3402
-                }
3403
-            }
3404
-        }
3405
-        if ($success === false) {
3406
-            EE_Error::add_error(
3407
-                esc_html__(
3408
-                    'Something went wrong with updating the meta table data for the registration.',
3409
-                    'event_espresso'
3410
-                ),
3411
-                __FILE__, __FUNCTION__, __LINE__
3412
-            );
3413
-        }
3414
-    }
3415
-
3416
-
3417
-    public function trash_cpt_item($post_id)
3418
-    {
3419
-    }
3420
-
3421
-
3422
-    public function delete_cpt_item($post_id)
3423
-    {
3424
-    }
3425
-
3426
-
3427
-    public function restore_cpt_item($post_id)
3428
-    {
3429
-    }
3430
-
3431
-
3432
-    protected function _restore_cpt_item($post_id, $revision_id)
3433
-    {
3434
-    }
3435
-
3436
-
3437
-    public function attendee_editor_metaboxes()
3438
-    {
3439
-        $this->verify_cpt_object();
3440
-        remove_meta_box(
3441
-            'postexcerpt',
3442
-            esc_html__('Excerpt', 'event_espresso'),
3443
-            'post_excerpt_meta_box',
3444
-            $this->_cpt_routes[$this->_req_action],
3445
-            'normal',
3446
-            'core'
3447
-        );
3448
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3449
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3450
-            add_meta_box(
3451
-                'postexcerpt',
3452
-                esc_html__('Short Biography', 'event_espresso'),
3453
-                'post_excerpt_meta_box',
3454
-                $this->_cpt_routes[$this->_req_action],
3455
-                'normal'
3456
-            );
3457
-        }
3458
-        if (post_type_supports('espresso_attendees', 'comments')) {
3459
-            add_meta_box(
3460
-                'commentsdiv',
3461
-                esc_html__('Notes on the Contact', 'event_espresso'),
3462
-                'post_comment_meta_box',
3463
-                $this->_cpt_routes[$this->_req_action],
3464
-                'normal',
3465
-                'core'
3466
-            );
3467
-        }
3468
-        add_meta_box(
3469
-            'attendee_contact_info',
3470
-            esc_html__('Contact Info', 'event_espresso'),
3471
-            array($this, 'attendee_contact_info'),
3472
-            $this->_cpt_routes[$this->_req_action],
3473
-            'side',
3474
-            'core'
3475
-        );
3476
-        add_meta_box(
3477
-            'attendee_details_address',
3478
-            esc_html__('Address Details', 'event_espresso'),
3479
-            array($this, 'attendee_address_details'),
3480
-            $this->_cpt_routes[$this->_req_action],
3481
-            'normal',
3482
-            'core'
3483
-        );
3484
-        add_meta_box(
3485
-            'attendee_registrations',
3486
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3487
-            array($this, 'attendee_registrations_meta_box'),
3488
-            $this->_cpt_routes[$this->_req_action],
3489
-            'normal',
3490
-            'high'
3491
-        );
3492
-    }
3493
-
3494
-
3495
-    /**
3496
-     * Metabox for attendee contact info
3497
-     *
3498
-     * @param  WP_Post $post wp post object
3499
-     * @return string attendee contact info ( and form )
3500
-     * @throws DomainException
3501
-     */
3502
-    public function attendee_contact_info($post)
3503
-    {
3504
-        //get attendee object ( should already have it )
3505
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3506
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3507
-        EEH_Template::display_template($template, $this->_template_args);
3508
-    }
3509
-
3510
-
3511
-    /**
3512
-     * Metabox for attendee details
3513
-     *
3514
-     * @param  WP_Post $post wp post object
3515
-     * @return string attendee address details (and form)
3516
-     * @throws DomainException
3517
-     */
3518
-    public function attendee_address_details($post)
3519
-    {
3520
-        //get attendee object (should already have it)
3521
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3522
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3523
-            new EE_Question_Form_Input(
3524
-                EE_Question::new_instance(
3525
-                    array(
3526
-                        'QST_ID'           => 0,
3527
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3528
-                        'QST_system'       => 'admin-state',
3529
-                    )
3530
-                ),
3531
-                EE_Answer::new_instance(
3532
-                    array(
3533
-                        'ANS_ID'    => 0,
3534
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3535
-                    )
3536
-                ),
3537
-                array(
3538
-                    'input_id'       => 'STA_ID',
3539
-                    'input_name'     => 'STA_ID',
3540
-                    'input_prefix'   => '',
3541
-                    'append_qstn_id' => false,
3542
-                )
3543
-            )
3544
-        );
3545
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3546
-            new EE_Question_Form_Input(
3547
-                EE_Question::new_instance(
3548
-                    array(
3549
-                        'QST_ID'           => 0,
3550
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3551
-                        'QST_system'       => 'admin-country',
3552
-                    )
3553
-                ),
3554
-                EE_Answer::new_instance(
3555
-                    array(
3556
-                        'ANS_ID'    => 0,
3557
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3558
-                    )
3559
-                ),
3560
-                array(
3561
-                    'input_id'       => 'CNT_ISO',
3562
-                    'input_name'     => 'CNT_ISO',
3563
-                    'input_prefix'   => '',
3564
-                    'append_qstn_id' => false,
3565
-                )
3566
-            )
3567
-        );
3568
-        $template                             =
3569
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3570
-        EEH_Template::display_template($template, $this->_template_args);
3571
-    }
3572
-
3573
-
3574
-    /**
3575
-     *        _attendee_details
3576
-     *
3577
-     * @access protected
3578
-     * @param $post
3579
-     * @return void
3580
-     * @throws DomainException
3581
-     * @throws EE_Error
3582
-     */
3583
-    public function attendee_registrations_meta_box($post)
3584
-    {
3585
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3586
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3587
-        $template                              =
3588
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3589
-        EEH_Template::display_template($template, $this->_template_args);
3590
-    }
3591
-
3592
-
3593
-    /**
3594
-     * add in the form fields for the attendee edit
3595
-     *
3596
-     * @param  WP_Post $post wp post object
3597
-     * @return string html for new form.
3598
-     * @throws DomainException
3599
-     */
3600
-    public function after_title_form_fields($post)
3601
-    {
3602
-        if ($post->post_type == 'espresso_attendees') {
3603
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3604
-            $template_args['attendee'] = $this->_cpt_model_obj;
3605
-            EEH_Template::display_template($template, $template_args);
3606
-        }
3607
-    }
3608
-
3609
-
3610
-    /**
3611
-     *        _trash_or_restore_attendee
3612
-     *
3613
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3614
-     * @return void
3615
-     * @throws EE_Error
3616
-     * @access protected
3617
-     */
3618
-    protected function _trash_or_restore_attendees($trash = true)
3619
-    {
3620
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3621
-        $ATT_MDL = EEM_Attendee::instance();
3622
-        $success = 1;
3623
-        //Checkboxes
3624
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3625
-            // if array has more than one element than success message should be plural
3626
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3627
-            // cycle thru checkboxes
3628
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3629
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3630
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3631
-                if ( ! $updated) {
3632
-                    $success = 0;
3633
-                }
3634
-            }
3635
-        } else {
3636
-            // grab single id and delete
3637
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3638
-            //get attendee
3639
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3640
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3641
-            $updated = $att->save();
3642
-            if ( ! $updated) {
3643
-                $success = 0;
3644
-            }
3645
-        }
3646
-        $what        = $success > 1
3647
-            ? esc_html__('Contacts', 'event_espresso')
3648
-            : esc_html__('Contact', 'event_espresso');
3649
-        $action_desc = $trash
3650
-            ? esc_html__('moved to the trash', 'event_espresso')
3651
-            : esc_html__('restored', 'event_espresso');
3652
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3653
-    }
2867
+		}
2868
+		$template_args = array(
2869
+			'title'                    => '',
2870
+			'content'                  => '',
2871
+			'step_button_text'         => '',
2872
+			'show_notification_toggle' => false,
2873
+		);
2874
+		//to indicate we're processing a new registration
2875
+		$hidden_fields = array(
2876
+			'processing_registration' => array(
2877
+				'type'  => 'hidden',
2878
+				'value' => 0,
2879
+			),
2880
+			'event_id'                => array(
2881
+				'type'  => 'hidden',
2882
+				'value' => $this->_reg_event->ID(),
2883
+			),
2884
+		);
2885
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2886
+		$cart = EE_Registry::instance()->SSN->cart();
2887
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2888
+		switch ($step) {
2889
+			case 'ticket' :
2890
+				$hidden_fields['processing_registration']['value'] = 1;
2891
+				$template_args['title']                            = esc_html__(
2892
+					'Step One: Select the Ticket for this registration',
2893
+					'event_espresso'
2894
+				);
2895
+				$template_args['content']                          =
2896
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2897
+				$template_args['step_button_text']                 = esc_html__(
2898
+					'Add Tickets and Continue to Registrant Details',
2899
+					'event_espresso'
2900
+				);
2901
+				$template_args['show_notification_toggle']         = false;
2902
+				break;
2903
+			case 'questions' :
2904
+				$hidden_fields['processing_registration']['value'] = 2;
2905
+				$template_args['title']                            = esc_html__(
2906
+					'Step Two: Add Registrant Details for this Registration',
2907
+					'event_espresso'
2908
+				);
2909
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2910
+				// properly by the first process_reg_step run.
2911
+				$template_args['content']                  =
2912
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2913
+				$template_args['step_button_text']         = esc_html__(
2914
+					'Save Registration and Continue to Details',
2915
+					'event_espresso'
2916
+				);
2917
+				$template_args['show_notification_toggle'] = true;
2918
+				break;
2919
+		}
2920
+		//we come back to the process_registration_step route.
2921
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2922
+		return EEH_Template::display_template(
2923
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2924
+			$template_args,
2925
+			true
2926
+		);
2927
+	}
2928
+
2929
+
2930
+	/**
2931
+	 *        set_reg_event
2932
+	 *
2933
+	 * @access private
2934
+	 * @return bool
2935
+	 * @throws EE_Error
2936
+	 */
2937
+	private function _set_reg_event()
2938
+	{
2939
+		if (is_object($this->_reg_event)) {
2940
+			return true;
2941
+		}
2942
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2943
+		if ( ! $EVT_ID) {
2944
+			return false;
2945
+		}
2946
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2947
+		return true;
2948
+	}
2949
+
2950
+
2951
+	/**
2952
+	 * process_reg_step
2953
+	 *
2954
+	 * @access        public
2955
+	 * @return string
2956
+	 * @throws DomainException
2957
+	 * @throws EE_Error
2958
+	 * @throws RuntimeException
2959
+	 */
2960
+	public function process_reg_step()
2961
+	{
2962
+		EE_System::do_not_cache();
2963
+		$this->_set_reg_event();
2964
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2965
+		EE_Registry::instance()->REQ->set('uts', time());
2966
+		//what step are we on?
2967
+		$cart = EE_Registry::instance()->SSN->cart();
2968
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2969
+		//if doing ajax then we need to verify the nonce
2970
+		if (defined('DOING_AJAX')) {
2971
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2972
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2973
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2974
+		}
2975
+		switch ($step) {
2976
+			case 'ticket' :
2977
+				//process ticket selection
2978
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2979
+				if ($success) {
2980
+					EE_Error::add_success(
2981
+						esc_html__(
2982
+							'Tickets Selected. Now complete the registration.',
2983
+							'event_espresso'
2984
+						)
2985
+					);
2986
+				} else {
2987
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2988
+				}
2989
+				if (defined('DOING_AJAX')) {
2990
+					$this->new_registration(); //display next step
2991
+				} else {
2992
+					$query_args = array(
2993
+						'action'                  => 'new_registration',
2994
+						'processing_registration' => 1,
2995
+						'event_id'                => $this->_reg_event->ID(),
2996
+						'uts'                     => time(),
2997
+					);
2998
+					$this->_redirect_after_action(
2999
+						false,
3000
+						'',
3001
+						'',
3002
+						$query_args,
3003
+						true
3004
+					);
3005
+				}
3006
+				break;
3007
+			case 'questions' :
3008
+				if (! isset(
3009
+					$this->_req_data['txn_reg_status_change'],
3010
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
3011
+				) {
3012
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3013
+				}
3014
+				//process registration
3015
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3016
+				if ($cart instanceof EE_Cart) {
3017
+					$grand_total = $cart->get_cart_grand_total();
3018
+					if ($grand_total instanceof EE_Line_Item) {
3019
+						$grand_total->save_this_and_descendants_to_txn();
3020
+					}
3021
+				}
3022
+				if ( ! $transaction instanceof EE_Transaction) {
3023
+					$query_args = array(
3024
+						'action'                  => 'new_registration',
3025
+						'processing_registration' => 2,
3026
+						'event_id'                => $this->_reg_event->ID(),
3027
+						'uts'                     => time(),
3028
+					);
3029
+					if (defined('DOING_AJAX')) {
3030
+						//display registration form again because there are errors (maybe validation?)
3031
+						$this->new_registration();
3032
+						return;
3033
+					} else {
3034
+						$this->_redirect_after_action(
3035
+							false,
3036
+							'',
3037
+							'',
3038
+							$query_args,
3039
+							true
3040
+						);
3041
+						return;
3042
+					}
3043
+				}
3044
+				// maybe update status, and make sure to save transaction if not done already
3045
+				if ( ! $transaction->update_status_based_on_total_paid()) {
3046
+					$transaction->save();
3047
+				}
3048
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3049
+				$this->_req_data = array();
3050
+				$query_args      = array(
3051
+					'action'        => 'redirect_to_txn',
3052
+					'TXN_ID'        => $transaction->ID(),
3053
+					'EVT_ID'        => $this->_reg_event->ID(),
3054
+					'event_name'    => urlencode($this->_reg_event->name()),
3055
+					'redirect_from' => 'new_registration',
3056
+				);
3057
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3058
+				break;
3059
+		}
3060
+		//what are you looking here for?  Should be nothing to do at this point.
3061
+	}
3062
+
3063
+
3064
+	/**
3065
+	 * redirect_to_txn
3066
+	 *
3067
+	 * @access public
3068
+	 * @return void
3069
+	 * @throws EE_Error
3070
+	 */
3071
+	public function redirect_to_txn()
3072
+	{
3073
+		EE_System::do_not_cache();
3074
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3075
+		$query_args = array(
3076
+			'action' => 'view_transaction',
3077
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3078
+			'page'   => 'espresso_transactions',
3079
+		);
3080
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3081
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3082
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3083
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3084
+		}
3085
+		EE_Error::add_success(
3086
+			esc_html__(
3087
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3088
+				'event_espresso'
3089
+			)
3090
+		);
3091
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3092
+	}
3093
+
3094
+
3095
+	/**
3096
+	 *        generates HTML for the Attendee Contact List
3097
+	 *
3098
+	 * @access protected
3099
+	 * @return void
3100
+	 */
3101
+	protected function _attendee_contact_list_table()
3102
+	{
3103
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3104
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3105
+		$this->display_admin_list_table_page_with_no_sidebar();
3106
+	}
3107
+
3108
+
3109
+	/**
3110
+	 *        get_attendees
3111
+	 *
3112
+	 * @param      $per_page
3113
+	 * @param bool $count whether to return count or data.
3114
+	 * @param bool $trash
3115
+	 * @return array
3116
+	 * @throws EE_Error
3117
+	 * @access public
3118
+	 */
3119
+	public function get_attendees($per_page, $count = false, $trash = false)
3120
+	{
3121
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3122
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3123
+		$ATT_MDL                    = EEM_Attendee::instance();
3124
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3125
+		switch ($this->_req_data['orderby']) {
3126
+			case 'ATT_ID':
3127
+				$orderby = 'ATT_ID';
3128
+				break;
3129
+			case 'ATT_fname':
3130
+				$orderby = 'ATT_fname';
3131
+				break;
3132
+			case 'ATT_email':
3133
+				$orderby = 'ATT_email';
3134
+				break;
3135
+			case 'ATT_city':
3136
+				$orderby = 'ATT_city';
3137
+				break;
3138
+			case 'STA_ID':
3139
+				$orderby = 'STA_ID';
3140
+				break;
3141
+			case 'CNT_ID':
3142
+				$orderby = 'CNT_ID';
3143
+				break;
3144
+			default:
3145
+				$orderby = 'ATT_lname';
3146
+		}
3147
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3148
+			? $this->_req_data['order']
3149
+			: 'ASC';
3150
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3151
+			? $this->_req_data['paged']
3152
+			: 1;
3153
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3154
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3155
+			? $this->_req_data['perpage']
3156
+			: $per_page;
3157
+		$_where       = array();
3158
+		if ( ! empty($this->_req_data['s'])) {
3159
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3160
+			$_where['OR'] = array(
3161
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3162
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3163
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3164
+				'ATT_fname'                         => array('LIKE', $sstr),
3165
+				'ATT_lname'                         => array('LIKE', $sstr),
3166
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3167
+				'ATT_email'                         => array('LIKE', $sstr),
3168
+				'ATT_address'                       => array('LIKE', $sstr),
3169
+				'ATT_address2'                      => array('LIKE', $sstr),
3170
+				'ATT_city'                          => array('LIKE', $sstr),
3171
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3172
+				'State.STA_name'                    => array('LIKE', $sstr),
3173
+				'ATT_phone'                         => array('LIKE', $sstr),
3174
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3175
+				'Registration.REG_code'             => array('LIKE', $sstr),
3176
+				'Registration.REG_count'            => array('LIKE', $sstr),
3177
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3178
+			);
3179
+		}
3180
+		$offset = ($current_page - 1) * $per_page;
3181
+		$limit  = $count ? null : array($offset, $per_page);
3182
+		if ($trash) {
3183
+			$_where['status'] = array('!=', 'publish');
3184
+			$all_attendees    = $count
3185
+				? $ATT_MDL->count(array(
3186
+					$_where,
3187
+					'order_by' => array($orderby => $sort),
3188
+					'limit'    => $limit,
3189
+				), 'ATT_ID', true)
3190
+				: $ATT_MDL->get_all(array(
3191
+					$_where,
3192
+					'order_by' => array($orderby => $sort),
3193
+					'limit'    => $limit,
3194
+				));
3195
+		} else {
3196
+			$_where['status'] = array('IN', array('publish'));
3197
+			$all_attendees    = $count
3198
+				? $ATT_MDL->count(array(
3199
+					$_where,
3200
+					'order_by' => array($orderby => $sort),
3201
+					'limit'    => $limit,
3202
+				), 'ATT_ID', true)
3203
+				: $ATT_MDL->get_all(array(
3204
+					$_where,
3205
+					'order_by' => array($orderby => $sort),
3206
+					'limit'    => $limit,
3207
+				));
3208
+		}
3209
+		return $all_attendees;
3210
+	}
3211
+
3212
+
3213
+	/**
3214
+	 * This is just taking care of resending the registration confirmation
3215
+	 *
3216
+	 * @access protected
3217
+	 * @return void
3218
+	 */
3219
+	protected function _resend_registration()
3220
+	{
3221
+		$this->_process_resend_registration();
3222
+		$query_args = isset($this->_req_data['redirect_to'])
3223
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3224
+			: array('action' => 'default');
3225
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3226
+	}
3227
+
3228
+	/**
3229
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3230
+	 * to use when selecting registrations
3231
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3232
+	 *                                                     the query parameters from the request
3233
+	 * @return void ends the request with a redirect or download
3234
+	 */
3235
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3236
+	{
3237
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3238
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3239
+				array(
3240
+					'page'        => 'espresso_batch',
3241
+					'batch'       => 'file',
3242
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3243
+					'filters'     => urlencode(
3244
+						serialize(
3245
+							call_user_func(
3246
+								array( $this, $method_name_for_getting_query_params ),
3247
+								EEH_Array::is_set(
3248
+									$this->_req_data,
3249
+									'filters',
3250
+									array()
3251
+								)
3252
+							)
3253
+						)
3254
+				),
3255
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3256
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3257
+				'return_url'  => urlencode($this->_req_data['return_url']),
3258
+			)));
3259
+		} else {
3260
+			$new_request_args = array(
3261
+				'export' => 'report',
3262
+				'action' => 'registrations_report_for_event',
3263
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3264
+			);
3265
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3266
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3267
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3268
+				$EE_Export = EE_Export::instance($this->_req_data);
3269
+				$EE_Export->export();
3270
+			}
3271
+		}
3272
+	}
3273
+
3274
+
3275
+
3276
+	/**
3277
+	 * Creates a registration report using only query parameters in the request
3278
+	 * @return void
3279
+	 */
3280
+	public function _registrations_report()
3281
+	{
3282
+		$this->_registrations_report_base('_get_registration_query_parameters');
3283
+	}
3284
+
3285
+
3286
+	public function _contact_list_export()
3287
+	{
3288
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3289
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3290
+			$EE_Export = EE_Export::instance($this->_req_data);
3291
+			$EE_Export->export_attendees();
3292
+		}
3293
+	}
3294
+
3295
+
3296
+	public function _contact_list_report()
3297
+	{
3298
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3299
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3300
+				'page'        => 'espresso_batch',
3301
+				'batch'       => 'file',
3302
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3303
+				'return_url'  => urlencode($this->_req_data['return_url']),
3304
+			)));
3305
+		} else {
3306
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3307
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3308
+				$EE_Export = EE_Export::instance($this->_req_data);
3309
+				$EE_Export->report_attendees();
3310
+			}
3311
+		}
3312
+	}
3313
+
3314
+
3315
+
3316
+
3317
+
3318
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3319
+	/**
3320
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3321
+	 *
3322
+	 * @return void
3323
+	 * @throws EE_Error
3324
+	 */
3325
+	protected function _duplicate_attendee()
3326
+	{
3327
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3328
+		//verify we have necessary info
3329
+		if (empty($this->_req_data['_REG_ID'])) {
3330
+			EE_Error::add_error(
3331
+				esc_html__(
3332
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3333
+					'event_espresso'
3334
+				), __FILE__, __LINE__, __FUNCTION__
3335
+			);
3336
+			$query_args = array('action' => $action);
3337
+			$this->_redirect_after_action('', '', '', $query_args, true);
3338
+		}
3339
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3340
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3341
+		$attendee     = $registration->attendee();
3342
+		//remove relation of existing attendee on registration
3343
+		$registration->_remove_relation_to($attendee, 'Attendee');
3344
+		//new attendee
3345
+		$new_attendee = clone $attendee;
3346
+		$new_attendee->set('ATT_ID', 0);
3347
+		$new_attendee->save();
3348
+		//add new attendee to reg
3349
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3350
+		EE_Error::add_success(
3351
+			esc_html__(
3352
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3353
+				'event_espresso'
3354
+			)
3355
+		);
3356
+		//redirect to edit page for attendee
3357
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3358
+		$this->_redirect_after_action('', '', '', $query_args, true);
3359
+	}
3360
+
3361
+
3362
+	//related to cpt routes
3363
+	protected function _insert_update_cpt_item($post_id, $post)
3364
+	{
3365
+		$success  = true;
3366
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3367
+		//for attendee updates
3368
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3369
+			//note we should only be UPDATING attendees at this point.
3370
+			$updated_fields = array(
3371
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3372
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3373
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3374
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3375
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3376
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3377
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3378
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3379
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3380
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3381
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3382
+			);
3383
+			foreach ($updated_fields as $field => $value) {
3384
+				$attendee->set($field, $value);
3385
+			}
3386
+			$success                   = $attendee->save();
3387
+			$attendee_update_callbacks = apply_filters(
3388
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3389
+				array()
3390
+			);
3391
+			foreach ($attendee_update_callbacks as $a_callback) {
3392
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3393
+					throw new EE_Error(
3394
+						sprintf(
3395
+							esc_html__(
3396
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3397
+								'event_espresso'
3398
+							),
3399
+							$a_callback
3400
+						)
3401
+					);
3402
+				}
3403
+			}
3404
+		}
3405
+		if ($success === false) {
3406
+			EE_Error::add_error(
3407
+				esc_html__(
3408
+					'Something went wrong with updating the meta table data for the registration.',
3409
+					'event_espresso'
3410
+				),
3411
+				__FILE__, __FUNCTION__, __LINE__
3412
+			);
3413
+		}
3414
+	}
3415
+
3416
+
3417
+	public function trash_cpt_item($post_id)
3418
+	{
3419
+	}
3420
+
3421
+
3422
+	public function delete_cpt_item($post_id)
3423
+	{
3424
+	}
3425
+
3426
+
3427
+	public function restore_cpt_item($post_id)
3428
+	{
3429
+	}
3430
+
3431
+
3432
+	protected function _restore_cpt_item($post_id, $revision_id)
3433
+	{
3434
+	}
3435
+
3436
+
3437
+	public function attendee_editor_metaboxes()
3438
+	{
3439
+		$this->verify_cpt_object();
3440
+		remove_meta_box(
3441
+			'postexcerpt',
3442
+			esc_html__('Excerpt', 'event_espresso'),
3443
+			'post_excerpt_meta_box',
3444
+			$this->_cpt_routes[$this->_req_action],
3445
+			'normal',
3446
+			'core'
3447
+		);
3448
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3449
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3450
+			add_meta_box(
3451
+				'postexcerpt',
3452
+				esc_html__('Short Biography', 'event_espresso'),
3453
+				'post_excerpt_meta_box',
3454
+				$this->_cpt_routes[$this->_req_action],
3455
+				'normal'
3456
+			);
3457
+		}
3458
+		if (post_type_supports('espresso_attendees', 'comments')) {
3459
+			add_meta_box(
3460
+				'commentsdiv',
3461
+				esc_html__('Notes on the Contact', 'event_espresso'),
3462
+				'post_comment_meta_box',
3463
+				$this->_cpt_routes[$this->_req_action],
3464
+				'normal',
3465
+				'core'
3466
+			);
3467
+		}
3468
+		add_meta_box(
3469
+			'attendee_contact_info',
3470
+			esc_html__('Contact Info', 'event_espresso'),
3471
+			array($this, 'attendee_contact_info'),
3472
+			$this->_cpt_routes[$this->_req_action],
3473
+			'side',
3474
+			'core'
3475
+		);
3476
+		add_meta_box(
3477
+			'attendee_details_address',
3478
+			esc_html__('Address Details', 'event_espresso'),
3479
+			array($this, 'attendee_address_details'),
3480
+			$this->_cpt_routes[$this->_req_action],
3481
+			'normal',
3482
+			'core'
3483
+		);
3484
+		add_meta_box(
3485
+			'attendee_registrations',
3486
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3487
+			array($this, 'attendee_registrations_meta_box'),
3488
+			$this->_cpt_routes[$this->_req_action],
3489
+			'normal',
3490
+			'high'
3491
+		);
3492
+	}
3493
+
3494
+
3495
+	/**
3496
+	 * Metabox for attendee contact info
3497
+	 *
3498
+	 * @param  WP_Post $post wp post object
3499
+	 * @return string attendee contact info ( and form )
3500
+	 * @throws DomainException
3501
+	 */
3502
+	public function attendee_contact_info($post)
3503
+	{
3504
+		//get attendee object ( should already have it )
3505
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3506
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3507
+		EEH_Template::display_template($template, $this->_template_args);
3508
+	}
3509
+
3510
+
3511
+	/**
3512
+	 * Metabox for attendee details
3513
+	 *
3514
+	 * @param  WP_Post $post wp post object
3515
+	 * @return string attendee address details (and form)
3516
+	 * @throws DomainException
3517
+	 */
3518
+	public function attendee_address_details($post)
3519
+	{
3520
+		//get attendee object (should already have it)
3521
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3522
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3523
+			new EE_Question_Form_Input(
3524
+				EE_Question::new_instance(
3525
+					array(
3526
+						'QST_ID'           => 0,
3527
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3528
+						'QST_system'       => 'admin-state',
3529
+					)
3530
+				),
3531
+				EE_Answer::new_instance(
3532
+					array(
3533
+						'ANS_ID'    => 0,
3534
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3535
+					)
3536
+				),
3537
+				array(
3538
+					'input_id'       => 'STA_ID',
3539
+					'input_name'     => 'STA_ID',
3540
+					'input_prefix'   => '',
3541
+					'append_qstn_id' => false,
3542
+				)
3543
+			)
3544
+		);
3545
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3546
+			new EE_Question_Form_Input(
3547
+				EE_Question::new_instance(
3548
+					array(
3549
+						'QST_ID'           => 0,
3550
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3551
+						'QST_system'       => 'admin-country',
3552
+					)
3553
+				),
3554
+				EE_Answer::new_instance(
3555
+					array(
3556
+						'ANS_ID'    => 0,
3557
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3558
+					)
3559
+				),
3560
+				array(
3561
+					'input_id'       => 'CNT_ISO',
3562
+					'input_name'     => 'CNT_ISO',
3563
+					'input_prefix'   => '',
3564
+					'append_qstn_id' => false,
3565
+				)
3566
+			)
3567
+		);
3568
+		$template                             =
3569
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3570
+		EEH_Template::display_template($template, $this->_template_args);
3571
+	}
3572
+
3573
+
3574
+	/**
3575
+	 *        _attendee_details
3576
+	 *
3577
+	 * @access protected
3578
+	 * @param $post
3579
+	 * @return void
3580
+	 * @throws DomainException
3581
+	 * @throws EE_Error
3582
+	 */
3583
+	public function attendee_registrations_meta_box($post)
3584
+	{
3585
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3586
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3587
+		$template                              =
3588
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3589
+		EEH_Template::display_template($template, $this->_template_args);
3590
+	}
3591
+
3592
+
3593
+	/**
3594
+	 * add in the form fields for the attendee edit
3595
+	 *
3596
+	 * @param  WP_Post $post wp post object
3597
+	 * @return string html for new form.
3598
+	 * @throws DomainException
3599
+	 */
3600
+	public function after_title_form_fields($post)
3601
+	{
3602
+		if ($post->post_type == 'espresso_attendees') {
3603
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3604
+			$template_args['attendee'] = $this->_cpt_model_obj;
3605
+			EEH_Template::display_template($template, $template_args);
3606
+		}
3607
+	}
3608
+
3609
+
3610
+	/**
3611
+	 *        _trash_or_restore_attendee
3612
+	 *
3613
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3614
+	 * @return void
3615
+	 * @throws EE_Error
3616
+	 * @access protected
3617
+	 */
3618
+	protected function _trash_or_restore_attendees($trash = true)
3619
+	{
3620
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3621
+		$ATT_MDL = EEM_Attendee::instance();
3622
+		$success = 1;
3623
+		//Checkboxes
3624
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3625
+			// if array has more than one element than success message should be plural
3626
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3627
+			// cycle thru checkboxes
3628
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3629
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3630
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3631
+				if ( ! $updated) {
3632
+					$success = 0;
3633
+				}
3634
+			}
3635
+		} else {
3636
+			// grab single id and delete
3637
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3638
+			//get attendee
3639
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3640
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3641
+			$updated = $att->save();
3642
+			if ( ! $updated) {
3643
+				$success = 0;
3644
+			}
3645
+		}
3646
+		$what        = $success > 1
3647
+			? esc_html__('Contacts', 'event_espresso')
3648
+			: esc_html__('Contact', 'event_espresso');
3649
+		$action_desc = $trash
3650
+			? esc_html__('moved to the trash', 'event_espresso')
3651
+			: esc_html__('restored', 'event_espresso');
3652
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3653
+	}
3654 3654
 
3655 3655
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Factory.lib.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
 	 * @param \EE_Message_Resource_Manager $Message_Resource_Manager
54 54
 	 * @return \EE_Message_Factory instance
55 55
 	 */
56
-	public static function instance( EE_Message_Resource_Manager $Message_Resource_Manager ) {
56
+	public static function instance(EE_Message_Resource_Manager $Message_Resource_Manager) {
57 57
 		// check if class object is instantiated, and instantiated properly
58
-		if ( ! self::$_instance instanceof EE_Message_Factory ) {
59
-			self::$_instance = new EE_Message_Factory( $Message_Resource_Manager );
58
+		if ( ! self::$_instance instanceof EE_Message_Factory) {
59
+			self::$_instance = new EE_Message_Factory($Message_Resource_Manager);
60 60
 		}
61 61
 		return self::$_instance;
62 62
 	}
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	 * @param  array $props_n_values
69 69
 	 * @return EE_Message
70 70
 	 */
71
-	public static function create( $props_n_values = array() ) {
71
+	public static function create($props_n_values = array()) {
72 72
 		/** @type EE_Message_Factory $Message_Factory */
73
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
74
-		return $Message_Factory->_create( $props_n_values );
73
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
74
+		return $Message_Factory->_create($props_n_values);
75 75
 	}
76 76
 
77 77
 
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
 	 * @return \EE_Message
83 83
 	 * @throws \EE_Error
84 84
 	 */
85
-	public static function set_messenger_and_message_type( EE_Message $message ) {
85
+	public static function set_messenger_and_message_type(EE_Message $message) {
86 86
 		/** @type EE_Message_Factory $Message_Factory */
87
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
88
-		return $Message_Factory->_set_messenger_and_message_type( $message );
87
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
88
+		return $Message_Factory->_set_messenger_and_message_type($message);
89 89
 	}
90 90
 
91 91
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @return \EE_Message
97 97
 	 * @throws \EE_Error
98 98
 	 */
99
-	public static function set_messenger( EE_Message $message ) {
99
+	public static function set_messenger(EE_Message $message) {
100 100
 		/** @type EE_Message_Factory $Message_Factory */
101
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
102
-		return $Message_Factory->_set_messenger( $message );
101
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
102
+		return $Message_Factory->_set_messenger($message);
103 103
 	}
104 104
 
105 105
 
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 	 * @return \EE_Message
111 111
 	 * @throws \EE_Error
112 112
 	 */
113
-	public static function set_message_type( EE_Message $message ) {
113
+	public static function set_message_type(EE_Message $message) {
114 114
 		/** @type EE_Message_Factory $Message_Factory */
115
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
116
-		return $Message_Factory->_set_message_type( $message );
115
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
116
+		return $Message_Factory->_set_message_type($message);
117 117
 	}
118 118
 
119 119
 
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
 	 * @return \EE_Message
125 125
 	 * @throws \EE_Error
126 126
 	 */
127
-	protected function _create( $props_n_values = array() ) {
127
+	protected function _create($props_n_values = array()) {
128 128
 		$new_instance = false;
129
-		if ( ! empty( $props_n_values['MSG_ID'] ) ) {
130
-			$message = EE_Message::new_instance_from_db( $props_n_values );
129
+		if ( ! empty($props_n_values['MSG_ID'])) {
130
+			$message = EE_Message::new_instance_from_db($props_n_values);
131 131
 		} else {
132
-			$message = EE_Message::new_instance( $props_n_values );
132
+			$message = EE_Message::new_instance($props_n_values);
133 133
 			$new_instance = true;
134 134
 		}
135
-		return $this->_set_messenger_and_message_type( $message, $new_instance );
135
+		return $this->_set_messenger_and_message_type($message, $new_instance);
136 136
 	}
137 137
 
138 138
 
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
 	 * @return \EE_Message
145 145
 	 * @throws \EE_Error
146 146
 	 */
147
-	protected function _set_messenger_and_message_type( EE_Message $message, $new_instance = false ) {
148
-		$message = $this->_set_messenger( $message );
149
-		$message = $this->_set_message_type( $message, $new_instance );
147
+	protected function _set_messenger_and_message_type(EE_Message $message, $new_instance = false) {
148
+		$message = $this->_set_messenger($message);
149
+		$message = $this->_set_message_type($message, $new_instance);
150 150
 		return $message;
151 151
 	}
152 152
 
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
 	 * @return \EE_Message
159 159
 	 * @throws \EE_Error
160 160
 	 */
161
-	protected function _set_messenger( EE_Message $message ) {
162
-		$messenger = $this->_message_resource_manager->get_messenger( $message->messenger() );
163
-		if ( $messenger instanceof EE_messenger ) {
164
-			$message->set_messenger_object( $messenger );
161
+	protected function _set_messenger(EE_Message $message) {
162
+		$messenger = $this->_message_resource_manager->get_messenger($message->messenger());
163
+		if ($messenger instanceof EE_messenger) {
164
+			$message->set_messenger_object($messenger);
165 165
 		}
166 166
 		return $message;
167 167
 	}
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
 	 * @return \EE_Message
176 176
 	 * @throws \EE_Error
177 177
 	 */
178
-	protected function _set_message_type( EE_Message $message, $new_instance = false ) {
179
-		$message_type = $this->_message_resource_manager->get_message_type( $message->message_type() );
180
-		if ( $message_type instanceof EE_message_type ) {
181
-			$message->set_message_type_object( $message_type, $new_instance );
178
+	protected function _set_message_type(EE_Message $message, $new_instance = false) {
179
+		$message_type = $this->_message_resource_manager->get_message_type($message->message_type());
180
+		if ($message_type instanceof EE_message_type) {
181
+			$message->set_message_type_object($message_type, $new_instance);
182 182
 		}
183 183
 		return $message;
184 184
 	}
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Queue.lib.php 1 patch
Indentation   +677 added lines, -677 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use \EventEspresso\core\exceptions\SendMessageException;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 /**
@@ -18,681 +18,681 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @type    string  reference for sending action
23
-     */
24
-    const action_sending = 'sending';
25
-
26
-    /**
27
-     * @type    string  reference for generation action
28
-     */
29
-    const action_generating = 'generation';
30
-
31
-
32
-    /**
33
-     * @type EE_Message_Repository $_message_repository
34
-     */
35
-    protected $_message_repository;
36
-
37
-    /**
38
-     * Sets the limit of how many messages are generated per process.
39
-     *
40
-     * @type int
41
-     */
42
-    protected $_batch_count;
43
-
44
-    /**
45
-     * Sets the limit of how many messages can be sent per hour.
46
-     *
47
-     * @type int
48
-     */
49
-    protected $_rate_limit;
50
-
51
-    /**
52
-     * This is an array of cached queue items being stored in this object.
53
-     * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
-     * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
-     *
56
-     * @type EE_Message[]
57
-     */
58
-    protected $_cached_queue_items;
59
-
60
-    /**
61
-     * Tracks the number of unsaved queue items.
62
-     *
63
-     * @type int
64
-     */
65
-    protected $_unsaved_count = 0;
66
-
67
-    /**
68
-     * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
-     * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
-     *
71
-     * @type array
72
-     */
73
-    protected $_did_hook = array();
74
-
75
-
76
-    /**
77
-     * Constructor.
78
-     * Setup all the initial properties and load a EE_Message_Repository.
79
-     *
80
-     * @param \EE_Message_Repository $message_repository
81
-     */
82
-    public function __construct(EE_Message_Repository $message_repository)
83
-    {
84
-        $this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
-        $this->_rate_limit         = $this->get_rate_limit();
86
-        $this->_message_repository = $message_repository;
87
-    }
88
-
89
-
90
-    /**
91
-     * Add a EE_Message object to the queue
92
-     *
93
-     * @param EE_Message $message
94
-     * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
-     *                                 object is persisted, this data will be saved on an extra_meta object related to
96
-     *                                 EE_Message.
97
-     * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
-     * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
-     *                                 use the messenger send method but typically is based on preview data.
100
-     * @return bool          Whether the message was successfully added to the repository or not.
101
-     */
102
-    public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
-    {
104
-        $data['preview']   = $preview;
105
-        $data['test_send'] = $test_send;
106
-        return $this->_message_repository->add($message, $data);
107
-    }
108
-
109
-
110
-    /**
111
-     * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
-     *
113
-     * @param EE_Message $message The message to detach from the queue
114
-     * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
-     * @return bool
116
-     */
117
-    public function remove(EE_Message $message, $persist = false)
118
-    {
119
-        if ($persist && $this->_message_repository->current() !== $message) {
120
-            //get pointer on right message
121
-            if ($this->_message_repository->has($message)) {
122
-                $this->_message_repository->rewind();
123
-                while ($this->_message_repository->valid()) {
124
-                    if ($this->_message_repository->current() === $message) {
125
-                        break;
126
-                    }
127
-                    $this->_message_repository->next();
128
-                }
129
-            } else {
130
-                return false;
131
-            }
132
-        }
133
-        return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
-    }
135
-
136
-
137
-    /**
138
-     * Persists all queued EE_Message objects to the db.
139
-     *
140
-     * @param bool $do_hooks_only       @see EE_Message_Repository::saveAll
141
-     * @return array @see EE_Messages_Repository::saveAll() for return values.
142
-     */
143
-    public function save($do_hooks_only = false)
144
-    {
145
-        return $this->_message_repository->saveAll($do_hooks_only);
146
-    }
147
-
148
-
149
-    /**
150
-     * @return EE_Message_Repository
151
-     */
152
-    public function get_message_repository()
153
-    {
154
-        return $this->_message_repository;
155
-    }
156
-
157
-
158
-    /**
159
-     * This does the following things:
160
-     * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
161
-     * false).
162
-     * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
163
-     * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
164
-     * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
165
-     * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
166
-     * removed.
167
-     *
168
-     * @return bool  true if successfully retrieved batch, false no batch ready.
169
-     */
170
-    public function get_batch_to_generate()
171
-    {
172
-        if ($this->is_locked(EE_Messages_Queue::action_generating)) {
173
-            return false;
174
-        }
175
-
176
-        //lock batch generation to prevent race conditions.
177
-        $this->lock_queue(EE_Messages_Queue::action_generating);
178
-
179
-        $query_args = array(
180
-            // key 0 = where conditions
181
-            0          => array('STS_ID' => EEM_Message::status_incomplete),
182
-            'order_by' => $this->_get_priority_orderby(),
183
-            'limit'    => $this->_batch_count,
184
-        );
185
-        $messages   = EEM_Message::instance()->get_all($query_args);
186
-
187
-        if ( ! $messages) {
188
-            return false; //nothing to generate
189
-        }
190
-
191
-        foreach ($messages as $message) {
192
-            if ($message instanceof EE_Message) {
193
-                $data = $message->all_extra_meta_array();
194
-                $this->add($message, $data);
195
-            }
196
-        }
197
-        return true;
198
-    }
199
-
200
-
201
-    /**
202
-     * This does the following things:
203
-     * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
204
-     * false).
205
-     * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
206
-     * return false.
207
-     * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
208
-     * 3. On success or unsuccessful send, sets status appropriately.
209
-     * 4. Saves messages via the queue
210
-     * 5. Releases lock.
211
-     *
212
-     * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
213
-     *               necessarily mean that all messages were successfully sent.  It just means that this method
214
-     *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
215
-     *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
216
-     *               will also have a saved error message on it to assist with notifying user.
217
-     */
218
-    public function get_to_send_batch_and_send()
219
-    {
220
-        if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
221
-            return false;
222
-        }
223
-
224
-        $this->lock_queue(EE_Messages_Queue::action_sending);
225
-
226
-        $batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
227
-
228
-        $query_args = array(
229
-            // key 0 = where conditions
230
-            0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
231
-            'order_by' => $this->_get_priority_orderby(),
232
-            'limit'    => $batch,
233
-        );
234
-
235
-        $messages_to_send = EEM_Message::instance()->get_all($query_args);
236
-
237
-
238
-        //any to send?
239
-        if ( ! $messages_to_send) {
240
-            $this->unlock_queue(EE_Messages_Queue::action_sending);
241
-            return false;
242
-        }
243
-
244
-        //add to queue.
245
-        foreach ($messages_to_send as $message) {
246
-            if ($message instanceof EE_Message) {
247
-                $this->add($message);
248
-            }
249
-        }
250
-
251
-        //send messages  (this also updates the rate limit)
252
-        $this->execute();
253
-
254
-        //release lock
255
-        $this->unlock_queue(EE_Messages_Queue::action_sending);
256
-        return true;
257
-    }
258
-
259
-
260
-    /**
261
-     * Locks the queue so that no other queues can call the "batch" methods.
262
-     *
263
-     * @param   string $type The type of queue being locked.
264
-     */
265
-    public function lock_queue($type = EE_Messages_Queue::action_generating)
266
-    {
267
-        set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
268
-    }
269
-
270
-
271
-    /**
272
-     * Unlocks the queue so that batch methods can be used.
273
-     *
274
-     * @param   string $type The type of queue being unlocked.
275
-     */
276
-    public function unlock_queue($type = EE_Messages_Queue::action_generating)
277
-    {
278
-        delete_transient($this->_get_lock_key($type));
279
-    }
280
-
281
-
282
-    /**
283
-     * Retrieve the key used for the lock transient.
284
-     *
285
-     * @param string $type The type of lock.
286
-     * @return string
287
-     */
288
-    protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
289
-    {
290
-        return '_ee_lock_' . $type;
291
-    }
292
-
293
-
294
-    /**
295
-     * Retrieve the expiry time for the lock transient.
296
-     *
297
-     * @param string $type The type of lock
298
-     * @return int   time to expiry in seconds.
299
-     */
300
-    protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
301
-    {
302
-        return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
303
-    }
304
-
305
-
306
-    /**
307
-     * Returns the key used for rate limit transient.
308
-     *
309
-     * @return string
310
-     */
311
-    protected function _get_rate_limit_key()
312
-    {
313
-        return '_ee_rate_limit';
314
-    }
315
-
316
-
317
-    /**
318
-     * Returns the rate limit expiry time.
319
-     *
320
-     * @return int
321
-     */
322
-    protected function _get_rate_limit_expiry()
323
-    {
324
-        return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
325
-    }
326
-
327
-
328
-    /**
329
-     * Returns the default rate limit for sending messages.
330
-     *
331
-     * @return int
332
-     */
333
-    protected function _default_rate_limit()
334
-    {
335
-        return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
336
-    }
337
-
338
-
339
-    /**
340
-     * Return the orderby array for priority.
341
-     *
342
-     * @return array
343
-     */
344
-    protected function _get_priority_orderby()
345
-    {
346
-        return array(
347
-            'MSG_priority' => 'ASC',
348
-            'MSG_modified' => 'DESC',
349
-        );
350
-    }
351
-
352
-
353
-    /**
354
-     * Returns whether batch methods are "locked" or not.
355
-     *
356
-     * @param  string $type The type of lock being checked for.
357
-     * @return bool
358
-     */
359
-    public function is_locked($type = EE_Messages_Queue::action_generating)
360
-    {
361
-        /**
362
-         * This filters the default is_locked behaviour.
363
-         */
364
-        $is_locked = filter_var(
365
-            apply_filters(
366
-                'FHEE__EE_Messages_Queue__is_locked',
367
-                get_transient($this->_get_lock_key($type)),
368
-                $this
369
-            ),
370
-            FILTER_VALIDATE_BOOLEAN
371
-        );
372
-
373
-        /**
374
-         * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
375
-         *            Also implemented here because messages processed on the same request should not have any locks applied.
376
-         */
377
-        if (
378
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
379
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
380
-        ) {
381
-            $is_locked = false;
382
-        }
383
-
384
-
385
-        return $is_locked;
386
-    }
387
-
388
-
389
-    /**
390
-     * Retrieves the rate limit that may be cached as a transient.
391
-     * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
392
-     *
393
-     * @return int
394
-     */
395
-    public function get_rate_limit()
396
-    {
397
-        if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
398
-            $rate_limit = $this->_default_rate_limit();
399
-            set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
400
-        }
401
-        return $rate_limit;
402
-    }
403
-
404
-
405
-    /**
406
-     * This updates existing rate limit with the new limit which is the old minus the batch.
407
-     *
408
-     * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
409
-     */
410
-    public function set_rate_limit($batch_completed)
411
-    {
412
-        //first get the most up to date rate limit (in case its expired and reset)
413
-        $rate_limit = $this->get_rate_limit();
414
-        $new_limit  = $rate_limit - $batch_completed;
415
-        //updating the transient option directly to avoid resetting the expiry.
416
-        update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
417
-    }
418
-
419
-
420
-    /**
421
-     * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
422
-     * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
423
-     * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
424
-     * request running on a queue for the given task.
425
-     *
426
-     * @param string $task     This indicates what type of request is going to be initiated.
427
-     * @param int    $priority This indicates the priority that triggers initiating the request.
428
-     */
429
-    public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
430
-    {
431
-        //determine what status is matched with the priority as part of the trigger conditions.
432
-        $status = $task == 'generate'
433
-            ? EEM_Message::status_incomplete
434
-            : EEM_Message::instance()->stati_indicating_to_send();
435
-        // always make sure we save because either this will get executed immediately on a separate request
436
-        // or remains in the queue for the regularly scheduled queue batch.
437
-        $this->save();
438
-        /**
439
-         * This filter/option allows users to override processing of messages on separate requests and instead have everything
440
-         * happen on the same request.  If this is utilized remember:
441
-         * - message priorities don't matter
442
-         * - existing unprocessed messages in the queue will not get processed unless manually triggered.
443
-         * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
444
-         *   processing happening on the same request.
445
-         * - any race condition protection (locks) are removed because they don't apply when things are processed on
446
-         *   the same request.
447
-         */
448
-        if (
449
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
450
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
451
-        ) {
452
-            $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
453
-            if ($messages_processor instanceof EE_Messages_Processor) {
454
-                return $messages_processor->process_immediately_from_queue($this);
455
-            }
456
-            //if we get here then that means the messages processor couldn't be loaded so messages will just remain
457
-            //queued for manual triggering by end user.
458
-        }
459
-
460
-        if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
461
-            EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
462
-        }
463
-    }
464
-
465
-
466
-    /**
467
-     *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
468
-     *
469
-     * @param   bool     $save                    Used to indicate whether to save the message queue after sending
470
-     *                                            (default will save).
471
-     * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
472
-     *                                            what is on the EE_Message object in the queue.
473
-     *                                            For instance, showing the browser view of an email message,
474
-     *                                            or giving a pdf generated view of an html document.
475
-     *                                            This should be an instance of EE_messenger but if you call this
476
-     *                                            method
477
-     *                                            intending it to be a sending messenger but a valid one could not be
478
-     *                                            retrieved then send in an instance of EE_Error that contains the
479
-     *                                            related error message.
480
-     * @param   bool|int $by_priority             When set, this indicates that only messages
481
-     *                                            matching the given priority should be executed.
482
-     * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
483
-     *                                            Also, if the messenger is an request type messenger (or a preview),
484
-     *                                            its entirely possible that the messenger will exit before
485
-     */
486
-    public function execute($save = true, $sending_messenger = null, $by_priority = false)
487
-    {
488
-        $messages_sent   = 0;
489
-        $this->_did_hook = array();
490
-        $this->_message_repository->rewind();
491
-
492
-        while ($this->_message_repository->valid()) {
493
-            $error_messages = array();
494
-            /** @type EE_Message $message */
495
-            $message = $this->_message_repository->current();
496
-            //only process things that are queued for sending
497
-            if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
498
-                $this->_message_repository->next();
499
-                continue;
500
-            }
501
-            //if $by_priority is set and does not match then continue;
502
-            if ($by_priority && $by_priority != $message->priority()) {
503
-                $this->_message_repository->next();
504
-                continue;
505
-            }
506
-            //error checking
507
-            if (! $message->valid_messenger()) {
508
-                $error_messages[] = sprintf(
509
-                    __('The %s messenger is not active at time of sending.', 'event_espresso'),
510
-                    $message->messenger()
511
-                );
512
-            }
513
-            if (! $message->valid_message_type()) {
514
-                $error_messages[] = sprintf(
515
-                    __('The %s message type is not active at the time of sending.', 'event_espresso'),
516
-                    $message->message_type()
517
-                );
518
-            }
519
-            // if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
520
-            // then it will instead be an EE_Error object, so let's check for that
521
-            if ($sending_messenger instanceof EE_Error) {
522
-                $error_messages[] = $sending_messenger->getMessage();
523
-            }
524
-            // if there are no errors, then let's process the message
525
-            if (empty($error_messages)) {
526
-                if ($save) {
527
-                    $message->set_messenger_is_executing();
528
-                }
529
-                if ($this->_process_message($message, $sending_messenger)) {
530
-                    $messages_sent++;
531
-                }
532
-            }
533
-            $this->_set_error_message($message, $error_messages);
534
-            //add modified time
535
-            $message->set_modified(time());
536
-            //we save each message after its processed to make sure its status persists in case PHP times-out or runs
537
-            //out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281
538
-            if ($save) {
539
-                $message->save();
540
-            }
541
-
542
-            $this->_message_repository->next();
543
-        }
544
-        if ($save) {
545
-            $this->save(true);
546
-        }
547
-        return $messages_sent;
548
-    }
549
-
550
-
551
-    /**
552
-     * _process_message
553
-     *
554
-     * @param EE_Message $message
555
-     * @param mixed      $sending_messenger (optional)
556
-     * @return bool
557
-     */
558
-    protected function _process_message(EE_Message $message, $sending_messenger = null)
559
-    {
560
-        // these *should* have been validated in the execute() method above
561
-        $messenger    = $message->messenger_object();
562
-        $message_type = $message->message_type_object();
563
-        //do actions for sending messenger if it differs from generating messenger and swap values.
564
-        if (
565
-            $sending_messenger instanceof EE_messenger
566
-            && $messenger instanceof EE_messenger
567
-            && $sending_messenger->name != $messenger->name
568
-        ) {
569
-            $messenger->do_secondary_messenger_hooks($sending_messenger->name);
570
-            $messenger = $sending_messenger;
571
-        }
572
-        // send using messenger, but double check objects
573
-        if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
574
-            //set hook for message type (but only if not using another messenger to send).
575
-            if ( ! isset($this->_did_hook[$message_type->name])) {
576
-                $message_type->do_messenger_hooks($messenger);
577
-                $this->_did_hook[$message_type->name] = 1;
578
-            }
579
-            //if preview then use preview method
580
-            return $this->_message_repository->is_preview()
581
-                ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
582
-                : $this->_do_send($message, $messenger, $message_type);
583
-        }
584
-        return false;
585
-    }
586
-
587
-
588
-    /**
589
-     * The intention of this method is to count how many EE_Message objects
590
-     * are in the queue with a given status.
591
-     * Example usage:
592
-     * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
593
-     * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
594
-     *
595
-     * @param array|string $status Stati to check for in queue
596
-     * @return int  Count of EE_Message's matching the given status.
597
-     */
598
-    public function count_STS_in_queue($status)
599
-    {
600
-        $count  = 0;
601
-        $status = is_array($status) ? $status : array($status);
602
-        $this->_message_repository->rewind();
603
-        foreach ($this->_message_repository as $message) {
604
-            if (in_array($message->STS_ID(), $status)) {
605
-                $count++;
606
-            }
607
-        }
608
-        return $count;
609
-    }
610
-
611
-
612
-    /**
613
-     * Executes the get_preview method on the provided messenger.
614
-     *
615
-     * @param EE_Message      $message
616
-     * @param EE_messenger    $messenger
617
-     * @param EE_message_type $message_type
618
-     * @param                 $test_send
619
-     * @return bool   true means all went well, false means, not so much.
620
-     */
621
-    protected function _do_preview(
622
-        EE_Message $message,
623
-        EE_messenger $messenger,
624
-        EE_message_type $message_type,
625
-        $test_send
626
-    ) {
627
-        if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
628
-            if ( ! $test_send) {
629
-                $message->set_content($preview);
630
-            }
631
-            $message->set_STS_ID(EEM_Message::status_sent);
632
-            return true;
633
-        } else {
634
-            $message->set_STS_ID(EEM_Message::status_failed);
635
-            return false;
636
-        }
637
-    }
638
-
639
-
640
-    /**
641
-     * Executes the send method on the provided messenger
642
-     * EE_Messengers are expected to:
643
-     * - return true if the send was successful.
644
-     * - return false if the send was unsuccessful but can be tried again.
645
-     * - throw an Exception if the send was unsuccessful and cannot be tried again.
646
-     *
647
-     * @param EE_Message      $message
648
-     * @param EE_messenger    $messenger
649
-     * @param EE_message_type $message_type
650
-     * @return bool true means all went well, false means, not so much.
651
-     */
652
-    protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
653
-    {
654
-        try {
655
-            if ($messenger->send_message($message, $message_type)) {
656
-                $message->set_STS_ID(EEM_Message::status_sent);
657
-                return true;
658
-            } else {
659
-                $message->set_STS_ID(EEM_Message::status_retry);
660
-                return false;
661
-            }
662
-        } catch (SendMessageException $e) {
663
-            $message->set_STS_ID(EEM_Message::status_failed);
664
-            $message->set_error_message($e->getMessage());
665
-            return false;
666
-        }
667
-    }
668
-
669
-
670
-    /**
671
-     * This sets any necessary error messages on the message object and its status to failed.
672
-     *
673
-     * @param EE_Message $message
674
-     * @param array      $error_messages the response from the messenger.
675
-     */
676
-    protected function _set_error_message(EE_Message $message, $error_messages)
677
-    {
678
-        $error_messages = (array)$error_messages;
679
-        if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
680
-            $notices          = EE_Error::has_notices();
681
-            $error_messages[] = __(
682
-                'Messenger and Message Type were valid and active, but the messenger send method failed.',
683
-                'event_espresso'
684
-            );
685
-            if ($notices === 1) {
686
-                $notices           = EE_Error::get_vanilla_notices();
687
-                $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
688
-                $error_messages[]  = implode("\n", $notices['errors']);
689
-            }
690
-        }
691
-        if (count($error_messages) > 0) {
692
-            $msg = __('Message was not executed successfully.', 'event_espresso');
693
-            $msg = $msg . "\n" . implode("\n", $error_messages);
694
-            $message->set_error_message($msg);
695
-        }
696
-    }
21
+	/**
22
+	 * @type    string  reference for sending action
23
+	 */
24
+	const action_sending = 'sending';
25
+
26
+	/**
27
+	 * @type    string  reference for generation action
28
+	 */
29
+	const action_generating = 'generation';
30
+
31
+
32
+	/**
33
+	 * @type EE_Message_Repository $_message_repository
34
+	 */
35
+	protected $_message_repository;
36
+
37
+	/**
38
+	 * Sets the limit of how many messages are generated per process.
39
+	 *
40
+	 * @type int
41
+	 */
42
+	protected $_batch_count;
43
+
44
+	/**
45
+	 * Sets the limit of how many messages can be sent per hour.
46
+	 *
47
+	 * @type int
48
+	 */
49
+	protected $_rate_limit;
50
+
51
+	/**
52
+	 * This is an array of cached queue items being stored in this object.
53
+	 * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
+	 * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
+	 *
56
+	 * @type EE_Message[]
57
+	 */
58
+	protected $_cached_queue_items;
59
+
60
+	/**
61
+	 * Tracks the number of unsaved queue items.
62
+	 *
63
+	 * @type int
64
+	 */
65
+	protected $_unsaved_count = 0;
66
+
67
+	/**
68
+	 * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
+	 * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
+	 *
71
+	 * @type array
72
+	 */
73
+	protected $_did_hook = array();
74
+
75
+
76
+	/**
77
+	 * Constructor.
78
+	 * Setup all the initial properties and load a EE_Message_Repository.
79
+	 *
80
+	 * @param \EE_Message_Repository $message_repository
81
+	 */
82
+	public function __construct(EE_Message_Repository $message_repository)
83
+	{
84
+		$this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
+		$this->_rate_limit         = $this->get_rate_limit();
86
+		$this->_message_repository = $message_repository;
87
+	}
88
+
89
+
90
+	/**
91
+	 * Add a EE_Message object to the queue
92
+	 *
93
+	 * @param EE_Message $message
94
+	 * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
+	 *                                 object is persisted, this data will be saved on an extra_meta object related to
96
+	 *                                 EE_Message.
97
+	 * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
+	 * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
+	 *                                 use the messenger send method but typically is based on preview data.
100
+	 * @return bool          Whether the message was successfully added to the repository or not.
101
+	 */
102
+	public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
+	{
104
+		$data['preview']   = $preview;
105
+		$data['test_send'] = $test_send;
106
+		return $this->_message_repository->add($message, $data);
107
+	}
108
+
109
+
110
+	/**
111
+	 * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
+	 *
113
+	 * @param EE_Message $message The message to detach from the queue
114
+	 * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
+	 * @return bool
116
+	 */
117
+	public function remove(EE_Message $message, $persist = false)
118
+	{
119
+		if ($persist && $this->_message_repository->current() !== $message) {
120
+			//get pointer on right message
121
+			if ($this->_message_repository->has($message)) {
122
+				$this->_message_repository->rewind();
123
+				while ($this->_message_repository->valid()) {
124
+					if ($this->_message_repository->current() === $message) {
125
+						break;
126
+					}
127
+					$this->_message_repository->next();
128
+				}
129
+			} else {
130
+				return false;
131
+			}
132
+		}
133
+		return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
+	}
135
+
136
+
137
+	/**
138
+	 * Persists all queued EE_Message objects to the db.
139
+	 *
140
+	 * @param bool $do_hooks_only       @see EE_Message_Repository::saveAll
141
+	 * @return array @see EE_Messages_Repository::saveAll() for return values.
142
+	 */
143
+	public function save($do_hooks_only = false)
144
+	{
145
+		return $this->_message_repository->saveAll($do_hooks_only);
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return EE_Message_Repository
151
+	 */
152
+	public function get_message_repository()
153
+	{
154
+		return $this->_message_repository;
155
+	}
156
+
157
+
158
+	/**
159
+	 * This does the following things:
160
+	 * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
161
+	 * false).
162
+	 * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
163
+	 * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
164
+	 * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
165
+	 * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
166
+	 * removed.
167
+	 *
168
+	 * @return bool  true if successfully retrieved batch, false no batch ready.
169
+	 */
170
+	public function get_batch_to_generate()
171
+	{
172
+		if ($this->is_locked(EE_Messages_Queue::action_generating)) {
173
+			return false;
174
+		}
175
+
176
+		//lock batch generation to prevent race conditions.
177
+		$this->lock_queue(EE_Messages_Queue::action_generating);
178
+
179
+		$query_args = array(
180
+			// key 0 = where conditions
181
+			0          => array('STS_ID' => EEM_Message::status_incomplete),
182
+			'order_by' => $this->_get_priority_orderby(),
183
+			'limit'    => $this->_batch_count,
184
+		);
185
+		$messages   = EEM_Message::instance()->get_all($query_args);
186
+
187
+		if ( ! $messages) {
188
+			return false; //nothing to generate
189
+		}
190
+
191
+		foreach ($messages as $message) {
192
+			if ($message instanceof EE_Message) {
193
+				$data = $message->all_extra_meta_array();
194
+				$this->add($message, $data);
195
+			}
196
+		}
197
+		return true;
198
+	}
199
+
200
+
201
+	/**
202
+	 * This does the following things:
203
+	 * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
204
+	 * false).
205
+	 * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
206
+	 * return false.
207
+	 * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
208
+	 * 3. On success or unsuccessful send, sets status appropriately.
209
+	 * 4. Saves messages via the queue
210
+	 * 5. Releases lock.
211
+	 *
212
+	 * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
213
+	 *               necessarily mean that all messages were successfully sent.  It just means that this method
214
+	 *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
215
+	 *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
216
+	 *               will also have a saved error message on it to assist with notifying user.
217
+	 */
218
+	public function get_to_send_batch_and_send()
219
+	{
220
+		if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
221
+			return false;
222
+		}
223
+
224
+		$this->lock_queue(EE_Messages_Queue::action_sending);
225
+
226
+		$batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
227
+
228
+		$query_args = array(
229
+			// key 0 = where conditions
230
+			0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
231
+			'order_by' => $this->_get_priority_orderby(),
232
+			'limit'    => $batch,
233
+		);
234
+
235
+		$messages_to_send = EEM_Message::instance()->get_all($query_args);
236
+
237
+
238
+		//any to send?
239
+		if ( ! $messages_to_send) {
240
+			$this->unlock_queue(EE_Messages_Queue::action_sending);
241
+			return false;
242
+		}
243
+
244
+		//add to queue.
245
+		foreach ($messages_to_send as $message) {
246
+			if ($message instanceof EE_Message) {
247
+				$this->add($message);
248
+			}
249
+		}
250
+
251
+		//send messages  (this also updates the rate limit)
252
+		$this->execute();
253
+
254
+		//release lock
255
+		$this->unlock_queue(EE_Messages_Queue::action_sending);
256
+		return true;
257
+	}
258
+
259
+
260
+	/**
261
+	 * Locks the queue so that no other queues can call the "batch" methods.
262
+	 *
263
+	 * @param   string $type The type of queue being locked.
264
+	 */
265
+	public function lock_queue($type = EE_Messages_Queue::action_generating)
266
+	{
267
+		set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
268
+	}
269
+
270
+
271
+	/**
272
+	 * Unlocks the queue so that batch methods can be used.
273
+	 *
274
+	 * @param   string $type The type of queue being unlocked.
275
+	 */
276
+	public function unlock_queue($type = EE_Messages_Queue::action_generating)
277
+	{
278
+		delete_transient($this->_get_lock_key($type));
279
+	}
280
+
281
+
282
+	/**
283
+	 * Retrieve the key used for the lock transient.
284
+	 *
285
+	 * @param string $type The type of lock.
286
+	 * @return string
287
+	 */
288
+	protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
289
+	{
290
+		return '_ee_lock_' . $type;
291
+	}
292
+
293
+
294
+	/**
295
+	 * Retrieve the expiry time for the lock transient.
296
+	 *
297
+	 * @param string $type The type of lock
298
+	 * @return int   time to expiry in seconds.
299
+	 */
300
+	protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
301
+	{
302
+		return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
303
+	}
304
+
305
+
306
+	/**
307
+	 * Returns the key used for rate limit transient.
308
+	 *
309
+	 * @return string
310
+	 */
311
+	protected function _get_rate_limit_key()
312
+	{
313
+		return '_ee_rate_limit';
314
+	}
315
+
316
+
317
+	/**
318
+	 * Returns the rate limit expiry time.
319
+	 *
320
+	 * @return int
321
+	 */
322
+	protected function _get_rate_limit_expiry()
323
+	{
324
+		return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
325
+	}
326
+
327
+
328
+	/**
329
+	 * Returns the default rate limit for sending messages.
330
+	 *
331
+	 * @return int
332
+	 */
333
+	protected function _default_rate_limit()
334
+	{
335
+		return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
336
+	}
337
+
338
+
339
+	/**
340
+	 * Return the orderby array for priority.
341
+	 *
342
+	 * @return array
343
+	 */
344
+	protected function _get_priority_orderby()
345
+	{
346
+		return array(
347
+			'MSG_priority' => 'ASC',
348
+			'MSG_modified' => 'DESC',
349
+		);
350
+	}
351
+
352
+
353
+	/**
354
+	 * Returns whether batch methods are "locked" or not.
355
+	 *
356
+	 * @param  string $type The type of lock being checked for.
357
+	 * @return bool
358
+	 */
359
+	public function is_locked($type = EE_Messages_Queue::action_generating)
360
+	{
361
+		/**
362
+		 * This filters the default is_locked behaviour.
363
+		 */
364
+		$is_locked = filter_var(
365
+			apply_filters(
366
+				'FHEE__EE_Messages_Queue__is_locked',
367
+				get_transient($this->_get_lock_key($type)),
368
+				$this
369
+			),
370
+			FILTER_VALIDATE_BOOLEAN
371
+		);
372
+
373
+		/**
374
+		 * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
375
+		 *            Also implemented here because messages processed on the same request should not have any locks applied.
376
+		 */
377
+		if (
378
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
379
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
380
+		) {
381
+			$is_locked = false;
382
+		}
383
+
384
+
385
+		return $is_locked;
386
+	}
387
+
388
+
389
+	/**
390
+	 * Retrieves the rate limit that may be cached as a transient.
391
+	 * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
392
+	 *
393
+	 * @return int
394
+	 */
395
+	public function get_rate_limit()
396
+	{
397
+		if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
398
+			$rate_limit = $this->_default_rate_limit();
399
+			set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
400
+		}
401
+		return $rate_limit;
402
+	}
403
+
404
+
405
+	/**
406
+	 * This updates existing rate limit with the new limit which is the old minus the batch.
407
+	 *
408
+	 * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
409
+	 */
410
+	public function set_rate_limit($batch_completed)
411
+	{
412
+		//first get the most up to date rate limit (in case its expired and reset)
413
+		$rate_limit = $this->get_rate_limit();
414
+		$new_limit  = $rate_limit - $batch_completed;
415
+		//updating the transient option directly to avoid resetting the expiry.
416
+		update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
417
+	}
418
+
419
+
420
+	/**
421
+	 * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
422
+	 * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
423
+	 * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
424
+	 * request running on a queue for the given task.
425
+	 *
426
+	 * @param string $task     This indicates what type of request is going to be initiated.
427
+	 * @param int    $priority This indicates the priority that triggers initiating the request.
428
+	 */
429
+	public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
430
+	{
431
+		//determine what status is matched with the priority as part of the trigger conditions.
432
+		$status = $task == 'generate'
433
+			? EEM_Message::status_incomplete
434
+			: EEM_Message::instance()->stati_indicating_to_send();
435
+		// always make sure we save because either this will get executed immediately on a separate request
436
+		// or remains in the queue for the regularly scheduled queue batch.
437
+		$this->save();
438
+		/**
439
+		 * This filter/option allows users to override processing of messages on separate requests and instead have everything
440
+		 * happen on the same request.  If this is utilized remember:
441
+		 * - message priorities don't matter
442
+		 * - existing unprocessed messages in the queue will not get processed unless manually triggered.
443
+		 * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
444
+		 *   processing happening on the same request.
445
+		 * - any race condition protection (locks) are removed because they don't apply when things are processed on
446
+		 *   the same request.
447
+		 */
448
+		if (
449
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
450
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
451
+		) {
452
+			$messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
453
+			if ($messages_processor instanceof EE_Messages_Processor) {
454
+				return $messages_processor->process_immediately_from_queue($this);
455
+			}
456
+			//if we get here then that means the messages processor couldn't be loaded so messages will just remain
457
+			//queued for manual triggering by end user.
458
+		}
459
+
460
+		if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
461
+			EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
462
+		}
463
+	}
464
+
465
+
466
+	/**
467
+	 *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
468
+	 *
469
+	 * @param   bool     $save                    Used to indicate whether to save the message queue after sending
470
+	 *                                            (default will save).
471
+	 * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
472
+	 *                                            what is on the EE_Message object in the queue.
473
+	 *                                            For instance, showing the browser view of an email message,
474
+	 *                                            or giving a pdf generated view of an html document.
475
+	 *                                            This should be an instance of EE_messenger but if you call this
476
+	 *                                            method
477
+	 *                                            intending it to be a sending messenger but a valid one could not be
478
+	 *                                            retrieved then send in an instance of EE_Error that contains the
479
+	 *                                            related error message.
480
+	 * @param   bool|int $by_priority             When set, this indicates that only messages
481
+	 *                                            matching the given priority should be executed.
482
+	 * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
483
+	 *                                            Also, if the messenger is an request type messenger (or a preview),
484
+	 *                                            its entirely possible that the messenger will exit before
485
+	 */
486
+	public function execute($save = true, $sending_messenger = null, $by_priority = false)
487
+	{
488
+		$messages_sent   = 0;
489
+		$this->_did_hook = array();
490
+		$this->_message_repository->rewind();
491
+
492
+		while ($this->_message_repository->valid()) {
493
+			$error_messages = array();
494
+			/** @type EE_Message $message */
495
+			$message = $this->_message_repository->current();
496
+			//only process things that are queued for sending
497
+			if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
498
+				$this->_message_repository->next();
499
+				continue;
500
+			}
501
+			//if $by_priority is set and does not match then continue;
502
+			if ($by_priority && $by_priority != $message->priority()) {
503
+				$this->_message_repository->next();
504
+				continue;
505
+			}
506
+			//error checking
507
+			if (! $message->valid_messenger()) {
508
+				$error_messages[] = sprintf(
509
+					__('The %s messenger is not active at time of sending.', 'event_espresso'),
510
+					$message->messenger()
511
+				);
512
+			}
513
+			if (! $message->valid_message_type()) {
514
+				$error_messages[] = sprintf(
515
+					__('The %s message type is not active at the time of sending.', 'event_espresso'),
516
+					$message->message_type()
517
+				);
518
+			}
519
+			// if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
520
+			// then it will instead be an EE_Error object, so let's check for that
521
+			if ($sending_messenger instanceof EE_Error) {
522
+				$error_messages[] = $sending_messenger->getMessage();
523
+			}
524
+			// if there are no errors, then let's process the message
525
+			if (empty($error_messages)) {
526
+				if ($save) {
527
+					$message->set_messenger_is_executing();
528
+				}
529
+				if ($this->_process_message($message, $sending_messenger)) {
530
+					$messages_sent++;
531
+				}
532
+			}
533
+			$this->_set_error_message($message, $error_messages);
534
+			//add modified time
535
+			$message->set_modified(time());
536
+			//we save each message after its processed to make sure its status persists in case PHP times-out or runs
537
+			//out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281
538
+			if ($save) {
539
+				$message->save();
540
+			}
541
+
542
+			$this->_message_repository->next();
543
+		}
544
+		if ($save) {
545
+			$this->save(true);
546
+		}
547
+		return $messages_sent;
548
+	}
549
+
550
+
551
+	/**
552
+	 * _process_message
553
+	 *
554
+	 * @param EE_Message $message
555
+	 * @param mixed      $sending_messenger (optional)
556
+	 * @return bool
557
+	 */
558
+	protected function _process_message(EE_Message $message, $sending_messenger = null)
559
+	{
560
+		// these *should* have been validated in the execute() method above
561
+		$messenger    = $message->messenger_object();
562
+		$message_type = $message->message_type_object();
563
+		//do actions for sending messenger if it differs from generating messenger and swap values.
564
+		if (
565
+			$sending_messenger instanceof EE_messenger
566
+			&& $messenger instanceof EE_messenger
567
+			&& $sending_messenger->name != $messenger->name
568
+		) {
569
+			$messenger->do_secondary_messenger_hooks($sending_messenger->name);
570
+			$messenger = $sending_messenger;
571
+		}
572
+		// send using messenger, but double check objects
573
+		if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
574
+			//set hook for message type (but only if not using another messenger to send).
575
+			if ( ! isset($this->_did_hook[$message_type->name])) {
576
+				$message_type->do_messenger_hooks($messenger);
577
+				$this->_did_hook[$message_type->name] = 1;
578
+			}
579
+			//if preview then use preview method
580
+			return $this->_message_repository->is_preview()
581
+				? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
582
+				: $this->_do_send($message, $messenger, $message_type);
583
+		}
584
+		return false;
585
+	}
586
+
587
+
588
+	/**
589
+	 * The intention of this method is to count how many EE_Message objects
590
+	 * are in the queue with a given status.
591
+	 * Example usage:
592
+	 * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
593
+	 * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
594
+	 *
595
+	 * @param array|string $status Stati to check for in queue
596
+	 * @return int  Count of EE_Message's matching the given status.
597
+	 */
598
+	public function count_STS_in_queue($status)
599
+	{
600
+		$count  = 0;
601
+		$status = is_array($status) ? $status : array($status);
602
+		$this->_message_repository->rewind();
603
+		foreach ($this->_message_repository as $message) {
604
+			if (in_array($message->STS_ID(), $status)) {
605
+				$count++;
606
+			}
607
+		}
608
+		return $count;
609
+	}
610
+
611
+
612
+	/**
613
+	 * Executes the get_preview method on the provided messenger.
614
+	 *
615
+	 * @param EE_Message      $message
616
+	 * @param EE_messenger    $messenger
617
+	 * @param EE_message_type $message_type
618
+	 * @param                 $test_send
619
+	 * @return bool   true means all went well, false means, not so much.
620
+	 */
621
+	protected function _do_preview(
622
+		EE_Message $message,
623
+		EE_messenger $messenger,
624
+		EE_message_type $message_type,
625
+		$test_send
626
+	) {
627
+		if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
628
+			if ( ! $test_send) {
629
+				$message->set_content($preview);
630
+			}
631
+			$message->set_STS_ID(EEM_Message::status_sent);
632
+			return true;
633
+		} else {
634
+			$message->set_STS_ID(EEM_Message::status_failed);
635
+			return false;
636
+		}
637
+	}
638
+
639
+
640
+	/**
641
+	 * Executes the send method on the provided messenger
642
+	 * EE_Messengers are expected to:
643
+	 * - return true if the send was successful.
644
+	 * - return false if the send was unsuccessful but can be tried again.
645
+	 * - throw an Exception if the send was unsuccessful and cannot be tried again.
646
+	 *
647
+	 * @param EE_Message      $message
648
+	 * @param EE_messenger    $messenger
649
+	 * @param EE_message_type $message_type
650
+	 * @return bool true means all went well, false means, not so much.
651
+	 */
652
+	protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
653
+	{
654
+		try {
655
+			if ($messenger->send_message($message, $message_type)) {
656
+				$message->set_STS_ID(EEM_Message::status_sent);
657
+				return true;
658
+			} else {
659
+				$message->set_STS_ID(EEM_Message::status_retry);
660
+				return false;
661
+			}
662
+		} catch (SendMessageException $e) {
663
+			$message->set_STS_ID(EEM_Message::status_failed);
664
+			$message->set_error_message($e->getMessage());
665
+			return false;
666
+		}
667
+	}
668
+
669
+
670
+	/**
671
+	 * This sets any necessary error messages on the message object and its status to failed.
672
+	 *
673
+	 * @param EE_Message $message
674
+	 * @param array      $error_messages the response from the messenger.
675
+	 */
676
+	protected function _set_error_message(EE_Message $message, $error_messages)
677
+	{
678
+		$error_messages = (array)$error_messages;
679
+		if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
680
+			$notices          = EE_Error::has_notices();
681
+			$error_messages[] = __(
682
+				'Messenger and Message Type were valid and active, but the messenger send method failed.',
683
+				'event_espresso'
684
+			);
685
+			if ($notices === 1) {
686
+				$notices           = EE_Error::get_vanilla_notices();
687
+				$notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
688
+				$error_messages[]  = implode("\n", $notices['errors']);
689
+			}
690
+		}
691
+		if (count($error_messages) > 0) {
692
+			$msg = __('Message was not executed successfully.', 'event_espresso');
693
+			$msg = $msg . "\n" . implode("\n", $error_messages);
694
+			$message->set_error_message($msg);
695
+		}
696
+	}
697 697
 
698 698
 } //end EE_Messages_Queue class
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Processor.lib.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -560,10 +560,10 @@
 block discarded – undo
560 560
 
561 561
 		foreach ( $regs_to_send as $status_group ) {
562 562
 			foreach ( $status_group as $status_id => $registrations ) {
563
-			    $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
564
-			    if (! $message_type) {
565
-			        continue;
566
-                }
563
+				$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
564
+				if (! $message_type) {
565
+					continue;
566
+				}
567 567
 				$messages_to_generate = array_merge(
568 568
 					$messages_to_generate,
569 569
 					$this->setup_mtgs_for_all_active_messengers(
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param EE_Message_Resource_Manager $message_resource_manager
37 37
 	 */
38
-	public function __construct( EE_Message_Resource_Manager $message_resource_manager ) {
38
+	public function __construct(EE_Message_Resource_Manager $message_resource_manager) {
39 39
 		$this->_message_resource_manager = $message_resource_manager;
40 40
 		$this->_init_queue_and_generator();
41 41
 	}
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * - $_generator = holds the messages generator
51 51
 	 */
52 52
 	protected function _init_queue_and_generator() {
53
-		$this->_generator = EE_Registry::factory( 'EE_Messages_Generator' );
53
+		$this->_generator = EE_Registry::factory('EE_Messages_Generator');
54 54
 		$this->_queue = $this->_generator->generation_queue();
55 55
 	}
56 56
 
@@ -75,31 +75,31 @@  discard block
 block discarded – undo
75 75
 	 * @param EE_Messages_Queue $queue_to_process
76 76
 	 * @return bool  true for success false for error.
77 77
 	 */
78
-	public function process_immediately_from_queue( EE_Messages_Queue $queue_to_process ) {
78
+	public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) {
79 79
 		$success = false;
80 80
 		$messages_to_send = array();
81 81
 		$messages_to_generate = array();
82 82
 		//loop through and setup the various messages from the queue so we know what is being processed
83 83
 		$queue_to_process->get_message_repository()->rewind();
84
-		foreach ( $queue_to_process->get_message_repository() as $message ) {
85
-			if ( $message->STS_ID() === EEM_Message::status_incomplete ) {
84
+		foreach ($queue_to_process->get_message_repository() as $message) {
85
+			if ($message->STS_ID() === EEM_Message::status_incomplete) {
86 86
 				$messages_to_generate[] = $message;
87 87
 				continue;
88 88
 			}
89 89
 
90
-			if ( in_array( $message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send() ) ) {
90
+			if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
91 91
 				$messages_to_send[] = $message;
92 92
 				continue;
93 93
 			}
94 94
 		}
95 95
 
96 96
 		//do generation/sends
97
-		if ( $messages_to_generate ) {
98
-			$success = $this->batch_generate_from_queue( $messages_to_generate, true );
97
+		if ($messages_to_generate) {
98
+			$success = $this->batch_generate_from_queue($messages_to_generate, true);
99 99
 		}
100 100
 
101
-		if ( $messages_to_send ) {
102
-			$sent = $this->batch_send_from_queue( $messages_to_send, true );
101
+		if ($messages_to_send) {
102
+			$sent = $this->batch_send_from_queue($messages_to_send, true);
103 103
 			//if there was messages to generate and it failed, then we override any success value for the sending process
104 104
 			//otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
105 105
 			//Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 	 * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
120 120
 	 *                                   generated messages.
121 121
 	 */
122
-	public function batch_generate_from_queue( $messages = array(), $clear_queue = false ) {
123
-		if ( $this->_build_queue_for_generation( $messages, $clear_queue ) ) {
122
+	public function batch_generate_from_queue($messages = array(), $clear_queue = false) {
123
+		if ($this->_build_queue_for_generation($messages, $clear_queue)) {
124 124
 			$new_queue = $this->_generator->generate();
125
-			if ( $new_queue instanceof EE_Messages_Queue ) {
125
+			if ($new_queue instanceof EE_Messages_Queue) {
126 126
 				//unlock queue
127 127
 				$this->_queue->unlock_queue();
128
-				$new_queue->initiate_request_by_priority( 'send' );
128
+				$new_queue->initiate_request_by_priority('send');
129 129
 				return $new_queue;
130 130
 			}
131 131
 		}
@@ -146,24 +146,24 @@  discard block
 block discarded – undo
146 146
 	 *
147 147
 	 * @return bool true means queue prepped, false means there was a lock so no generation please.
148 148
 	 */
149
-	protected function _build_queue_for_generation( $messages = array(), $clear_queue = false ) {
149
+	protected function _build_queue_for_generation($messages = array(), $clear_queue = false) {
150 150
 
151
-		if ( $clear_queue ) {
151
+		if ($clear_queue) {
152 152
 			$this->_init_queue_and_generator();
153 153
 		}
154 154
 
155
-		if ( $messages ) {
155
+		if ($messages) {
156 156
 			//if generation is locked then get out now because that means processing is already happening.
157
-			if ( $this->_queue->is_locked() ) {
157
+			if ($this->_queue->is_locked()) {
158 158
 				return false;
159 159
 			}
160 160
 
161 161
 			$this->_queue->lock_queue();
162
-			$messages = is_array( $messages ) ? $messages : array( $messages );
163
-			foreach ( $messages as $message ) {
164
-				if ( $message instanceof EE_Message ) {
162
+			$messages = is_array($messages) ? $messages : array($messages);
163
+			foreach ($messages as $message) {
164
+				if ($message instanceof EE_Message) {
165 165
 					$data = $message->all_extra_meta_array();
166
-					$this->_queue->add( $message, $data );
166
+					$this->_queue->add($message, $data);
167 167
 				}
168 168
 			}
169 169
 			return true;
@@ -181,22 +181,22 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return bool true means queue prepped, false means there was a lock so no queue prepped.
183 183
 	 */
184
-	protected function _build_queue_for_sending( $messages, $clear_queue = false ) {
184
+	protected function _build_queue_for_sending($messages, $clear_queue = false) {
185 185
 		//if sending is locked then get out now because that means processing is already happening.
186
-		if ( $this->_queue->is_locked( EE_Messages_Queue::action_sending ) ) {
186
+		if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
187 187
 			return false;
188 188
 		}
189 189
 
190
-		$this->_queue->lock_queue( EE_Messages_Queue::action_sending );
190
+		$this->_queue->lock_queue(EE_Messages_Queue::action_sending);
191 191
 
192
-		if ( $clear_queue ) {
192
+		if ($clear_queue) {
193 193
 			$this->_init_queue_and_generator();
194 194
 		}
195 195
 
196
-		$messages = is_array( $messages ) ? $messages : array( $messages );
196
+		$messages = is_array($messages) ? $messages : array($messages);
197 197
 
198
-		foreach ( $messages as $message ) {
199
-			$this->_queue->add( $message );
198
+		foreach ($messages as $message) {
199
+			$this->_queue->add($message);
200 200
 		}
201 201
 		return true;
202 202
 	}
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return EE_Messages_Queue
214 214
 	 */
215
-	public function batch_send_from_queue( $messages = array(), $clear_queue = false ) {
215
+	public function batch_send_from_queue($messages = array(), $clear_queue = false) {
216 216
 
217
-		if ( $messages && $this->_build_queue_for_sending( $messages, $clear_queue ) ) {
217
+		if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
218 218
 			$this->_queue->execute();
219
-			$this->_queue->unlock_queue( EE_Messages_Queue::action_sending );
219
+			$this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
220 220
 		} else {
221 221
 			//get messages to send and execute.
222 222
 			$this->_queue->get_to_send_batch_and_send();
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
 	 * @param EE_Message_To_Generate[] $messages_to_generate
240 240
 	 * @return EE_Messages_Queue
241 241
 	 */
242
-	public function generate_and_return(  $messages_to_generate ) {
242
+	public function generate_and_return($messages_to_generate) {
243 243
 		$this->_init_queue_and_generator();
244
-		$this->_queue_for_generation_loop( $messages_to_generate );
245
-		return $this->_generator->generate( false );
244
+		$this->_queue_for_generation_loop($messages_to_generate);
245
+		return $this->_generator->generate(false);
246 246
 	}
247 247
 
248 248
 
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 	 * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
254 254
 	 * @return EE_Messages_Queue
255 255
 	 */
256
-	public function generate_queue( $persist = true ) {
257
-		return $this->_generator->generate( $persist );
256
+	public function generate_queue($persist = true) {
257
+		return $this->_generator->generate($persist);
258 258
 	}
259 259
 
260 260
 
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 	 * @param bool                   $test_send             Whether this item is for a test send or not.
268 268
 	 * @return  EE_Messages_Queue
269 269
 	 */
270
-	public function queue_for_generation( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
271
-		if ( $message_to_generate->valid() ) {
272
-			$this->_generator->create_and_add_message_to_queue( $message_to_generate, $test_send );
270
+	public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) {
271
+		if ($message_to_generate->valid()) {
272
+			$this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
273 273
 		}
274 274
 	}
275 275
 
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 	 *
286 286
 	 * @param EE_Message_To_Generate[] $messages_to_generate
287 287
 	 */
288
-	public function batch_queue_for_generation_and_persist( $messages_to_generate ) {
288
+	public function batch_queue_for_generation_and_persist($messages_to_generate) {
289 289
 		$this->_init_queue_and_generator();
290
-		$this->_queue_for_generation_loop( $messages_to_generate );
290
+		$this->_queue_for_generation_loop($messages_to_generate);
291 291
 		$this->_queue->save();
292 292
 	}
293 293
 
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param EE_Message_To_Generate[]  $messages_to_generate
305 305
 	 */
306
-	public function batch_queue_for_generation_no_persist( $messages_to_generate ) {
306
+	public function batch_queue_for_generation_no_persist($messages_to_generate) {
307 307
 		$this->_init_queue_and_generator();
308
-		$this->_queue_for_generation_loop( $messages_to_generate );
308
+		$this->_queue_for_generation_loop($messages_to_generate);
309 309
 	}
310 310
 
311 311
 
@@ -317,15 +317,15 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @param EE_Message_To_Generate[] $messages_to_generate
319 319
 	 */
320
-	protected function _queue_for_generation_loop( $messages_to_generate ) {
320
+	protected function _queue_for_generation_loop($messages_to_generate) {
321 321
 		//make sure is in an array.
322
-		if ( ! is_array( $messages_to_generate ) ) {
323
-			$messages_to_generate = array( $messages_to_generate );
322
+		if ( ! is_array($messages_to_generate)) {
323
+			$messages_to_generate = array($messages_to_generate);
324 324
 		}
325 325
 
326
-		foreach ( $messages_to_generate as $message_to_generate ) {
327
-			if ( $message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid() ) {
328
-				$this->queue_for_generation( $message_to_generate );
326
+		foreach ($messages_to_generate as $message_to_generate) {
327
+			if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
328
+				$this->queue_for_generation($message_to_generate);
329 329
 			}
330 330
 		}
331 331
 	}
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 	 * @param  EE_Message_To_Generate[]
341 341
 	 * @return EE_Messages_Queue
342 342
 	 */
343
-	public function generate_and_queue_for_sending( $messages_to_generate ) {
343
+	public function generate_and_queue_for_sending($messages_to_generate) {
344 344
 		$this->_init_queue_and_generator();
345
-		$this->_queue_for_generation_loop( $messages_to_generate );
346
-		return $this->_generator->generate( true );
345
+		$this->_queue_for_generation_loop($messages_to_generate);
346
+		return $this->_generator->generate(true);
347 347
 	}
348 348
 
349 349
 
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	 * @param   bool                   $test_send                Whether this is a test send or not.
358 358
 	 * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
359 359
 	 */
360
-	public function generate_for_preview( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
361
-		if ( ! $message_to_generate->valid() ) {
360
+	public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) {
361
+		if ( ! $message_to_generate->valid()) {
362 362
 			EE_Error::add_error(
363
-				__( 'Unable to generate preview because of invalid data', 'event_espresso' ),
363
+				__('Unable to generate preview because of invalid data', 'event_espresso'),
364 364
 				__FILE__,
365 365
 				__FUNCTION__,
366 366
 				__LINE__
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 			return false;
369 369
 		}
370 370
 		//just make sure preview is set on the $message_to_generate (in case client forgot)
371
-		$message_to_generate->set_preview( true );
371
+		$message_to_generate->set_preview(true);
372 372
 		$this->_init_queue_and_generator();
373
-		$this->queue_for_generation( $message_to_generate, $test_send );
374
-		$generated_queue = $this->_generator->generate( false );
375
-		if ( $generated_queue->execute( false ) ) {
373
+		$this->queue_for_generation($message_to_generate, $test_send);
374
+		$generated_queue = $this->_generator->generate(false);
375
+		if ($generated_queue->execute(false)) {
376 376
 			//the first queue item should be the preview
377 377
 			$generated_queue->get_message_repository()->rewind();
378
-			if ( ! $generated_queue->get_message_repository()->valid() ) {
378
+			if ( ! $generated_queue->get_message_repository()->valid()) {
379 379
 				return $generated_queue;
380 380
 			}
381 381
 			return $generated_queue;
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
 	 * @param EE_Message_To_Generate $message_to_generate
393 393
 	 * @return bool true or false for success.
394 394
 	 */
395
-	public function queue_for_sending( EE_Message_To_Generate $message_to_generate ) {
396
-		if ( ! $message_to_generate->valid() ) {
395
+	public function queue_for_sending(EE_Message_To_Generate $message_to_generate) {
396
+		if ( ! $message_to_generate->valid()) {
397 397
 			return false;
398 398
 		}
399 399
 		$this->_init_queue_and_generator();
400 400
 		$message = $message_to_generate->get_EE_Message();
401
-		$this->_queue->add( $message );
402
-		if ( $message->send_now() ) {
403
-			$this->_queue->execute( false );
401
+		$this->_queue->add($message);
402
+		if ($message->send_now()) {
403
+			$this->_queue->execute(false);
404 404
 		} else {
405 405
 			$this->_queue->save();
406 406
 		}
@@ -413,12 +413,12 @@  discard block
 block discarded – undo
413 413
 	 * @param EE_Message_To_Generate $message_to_generate
414 414
 	 * @return EE_Messages_Queue | null
415 415
 	 */
416
-	public function generate_and_send_now( EE_Message_To_Generate $message_to_generate ) {
417
-		if ( ! $message_to_generate->valid() ) {
416
+	public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) {
417
+		if ( ! $message_to_generate->valid()) {
418 418
 			return null;
419 419
 		}
420 420
 		// is there supposed to be a sending messenger for this message?
421
-		if ( $message_to_generate instanceof EEI_Has_Sending_Messenger ) {
421
+		if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
422 422
 			// make sure it's valid, but if it's not,
423 423
 			// then set the value of $sending_messenger to an EE_Error object
424 424
 			// so that downstream code can easily see that things went wrong.
@@ -434,14 +434,14 @@  discard block
 block discarded – undo
434 434
 			$sending_messenger = null;
435 435
 		}
436 436
 
437
-		if ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle ) {
437
+		if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
438 438
 			$this->_init_queue_and_generator();
439
-			$this->_queue->add( $message_to_generate->get_EE_Message() );
440
-			$this->_queue->execute( false, $sending_messenger );
439
+			$this->_queue->add($message_to_generate->get_EE_Message());
440
+			$this->_queue->execute(false, $sending_messenger);
441 441
 			return $this->_queue;
442
-		} elseif ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete ) {
443
-			$generated_queue = $this->generate_and_return( array( $message_to_generate ) );
444
-			$generated_queue->execute( false, $sending_messenger );
442
+		} elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
443
+			$generated_queue = $this->generate_and_return(array($message_to_generate));
444
+			$generated_queue->execute(false, $sending_messenger);
445 445
 			return $generated_queue;
446 446
 		}
447 447
 		return null;
@@ -458,13 +458,13 @@  discard block
 block discarded – undo
458 458
 	 * @param mixed  $data   The data being used for generation.
459 459
 	 * @param bool   $persist   Whether to persist the queued messages to the db or not.
460 460
 	 */
461
-	public function generate_for_all_active_messengers( $message_type, $data, $persist = true ) {
462
-		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers( $message_type, $data );
463
-		if ( $persist ) {
464
-			$this->batch_queue_for_generation_and_persist( $messages_to_generate );
461
+	public function generate_for_all_active_messengers($message_type, $data, $persist = true) {
462
+		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
463
+		if ($persist) {
464
+			$this->batch_queue_for_generation_and_persist($messages_to_generate);
465 465
 			$this->_queue->initiate_request_by_priority();
466 466
 		} else {
467
-			$this->batch_queue_for_generation_no_persist( $messages_to_generate );
467
+			$this->batch_queue_for_generation_no_persist($messages_to_generate);
468 468
 		}
469 469
 	}
470 470
 
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
 	 *
480 480
 	 * @return EE_Message_To_Generate[]
481 481
 	 */
482
-	public function setup_mtgs_for_all_active_messengers( $message_type, $data ) {
482
+	public function setup_mtgs_for_all_active_messengers($message_type, $data) {
483 483
 		$messages_to_generate = array();
484
-		foreach ( $this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object  ) {
485
-			$message_to_generate = new EE_Message_To_Generate( $messenger_slug, $message_type, $data );
486
-			if ( $message_to_generate->valid() ) {
484
+		foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
485
+			$message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
486
+			if ($message_to_generate->valid()) {
487 487
 				$messages_to_generate[] = $message_to_generate;
488 488
 			}
489 489
 		}
@@ -498,29 +498,29 @@  discard block
 block discarded – undo
498 498
 	 * and send.
499 499
 	 * @param array $message_ids
500 500
 	 */
501
-	public function setup_messages_from_ids_and_send( $message_ids ) {
501
+	public function setup_messages_from_ids_and_send($message_ids) {
502 502
 		$this->_init_queue_and_generator();
503
-		$messages = EEM_Message::instance()->get_all( array(
503
+		$messages = EEM_Message::instance()->get_all(array(
504 504
 			array(
505
-				'MSG_ID' => array( 'IN', $message_ids ),
505
+				'MSG_ID' => array('IN', $message_ids),
506 506
 				'STS_ID' => array(
507 507
 					'IN',
508 508
 					array_merge(
509 509
 						EEM_Message::instance()->stati_indicating_sent(),
510
-						array( EEM_Message::status_retry )
510
+						array(EEM_Message::status_retry)
511 511
 					),
512 512
 				),
513 513
 			),
514 514
 		));
515 515
 		//set the Messages to resend.
516
-		foreach ( $messages as $message ) {
517
-			if ( $message instanceof EE_Message ) {
518
-				$message->set_STS_ID( EEM_Message::status_resend );
519
-				$this->_queue->add( $message );
516
+		foreach ($messages as $message) {
517
+			if ($message instanceof EE_Message) {
518
+				$message->set_STS_ID(EEM_Message::status_resend);
519
+				$this->_queue->add($message);
520 520
 			}
521 521
 		}
522 522
 
523
-		$this->_queue->initiate_request_by_priority( 'send' );
523
+		$this->_queue->initiate_request_by_priority('send');
524 524
 	}
525 525
 
526 526
 
@@ -534,23 +534,23 @@  discard block
 block discarded – undo
534 534
 	 *
535 535
 	 * @return EE_Message_To_Generate[]
536 536
 	 */
537
-	public function setup_messages_to_generate_from_registration_ids_in_request( $registration_ids_key = '_REG_ID' ) {
538
-		EE_Registry::instance()->load_core( 'Request_Handler' );
539
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
537
+	public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') {
538
+		EE_Registry::instance()->load_core('Request_Handler');
539
+		EE_Registry::instance()->load_helper('MSG_Template');
540 540
 		$regs_to_send = array();
541
-		$regIDs = EE_Registry::instance()->REQ->get( $registration_ids_key );
542
-		if ( empty( $regIDs ) ) {
543
-			EE_Error::add_error( __('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
541
+		$regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
542
+		if (empty($regIDs)) {
543
+			EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
544 544
 			return false;
545 545
 		}
546 546
 
547 547
 		//make sure is an array
548
-		$regIDs = is_array( $regIDs ) ? $regIDs : array( $regIDs );
548
+		$regIDs = is_array($regIDs) ? $regIDs : array($regIDs);
549 549
 
550
-		foreach( $regIDs as $regID ) {
551
-			$reg = EEM_Registration::instance()->get_one_by_ID( $regID );
552
-			if ( ! $reg instanceof EE_Registration ) {
553
-				EE_Error::add_error( sprintf( __('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID ) );
550
+		foreach ($regIDs as $regID) {
551
+			$reg = EEM_Registration::instance()->get_one_by_ID($regID);
552
+			if ( ! $reg instanceof EE_Registration) {
553
+				EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
554 554
 				return false;
555 555
 			}
556 556
 			$regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
@@ -558,17 +558,17 @@  discard block
 block discarded – undo
558 558
 
559 559
 		$messages_to_generate = array();
560 560
 
561
-		foreach ( $regs_to_send as $status_group ) {
562
-			foreach ( $status_group as $status_id => $registrations ) {
561
+		foreach ($regs_to_send as $status_group) {
562
+			foreach ($status_group as $status_id => $registrations) {
563 563
 			    $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
564
-			    if (! $message_type) {
564
+			    if ( ! $message_type) {
565 565
 			        continue;
566 566
                 }
567 567
 				$messages_to_generate = array_merge(
568 568
 					$messages_to_generate,
569 569
 					$this->setup_mtgs_for_all_active_messengers(
570 570
 						$message_type,
571
-						array( $registrations, $status_id )
571
+						array($registrations, $status_id)
572 572
 					)
573 573
 				);
574 574
 			}
Please login to merge, or discard this patch.
core/domain/Domain.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@
 block discarded – undo
15 15
  */
16 16
 class Domain extends DomainBase
17 17
 {
18
-    /**
19
-     * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
20
-     * Page ui.
21
-     */
22
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
23
-        = 'manual_registration_status_change_from_registration_admin';
18
+	/**
19
+	 * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
20
+	 * Page ui.
21
+	 */
22
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
23
+		= 'manual_registration_status_change_from_registration_admin';
24 24
 
25
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
26
-        = 'manual_registration_status_change_from_registration_admin_and_notify';
25
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
26
+		= 'manual_registration_status_change_from_registration_admin_and_notify';
27 27
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +636 added lines, -636 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
16 16
 
17 17
 if (! defined('EVENT_ESPRESSO_VERSION')) {
18
-    exit('No direct script access allowed');
18
+	exit('No direct script access allowed');
19 19
 }
20 20
 
21 21
 
@@ -34,641 +34,641 @@  discard block
 block discarded – undo
34 34
 abstract class FormHandler implements FormHandlerInterface
35 35
 {
36 36
 
37
-    /**
38
-     * will add opening and closing HTML form tags as well as a submit button
39
-     */
40
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
41
-
42
-    /**
43
-     * will add opening and closing HTML form tags but NOT a submit button
44
-     */
45
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
46
-
47
-    /**
48
-     * will NOT add opening and closing HTML form tags but will add a submit button
49
-     */
50
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
51
-
52
-    /**
53
-     * will NOT add opening and closing HTML form tags NOR a submit button
54
-     */
55
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
56
-
57
-    /**
58
-     * if set to false, then this form has no displayable content,
59
-     * and will only be used for processing data sent passed via GET or POST
60
-     * defaults to true ( ie: form has displayable content )
61
-     *
62
-     * @var boolean $displayable
63
-     */
64
-    private $displayable = true;
65
-
66
-    /**
67
-     * @var string $form_name
68
-     */
69
-    private $form_name;
70
-
71
-    /**
72
-     * @var string $admin_name
73
-     */
74
-    private $admin_name;
75
-
76
-    /**
77
-     * @var string $slug
78
-     */
79
-    private $slug;
80
-
81
-    /**
82
-     * @var string $submit_btn_text
83
-     */
84
-    private $submit_btn_text;
85
-
86
-    /**
87
-     * @var string $form_action
88
-     */
89
-    private $form_action;
90
-
91
-    /**
92
-     * form params in key value pairs
93
-     * can be added to form action URL or as hidden inputs
94
-     *
95
-     * @var array $form_args
96
-     */
97
-    private $form_args = array();
98
-
99
-    /**
100
-     * value of one of the string constant above
101
-     *
102
-     * @var string $form_config
103
-     */
104
-    private $form_config;
105
-
106
-    /**
107
-     * whether or not the form was determined to be invalid
108
-     *
109
-     * @var boolean $form_has_errors
110
-     */
111
-    private $form_has_errors;
112
-
113
-    /**
114
-     * the absolute top level form section being used on the page
115
-     *
116
-     * @var EE_Form_Section_Proper $form
117
-     */
118
-    private $form;
119
-
120
-    /**
121
-     * @var EE_Registry $registry
122
-     */
123
-    protected $registry;
124
-
125
-
126
-
127
-    /**
128
-     * Form constructor.
129
-     *
130
-     * @param string      $form_name
131
-     * @param string      $admin_name
132
-     * @param string      $slug
133
-     * @param string      $form_action
134
-     * @param string      $form_config
135
-     * @param EE_Registry $registry
136
-     * @throws InvalidDataTypeException
137
-     * @throws DomainException
138
-     * @throws InvalidArgumentException
139
-     */
140
-    public function __construct(
141
-        $form_name,
142
-        $admin_name,
143
-        $slug,
144
-        $form_action = '',
145
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
146
-        EE_Registry $registry
147
-    ) {
148
-        $this->setFormName($form_name);
149
-        $this->setAdminName($admin_name);
150
-        $this->setSlug($slug);
151
-        $this->setFormAction($form_action);
152
-        $this->setFormConfig($form_config);
153
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
154
-        $this->registry = $registry;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * @return array
161
-     */
162
-    public static function getFormConfigConstants()
163
-    {
164
-        return array(
165
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
166
-            FormHandler::ADD_FORM_TAGS_ONLY,
167
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
168
-            FormHandler::DO_NOT_SETUP_FORM,
169
-        );
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * @param bool $for_display
176
-     * @return EE_Form_Section_Proper
177
-     * @throws EE_Error
178
-     * @throws LogicException
179
-     */
180
-    public function form($for_display = false)
181
-    {
182
-        if (! $this->formIsValid()) {
183
-            return null;
184
-        }
185
-        if ($for_display) {
186
-            $form_config = $this->formConfig();
187
-            if (
188
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
189
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
190
-            ) {
191
-                $this->appendSubmitButton();
192
-                $this->clearFormButtonFloats();
193
-            }
194
-        }
195
-        return $this->form;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @return boolean
202
-     * @throws LogicException
203
-     */
204
-    public function formIsValid()
205
-    {
206
-        if ($this->form instanceof EE_Form_Section_Proper) {
207
-            return true;
208
-        }
209
-        $form = apply_filters(
210
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
211
-            $this->generate(),
212
-            $this
213
-        );
214
-        if ($this->verifyForm($form)) {
215
-            $this->setForm($form);
216
-        }
217
-        return true;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * @param EE_Form_Section_Proper|null $form
224
-     * @return bool
225
-     * @throws LogicException
226
-     */
227
-    public function verifyForm(EE_Form_Section_Proper $form = null)
228
-    {
229
-        $form = $form !== null ? $form : $this->form;
230
-        if ($form instanceof EE_Form_Section_Proper) {
231
-            return true;
232
-        }
233
-        throw new LogicException(
234
-            sprintf(
235
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
236
-                $this->form_name,
237
-                var_export($form, true)
238
-            )
239
-        );
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * @param EE_Form_Section_Proper $form
246
-     */
247
-    public function setForm(EE_Form_Section_Proper $form)
248
-    {
249
-        $this->form = $form;
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * @return boolean
256
-     */
257
-    public function displayable()
258
-    {
259
-        return $this->displayable;
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     * @param boolean $displayable
266
-     */
267
-    public function setDisplayable($displayable = false)
268
-    {
269
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
270
-    }
271
-
272
-
273
-
274
-    /**
275
-     * a public name for the form that can be displayed on the frontend of a site
276
-     *
277
-     * @return string
278
-     */
279
-    public function formName()
280
-    {
281
-        return $this->form_name;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param string $form_name
288
-     * @throws InvalidDataTypeException
289
-     */
290
-    public function setFormName($form_name)
291
-    {
292
-        if (! is_string($form_name)) {
293
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
294
-        }
295
-        $this->form_name = $form_name;
296
-    }
297
-
298
-
299
-
300
-    /**
301
-     * a public name for the form that can be displayed, but only in the admin
302
-     *
303
-     * @return string
304
-     */
305
-    public function adminName()
306
-    {
307
-        return $this->admin_name;
308
-    }
309
-
310
-
311
-
312
-    /**
313
-     * @param string $admin_name
314
-     * @throws InvalidDataTypeException
315
-     */
316
-    public function setAdminName($admin_name)
317
-    {
318
-        if (! is_string($admin_name)) {
319
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
320
-        }
321
-        $this->admin_name = $admin_name;
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * a URL friendly string that can be used for identifying the form
328
-     *
329
-     * @return string
330
-     */
331
-    public function slug()
332
-    {
333
-        return $this->slug;
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * @param string $slug
340
-     * @throws InvalidDataTypeException
341
-     */
342
-    public function setSlug($slug)
343
-    {
344
-        if (! is_string($slug)) {
345
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
346
-        }
347
-        $this->slug = $slug;
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @return string
354
-     */
355
-    public function submitBtnText()
356
-    {
357
-        return $this->submit_btn_text;
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * @param string $submit_btn_text
364
-     * @throws InvalidDataTypeException
365
-     * @throws InvalidArgumentException
366
-     */
367
-    public function setSubmitBtnText($submit_btn_text)
368
-    {
369
-        if (! is_string($submit_btn_text)) {
370
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
371
-        }
372
-        if (empty($submit_btn_text)) {
373
-            throw new InvalidArgumentException(
374
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
375
-            );
376
-        }
377
-        $this->submit_btn_text = $submit_btn_text;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * @return string
384
-     */
385
-    public function formAction()
386
-    {
387
-        return ! empty($this->form_args)
388
-            ? add_query_arg($this->form_args, $this->form_action)
389
-            : $this->form_action;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * @param string $form_action
396
-     * @throws InvalidDataTypeException
397
-     */
398
-    public function setFormAction($form_action)
399
-    {
400
-        if (! is_string($form_action)) {
401
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
402
-        }
403
-        $this->form_action = $form_action;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * @param array $form_args
410
-     * @throws InvalidDataTypeException
411
-     * @throws InvalidArgumentException
412
-     */
413
-    public function addFormActionArgs($form_args = array())
414
-    {
415
-        if (is_object($form_args)) {
416
-            throw new InvalidDataTypeException(
417
-                '$form_args',
418
-                $form_args,
419
-                'anything other than an object was expected.'
420
-            );
421
-        }
422
-        if (empty($form_args)) {
423
-            throw new InvalidArgumentException(
424
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
425
-            );
426
-        }
427
-        $this->form_args = array_merge($this->form_args, $form_args);
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * @return string
434
-     */
435
-    public function formConfig()
436
-    {
437
-        return $this->form_config;
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * @param string $form_config
444
-     * @throws DomainException
445
-     */
446
-    public function setFormConfig($form_config)
447
-    {
448
-        if (
449
-        ! in_array(
450
-            $form_config,
451
-            array(
452
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
453
-                FormHandler::ADD_FORM_TAGS_ONLY,
454
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
455
-                FormHandler::DO_NOT_SETUP_FORM,
456
-            ),
457
-            true
458
-        )
459
-        ) {
460
-            throw new DomainException(
461
-                sprintf(
462
-                    esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
463
-                        'event_espresso'),
464
-                    $form_config
465
-                )
466
-            );
467
-        }
468
-        $this->form_config = $form_config;
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * called after the form is instantiated
475
-     * and used for performing any logic that needs to occur early
476
-     * before any of the other methods are called.
477
-     * returns true if everything is ok to proceed,
478
-     * and false if no further form logic should be implemented
479
-     *
480
-     * @return boolean
481
-     */
482
-    public function initialize()
483
-    {
484
-        $this->form_has_errors = EE_Error::has_error(true);
485
-        return true;
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * used for setting up css and js
492
-     *
493
-     * @return void
494
-     * @throws LogicException
495
-     * @throws EE_Error
496
-     */
497
-    public function enqueueStylesAndScripts()
498
-    {
499
-        $this->form()->enqueue_js();
500
-    }
501
-
502
-
503
-
504
-    /**
505
-     * creates and returns the actual form
506
-     *
507
-     * @return EE_Form_Section_Proper
508
-     */
509
-    abstract public function generate();
510
-
511
-
512
-
513
-    /**
514
-     * creates and returns an EE_Submit_Input labeled "Submit"
515
-     *
516
-     * @param string $text
517
-     * @return EE_Submit_Input
518
-     */
519
-    public function generateSubmitButton($text = '')
520
-    {
521
-        $text = ! empty($text) ? $text : $this->submitBtnText();
522
-        return new EE_Submit_Input(
523
-            array(
524
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
525
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
526
-                'html_class'            => 'ee-form-submit',
527
-                'html_label'            => '&nbsp;',
528
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
529
-                'default'               => $text,
530
-            )
531
-        );
532
-    }
533
-
534
-
535
-
536
-    /**
537
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
538
-     *
539
-     * @param string $text
540
-     * @return void
541
-     * @throws LogicException
542
-     * @throws EE_Error
543
-     */
544
-    public function appendSubmitButton($text = '')
545
-    {
546
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
547
-            return;
548
-        }
549
-        $this->form->add_subsections(
550
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
551
-            null,
552
-            false
553
-        );
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     * creates and returns an EE_Submit_Input labeled "Cancel"
560
-     *
561
-     * @param string $text
562
-     * @return EE_Submit_Input
563
-     */
564
-    public function generateCancelButton($text = '')
565
-    {
566
-        $cancel_button = new EE_Submit_Input(
567
-            array(
568
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
569
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
570
-                'html_class'            => 'ee-cancel-form',
571
-                'html_label'            => '&nbsp;',
572
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
573
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
574
-            )
575
-        );
576
-        $cancel_button->set_button_css_attributes(false);
577
-        return $cancel_button;
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * appends a float clearing div onto end of form
584
-     *
585
-     * @return void
586
-     * @throws EE_Error
587
-     */
588
-    public function clearFormButtonFloats()
589
-    {
590
-        $this->form->add_subsections(
591
-            array(
592
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
593
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
594
-                ),
595
-            ),
596
-            null,
597
-            false
598
-        );
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
605
-     * returns a string of HTML that can be directly echoed in a template
606
-     *
607
-     * @return string
608
-     * @throws LogicException
609
-     * @throws EE_Error
610
-     */
611
-    public function display()
612
-    {
613
-        $form_html = apply_filters(
614
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
615
-            ''
616
-        );
617
-        $form_config = $this->formConfig();
618
-        if (
619
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
620
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
621
-        ) {
622
-            $form_html .= $this->form()->form_open($this->formAction());
623
-        }
624
-        $form_html .= $this->form(true)->get_html($this->form_has_errors);
625
-        if (
626
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
627
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
628
-        ) {
629
-            $form_html .= $this->form()->form_close();
630
-        }
631
-        $form_html .= apply_filters(
632
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
633
-            ''
634
-        );
635
-        return $form_html;
636
-    }
637
-
638
-
639
-
640
-    /**
641
-     * handles processing the form submission
642
-     * returns true or false depending on whether the form was processed successfully or not
643
-     *
644
-     * @param array $submitted_form_data
645
-     * @return array
646
-     * @throws EE_Error
647
-     * @throws LogicException
648
-     * @throws InvalidFormSubmissionException
649
-     */
650
-    public function process($submitted_form_data = array())
651
-    {
652
-        if (! $this->form()->was_submitted($submitted_form_data)) {
653
-            throw new InvalidFormSubmissionException($this->form_name);
654
-        }
655
-        $this->form(true)->receive_form_submission($submitted_form_data);
656
-        if (! $this->form()->is_valid()) {
657
-            throw new InvalidFormSubmissionException(
658
-                $this->form_name,
659
-                sprintf(
660
-                    esc_html__(
661
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
662
-                        'event_espresso'
663
-                    ),
664
-                    $this->form_name,
665
-                    '<br />',
666
-                    $this->form()->submission_error_message()
667
-                )
668
-            );
669
-        }
670
-        return $this->form()->valid_data();
671
-    }
37
+	/**
38
+	 * will add opening and closing HTML form tags as well as a submit button
39
+	 */
40
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
41
+
42
+	/**
43
+	 * will add opening and closing HTML form tags but NOT a submit button
44
+	 */
45
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
46
+
47
+	/**
48
+	 * will NOT add opening and closing HTML form tags but will add a submit button
49
+	 */
50
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
51
+
52
+	/**
53
+	 * will NOT add opening and closing HTML form tags NOR a submit button
54
+	 */
55
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
56
+
57
+	/**
58
+	 * if set to false, then this form has no displayable content,
59
+	 * and will only be used for processing data sent passed via GET or POST
60
+	 * defaults to true ( ie: form has displayable content )
61
+	 *
62
+	 * @var boolean $displayable
63
+	 */
64
+	private $displayable = true;
65
+
66
+	/**
67
+	 * @var string $form_name
68
+	 */
69
+	private $form_name;
70
+
71
+	/**
72
+	 * @var string $admin_name
73
+	 */
74
+	private $admin_name;
75
+
76
+	/**
77
+	 * @var string $slug
78
+	 */
79
+	private $slug;
80
+
81
+	/**
82
+	 * @var string $submit_btn_text
83
+	 */
84
+	private $submit_btn_text;
85
+
86
+	/**
87
+	 * @var string $form_action
88
+	 */
89
+	private $form_action;
90
+
91
+	/**
92
+	 * form params in key value pairs
93
+	 * can be added to form action URL or as hidden inputs
94
+	 *
95
+	 * @var array $form_args
96
+	 */
97
+	private $form_args = array();
98
+
99
+	/**
100
+	 * value of one of the string constant above
101
+	 *
102
+	 * @var string $form_config
103
+	 */
104
+	private $form_config;
105
+
106
+	/**
107
+	 * whether or not the form was determined to be invalid
108
+	 *
109
+	 * @var boolean $form_has_errors
110
+	 */
111
+	private $form_has_errors;
112
+
113
+	/**
114
+	 * the absolute top level form section being used on the page
115
+	 *
116
+	 * @var EE_Form_Section_Proper $form
117
+	 */
118
+	private $form;
119
+
120
+	/**
121
+	 * @var EE_Registry $registry
122
+	 */
123
+	protected $registry;
124
+
125
+
126
+
127
+	/**
128
+	 * Form constructor.
129
+	 *
130
+	 * @param string      $form_name
131
+	 * @param string      $admin_name
132
+	 * @param string      $slug
133
+	 * @param string      $form_action
134
+	 * @param string      $form_config
135
+	 * @param EE_Registry $registry
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws DomainException
138
+	 * @throws InvalidArgumentException
139
+	 */
140
+	public function __construct(
141
+		$form_name,
142
+		$admin_name,
143
+		$slug,
144
+		$form_action = '',
145
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
146
+		EE_Registry $registry
147
+	) {
148
+		$this->setFormName($form_name);
149
+		$this->setAdminName($admin_name);
150
+		$this->setSlug($slug);
151
+		$this->setFormAction($form_action);
152
+		$this->setFormConfig($form_config);
153
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
154
+		$this->registry = $registry;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * @return array
161
+	 */
162
+	public static function getFormConfigConstants()
163
+	{
164
+		return array(
165
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
166
+			FormHandler::ADD_FORM_TAGS_ONLY,
167
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
168
+			FormHandler::DO_NOT_SETUP_FORM,
169
+		);
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * @param bool $for_display
176
+	 * @return EE_Form_Section_Proper
177
+	 * @throws EE_Error
178
+	 * @throws LogicException
179
+	 */
180
+	public function form($for_display = false)
181
+	{
182
+		if (! $this->formIsValid()) {
183
+			return null;
184
+		}
185
+		if ($for_display) {
186
+			$form_config = $this->formConfig();
187
+			if (
188
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
189
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
190
+			) {
191
+				$this->appendSubmitButton();
192
+				$this->clearFormButtonFloats();
193
+			}
194
+		}
195
+		return $this->form;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @return boolean
202
+	 * @throws LogicException
203
+	 */
204
+	public function formIsValid()
205
+	{
206
+		if ($this->form instanceof EE_Form_Section_Proper) {
207
+			return true;
208
+		}
209
+		$form = apply_filters(
210
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
211
+			$this->generate(),
212
+			$this
213
+		);
214
+		if ($this->verifyForm($form)) {
215
+			$this->setForm($form);
216
+		}
217
+		return true;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * @param EE_Form_Section_Proper|null $form
224
+	 * @return bool
225
+	 * @throws LogicException
226
+	 */
227
+	public function verifyForm(EE_Form_Section_Proper $form = null)
228
+	{
229
+		$form = $form !== null ? $form : $this->form;
230
+		if ($form instanceof EE_Form_Section_Proper) {
231
+			return true;
232
+		}
233
+		throw new LogicException(
234
+			sprintf(
235
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
236
+				$this->form_name,
237
+				var_export($form, true)
238
+			)
239
+		);
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * @param EE_Form_Section_Proper $form
246
+	 */
247
+	public function setForm(EE_Form_Section_Proper $form)
248
+	{
249
+		$this->form = $form;
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * @return boolean
256
+	 */
257
+	public function displayable()
258
+	{
259
+		return $this->displayable;
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 * @param boolean $displayable
266
+	 */
267
+	public function setDisplayable($displayable = false)
268
+	{
269
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
270
+	}
271
+
272
+
273
+
274
+	/**
275
+	 * a public name for the form that can be displayed on the frontend of a site
276
+	 *
277
+	 * @return string
278
+	 */
279
+	public function formName()
280
+	{
281
+		return $this->form_name;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param string $form_name
288
+	 * @throws InvalidDataTypeException
289
+	 */
290
+	public function setFormName($form_name)
291
+	{
292
+		if (! is_string($form_name)) {
293
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
294
+		}
295
+		$this->form_name = $form_name;
296
+	}
297
+
298
+
299
+
300
+	/**
301
+	 * a public name for the form that can be displayed, but only in the admin
302
+	 *
303
+	 * @return string
304
+	 */
305
+	public function adminName()
306
+	{
307
+		return $this->admin_name;
308
+	}
309
+
310
+
311
+
312
+	/**
313
+	 * @param string $admin_name
314
+	 * @throws InvalidDataTypeException
315
+	 */
316
+	public function setAdminName($admin_name)
317
+	{
318
+		if (! is_string($admin_name)) {
319
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
320
+		}
321
+		$this->admin_name = $admin_name;
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * a URL friendly string that can be used for identifying the form
328
+	 *
329
+	 * @return string
330
+	 */
331
+	public function slug()
332
+	{
333
+		return $this->slug;
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * @param string $slug
340
+	 * @throws InvalidDataTypeException
341
+	 */
342
+	public function setSlug($slug)
343
+	{
344
+		if (! is_string($slug)) {
345
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
346
+		}
347
+		$this->slug = $slug;
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @return string
354
+	 */
355
+	public function submitBtnText()
356
+	{
357
+		return $this->submit_btn_text;
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * @param string $submit_btn_text
364
+	 * @throws InvalidDataTypeException
365
+	 * @throws InvalidArgumentException
366
+	 */
367
+	public function setSubmitBtnText($submit_btn_text)
368
+	{
369
+		if (! is_string($submit_btn_text)) {
370
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
371
+		}
372
+		if (empty($submit_btn_text)) {
373
+			throw new InvalidArgumentException(
374
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
375
+			);
376
+		}
377
+		$this->submit_btn_text = $submit_btn_text;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * @return string
384
+	 */
385
+	public function formAction()
386
+	{
387
+		return ! empty($this->form_args)
388
+			? add_query_arg($this->form_args, $this->form_action)
389
+			: $this->form_action;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * @param string $form_action
396
+	 * @throws InvalidDataTypeException
397
+	 */
398
+	public function setFormAction($form_action)
399
+	{
400
+		if (! is_string($form_action)) {
401
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
402
+		}
403
+		$this->form_action = $form_action;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * @param array $form_args
410
+	 * @throws InvalidDataTypeException
411
+	 * @throws InvalidArgumentException
412
+	 */
413
+	public function addFormActionArgs($form_args = array())
414
+	{
415
+		if (is_object($form_args)) {
416
+			throw new InvalidDataTypeException(
417
+				'$form_args',
418
+				$form_args,
419
+				'anything other than an object was expected.'
420
+			);
421
+		}
422
+		if (empty($form_args)) {
423
+			throw new InvalidArgumentException(
424
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
425
+			);
426
+		}
427
+		$this->form_args = array_merge($this->form_args, $form_args);
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * @return string
434
+	 */
435
+	public function formConfig()
436
+	{
437
+		return $this->form_config;
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * @param string $form_config
444
+	 * @throws DomainException
445
+	 */
446
+	public function setFormConfig($form_config)
447
+	{
448
+		if (
449
+		! in_array(
450
+			$form_config,
451
+			array(
452
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
453
+				FormHandler::ADD_FORM_TAGS_ONLY,
454
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
455
+				FormHandler::DO_NOT_SETUP_FORM,
456
+			),
457
+			true
458
+		)
459
+		) {
460
+			throw new DomainException(
461
+				sprintf(
462
+					esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
463
+						'event_espresso'),
464
+					$form_config
465
+				)
466
+			);
467
+		}
468
+		$this->form_config = $form_config;
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * called after the form is instantiated
475
+	 * and used for performing any logic that needs to occur early
476
+	 * before any of the other methods are called.
477
+	 * returns true if everything is ok to proceed,
478
+	 * and false if no further form logic should be implemented
479
+	 *
480
+	 * @return boolean
481
+	 */
482
+	public function initialize()
483
+	{
484
+		$this->form_has_errors = EE_Error::has_error(true);
485
+		return true;
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * used for setting up css and js
492
+	 *
493
+	 * @return void
494
+	 * @throws LogicException
495
+	 * @throws EE_Error
496
+	 */
497
+	public function enqueueStylesAndScripts()
498
+	{
499
+		$this->form()->enqueue_js();
500
+	}
501
+
502
+
503
+
504
+	/**
505
+	 * creates and returns the actual form
506
+	 *
507
+	 * @return EE_Form_Section_Proper
508
+	 */
509
+	abstract public function generate();
510
+
511
+
512
+
513
+	/**
514
+	 * creates and returns an EE_Submit_Input labeled "Submit"
515
+	 *
516
+	 * @param string $text
517
+	 * @return EE_Submit_Input
518
+	 */
519
+	public function generateSubmitButton($text = '')
520
+	{
521
+		$text = ! empty($text) ? $text : $this->submitBtnText();
522
+		return new EE_Submit_Input(
523
+			array(
524
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
525
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
526
+				'html_class'            => 'ee-form-submit',
527
+				'html_label'            => '&nbsp;',
528
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
529
+				'default'               => $text,
530
+			)
531
+		);
532
+	}
533
+
534
+
535
+
536
+	/**
537
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
538
+	 *
539
+	 * @param string $text
540
+	 * @return void
541
+	 * @throws LogicException
542
+	 * @throws EE_Error
543
+	 */
544
+	public function appendSubmitButton($text = '')
545
+	{
546
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
547
+			return;
548
+		}
549
+		$this->form->add_subsections(
550
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
551
+			null,
552
+			false
553
+		);
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
560
+	 *
561
+	 * @param string $text
562
+	 * @return EE_Submit_Input
563
+	 */
564
+	public function generateCancelButton($text = '')
565
+	{
566
+		$cancel_button = new EE_Submit_Input(
567
+			array(
568
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
569
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
570
+				'html_class'            => 'ee-cancel-form',
571
+				'html_label'            => '&nbsp;',
572
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
573
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
574
+			)
575
+		);
576
+		$cancel_button->set_button_css_attributes(false);
577
+		return $cancel_button;
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * appends a float clearing div onto end of form
584
+	 *
585
+	 * @return void
586
+	 * @throws EE_Error
587
+	 */
588
+	public function clearFormButtonFloats()
589
+	{
590
+		$this->form->add_subsections(
591
+			array(
592
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
593
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
594
+				),
595
+			),
596
+			null,
597
+			false
598
+		);
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
605
+	 * returns a string of HTML that can be directly echoed in a template
606
+	 *
607
+	 * @return string
608
+	 * @throws LogicException
609
+	 * @throws EE_Error
610
+	 */
611
+	public function display()
612
+	{
613
+		$form_html = apply_filters(
614
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
615
+			''
616
+		);
617
+		$form_config = $this->formConfig();
618
+		if (
619
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
620
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
621
+		) {
622
+			$form_html .= $this->form()->form_open($this->formAction());
623
+		}
624
+		$form_html .= $this->form(true)->get_html($this->form_has_errors);
625
+		if (
626
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
627
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
628
+		) {
629
+			$form_html .= $this->form()->form_close();
630
+		}
631
+		$form_html .= apply_filters(
632
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
633
+			''
634
+		);
635
+		return $form_html;
636
+	}
637
+
638
+
639
+
640
+	/**
641
+	 * handles processing the form submission
642
+	 * returns true or false depending on whether the form was processed successfully or not
643
+	 *
644
+	 * @param array $submitted_form_data
645
+	 * @return array
646
+	 * @throws EE_Error
647
+	 * @throws LogicException
648
+	 * @throws InvalidFormSubmissionException
649
+	 */
650
+	public function process($submitted_form_data = array())
651
+	{
652
+		if (! $this->form()->was_submitted($submitted_form_data)) {
653
+			throw new InvalidFormSubmissionException($this->form_name);
654
+		}
655
+		$this->form(true)->receive_form_submission($submitted_form_data);
656
+		if (! $this->form()->is_valid()) {
657
+			throw new InvalidFormSubmissionException(
658
+				$this->form_name,
659
+				sprintf(
660
+					esc_html__(
661
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
662
+						'event_espresso'
663
+					),
664
+					$this->form_name,
665
+					'<br />',
666
+					$this->form()->submission_error_message()
667
+				)
668
+			);
669
+		}
670
+		return $this->form()->valid_data();
671
+	}
672 672
 
673 673
 
674 674
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 use EventEspresso\core\exceptions\InvalidDataTypeException;
15 15
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
16 16
 
17
-if (! defined('EVENT_ESPRESSO_VERSION')) {
17
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
18 18
     exit('No direct script access allowed');
19 19
 }
20 20
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function form($for_display = false)
181 181
     {
182
-        if (! $this->formIsValid()) {
182
+        if ( ! $this->formIsValid()) {
183 183
             return null;
184 184
         }
185 185
         if ($for_display) {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      */
290 290
     public function setFormName($form_name)
291 291
     {
292
-        if (! is_string($form_name)) {
292
+        if ( ! is_string($form_name)) {
293 293
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
294 294
         }
295 295
         $this->form_name = $form_name;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      */
316 316
     public function setAdminName($admin_name)
317 317
     {
318
-        if (! is_string($admin_name)) {
318
+        if ( ! is_string($admin_name)) {
319 319
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
320 320
         }
321 321
         $this->admin_name = $admin_name;
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     public function setSlug($slug)
343 343
     {
344
-        if (! is_string($slug)) {
344
+        if ( ! is_string($slug)) {
345 345
             throw new InvalidDataTypeException('$slug', $slug, 'string');
346 346
         }
347 347
         $this->slug = $slug;
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public function setSubmitBtnText($submit_btn_text)
368 368
     {
369
-        if (! is_string($submit_btn_text)) {
369
+        if ( ! is_string($submit_btn_text)) {
370 370
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
371 371
         }
372 372
         if (empty($submit_btn_text)) {
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
      */
398 398
     public function setFormAction($form_action)
399 399
     {
400
-        if (! is_string($form_action)) {
400
+        if ( ! is_string($form_action)) {
401 401
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
402 402
         }
403 403
         $this->form_action = $form_action;
@@ -521,11 +521,11 @@  discard block
 block discarded – undo
521 521
         $text = ! empty($text) ? $text : $this->submitBtnText();
522 522
         return new EE_Submit_Input(
523 523
             array(
524
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
525
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
524
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
525
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
526 526
                 'html_class'            => 'ee-form-submit',
527 527
                 'html_label'            => '&nbsp;',
528
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
528
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
529 529
                 'default'               => $text,
530 530
             )
531 531
         );
@@ -543,11 +543,11 @@  discard block
 block discarded – undo
543 543
      */
544 544
     public function appendSubmitButton($text = '')
545 545
     {
546
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
546
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
547 547
             return;
548 548
         }
549 549
         $this->form->add_subsections(
550
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
550
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
551 551
             null,
552 552
             false
553 553
         );
@@ -565,11 +565,11 @@  discard block
 block discarded – undo
565 565
     {
566 566
         $cancel_button = new EE_Submit_Input(
567 567
             array(
568
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
569
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
568
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
569
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
570 570
                 'html_class'            => 'ee-cancel-form',
571 571
                 'html_label'            => '&nbsp;',
572
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
572
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
573 573
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
574 574
             )
575 575
         );
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
         $this->form->add_subsections(
591 591
             array(
592 592
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
593
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
593
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
594 594
                 ),
595 595
             ),
596 596
             null,
@@ -649,11 +649,11 @@  discard block
 block discarded – undo
649 649
      */
650 650
     public function process($submitted_form_data = array())
651 651
     {
652
-        if (! $this->form()->was_submitted($submitted_form_data)) {
652
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
653 653
             throw new InvalidFormSubmissionException($this->form_name);
654 654
         }
655 655
         $this->form(true)->receive_form_submission($submitted_form_data);
656
-        if (! $this->form()->is_valid()) {
656
+        if ( ! $this->form()->is_valid()) {
657 657
             throw new InvalidFormSubmissionException(
658 658
                 $this->form_name,
659 659
                 sprintf(
Please login to merge, or discard this patch.