Completed
Branch feature/checkins-to-csv (6396a5)
by
unknown
07:19 queued 04:57
created
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3684 added lines, -3684 removed lines patch added patch discarded remove patch
@@ -20,2228 +20,2228 @@  discard block
 block discarded – undo
20 20
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Registration
25
-     */
26
-    private $_registration;
27
-
28
-    /**
29
-     * @var EE_Event
30
-     */
31
-    private $_reg_event;
32
-
33
-    /**
34
-     * @var EE_Session
35
-     */
36
-    private $_session;
37
-
38
-    /**
39
-     * @var array
40
-     */
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-    /**
52
-     * @var EEM_Registration $registration_model
53
-     */
54
-    private $registration_model;
55
-
56
-    /**
57
-     * @var EEM_Attendee $attendee_model
58
-     */
59
-    private $attendee_model;
60
-
61
-    /**
62
-     * @var EEM_Event $event_model
63
-     */
64
-    private $event_model;
65
-
66
-    /**
67
-     * @var EEM_Status $status_model
68
-     */
69
-    private $status_model;
70
-
71
-
72
-    /**
73
-     * @param bool $routing
74
-     * @throws EE_Error
75
-     * @throws InvalidArgumentException
76
-     * @throws InvalidDataTypeException
77
-     * @throws InvalidInterfaceException
78
-     * @throws ReflectionException
79
-     */
80
-    public function __construct($routing = true)
81
-    {
82
-        parent::__construct($routing);
83
-        add_action('wp_loaded', [$this, 'wp_loaded']);
84
-    }
85
-
86
-
87
-    /**
88
-     * @return EEM_Registration
89
-     * @throws InvalidArgumentException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidInterfaceException
92
-     * @since 4.10.2.p
93
-     */
94
-    protected function getRegistrationModel()
95
-    {
96
-        if (! $this->registration_model instanceof EEM_Registration) {
97
-            $this->registration_model = $this->getLoader()->getShared('EEM_Registration');
98
-        }
99
-        return $this->registration_model;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return EEM_Attendee
105
-     * @throws InvalidArgumentException
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidInterfaceException
108
-     * @since 4.10.2.p
109
-     */
110
-    protected function getAttendeeModel()
111
-    {
112
-        if (! $this->attendee_model instanceof EEM_Attendee) {
113
-            $this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
114
-        }
115
-        return $this->attendee_model;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return EEM_Event
121
-     * @throws InvalidArgumentException
122
-     * @throws InvalidDataTypeException
123
-     * @throws InvalidInterfaceException
124
-     * @since 4.10.2.p
125
-     */
126
-    protected function getEventModel()
127
-    {
128
-        if (! $this->event_model instanceof EEM_Event) {
129
-            $this->event_model = $this->getLoader()->getShared('EEM_Event');
130
-        }
131
-        return $this->event_model;
132
-    }
133
-
134
-
135
-    /**
136
-     * @return EEM_Status
137
-     * @throws InvalidArgumentException
138
-     * @throws InvalidDataTypeException
139
-     * @throws InvalidInterfaceException
140
-     * @since 4.10.2.p
141
-     */
142
-    protected function getStatusModel()
143
-    {
144
-        if (! $this->status_model instanceof EEM_Status) {
145
-            $this->status_model = $this->getLoader()->getShared('EEM_Status');
146
-        }
147
-        return $this->status_model;
148
-    }
149
-
150
-
151
-    public function wp_loaded()
152
-    {
153
-        // when adding a new registration...
154
-        $action = $this->request->getRequestParam('action');
155
-        if ($action === 'new_registration') {
156
-            EE_System::do_not_cache();
157
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
158
-                // and it's NOT the attendee information reg step
159
-                // force cookie expiration by setting time to last week
160
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
161
-                // and update the global
162
-                $_COOKIE['ee_registration_added'] = 0;
163
-            }
164
-        }
165
-    }
166
-
167
-
168
-    protected function _init_page_props()
169
-    {
170
-        $this->page_slug        = REG_PG_SLUG;
171
-        $this->_admin_base_url  = REG_ADMIN_URL;
172
-        $this->_admin_base_path = REG_ADMIN;
173
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
174
-        $this->_cpt_routes      = [
175
-            'add_new_attendee' => 'espresso_attendees',
176
-            'edit_attendee'    => 'espresso_attendees',
177
-            'insert_attendee'  => 'espresso_attendees',
178
-            'update_attendee'  => 'espresso_attendees',
179
-        ];
180
-        $this->_cpt_model_names = [
181
-            'add_new_attendee' => 'EEM_Attendee',
182
-            'edit_attendee'    => 'EEM_Attendee',
183
-        ];
184
-        $this->_cpt_edit_routes = [
185
-            'espresso_attendees' => 'edit_attendee',
186
-        ];
187
-        $this->_pagenow_map     = [
188
-            'add_new_attendee' => 'post-new.php',
189
-            'edit_attendee'    => 'post.php',
190
-            'trash'            => 'post.php',
191
-        ];
192
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
193
-        // add filters so that the comment urls don't take users to a confusing 404 page
194
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
195
-    }
196
-
197
-
198
-    /**
199
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
200
-     * @param WP_Comment $comment The current comment object.
201
-     * @return string
202
-     */
203
-    public function clear_comment_link($link, WP_Comment $comment)
204
-    {
205
-        // gotta make sure this only happens on this route
206
-        $post_type = get_post_type($comment->comment_post_ID);
207
-        if ($post_type === 'espresso_attendees') {
208
-            return '#commentsdiv';
209
-        }
210
-        return $link;
211
-    }
212
-
213
-
214
-    protected function _ajax_hooks()
215
-    {
216
-        // todo: all hooks for registrations ajax goes in here
217
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
218
-    }
219
-
220
-
221
-    protected function _define_page_props()
222
-    {
223
-        $this->_admin_page_title = $this->page_label;
224
-        $this->_labels           = [
225
-            'buttons'                      => [
226
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
227
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
228
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
229
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
230
-                'report_datetime'     => esc_html__('Datetime Registrations CSV Report', 'event_espresso'),
231
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
232
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
233
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
234
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
235
-            ],
236
-            'publishbox'                   => [
237
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
238
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
239
-            ],
240
-            'hide_add_button_on_cpt_route' => [
241
-                'edit_attendee' => true,
242
-            ],
243
-        ];
244
-    }
245
-
246
-
247
-    /**
248
-     * grab url requests and route them
249
-     *
250
-     * @return void
251
-     * @throws EE_Error
252
-     */
253
-    public function _set_page_routes()
254
-    {
255
-        $this->_get_registration_status_array();
256
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
257
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
258
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
259
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
260
-        $this->_page_routes = [
261
-            'default'                             => [
262
-                'func'       => '_registrations_overview_list_table',
263
-                'capability' => 'ee_read_registrations',
264
-            ],
265
-            'view_registration'                   => [
266
-                'func'       => '_registration_details',
267
-                'capability' => 'ee_read_registration',
268
-                'obj_id'     => $REG_ID,
269
-            ],
270
-            'edit_registration'                   => [
271
-                'func'               => '_update_attendee_registration_form',
272
-                'noheader'           => true,
273
-                'headers_sent_route' => 'view_registration',
274
-                'capability'         => 'ee_edit_registration',
275
-                'obj_id'             => $REG_ID,
276
-                '_REG_ID'            => $REG_ID,
277
-            ],
278
-            'trash_registrations'                 => [
279
-                'func'       => '_trash_or_restore_registrations',
280
-                'args'       => ['trash' => true],
281
-                'noheader'   => true,
282
-                'capability' => 'ee_delete_registrations',
283
-            ],
284
-            'restore_registrations'               => [
285
-                'func'       => '_trash_or_restore_registrations',
286
-                'args'       => ['trash' => false],
287
-                'noheader'   => true,
288
-                'capability' => 'ee_delete_registrations',
289
-            ],
290
-            'delete_registrations'                => [
291
-                'func'       => '_delete_registrations',
292
-                'noheader'   => true,
293
-                'capability' => 'ee_delete_registrations',
294
-            ],
295
-            'new_registration'                    => [
296
-                'func'       => 'new_registration',
297
-                'capability' => 'ee_edit_registrations',
298
-            ],
299
-            'process_reg_step'                    => [
300
-                'func'       => 'process_reg_step',
301
-                'noheader'   => true,
302
-                'capability' => 'ee_edit_registrations',
303
-            ],
304
-            'redirect_to_txn'                     => [
305
-                'func'       => 'redirect_to_txn',
306
-                'noheader'   => true,
307
-                'capability' => 'ee_edit_registrations',
308
-            ],
309
-            'change_reg_status'                   => [
310
-                'func'       => '_change_reg_status',
311
-                'noheader'   => true,
312
-                'capability' => 'ee_edit_registration',
313
-                'obj_id'     => $REG_ID,
314
-            ],
315
-            'approve_registration'                => [
316
-                'func'       => 'approve_registration',
317
-                'noheader'   => true,
318
-                'capability' => 'ee_edit_registration',
319
-                'obj_id'     => $REG_ID,
320
-            ],
321
-            'approve_and_notify_registration'     => [
322
-                'func'       => 'approve_registration',
323
-                'noheader'   => true,
324
-                'args'       => [true],
325
-                'capability' => 'ee_edit_registration',
326
-                'obj_id'     => $REG_ID,
327
-            ],
328
-            'approve_registrations'               => [
329
-                'func'       => 'bulk_action_on_registrations',
330
-                'noheader'   => true,
331
-                'capability' => 'ee_edit_registrations',
332
-                'args'       => ['approve'],
333
-            ],
334
-            'approve_and_notify_registrations'    => [
335
-                'func'       => 'bulk_action_on_registrations',
336
-                'noheader'   => true,
337
-                'capability' => 'ee_edit_registrations',
338
-                'args'       => ['approve', true],
339
-            ],
340
-            'decline_registration'                => [
341
-                'func'       => 'decline_registration',
342
-                'noheader'   => true,
343
-                'capability' => 'ee_edit_registration',
344
-                'obj_id'     => $REG_ID,
345
-            ],
346
-            'decline_and_notify_registration'     => [
347
-                'func'       => 'decline_registration',
348
-                'noheader'   => true,
349
-                'args'       => [true],
350
-                'capability' => 'ee_edit_registration',
351
-                'obj_id'     => $REG_ID,
352
-            ],
353
-            'decline_registrations'               => [
354
-                'func'       => 'bulk_action_on_registrations',
355
-                'noheader'   => true,
356
-                'capability' => 'ee_edit_registrations',
357
-                'args'       => ['decline'],
358
-            ],
359
-            'decline_and_notify_registrations'    => [
360
-                'func'       => 'bulk_action_on_registrations',
361
-                'noheader'   => true,
362
-                'capability' => 'ee_edit_registrations',
363
-                'args'       => ['decline', true],
364
-            ],
365
-            'pending_registration'                => [
366
-                'func'       => 'pending_registration',
367
-                'noheader'   => true,
368
-                'capability' => 'ee_edit_registration',
369
-                'obj_id'     => $REG_ID,
370
-            ],
371
-            'pending_and_notify_registration'     => [
372
-                'func'       => 'pending_registration',
373
-                'noheader'   => true,
374
-                'args'       => [true],
375
-                'capability' => 'ee_edit_registration',
376
-                'obj_id'     => $REG_ID,
377
-            ],
378
-            'pending_registrations'               => [
379
-                'func'       => 'bulk_action_on_registrations',
380
-                'noheader'   => true,
381
-                'capability' => 'ee_edit_registrations',
382
-                'args'       => ['pending'],
383
-            ],
384
-            'pending_and_notify_registrations'    => [
385
-                'func'       => 'bulk_action_on_registrations',
386
-                'noheader'   => true,
387
-                'capability' => 'ee_edit_registrations',
388
-                'args'       => ['pending', true],
389
-            ],
390
-            'no_approve_registration'             => [
391
-                'func'       => 'not_approve_registration',
392
-                'noheader'   => true,
393
-                'capability' => 'ee_edit_registration',
394
-                'obj_id'     => $REG_ID,
395
-            ],
396
-            'no_approve_and_notify_registration'  => [
397
-                'func'       => 'not_approve_registration',
398
-                'noheader'   => true,
399
-                'args'       => [true],
400
-                'capability' => 'ee_edit_registration',
401
-                'obj_id'     => $REG_ID,
402
-            ],
403
-            'no_approve_registrations'            => [
404
-                'func'       => 'bulk_action_on_registrations',
405
-                'noheader'   => true,
406
-                'capability' => 'ee_edit_registrations',
407
-                'args'       => ['not_approve'],
408
-            ],
409
-            'no_approve_and_notify_registrations' => [
410
-                'func'       => 'bulk_action_on_registrations',
411
-                'noheader'   => true,
412
-                'capability' => 'ee_edit_registrations',
413
-                'args'       => ['not_approve', true],
414
-            ],
415
-            'cancel_registration'                 => [
416
-                'func'       => 'cancel_registration',
417
-                'noheader'   => true,
418
-                'capability' => 'ee_edit_registration',
419
-                'obj_id'     => $REG_ID,
420
-            ],
421
-            'cancel_and_notify_registration'      => [
422
-                'func'       => 'cancel_registration',
423
-                'noheader'   => true,
424
-                'args'       => [true],
425
-                'capability' => 'ee_edit_registration',
426
-                'obj_id'     => $REG_ID,
427
-            ],
428
-            'cancel_registrations'                => [
429
-                'func'       => 'bulk_action_on_registrations',
430
-                'noheader'   => true,
431
-                'capability' => 'ee_edit_registrations',
432
-                'args'       => ['cancel'],
433
-            ],
434
-            'cancel_and_notify_registrations'     => [
435
-                'func'       => 'bulk_action_on_registrations',
436
-                'noheader'   => true,
437
-                'capability' => 'ee_edit_registrations',
438
-                'args'       => ['cancel', true],
439
-            ],
440
-            'wait_list_registration'              => [
441
-                'func'       => 'wait_list_registration',
442
-                'noheader'   => true,
443
-                'capability' => 'ee_edit_registration',
444
-                'obj_id'     => $REG_ID,
445
-            ],
446
-            'wait_list_and_notify_registration'   => [
447
-                'func'       => 'wait_list_registration',
448
-                'noheader'   => true,
449
-                'args'       => [true],
450
-                'capability' => 'ee_edit_registration',
451
-                'obj_id'     => $REG_ID,
452
-            ],
453
-            'contact_list'                        => [
454
-                'func'       => '_attendee_contact_list_table',
455
-                'capability' => 'ee_read_contacts',
456
-            ],
457
-            'add_new_attendee'                    => [
458
-                'func' => '_create_new_cpt_item',
459
-                'args' => [
460
-                    'new_attendee' => true,
461
-                    'capability'   => 'ee_edit_contacts',
462
-                ],
463
-            ],
464
-            'edit_attendee'                       => [
465
-                'func'       => '_edit_cpt_item',
466
-                'capability' => 'ee_edit_contacts',
467
-                'obj_id'     => $ATT_ID,
468
-            ],
469
-            'duplicate_attendee'                  => [
470
-                'func'       => '_duplicate_attendee',
471
-                'noheader'   => true,
472
-                'capability' => 'ee_edit_contacts',
473
-                'obj_id'     => $ATT_ID,
474
-            ],
475
-            'insert_attendee'                     => [
476
-                'func'       => '_insert_or_update_attendee',
477
-                'args'       => [
478
-                    'new_attendee' => true,
479
-                ],
480
-                'noheader'   => true,
481
-                'capability' => 'ee_edit_contacts',
482
-            ],
483
-            'update_attendee'                     => [
484
-                'func'       => '_insert_or_update_attendee',
485
-                'args'       => [
486
-                    'new_attendee' => false,
487
-                ],
488
-                'noheader'   => true,
489
-                'capability' => 'ee_edit_contacts',
490
-                'obj_id'     => $ATT_ID,
491
-            ],
492
-            'trash_attendees'                     => [
493
-                'func'       => '_trash_or_restore_attendees',
494
-                'args'       => [
495
-                    'trash' => 'true',
496
-                ],
497
-                'noheader'   => true,
498
-                'capability' => 'ee_delete_contacts',
499
-            ],
500
-            'trash_attendee'                      => [
501
-                'func'       => '_trash_or_restore_attendees',
502
-                'args'       => [
503
-                    'trash' => true,
504
-                ],
505
-                'noheader'   => true,
506
-                'capability' => 'ee_delete_contacts',
507
-                'obj_id'     => $ATT_ID,
508
-            ],
509
-            'restore_attendees'                   => [
510
-                'func'       => '_trash_or_restore_attendees',
511
-                'args'       => [
512
-                    'trash' => false,
513
-                ],
514
-                'noheader'   => true,
515
-                'capability' => 'ee_delete_contacts',
516
-                'obj_id'     => $ATT_ID,
517
-            ],
518
-            'resend_registration'                 => [
519
-                'func'       => '_resend_registration',
520
-                'noheader'   => true,
521
-                'capability' => 'ee_send_message',
522
-            ],
523
-            'registrations_report'                => [
524
-                'func'       => '_registrations_report',
525
-                'noheader'   => true,
526
-                'capability' => 'ee_read_registrations',
527
-            ],
528
-            'contact_list_export'                 => [
529
-                'func'       => '_contact_list_export',
530
-                'noheader'   => true,
531
-                'capability' => 'export',
532
-            ],
533
-            'contact_list_report'                 => [
534
-                'func'       => '_contact_list_report',
535
-                'noheader'   => true,
536
-                'capability' => 'ee_read_contacts',
537
-            ],
538
-        ];
539
-    }
540
-
541
-
542
-    protected function _set_page_config()
543
-    {
544
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
545
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
546
-        $this->_page_config = [
547
-            'default'           => [
548
-                'nav'           => [
549
-                    'label' => esc_html__('Overview', 'event_espresso'),
550
-                    'order' => 5,
551
-                ],
552
-                'help_tabs'     => [
553
-                    'registrations_overview_help_tab'                       => [
554
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
555
-                        'filename' => 'registrations_overview',
556
-                    ],
557
-                    'registrations_overview_table_column_headings_help_tab' => [
558
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
559
-                        'filename' => 'registrations_overview_table_column_headings',
560
-                    ],
561
-                    'registrations_overview_filters_help_tab'               => [
562
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
563
-                        'filename' => 'registrations_overview_filters',
564
-                    ],
565
-                    'registrations_overview_views_help_tab'                 => [
566
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
567
-                        'filename' => 'registrations_overview_views',
568
-                    ],
569
-                    'registrations_regoverview_other_help_tab'              => [
570
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
571
-                        'filename' => 'registrations_overview_other',
572
-                    ],
573
-                ],
574
-                'qtips'         => ['Registration_List_Table_Tips'],
575
-                'list_table'    => 'EE_Registrations_List_Table',
576
-                'require_nonce' => false,
577
-            ],
578
-            'view_registration' => [
579
-                'nav'           => [
580
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
581
-                    'order'      => 15,
582
-                    'url'        => $REG_ID
583
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
584
-                        : $this->_admin_base_url,
585
-                    'persistent' => false,
586
-                ],
587
-                'help_tabs'     => [
588
-                    'registrations_details_help_tab'                    => [
589
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
590
-                        'filename' => 'registrations_details',
591
-                    ],
592
-                    'registrations_details_table_help_tab'              => [
593
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
594
-                        'filename' => 'registrations_details_table',
595
-                    ],
596
-                    'registrations_details_form_answers_help_tab'       => [
597
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
598
-                        'filename' => 'registrations_details_form_answers',
599
-                    ],
600
-                    'registrations_details_registrant_details_help_tab' => [
601
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
602
-                        'filename' => 'registrations_details_registrant_details',
603
-                    ],
604
-                ],
605
-                'metaboxes'     => array_merge(
606
-                    $this->_default_espresso_metaboxes,
607
-                    ['_registration_details_metaboxes']
608
-                ),
609
-                'require_nonce' => false,
610
-            ],
611
-            'new_registration'  => [
612
-                'nav'           => [
613
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
614
-                    'url'        => '#',
615
-                    'order'      => 15,
616
-                    'persistent' => false,
617
-                ],
618
-                'metaboxes'     => $this->_default_espresso_metaboxes,
619
-                'labels'        => [
620
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
621
-                ],
622
-                'require_nonce' => false,
623
-            ],
624
-            'add_new_attendee'  => [
625
-                'nav'           => [
626
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
627
-                    'order'      => 15,
628
-                    'persistent' => false,
629
-                ],
630
-                'metaboxes'     => array_merge(
631
-                    $this->_default_espresso_metaboxes,
632
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
633
-                ),
634
-                'require_nonce' => false,
635
-            ],
636
-            'edit_attendee'     => [
637
-                'nav'           => [
638
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
639
-                    'order'      => 15,
640
-                    'persistent' => false,
641
-                    'url'        => $ATT_ID
642
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
643
-                        : $this->_admin_base_url,
644
-                ],
645
-                'metaboxes'     => ['attendee_editor_metaboxes'],
646
-                'require_nonce' => false,
647
-            ],
648
-            'contact_list'      => [
649
-                'nav'           => [
650
-                    'label' => esc_html__('Contact List', 'event_espresso'),
651
-                    'order' => 20,
652
-                ],
653
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
654
-                'help_tabs'     => [
655
-                    'registrations_contact_list_help_tab'                       => [
656
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
657
-                        'filename' => 'registrations_contact_list',
658
-                    ],
659
-                    'registrations_contact-list_table_column_headings_help_tab' => [
660
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
661
-                        'filename' => 'registrations_contact_list_table_column_headings',
662
-                    ],
663
-                    'registrations_contact_list_views_help_tab'                 => [
664
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
665
-                        'filename' => 'registrations_contact_list_views',
666
-                    ],
667
-                    'registrations_contact_list_other_help_tab'                 => [
668
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
669
-                        'filename' => 'registrations_contact_list_other',
670
-                    ],
671
-                ],
672
-                'metaboxes'     => [],
673
-                'require_nonce' => false,
674
-            ],
675
-            // override default cpt routes
676
-            'create_new'        => '',
677
-            'edit'              => '',
678
-        ];
679
-    }
680
-
681
-
682
-    /**
683
-     * The below methods aren't used by this class currently
684
-     */
685
-    protected function _add_screen_options()
686
-    {
687
-    }
688
-
689
-
690
-    protected function _add_feature_pointers()
691
-    {
692
-    }
693
-
694
-
695
-    public function admin_init()
696
-    {
697
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
698
-            'click "Update Registration Questions" to save your changes',
699
-            'event_espresso'
700
-        );
701
-    }
702
-
703
-
704
-    public function admin_notices()
705
-    {
706
-    }
707
-
708
-
709
-    public function admin_footer_scripts()
710
-    {
711
-    }
712
-
713
-
714
-    /**
715
-     * get list of registration statuses
716
-     *
717
-     * @return void
718
-     * @throws EE_Error
719
-     */
720
-    private function _get_registration_status_array()
721
-    {
722
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
723
-    }
724
-
725
-
726
-    /**
727
-     * @throws InvalidArgumentException
728
-     * @throws InvalidDataTypeException
729
-     * @throws InvalidInterfaceException
730
-     * @since 4.10.2.p
731
-     */
732
-    protected function _add_screen_options_default()
733
-    {
734
-        $this->_per_page_screen_option();
735
-    }
736
-
737
-
738
-    /**
739
-     * @throws InvalidArgumentException
740
-     * @throws InvalidDataTypeException
741
-     * @throws InvalidInterfaceException
742
-     * @since 4.10.2.p
743
-     */
744
-    protected function _add_screen_options_contact_list()
745
-    {
746
-        $page_title              = $this->_admin_page_title;
747
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
-        $this->_per_page_screen_option();
749
-        $this->_admin_page_title = $page_title;
750
-    }
751
-
752
-
753
-    public function load_scripts_styles()
754
-    {
755
-        // style
756
-        wp_register_style(
757
-            'espresso_reg',
758
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
-            ['ee-admin-css'],
760
-            EVENT_ESPRESSO_VERSION
761
-        );
762
-        wp_enqueue_style('espresso_reg');
763
-        // script
764
-        wp_register_script(
765
-            'espresso_reg',
766
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
768
-            EVENT_ESPRESSO_VERSION,
769
-            true
770
-        );
771
-        wp_enqueue_script('espresso_reg');
772
-    }
773
-
774
-
775
-    /**
776
-     * @throws EE_Error
777
-     * @throws InvalidArgumentException
778
-     * @throws InvalidDataTypeException
779
-     * @throws InvalidInterfaceException
780
-     * @throws ReflectionException
781
-     * @since 4.10.2.p
782
-     */
783
-    public function load_scripts_styles_edit_attendee()
784
-    {
785
-        // stuff to only show up on our attendee edit details page.
786
-        $attendee_details_translations = [
787
-            'att_publish_text' => sprintf(
788
-            /* translators: The date and time */
789
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
-            ),
792
-        ];
793
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
-        wp_enqueue_script('jquery-validate');
795
-    }
796
-
797
-
798
-    /**
799
-     * @throws EE_Error
800
-     * @throws InvalidArgumentException
801
-     * @throws InvalidDataTypeException
802
-     * @throws InvalidInterfaceException
803
-     * @throws ReflectionException
804
-     * @since 4.10.2.p
805
-     */
806
-    public function load_scripts_styles_view_registration()
807
-    {
808
-        // styles
809
-        wp_enqueue_style('espresso-ui-theme');
810
-        // scripts
811
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
812
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
813
-    }
814
-
815
-
816
-    public function load_scripts_styles_contact_list()
817
-    {
818
-        wp_dequeue_style('espresso_reg');
819
-        wp_register_style(
820
-            'espresso_att',
821
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
-            ['ee-admin-css'],
823
-            EVENT_ESPRESSO_VERSION
824
-        );
825
-        wp_enqueue_style('espresso_att');
826
-    }
827
-
828
-
829
-    public function load_scripts_styles_new_registration()
830
-    {
831
-        wp_register_script(
832
-            'ee-spco-for-admin',
833
-            REG_ASSETS_URL . 'spco_for_admin.js',
834
-            ['underscore', 'jquery'],
835
-            EVENT_ESPRESSO_VERSION,
836
-            true
837
-        );
838
-        wp_enqueue_script('ee-spco-for-admin');
839
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
-        EE_Form_Section_Proper::wp_enqueue_scripts();
841
-        EED_Ticket_Selector::load_tckt_slctr_assets();
842
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
843
-    }
844
-
845
-
846
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
-    {
848
-        add_filter('FHEE_load_EE_messages', '__return_true');
849
-    }
850
-
851
-
852
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
-    {
854
-        add_filter('FHEE_load_EE_messages', '__return_true');
855
-    }
856
-
857
-
858
-    /**
859
-     * @throws EE_Error
860
-     * @throws InvalidArgumentException
861
-     * @throws InvalidDataTypeException
862
-     * @throws InvalidInterfaceException
863
-     * @throws ReflectionException
864
-     * @since 4.10.2.p
865
-     */
866
-    protected function _set_list_table_views_default()
867
-    {
868
-        // for notification related bulk actions we need to make sure only active messengers have an option.
869
-        EED_Messages::set_autoloaders();
870
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
871
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
873
-        // key= bulk_action_slug, value= message type.
874
-        $match_array = [
875
-            'approve_registrations'    => 'registration',
876
-            'decline_registrations'    => 'declined_registration',
877
-            'pending_registrations'    => 'pending_approval',
878
-            'no_approve_registrations' => 'not_approved_registration',
879
-            'cancel_registrations'     => 'cancelled_registration',
880
-        ];
881
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
882
-            'ee_send_message',
883
-            'batch_send_messages'
884
-        );
885
-        /** setup reg status bulk actions **/
886
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
-                'Approve and Notify Registrations',
890
-                'event_espresso'
891
-            );
892
-        }
893
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
-                'Decline and Notify Registrations',
897
-                'event_espresso'
898
-            );
899
-        }
900
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
901
-            'Set Registrations to Pending Payment',
902
-            'event_espresso'
903
-        );
904
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
-                'Set Registrations to Pending Payment and Notify',
907
-                'event_espresso'
908
-            );
909
-        }
910
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
-            'Set Registrations to Not Approved',
912
-            'event_espresso'
913
-        );
914
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
-                'Set Registrations to Not Approved and Notify',
917
-                'event_espresso'
918
-            );
919
-        }
920
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
-                'Cancel Registrations and Notify',
924
-                'event_espresso'
925
-            );
926
-        }
927
-        $def_reg_status_actions = apply_filters(
928
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
-            $def_reg_status_actions,
930
-            $active_mts,
931
-            $can_send
932
-        );
933
-
934
-        $this->_views = [
935
-            'all'   => [
936
-                'slug'        => 'all',
937
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
-                'count'       => 0,
939
-                'bulk_action' => array_merge(
940
-                    $def_reg_status_actions,
941
-                    [
942
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
-                    ]
944
-                ),
945
-            ],
946
-            'month' => [
947
-                'slug'        => 'month',
948
-                'label'       => esc_html__('This Month', 'event_espresso'),
949
-                'count'       => 0,
950
-                'bulk_action' => array_merge(
951
-                    $def_reg_status_actions,
952
-                    [
953
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
-                    ]
955
-                ),
956
-            ],
957
-            'today' => [
958
-                'slug'        => 'today',
959
-                'label'       => sprintf(
960
-                    esc_html__('Today - %s', 'event_espresso'),
961
-                    date('M d, Y', current_time('timestamp'))
962
-                ),
963
-                'count'       => 0,
964
-                'bulk_action' => array_merge(
965
-                    $def_reg_status_actions,
966
-                    [
967
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
-                    ]
969
-                ),
970
-            ],
971
-        ];
972
-        if (
973
-            EE_Registry::instance()->CAP->current_user_can(
974
-                'ee_delete_registrations',
975
-                'espresso_registrations_delete_registration'
976
-            )
977
-        ) {
978
-            $this->_views['incomplete'] = [
979
-                'slug'        => 'incomplete',
980
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
981
-                'count'       => 0,
982
-                'bulk_action' => [
983
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
-                ],
985
-            ];
986
-            $this->_views['trash']      = [
987
-                'slug'        => 'trash',
988
-                'label'       => esc_html__('Trash', 'event_espresso'),
989
-                'count'       => 0,
990
-                'bulk_action' => [
991
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
-                ],
994
-            ];
995
-        }
996
-    }
997
-
998
-
999
-    protected function _set_list_table_views_contact_list()
1000
-    {
1001
-        $this->_views = [
1002
-            'in_use' => [
1003
-                'slug'        => 'in_use',
1004
-                'label'       => esc_html__('In Use', 'event_espresso'),
1005
-                'count'       => 0,
1006
-                'bulk_action' => [
1007
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
-                ],
1009
-            ],
1010
-        ];
1011
-        if (
1012
-            EE_Registry::instance()->CAP->current_user_can(
1013
-                'ee_delete_contacts',
1014
-                'espresso_registrations_trash_attendees'
1015
-            )
1016
-        ) {
1017
-            $this->_views['trash'] = [
1018
-                'slug'        => 'trash',
1019
-                'label'       => esc_html__('Trash', 'event_espresso'),
1020
-                'count'       => 0,
1021
-                'bulk_action' => [
1022
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
-                ],
1024
-            ];
1025
-        }
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * @return array
1031
-     * @throws EE_Error
1032
-     */
1033
-    protected function _registration_legend_items()
1034
-    {
1035
-        $fc_items = [
1036
-            'star-icon'        => [
1037
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1038
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1039
-            ],
1040
-            'view_details'     => [
1041
-                'class' => 'dashicons dashicons-clipboard',
1042
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1043
-            ],
1044
-            'edit_attendee'    => [
1045
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1046
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1047
-            ],
1048
-            'view_transaction' => [
1049
-                'class' => 'dashicons dashicons-cart',
1050
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1051
-            ],
1052
-            'view_invoice'     => [
1053
-                'class' => 'dashicons dashicons-media-spreadsheet',
1054
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1055
-            ],
1056
-        ];
1057
-        if (
1058
-            EE_Registry::instance()->CAP->current_user_can(
1059
-                'ee_send_message',
1060
-                'espresso_registrations_resend_registration'
1061
-            )
1062
-        ) {
1063
-            $fc_items['resend_registration'] = [
1064
-                'class' => 'dashicons dashicons-email-alt',
1065
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1066
-            ];
1067
-        } else {
1068
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1069
-        }
1070
-        if (
1071
-            EE_Registry::instance()->CAP->current_user_can(
1072
-                'ee_read_global_messages',
1073
-                'view_filtered_messages'
1074
-            )
1075
-        ) {
1076
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1077
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1078
-                $fc_items['view_related_messages'] = [
1079
-                    'class' => $related_for_icon['css_class'],
1080
-                    'desc'  => $related_for_icon['label'],
1081
-                ];
1082
-            }
1083
-        }
1084
-        $sc_items = [
1085
-            'approved_status'   => [
1086
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1087
-                'desc'  => EEH_Template::pretty_status(
1088
-                    EEM_Registration::status_id_approved,
1089
-                    false,
1090
-                    'sentence'
1091
-                ),
1092
-            ],
1093
-            'pending_status'    => [
1094
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1095
-                'desc'  => EEH_Template::pretty_status(
1096
-                    EEM_Registration::status_id_pending_payment,
1097
-                    false,
1098
-                    'sentence'
1099
-                ),
1100
-            ],
1101
-            'wait_list'         => [
1102
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1103
-                'desc'  => EEH_Template::pretty_status(
1104
-                    EEM_Registration::status_id_wait_list,
1105
-                    false,
1106
-                    'sentence'
1107
-                ),
1108
-            ],
1109
-            'incomplete_status' => [
1110
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1111
-                'desc'  => EEH_Template::pretty_status(
1112
-                    EEM_Registration::status_id_incomplete,
1113
-                    false,
1114
-                    'sentence'
1115
-                ),
1116
-            ],
1117
-            'not_approved'      => [
1118
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1119
-                'desc'  => EEH_Template::pretty_status(
1120
-                    EEM_Registration::status_id_not_approved,
1121
-                    false,
1122
-                    'sentence'
1123
-                ),
1124
-            ],
1125
-            'declined_status'   => [
1126
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1127
-                'desc'  => EEH_Template::pretty_status(
1128
-                    EEM_Registration::status_id_declined,
1129
-                    false,
1130
-                    'sentence'
1131
-                ),
1132
-            ],
1133
-            'cancelled_status'  => [
1134
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1135
-                'desc'  => EEH_Template::pretty_status(
1136
-                    EEM_Registration::status_id_cancelled,
1137
-                    false,
1138
-                    'sentence'
1139
-                ),
1140
-            ],
1141
-        ];
1142
-        return array_merge($fc_items, $sc_items);
1143
-    }
1144
-
1145
-
1146
-
1147
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1148
-
1149
-
1150
-    /**
1151
-     * @throws DomainException
1152
-     * @throws EE_Error
1153
-     * @throws InvalidArgumentException
1154
-     * @throws InvalidDataTypeException
1155
-     * @throws InvalidInterfaceException
1156
-     */
1157
-    protected function _registrations_overview_list_table()
1158
-    {
1159
-        $this->appendAddNewRegistrationButtonToPageTitle();
1160
-        $header_text                  = '';
1161
-        $admin_page_header_decorators = [
1162
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1164
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1165
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1166
-        ];
1167
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1168
-            $filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1169
-            $header_text             = $filter_header_decorator->getHeaderText($header_text);
1170
-        }
1171
-        $this->_template_args['admin_page_header'] = $header_text;
1172
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1173
-        $this->display_admin_list_table_page_with_no_sidebar();
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * @throws EE_Error
1179
-     * @throws InvalidArgumentException
1180
-     * @throws InvalidDataTypeException
1181
-     * @throws InvalidInterfaceException
1182
-     */
1183
-    private function appendAddNewRegistrationButtonToPageTitle()
1184
-    {
1185
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1186
-        if (
1187
-            $EVT_ID
1188
-            && EE_Registry::instance()->CAP->current_user_can(
1189
-                'ee_edit_registrations',
1190
-                'espresso_registrations_new_registration',
1191
-                $EVT_ID
1192
-            )
1193
-        ) {
1194
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
-                'new_registration',
1196
-                'add-registrant',
1197
-                ['event_id' => $EVT_ID],
1198
-                'add-new-h2'
1199
-            );
1200
-        }
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * This sets the _registration property for the registration details screen
1206
-     *
1207
-     * @return void
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws InvalidDataTypeException
1211
-     * @throws InvalidInterfaceException
1212
-     */
1213
-    private function _set_registration_object()
1214
-    {
1215
-        // get out if we've already set the object
1216
-        if ($this->_registration instanceof EE_Registration) {
1217
-            return;
1218
-        }
1219
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1220
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1221
-            return;
1222
-        }
1223
-        $error_msg = sprintf(
1224
-            esc_html__(
1225
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1226
-                'event_espresso'
1227
-            ),
1228
-            $REG_ID
1229
-        );
1230
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1231
-        $this->_registration = null;
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * Used to retrieve registrations for the list table.
1237
-     *
1238
-     * @param int  $per_page
1239
-     * @param bool $count
1240
-     * @param bool $this_month
1241
-     * @param bool $today
1242
-     * @return EE_Registration[]|int
1243
-     * @throws EE_Error
1244
-     * @throws InvalidArgumentException
1245
-     * @throws InvalidDataTypeException
1246
-     * @throws InvalidInterfaceException
1247
-     */
1248
-    public function get_registrations(
1249
-        $per_page = 10,
1250
-        $count = false,
1251
-        $this_month = false,
1252
-        $today = false
1253
-    ) {
1254
-        if ($this_month) {
1255
-            $this->request->setRequestParam('status', 'month');
1256
-        }
1257
-        if ($today) {
1258
-            $this->request->setRequestParam('status', 'today');
1259
-        }
1260
-        $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1261
-        /**
1262
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
-         *
1264
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1265
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1266
-         *                      or if you have the development copy of EE you can view this at the path:
1267
-         *                      /docs/G--Model-System/model-query-params.md
1268
-         */
1269
-        $query_params['group_by'] = '';
1270
-
1271
-        return $count
1272
-            ? $this->getRegistrationModel()->count($query_params)
1273
-            /** @type EE_Registration[] */
1274
-            : $this->getRegistrationModel()->get_all($query_params);
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1280
-     * Note: this listens to values on the request for some of the query parameters.
1281
-     *
1282
-     * @param array $request
1283
-     * @param int   $per_page
1284
-     * @param bool  $count
1285
-     * @return array
1286
-     * @throws EE_Error
1287
-     * @throws InvalidArgumentException
1288
-     * @throws InvalidDataTypeException
1289
-     * @throws InvalidInterfaceException
1290
-     */
1291
-    protected function _get_registration_query_parameters(
1292
-        $request = [],
1293
-        $per_page = 10,
1294
-        $count = false
1295
-    ) {
1296
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1297
-        $list_table_query_builder = $this->getLoader()->getNew(
1298
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1299
-            [null, null, $request]
1300
-        );
1301
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1302
-    }
1303
-
1304
-
1305
-    public function get_registration_status_array()
1306
-    {
1307
-        return self::$_reg_status;
1308
-    }
1309
-
1310
-
1311
-
1312
-
1313
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1314
-    /**
1315
-     * generates HTML for the View Registration Details Admin page
1316
-     *
1317
-     * @return void
1318
-     * @throws DomainException
1319
-     * @throws EE_Error
1320
-     * @throws InvalidArgumentException
1321
-     * @throws InvalidDataTypeException
1322
-     * @throws InvalidInterfaceException
1323
-     * @throws EntityNotFoundException
1324
-     * @throws ReflectionException
1325
-     */
1326
-    protected function _registration_details()
1327
-    {
1328
-        $this->_template_args = [];
1329
-        $this->_set_registration_object();
1330
-        if (is_object($this->_registration)) {
1331
-            $transaction                                   = $this->_registration->transaction()
1332
-                ? $this->_registration->transaction()
1333
-                : EE_Transaction::new_instance();
1334
-            $this->_session                                = $transaction->session_data();
1335
-            $event_id                                      = $this->_registration->event_ID();
1336
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1337
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1338
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1339
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1340
-            $this->_template_args['grand_total']           = $transaction->total();
1341
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1342
-            // link back to overview
1343
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1344
-            $this->_template_args['registration']                = $this->_registration;
1345
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1346
-                [
1347
-                    'action'   => 'default',
1348
-                    'event_id' => $event_id,
1349
-                ],
1350
-                REG_ADMIN_URL
1351
-            );
1352
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1353
-                [
1354
-                    'action' => 'default',
1355
-                    'EVT_ID' => $event_id,
1356
-                    'page'   => 'espresso_transactions',
1357
-                ],
1358
-                admin_url('admin.php')
1359
-            );
1360
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1361
-                [
1362
-                    'page'   => 'espresso_events',
1363
-                    'action' => 'edit',
1364
-                    'post'   => $event_id,
1365
-                ],
1366
-                admin_url('admin.php')
1367
-            );
1368
-            // next and previous links
1369
-            $next_reg                                      = $this->_registration->next(
1370
-                null,
1371
-                [],
1372
-                'REG_ID'
1373
-            );
1374
-            $this->_template_args['next_registration']     = $next_reg
1375
-                ? $this->_next_link(
1376
-                    EE_Admin_Page::add_query_args_and_nonce(
1377
-                        [
1378
-                            'action'  => 'view_registration',
1379
-                            '_REG_ID' => $next_reg['REG_ID'],
1380
-                        ],
1381
-                        REG_ADMIN_URL
1382
-                    ),
1383
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1384
-                )
1385
-                : '';
1386
-            $previous_reg                                  = $this->_registration->previous(
1387
-                null,
1388
-                [],
1389
-                'REG_ID'
1390
-            );
1391
-            $this->_template_args['previous_registration'] = $previous_reg
1392
-                ? $this->_previous_link(
1393
-                    EE_Admin_Page::add_query_args_and_nonce(
1394
-                        [
1395
-                            'action'  => 'view_registration',
1396
-                            '_REG_ID' => $previous_reg['REG_ID'],
1397
-                        ],
1398
-                        REG_ADMIN_URL
1399
-                    ),
1400
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1401
-                )
1402
-                : '';
1403
-            // grab header
1404
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1405
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1406
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1407
-                $template_path,
1408
-                $this->_template_args,
1409
-                true
1410
-            );
1411
-        } else {
1412
-            $this->_template_args['admin_page_header'] = '';
1413
-            $this->_display_espresso_notices();
1414
-        }
1415
-        // the details template wrapper
1416
-        $this->display_admin_page_with_sidebar();
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     * @throws EE_Error
1422
-     * @throws InvalidArgumentException
1423
-     * @throws InvalidDataTypeException
1424
-     * @throws InvalidInterfaceException
1425
-     * @throws ReflectionException
1426
-     * @since 4.10.2.p
1427
-     */
1428
-    protected function _registration_details_metaboxes()
1429
-    {
1430
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1431
-        $this->_set_registration_object();
1432
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1433
-        add_meta_box(
1434
-            'edit-reg-status-mbox',
1435
-            esc_html__('Registration Status', 'event_espresso'),
1436
-            [$this, 'set_reg_status_buttons_metabox'],
1437
-            $this->_wp_page_slug,
1438
-            'normal',
1439
-            'high'
1440
-        );
1441
-        add_meta_box(
1442
-            'edit-reg-details-mbox',
1443
-            esc_html__('Registration Details', 'event_espresso'),
1444
-            [$this, '_reg_details_meta_box'],
1445
-            $this->_wp_page_slug,
1446
-            'normal',
1447
-            'high'
1448
-        );
1449
-        if (
1450
-            $attendee instanceof EE_Attendee
1451
-            && EE_Registry::instance()->CAP->current_user_can(
1452
-                'ee_read_registration',
1453
-                'edit-reg-questions-mbox',
1454
-                $this->_registration->ID()
1455
-            )
1456
-        ) {
1457
-            add_meta_box(
1458
-                'edit-reg-questions-mbox',
1459
-                esc_html__('Registration Form Answers', 'event_espresso'),
1460
-                [$this, '_reg_questions_meta_box'],
1461
-                $this->_wp_page_slug,
1462
-                'normal',
1463
-                'high'
1464
-            );
1465
-        }
1466
-        add_meta_box(
1467
-            'edit-reg-registrant-mbox',
1468
-            esc_html__('Contact Details', 'event_espresso'),
1469
-            [$this, '_reg_registrant_side_meta_box'],
1470
-            $this->_wp_page_slug,
1471
-            'side',
1472
-            'high'
1473
-        );
1474
-        if ($this->_registration->group_size() > 1) {
1475
-            add_meta_box(
1476
-                'edit-reg-attendees-mbox',
1477
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1478
-                [$this, '_reg_attendees_meta_box'],
1479
-                $this->_wp_page_slug,
1480
-                'normal',
1481
-                'high'
1482
-            );
1483
-        }
1484
-    }
1485
-
1486
-
1487
-    /**
1488
-     * set_reg_status_buttons_metabox
1489
-     *
1490
-     * @return void
1491
-     * @throws EE_Error
1492
-     * @throws EntityNotFoundException
1493
-     * @throws InvalidArgumentException
1494
-     * @throws InvalidDataTypeException
1495
-     * @throws InvalidInterfaceException
1496
-     * @throws ReflectionException
1497
-     */
1498
-    public function set_reg_status_buttons_metabox()
1499
-    {
1500
-        $this->_set_registration_object();
1501
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1502
-        $output                 = $change_reg_status_form->form_open(
1503
-            self::add_query_args_and_nonce(
1504
-                [
1505
-                    'action' => 'change_reg_status',
1506
-                ],
1507
-                REG_ADMIN_URL
1508
-            )
1509
-        );
1510
-        $output                 .= $change_reg_status_form->get_html();
1511
-        $output                 .= $change_reg_status_form->form_close();
1512
-        echo wp_kses($output, AllowedTags::getWithFormTags());
1513
-    }
1514
-
1515
-
1516
-    /**
1517
-     * @return EE_Form_Section_Proper
1518
-     * @throws EE_Error
1519
-     * @throws InvalidArgumentException
1520
-     * @throws InvalidDataTypeException
1521
-     * @throws InvalidInterfaceException
1522
-     * @throws EntityNotFoundException
1523
-     * @throws ReflectionException
1524
-     */
1525
-    protected function _generate_reg_status_change_form()
1526
-    {
1527
-        $reg_status_change_form_array = [
1528
-            'name'            => 'reg_status_change_form',
1529
-            'html_id'         => 'reg-status-change-form',
1530
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1531
-            'subsections'     => [
1532
-                'return'         => new EE_Hidden_Input(
1533
-                    [
1534
-                        'name'    => 'return',
1535
-                        'default' => 'view_registration',
1536
-                    ]
1537
-                ),
1538
-                'REG_ID'         => new EE_Hidden_Input(
1539
-                    [
1540
-                        'name'    => 'REG_ID',
1541
-                        'default' => $this->_registration->ID(),
1542
-                    ]
1543
-                ),
1544
-                'current_status' => new EE_Form_Section_HTML(
1545
-                    EEH_HTML::table(
1546
-                        EEH_HTML::tr(
1547
-                            EEH_HTML::th(
1548
-                                EEH_HTML::label(
1549
-                                    EEH_HTML::strong(
1550
-                                        esc_html__('Current Registration Status', 'event_espresso')
1551
-                                    )
1552
-                                )
1553
-                            )
1554
-                            . EEH_HTML::td(
1555
-                                EEH_HTML::strong(
1556
-                                    $this->_registration->pretty_status(),
1557
-                                    '',
1558
-                                    'status-' . $this->_registration->status_ID(),
1559
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1560
-                                )
1561
-                            )
1562
-                        )
1563
-                    )
1564
-                ),
1565
-            ],
1566
-        ];
1567
-        if (
1568
-            EE_Registry::instance()->CAP->current_user_can(
1569
-                'ee_edit_registration',
1570
-                'toggle_registration_status',
1571
-                $this->_registration->ID()
1572
-            )
1573
-        ) {
1574
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1575
-                $this->_get_reg_statuses(),
1576
-                [
1577
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1578
-                    'default'         => $this->_registration->status_ID(),
1579
-                ]
1580
-            );
1581
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1582
-                [
1583
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1584
-                    'default'         => false,
1585
-                    'html_help_text'  => esc_html__(
1586
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1587
-                        'event_espresso'
1588
-                    ),
1589
-                ]
1590
-            );
1591
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1592
-                [
1593
-                    'html_class'      => 'button-primary',
1594
-                    'html_label_text' => '&nbsp;',
1595
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1596
-                ]
1597
-            );
1598
-        }
1599
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1600
-    }
1601
-
1602
-
1603
-    /**
1604
-     * Returns an array of all the buttons for the various statuses and switch status actions
1605
-     *
1606
-     * @return array
1607
-     * @throws EE_Error
1608
-     * @throws InvalidArgumentException
1609
-     * @throws InvalidDataTypeException
1610
-     * @throws InvalidInterfaceException
1611
-     * @throws EntityNotFoundException
1612
-     */
1613
-    protected function _get_reg_statuses()
1614
-    {
1615
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1616
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1617
-        // get current reg status
1618
-        $current_status = $this->_registration->status_ID();
1619
-        // is registration for free event? This will determine whether to display the pending payment option
1620
-        if (
1621
-            $current_status !== EEM_Registration::status_id_pending_payment
1622
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1623
-        ) {
1624
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1625
-        }
1626
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1632
-     *
1633
-     * @param bool $status REG status given for changing registrations to.
1634
-     * @param bool $notify Whether to send messages notifications or not.
1635
-     * @return array (array with reg_id(s) updated and whether update was successful.
1636
-     * @throws DomainException
1637
-     * @throws EE_Error
1638
-     * @throws EntityNotFoundException
1639
-     * @throws InvalidArgumentException
1640
-     * @throws InvalidDataTypeException
1641
-     * @throws InvalidInterfaceException
1642
-     * @throws ReflectionException
1643
-     * @throws RuntimeException
1644
-     */
1645
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1646
-    {
1647
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1648
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1649
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1650
-
1651
-        // sanitize $REG_IDs
1652
-        $REG_IDs = array_map('absint', $REG_IDs);
1653
-        // and remove empty entries
1654
-        $REG_IDs = array_filter($REG_IDs);
1655
-
1656
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1657
-
1658
-        /**
1659
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1660
-         * Currently this value is used downstream by the _process_resend_registration method.
1661
-         *
1662
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1663
-         * @param bool                     $status           The status registrations were changed to.
1664
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1665
-         * @param Registrations_Admin_Page $admin_page_object
1666
-         */
1667
-        $REG_ID = apply_filters(
1668
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1669
-            $result['REG_ID'],
1670
-            $status,
1671
-            $result['success'],
1672
-            $this
1673
-        );
1674
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1675
-
1676
-        // notify?
1677
-        if (
1678
-            $notify
1679
-            && $result['success']
1680
-            && ! empty($REG_ID)
1681
-            && EE_Registry::instance()->CAP->current_user_can(
1682
-                'ee_send_message',
1683
-                'espresso_registrations_resend_registration'
1684
-            )
1685
-        ) {
1686
-            $this->_process_resend_registration();
1687
-        }
1688
-        return $result;
1689
-    }
1690
-
1691
-
1692
-    /**
1693
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1694
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1695
-     *
1696
-     * @param array  $REG_IDs
1697
-     * @param string $status
1698
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1699
-     *                       slug sent with setting the registration status.
1700
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1701
-     * @throws EE_Error
1702
-     * @throws InvalidArgumentException
1703
-     * @throws InvalidDataTypeException
1704
-     * @throws InvalidInterfaceException
1705
-     * @throws ReflectionException
1706
-     * @throws RuntimeException
1707
-     * @throws EntityNotFoundException
1708
-     * @throws DomainException
1709
-     */
1710
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1711
-    {
1712
-        $success = false;
1713
-        // typecast $REG_IDs
1714
-        $REG_IDs = (array) $REG_IDs;
1715
-        if (! empty($REG_IDs)) {
1716
-            $success = true;
1717
-            // set default status if none is passed
1718
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1719
-            $status_context = $notify
1720
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1721
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1722
-            // loop through REG_ID's and change status
1723
-            foreach ($REG_IDs as $REG_ID) {
1724
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1725
-                if ($registration instanceof EE_Registration) {
1726
-                    $registration->set_status(
1727
-                        $status,
1728
-                        false,
1729
-                        new Context(
1730
-                            $status_context,
1731
-                            esc_html__(
1732
-                                'Manually triggered status change on a Registration Admin Page route.',
1733
-                                'event_espresso'
1734
-                            )
1735
-                        )
1736
-                    );
1737
-                    $result = $registration->save();
1738
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1739
-                    $success = $result !== false ? $success : false;
1740
-                }
1741
-            }
1742
-        }
1743
-
1744
-        // return $success and processed registrations
1745
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1746
-    }
1747
-
1748
-
1749
-    /**
1750
-     * Common logic for setting up success message and redirecting to appropriate route
1751
-     *
1752
-     * @param string $STS_ID status id for the registration changed to
1753
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1754
-     * @return void
1755
-     * @throws DomainException
1756
-     * @throws EE_Error
1757
-     * @throws EntityNotFoundException
1758
-     * @throws InvalidArgumentException
1759
-     * @throws InvalidDataTypeException
1760
-     * @throws InvalidInterfaceException
1761
-     * @throws ReflectionException
1762
-     * @throws RuntimeException
1763
-     */
1764
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1765
-    {
1766
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1767
-            : ['success' => false];
1768
-        $success = isset($result['success']) && $result['success'];
1769
-        // setup success message
1770
-        if ($success) {
1771
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1772
-                $msg = sprintf(
1773
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1774
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1775
-                );
1776
-            } else {
1777
-                $msg = sprintf(
1778
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1779
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1780
-                );
1781
-            }
1782
-            EE_Error::add_success($msg);
1783
-        } else {
1784
-            EE_Error::add_error(
1785
-                esc_html__(
1786
-                    'Something went wrong, and the status was not changed',
1787
-                    'event_espresso'
1788
-                ),
1789
-                __FILE__,
1790
-                __LINE__,
1791
-                __FUNCTION__
1792
-            );
1793
-        }
1794
-        $return = $this->request->getRequestParam('return');
1795
-        $route  = $return === 'view_registration'
1796
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1797
-            : ['action' => 'default'];
1798
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1799
-        $this->_redirect_after_action($success, '', '', $route, true);
1800
-    }
1801
-
1802
-
1803
-    /**
1804
-     * incoming reg status change from reg details page.
1805
-     *
1806
-     * @return void
1807
-     * @throws EE_Error
1808
-     * @throws EntityNotFoundException
1809
-     * @throws InvalidArgumentException
1810
-     * @throws InvalidDataTypeException
1811
-     * @throws InvalidInterfaceException
1812
-     * @throws ReflectionException
1813
-     * @throws RuntimeException
1814
-     * @throws DomainException
1815
-     */
1816
-    protected function _change_reg_status()
1817
-    {
1818
-        $this->request->setRequestParam('return', 'view_registration');
1819
-        // set notify based on whether the send notifications toggle is set or not
1820
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1821
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1822
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1823
-        switch ($reg_status) {
1824
-            case EEM_Registration::status_id_approved:
1825
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1826
-                $this->approve_registration($notify);
1827
-                break;
1828
-            case EEM_Registration::status_id_pending_payment:
1829
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1830
-                $this->pending_registration($notify);
1831
-                break;
1832
-            case EEM_Registration::status_id_not_approved:
1833
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1834
-                $this->not_approve_registration($notify);
1835
-                break;
1836
-            case EEM_Registration::status_id_declined:
1837
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1838
-                $this->decline_registration($notify);
1839
-                break;
1840
-            case EEM_Registration::status_id_cancelled:
1841
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1842
-                $this->cancel_registration($notify);
1843
-                break;
1844
-            case EEM_Registration::status_id_wait_list:
1845
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1846
-                $this->wait_list_registration($notify);
1847
-                break;
1848
-            case EEM_Registration::status_id_incomplete:
1849
-            default:
1850
-                $this->request->unSetRequestParam('return');
1851
-                $this->_reg_status_change_return('');
1852
-                break;
1853
-        }
1854
-    }
1855
-
1856
-
1857
-    /**
1858
-     * Callback for bulk action routes.
1859
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1860
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1861
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1862
-     * when an action is happening on just a single registration).
1863
-     *
1864
-     * @param      $action
1865
-     * @param bool $notify
1866
-     */
1867
-    protected function bulk_action_on_registrations($action, $notify = false)
1868
-    {
1869
-        do_action(
1870
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1871
-            $this,
1872
-            $action,
1873
-            $notify
1874
-        );
1875
-        $method = $action . '_registration';
1876
-        if (method_exists($this, $method)) {
1877
-            $this->$method($notify);
1878
-        }
1879
-    }
1880
-
1881
-
1882
-    /**
1883
-     * approve_registration
1884
-     *
1885
-     * @param bool $notify whether or not to notify the registrant about their approval.
1886
-     * @return void
1887
-     * @throws EE_Error
1888
-     * @throws EntityNotFoundException
1889
-     * @throws InvalidArgumentException
1890
-     * @throws InvalidDataTypeException
1891
-     * @throws InvalidInterfaceException
1892
-     * @throws ReflectionException
1893
-     * @throws RuntimeException
1894
-     * @throws DomainException
1895
-     */
1896
-    protected function approve_registration($notify = false)
1897
-    {
1898
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1899
-    }
1900
-
1901
-
1902
-    /**
1903
-     * decline_registration
1904
-     *
1905
-     * @param bool $notify whether or not to notify the registrant about their status change.
1906
-     * @return void
1907
-     * @throws EE_Error
1908
-     * @throws EntityNotFoundException
1909
-     * @throws InvalidArgumentException
1910
-     * @throws InvalidDataTypeException
1911
-     * @throws InvalidInterfaceException
1912
-     * @throws ReflectionException
1913
-     * @throws RuntimeException
1914
-     * @throws DomainException
1915
-     */
1916
-    protected function decline_registration($notify = false)
1917
-    {
1918
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1919
-    }
1920
-
1921
-
1922
-    /**
1923
-     * cancel_registration
1924
-     *
1925
-     * @param bool $notify whether or not to notify the registrant about their status change.
1926
-     * @return void
1927
-     * @throws EE_Error
1928
-     * @throws EntityNotFoundException
1929
-     * @throws InvalidArgumentException
1930
-     * @throws InvalidDataTypeException
1931
-     * @throws InvalidInterfaceException
1932
-     * @throws ReflectionException
1933
-     * @throws RuntimeException
1934
-     * @throws DomainException
1935
-     */
1936
-    protected function cancel_registration($notify = false)
1937
-    {
1938
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1939
-    }
1940
-
1941
-
1942
-    /**
1943
-     * not_approve_registration
1944
-     *
1945
-     * @param bool $notify whether or not to notify the registrant about their status change.
1946
-     * @return void
1947
-     * @throws EE_Error
1948
-     * @throws EntityNotFoundException
1949
-     * @throws InvalidArgumentException
1950
-     * @throws InvalidDataTypeException
1951
-     * @throws InvalidInterfaceException
1952
-     * @throws ReflectionException
1953
-     * @throws RuntimeException
1954
-     * @throws DomainException
1955
-     */
1956
-    protected function not_approve_registration($notify = false)
1957
-    {
1958
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1959
-    }
1960
-
1961
-
1962
-    /**
1963
-     * decline_registration
1964
-     *
1965
-     * @param bool $notify whether or not to notify the registrant about their status change.
1966
-     * @return void
1967
-     * @throws EE_Error
1968
-     * @throws EntityNotFoundException
1969
-     * @throws InvalidArgumentException
1970
-     * @throws InvalidDataTypeException
1971
-     * @throws InvalidInterfaceException
1972
-     * @throws ReflectionException
1973
-     * @throws RuntimeException
1974
-     * @throws DomainException
1975
-     */
1976
-    protected function pending_registration($notify = false)
1977
-    {
1978
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1979
-    }
1980
-
1981
-
1982
-    /**
1983
-     * waitlist_registration
1984
-     *
1985
-     * @param bool $notify whether or not to notify the registrant about their status change.
1986
-     * @return void
1987
-     * @throws EE_Error
1988
-     * @throws EntityNotFoundException
1989
-     * @throws InvalidArgumentException
1990
-     * @throws InvalidDataTypeException
1991
-     * @throws InvalidInterfaceException
1992
-     * @throws ReflectionException
1993
-     * @throws RuntimeException
1994
-     * @throws DomainException
1995
-     */
1996
-    protected function wait_list_registration($notify = false)
1997
-    {
1998
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1999
-    }
2000
-
2001
-
2002
-    /**
2003
-     * generates HTML for the Registration main meta box
2004
-     *
2005
-     * @return void
2006
-     * @throws DomainException
2007
-     * @throws EE_Error
2008
-     * @throws InvalidArgumentException
2009
-     * @throws InvalidDataTypeException
2010
-     * @throws InvalidInterfaceException
2011
-     * @throws ReflectionException
2012
-     * @throws EntityNotFoundException
2013
-     */
2014
-    public function _reg_details_meta_box()
2015
-    {
2016
-        EEH_Autoloader::register_line_item_display_autoloaders();
2017
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2018
-        EE_Registry::instance()->load_helper('Line_Item');
2019
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2020
-            : EE_Transaction::new_instance();
2021
-        $this->_session = $transaction->session_data();
2022
-        $filters        = new EE_Line_Item_Filter_Collection();
2023
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2024
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2025
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2026
-            $filters,
2027
-            $transaction->total_line_item()
2028
-        );
2029
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2030
-        $line_item_display                       = new EE_Line_Item_Display(
2031
-            'reg_admin_table',
2032
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2033
-        );
2034
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2035
-            $filtered_line_item_tree,
2036
-            ['EE_Registration' => $this->_registration]
2037
-        );
2038
-        $attendee                                = $this->_registration->attendee();
2039
-        if (
2040
-            EE_Registry::instance()->CAP->current_user_can(
2041
-                'ee_read_transaction',
2042
-                'espresso_transactions_view_transaction'
2043
-            )
2044
-        ) {
2045
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2046
-                EE_Admin_Page::add_query_args_and_nonce(
2047
-                    [
2048
-                        'action' => 'view_transaction',
2049
-                        'TXN_ID' => $transaction->ID(),
2050
-                    ],
2051
-                    TXN_ADMIN_URL
2052
-                ),
2053
-                esc_html__(' View Transaction', 'event_espresso'),
2054
-                'button secondary-button right',
2055
-                'dashicons dashicons-cart'
2056
-            );
2057
-        } else {
2058
-            $this->_template_args['view_transaction_button'] = '';
2059
-        }
2060
-        if (
2061
-            $attendee instanceof EE_Attendee
2062
-            && EE_Registry::instance()->CAP->current_user_can(
2063
-                'ee_send_message',
2064
-                'espresso_registrations_resend_registration'
2065
-            )
2066
-        ) {
2067
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2068
-                EE_Admin_Page::add_query_args_and_nonce(
2069
-                    [
2070
-                        'action'      => 'resend_registration',
2071
-                        '_REG_ID'     => $this->_registration->ID(),
2072
-                        'redirect_to' => 'view_registration',
2073
-                    ],
2074
-                    REG_ADMIN_URL
2075
-                ),
2076
-                esc_html__(' Resend Registration', 'event_espresso'),
2077
-                'button secondary-button right',
2078
-                'dashicons dashicons-email-alt'
2079
-            );
2080
-        } else {
2081
-            $this->_template_args['resend_registration_button'] = '';
2082
-        }
2083
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2084
-        $payment                               = $transaction->get_first_related('Payment');
2085
-        $payment                               = ! $payment instanceof EE_Payment
2086
-            ? EE_Payment::new_instance()
2087
-            : $payment;
2088
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2089
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2090
-            ? EE_Payment_Method::new_instance()
2091
-            : $payment_method;
2092
-        $reg_details                           = [
2093
-            'payment_method'       => $payment_method->name(),
2094
-            'response_msg'         => $payment->gateway_response(),
2095
-            'registration_id'      => $this->_registration->get('REG_code'),
2096
-            'registration_session' => $this->_registration->session_ID(),
2097
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2098
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2099
-        ];
2100
-        if (isset($reg_details['registration_id'])) {
2101
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2102
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2103
-                'Registration ID',
2104
-                'event_espresso'
2105
-            );
2106
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2107
-        }
2108
-        if (isset($reg_details['payment_method'])) {
2109
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2110
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2111
-                'Most Recent Payment Method',
2112
-                'event_espresso'
2113
-            );
2114
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2115
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2116
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2117
-                'Payment method response',
2118
-                'event_espresso'
2119
-            );
2120
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2121
-        }
2122
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2123
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2124
-            'Registration Session',
2125
-            'event_espresso'
2126
-        );
2127
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2128
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2129
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2130
-            'Registration placed from IP',
2131
-            'event_espresso'
2132
-        );
2133
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2134
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2135
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2136
-            'Registrant User Agent',
2137
-            'event_espresso'
2138
-        );
2139
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2140
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2141
-            [
2142
-                'action'   => 'default',
2143
-                'event_id' => $this->_registration->event_ID(),
2144
-            ],
2145
-            REG_ADMIN_URL
2146
-        );
2147
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2148
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2149
-        $template_path                                                        =
2150
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2151
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2152
-    }
2153
-
2154
-
2155
-    /**
2156
-     * generates HTML for the Registration Questions meta box.
2157
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2158
-     * otherwise uses new forms system
2159
-     *
2160
-     * @return void
2161
-     * @throws DomainException
2162
-     * @throws EE_Error
2163
-     * @throws InvalidArgumentException
2164
-     * @throws InvalidDataTypeException
2165
-     * @throws InvalidInterfaceException
2166
-     * @throws ReflectionException
2167
-     */
2168
-    public function _reg_questions_meta_box()
2169
-    {
2170
-        // allow someone to override this method entirely
2171
-        if (
2172
-            apply_filters(
2173
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2174
-                true,
2175
-                $this,
2176
-                $this->_registration
2177
-            )
2178
-        ) {
2179
-            $form                                              = $this->_get_reg_custom_questions_form(
2180
-                $this->_registration->ID()
2181
-            );
2182
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2183
-                ? $form->get_html_and_js()
2184
-                : '';
2185
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2186
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2187
-            $template_path                                     =
2188
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2189
-            EEH_Template::display_template($template_path, $this->_template_args);
2190
-        }
2191
-    }
2192
-
2193
-
2194
-    /**
2195
-     * form_before_question_group
2196
-     *
2197
-     * @param string $output
2198
-     * @return        string
2199
-     * @deprecated    as of 4.8.32.rc.000
2200
-     */
2201
-    public function form_before_question_group($output)
2202
-    {
2203
-        EE_Error::doing_it_wrong(
2204
-            __CLASS__ . '::' . __FUNCTION__,
2205
-            esc_html__(
2206
-                '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.',
2207
-                'event_espresso'
2208
-            ),
2209
-            '4.8.32.rc.000'
2210
-        );
2211
-        return '
23
+	/**
24
+	 * @var EE_Registration
25
+	 */
26
+	private $_registration;
27
+
28
+	/**
29
+	 * @var EE_Event
30
+	 */
31
+	private $_reg_event;
32
+
33
+	/**
34
+	 * @var EE_Session
35
+	 */
36
+	private $_session;
37
+
38
+	/**
39
+	 * @var array
40
+	 */
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+	/**
52
+	 * @var EEM_Registration $registration_model
53
+	 */
54
+	private $registration_model;
55
+
56
+	/**
57
+	 * @var EEM_Attendee $attendee_model
58
+	 */
59
+	private $attendee_model;
60
+
61
+	/**
62
+	 * @var EEM_Event $event_model
63
+	 */
64
+	private $event_model;
65
+
66
+	/**
67
+	 * @var EEM_Status $status_model
68
+	 */
69
+	private $status_model;
70
+
71
+
72
+	/**
73
+	 * @param bool $routing
74
+	 * @throws EE_Error
75
+	 * @throws InvalidArgumentException
76
+	 * @throws InvalidDataTypeException
77
+	 * @throws InvalidInterfaceException
78
+	 * @throws ReflectionException
79
+	 */
80
+	public function __construct($routing = true)
81
+	{
82
+		parent::__construct($routing);
83
+		add_action('wp_loaded', [$this, 'wp_loaded']);
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return EEM_Registration
89
+	 * @throws InvalidArgumentException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidInterfaceException
92
+	 * @since 4.10.2.p
93
+	 */
94
+	protected function getRegistrationModel()
95
+	{
96
+		if (! $this->registration_model instanceof EEM_Registration) {
97
+			$this->registration_model = $this->getLoader()->getShared('EEM_Registration');
98
+		}
99
+		return $this->registration_model;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return EEM_Attendee
105
+	 * @throws InvalidArgumentException
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidInterfaceException
108
+	 * @since 4.10.2.p
109
+	 */
110
+	protected function getAttendeeModel()
111
+	{
112
+		if (! $this->attendee_model instanceof EEM_Attendee) {
113
+			$this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
114
+		}
115
+		return $this->attendee_model;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return EEM_Event
121
+	 * @throws InvalidArgumentException
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws InvalidInterfaceException
124
+	 * @since 4.10.2.p
125
+	 */
126
+	protected function getEventModel()
127
+	{
128
+		if (! $this->event_model instanceof EEM_Event) {
129
+			$this->event_model = $this->getLoader()->getShared('EEM_Event');
130
+		}
131
+		return $this->event_model;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return EEM_Status
137
+	 * @throws InvalidArgumentException
138
+	 * @throws InvalidDataTypeException
139
+	 * @throws InvalidInterfaceException
140
+	 * @since 4.10.2.p
141
+	 */
142
+	protected function getStatusModel()
143
+	{
144
+		if (! $this->status_model instanceof EEM_Status) {
145
+			$this->status_model = $this->getLoader()->getShared('EEM_Status');
146
+		}
147
+		return $this->status_model;
148
+	}
149
+
150
+
151
+	public function wp_loaded()
152
+	{
153
+		// when adding a new registration...
154
+		$action = $this->request->getRequestParam('action');
155
+		if ($action === 'new_registration') {
156
+			EE_System::do_not_cache();
157
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
158
+				// and it's NOT the attendee information reg step
159
+				// force cookie expiration by setting time to last week
160
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
161
+				// and update the global
162
+				$_COOKIE['ee_registration_added'] = 0;
163
+			}
164
+		}
165
+	}
166
+
167
+
168
+	protected function _init_page_props()
169
+	{
170
+		$this->page_slug        = REG_PG_SLUG;
171
+		$this->_admin_base_url  = REG_ADMIN_URL;
172
+		$this->_admin_base_path = REG_ADMIN;
173
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
174
+		$this->_cpt_routes      = [
175
+			'add_new_attendee' => 'espresso_attendees',
176
+			'edit_attendee'    => 'espresso_attendees',
177
+			'insert_attendee'  => 'espresso_attendees',
178
+			'update_attendee'  => 'espresso_attendees',
179
+		];
180
+		$this->_cpt_model_names = [
181
+			'add_new_attendee' => 'EEM_Attendee',
182
+			'edit_attendee'    => 'EEM_Attendee',
183
+		];
184
+		$this->_cpt_edit_routes = [
185
+			'espresso_attendees' => 'edit_attendee',
186
+		];
187
+		$this->_pagenow_map     = [
188
+			'add_new_attendee' => 'post-new.php',
189
+			'edit_attendee'    => 'post.php',
190
+			'trash'            => 'post.php',
191
+		];
192
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
193
+		// add filters so that the comment urls don't take users to a confusing 404 page
194
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
195
+	}
196
+
197
+
198
+	/**
199
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
200
+	 * @param WP_Comment $comment The current comment object.
201
+	 * @return string
202
+	 */
203
+	public function clear_comment_link($link, WP_Comment $comment)
204
+	{
205
+		// gotta make sure this only happens on this route
206
+		$post_type = get_post_type($comment->comment_post_ID);
207
+		if ($post_type === 'espresso_attendees') {
208
+			return '#commentsdiv';
209
+		}
210
+		return $link;
211
+	}
212
+
213
+
214
+	protected function _ajax_hooks()
215
+	{
216
+		// todo: all hooks for registrations ajax goes in here
217
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
218
+	}
219
+
220
+
221
+	protected function _define_page_props()
222
+	{
223
+		$this->_admin_page_title = $this->page_label;
224
+		$this->_labels           = [
225
+			'buttons'                      => [
226
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
227
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
228
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
229
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
230
+				'report_datetime'     => esc_html__('Datetime Registrations CSV Report', 'event_espresso'),
231
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
232
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
233
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
234
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
235
+			],
236
+			'publishbox'                   => [
237
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
238
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
239
+			],
240
+			'hide_add_button_on_cpt_route' => [
241
+				'edit_attendee' => true,
242
+			],
243
+		];
244
+	}
245
+
246
+
247
+	/**
248
+	 * grab url requests and route them
249
+	 *
250
+	 * @return void
251
+	 * @throws EE_Error
252
+	 */
253
+	public function _set_page_routes()
254
+	{
255
+		$this->_get_registration_status_array();
256
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
257
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
258
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
259
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
260
+		$this->_page_routes = [
261
+			'default'                             => [
262
+				'func'       => '_registrations_overview_list_table',
263
+				'capability' => 'ee_read_registrations',
264
+			],
265
+			'view_registration'                   => [
266
+				'func'       => '_registration_details',
267
+				'capability' => 'ee_read_registration',
268
+				'obj_id'     => $REG_ID,
269
+			],
270
+			'edit_registration'                   => [
271
+				'func'               => '_update_attendee_registration_form',
272
+				'noheader'           => true,
273
+				'headers_sent_route' => 'view_registration',
274
+				'capability'         => 'ee_edit_registration',
275
+				'obj_id'             => $REG_ID,
276
+				'_REG_ID'            => $REG_ID,
277
+			],
278
+			'trash_registrations'                 => [
279
+				'func'       => '_trash_or_restore_registrations',
280
+				'args'       => ['trash' => true],
281
+				'noheader'   => true,
282
+				'capability' => 'ee_delete_registrations',
283
+			],
284
+			'restore_registrations'               => [
285
+				'func'       => '_trash_or_restore_registrations',
286
+				'args'       => ['trash' => false],
287
+				'noheader'   => true,
288
+				'capability' => 'ee_delete_registrations',
289
+			],
290
+			'delete_registrations'                => [
291
+				'func'       => '_delete_registrations',
292
+				'noheader'   => true,
293
+				'capability' => 'ee_delete_registrations',
294
+			],
295
+			'new_registration'                    => [
296
+				'func'       => 'new_registration',
297
+				'capability' => 'ee_edit_registrations',
298
+			],
299
+			'process_reg_step'                    => [
300
+				'func'       => 'process_reg_step',
301
+				'noheader'   => true,
302
+				'capability' => 'ee_edit_registrations',
303
+			],
304
+			'redirect_to_txn'                     => [
305
+				'func'       => 'redirect_to_txn',
306
+				'noheader'   => true,
307
+				'capability' => 'ee_edit_registrations',
308
+			],
309
+			'change_reg_status'                   => [
310
+				'func'       => '_change_reg_status',
311
+				'noheader'   => true,
312
+				'capability' => 'ee_edit_registration',
313
+				'obj_id'     => $REG_ID,
314
+			],
315
+			'approve_registration'                => [
316
+				'func'       => 'approve_registration',
317
+				'noheader'   => true,
318
+				'capability' => 'ee_edit_registration',
319
+				'obj_id'     => $REG_ID,
320
+			],
321
+			'approve_and_notify_registration'     => [
322
+				'func'       => 'approve_registration',
323
+				'noheader'   => true,
324
+				'args'       => [true],
325
+				'capability' => 'ee_edit_registration',
326
+				'obj_id'     => $REG_ID,
327
+			],
328
+			'approve_registrations'               => [
329
+				'func'       => 'bulk_action_on_registrations',
330
+				'noheader'   => true,
331
+				'capability' => 'ee_edit_registrations',
332
+				'args'       => ['approve'],
333
+			],
334
+			'approve_and_notify_registrations'    => [
335
+				'func'       => 'bulk_action_on_registrations',
336
+				'noheader'   => true,
337
+				'capability' => 'ee_edit_registrations',
338
+				'args'       => ['approve', true],
339
+			],
340
+			'decline_registration'                => [
341
+				'func'       => 'decline_registration',
342
+				'noheader'   => true,
343
+				'capability' => 'ee_edit_registration',
344
+				'obj_id'     => $REG_ID,
345
+			],
346
+			'decline_and_notify_registration'     => [
347
+				'func'       => 'decline_registration',
348
+				'noheader'   => true,
349
+				'args'       => [true],
350
+				'capability' => 'ee_edit_registration',
351
+				'obj_id'     => $REG_ID,
352
+			],
353
+			'decline_registrations'               => [
354
+				'func'       => 'bulk_action_on_registrations',
355
+				'noheader'   => true,
356
+				'capability' => 'ee_edit_registrations',
357
+				'args'       => ['decline'],
358
+			],
359
+			'decline_and_notify_registrations'    => [
360
+				'func'       => 'bulk_action_on_registrations',
361
+				'noheader'   => true,
362
+				'capability' => 'ee_edit_registrations',
363
+				'args'       => ['decline', true],
364
+			],
365
+			'pending_registration'                => [
366
+				'func'       => 'pending_registration',
367
+				'noheader'   => true,
368
+				'capability' => 'ee_edit_registration',
369
+				'obj_id'     => $REG_ID,
370
+			],
371
+			'pending_and_notify_registration'     => [
372
+				'func'       => 'pending_registration',
373
+				'noheader'   => true,
374
+				'args'       => [true],
375
+				'capability' => 'ee_edit_registration',
376
+				'obj_id'     => $REG_ID,
377
+			],
378
+			'pending_registrations'               => [
379
+				'func'       => 'bulk_action_on_registrations',
380
+				'noheader'   => true,
381
+				'capability' => 'ee_edit_registrations',
382
+				'args'       => ['pending'],
383
+			],
384
+			'pending_and_notify_registrations'    => [
385
+				'func'       => 'bulk_action_on_registrations',
386
+				'noheader'   => true,
387
+				'capability' => 'ee_edit_registrations',
388
+				'args'       => ['pending', true],
389
+			],
390
+			'no_approve_registration'             => [
391
+				'func'       => 'not_approve_registration',
392
+				'noheader'   => true,
393
+				'capability' => 'ee_edit_registration',
394
+				'obj_id'     => $REG_ID,
395
+			],
396
+			'no_approve_and_notify_registration'  => [
397
+				'func'       => 'not_approve_registration',
398
+				'noheader'   => true,
399
+				'args'       => [true],
400
+				'capability' => 'ee_edit_registration',
401
+				'obj_id'     => $REG_ID,
402
+			],
403
+			'no_approve_registrations'            => [
404
+				'func'       => 'bulk_action_on_registrations',
405
+				'noheader'   => true,
406
+				'capability' => 'ee_edit_registrations',
407
+				'args'       => ['not_approve'],
408
+			],
409
+			'no_approve_and_notify_registrations' => [
410
+				'func'       => 'bulk_action_on_registrations',
411
+				'noheader'   => true,
412
+				'capability' => 'ee_edit_registrations',
413
+				'args'       => ['not_approve', true],
414
+			],
415
+			'cancel_registration'                 => [
416
+				'func'       => 'cancel_registration',
417
+				'noheader'   => true,
418
+				'capability' => 'ee_edit_registration',
419
+				'obj_id'     => $REG_ID,
420
+			],
421
+			'cancel_and_notify_registration'      => [
422
+				'func'       => 'cancel_registration',
423
+				'noheader'   => true,
424
+				'args'       => [true],
425
+				'capability' => 'ee_edit_registration',
426
+				'obj_id'     => $REG_ID,
427
+			],
428
+			'cancel_registrations'                => [
429
+				'func'       => 'bulk_action_on_registrations',
430
+				'noheader'   => true,
431
+				'capability' => 'ee_edit_registrations',
432
+				'args'       => ['cancel'],
433
+			],
434
+			'cancel_and_notify_registrations'     => [
435
+				'func'       => 'bulk_action_on_registrations',
436
+				'noheader'   => true,
437
+				'capability' => 'ee_edit_registrations',
438
+				'args'       => ['cancel', true],
439
+			],
440
+			'wait_list_registration'              => [
441
+				'func'       => 'wait_list_registration',
442
+				'noheader'   => true,
443
+				'capability' => 'ee_edit_registration',
444
+				'obj_id'     => $REG_ID,
445
+			],
446
+			'wait_list_and_notify_registration'   => [
447
+				'func'       => 'wait_list_registration',
448
+				'noheader'   => true,
449
+				'args'       => [true],
450
+				'capability' => 'ee_edit_registration',
451
+				'obj_id'     => $REG_ID,
452
+			],
453
+			'contact_list'                        => [
454
+				'func'       => '_attendee_contact_list_table',
455
+				'capability' => 'ee_read_contacts',
456
+			],
457
+			'add_new_attendee'                    => [
458
+				'func' => '_create_new_cpt_item',
459
+				'args' => [
460
+					'new_attendee' => true,
461
+					'capability'   => 'ee_edit_contacts',
462
+				],
463
+			],
464
+			'edit_attendee'                       => [
465
+				'func'       => '_edit_cpt_item',
466
+				'capability' => 'ee_edit_contacts',
467
+				'obj_id'     => $ATT_ID,
468
+			],
469
+			'duplicate_attendee'                  => [
470
+				'func'       => '_duplicate_attendee',
471
+				'noheader'   => true,
472
+				'capability' => 'ee_edit_contacts',
473
+				'obj_id'     => $ATT_ID,
474
+			],
475
+			'insert_attendee'                     => [
476
+				'func'       => '_insert_or_update_attendee',
477
+				'args'       => [
478
+					'new_attendee' => true,
479
+				],
480
+				'noheader'   => true,
481
+				'capability' => 'ee_edit_contacts',
482
+			],
483
+			'update_attendee'                     => [
484
+				'func'       => '_insert_or_update_attendee',
485
+				'args'       => [
486
+					'new_attendee' => false,
487
+				],
488
+				'noheader'   => true,
489
+				'capability' => 'ee_edit_contacts',
490
+				'obj_id'     => $ATT_ID,
491
+			],
492
+			'trash_attendees'                     => [
493
+				'func'       => '_trash_or_restore_attendees',
494
+				'args'       => [
495
+					'trash' => 'true',
496
+				],
497
+				'noheader'   => true,
498
+				'capability' => 'ee_delete_contacts',
499
+			],
500
+			'trash_attendee'                      => [
501
+				'func'       => '_trash_or_restore_attendees',
502
+				'args'       => [
503
+					'trash' => true,
504
+				],
505
+				'noheader'   => true,
506
+				'capability' => 'ee_delete_contacts',
507
+				'obj_id'     => $ATT_ID,
508
+			],
509
+			'restore_attendees'                   => [
510
+				'func'       => '_trash_or_restore_attendees',
511
+				'args'       => [
512
+					'trash' => false,
513
+				],
514
+				'noheader'   => true,
515
+				'capability' => 'ee_delete_contacts',
516
+				'obj_id'     => $ATT_ID,
517
+			],
518
+			'resend_registration'                 => [
519
+				'func'       => '_resend_registration',
520
+				'noheader'   => true,
521
+				'capability' => 'ee_send_message',
522
+			],
523
+			'registrations_report'                => [
524
+				'func'       => '_registrations_report',
525
+				'noheader'   => true,
526
+				'capability' => 'ee_read_registrations',
527
+			],
528
+			'contact_list_export'                 => [
529
+				'func'       => '_contact_list_export',
530
+				'noheader'   => true,
531
+				'capability' => 'export',
532
+			],
533
+			'contact_list_report'                 => [
534
+				'func'       => '_contact_list_report',
535
+				'noheader'   => true,
536
+				'capability' => 'ee_read_contacts',
537
+			],
538
+		];
539
+	}
540
+
541
+
542
+	protected function _set_page_config()
543
+	{
544
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
545
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
546
+		$this->_page_config = [
547
+			'default'           => [
548
+				'nav'           => [
549
+					'label' => esc_html__('Overview', 'event_espresso'),
550
+					'order' => 5,
551
+				],
552
+				'help_tabs'     => [
553
+					'registrations_overview_help_tab'                       => [
554
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
555
+						'filename' => 'registrations_overview',
556
+					],
557
+					'registrations_overview_table_column_headings_help_tab' => [
558
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
559
+						'filename' => 'registrations_overview_table_column_headings',
560
+					],
561
+					'registrations_overview_filters_help_tab'               => [
562
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
563
+						'filename' => 'registrations_overview_filters',
564
+					],
565
+					'registrations_overview_views_help_tab'                 => [
566
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
567
+						'filename' => 'registrations_overview_views',
568
+					],
569
+					'registrations_regoverview_other_help_tab'              => [
570
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
571
+						'filename' => 'registrations_overview_other',
572
+					],
573
+				],
574
+				'qtips'         => ['Registration_List_Table_Tips'],
575
+				'list_table'    => 'EE_Registrations_List_Table',
576
+				'require_nonce' => false,
577
+			],
578
+			'view_registration' => [
579
+				'nav'           => [
580
+					'label'      => esc_html__('REG Details', 'event_espresso'),
581
+					'order'      => 15,
582
+					'url'        => $REG_ID
583
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
584
+						: $this->_admin_base_url,
585
+					'persistent' => false,
586
+				],
587
+				'help_tabs'     => [
588
+					'registrations_details_help_tab'                    => [
589
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
590
+						'filename' => 'registrations_details',
591
+					],
592
+					'registrations_details_table_help_tab'              => [
593
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
594
+						'filename' => 'registrations_details_table',
595
+					],
596
+					'registrations_details_form_answers_help_tab'       => [
597
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
598
+						'filename' => 'registrations_details_form_answers',
599
+					],
600
+					'registrations_details_registrant_details_help_tab' => [
601
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
602
+						'filename' => 'registrations_details_registrant_details',
603
+					],
604
+				],
605
+				'metaboxes'     => array_merge(
606
+					$this->_default_espresso_metaboxes,
607
+					['_registration_details_metaboxes']
608
+				),
609
+				'require_nonce' => false,
610
+			],
611
+			'new_registration'  => [
612
+				'nav'           => [
613
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
614
+					'url'        => '#',
615
+					'order'      => 15,
616
+					'persistent' => false,
617
+				],
618
+				'metaboxes'     => $this->_default_espresso_metaboxes,
619
+				'labels'        => [
620
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
621
+				],
622
+				'require_nonce' => false,
623
+			],
624
+			'add_new_attendee'  => [
625
+				'nav'           => [
626
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
627
+					'order'      => 15,
628
+					'persistent' => false,
629
+				],
630
+				'metaboxes'     => array_merge(
631
+					$this->_default_espresso_metaboxes,
632
+					['_publish_post_box', 'attendee_editor_metaboxes']
633
+				),
634
+				'require_nonce' => false,
635
+			],
636
+			'edit_attendee'     => [
637
+				'nav'           => [
638
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
639
+					'order'      => 15,
640
+					'persistent' => false,
641
+					'url'        => $ATT_ID
642
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
643
+						: $this->_admin_base_url,
644
+				],
645
+				'metaboxes'     => ['attendee_editor_metaboxes'],
646
+				'require_nonce' => false,
647
+			],
648
+			'contact_list'      => [
649
+				'nav'           => [
650
+					'label' => esc_html__('Contact List', 'event_espresso'),
651
+					'order' => 20,
652
+				],
653
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
654
+				'help_tabs'     => [
655
+					'registrations_contact_list_help_tab'                       => [
656
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
657
+						'filename' => 'registrations_contact_list',
658
+					],
659
+					'registrations_contact-list_table_column_headings_help_tab' => [
660
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
661
+						'filename' => 'registrations_contact_list_table_column_headings',
662
+					],
663
+					'registrations_contact_list_views_help_tab'                 => [
664
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
665
+						'filename' => 'registrations_contact_list_views',
666
+					],
667
+					'registrations_contact_list_other_help_tab'                 => [
668
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
669
+						'filename' => 'registrations_contact_list_other',
670
+					],
671
+				],
672
+				'metaboxes'     => [],
673
+				'require_nonce' => false,
674
+			],
675
+			// override default cpt routes
676
+			'create_new'        => '',
677
+			'edit'              => '',
678
+		];
679
+	}
680
+
681
+
682
+	/**
683
+	 * The below methods aren't used by this class currently
684
+	 */
685
+	protected function _add_screen_options()
686
+	{
687
+	}
688
+
689
+
690
+	protected function _add_feature_pointers()
691
+	{
692
+	}
693
+
694
+
695
+	public function admin_init()
696
+	{
697
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
698
+			'click "Update Registration Questions" to save your changes',
699
+			'event_espresso'
700
+		);
701
+	}
702
+
703
+
704
+	public function admin_notices()
705
+	{
706
+	}
707
+
708
+
709
+	public function admin_footer_scripts()
710
+	{
711
+	}
712
+
713
+
714
+	/**
715
+	 * get list of registration statuses
716
+	 *
717
+	 * @return void
718
+	 * @throws EE_Error
719
+	 */
720
+	private function _get_registration_status_array()
721
+	{
722
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
723
+	}
724
+
725
+
726
+	/**
727
+	 * @throws InvalidArgumentException
728
+	 * @throws InvalidDataTypeException
729
+	 * @throws InvalidInterfaceException
730
+	 * @since 4.10.2.p
731
+	 */
732
+	protected function _add_screen_options_default()
733
+	{
734
+		$this->_per_page_screen_option();
735
+	}
736
+
737
+
738
+	/**
739
+	 * @throws InvalidArgumentException
740
+	 * @throws InvalidDataTypeException
741
+	 * @throws InvalidInterfaceException
742
+	 * @since 4.10.2.p
743
+	 */
744
+	protected function _add_screen_options_contact_list()
745
+	{
746
+		$page_title              = $this->_admin_page_title;
747
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
+		$this->_per_page_screen_option();
749
+		$this->_admin_page_title = $page_title;
750
+	}
751
+
752
+
753
+	public function load_scripts_styles()
754
+	{
755
+		// style
756
+		wp_register_style(
757
+			'espresso_reg',
758
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
+			['ee-admin-css'],
760
+			EVENT_ESPRESSO_VERSION
761
+		);
762
+		wp_enqueue_style('espresso_reg');
763
+		// script
764
+		wp_register_script(
765
+			'espresso_reg',
766
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
768
+			EVENT_ESPRESSO_VERSION,
769
+			true
770
+		);
771
+		wp_enqueue_script('espresso_reg');
772
+	}
773
+
774
+
775
+	/**
776
+	 * @throws EE_Error
777
+	 * @throws InvalidArgumentException
778
+	 * @throws InvalidDataTypeException
779
+	 * @throws InvalidInterfaceException
780
+	 * @throws ReflectionException
781
+	 * @since 4.10.2.p
782
+	 */
783
+	public function load_scripts_styles_edit_attendee()
784
+	{
785
+		// stuff to only show up on our attendee edit details page.
786
+		$attendee_details_translations = [
787
+			'att_publish_text' => sprintf(
788
+			/* translators: The date and time */
789
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
+			),
792
+		];
793
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
+		wp_enqueue_script('jquery-validate');
795
+	}
796
+
797
+
798
+	/**
799
+	 * @throws EE_Error
800
+	 * @throws InvalidArgumentException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws InvalidInterfaceException
803
+	 * @throws ReflectionException
804
+	 * @since 4.10.2.p
805
+	 */
806
+	public function load_scripts_styles_view_registration()
807
+	{
808
+		// styles
809
+		wp_enqueue_style('espresso-ui-theme');
810
+		// scripts
811
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
812
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
813
+	}
814
+
815
+
816
+	public function load_scripts_styles_contact_list()
817
+	{
818
+		wp_dequeue_style('espresso_reg');
819
+		wp_register_style(
820
+			'espresso_att',
821
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
+			['ee-admin-css'],
823
+			EVENT_ESPRESSO_VERSION
824
+		);
825
+		wp_enqueue_style('espresso_att');
826
+	}
827
+
828
+
829
+	public function load_scripts_styles_new_registration()
830
+	{
831
+		wp_register_script(
832
+			'ee-spco-for-admin',
833
+			REG_ASSETS_URL . 'spco_for_admin.js',
834
+			['underscore', 'jquery'],
835
+			EVENT_ESPRESSO_VERSION,
836
+			true
837
+		);
838
+		wp_enqueue_script('ee-spco-for-admin');
839
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
+		EE_Form_Section_Proper::wp_enqueue_scripts();
841
+		EED_Ticket_Selector::load_tckt_slctr_assets();
842
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
843
+	}
844
+
845
+
846
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
+	{
848
+		add_filter('FHEE_load_EE_messages', '__return_true');
849
+	}
850
+
851
+
852
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
+	{
854
+		add_filter('FHEE_load_EE_messages', '__return_true');
855
+	}
856
+
857
+
858
+	/**
859
+	 * @throws EE_Error
860
+	 * @throws InvalidArgumentException
861
+	 * @throws InvalidDataTypeException
862
+	 * @throws InvalidInterfaceException
863
+	 * @throws ReflectionException
864
+	 * @since 4.10.2.p
865
+	 */
866
+	protected function _set_list_table_views_default()
867
+	{
868
+		// for notification related bulk actions we need to make sure only active messengers have an option.
869
+		EED_Messages::set_autoloaders();
870
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
871
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
873
+		// key= bulk_action_slug, value= message type.
874
+		$match_array = [
875
+			'approve_registrations'    => 'registration',
876
+			'decline_registrations'    => 'declined_registration',
877
+			'pending_registrations'    => 'pending_approval',
878
+			'no_approve_registrations' => 'not_approved_registration',
879
+			'cancel_registrations'     => 'cancelled_registration',
880
+		];
881
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
882
+			'ee_send_message',
883
+			'batch_send_messages'
884
+		);
885
+		/** setup reg status bulk actions **/
886
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
+				'Approve and Notify Registrations',
890
+				'event_espresso'
891
+			);
892
+		}
893
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
+				'Decline and Notify Registrations',
897
+				'event_espresso'
898
+			);
899
+		}
900
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
901
+			'Set Registrations to Pending Payment',
902
+			'event_espresso'
903
+		);
904
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
+				'Set Registrations to Pending Payment and Notify',
907
+				'event_espresso'
908
+			);
909
+		}
910
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
+			'Set Registrations to Not Approved',
912
+			'event_espresso'
913
+		);
914
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
+				'Set Registrations to Not Approved and Notify',
917
+				'event_espresso'
918
+			);
919
+		}
920
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
+				'Cancel Registrations and Notify',
924
+				'event_espresso'
925
+			);
926
+		}
927
+		$def_reg_status_actions = apply_filters(
928
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
+			$def_reg_status_actions,
930
+			$active_mts,
931
+			$can_send
932
+		);
933
+
934
+		$this->_views = [
935
+			'all'   => [
936
+				'slug'        => 'all',
937
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
+				'count'       => 0,
939
+				'bulk_action' => array_merge(
940
+					$def_reg_status_actions,
941
+					[
942
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
+					]
944
+				),
945
+			],
946
+			'month' => [
947
+				'slug'        => 'month',
948
+				'label'       => esc_html__('This Month', 'event_espresso'),
949
+				'count'       => 0,
950
+				'bulk_action' => array_merge(
951
+					$def_reg_status_actions,
952
+					[
953
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
+					]
955
+				),
956
+			],
957
+			'today' => [
958
+				'slug'        => 'today',
959
+				'label'       => sprintf(
960
+					esc_html__('Today - %s', 'event_espresso'),
961
+					date('M d, Y', current_time('timestamp'))
962
+				),
963
+				'count'       => 0,
964
+				'bulk_action' => array_merge(
965
+					$def_reg_status_actions,
966
+					[
967
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
+					]
969
+				),
970
+			],
971
+		];
972
+		if (
973
+			EE_Registry::instance()->CAP->current_user_can(
974
+				'ee_delete_registrations',
975
+				'espresso_registrations_delete_registration'
976
+			)
977
+		) {
978
+			$this->_views['incomplete'] = [
979
+				'slug'        => 'incomplete',
980
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
981
+				'count'       => 0,
982
+				'bulk_action' => [
983
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
+				],
985
+			];
986
+			$this->_views['trash']      = [
987
+				'slug'        => 'trash',
988
+				'label'       => esc_html__('Trash', 'event_espresso'),
989
+				'count'       => 0,
990
+				'bulk_action' => [
991
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
+				],
994
+			];
995
+		}
996
+	}
997
+
998
+
999
+	protected function _set_list_table_views_contact_list()
1000
+	{
1001
+		$this->_views = [
1002
+			'in_use' => [
1003
+				'slug'        => 'in_use',
1004
+				'label'       => esc_html__('In Use', 'event_espresso'),
1005
+				'count'       => 0,
1006
+				'bulk_action' => [
1007
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
+				],
1009
+			],
1010
+		];
1011
+		if (
1012
+			EE_Registry::instance()->CAP->current_user_can(
1013
+				'ee_delete_contacts',
1014
+				'espresso_registrations_trash_attendees'
1015
+			)
1016
+		) {
1017
+			$this->_views['trash'] = [
1018
+				'slug'        => 'trash',
1019
+				'label'       => esc_html__('Trash', 'event_espresso'),
1020
+				'count'       => 0,
1021
+				'bulk_action' => [
1022
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
+				],
1024
+			];
1025
+		}
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * @return array
1031
+	 * @throws EE_Error
1032
+	 */
1033
+	protected function _registration_legend_items()
1034
+	{
1035
+		$fc_items = [
1036
+			'star-icon'        => [
1037
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1038
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1039
+			],
1040
+			'view_details'     => [
1041
+				'class' => 'dashicons dashicons-clipboard',
1042
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1043
+			],
1044
+			'edit_attendee'    => [
1045
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1046
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1047
+			],
1048
+			'view_transaction' => [
1049
+				'class' => 'dashicons dashicons-cart',
1050
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1051
+			],
1052
+			'view_invoice'     => [
1053
+				'class' => 'dashicons dashicons-media-spreadsheet',
1054
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1055
+			],
1056
+		];
1057
+		if (
1058
+			EE_Registry::instance()->CAP->current_user_can(
1059
+				'ee_send_message',
1060
+				'espresso_registrations_resend_registration'
1061
+			)
1062
+		) {
1063
+			$fc_items['resend_registration'] = [
1064
+				'class' => 'dashicons dashicons-email-alt',
1065
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1066
+			];
1067
+		} else {
1068
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1069
+		}
1070
+		if (
1071
+			EE_Registry::instance()->CAP->current_user_can(
1072
+				'ee_read_global_messages',
1073
+				'view_filtered_messages'
1074
+			)
1075
+		) {
1076
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1077
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1078
+				$fc_items['view_related_messages'] = [
1079
+					'class' => $related_for_icon['css_class'],
1080
+					'desc'  => $related_for_icon['label'],
1081
+				];
1082
+			}
1083
+		}
1084
+		$sc_items = [
1085
+			'approved_status'   => [
1086
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1087
+				'desc'  => EEH_Template::pretty_status(
1088
+					EEM_Registration::status_id_approved,
1089
+					false,
1090
+					'sentence'
1091
+				),
1092
+			],
1093
+			'pending_status'    => [
1094
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1095
+				'desc'  => EEH_Template::pretty_status(
1096
+					EEM_Registration::status_id_pending_payment,
1097
+					false,
1098
+					'sentence'
1099
+				),
1100
+			],
1101
+			'wait_list'         => [
1102
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1103
+				'desc'  => EEH_Template::pretty_status(
1104
+					EEM_Registration::status_id_wait_list,
1105
+					false,
1106
+					'sentence'
1107
+				),
1108
+			],
1109
+			'incomplete_status' => [
1110
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1111
+				'desc'  => EEH_Template::pretty_status(
1112
+					EEM_Registration::status_id_incomplete,
1113
+					false,
1114
+					'sentence'
1115
+				),
1116
+			],
1117
+			'not_approved'      => [
1118
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1119
+				'desc'  => EEH_Template::pretty_status(
1120
+					EEM_Registration::status_id_not_approved,
1121
+					false,
1122
+					'sentence'
1123
+				),
1124
+			],
1125
+			'declined_status'   => [
1126
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1127
+				'desc'  => EEH_Template::pretty_status(
1128
+					EEM_Registration::status_id_declined,
1129
+					false,
1130
+					'sentence'
1131
+				),
1132
+			],
1133
+			'cancelled_status'  => [
1134
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1135
+				'desc'  => EEH_Template::pretty_status(
1136
+					EEM_Registration::status_id_cancelled,
1137
+					false,
1138
+					'sentence'
1139
+				),
1140
+			],
1141
+		];
1142
+		return array_merge($fc_items, $sc_items);
1143
+	}
1144
+
1145
+
1146
+
1147
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1148
+
1149
+
1150
+	/**
1151
+	 * @throws DomainException
1152
+	 * @throws EE_Error
1153
+	 * @throws InvalidArgumentException
1154
+	 * @throws InvalidDataTypeException
1155
+	 * @throws InvalidInterfaceException
1156
+	 */
1157
+	protected function _registrations_overview_list_table()
1158
+	{
1159
+		$this->appendAddNewRegistrationButtonToPageTitle();
1160
+		$header_text                  = '';
1161
+		$admin_page_header_decorators = [
1162
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1164
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1165
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1166
+		];
1167
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1168
+			$filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1169
+			$header_text             = $filter_header_decorator->getHeaderText($header_text);
1170
+		}
1171
+		$this->_template_args['admin_page_header'] = $header_text;
1172
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1173
+		$this->display_admin_list_table_page_with_no_sidebar();
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * @throws EE_Error
1179
+	 * @throws InvalidArgumentException
1180
+	 * @throws InvalidDataTypeException
1181
+	 * @throws InvalidInterfaceException
1182
+	 */
1183
+	private function appendAddNewRegistrationButtonToPageTitle()
1184
+	{
1185
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1186
+		if (
1187
+			$EVT_ID
1188
+			&& EE_Registry::instance()->CAP->current_user_can(
1189
+				'ee_edit_registrations',
1190
+				'espresso_registrations_new_registration',
1191
+				$EVT_ID
1192
+			)
1193
+		) {
1194
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
+				'new_registration',
1196
+				'add-registrant',
1197
+				['event_id' => $EVT_ID],
1198
+				'add-new-h2'
1199
+			);
1200
+		}
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * This sets the _registration property for the registration details screen
1206
+	 *
1207
+	 * @return void
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws InvalidDataTypeException
1211
+	 * @throws InvalidInterfaceException
1212
+	 */
1213
+	private function _set_registration_object()
1214
+	{
1215
+		// get out if we've already set the object
1216
+		if ($this->_registration instanceof EE_Registration) {
1217
+			return;
1218
+		}
1219
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1220
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1221
+			return;
1222
+		}
1223
+		$error_msg = sprintf(
1224
+			esc_html__(
1225
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1226
+				'event_espresso'
1227
+			),
1228
+			$REG_ID
1229
+		);
1230
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1231
+		$this->_registration = null;
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * Used to retrieve registrations for the list table.
1237
+	 *
1238
+	 * @param int  $per_page
1239
+	 * @param bool $count
1240
+	 * @param bool $this_month
1241
+	 * @param bool $today
1242
+	 * @return EE_Registration[]|int
1243
+	 * @throws EE_Error
1244
+	 * @throws InvalidArgumentException
1245
+	 * @throws InvalidDataTypeException
1246
+	 * @throws InvalidInterfaceException
1247
+	 */
1248
+	public function get_registrations(
1249
+		$per_page = 10,
1250
+		$count = false,
1251
+		$this_month = false,
1252
+		$today = false
1253
+	) {
1254
+		if ($this_month) {
1255
+			$this->request->setRequestParam('status', 'month');
1256
+		}
1257
+		if ($today) {
1258
+			$this->request->setRequestParam('status', 'today');
1259
+		}
1260
+		$query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1261
+		/**
1262
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
+		 *
1264
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1265
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1266
+		 *                      or if you have the development copy of EE you can view this at the path:
1267
+		 *                      /docs/G--Model-System/model-query-params.md
1268
+		 */
1269
+		$query_params['group_by'] = '';
1270
+
1271
+		return $count
1272
+			? $this->getRegistrationModel()->count($query_params)
1273
+			/** @type EE_Registration[] */
1274
+			: $this->getRegistrationModel()->get_all($query_params);
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1280
+	 * Note: this listens to values on the request for some of the query parameters.
1281
+	 *
1282
+	 * @param array $request
1283
+	 * @param int   $per_page
1284
+	 * @param bool  $count
1285
+	 * @return array
1286
+	 * @throws EE_Error
1287
+	 * @throws InvalidArgumentException
1288
+	 * @throws InvalidDataTypeException
1289
+	 * @throws InvalidInterfaceException
1290
+	 */
1291
+	protected function _get_registration_query_parameters(
1292
+		$request = [],
1293
+		$per_page = 10,
1294
+		$count = false
1295
+	) {
1296
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1297
+		$list_table_query_builder = $this->getLoader()->getNew(
1298
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1299
+			[null, null, $request]
1300
+		);
1301
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1302
+	}
1303
+
1304
+
1305
+	public function get_registration_status_array()
1306
+	{
1307
+		return self::$_reg_status;
1308
+	}
1309
+
1310
+
1311
+
1312
+
1313
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1314
+	/**
1315
+	 * generates HTML for the View Registration Details Admin page
1316
+	 *
1317
+	 * @return void
1318
+	 * @throws DomainException
1319
+	 * @throws EE_Error
1320
+	 * @throws InvalidArgumentException
1321
+	 * @throws InvalidDataTypeException
1322
+	 * @throws InvalidInterfaceException
1323
+	 * @throws EntityNotFoundException
1324
+	 * @throws ReflectionException
1325
+	 */
1326
+	protected function _registration_details()
1327
+	{
1328
+		$this->_template_args = [];
1329
+		$this->_set_registration_object();
1330
+		if (is_object($this->_registration)) {
1331
+			$transaction                                   = $this->_registration->transaction()
1332
+				? $this->_registration->transaction()
1333
+				: EE_Transaction::new_instance();
1334
+			$this->_session                                = $transaction->session_data();
1335
+			$event_id                                      = $this->_registration->event_ID();
1336
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1337
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1338
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1339
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1340
+			$this->_template_args['grand_total']           = $transaction->total();
1341
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1342
+			// link back to overview
1343
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1344
+			$this->_template_args['registration']                = $this->_registration;
1345
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1346
+				[
1347
+					'action'   => 'default',
1348
+					'event_id' => $event_id,
1349
+				],
1350
+				REG_ADMIN_URL
1351
+			);
1352
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1353
+				[
1354
+					'action' => 'default',
1355
+					'EVT_ID' => $event_id,
1356
+					'page'   => 'espresso_transactions',
1357
+				],
1358
+				admin_url('admin.php')
1359
+			);
1360
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1361
+				[
1362
+					'page'   => 'espresso_events',
1363
+					'action' => 'edit',
1364
+					'post'   => $event_id,
1365
+				],
1366
+				admin_url('admin.php')
1367
+			);
1368
+			// next and previous links
1369
+			$next_reg                                      = $this->_registration->next(
1370
+				null,
1371
+				[],
1372
+				'REG_ID'
1373
+			);
1374
+			$this->_template_args['next_registration']     = $next_reg
1375
+				? $this->_next_link(
1376
+					EE_Admin_Page::add_query_args_and_nonce(
1377
+						[
1378
+							'action'  => 'view_registration',
1379
+							'_REG_ID' => $next_reg['REG_ID'],
1380
+						],
1381
+						REG_ADMIN_URL
1382
+					),
1383
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1384
+				)
1385
+				: '';
1386
+			$previous_reg                                  = $this->_registration->previous(
1387
+				null,
1388
+				[],
1389
+				'REG_ID'
1390
+			);
1391
+			$this->_template_args['previous_registration'] = $previous_reg
1392
+				? $this->_previous_link(
1393
+					EE_Admin_Page::add_query_args_and_nonce(
1394
+						[
1395
+							'action'  => 'view_registration',
1396
+							'_REG_ID' => $previous_reg['REG_ID'],
1397
+						],
1398
+						REG_ADMIN_URL
1399
+					),
1400
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1401
+				)
1402
+				: '';
1403
+			// grab header
1404
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1405
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1406
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1407
+				$template_path,
1408
+				$this->_template_args,
1409
+				true
1410
+			);
1411
+		} else {
1412
+			$this->_template_args['admin_page_header'] = '';
1413
+			$this->_display_espresso_notices();
1414
+		}
1415
+		// the details template wrapper
1416
+		$this->display_admin_page_with_sidebar();
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 * @throws EE_Error
1422
+	 * @throws InvalidArgumentException
1423
+	 * @throws InvalidDataTypeException
1424
+	 * @throws InvalidInterfaceException
1425
+	 * @throws ReflectionException
1426
+	 * @since 4.10.2.p
1427
+	 */
1428
+	protected function _registration_details_metaboxes()
1429
+	{
1430
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1431
+		$this->_set_registration_object();
1432
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1433
+		add_meta_box(
1434
+			'edit-reg-status-mbox',
1435
+			esc_html__('Registration Status', 'event_espresso'),
1436
+			[$this, 'set_reg_status_buttons_metabox'],
1437
+			$this->_wp_page_slug,
1438
+			'normal',
1439
+			'high'
1440
+		);
1441
+		add_meta_box(
1442
+			'edit-reg-details-mbox',
1443
+			esc_html__('Registration Details', 'event_espresso'),
1444
+			[$this, '_reg_details_meta_box'],
1445
+			$this->_wp_page_slug,
1446
+			'normal',
1447
+			'high'
1448
+		);
1449
+		if (
1450
+			$attendee instanceof EE_Attendee
1451
+			&& EE_Registry::instance()->CAP->current_user_can(
1452
+				'ee_read_registration',
1453
+				'edit-reg-questions-mbox',
1454
+				$this->_registration->ID()
1455
+			)
1456
+		) {
1457
+			add_meta_box(
1458
+				'edit-reg-questions-mbox',
1459
+				esc_html__('Registration Form Answers', 'event_espresso'),
1460
+				[$this, '_reg_questions_meta_box'],
1461
+				$this->_wp_page_slug,
1462
+				'normal',
1463
+				'high'
1464
+			);
1465
+		}
1466
+		add_meta_box(
1467
+			'edit-reg-registrant-mbox',
1468
+			esc_html__('Contact Details', 'event_espresso'),
1469
+			[$this, '_reg_registrant_side_meta_box'],
1470
+			$this->_wp_page_slug,
1471
+			'side',
1472
+			'high'
1473
+		);
1474
+		if ($this->_registration->group_size() > 1) {
1475
+			add_meta_box(
1476
+				'edit-reg-attendees-mbox',
1477
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1478
+				[$this, '_reg_attendees_meta_box'],
1479
+				$this->_wp_page_slug,
1480
+				'normal',
1481
+				'high'
1482
+			);
1483
+		}
1484
+	}
1485
+
1486
+
1487
+	/**
1488
+	 * set_reg_status_buttons_metabox
1489
+	 *
1490
+	 * @return void
1491
+	 * @throws EE_Error
1492
+	 * @throws EntityNotFoundException
1493
+	 * @throws InvalidArgumentException
1494
+	 * @throws InvalidDataTypeException
1495
+	 * @throws InvalidInterfaceException
1496
+	 * @throws ReflectionException
1497
+	 */
1498
+	public function set_reg_status_buttons_metabox()
1499
+	{
1500
+		$this->_set_registration_object();
1501
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1502
+		$output                 = $change_reg_status_form->form_open(
1503
+			self::add_query_args_and_nonce(
1504
+				[
1505
+					'action' => 'change_reg_status',
1506
+				],
1507
+				REG_ADMIN_URL
1508
+			)
1509
+		);
1510
+		$output                 .= $change_reg_status_form->get_html();
1511
+		$output                 .= $change_reg_status_form->form_close();
1512
+		echo wp_kses($output, AllowedTags::getWithFormTags());
1513
+	}
1514
+
1515
+
1516
+	/**
1517
+	 * @return EE_Form_Section_Proper
1518
+	 * @throws EE_Error
1519
+	 * @throws InvalidArgumentException
1520
+	 * @throws InvalidDataTypeException
1521
+	 * @throws InvalidInterfaceException
1522
+	 * @throws EntityNotFoundException
1523
+	 * @throws ReflectionException
1524
+	 */
1525
+	protected function _generate_reg_status_change_form()
1526
+	{
1527
+		$reg_status_change_form_array = [
1528
+			'name'            => 'reg_status_change_form',
1529
+			'html_id'         => 'reg-status-change-form',
1530
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1531
+			'subsections'     => [
1532
+				'return'         => new EE_Hidden_Input(
1533
+					[
1534
+						'name'    => 'return',
1535
+						'default' => 'view_registration',
1536
+					]
1537
+				),
1538
+				'REG_ID'         => new EE_Hidden_Input(
1539
+					[
1540
+						'name'    => 'REG_ID',
1541
+						'default' => $this->_registration->ID(),
1542
+					]
1543
+				),
1544
+				'current_status' => new EE_Form_Section_HTML(
1545
+					EEH_HTML::table(
1546
+						EEH_HTML::tr(
1547
+							EEH_HTML::th(
1548
+								EEH_HTML::label(
1549
+									EEH_HTML::strong(
1550
+										esc_html__('Current Registration Status', 'event_espresso')
1551
+									)
1552
+								)
1553
+							)
1554
+							. EEH_HTML::td(
1555
+								EEH_HTML::strong(
1556
+									$this->_registration->pretty_status(),
1557
+									'',
1558
+									'status-' . $this->_registration->status_ID(),
1559
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1560
+								)
1561
+							)
1562
+						)
1563
+					)
1564
+				),
1565
+			],
1566
+		];
1567
+		if (
1568
+			EE_Registry::instance()->CAP->current_user_can(
1569
+				'ee_edit_registration',
1570
+				'toggle_registration_status',
1571
+				$this->_registration->ID()
1572
+			)
1573
+		) {
1574
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1575
+				$this->_get_reg_statuses(),
1576
+				[
1577
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1578
+					'default'         => $this->_registration->status_ID(),
1579
+				]
1580
+			);
1581
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1582
+				[
1583
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1584
+					'default'         => false,
1585
+					'html_help_text'  => esc_html__(
1586
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1587
+						'event_espresso'
1588
+					),
1589
+				]
1590
+			);
1591
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1592
+				[
1593
+					'html_class'      => 'button-primary',
1594
+					'html_label_text' => '&nbsp;',
1595
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1596
+				]
1597
+			);
1598
+		}
1599
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1600
+	}
1601
+
1602
+
1603
+	/**
1604
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1605
+	 *
1606
+	 * @return array
1607
+	 * @throws EE_Error
1608
+	 * @throws InvalidArgumentException
1609
+	 * @throws InvalidDataTypeException
1610
+	 * @throws InvalidInterfaceException
1611
+	 * @throws EntityNotFoundException
1612
+	 */
1613
+	protected function _get_reg_statuses()
1614
+	{
1615
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1616
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1617
+		// get current reg status
1618
+		$current_status = $this->_registration->status_ID();
1619
+		// is registration for free event? This will determine whether to display the pending payment option
1620
+		if (
1621
+			$current_status !== EEM_Registration::status_id_pending_payment
1622
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1623
+		) {
1624
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1625
+		}
1626
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1632
+	 *
1633
+	 * @param bool $status REG status given for changing registrations to.
1634
+	 * @param bool $notify Whether to send messages notifications or not.
1635
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1636
+	 * @throws DomainException
1637
+	 * @throws EE_Error
1638
+	 * @throws EntityNotFoundException
1639
+	 * @throws InvalidArgumentException
1640
+	 * @throws InvalidDataTypeException
1641
+	 * @throws InvalidInterfaceException
1642
+	 * @throws ReflectionException
1643
+	 * @throws RuntimeException
1644
+	 */
1645
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1646
+	{
1647
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1648
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1649
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1650
+
1651
+		// sanitize $REG_IDs
1652
+		$REG_IDs = array_map('absint', $REG_IDs);
1653
+		// and remove empty entries
1654
+		$REG_IDs = array_filter($REG_IDs);
1655
+
1656
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1657
+
1658
+		/**
1659
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1660
+		 * Currently this value is used downstream by the _process_resend_registration method.
1661
+		 *
1662
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1663
+		 * @param bool                     $status           The status registrations were changed to.
1664
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1665
+		 * @param Registrations_Admin_Page $admin_page_object
1666
+		 */
1667
+		$REG_ID = apply_filters(
1668
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1669
+			$result['REG_ID'],
1670
+			$status,
1671
+			$result['success'],
1672
+			$this
1673
+		);
1674
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1675
+
1676
+		// notify?
1677
+		if (
1678
+			$notify
1679
+			&& $result['success']
1680
+			&& ! empty($REG_ID)
1681
+			&& EE_Registry::instance()->CAP->current_user_can(
1682
+				'ee_send_message',
1683
+				'espresso_registrations_resend_registration'
1684
+			)
1685
+		) {
1686
+			$this->_process_resend_registration();
1687
+		}
1688
+		return $result;
1689
+	}
1690
+
1691
+
1692
+	/**
1693
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1694
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1695
+	 *
1696
+	 * @param array  $REG_IDs
1697
+	 * @param string $status
1698
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1699
+	 *                       slug sent with setting the registration status.
1700
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1701
+	 * @throws EE_Error
1702
+	 * @throws InvalidArgumentException
1703
+	 * @throws InvalidDataTypeException
1704
+	 * @throws InvalidInterfaceException
1705
+	 * @throws ReflectionException
1706
+	 * @throws RuntimeException
1707
+	 * @throws EntityNotFoundException
1708
+	 * @throws DomainException
1709
+	 */
1710
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1711
+	{
1712
+		$success = false;
1713
+		// typecast $REG_IDs
1714
+		$REG_IDs = (array) $REG_IDs;
1715
+		if (! empty($REG_IDs)) {
1716
+			$success = true;
1717
+			// set default status if none is passed
1718
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1719
+			$status_context = $notify
1720
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1721
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1722
+			// loop through REG_ID's and change status
1723
+			foreach ($REG_IDs as $REG_ID) {
1724
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1725
+				if ($registration instanceof EE_Registration) {
1726
+					$registration->set_status(
1727
+						$status,
1728
+						false,
1729
+						new Context(
1730
+							$status_context,
1731
+							esc_html__(
1732
+								'Manually triggered status change on a Registration Admin Page route.',
1733
+								'event_espresso'
1734
+							)
1735
+						)
1736
+					);
1737
+					$result = $registration->save();
1738
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1739
+					$success = $result !== false ? $success : false;
1740
+				}
1741
+			}
1742
+		}
1743
+
1744
+		// return $success and processed registrations
1745
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1746
+	}
1747
+
1748
+
1749
+	/**
1750
+	 * Common logic for setting up success message and redirecting to appropriate route
1751
+	 *
1752
+	 * @param string $STS_ID status id for the registration changed to
1753
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1754
+	 * @return void
1755
+	 * @throws DomainException
1756
+	 * @throws EE_Error
1757
+	 * @throws EntityNotFoundException
1758
+	 * @throws InvalidArgumentException
1759
+	 * @throws InvalidDataTypeException
1760
+	 * @throws InvalidInterfaceException
1761
+	 * @throws ReflectionException
1762
+	 * @throws RuntimeException
1763
+	 */
1764
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1765
+	{
1766
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1767
+			: ['success' => false];
1768
+		$success = isset($result['success']) && $result['success'];
1769
+		// setup success message
1770
+		if ($success) {
1771
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1772
+				$msg = sprintf(
1773
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1774
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1775
+				);
1776
+			} else {
1777
+				$msg = sprintf(
1778
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1779
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1780
+				);
1781
+			}
1782
+			EE_Error::add_success($msg);
1783
+		} else {
1784
+			EE_Error::add_error(
1785
+				esc_html__(
1786
+					'Something went wrong, and the status was not changed',
1787
+					'event_espresso'
1788
+				),
1789
+				__FILE__,
1790
+				__LINE__,
1791
+				__FUNCTION__
1792
+			);
1793
+		}
1794
+		$return = $this->request->getRequestParam('return');
1795
+		$route  = $return === 'view_registration'
1796
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1797
+			: ['action' => 'default'];
1798
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1799
+		$this->_redirect_after_action($success, '', '', $route, true);
1800
+	}
1801
+
1802
+
1803
+	/**
1804
+	 * incoming reg status change from reg details page.
1805
+	 *
1806
+	 * @return void
1807
+	 * @throws EE_Error
1808
+	 * @throws EntityNotFoundException
1809
+	 * @throws InvalidArgumentException
1810
+	 * @throws InvalidDataTypeException
1811
+	 * @throws InvalidInterfaceException
1812
+	 * @throws ReflectionException
1813
+	 * @throws RuntimeException
1814
+	 * @throws DomainException
1815
+	 */
1816
+	protected function _change_reg_status()
1817
+	{
1818
+		$this->request->setRequestParam('return', 'view_registration');
1819
+		// set notify based on whether the send notifications toggle is set or not
1820
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1821
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1822
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1823
+		switch ($reg_status) {
1824
+			case EEM_Registration::status_id_approved:
1825
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1826
+				$this->approve_registration($notify);
1827
+				break;
1828
+			case EEM_Registration::status_id_pending_payment:
1829
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1830
+				$this->pending_registration($notify);
1831
+				break;
1832
+			case EEM_Registration::status_id_not_approved:
1833
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1834
+				$this->not_approve_registration($notify);
1835
+				break;
1836
+			case EEM_Registration::status_id_declined:
1837
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1838
+				$this->decline_registration($notify);
1839
+				break;
1840
+			case EEM_Registration::status_id_cancelled:
1841
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1842
+				$this->cancel_registration($notify);
1843
+				break;
1844
+			case EEM_Registration::status_id_wait_list:
1845
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1846
+				$this->wait_list_registration($notify);
1847
+				break;
1848
+			case EEM_Registration::status_id_incomplete:
1849
+			default:
1850
+				$this->request->unSetRequestParam('return');
1851
+				$this->_reg_status_change_return('');
1852
+				break;
1853
+		}
1854
+	}
1855
+
1856
+
1857
+	/**
1858
+	 * Callback for bulk action routes.
1859
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1860
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1861
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1862
+	 * when an action is happening on just a single registration).
1863
+	 *
1864
+	 * @param      $action
1865
+	 * @param bool $notify
1866
+	 */
1867
+	protected function bulk_action_on_registrations($action, $notify = false)
1868
+	{
1869
+		do_action(
1870
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1871
+			$this,
1872
+			$action,
1873
+			$notify
1874
+		);
1875
+		$method = $action . '_registration';
1876
+		if (method_exists($this, $method)) {
1877
+			$this->$method($notify);
1878
+		}
1879
+	}
1880
+
1881
+
1882
+	/**
1883
+	 * approve_registration
1884
+	 *
1885
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1886
+	 * @return void
1887
+	 * @throws EE_Error
1888
+	 * @throws EntityNotFoundException
1889
+	 * @throws InvalidArgumentException
1890
+	 * @throws InvalidDataTypeException
1891
+	 * @throws InvalidInterfaceException
1892
+	 * @throws ReflectionException
1893
+	 * @throws RuntimeException
1894
+	 * @throws DomainException
1895
+	 */
1896
+	protected function approve_registration($notify = false)
1897
+	{
1898
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1899
+	}
1900
+
1901
+
1902
+	/**
1903
+	 * decline_registration
1904
+	 *
1905
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1906
+	 * @return void
1907
+	 * @throws EE_Error
1908
+	 * @throws EntityNotFoundException
1909
+	 * @throws InvalidArgumentException
1910
+	 * @throws InvalidDataTypeException
1911
+	 * @throws InvalidInterfaceException
1912
+	 * @throws ReflectionException
1913
+	 * @throws RuntimeException
1914
+	 * @throws DomainException
1915
+	 */
1916
+	protected function decline_registration($notify = false)
1917
+	{
1918
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1919
+	}
1920
+
1921
+
1922
+	/**
1923
+	 * cancel_registration
1924
+	 *
1925
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1926
+	 * @return void
1927
+	 * @throws EE_Error
1928
+	 * @throws EntityNotFoundException
1929
+	 * @throws InvalidArgumentException
1930
+	 * @throws InvalidDataTypeException
1931
+	 * @throws InvalidInterfaceException
1932
+	 * @throws ReflectionException
1933
+	 * @throws RuntimeException
1934
+	 * @throws DomainException
1935
+	 */
1936
+	protected function cancel_registration($notify = false)
1937
+	{
1938
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1939
+	}
1940
+
1941
+
1942
+	/**
1943
+	 * not_approve_registration
1944
+	 *
1945
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1946
+	 * @return void
1947
+	 * @throws EE_Error
1948
+	 * @throws EntityNotFoundException
1949
+	 * @throws InvalidArgumentException
1950
+	 * @throws InvalidDataTypeException
1951
+	 * @throws InvalidInterfaceException
1952
+	 * @throws ReflectionException
1953
+	 * @throws RuntimeException
1954
+	 * @throws DomainException
1955
+	 */
1956
+	protected function not_approve_registration($notify = false)
1957
+	{
1958
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1959
+	}
1960
+
1961
+
1962
+	/**
1963
+	 * decline_registration
1964
+	 *
1965
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1966
+	 * @return void
1967
+	 * @throws EE_Error
1968
+	 * @throws EntityNotFoundException
1969
+	 * @throws InvalidArgumentException
1970
+	 * @throws InvalidDataTypeException
1971
+	 * @throws InvalidInterfaceException
1972
+	 * @throws ReflectionException
1973
+	 * @throws RuntimeException
1974
+	 * @throws DomainException
1975
+	 */
1976
+	protected function pending_registration($notify = false)
1977
+	{
1978
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1979
+	}
1980
+
1981
+
1982
+	/**
1983
+	 * waitlist_registration
1984
+	 *
1985
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1986
+	 * @return void
1987
+	 * @throws EE_Error
1988
+	 * @throws EntityNotFoundException
1989
+	 * @throws InvalidArgumentException
1990
+	 * @throws InvalidDataTypeException
1991
+	 * @throws InvalidInterfaceException
1992
+	 * @throws ReflectionException
1993
+	 * @throws RuntimeException
1994
+	 * @throws DomainException
1995
+	 */
1996
+	protected function wait_list_registration($notify = false)
1997
+	{
1998
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1999
+	}
2000
+
2001
+
2002
+	/**
2003
+	 * generates HTML for the Registration main meta box
2004
+	 *
2005
+	 * @return void
2006
+	 * @throws DomainException
2007
+	 * @throws EE_Error
2008
+	 * @throws InvalidArgumentException
2009
+	 * @throws InvalidDataTypeException
2010
+	 * @throws InvalidInterfaceException
2011
+	 * @throws ReflectionException
2012
+	 * @throws EntityNotFoundException
2013
+	 */
2014
+	public function _reg_details_meta_box()
2015
+	{
2016
+		EEH_Autoloader::register_line_item_display_autoloaders();
2017
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2018
+		EE_Registry::instance()->load_helper('Line_Item');
2019
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2020
+			: EE_Transaction::new_instance();
2021
+		$this->_session = $transaction->session_data();
2022
+		$filters        = new EE_Line_Item_Filter_Collection();
2023
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2024
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2025
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2026
+			$filters,
2027
+			$transaction->total_line_item()
2028
+		);
2029
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2030
+		$line_item_display                       = new EE_Line_Item_Display(
2031
+			'reg_admin_table',
2032
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2033
+		);
2034
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2035
+			$filtered_line_item_tree,
2036
+			['EE_Registration' => $this->_registration]
2037
+		);
2038
+		$attendee                                = $this->_registration->attendee();
2039
+		if (
2040
+			EE_Registry::instance()->CAP->current_user_can(
2041
+				'ee_read_transaction',
2042
+				'espresso_transactions_view_transaction'
2043
+			)
2044
+		) {
2045
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2046
+				EE_Admin_Page::add_query_args_and_nonce(
2047
+					[
2048
+						'action' => 'view_transaction',
2049
+						'TXN_ID' => $transaction->ID(),
2050
+					],
2051
+					TXN_ADMIN_URL
2052
+				),
2053
+				esc_html__(' View Transaction', 'event_espresso'),
2054
+				'button secondary-button right',
2055
+				'dashicons dashicons-cart'
2056
+			);
2057
+		} else {
2058
+			$this->_template_args['view_transaction_button'] = '';
2059
+		}
2060
+		if (
2061
+			$attendee instanceof EE_Attendee
2062
+			&& EE_Registry::instance()->CAP->current_user_can(
2063
+				'ee_send_message',
2064
+				'espresso_registrations_resend_registration'
2065
+			)
2066
+		) {
2067
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2068
+				EE_Admin_Page::add_query_args_and_nonce(
2069
+					[
2070
+						'action'      => 'resend_registration',
2071
+						'_REG_ID'     => $this->_registration->ID(),
2072
+						'redirect_to' => 'view_registration',
2073
+					],
2074
+					REG_ADMIN_URL
2075
+				),
2076
+				esc_html__(' Resend Registration', 'event_espresso'),
2077
+				'button secondary-button right',
2078
+				'dashicons dashicons-email-alt'
2079
+			);
2080
+		} else {
2081
+			$this->_template_args['resend_registration_button'] = '';
2082
+		}
2083
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2084
+		$payment                               = $transaction->get_first_related('Payment');
2085
+		$payment                               = ! $payment instanceof EE_Payment
2086
+			? EE_Payment::new_instance()
2087
+			: $payment;
2088
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2089
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2090
+			? EE_Payment_Method::new_instance()
2091
+			: $payment_method;
2092
+		$reg_details                           = [
2093
+			'payment_method'       => $payment_method->name(),
2094
+			'response_msg'         => $payment->gateway_response(),
2095
+			'registration_id'      => $this->_registration->get('REG_code'),
2096
+			'registration_session' => $this->_registration->session_ID(),
2097
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2098
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2099
+		];
2100
+		if (isset($reg_details['registration_id'])) {
2101
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2102
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2103
+				'Registration ID',
2104
+				'event_espresso'
2105
+			);
2106
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2107
+		}
2108
+		if (isset($reg_details['payment_method'])) {
2109
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2110
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2111
+				'Most Recent Payment Method',
2112
+				'event_espresso'
2113
+			);
2114
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2115
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2116
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2117
+				'Payment method response',
2118
+				'event_espresso'
2119
+			);
2120
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2121
+		}
2122
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2123
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2124
+			'Registration Session',
2125
+			'event_espresso'
2126
+		);
2127
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2128
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2129
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2130
+			'Registration placed from IP',
2131
+			'event_espresso'
2132
+		);
2133
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2134
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2135
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2136
+			'Registrant User Agent',
2137
+			'event_espresso'
2138
+		);
2139
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2140
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2141
+			[
2142
+				'action'   => 'default',
2143
+				'event_id' => $this->_registration->event_ID(),
2144
+			],
2145
+			REG_ADMIN_URL
2146
+		);
2147
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2148
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2149
+		$template_path                                                        =
2150
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2151
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2152
+	}
2153
+
2154
+
2155
+	/**
2156
+	 * generates HTML for the Registration Questions meta box.
2157
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2158
+	 * otherwise uses new forms system
2159
+	 *
2160
+	 * @return void
2161
+	 * @throws DomainException
2162
+	 * @throws EE_Error
2163
+	 * @throws InvalidArgumentException
2164
+	 * @throws InvalidDataTypeException
2165
+	 * @throws InvalidInterfaceException
2166
+	 * @throws ReflectionException
2167
+	 */
2168
+	public function _reg_questions_meta_box()
2169
+	{
2170
+		// allow someone to override this method entirely
2171
+		if (
2172
+			apply_filters(
2173
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2174
+				true,
2175
+				$this,
2176
+				$this->_registration
2177
+			)
2178
+		) {
2179
+			$form                                              = $this->_get_reg_custom_questions_form(
2180
+				$this->_registration->ID()
2181
+			);
2182
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2183
+				? $form->get_html_and_js()
2184
+				: '';
2185
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2186
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2187
+			$template_path                                     =
2188
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2189
+			EEH_Template::display_template($template_path, $this->_template_args);
2190
+		}
2191
+	}
2192
+
2193
+
2194
+	/**
2195
+	 * form_before_question_group
2196
+	 *
2197
+	 * @param string $output
2198
+	 * @return        string
2199
+	 * @deprecated    as of 4.8.32.rc.000
2200
+	 */
2201
+	public function form_before_question_group($output)
2202
+	{
2203
+		EE_Error::doing_it_wrong(
2204
+			__CLASS__ . '::' . __FUNCTION__,
2205
+			esc_html__(
2206
+				'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.',
2207
+				'event_espresso'
2208
+			),
2209
+			'4.8.32.rc.000'
2210
+		);
2211
+		return '
2212 2212
 	<table class="form-table ee-width-100">
2213 2213
 		<tbody>
2214 2214
 			';
2215
-    }
2216
-
2217
-
2218
-    /**
2219
-     * form_after_question_group
2220
-     *
2221
-     * @param string $output
2222
-     * @return        string
2223
-     * @deprecated    as of 4.8.32.rc.000
2224
-     */
2225
-    public function form_after_question_group($output)
2226
-    {
2227
-        EE_Error::doing_it_wrong(
2228
-            __CLASS__ . '::' . __FUNCTION__,
2229
-            esc_html__(
2230
-                '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.',
2231
-                'event_espresso'
2232
-            ),
2233
-            '4.8.32.rc.000'
2234
-        );
2235
-        return '
2215
+	}
2216
+
2217
+
2218
+	/**
2219
+	 * form_after_question_group
2220
+	 *
2221
+	 * @param string $output
2222
+	 * @return        string
2223
+	 * @deprecated    as of 4.8.32.rc.000
2224
+	 */
2225
+	public function form_after_question_group($output)
2226
+	{
2227
+		EE_Error::doing_it_wrong(
2228
+			__CLASS__ . '::' . __FUNCTION__,
2229
+			esc_html__(
2230
+				'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.',
2231
+				'event_espresso'
2232
+			),
2233
+			'4.8.32.rc.000'
2234
+		);
2235
+		return '
2236 2236
 			<tr class="hide-if-no-js">
2237 2237
 				<th> </th>
2238 2238
 				<td class="reg-admin-edit-attendee-question-td">
2239 2239
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2240
-               . esc_attr__('click to edit question', 'event_espresso')
2241
-               . '">
2240
+			   . esc_attr__('click to edit question', 'event_espresso')
2241
+			   . '">
2242 2242
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2243
-               . esc_html__('edit the above question group', 'event_espresso')
2244
-               . '</span>
2243
+			   . esc_html__('edit the above question group', 'event_espresso')
2244
+			   . '</span>
2245 2245
 						<div class="dashicons dashicons-edit"></div>
2246 2246
 					</a>
2247 2247
 				</td>
@@ -2249,637 +2249,637 @@  discard block
 block discarded – undo
2249 2249
 		</tbody>
2250 2250
 	</table>
2251 2251
 ';
2252
-    }
2253
-
2254
-
2255
-    /**
2256
-     * form_form_field_label_wrap
2257
-     *
2258
-     * @param string $label
2259
-     * @return        string
2260
-     * @deprecated    as of 4.8.32.rc.000
2261
-     */
2262
-    public function form_form_field_label_wrap($label)
2263
-    {
2264
-        EE_Error::doing_it_wrong(
2265
-            __CLASS__ . '::' . __FUNCTION__,
2266
-            esc_html__(
2267
-                '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.',
2268
-                'event_espresso'
2269
-            ),
2270
-            '4.8.32.rc.000'
2271
-        );
2272
-        return '
2252
+	}
2253
+
2254
+
2255
+	/**
2256
+	 * form_form_field_label_wrap
2257
+	 *
2258
+	 * @param string $label
2259
+	 * @return        string
2260
+	 * @deprecated    as of 4.8.32.rc.000
2261
+	 */
2262
+	public function form_form_field_label_wrap($label)
2263
+	{
2264
+		EE_Error::doing_it_wrong(
2265
+			__CLASS__ . '::' . __FUNCTION__,
2266
+			esc_html__(
2267
+				'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.',
2268
+				'event_espresso'
2269
+			),
2270
+			'4.8.32.rc.000'
2271
+		);
2272
+		return '
2273 2273
 			<tr>
2274 2274
 				<th>
2275 2275
 					' . $label . '
2276 2276
 				</th>';
2277
-    }
2278
-
2279
-
2280
-    /**
2281
-     * form_form_field_input__wrap
2282
-     *
2283
-     * @param string $input
2284
-     * @return        string
2285
-     * @deprecated    as of 4.8.32.rc.000
2286
-     */
2287
-    public function form_form_field_input__wrap($input)
2288
-    {
2289
-        EE_Error::doing_it_wrong(
2290
-            __CLASS__ . '::' . __FUNCTION__,
2291
-            esc_html__(
2292
-                '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.',
2293
-                'event_espresso'
2294
-            ),
2295
-            '4.8.32.rc.000'
2296
-        );
2297
-        return '
2277
+	}
2278
+
2279
+
2280
+	/**
2281
+	 * form_form_field_input__wrap
2282
+	 *
2283
+	 * @param string $input
2284
+	 * @return        string
2285
+	 * @deprecated    as of 4.8.32.rc.000
2286
+	 */
2287
+	public function form_form_field_input__wrap($input)
2288
+	{
2289
+		EE_Error::doing_it_wrong(
2290
+			__CLASS__ . '::' . __FUNCTION__,
2291
+			esc_html__(
2292
+				'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.',
2293
+				'event_espresso'
2294
+			),
2295
+			'4.8.32.rc.000'
2296
+		);
2297
+		return '
2298 2298
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2299 2299
 					' . $input . '
2300 2300
 				</td>
2301 2301
 			</tr>';
2302
-    }
2303
-
2304
-
2305
-    /**
2306
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2307
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2308
-     * to display the page
2309
-     *
2310
-     * @return void
2311
-     * @throws EE_Error
2312
-     * @throws InvalidArgumentException
2313
-     * @throws InvalidDataTypeException
2314
-     * @throws InvalidInterfaceException
2315
-     * @throws ReflectionException
2316
-     */
2317
-    protected function _update_attendee_registration_form()
2318
-    {
2319
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2320
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2321
-            $REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2322
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2323
-            if ($success) {
2324
-                $what  = esc_html__('Registration Form', 'event_espresso');
2325
-                $route = $REG_ID
2326
-                    ? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2327
-                    : ['action' => 'default'];
2328
-                $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2329
-            }
2330
-        }
2331
-    }
2332
-
2333
-
2334
-    /**
2335
-     * Gets the form for saving registrations custom questions (if done
2336
-     * previously retrieves the cached form object, which may have validation errors in it)
2337
-     *
2338
-     * @param int $REG_ID
2339
-     * @return EE_Registration_Custom_Questions_Form
2340
-     * @throws EE_Error
2341
-     * @throws InvalidArgumentException
2342
-     * @throws InvalidDataTypeException
2343
-     * @throws InvalidInterfaceException
2344
-     * @throws ReflectionException
2345
-     */
2346
-    protected function _get_reg_custom_questions_form($REG_ID)
2347
-    {
2348
-        if (! $this->_reg_custom_questions_form) {
2349
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2350
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2351
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2352
-            );
2353
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2354
-        }
2355
-        return $this->_reg_custom_questions_form;
2356
-    }
2357
-
2358
-
2359
-    /**
2360
-     * Saves
2361
-     *
2362
-     * @param bool $REG_ID
2363
-     * @return bool
2364
-     * @throws EE_Error
2365
-     * @throws InvalidArgumentException
2366
-     * @throws InvalidDataTypeException
2367
-     * @throws InvalidInterfaceException
2368
-     * @throws ReflectionException
2369
-     */
2370
-    private function _save_reg_custom_questions_form($REG_ID = 0)
2371
-    {
2372
-        if (! $REG_ID) {
2373
-            EE_Error::add_error(
2374
-                esc_html__(
2375
-                    'An error occurred. No registration ID was received.',
2376
-                    'event_espresso'
2377
-                ),
2378
-                __FILE__,
2379
-                __FUNCTION__,
2380
-                __LINE__
2381
-            );
2382
-        }
2383
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2384
-        $form->receive_form_submission($this->request->requestParams());
2385
-        $success = false;
2386
-        if ($form->is_valid()) {
2387
-            foreach ($form->subforms() as $question_group_form) {
2388
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2389
-                    $where_conditions    = [
2390
-                        'QST_ID' => $question_id,
2391
-                        'REG_ID' => $REG_ID,
2392
-                    ];
2393
-                    $possibly_new_values = [
2394
-                        'ANS_value' => $input->normalized_value(),
2395
-                    ];
2396
-                    $answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2397
-                    if ($answer instanceof EE_Answer) {
2398
-                        $success = $answer->save($possibly_new_values);
2399
-                    } else {
2400
-                        // insert it then
2401
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2402
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2403
-                        $success     = $answer->save();
2404
-                    }
2405
-                }
2406
-            }
2407
-        } else {
2408
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2409
-        }
2410
-        return $success;
2411
-    }
2412
-
2413
-
2414
-    /**
2415
-     * generates HTML for the Registration main meta box
2416
-     *
2417
-     * @return void
2418
-     * @throws DomainException
2419
-     * @throws EE_Error
2420
-     * @throws InvalidArgumentException
2421
-     * @throws InvalidDataTypeException
2422
-     * @throws InvalidInterfaceException
2423
-     * @throws ReflectionException
2424
-     */
2425
-    public function _reg_attendees_meta_box()
2426
-    {
2427
-        $REG = $this->getRegistrationModel();
2428
-        // get all other registrations on this transaction, and cache
2429
-        // the attendees for them so we don't have to run another query using force_join
2430
-        $registrations                           = $REG->get_all(
2431
-            [
2432
-                [
2433
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2434
-                    'REG_ID' => ['!=', $this->_registration->ID()],
2435
-                ],
2436
-                'force_join'               => ['Attendee'],
2437
-                'default_where_conditions' => 'other_models_only',
2438
-            ]
2439
-        );
2440
-        $this->_template_args['attendees']       = [];
2441
-        $this->_template_args['attendee_notice'] = '';
2442
-        if (
2443
-            empty($registrations)
2444
-            || (is_array($registrations)
2445
-                && ! EEH_Array::get_one_item_from_array($registrations))
2446
-        ) {
2447
-            EE_Error::add_error(
2448
-                esc_html__(
2449
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2450
-                    'event_espresso'
2451
-                ),
2452
-                __FILE__,
2453
-                __FUNCTION__,
2454
-                __LINE__
2455
-            );
2456
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2457
-        } else {
2458
-            $att_nmbr = 1;
2459
-            foreach ($registrations as $registration) {
2460
-                /* @var $registration EE_Registration */
2461
-                $attendee                                                      = $registration->attendee()
2462
-                    ? $registration->attendee()
2463
-                    : $this->getAttendeeModel()->create_default_object();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2469
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2470
-                    ', ',
2471
-                    $attendee->full_address_as_array()
2472
-                );
2473
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2474
-                    [
2475
-                        'action' => 'edit_attendee',
2476
-                        'post'   => $attendee->ID(),
2477
-                    ],
2478
-                    REG_ADMIN_URL
2479
-                );
2480
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2481
-                    $registration->event_obj() instanceof EE_Event
2482
-                        ? $registration->event_obj()->name()
2483
-                        : '';
2484
-                $att_nmbr++;
2485
-            }
2486
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2487
-        }
2488
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2489
-        EEH_Template::display_template($template_path, $this->_template_args);
2490
-    }
2491
-
2492
-
2493
-    /**
2494
-     * generates HTML for the Edit Registration side meta box
2495
-     *
2496
-     * @return void
2497
-     * @throws DomainException
2498
-     * @throws EE_Error
2499
-     * @throws InvalidArgumentException
2500
-     * @throws InvalidDataTypeException
2501
-     * @throws InvalidInterfaceException
2502
-     * @throws ReflectionException
2503
-     */
2504
-    public function _reg_registrant_side_meta_box()
2505
-    {
2506
-        /*@var $attendee EE_Attendee */
2507
-        $att_check = $this->_registration->attendee();
2508
-        $attendee  = $att_check instanceof EE_Attendee
2509
-            ? $att_check
2510
-            : $this->getAttendeeModel()->create_default_object();
2511
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2512
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2513
-        // primary registration object (that way we know if we need to show create button or not)
2514
-        if (! $this->_registration->is_primary_registrant()) {
2515
-            $primary_registration = $this->_registration->get_primary_registration();
2516
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2517
-                : null;
2518
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2519
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2520
-                // custom attendee object so let's not worry about the primary reg.
2521
-                $primary_registration = null;
2522
-            }
2523
-        } else {
2524
-            $primary_registration = null;
2525
-        }
2526
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2527
-        $this->_template_args['fname']             = $attendee->fname();
2528
-        $this->_template_args['lname']             = $attendee->lname();
2529
-        $this->_template_args['email']             = $attendee->email();
2530
-        $this->_template_args['phone']             = $attendee->phone();
2531
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2532
-        // edit link
2533
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2534
-            [
2535
-                'action' => 'edit_attendee',
2536
-                'post'   => $attendee->ID(),
2537
-            ],
2538
-            REG_ADMIN_URL
2539
-        );
2540
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2541
-        // create link
2542
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2543
-            ? EE_Admin_Page::add_query_args_and_nonce(
2544
-                [
2545
-                    'action'  => 'duplicate_attendee',
2546
-                    '_REG_ID' => $this->_registration->ID(),
2547
-                ],
2548
-                REG_ADMIN_URL
2549
-            ) : '';
2550
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2551
-        $this->_template_args['att_check']    = $att_check;
2552
-        $template_path                        =
2553
-            REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2554
-        EEH_Template::display_template($template_path, $this->_template_args);
2555
-    }
2556
-
2557
-
2558
-    /**
2559
-     * trash or restore registrations
2560
-     *
2561
-     * @param boolean $trash whether to archive or restore
2562
-     * @return void
2563
-     * @throws EE_Error
2564
-     * @throws InvalidArgumentException
2565
-     * @throws InvalidDataTypeException
2566
-     * @throws InvalidInterfaceException
2567
-     * @throws RuntimeException
2568
-     */
2569
-    protected function _trash_or_restore_registrations($trash = true)
2570
-    {
2571
-        // if empty _REG_ID then get out because there's nothing to do
2572
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2573
-        if (empty($REG_IDs)) {
2574
-            EE_Error::add_error(
2575
-                sprintf(
2576
-                    esc_html__(
2577
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2578
-                        'event_espresso'
2579
-                    ),
2580
-                    $trash ? 'trash' : 'restore'
2581
-                ),
2582
-                __FILE__,
2583
-                __LINE__,
2584
-                __FUNCTION__
2585
-            );
2586
-            $this->_redirect_after_action(false, '', '', [], true);
2587
-        }
2588
-        $success        = 0;
2589
-        $overwrite_msgs = false;
2590
-        // Checkboxes
2591
-        $reg_count = count($REG_IDs);
2592
-        // cycle thru checkboxes
2593
-        foreach ($REG_IDs as $REG_ID) {
2594
-            /** @var EE_Registration $REG */
2595
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2596
-            $payments = $REG->registration_payments();
2597
-            if (! empty($payments)) {
2598
-                $name           = $REG->attendee() instanceof EE_Attendee
2599
-                    ? $REG->attendee()->full_name()
2600
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2601
-                $overwrite_msgs = true;
2602
-                EE_Error::add_error(
2603
-                    sprintf(
2604
-                        esc_html__(
2605
-                            '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.',
2606
-                            'event_espresso'
2607
-                        ),
2608
-                        $name
2609
-                    ),
2610
-                    __FILE__,
2611
-                    __FUNCTION__,
2612
-                    __LINE__
2613
-                );
2614
-                // can't trash this registration because it has payments.
2615
-                continue;
2616
-            }
2617
-            $updated = $trash ? $REG->delete() : $REG->restore();
2618
-            if ($updated) {
2619
-                $success++;
2620
-            }
2621
-        }
2622
-        $this->_redirect_after_action(
2623
-            $success === $reg_count, // were ALL registrations affected?
2624
-            $success > 1
2625
-                ? esc_html__('Registrations', 'event_espresso')
2626
-                : esc_html__('Registration', 'event_espresso'),
2627
-            $trash
2628
-                ? esc_html__('moved to the trash', 'event_espresso')
2629
-                : esc_html__('restored', 'event_espresso'),
2630
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2631
-            $overwrite_msgs
2632
-        );
2633
-    }
2634
-
2635
-
2636
-    /**
2637
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2638
-     * registration but also.
2639
-     * 1. Removing relations to EE_Attendee
2640
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2641
-     * ALSO trashed.
2642
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2643
-     * 4. Removing relationships between all tickets and the related registrations
2644
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2645
-     * 6. Deleting permanently any related Checkins.
2646
-     *
2647
-     * @return void
2648
-     * @throws EE_Error
2649
-     * @throws InvalidArgumentException
2650
-     * @throws InvalidDataTypeException
2651
-     * @throws InvalidInterfaceException
2652
-     * @throws ReflectionException
2653
-     */
2654
-    protected function _delete_registrations()
2655
-    {
2656
-        $REG_MDL = $this->getRegistrationModel();
2657
-        $success = 0;
2658
-        // Checkboxes
2659
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2660
-
2661
-        if (! empty($REG_IDs)) {
2662
-            // if array has more than one element than success message should be plural
2663
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2664
-            // cycle thru checkboxes
2665
-            foreach ($REG_IDs as $REG_ID) {
2666
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2667
-                if (! $REG instanceof EE_Registration) {
2668
-                    continue;
2669
-                }
2670
-                $deleted = $this->_delete_registration($REG);
2671
-                if (! $deleted) {
2672
-                    $success = 0;
2673
-                }
2674
-            }
2675
-        }
2676
-
2677
-        $what        = $success > 1
2678
-            ? esc_html__('Registrations', 'event_espresso')
2679
-            : esc_html__('Registration', 'event_espresso');
2680
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2681
-        $this->_redirect_after_action(
2682
-            $success,
2683
-            $what,
2684
-            $action_desc,
2685
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2686
-            true
2687
-        );
2688
-    }
2689
-
2690
-
2691
-    /**
2692
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2693
-     * models get affected.
2694
-     *
2695
-     * @param EE_Registration $REG registration to be deleted permanently
2696
-     * @return bool true = successful deletion, false = fail.
2697
-     * @throws EE_Error
2698
-     * @throws InvalidArgumentException
2699
-     * @throws InvalidDataTypeException
2700
-     * @throws InvalidInterfaceException
2701
-     * @throws ReflectionException
2702
-     */
2703
-    protected function _delete_registration(EE_Registration $REG)
2704
-    {
2705
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2706
-        // registrations on the transaction that are NOT trashed.
2707
-        $TXN = $REG->get_first_related('Transaction');
2708
-        if (! $TXN instanceof EE_Transaction) {
2709
-            EE_Error::add_error(
2710
-                sprintf(
2711
-                    esc_html__(
2712
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2713
-                        'event_espresso'
2714
-                    ),
2715
-                    $REG->id()
2716
-                ),
2717
-                __FILE__,
2718
-                __FUNCTION__,
2719
-                __LINE__
2720
-            );
2721
-            return false;
2722
-        }
2723
-        $REGS        = $TXN->get_many_related('Registration');
2724
-        $all_trashed = true;
2725
-        foreach ($REGS as $registration) {
2726
-            if (! $registration->get('REG_deleted')) {
2727
-                $all_trashed = false;
2728
-            }
2729
-        }
2730
-        if (! $all_trashed) {
2731
-            EE_Error::add_error(
2732
-                esc_html__(
2733
-                    '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.',
2734
-                    'event_espresso'
2735
-                ),
2736
-                __FILE__,
2737
-                __FUNCTION__,
2738
-                __LINE__
2739
-            );
2740
-            return false;
2741
-        }
2742
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2743
-        // separately from THIS one).
2744
-        foreach ($REGS as $registration) {
2745
-            // delete related answers
2746
-            $registration->delete_related_permanently('Answer');
2747
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2748
-            $attendee = $registration->get_first_related('Attendee');
2749
-            if ($attendee instanceof EE_Attendee) {
2750
-                $registration->_remove_relation_to($attendee, 'Attendee');
2751
-            }
2752
-            // now remove relationships to tickets on this registration.
2753
-            $registration->_remove_relations('Ticket');
2754
-            // now delete permanently the checkins related to this registration.
2755
-            $registration->delete_related_permanently('Checkin');
2756
-            if ($registration->ID() === $REG->ID()) {
2757
-                continue;
2758
-            } //we don't want to delete permanently the existing registration just yet.
2759
-            // remove relation to transaction for these registrations if NOT the existing registrations
2760
-            $registration->_remove_relations('Transaction');
2761
-            // delete permanently any related messages.
2762
-            $registration->delete_related_permanently('Message');
2763
-            // now delete this registration permanently
2764
-            $registration->delete_permanently();
2765
-        }
2766
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2767
-        // (the transaction and line items should be all that's left).
2768
-        // delete the line items related to the transaction for this registration.
2769
-        $TXN->delete_related_permanently('Line_Item');
2770
-        // we need to remove all the relationships on the transaction
2771
-        $TXN->delete_related_permanently('Payment');
2772
-        $TXN->delete_related_permanently('Extra_Meta');
2773
-        $TXN->delete_related_permanently('Message');
2774
-        // now we can delete this REG permanently (and the transaction of course)
2775
-        $REG->delete_related_permanently('Transaction');
2776
-        return $REG->delete_permanently();
2777
-    }
2778
-
2779
-
2780
-    /**
2781
-     *    generates HTML for the Register New Attendee Admin page
2782
-     *
2783
-     * @throws DomainException
2784
-     * @throws EE_Error
2785
-     * @throws InvalidArgumentException
2786
-     * @throws InvalidDataTypeException
2787
-     * @throws InvalidInterfaceException
2788
-     * @throws ReflectionException
2789
-     */
2790
-    public function new_registration()
2791
-    {
2792
-        if (! $this->_set_reg_event()) {
2793
-            throw new EE_Error(
2794
-                esc_html__(
2795
-                    'Unable to continue with registering because there is no Event ID in the request',
2796
-                    'event_espresso'
2797
-                )
2798
-            );
2799
-        }
2800
-        /** @var CurrentPage $current_page */
2801
-        $current_page = $this->loader->getShared(CurrentPage::class);
2802
-        $current_page->setEspressoPage(true);
2803
-        // gotta start with a clean slate if we're not coming here via ajax
2804
-        if (
2805
-            ! $this->request->isAjax()
2806
-            && (
2807
-                ! $this->request->requestParamIsSet('processing_registration')
2808
-                || $this->request->requestParamIsSet('step_error')
2809
-            )
2810
-        ) {
2811
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2812
-        }
2813
-        $this->_template_args['event_name'] = '';
2814
-        // event name
2815
-        if ($this->_reg_event) {
2816
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2817
-            $edit_event_url                     = self::add_query_args_and_nonce(
2818
-                [
2819
-                    'action' => 'edit',
2820
-                    'post'   => $this->_reg_event->ID(),
2821
-                ],
2822
-                EVENTS_ADMIN_URL
2823
-            );
2824
-            $edit_event_lnk                     = '<a href="'
2825
-                                                  . $edit_event_url
2826
-                                                  . '" title="'
2827
-                                                  . esc_attr__('Edit ', 'event_espresso')
2828
-                                                  . $this->_reg_event->name()
2829
-                                                  . '">'
2830
-                                                  . esc_html__('Edit Event', 'event_espresso')
2831
-                                                  . '</a>';
2832
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2833
-                                                   . $edit_event_lnk
2834
-                                                   . '</span>';
2835
-        }
2836
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2837
-        if ($this->request->isAjax()) {
2838
-            $this->_return_json();
2839
-        }
2840
-        // grab header
2841
-        $template_path                              =
2842
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2843
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2844
-            $template_path,
2845
-            $this->_template_args,
2846
-            true
2847
-        );
2848
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2849
-        // the details template wrapper
2850
-        $this->display_admin_page_with_sidebar();
2851
-    }
2852
-
2853
-
2854
-    /**
2855
-     * This returns the content for a registration step
2856
-     *
2857
-     * @return string html
2858
-     * @throws DomainException
2859
-     * @throws EE_Error
2860
-     * @throws InvalidArgumentException
2861
-     * @throws InvalidDataTypeException
2862
-     * @throws InvalidInterfaceException
2863
-     * @throws ReflectionException
2864
-     */
2865
-    protected function _get_registration_step_content()
2866
-    {
2867
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2868
-            $warning_msg = sprintf(
2869
-                esc_html__(
2870
-                    '%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',
2871
-                    'event_espresso'
2872
-                ),
2873
-                '<br />',
2874
-                '<h3 class="important-notice">',
2875
-                '</h3>',
2876
-                '<div class="float-right">',
2877
-                '<span id="redirect_timer" class="important-notice">30</span>',
2878
-                '</div>',
2879
-                '<b>',
2880
-                '</b>'
2881
-            );
2882
-            return '
2302
+	}
2303
+
2304
+
2305
+	/**
2306
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2307
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2308
+	 * to display the page
2309
+	 *
2310
+	 * @return void
2311
+	 * @throws EE_Error
2312
+	 * @throws InvalidArgumentException
2313
+	 * @throws InvalidDataTypeException
2314
+	 * @throws InvalidInterfaceException
2315
+	 * @throws ReflectionException
2316
+	 */
2317
+	protected function _update_attendee_registration_form()
2318
+	{
2319
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2320
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2321
+			$REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2322
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2323
+			if ($success) {
2324
+				$what  = esc_html__('Registration Form', 'event_espresso');
2325
+				$route = $REG_ID
2326
+					? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2327
+					: ['action' => 'default'];
2328
+				$this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2329
+			}
2330
+		}
2331
+	}
2332
+
2333
+
2334
+	/**
2335
+	 * Gets the form for saving registrations custom questions (if done
2336
+	 * previously retrieves the cached form object, which may have validation errors in it)
2337
+	 *
2338
+	 * @param int $REG_ID
2339
+	 * @return EE_Registration_Custom_Questions_Form
2340
+	 * @throws EE_Error
2341
+	 * @throws InvalidArgumentException
2342
+	 * @throws InvalidDataTypeException
2343
+	 * @throws InvalidInterfaceException
2344
+	 * @throws ReflectionException
2345
+	 */
2346
+	protected function _get_reg_custom_questions_form($REG_ID)
2347
+	{
2348
+		if (! $this->_reg_custom_questions_form) {
2349
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2350
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2351
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2352
+			);
2353
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2354
+		}
2355
+		return $this->_reg_custom_questions_form;
2356
+	}
2357
+
2358
+
2359
+	/**
2360
+	 * Saves
2361
+	 *
2362
+	 * @param bool $REG_ID
2363
+	 * @return bool
2364
+	 * @throws EE_Error
2365
+	 * @throws InvalidArgumentException
2366
+	 * @throws InvalidDataTypeException
2367
+	 * @throws InvalidInterfaceException
2368
+	 * @throws ReflectionException
2369
+	 */
2370
+	private function _save_reg_custom_questions_form($REG_ID = 0)
2371
+	{
2372
+		if (! $REG_ID) {
2373
+			EE_Error::add_error(
2374
+				esc_html__(
2375
+					'An error occurred. No registration ID was received.',
2376
+					'event_espresso'
2377
+				),
2378
+				__FILE__,
2379
+				__FUNCTION__,
2380
+				__LINE__
2381
+			);
2382
+		}
2383
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2384
+		$form->receive_form_submission($this->request->requestParams());
2385
+		$success = false;
2386
+		if ($form->is_valid()) {
2387
+			foreach ($form->subforms() as $question_group_form) {
2388
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2389
+					$where_conditions    = [
2390
+						'QST_ID' => $question_id,
2391
+						'REG_ID' => $REG_ID,
2392
+					];
2393
+					$possibly_new_values = [
2394
+						'ANS_value' => $input->normalized_value(),
2395
+					];
2396
+					$answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2397
+					if ($answer instanceof EE_Answer) {
2398
+						$success = $answer->save($possibly_new_values);
2399
+					} else {
2400
+						// insert it then
2401
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2402
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2403
+						$success     = $answer->save();
2404
+					}
2405
+				}
2406
+			}
2407
+		} else {
2408
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2409
+		}
2410
+		return $success;
2411
+	}
2412
+
2413
+
2414
+	/**
2415
+	 * generates HTML for the Registration main meta box
2416
+	 *
2417
+	 * @return void
2418
+	 * @throws DomainException
2419
+	 * @throws EE_Error
2420
+	 * @throws InvalidArgumentException
2421
+	 * @throws InvalidDataTypeException
2422
+	 * @throws InvalidInterfaceException
2423
+	 * @throws ReflectionException
2424
+	 */
2425
+	public function _reg_attendees_meta_box()
2426
+	{
2427
+		$REG = $this->getRegistrationModel();
2428
+		// get all other registrations on this transaction, and cache
2429
+		// the attendees for them so we don't have to run another query using force_join
2430
+		$registrations                           = $REG->get_all(
2431
+			[
2432
+				[
2433
+					'TXN_ID' => $this->_registration->transaction_ID(),
2434
+					'REG_ID' => ['!=', $this->_registration->ID()],
2435
+				],
2436
+				'force_join'               => ['Attendee'],
2437
+				'default_where_conditions' => 'other_models_only',
2438
+			]
2439
+		);
2440
+		$this->_template_args['attendees']       = [];
2441
+		$this->_template_args['attendee_notice'] = '';
2442
+		if (
2443
+			empty($registrations)
2444
+			|| (is_array($registrations)
2445
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2446
+		) {
2447
+			EE_Error::add_error(
2448
+				esc_html__(
2449
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2450
+					'event_espresso'
2451
+				),
2452
+				__FILE__,
2453
+				__FUNCTION__,
2454
+				__LINE__
2455
+			);
2456
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2457
+		} else {
2458
+			$att_nmbr = 1;
2459
+			foreach ($registrations as $registration) {
2460
+				/* @var $registration EE_Registration */
2461
+				$attendee                                                      = $registration->attendee()
2462
+					? $registration->attendee()
2463
+					: $this->getAttendeeModel()->create_default_object();
2464
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2465
+				$this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2466
+				$this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2467
+				$this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2468
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2469
+				$this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2470
+					', ',
2471
+					$attendee->full_address_as_array()
2472
+				);
2473
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2474
+					[
2475
+						'action' => 'edit_attendee',
2476
+						'post'   => $attendee->ID(),
2477
+					],
2478
+					REG_ADMIN_URL
2479
+				);
2480
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2481
+					$registration->event_obj() instanceof EE_Event
2482
+						? $registration->event_obj()->name()
2483
+						: '';
2484
+				$att_nmbr++;
2485
+			}
2486
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2487
+		}
2488
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2489
+		EEH_Template::display_template($template_path, $this->_template_args);
2490
+	}
2491
+
2492
+
2493
+	/**
2494
+	 * generates HTML for the Edit Registration side meta box
2495
+	 *
2496
+	 * @return void
2497
+	 * @throws DomainException
2498
+	 * @throws EE_Error
2499
+	 * @throws InvalidArgumentException
2500
+	 * @throws InvalidDataTypeException
2501
+	 * @throws InvalidInterfaceException
2502
+	 * @throws ReflectionException
2503
+	 */
2504
+	public function _reg_registrant_side_meta_box()
2505
+	{
2506
+		/*@var $attendee EE_Attendee */
2507
+		$att_check = $this->_registration->attendee();
2508
+		$attendee  = $att_check instanceof EE_Attendee
2509
+			? $att_check
2510
+			: $this->getAttendeeModel()->create_default_object();
2511
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2512
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2513
+		// primary registration object (that way we know if we need to show create button or not)
2514
+		if (! $this->_registration->is_primary_registrant()) {
2515
+			$primary_registration = $this->_registration->get_primary_registration();
2516
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2517
+				: null;
2518
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2519
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2520
+				// custom attendee object so let's not worry about the primary reg.
2521
+				$primary_registration = null;
2522
+			}
2523
+		} else {
2524
+			$primary_registration = null;
2525
+		}
2526
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2527
+		$this->_template_args['fname']             = $attendee->fname();
2528
+		$this->_template_args['lname']             = $attendee->lname();
2529
+		$this->_template_args['email']             = $attendee->email();
2530
+		$this->_template_args['phone']             = $attendee->phone();
2531
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2532
+		// edit link
2533
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2534
+			[
2535
+				'action' => 'edit_attendee',
2536
+				'post'   => $attendee->ID(),
2537
+			],
2538
+			REG_ADMIN_URL
2539
+		);
2540
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2541
+		// create link
2542
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2543
+			? EE_Admin_Page::add_query_args_and_nonce(
2544
+				[
2545
+					'action'  => 'duplicate_attendee',
2546
+					'_REG_ID' => $this->_registration->ID(),
2547
+				],
2548
+				REG_ADMIN_URL
2549
+			) : '';
2550
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2551
+		$this->_template_args['att_check']    = $att_check;
2552
+		$template_path                        =
2553
+			REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2554
+		EEH_Template::display_template($template_path, $this->_template_args);
2555
+	}
2556
+
2557
+
2558
+	/**
2559
+	 * trash or restore registrations
2560
+	 *
2561
+	 * @param boolean $trash whether to archive or restore
2562
+	 * @return void
2563
+	 * @throws EE_Error
2564
+	 * @throws InvalidArgumentException
2565
+	 * @throws InvalidDataTypeException
2566
+	 * @throws InvalidInterfaceException
2567
+	 * @throws RuntimeException
2568
+	 */
2569
+	protected function _trash_or_restore_registrations($trash = true)
2570
+	{
2571
+		// if empty _REG_ID then get out because there's nothing to do
2572
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2573
+		if (empty($REG_IDs)) {
2574
+			EE_Error::add_error(
2575
+				sprintf(
2576
+					esc_html__(
2577
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2578
+						'event_espresso'
2579
+					),
2580
+					$trash ? 'trash' : 'restore'
2581
+				),
2582
+				__FILE__,
2583
+				__LINE__,
2584
+				__FUNCTION__
2585
+			);
2586
+			$this->_redirect_after_action(false, '', '', [], true);
2587
+		}
2588
+		$success        = 0;
2589
+		$overwrite_msgs = false;
2590
+		// Checkboxes
2591
+		$reg_count = count($REG_IDs);
2592
+		// cycle thru checkboxes
2593
+		foreach ($REG_IDs as $REG_ID) {
2594
+			/** @var EE_Registration $REG */
2595
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2596
+			$payments = $REG->registration_payments();
2597
+			if (! empty($payments)) {
2598
+				$name           = $REG->attendee() instanceof EE_Attendee
2599
+					? $REG->attendee()->full_name()
2600
+					: esc_html__('Unknown Attendee', 'event_espresso');
2601
+				$overwrite_msgs = true;
2602
+				EE_Error::add_error(
2603
+					sprintf(
2604
+						esc_html__(
2605
+							'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.',
2606
+							'event_espresso'
2607
+						),
2608
+						$name
2609
+					),
2610
+					__FILE__,
2611
+					__FUNCTION__,
2612
+					__LINE__
2613
+				);
2614
+				// can't trash this registration because it has payments.
2615
+				continue;
2616
+			}
2617
+			$updated = $trash ? $REG->delete() : $REG->restore();
2618
+			if ($updated) {
2619
+				$success++;
2620
+			}
2621
+		}
2622
+		$this->_redirect_after_action(
2623
+			$success === $reg_count, // were ALL registrations affected?
2624
+			$success > 1
2625
+				? esc_html__('Registrations', 'event_espresso')
2626
+				: esc_html__('Registration', 'event_espresso'),
2627
+			$trash
2628
+				? esc_html__('moved to the trash', 'event_espresso')
2629
+				: esc_html__('restored', 'event_espresso'),
2630
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2631
+			$overwrite_msgs
2632
+		);
2633
+	}
2634
+
2635
+
2636
+	/**
2637
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2638
+	 * registration but also.
2639
+	 * 1. Removing relations to EE_Attendee
2640
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2641
+	 * ALSO trashed.
2642
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2643
+	 * 4. Removing relationships between all tickets and the related registrations
2644
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2645
+	 * 6. Deleting permanently any related Checkins.
2646
+	 *
2647
+	 * @return void
2648
+	 * @throws EE_Error
2649
+	 * @throws InvalidArgumentException
2650
+	 * @throws InvalidDataTypeException
2651
+	 * @throws InvalidInterfaceException
2652
+	 * @throws ReflectionException
2653
+	 */
2654
+	protected function _delete_registrations()
2655
+	{
2656
+		$REG_MDL = $this->getRegistrationModel();
2657
+		$success = 0;
2658
+		// Checkboxes
2659
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2660
+
2661
+		if (! empty($REG_IDs)) {
2662
+			// if array has more than one element than success message should be plural
2663
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2664
+			// cycle thru checkboxes
2665
+			foreach ($REG_IDs as $REG_ID) {
2666
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2667
+				if (! $REG instanceof EE_Registration) {
2668
+					continue;
2669
+				}
2670
+				$deleted = $this->_delete_registration($REG);
2671
+				if (! $deleted) {
2672
+					$success = 0;
2673
+				}
2674
+			}
2675
+		}
2676
+
2677
+		$what        = $success > 1
2678
+			? esc_html__('Registrations', 'event_espresso')
2679
+			: esc_html__('Registration', 'event_espresso');
2680
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2681
+		$this->_redirect_after_action(
2682
+			$success,
2683
+			$what,
2684
+			$action_desc,
2685
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2686
+			true
2687
+		);
2688
+	}
2689
+
2690
+
2691
+	/**
2692
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2693
+	 * models get affected.
2694
+	 *
2695
+	 * @param EE_Registration $REG registration to be deleted permanently
2696
+	 * @return bool true = successful deletion, false = fail.
2697
+	 * @throws EE_Error
2698
+	 * @throws InvalidArgumentException
2699
+	 * @throws InvalidDataTypeException
2700
+	 * @throws InvalidInterfaceException
2701
+	 * @throws ReflectionException
2702
+	 */
2703
+	protected function _delete_registration(EE_Registration $REG)
2704
+	{
2705
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2706
+		// registrations on the transaction that are NOT trashed.
2707
+		$TXN = $REG->get_first_related('Transaction');
2708
+		if (! $TXN instanceof EE_Transaction) {
2709
+			EE_Error::add_error(
2710
+				sprintf(
2711
+					esc_html__(
2712
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2713
+						'event_espresso'
2714
+					),
2715
+					$REG->id()
2716
+				),
2717
+				__FILE__,
2718
+				__FUNCTION__,
2719
+				__LINE__
2720
+			);
2721
+			return false;
2722
+		}
2723
+		$REGS        = $TXN->get_many_related('Registration');
2724
+		$all_trashed = true;
2725
+		foreach ($REGS as $registration) {
2726
+			if (! $registration->get('REG_deleted')) {
2727
+				$all_trashed = false;
2728
+			}
2729
+		}
2730
+		if (! $all_trashed) {
2731
+			EE_Error::add_error(
2732
+				esc_html__(
2733
+					'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.',
2734
+					'event_espresso'
2735
+				),
2736
+				__FILE__,
2737
+				__FUNCTION__,
2738
+				__LINE__
2739
+			);
2740
+			return false;
2741
+		}
2742
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2743
+		// separately from THIS one).
2744
+		foreach ($REGS as $registration) {
2745
+			// delete related answers
2746
+			$registration->delete_related_permanently('Answer');
2747
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2748
+			$attendee = $registration->get_first_related('Attendee');
2749
+			if ($attendee instanceof EE_Attendee) {
2750
+				$registration->_remove_relation_to($attendee, 'Attendee');
2751
+			}
2752
+			// now remove relationships to tickets on this registration.
2753
+			$registration->_remove_relations('Ticket');
2754
+			// now delete permanently the checkins related to this registration.
2755
+			$registration->delete_related_permanently('Checkin');
2756
+			if ($registration->ID() === $REG->ID()) {
2757
+				continue;
2758
+			} //we don't want to delete permanently the existing registration just yet.
2759
+			// remove relation to transaction for these registrations if NOT the existing registrations
2760
+			$registration->_remove_relations('Transaction');
2761
+			// delete permanently any related messages.
2762
+			$registration->delete_related_permanently('Message');
2763
+			// now delete this registration permanently
2764
+			$registration->delete_permanently();
2765
+		}
2766
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2767
+		// (the transaction and line items should be all that's left).
2768
+		// delete the line items related to the transaction for this registration.
2769
+		$TXN->delete_related_permanently('Line_Item');
2770
+		// we need to remove all the relationships on the transaction
2771
+		$TXN->delete_related_permanently('Payment');
2772
+		$TXN->delete_related_permanently('Extra_Meta');
2773
+		$TXN->delete_related_permanently('Message');
2774
+		// now we can delete this REG permanently (and the transaction of course)
2775
+		$REG->delete_related_permanently('Transaction');
2776
+		return $REG->delete_permanently();
2777
+	}
2778
+
2779
+
2780
+	/**
2781
+	 *    generates HTML for the Register New Attendee Admin page
2782
+	 *
2783
+	 * @throws DomainException
2784
+	 * @throws EE_Error
2785
+	 * @throws InvalidArgumentException
2786
+	 * @throws InvalidDataTypeException
2787
+	 * @throws InvalidInterfaceException
2788
+	 * @throws ReflectionException
2789
+	 */
2790
+	public function new_registration()
2791
+	{
2792
+		if (! $this->_set_reg_event()) {
2793
+			throw new EE_Error(
2794
+				esc_html__(
2795
+					'Unable to continue with registering because there is no Event ID in the request',
2796
+					'event_espresso'
2797
+				)
2798
+			);
2799
+		}
2800
+		/** @var CurrentPage $current_page */
2801
+		$current_page = $this->loader->getShared(CurrentPage::class);
2802
+		$current_page->setEspressoPage(true);
2803
+		// gotta start with a clean slate if we're not coming here via ajax
2804
+		if (
2805
+			! $this->request->isAjax()
2806
+			&& (
2807
+				! $this->request->requestParamIsSet('processing_registration')
2808
+				|| $this->request->requestParamIsSet('step_error')
2809
+			)
2810
+		) {
2811
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2812
+		}
2813
+		$this->_template_args['event_name'] = '';
2814
+		// event name
2815
+		if ($this->_reg_event) {
2816
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2817
+			$edit_event_url                     = self::add_query_args_and_nonce(
2818
+				[
2819
+					'action' => 'edit',
2820
+					'post'   => $this->_reg_event->ID(),
2821
+				],
2822
+				EVENTS_ADMIN_URL
2823
+			);
2824
+			$edit_event_lnk                     = '<a href="'
2825
+												  . $edit_event_url
2826
+												  . '" title="'
2827
+												  . esc_attr__('Edit ', 'event_espresso')
2828
+												  . $this->_reg_event->name()
2829
+												  . '">'
2830
+												  . esc_html__('Edit Event', 'event_espresso')
2831
+												  . '</a>';
2832
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2833
+												   . $edit_event_lnk
2834
+												   . '</span>';
2835
+		}
2836
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2837
+		if ($this->request->isAjax()) {
2838
+			$this->_return_json();
2839
+		}
2840
+		// grab header
2841
+		$template_path                              =
2842
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2843
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2844
+			$template_path,
2845
+			$this->_template_args,
2846
+			true
2847
+		);
2848
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2849
+		// the details template wrapper
2850
+		$this->display_admin_page_with_sidebar();
2851
+	}
2852
+
2853
+
2854
+	/**
2855
+	 * This returns the content for a registration step
2856
+	 *
2857
+	 * @return string html
2858
+	 * @throws DomainException
2859
+	 * @throws EE_Error
2860
+	 * @throws InvalidArgumentException
2861
+	 * @throws InvalidDataTypeException
2862
+	 * @throws InvalidInterfaceException
2863
+	 * @throws ReflectionException
2864
+	 */
2865
+	protected function _get_registration_step_content()
2866
+	{
2867
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2868
+			$warning_msg = sprintf(
2869
+				esc_html__(
2870
+					'%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',
2871
+					'event_espresso'
2872
+				),
2873
+				'<br />',
2874
+				'<h3 class="important-notice">',
2875
+				'</h3>',
2876
+				'<div class="float-right">',
2877
+				'<span id="redirect_timer" class="important-notice">30</span>',
2878
+				'</div>',
2879
+				'<b>',
2880
+				'</b>'
2881
+			);
2882
+			return '
2883 2883
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2884 2884
 	<script >
2885 2885
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2892,851 +2892,851 @@  discard block
 block discarded – undo
2892 2892
 	        }
2893 2893
 	    }, 800 );
2894 2894
 	</script >';
2895
-        }
2896
-        $template_args = [
2897
-            'title'                    => '',
2898
-            'content'                  => '',
2899
-            'step_button_text'         => '',
2900
-            'show_notification_toggle' => false,
2901
-        ];
2902
-        // to indicate we're processing a new registration
2903
-        $hidden_fields = [
2904
-            'processing_registration' => [
2905
-                'type'  => 'hidden',
2906
-                'value' => 0,
2907
-            ],
2908
-            'event_id'                => [
2909
-                'type'  => 'hidden',
2910
-                'value' => $this->_reg_event->ID(),
2911
-            ],
2912
-        ];
2913
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2914
-        $cart = EE_Registry::instance()->SSN->cart();
2915
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2916
-        switch ($step) {
2917
-            case 'ticket':
2918
-                $hidden_fields['processing_registration']['value'] = 1;
2919
-                $template_args['title']                            = esc_html__(
2920
-                    'Step One: Select the Ticket for this registration',
2921
-                    'event_espresso'
2922
-                );
2923
-                $template_args['content']                          =
2924
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2925
-                $template_args['content']                          .= '</div>';
2926
-                $template_args['step_button_text']                 = esc_html__(
2927
-                    'Add Tickets and Continue to Registrant Details',
2928
-                    'event_espresso'
2929
-                );
2930
-                $template_args['show_notification_toggle']         = false;
2931
-                break;
2932
-            case 'questions':
2933
-                $hidden_fields['processing_registration']['value'] = 2;
2934
-                $template_args['title']                            = esc_html__(
2935
-                    'Step Two: Add Registrant Details for this Registration',
2936
-                    'event_espresso'
2937
-                );
2938
-                // in theory, we should be able to run EED_SPCO at this point
2939
-                // because the cart should have been set up properly by the first process_reg_step run.
2940
-                $template_args['content']                  =
2941
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2942
-                $template_args['step_button_text']         = esc_html__(
2943
-                    'Save Registration and Continue to Details',
2944
-                    'event_espresso'
2945
-                );
2946
-                $template_args['show_notification_toggle'] = true;
2947
-                break;
2948
-        }
2949
-        // we come back to the process_registration_step route.
2950
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2951
-        return EEH_Template::display_template(
2952
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2953
-            $template_args,
2954
-            true
2955
-        );
2956
-    }
2957
-
2958
-
2959
-    /**
2960
-     * set_reg_event
2961
-     *
2962
-     * @return bool
2963
-     * @throws EE_Error
2964
-     * @throws InvalidArgumentException
2965
-     * @throws InvalidDataTypeException
2966
-     * @throws InvalidInterfaceException
2967
-     */
2968
-    private function _set_reg_event()
2969
-    {
2970
-        if (is_object($this->_reg_event)) {
2971
-            return true;
2972
-        }
2973
-
2974
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2975
-        if (! $EVT_ID) {
2976
-            return false;
2977
-        }
2978
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2979
-        return true;
2980
-    }
2981
-
2982
-
2983
-    /**
2984
-     * process_reg_step
2985
-     *
2986
-     * @return void
2987
-     * @throws DomainException
2988
-     * @throws EE_Error
2989
-     * @throws InvalidArgumentException
2990
-     * @throws InvalidDataTypeException
2991
-     * @throws InvalidInterfaceException
2992
-     * @throws ReflectionException
2993
-     * @throws RuntimeException
2994
-     */
2995
-    public function process_reg_step()
2996
-    {
2997
-        EE_System::do_not_cache();
2998
-        $this->_set_reg_event();
2999
-        /** @var CurrentPage $current_page */
3000
-        $current_page = $this->loader->getShared(CurrentPage::class);
3001
-        $current_page->setEspressoPage(true);
3002
-        $this->request->setRequestParam('uts', time());
3003
-        // what step are we on?
3004
-        $cart = EE_Registry::instance()->SSN->cart();
3005
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3006
-        // if doing ajax then we need to verify the nonce
3007
-        if ($this->request->isAjax()) {
3008
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
3009
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3010
-        }
3011
-        switch ($step) {
3012
-            case 'ticket':
3013
-                // process ticket selection
3014
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3015
-                if ($success) {
3016
-                    EE_Error::add_success(
3017
-                        esc_html__(
3018
-                            'Tickets Selected. Now complete the registration.',
3019
-                            'event_espresso'
3020
-                        )
3021
-                    );
3022
-                } else {
3023
-                    $this->request->setRequestParam('step_error', true);
3024
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3025
-                }
3026
-                if ($this->request->isAjax()) {
3027
-                    $this->new_registration(); // display next step
3028
-                } else {
3029
-                    $query_args = [
3030
-                        'action'                  => 'new_registration',
3031
-                        'processing_registration' => 1,
3032
-                        'event_id'                => $this->_reg_event->ID(),
3033
-                        'uts'                     => time(),
3034
-                    ];
3035
-                    $this->_redirect_after_action(
3036
-                        false,
3037
-                        '',
3038
-                        '',
3039
-                        $query_args,
3040
-                        true
3041
-                    );
3042
-                }
3043
-                break;
3044
-            case 'questions':
3045
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3046
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3047
-                }
3048
-                // process registration
3049
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3050
-                if ($cart instanceof EE_Cart) {
3051
-                    $grand_total = $cart->get_grand_total();
3052
-                    if ($grand_total instanceof EE_Line_Item) {
3053
-                        $grand_total->save_this_and_descendants_to_txn();
3054
-                    }
3055
-                }
3056
-                if (! $transaction instanceof EE_Transaction) {
3057
-                    $query_args = [
3058
-                        'action'                  => 'new_registration',
3059
-                        'processing_registration' => 2,
3060
-                        'event_id'                => $this->_reg_event->ID(),
3061
-                        'uts'                     => time(),
3062
-                    ];
3063
-                    if ($this->request->isAjax()) {
3064
-                        // display registration form again because there are errors (maybe validation?)
3065
-                        $this->new_registration();
3066
-                        return;
3067
-                    }
3068
-                    $this->_redirect_after_action(
3069
-                        false,
3070
-                        '',
3071
-                        '',
3072
-                        $query_args,
3073
-                        true
3074
-                    );
3075
-                    return;
3076
-                }
3077
-                // maybe update status, and make sure to save transaction if not done already
3078
-                if (! $transaction->update_status_based_on_total_paid()) {
3079
-                    $transaction->save();
3080
-                }
3081
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3082
-                $query_args = [
3083
-                    'action'        => 'redirect_to_txn',
3084
-                    'TXN_ID'        => $transaction->ID(),
3085
-                    'EVT_ID'        => $this->_reg_event->ID(),
3086
-                    'event_name'    => urlencode($this->_reg_event->name()),
3087
-                    'redirect_from' => 'new_registration',
3088
-                ];
3089
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3090
-                break;
3091
-        }
3092
-        // what are you looking here for?  Should be nothing to do at this point.
3093
-    }
3094
-
3095
-
3096
-    /**
3097
-     * redirect_to_txn
3098
-     *
3099
-     * @return void
3100
-     * @throws EE_Error
3101
-     * @throws InvalidArgumentException
3102
-     * @throws InvalidDataTypeException
3103
-     * @throws InvalidInterfaceException
3104
-     * @throws ReflectionException
3105
-     */
3106
-    public function redirect_to_txn()
3107
-    {
3108
-        EE_System::do_not_cache();
3109
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3110
-        $query_args = [
3111
-            'action' => 'view_transaction',
3112
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3113
-            'page'   => 'espresso_transactions',
3114
-        ];
3115
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3116
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3117
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3118
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3119
-        }
3120
-        EE_Error::add_success(
3121
-            esc_html__(
3122
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3123
-                'event_espresso'
3124
-            )
3125
-        );
3126
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3127
-    }
3128
-
3129
-
3130
-    /**
3131
-     * generates HTML for the Attendee Contact List
3132
-     *
3133
-     * @return void
3134
-     * @throws DomainException
3135
-     * @throws EE_Error
3136
-     */
3137
-    protected function _attendee_contact_list_table()
3138
-    {
3139
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3140
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3141
-        $this->display_admin_list_table_page_with_no_sidebar();
3142
-    }
3143
-
3144
-
3145
-    /**
3146
-     * get_attendees
3147
-     *
3148
-     * @param      $per_page
3149
-     * @param bool $count whether to return count or data.
3150
-     * @param bool $trash
3151
-     * @return array|int
3152
-     * @throws EE_Error
3153
-     * @throws InvalidArgumentException
3154
-     * @throws InvalidDataTypeException
3155
-     * @throws InvalidInterfaceException
3156
-     */
3157
-    public function get_attendees($per_page, $count = false, $trash = false)
3158
-    {
3159
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3160
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3161
-        $orderby = $this->request->getRequestParam('orderby');
3162
-        switch ($orderby) {
3163
-            case 'ATT_ID':
3164
-            case 'ATT_fname':
3165
-            case 'ATT_email':
3166
-            case 'ATT_city':
3167
-            case 'STA_ID':
3168
-            case 'CNT_ID':
3169
-                break;
3170
-            case 'Registration_Count':
3171
-                $orderby = 'Registration_Count';
3172
-                break;
3173
-            default:
3174
-                $orderby = 'ATT_lname';
3175
-        }
3176
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3177
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3178
-        $per_page     = absint($per_page) ? $per_page : 10;
3179
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3180
-        $_where       = [];
3181
-        $search_term  = $this->request->getRequestParam('s');
3182
-        if ($search_term) {
3183
-            $search_term  = '%' . $search_term . '%';
3184
-            $_where['OR'] = [
3185
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3186
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3187
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3188
-                'ATT_fname'                         => ['LIKE', $search_term],
3189
-                'ATT_lname'                         => ['LIKE', $search_term],
3190
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3191
-                'ATT_email'                         => ['LIKE', $search_term],
3192
-                'ATT_address'                       => ['LIKE', $search_term],
3193
-                'ATT_address2'                      => ['LIKE', $search_term],
3194
-                'ATT_city'                          => ['LIKE', $search_term],
3195
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3196
-                'State.STA_name'                    => ['LIKE', $search_term],
3197
-                'ATT_phone'                         => ['LIKE', $search_term],
3198
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3199
-                'Registration.REG_code'             => ['LIKE', $search_term],
3200
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3201
-            ];
3202
-        }
3203
-        $offset     = ($current_page - 1) * $per_page;
3204
-        $limit      = $count ? null : [$offset, $per_page];
3205
-        $query_args = [
3206
-            $_where,
3207
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3208
-            'limit'         => $limit,
3209
-        ];
3210
-        if (! $count) {
3211
-            $query_args['order_by'] = [$orderby => $sort];
3212
-        }
3213
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3214
-        return $count
3215
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3216
-            : $this->getAttendeeModel()->get_all($query_args);
3217
-    }
3218
-
3219
-
3220
-    /**
3221
-     * This is just taking care of resending the registration confirmation
3222
-     *
3223
-     * @return void
3224
-     * @throws EE_Error
3225
-     * @throws InvalidArgumentException
3226
-     * @throws InvalidDataTypeException
3227
-     * @throws InvalidInterfaceException
3228
-     * @throws ReflectionException
3229
-     */
3230
-    protected function _resend_registration()
3231
-    {
3232
-        $this->_process_resend_registration();
3233
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3234
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3235
-        $query_args  = $redirect_to
3236
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3237
-            : ['action' => 'default'];
3238
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3239
-    }
3240
-
3241
-
3242
-    /**
3243
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3244
-     * to use when selecting registrations
3245
-     *
3246
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3247
-     *                                                     the query parameters from the request
3248
-     * @return void ends the request with a redirect or download
3249
-     */
3250
-    public function _registrations_report_base($method_name_for_getting_query_params)
3251
-    {
3252
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3253
-            ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3254
-            : null;
3255
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3256
-            $request_params = $this->request->requestParams();
3257
-            wp_redirect(
3258
-                EE_Admin_Page::add_query_args_and_nonce(
3259
-                    [
3260
-                        'page'        => 'espresso_batch',
3261
-                        'batch'       => 'file',
3262
-                        'EVT_ID'      => $EVT_ID,
3263
-                        'filters'     => urlencode(
3264
-                            serialize(
3265
-                                $this->$method_name_for_getting_query_params(
3266
-                                    EEH_Array::is_set($request_params, 'filters', [])
3267
-                                )
3268
-                            )
3269
-                        ),
3270
-                        'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3271
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3272
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3273
-                    ]
3274
-                )
3275
-            );
3276
-        } else {
3277
-            // Pull the current request params
3278
-            $request_args = $this->request->requestParams();
3279
-            // Set the required request_args to be passed to the export
3280
-            $required_request_args = [
3281
-                'export' => 'report',
3282
-                'action' => 'registrations_report_for_event',
3283
-                'EVT_ID' => $EVT_ID,
3284
-            ];
3285
-            // Merge required request args, overriding any currently set
3286
-            $request_args = array_merge($request_args, $required_request_args);
3287
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3288
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3289
-                $EE_Export = EE_Export::instance($request_args);
3290
-                $EE_Export->export();
3291
-            }
3292
-        }
3293
-    }
3294
-
3295
-
3296
-    /**
3297
-     * Creates a registration report using only query parameters in the request
3298
-     *
3299
-     * @return void
3300
-     */
3301
-    public function _registrations_report()
3302
-    {
3303
-        $this->_registrations_report_base('_get_registration_query_parameters');
3304
-    }
3305
-
3306
-
3307
-    public function _contact_list_export()
3308
-    {
3309
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3310
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3311
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3312
-            $EE_Export->export_attendees();
3313
-        }
3314
-    }
3315
-
3316
-
3317
-    public function _contact_list_report()
3318
-    {
3319
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3320
-            wp_redirect(
3321
-                EE_Admin_Page::add_query_args_and_nonce(
3322
-                    [
3323
-                        'page'        => 'espresso_batch',
3324
-                        'batch'       => 'file',
3325
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3326
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3327
-                    ]
3328
-                )
3329
-            );
3330
-        } else {
3331
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3332
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3333
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3334
-                $EE_Export->report_attendees();
3335
-            }
3336
-        }
3337
-    }
3338
-
3339
-
3340
-
3341
-
3342
-
3343
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3344
-    /**
3345
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3346
-     *
3347
-     * @return void
3348
-     * @throws EE_Error
3349
-     * @throws InvalidArgumentException
3350
-     * @throws InvalidDataTypeException
3351
-     * @throws InvalidInterfaceException
3352
-     * @throws ReflectionException
3353
-     */
3354
-    protected function _duplicate_attendee()
3355
-    {
3356
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3357
-        $action = $this->request->getRequestParam('return', 'default');
3358
-        // verify we have necessary info
3359
-        if (! $REG_ID) {
3360
-            EE_Error::add_error(
3361
-                esc_html__(
3362
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3363
-                    'event_espresso'
3364
-                ),
3365
-                __FILE__,
3366
-                __LINE__,
3367
-                __FUNCTION__
3368
-            );
3369
-            $query_args = ['action' => $action];
3370
-            $this->_redirect_after_action('', '', '', $query_args, true);
3371
-        }
3372
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3373
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3374
-        if (! $registration instanceof EE_Registration) {
3375
-            throw new RuntimeException(
3376
-                sprintf(
3377
-                    esc_html__(
3378
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3379
-                        'event_espresso'
3380
-                    ),
3381
-                    $REG_ID
3382
-                )
3383
-            );
3384
-        }
3385
-        $attendee = $registration->attendee();
3386
-        // remove relation of existing attendee on registration
3387
-        $registration->_remove_relation_to($attendee, 'Attendee');
3388
-        // new attendee
3389
-        $new_attendee = clone $attendee;
3390
-        $new_attendee->set('ATT_ID', 0);
3391
-        $new_attendee->save();
3392
-        // add new attendee to reg
3393
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3394
-        EE_Error::add_success(
3395
-            esc_html__(
3396
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3397
-                'event_espresso'
3398
-            )
3399
-        );
3400
-        // redirect to edit page for attendee
3401
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3402
-        $this->_redirect_after_action('', '', '', $query_args, true);
3403
-    }
3404
-
3405
-
3406
-    /**
3407
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3408
-     *
3409
-     * @param int     $post_id
3410
-     * @param WP_Post $post
3411
-     * @throws DomainException
3412
-     * @throws EE_Error
3413
-     * @throws InvalidArgumentException
3414
-     * @throws InvalidDataTypeException
3415
-     * @throws InvalidInterfaceException
3416
-     * @throws LogicException
3417
-     * @throws InvalidFormSubmissionException
3418
-     * @throws ReflectionException
3419
-     */
3420
-    protected function _insert_update_cpt_item($post_id, $post)
3421
-    {
3422
-        $success  = true;
3423
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3424
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3425
-            : null;
3426
-        // for attendee updates
3427
-        if ($attendee instanceof EE_Attendee) {
3428
-            // note we should only be UPDATING attendees at this point.
3429
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3430
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3431
-            $updated_fields = [
3432
-                'ATT_fname'     => $fname,
3433
-                'ATT_lname'     => $lname,
3434
-                'ATT_full_name' => "{$fname} {$lname}",
3435
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3436
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3437
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3438
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3439
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3440
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3441
-            ];
3442
-            foreach ($updated_fields as $field => $value) {
3443
-                $attendee->set($field, $value);
3444
-            }
3445
-
3446
-            // process contact details metabox form handler (which will also save the attendee)
3447
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3448
-            $success              = $contact_details_form->process($this->request->requestParams());
3449
-
3450
-            $attendee_update_callbacks = apply_filters(
3451
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3452
-                []
3453
-            );
3454
-            foreach ($attendee_update_callbacks as $a_callback) {
3455
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3456
-                    throw new EE_Error(
3457
-                        sprintf(
3458
-                            esc_html__(
3459
-                                '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.',
3460
-                                'event_espresso'
3461
-                            ),
3462
-                            $a_callback
3463
-                        )
3464
-                    );
3465
-                }
3466
-            }
3467
-        }
3468
-
3469
-        if ($success === false) {
3470
-            EE_Error::add_error(
3471
-                esc_html__(
3472
-                    'Something went wrong with updating the meta table data for the registration.',
3473
-                    'event_espresso'
3474
-                ),
3475
-                __FILE__,
3476
-                __FUNCTION__,
3477
-                __LINE__
3478
-            );
3479
-        }
3480
-    }
3481
-
3482
-
3483
-    public function trash_cpt_item($post_id)
3484
-    {
3485
-    }
3486
-
3487
-
3488
-    public function delete_cpt_item($post_id)
3489
-    {
3490
-    }
3491
-
3492
-
3493
-    public function restore_cpt_item($post_id)
3494
-    {
3495
-    }
3496
-
3497
-
3498
-    protected function _restore_cpt_item($post_id, $revision_id)
3499
-    {
3500
-    }
3501
-
3502
-
3503
-    /**
3504
-     * @throws EE_Error
3505
-     * @throws ReflectionException
3506
-     * @since 4.10.2.p
3507
-     */
3508
-    public function attendee_editor_metaboxes()
3509
-    {
3510
-        $this->verify_cpt_object();
3511
-        remove_meta_box(
3512
-            'postexcerpt',
3513
-            $this->_cpt_routes[ $this->_req_action ],
3514
-            'normal'
3515
-        );
3516
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3517
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3518
-            add_meta_box(
3519
-                'postexcerpt',
3520
-                esc_html__('Short Biography', 'event_espresso'),
3521
-                'post_excerpt_meta_box',
3522
-                $this->_cpt_routes[ $this->_req_action ],
3523
-                'normal'
3524
-            );
3525
-        }
3526
-        if (post_type_supports('espresso_attendees', 'comments')) {
3527
-            add_meta_box(
3528
-                'commentsdiv',
3529
-                esc_html__('Notes on the Contact', 'event_espresso'),
3530
-                'post_comment_meta_box',
3531
-                $this->_cpt_routes[ $this->_req_action ],
3532
-                'normal',
3533
-                'core'
3534
-            );
3535
-        }
3536
-        add_meta_box(
3537
-            'attendee_contact_info',
3538
-            esc_html__('Contact Info', 'event_espresso'),
3539
-            [$this, 'attendee_contact_info'],
3540
-            $this->_cpt_routes[ $this->_req_action ],
3541
-            'side',
3542
-            'core'
3543
-        );
3544
-        add_meta_box(
3545
-            'attendee_details_address',
3546
-            esc_html__('Address Details', 'event_espresso'),
3547
-            [$this, 'attendee_address_details'],
3548
-            $this->_cpt_routes[ $this->_req_action ],
3549
-            'normal',
3550
-            'core'
3551
-        );
3552
-        add_meta_box(
3553
-            'attendee_registrations',
3554
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3555
-            [$this, 'attendee_registrations_meta_box'],
3556
-            $this->_cpt_routes[ $this->_req_action ],
3557
-            'normal',
3558
-            'high'
3559
-        );
3560
-    }
3561
-
3562
-
3563
-    /**
3564
-     * Metabox for attendee contact info
3565
-     *
3566
-     * @param WP_Post $post wp post object
3567
-     * @return void attendee contact info ( and form )
3568
-     * @throws EE_Error
3569
-     * @throws InvalidArgumentException
3570
-     * @throws InvalidDataTypeException
3571
-     * @throws InvalidInterfaceException
3572
-     * @throws LogicException
3573
-     * @throws DomainException
3574
-     */
3575
-    public function attendee_contact_info($post)
3576
-    {
3577
-        // get attendee object ( should already have it )
3578
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3579
-        $form->enqueueStylesAndScripts();
3580
-        echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3581
-    }
3582
-
3583
-
3584
-    /**
3585
-     * Return form handler for the contact details metabox
3586
-     *
3587
-     * @param EE_Attendee $attendee
3588
-     * @return AttendeeContactDetailsMetaboxFormHandler
3589
-     * @throws DomainException
3590
-     * @throws InvalidArgumentException
3591
-     * @throws InvalidDataTypeException
3592
-     * @throws InvalidInterfaceException
3593
-     */
3594
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3595
-    {
3596
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3597
-    }
3598
-
3599
-
3600
-    /**
3601
-     * Metabox for attendee details
3602
-     *
3603
-     * @param WP_Post $post wp post object
3604
-     * @throws EE_Error
3605
-     * @throws ReflectionException
3606
-     */
3607
-    public function attendee_address_details($post)
3608
-    {
3609
-        // get attendee object (should already have it)
3610
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3611
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3612
-            new EE_Question_Form_Input(
3613
-                EE_Question::new_instance(
3614
-                    [
3615
-                        'QST_ID'           => 0,
3616
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3617
-                        'QST_system'       => 'admin-state',
3618
-                    ]
3619
-                ),
3620
-                EE_Answer::new_instance(
3621
-                    [
3622
-                        'ANS_ID'    => 0,
3623
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3624
-                    ]
3625
-                ),
3626
-                [
3627
-                    'input_id'       => 'STA_ID',
3628
-                    'input_name'     => 'STA_ID',
3629
-                    'input_prefix'   => '',
3630
-                    'append_qstn_id' => false,
3631
-                ]
3632
-            )
3633
-        );
3634
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3635
-            new EE_Question_Form_Input(
3636
-                EE_Question::new_instance(
3637
-                    [
3638
-                        'QST_ID'           => 0,
3639
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3640
-                        'QST_system'       => 'admin-country',
3641
-                    ]
3642
-                ),
3643
-                EE_Answer::new_instance(
3644
-                    [
3645
-                        'ANS_ID'    => 0,
3646
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3647
-                    ]
3648
-                ),
3649
-                [
3650
-                    'input_id'       => 'CNT_ISO',
3651
-                    'input_name'     => 'CNT_ISO',
3652
-                    'input_prefix'   => '',
3653
-                    'append_qstn_id' => false,
3654
-                ]
3655
-            )
3656
-        );
3657
-        $template                             =
3658
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3659
-        EEH_Template::display_template($template, $this->_template_args);
3660
-    }
3661
-
3662
-
3663
-    /**
3664
-     * _attendee_details
3665
-     *
3666
-     * @param $post
3667
-     * @return void
3668
-     * @throws DomainException
3669
-     * @throws EE_Error
3670
-     * @throws InvalidArgumentException
3671
-     * @throws InvalidDataTypeException
3672
-     * @throws InvalidInterfaceException
3673
-     * @throws ReflectionException
3674
-     */
3675
-    public function attendee_registrations_meta_box($post)
3676
-    {
3677
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3678
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3679
-        $template                              =
3680
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3681
-        EEH_Template::display_template($template, $this->_template_args);
3682
-    }
3683
-
3684
-
3685
-    /**
3686
-     * add in the form fields for the attendee edit
3687
-     *
3688
-     * @param WP_Post $post wp post object
3689
-     * @return void echos html for new form.
3690
-     * @throws DomainException
3691
-     */
3692
-    public function after_title_form_fields($post)
3693
-    {
3694
-        if ($post->post_type === 'espresso_attendees') {
3695
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3696
-            $template_args['attendee'] = $this->_cpt_model_obj;
3697
-            EEH_Template::display_template($template, $template_args);
3698
-        }
3699
-    }
3700
-
3701
-
3702
-    /**
3703
-     * _trash_or_restore_attendee
3704
-     *
3705
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3706
-     * @return void
3707
-     * @throws EE_Error
3708
-     * @throws InvalidArgumentException
3709
-     * @throws InvalidDataTypeException
3710
-     * @throws InvalidInterfaceException
3711
-     */
3712
-    protected function _trash_or_restore_attendees($trash = true)
3713
-    {
3714
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3715
-        $status = $trash ? 'trash' : 'publish';
3716
-        // Checkboxes
3717
-        if ($this->request->requestParamIsSet('checkbox')) {
3718
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3719
-            // if array has more than one element than success message should be plural
3720
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3721
-            // cycle thru checkboxes
3722
-            foreach ($ATT_IDs as $ATT_ID) {
3723
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3724
-                if (! $updated) {
3725
-                    $success = 0;
3726
-                }
3727
-            }
3728
-        } else {
3729
-            // grab single id and delete
3730
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3731
-            // update attendee
3732
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3733
-        }
3734
-        $what        = $success > 1
3735
-            ? esc_html__('Contacts', 'event_espresso')
3736
-            : esc_html__('Contact', 'event_espresso');
3737
-        $action_desc = $trash
3738
-            ? esc_html__('moved to the trash', 'event_espresso')
3739
-            : esc_html__('restored', 'event_espresso');
3740
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3741
-    }
2895
+		}
2896
+		$template_args = [
2897
+			'title'                    => '',
2898
+			'content'                  => '',
2899
+			'step_button_text'         => '',
2900
+			'show_notification_toggle' => false,
2901
+		];
2902
+		// to indicate we're processing a new registration
2903
+		$hidden_fields = [
2904
+			'processing_registration' => [
2905
+				'type'  => 'hidden',
2906
+				'value' => 0,
2907
+			],
2908
+			'event_id'                => [
2909
+				'type'  => 'hidden',
2910
+				'value' => $this->_reg_event->ID(),
2911
+			],
2912
+		];
2913
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2914
+		$cart = EE_Registry::instance()->SSN->cart();
2915
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2916
+		switch ($step) {
2917
+			case 'ticket':
2918
+				$hidden_fields['processing_registration']['value'] = 1;
2919
+				$template_args['title']                            = esc_html__(
2920
+					'Step One: Select the Ticket for this registration',
2921
+					'event_espresso'
2922
+				);
2923
+				$template_args['content']                          =
2924
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2925
+				$template_args['content']                          .= '</div>';
2926
+				$template_args['step_button_text']                 = esc_html__(
2927
+					'Add Tickets and Continue to Registrant Details',
2928
+					'event_espresso'
2929
+				);
2930
+				$template_args['show_notification_toggle']         = false;
2931
+				break;
2932
+			case 'questions':
2933
+				$hidden_fields['processing_registration']['value'] = 2;
2934
+				$template_args['title']                            = esc_html__(
2935
+					'Step Two: Add Registrant Details for this Registration',
2936
+					'event_espresso'
2937
+				);
2938
+				// in theory, we should be able to run EED_SPCO at this point
2939
+				// because the cart should have been set up properly by the first process_reg_step run.
2940
+				$template_args['content']                  =
2941
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2942
+				$template_args['step_button_text']         = esc_html__(
2943
+					'Save Registration and Continue to Details',
2944
+					'event_espresso'
2945
+				);
2946
+				$template_args['show_notification_toggle'] = true;
2947
+				break;
2948
+		}
2949
+		// we come back to the process_registration_step route.
2950
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2951
+		return EEH_Template::display_template(
2952
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2953
+			$template_args,
2954
+			true
2955
+		);
2956
+	}
2957
+
2958
+
2959
+	/**
2960
+	 * set_reg_event
2961
+	 *
2962
+	 * @return bool
2963
+	 * @throws EE_Error
2964
+	 * @throws InvalidArgumentException
2965
+	 * @throws InvalidDataTypeException
2966
+	 * @throws InvalidInterfaceException
2967
+	 */
2968
+	private function _set_reg_event()
2969
+	{
2970
+		if (is_object($this->_reg_event)) {
2971
+			return true;
2972
+		}
2973
+
2974
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2975
+		if (! $EVT_ID) {
2976
+			return false;
2977
+		}
2978
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2979
+		return true;
2980
+	}
2981
+
2982
+
2983
+	/**
2984
+	 * process_reg_step
2985
+	 *
2986
+	 * @return void
2987
+	 * @throws DomainException
2988
+	 * @throws EE_Error
2989
+	 * @throws InvalidArgumentException
2990
+	 * @throws InvalidDataTypeException
2991
+	 * @throws InvalidInterfaceException
2992
+	 * @throws ReflectionException
2993
+	 * @throws RuntimeException
2994
+	 */
2995
+	public function process_reg_step()
2996
+	{
2997
+		EE_System::do_not_cache();
2998
+		$this->_set_reg_event();
2999
+		/** @var CurrentPage $current_page */
3000
+		$current_page = $this->loader->getShared(CurrentPage::class);
3001
+		$current_page->setEspressoPage(true);
3002
+		$this->request->setRequestParam('uts', time());
3003
+		// what step are we on?
3004
+		$cart = EE_Registry::instance()->SSN->cart();
3005
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3006
+		// if doing ajax then we need to verify the nonce
3007
+		if ($this->request->isAjax()) {
3008
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
3009
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3010
+		}
3011
+		switch ($step) {
3012
+			case 'ticket':
3013
+				// process ticket selection
3014
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3015
+				if ($success) {
3016
+					EE_Error::add_success(
3017
+						esc_html__(
3018
+							'Tickets Selected. Now complete the registration.',
3019
+							'event_espresso'
3020
+						)
3021
+					);
3022
+				} else {
3023
+					$this->request->setRequestParam('step_error', true);
3024
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3025
+				}
3026
+				if ($this->request->isAjax()) {
3027
+					$this->new_registration(); // display next step
3028
+				} else {
3029
+					$query_args = [
3030
+						'action'                  => 'new_registration',
3031
+						'processing_registration' => 1,
3032
+						'event_id'                => $this->_reg_event->ID(),
3033
+						'uts'                     => time(),
3034
+					];
3035
+					$this->_redirect_after_action(
3036
+						false,
3037
+						'',
3038
+						'',
3039
+						$query_args,
3040
+						true
3041
+					);
3042
+				}
3043
+				break;
3044
+			case 'questions':
3045
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3046
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3047
+				}
3048
+				// process registration
3049
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3050
+				if ($cart instanceof EE_Cart) {
3051
+					$grand_total = $cart->get_grand_total();
3052
+					if ($grand_total instanceof EE_Line_Item) {
3053
+						$grand_total->save_this_and_descendants_to_txn();
3054
+					}
3055
+				}
3056
+				if (! $transaction instanceof EE_Transaction) {
3057
+					$query_args = [
3058
+						'action'                  => 'new_registration',
3059
+						'processing_registration' => 2,
3060
+						'event_id'                => $this->_reg_event->ID(),
3061
+						'uts'                     => time(),
3062
+					];
3063
+					if ($this->request->isAjax()) {
3064
+						// display registration form again because there are errors (maybe validation?)
3065
+						$this->new_registration();
3066
+						return;
3067
+					}
3068
+					$this->_redirect_after_action(
3069
+						false,
3070
+						'',
3071
+						'',
3072
+						$query_args,
3073
+						true
3074
+					);
3075
+					return;
3076
+				}
3077
+				// maybe update status, and make sure to save transaction if not done already
3078
+				if (! $transaction->update_status_based_on_total_paid()) {
3079
+					$transaction->save();
3080
+				}
3081
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3082
+				$query_args = [
3083
+					'action'        => 'redirect_to_txn',
3084
+					'TXN_ID'        => $transaction->ID(),
3085
+					'EVT_ID'        => $this->_reg_event->ID(),
3086
+					'event_name'    => urlencode($this->_reg_event->name()),
3087
+					'redirect_from' => 'new_registration',
3088
+				];
3089
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3090
+				break;
3091
+		}
3092
+		// what are you looking here for?  Should be nothing to do at this point.
3093
+	}
3094
+
3095
+
3096
+	/**
3097
+	 * redirect_to_txn
3098
+	 *
3099
+	 * @return void
3100
+	 * @throws EE_Error
3101
+	 * @throws InvalidArgumentException
3102
+	 * @throws InvalidDataTypeException
3103
+	 * @throws InvalidInterfaceException
3104
+	 * @throws ReflectionException
3105
+	 */
3106
+	public function redirect_to_txn()
3107
+	{
3108
+		EE_System::do_not_cache();
3109
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3110
+		$query_args = [
3111
+			'action' => 'view_transaction',
3112
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3113
+			'page'   => 'espresso_transactions',
3114
+		];
3115
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3116
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3117
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3118
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3119
+		}
3120
+		EE_Error::add_success(
3121
+			esc_html__(
3122
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3123
+				'event_espresso'
3124
+			)
3125
+		);
3126
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3127
+	}
3128
+
3129
+
3130
+	/**
3131
+	 * generates HTML for the Attendee Contact List
3132
+	 *
3133
+	 * @return void
3134
+	 * @throws DomainException
3135
+	 * @throws EE_Error
3136
+	 */
3137
+	protected function _attendee_contact_list_table()
3138
+	{
3139
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3140
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3141
+		$this->display_admin_list_table_page_with_no_sidebar();
3142
+	}
3143
+
3144
+
3145
+	/**
3146
+	 * get_attendees
3147
+	 *
3148
+	 * @param      $per_page
3149
+	 * @param bool $count whether to return count or data.
3150
+	 * @param bool $trash
3151
+	 * @return array|int
3152
+	 * @throws EE_Error
3153
+	 * @throws InvalidArgumentException
3154
+	 * @throws InvalidDataTypeException
3155
+	 * @throws InvalidInterfaceException
3156
+	 */
3157
+	public function get_attendees($per_page, $count = false, $trash = false)
3158
+	{
3159
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3160
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3161
+		$orderby = $this->request->getRequestParam('orderby');
3162
+		switch ($orderby) {
3163
+			case 'ATT_ID':
3164
+			case 'ATT_fname':
3165
+			case 'ATT_email':
3166
+			case 'ATT_city':
3167
+			case 'STA_ID':
3168
+			case 'CNT_ID':
3169
+				break;
3170
+			case 'Registration_Count':
3171
+				$orderby = 'Registration_Count';
3172
+				break;
3173
+			default:
3174
+				$orderby = 'ATT_lname';
3175
+		}
3176
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3177
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3178
+		$per_page     = absint($per_page) ? $per_page : 10;
3179
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3180
+		$_where       = [];
3181
+		$search_term  = $this->request->getRequestParam('s');
3182
+		if ($search_term) {
3183
+			$search_term  = '%' . $search_term . '%';
3184
+			$_where['OR'] = [
3185
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3186
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3187
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3188
+				'ATT_fname'                         => ['LIKE', $search_term],
3189
+				'ATT_lname'                         => ['LIKE', $search_term],
3190
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3191
+				'ATT_email'                         => ['LIKE', $search_term],
3192
+				'ATT_address'                       => ['LIKE', $search_term],
3193
+				'ATT_address2'                      => ['LIKE', $search_term],
3194
+				'ATT_city'                          => ['LIKE', $search_term],
3195
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3196
+				'State.STA_name'                    => ['LIKE', $search_term],
3197
+				'ATT_phone'                         => ['LIKE', $search_term],
3198
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3199
+				'Registration.REG_code'             => ['LIKE', $search_term],
3200
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3201
+			];
3202
+		}
3203
+		$offset     = ($current_page - 1) * $per_page;
3204
+		$limit      = $count ? null : [$offset, $per_page];
3205
+		$query_args = [
3206
+			$_where,
3207
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3208
+			'limit'         => $limit,
3209
+		];
3210
+		if (! $count) {
3211
+			$query_args['order_by'] = [$orderby => $sort];
3212
+		}
3213
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3214
+		return $count
3215
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3216
+			: $this->getAttendeeModel()->get_all($query_args);
3217
+	}
3218
+
3219
+
3220
+	/**
3221
+	 * This is just taking care of resending the registration confirmation
3222
+	 *
3223
+	 * @return void
3224
+	 * @throws EE_Error
3225
+	 * @throws InvalidArgumentException
3226
+	 * @throws InvalidDataTypeException
3227
+	 * @throws InvalidInterfaceException
3228
+	 * @throws ReflectionException
3229
+	 */
3230
+	protected function _resend_registration()
3231
+	{
3232
+		$this->_process_resend_registration();
3233
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3234
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3235
+		$query_args  = $redirect_to
3236
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3237
+			: ['action' => 'default'];
3238
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3239
+	}
3240
+
3241
+
3242
+	/**
3243
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3244
+	 * to use when selecting registrations
3245
+	 *
3246
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3247
+	 *                                                     the query parameters from the request
3248
+	 * @return void ends the request with a redirect or download
3249
+	 */
3250
+	public function _registrations_report_base($method_name_for_getting_query_params)
3251
+	{
3252
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3253
+			? $this->request->getRequestParam('EVT_ID', 0, 'int')
3254
+			: null;
3255
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3256
+			$request_params = $this->request->requestParams();
3257
+			wp_redirect(
3258
+				EE_Admin_Page::add_query_args_and_nonce(
3259
+					[
3260
+						'page'        => 'espresso_batch',
3261
+						'batch'       => 'file',
3262
+						'EVT_ID'      => $EVT_ID,
3263
+						'filters'     => urlencode(
3264
+							serialize(
3265
+								$this->$method_name_for_getting_query_params(
3266
+									EEH_Array::is_set($request_params, 'filters', [])
3267
+								)
3268
+							)
3269
+						),
3270
+						'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3271
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3272
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3273
+					]
3274
+				)
3275
+			);
3276
+		} else {
3277
+			// Pull the current request params
3278
+			$request_args = $this->request->requestParams();
3279
+			// Set the required request_args to be passed to the export
3280
+			$required_request_args = [
3281
+				'export' => 'report',
3282
+				'action' => 'registrations_report_for_event',
3283
+				'EVT_ID' => $EVT_ID,
3284
+			];
3285
+			// Merge required request args, overriding any currently set
3286
+			$request_args = array_merge($request_args, $required_request_args);
3287
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3288
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3289
+				$EE_Export = EE_Export::instance($request_args);
3290
+				$EE_Export->export();
3291
+			}
3292
+		}
3293
+	}
3294
+
3295
+
3296
+	/**
3297
+	 * Creates a registration report using only query parameters in the request
3298
+	 *
3299
+	 * @return void
3300
+	 */
3301
+	public function _registrations_report()
3302
+	{
3303
+		$this->_registrations_report_base('_get_registration_query_parameters');
3304
+	}
3305
+
3306
+
3307
+	public function _contact_list_export()
3308
+	{
3309
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3310
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3311
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3312
+			$EE_Export->export_attendees();
3313
+		}
3314
+	}
3315
+
3316
+
3317
+	public function _contact_list_report()
3318
+	{
3319
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3320
+			wp_redirect(
3321
+				EE_Admin_Page::add_query_args_and_nonce(
3322
+					[
3323
+						'page'        => 'espresso_batch',
3324
+						'batch'       => 'file',
3325
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3326
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3327
+					]
3328
+				)
3329
+			);
3330
+		} else {
3331
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3332
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3333
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3334
+				$EE_Export->report_attendees();
3335
+			}
3336
+		}
3337
+	}
3338
+
3339
+
3340
+
3341
+
3342
+
3343
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3344
+	/**
3345
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3346
+	 *
3347
+	 * @return void
3348
+	 * @throws EE_Error
3349
+	 * @throws InvalidArgumentException
3350
+	 * @throws InvalidDataTypeException
3351
+	 * @throws InvalidInterfaceException
3352
+	 * @throws ReflectionException
3353
+	 */
3354
+	protected function _duplicate_attendee()
3355
+	{
3356
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3357
+		$action = $this->request->getRequestParam('return', 'default');
3358
+		// verify we have necessary info
3359
+		if (! $REG_ID) {
3360
+			EE_Error::add_error(
3361
+				esc_html__(
3362
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3363
+					'event_espresso'
3364
+				),
3365
+				__FILE__,
3366
+				__LINE__,
3367
+				__FUNCTION__
3368
+			);
3369
+			$query_args = ['action' => $action];
3370
+			$this->_redirect_after_action('', '', '', $query_args, true);
3371
+		}
3372
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3373
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3374
+		if (! $registration instanceof EE_Registration) {
3375
+			throw new RuntimeException(
3376
+				sprintf(
3377
+					esc_html__(
3378
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3379
+						'event_espresso'
3380
+					),
3381
+					$REG_ID
3382
+				)
3383
+			);
3384
+		}
3385
+		$attendee = $registration->attendee();
3386
+		// remove relation of existing attendee on registration
3387
+		$registration->_remove_relation_to($attendee, 'Attendee');
3388
+		// new attendee
3389
+		$new_attendee = clone $attendee;
3390
+		$new_attendee->set('ATT_ID', 0);
3391
+		$new_attendee->save();
3392
+		// add new attendee to reg
3393
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3394
+		EE_Error::add_success(
3395
+			esc_html__(
3396
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3397
+				'event_espresso'
3398
+			)
3399
+		);
3400
+		// redirect to edit page for attendee
3401
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3402
+		$this->_redirect_after_action('', '', '', $query_args, true);
3403
+	}
3404
+
3405
+
3406
+	/**
3407
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3408
+	 *
3409
+	 * @param int     $post_id
3410
+	 * @param WP_Post $post
3411
+	 * @throws DomainException
3412
+	 * @throws EE_Error
3413
+	 * @throws InvalidArgumentException
3414
+	 * @throws InvalidDataTypeException
3415
+	 * @throws InvalidInterfaceException
3416
+	 * @throws LogicException
3417
+	 * @throws InvalidFormSubmissionException
3418
+	 * @throws ReflectionException
3419
+	 */
3420
+	protected function _insert_update_cpt_item($post_id, $post)
3421
+	{
3422
+		$success  = true;
3423
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3424
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3425
+			: null;
3426
+		// for attendee updates
3427
+		if ($attendee instanceof EE_Attendee) {
3428
+			// note we should only be UPDATING attendees at this point.
3429
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3430
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3431
+			$updated_fields = [
3432
+				'ATT_fname'     => $fname,
3433
+				'ATT_lname'     => $lname,
3434
+				'ATT_full_name' => "{$fname} {$lname}",
3435
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3436
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3437
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3438
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3439
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3440
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3441
+			];
3442
+			foreach ($updated_fields as $field => $value) {
3443
+				$attendee->set($field, $value);
3444
+			}
3445
+
3446
+			// process contact details metabox form handler (which will also save the attendee)
3447
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3448
+			$success              = $contact_details_form->process($this->request->requestParams());
3449
+
3450
+			$attendee_update_callbacks = apply_filters(
3451
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3452
+				[]
3453
+			);
3454
+			foreach ($attendee_update_callbacks as $a_callback) {
3455
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3456
+					throw new EE_Error(
3457
+						sprintf(
3458
+							esc_html__(
3459
+								'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.',
3460
+								'event_espresso'
3461
+							),
3462
+							$a_callback
3463
+						)
3464
+					);
3465
+				}
3466
+			}
3467
+		}
3468
+
3469
+		if ($success === false) {
3470
+			EE_Error::add_error(
3471
+				esc_html__(
3472
+					'Something went wrong with updating the meta table data for the registration.',
3473
+					'event_espresso'
3474
+				),
3475
+				__FILE__,
3476
+				__FUNCTION__,
3477
+				__LINE__
3478
+			);
3479
+		}
3480
+	}
3481
+
3482
+
3483
+	public function trash_cpt_item($post_id)
3484
+	{
3485
+	}
3486
+
3487
+
3488
+	public function delete_cpt_item($post_id)
3489
+	{
3490
+	}
3491
+
3492
+
3493
+	public function restore_cpt_item($post_id)
3494
+	{
3495
+	}
3496
+
3497
+
3498
+	protected function _restore_cpt_item($post_id, $revision_id)
3499
+	{
3500
+	}
3501
+
3502
+
3503
+	/**
3504
+	 * @throws EE_Error
3505
+	 * @throws ReflectionException
3506
+	 * @since 4.10.2.p
3507
+	 */
3508
+	public function attendee_editor_metaboxes()
3509
+	{
3510
+		$this->verify_cpt_object();
3511
+		remove_meta_box(
3512
+			'postexcerpt',
3513
+			$this->_cpt_routes[ $this->_req_action ],
3514
+			'normal'
3515
+		);
3516
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3517
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3518
+			add_meta_box(
3519
+				'postexcerpt',
3520
+				esc_html__('Short Biography', 'event_espresso'),
3521
+				'post_excerpt_meta_box',
3522
+				$this->_cpt_routes[ $this->_req_action ],
3523
+				'normal'
3524
+			);
3525
+		}
3526
+		if (post_type_supports('espresso_attendees', 'comments')) {
3527
+			add_meta_box(
3528
+				'commentsdiv',
3529
+				esc_html__('Notes on the Contact', 'event_espresso'),
3530
+				'post_comment_meta_box',
3531
+				$this->_cpt_routes[ $this->_req_action ],
3532
+				'normal',
3533
+				'core'
3534
+			);
3535
+		}
3536
+		add_meta_box(
3537
+			'attendee_contact_info',
3538
+			esc_html__('Contact Info', 'event_espresso'),
3539
+			[$this, 'attendee_contact_info'],
3540
+			$this->_cpt_routes[ $this->_req_action ],
3541
+			'side',
3542
+			'core'
3543
+		);
3544
+		add_meta_box(
3545
+			'attendee_details_address',
3546
+			esc_html__('Address Details', 'event_espresso'),
3547
+			[$this, 'attendee_address_details'],
3548
+			$this->_cpt_routes[ $this->_req_action ],
3549
+			'normal',
3550
+			'core'
3551
+		);
3552
+		add_meta_box(
3553
+			'attendee_registrations',
3554
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3555
+			[$this, 'attendee_registrations_meta_box'],
3556
+			$this->_cpt_routes[ $this->_req_action ],
3557
+			'normal',
3558
+			'high'
3559
+		);
3560
+	}
3561
+
3562
+
3563
+	/**
3564
+	 * Metabox for attendee contact info
3565
+	 *
3566
+	 * @param WP_Post $post wp post object
3567
+	 * @return void attendee contact info ( and form )
3568
+	 * @throws EE_Error
3569
+	 * @throws InvalidArgumentException
3570
+	 * @throws InvalidDataTypeException
3571
+	 * @throws InvalidInterfaceException
3572
+	 * @throws LogicException
3573
+	 * @throws DomainException
3574
+	 */
3575
+	public function attendee_contact_info($post)
3576
+	{
3577
+		// get attendee object ( should already have it )
3578
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3579
+		$form->enqueueStylesAndScripts();
3580
+		echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3581
+	}
3582
+
3583
+
3584
+	/**
3585
+	 * Return form handler for the contact details metabox
3586
+	 *
3587
+	 * @param EE_Attendee $attendee
3588
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3589
+	 * @throws DomainException
3590
+	 * @throws InvalidArgumentException
3591
+	 * @throws InvalidDataTypeException
3592
+	 * @throws InvalidInterfaceException
3593
+	 */
3594
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3595
+	{
3596
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3597
+	}
3598
+
3599
+
3600
+	/**
3601
+	 * Metabox for attendee details
3602
+	 *
3603
+	 * @param WP_Post $post wp post object
3604
+	 * @throws EE_Error
3605
+	 * @throws ReflectionException
3606
+	 */
3607
+	public function attendee_address_details($post)
3608
+	{
3609
+		// get attendee object (should already have it)
3610
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3611
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3612
+			new EE_Question_Form_Input(
3613
+				EE_Question::new_instance(
3614
+					[
3615
+						'QST_ID'           => 0,
3616
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3617
+						'QST_system'       => 'admin-state',
3618
+					]
3619
+				),
3620
+				EE_Answer::new_instance(
3621
+					[
3622
+						'ANS_ID'    => 0,
3623
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3624
+					]
3625
+				),
3626
+				[
3627
+					'input_id'       => 'STA_ID',
3628
+					'input_name'     => 'STA_ID',
3629
+					'input_prefix'   => '',
3630
+					'append_qstn_id' => false,
3631
+				]
3632
+			)
3633
+		);
3634
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3635
+			new EE_Question_Form_Input(
3636
+				EE_Question::new_instance(
3637
+					[
3638
+						'QST_ID'           => 0,
3639
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3640
+						'QST_system'       => 'admin-country',
3641
+					]
3642
+				),
3643
+				EE_Answer::new_instance(
3644
+					[
3645
+						'ANS_ID'    => 0,
3646
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3647
+					]
3648
+				),
3649
+				[
3650
+					'input_id'       => 'CNT_ISO',
3651
+					'input_name'     => 'CNT_ISO',
3652
+					'input_prefix'   => '',
3653
+					'append_qstn_id' => false,
3654
+				]
3655
+			)
3656
+		);
3657
+		$template                             =
3658
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3659
+		EEH_Template::display_template($template, $this->_template_args);
3660
+	}
3661
+
3662
+
3663
+	/**
3664
+	 * _attendee_details
3665
+	 *
3666
+	 * @param $post
3667
+	 * @return void
3668
+	 * @throws DomainException
3669
+	 * @throws EE_Error
3670
+	 * @throws InvalidArgumentException
3671
+	 * @throws InvalidDataTypeException
3672
+	 * @throws InvalidInterfaceException
3673
+	 * @throws ReflectionException
3674
+	 */
3675
+	public function attendee_registrations_meta_box($post)
3676
+	{
3677
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3678
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3679
+		$template                              =
3680
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3681
+		EEH_Template::display_template($template, $this->_template_args);
3682
+	}
3683
+
3684
+
3685
+	/**
3686
+	 * add in the form fields for the attendee edit
3687
+	 *
3688
+	 * @param WP_Post $post wp post object
3689
+	 * @return void echos html for new form.
3690
+	 * @throws DomainException
3691
+	 */
3692
+	public function after_title_form_fields($post)
3693
+	{
3694
+		if ($post->post_type === 'espresso_attendees') {
3695
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3696
+			$template_args['attendee'] = $this->_cpt_model_obj;
3697
+			EEH_Template::display_template($template, $template_args);
3698
+		}
3699
+	}
3700
+
3701
+
3702
+	/**
3703
+	 * _trash_or_restore_attendee
3704
+	 *
3705
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3706
+	 * @return void
3707
+	 * @throws EE_Error
3708
+	 * @throws InvalidArgumentException
3709
+	 * @throws InvalidDataTypeException
3710
+	 * @throws InvalidInterfaceException
3711
+	 */
3712
+	protected function _trash_or_restore_attendees($trash = true)
3713
+	{
3714
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3715
+		$status = $trash ? 'trash' : 'publish';
3716
+		// Checkboxes
3717
+		if ($this->request->requestParamIsSet('checkbox')) {
3718
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3719
+			// if array has more than one element than success message should be plural
3720
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3721
+			// cycle thru checkboxes
3722
+			foreach ($ATT_IDs as $ATT_ID) {
3723
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3724
+				if (! $updated) {
3725
+					$success = 0;
3726
+				}
3727
+			}
3728
+		} else {
3729
+			// grab single id and delete
3730
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3731
+			// update attendee
3732
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3733
+		}
3734
+		$what        = $success > 1
3735
+			? esc_html__('Contacts', 'event_espresso')
3736
+			: esc_html__('Contact', 'event_espresso');
3737
+		$action_desc = $trash
3738
+			? esc_html__('moved to the trash', 'event_espresso')
3739
+			: esc_html__('restored', 'event_espresso');
3740
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3741
+	}
3742 3742
 }
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 2 patches
Indentation   +1007 added lines, -1007 removed lines patch added patch discarded remove patch
@@ -15,1041 +15,1041 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @var Registrations_Admin_Page
20
-     */
21
-    protected $_admin_page;
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    private $_status;
27
-
28
-    /**
29
-     * An array of transaction details for the related transaction to the registration being processed.
30
-     * This is set via the _set_related_details method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_transaction_details = [];
35
-
36
-    /**
37
-     * An array of event details for the related event to the registration being processed.
38
-     * This is set via the _set_related_details method.
39
-     *
40
-     * @var array
41
-     */
42
-    protected $_event_details = [];
43
-
44
-
45
-    /**
46
-     * @param Registrations_Admin_Page $admin_page
47
-     */
48
-    public function __construct(Registrations_Admin_Page $admin_page)
49
-    {
50
-        $req_data = $admin_page->get_request_data();
51
-        if (! empty($req_data['event_id'])) {
52
-            $extra_query_args = [];
53
-            foreach ($admin_page->get_views() as $view_details) {
54
-                $extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
-            }
56
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
-        }
58
-        parent::__construct($admin_page);
59
-        $this->_status = $this->_admin_page->get_registration_status_array();
60
-    }
61
-
62
-
63
-    /**
64
-     * @return void
65
-     * @throws EE_Error
66
-     */
67
-    protected function _setup_data()
68
-    {
69
-        $this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
-    }
72
-
73
-
74
-    /**
75
-     * @return void
76
-     */
77
-    protected function _set_properties()
78
-    {
79
-        $return_url          = $this->getReturnUrl();
80
-        $this->_wp_list_args = [
81
-            'singular' => esc_html__('registration', 'event_espresso'),
82
-            'plural'   => esc_html__('registrations', 'event_espresso'),
83
-            'ajax'     => true,
84
-            'screen'   => $this->_admin_page->get_current_screen()->id,
85
-        ];
86
-        $ID_column_name      = esc_html__('ID', 'event_espresso');
87
-        $ID_column_name      .= ' : <span class="show-on-mobile-view-only" style="float:none">';
88
-        $ID_column_name      .= esc_html__('Registrant Name', 'event_espresso');
89
-        $ID_column_name      .= '</span> ';
90
-        $req_data            = $this->_admin_page->get_request_data();
91
-        if (isset($req_data['event_id'])) {
92
-            $this->_columns        = [
93
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
94
-                '_REG_ID'          => $ID_column_name,
95
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
96
-                'ATT_email'        => esc_html__('Email', 'event_espresso'),
97
-                '_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
98
-                'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
99
-                '_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
100
-                'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
101
-                'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
102
-                'actions'          => esc_html__('Actions', 'event_espresso'),
103
-            ];
104
-            $this->_bottom_buttons = [
105
-                'report' => [
106
-                    'route'         => 'registrations_report',
107
-                    'extra_request' => [
108
-                        'EVT_ID'     => $this->_req_data['event_id'],
109
-                        'return_url' => $return_url,
110
-                    ],
111
-                ],
112
-            ];
113
-        } else {
114
-            $this->_columns        = [
115
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
116
-                '_REG_ID'          => $ID_column_name,
117
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
118
-                '_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
119
-                'event_name'       => esc_html__('Event', 'event_espresso'),
120
-                'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
121
-                '_REG_final_price' => esc_html__('Price', 'event_espresso'),
122
-                '_REG_paid'        => esc_html__('Paid', 'event_espresso'),
123
-                'actions'          => esc_html__('Actions', 'event_espresso'),
124
-            ];
125
-            $this->_bottom_buttons = [
126
-                'report_all' => [
127
-                    'route'         => 'registrations_report',
128
-                    'extra_request' => [
129
-                        'return_url' => $return_url,
130
-                    ],
131
-                ],
132
-            ];
133
-        }
134
-        $this->_primary_column   = '_REG_ID';
135
-        $this->_sortable_columns = [
136
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
137
-            /**
138
-             * Allows users to change the default sort if they wish.
139
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
140
-             * name.
141
-             */
142
-            'ATT_fname'     => [
143
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
144
-                true,
145
-                $this,
146
-            ]
147
-                ? ['ATT_lname' => false]
148
-                : ['ATT_fname' => false],
149
-            'event_name'    => ['event_name' => false],
150
-            'DTT_EVT_start' => ['DTT_EVT_start' => false],
151
-            '_REG_ID'       => ['_REG_ID' => false],
152
-        ];
153
-        $this->_hidden_columns   = [];
154
-    }
155
-
156
-
157
-    /**
158
-     * This simply sets up the row class for the table rows.
159
-     * Allows for easier overriding of child methods for setting up sorting.
160
-     *
161
-     * @param EE_Registration $item the current item
162
-     * @return string
163
-     */
164
-    protected function _get_row_class($item)
165
-    {
166
-        $class = parent::_get_row_class($item);
167
-        // add status class
168
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
169
-        if ($this->_has_checkbox_column) {
170
-            $class .= ' has-checkbox-column';
171
-        }
172
-        return $class;
173
-    }
174
-
175
-
176
-    /**
177
-     * Set the $_transaction_details property if not set yet.
178
-     *
179
-     * @param EE_Registration $registration
180
-     * @throws EE_Error
181
-     * @throws InvalidArgumentException
182
-     * @throws ReflectionException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    protected function _set_related_details(EE_Registration $registration)
187
-    {
188
-        $transaction                = $registration->get_first_related('Transaction');
189
-        $status                     = $transaction instanceof EE_Transaction
190
-            ? $transaction->status_ID()
191
-            : EEM_Transaction::failed_status_code;
192
-        $this->_transaction_details = [
193
-            'transaction' => $transaction,
194
-            'status'      => $status,
195
-            'id'          => $transaction instanceof EE_Transaction
196
-                ? $transaction->ID()
197
-                : 0,
198
-            'title_attr'  => sprintf(
199
-                esc_html__('View Transaction Details (%s)', 'event_espresso'),
200
-                EEH_Template::pretty_status($status, false, 'sentence')
201
-            ),
202
-        ];
203
-        try {
204
-            $event = $registration->event();
205
-        } catch (EntityNotFoundException $e) {
206
-            $event = null;
207
-        }
208
-        $status               = $event instanceof EE_Event
209
-            ? $event->get_active_status()
210
-            : EE_Datetime::inactive;
211
-        $this->_event_details = [
212
-            'event'      => $event,
213
-            'status'     => $status,
214
-            'id'         => $event instanceof EE_Event
215
-                ? $event->ID()
216
-                : 0,
217
-            'title_attr' => sprintf(
218
-                esc_html__('Edit Event (%s)', 'event_espresso'),
219
-                EEH_Template::pretty_status($status, false, 'sentence')
220
-            ),
221
-        ];
222
-    }
223
-
224
-
225
-    /**
226
-     *    _get_table_filters
227
-     *
228
-     * @return array
229
-     */
230
-    protected function _get_table_filters()
231
-    {
232
-        $filters = [];
233
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
234
-        // methods.
235
-        $cur_date     = isset($this->_req_data['month_range'])
236
-            ? $this->_req_data['month_range']
237
-            : '';
238
-        $cur_category = isset($this->_req_data['EVT_CAT'])
239
-            ? $this->_req_data['EVT_CAT']
240
-            : -1;
241
-        $reg_status   = isset($this->_req_data['_reg_status'])
242
-            ? $this->_req_data['_reg_status']
243
-            : '';
244
-        $filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
245
-        $filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
246
-        $status       = [];
247
-        $status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
248
-        foreach ($this->_status as $key => $value) {
249
-            $status[] = ['id' => $key, 'text' => $value];
250
-        }
251
-        if ($this->_view !== 'incomplete') {
252
-            $filters[] = EEH_Form_Fields::select_input(
253
-                '_reg_status',
254
-                $status,
255
-                isset($this->_req_data['_reg_status'])
256
-                    ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
257
-                    : ''
258
-            );
259
-        }
260
-        if (isset($this->_req_data['event_id'])) {
261
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
262
-        }
263
-        return $filters;
264
-    }
265
-
266
-
267
-    /**
268
-     * @return void
269
-     * @throws EE_Error
270
-     * @throws InvalidArgumentException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     */
274
-    protected function _add_view_counts()
275
-    {
276
-        $this->_views['all']['count']   = $this->_total_registrations();
277
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
278
-        $this->_views['today']['count'] = $this->_total_registrations_today();
279
-        if (
280
-            EE_Registry::instance()->CAP->current_user_can(
281
-                'ee_delete_registrations',
282
-                'espresso_registrations_trash_registrations'
283
-            )
284
-        ) {
285
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
286
-            $this->_views['trash']['count']      = $this->_total_registrations('trash');
287
-        }
288
-    }
289
-
290
-
291
-    /**
292
-     * @param string $view
293
-     * @return int
294
-     * @throws EE_Error
295
-     * @throws InvalidArgumentException
296
-     * @throws InvalidDataTypeException
297
-     * @throws InvalidInterfaceException
298
-     */
299
-    protected function _total_registrations($view = '')
300
-    {
301
-        $_where = [];
302
-        $EVT_ID = isset($this->_req_data['event_id'])
303
-            ? absint($this->_req_data['event_id'])
304
-            : false;
305
-        if ($EVT_ID) {
306
-            $_where['EVT_ID'] = $EVT_ID;
307
-        }
308
-        switch ($view) {
309
-            case 'trash':
310
-                return EEM_Registration::instance()->count_deleted([$_where]);
311
-            case 'incomplete':
312
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
313
-                break;
314
-            default:
315
-                $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
316
-        }
317
-        return EEM_Registration::instance()->count([$_where]);
318
-    }
319
-
320
-
321
-    /**
322
-     * @return int
323
-     * @throws EE_Error
324
-     * @throws InvalidArgumentException
325
-     * @throws InvalidDataTypeException
326
-     * @throws InvalidInterfaceException
327
-     */
328
-    protected function _total_registrations_this_month()
329
-    {
330
-        $EVT_ID          = isset($this->_req_data['event_id'])
331
-            ? absint($this->_req_data['event_id'])
332
-            : false;
333
-        $_where          = $EVT_ID
334
-            ? ['EVT_ID' => $EVT_ID]
335
-            : [];
336
-        $this_year_r     = date('Y', current_time('timestamp'));
337
-        $time_start      = ' 00:00:00';
338
-        $time_end        = ' 23:59:59';
339
-        $this_month_r    = date('m', current_time('timestamp'));
340
-        $days_this_month = date('t', current_time('timestamp'));
341
-        // setup date query.
342
-        $beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
343
-            'REG_date',
344
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
345
-            'Y-m-d H:i:s'
346
-        );
347
-        $end_string         = EEM_Registration::instance()->convert_datetime_for_query(
348
-            'REG_date',
349
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
350
-            'Y-m-d H:i:s'
351
-        );
352
-        $_where['REG_date'] = [
353
-            'BETWEEN',
354
-            [
355
-                $beginning_string,
356
-                $end_string,
357
-            ],
358
-        ];
359
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
360
-        return EEM_Registration::instance()->count([$_where]);
361
-    }
362
-
363
-
364
-    /**
365
-     * @return int
366
-     * @throws EE_Error
367
-     * @throws InvalidArgumentException
368
-     * @throws InvalidDataTypeException
369
-     * @throws InvalidInterfaceException
370
-     */
371
-    protected function _total_registrations_today()
372
-    {
373
-        $EVT_ID             = isset($this->_req_data['event_id'])
374
-            ? absint($this->_req_data['event_id'])
375
-            : false;
376
-        $_where             = $EVT_ID
377
-            ? ['EVT_ID' => $EVT_ID]
378
-            : [];
379
-        $current_date       = date('Y-m-d', current_time('timestamp'));
380
-        $time_start         = ' 00:00:00';
381
-        $time_end           = ' 23:59:59';
382
-        $_where['REG_date'] = [
383
-            'BETWEEN',
384
-            [
385
-                EEM_Registration::instance()->convert_datetime_for_query(
386
-                    'REG_date',
387
-                    $current_date . $time_start,
388
-                    'Y-m-d H:i:s'
389
-                ),
390
-                EEM_Registration::instance()->convert_datetime_for_query(
391
-                    'REG_date',
392
-                    $current_date . $time_end,
393
-                    'Y-m-d H:i:s'
394
-                ),
395
-            ],
396
-        ];
397
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
398
-        return EEM_Registration::instance()->count([$_where]);
399
-    }
400
-
401
-
402
-    /**
403
-     * @param EE_Registration $item
404
-     * @return string
405
-     * @throws EE_Error
406
-     * @throws InvalidArgumentException
407
-     * @throws InvalidDataTypeException
408
-     * @throws InvalidInterfaceException
409
-     * @throws ReflectionException
410
-     */
411
-    public function column_cb($item)
412
-    {
413
-        /** checkbox/lock **/
414
-        $transaction   = $item->get_first_related('Transaction');
415
-        $payment_count = $transaction instanceof EE_Transaction
416
-            ? $transaction->count_related('Payment')
417
-            : 0;
418
-        return $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
419
-            'ee_edit_registration',
420
-            'registration_list_table_checkbox_input',
421
-            $item->ID()
422
-        )
423
-            ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
424
-              . '<span class="ee-lock-icon"></span>'
425
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
426
-    }
427
-
428
-
429
-    /**
430
-     * @param EE_Registration $item
431
-     * @return string
432
-     * @throws EE_Error
433
-     * @throws InvalidArgumentException
434
-     * @throws InvalidDataTypeException
435
-     * @throws InvalidInterfaceException
436
-     * @throws ReflectionException
437
-     */
438
-    public function column__REG_ID(EE_Registration $item)
439
-    {
440
-        $attendee = $item->attendee();
441
-        $content  = $item->ID();
442
-        $content  .= '<div class="show-on-mobile-view-only">';
443
-        $content  .= '<br>';
444
-        $content  .= $attendee instanceof EE_Attendee
445
-            ? $attendee->full_name()
446
-            : '';
447
-        $content  .= '&nbsp;';
448
-        $content  .= sprintf(
449
-            esc_html__('(%1$s / %2$s)', 'event_espresso'),
450
-            $item->count(),
451
-            $item->group_size()
452
-        );
453
-        $content  .= '<br>';
454
-        $content  .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
455
-        $content  .= '</div>';
456
-        return $content;
457
-    }
458
-
459
-
460
-    /**
461
-     * @param EE_Registration $item
462
-     * @return string
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws InvalidDataTypeException
466
-     * @throws InvalidInterfaceException
467
-     * @throws ReflectionException
468
-     */
469
-    public function column__REG_date(EE_Registration $item)
470
-    {
471
-        $this->_set_related_details($item);
472
-        // Build row actions
473
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
474
-            [
475
-                'action' => 'view_transaction',
476
-                'TXN_ID' => $this->_transaction_details['id'],
477
-            ],
478
-            TXN_ADMIN_URL
479
-        );
480
-        $view_link    = EE_Registry::instance()->CAP->current_user_can(
481
-            'ee_read_transaction',
482
-            'espresso_transactions_view_transaction'
483
-        )
484
-            ? '<a class="ee-status-color-'
485
-              . $this->_transaction_details['status']
486
-              . '" href="'
487
-              . $view_lnk_url
488
-              . '" title="'
489
-              . esc_attr($this->_transaction_details['title_attr'])
490
-              . '">'
491
-              . $item->get_i18n_datetime('REG_date')
492
-              . '</a>'
493
-            : $item->get_i18n_datetime('REG_date');
494
-        $view_link    .= '<br><span class="ee-status-text-small">'
495
-                         . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
496
-                         . '</span>';
497
-        return $view_link;
498
-    }
499
-
500
-
501
-    /**
502
-     * @param EE_Registration $item
503
-     * @return string
504
-     * @throws EE_Error
505
-     * @throws InvalidArgumentException
506
-     * @throws InvalidDataTypeException
507
-     * @throws InvalidInterfaceException
508
-     * @throws ReflectionException
509
-     */
510
-    public function column_event_name(EE_Registration $item)
511
-    {
512
-        $this->_set_related_details($item);
513
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
514
-        $EVT_ID     = $item->event_ID();
515
-        $event_name = $item->event_name();
516
-        $event_name =
517
-            $event_name
518
-                ?: esc_html__("No Associated Event", 'event_espresso');
519
-        $event_name = wp_trim_words($event_name, 30, '...');
520
-        if ($EVT_ID) {
521
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
522
-                ['action' => 'edit', 'post' => $EVT_ID],
523
-                EVENTS_ADMIN_URL
524
-            );
525
-            $edit_event              =
526
-                EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
527
-                    ? '<a class="ee-status-color-'
528
-                      . $this->_event_details['status']
529
-                      . '" href="'
530
-                      . $edit_event_url
531
-                      . '" title="'
532
-                      . esc_attr($this->_event_details['title_attr'])
533
-                      . '">'
534
-                      . $event_name
535
-                      . '</a>'
536
-                    : $event_name;
537
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
538
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
539
-            $actions['event_filter'] .= sprintf(
540
-                esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
541
-                $event_name
542
-            );
543
-            $actions['event_filter'] .= '">' . esc_html__('View Registrations', 'event_espresso') . '</a>';
544
-        } else {
545
-            $edit_event              = $event_name;
546
-            $actions['event_filter'] = '';
547
-        }
548
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
549
-    }
550
-
551
-
552
-    /**
553
-     * @param EE_Registration $item
554
-     * @return string
555
-     * @throws EE_Error
556
-     * @throws InvalidArgumentException
557
-     * @throws InvalidDataTypeException
558
-     * @throws InvalidInterfaceException
559
-     * @throws ReflectionException
560
-     */
561
-    public function column_DTT_EVT_start(EE_Registration $item)
562
-    {
563
-        $datetime_strings = [];
564
-        $ticket           = $item->ticket();
565
-        if ($ticket instanceof EE_Ticket) {
566
-            $remove_defaults = ['default_where_conditions' => 'none'];
567
-            $datetimes       = $ticket->datetimes($remove_defaults);
568
-            foreach ($datetimes as $datetime) {
569
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
570
-            }
571
-            return $this->generateDisplayForDatetimes($datetime_strings);
572
-        }
573
-        return esc_html__('There is no ticket on this registration', 'event_espresso');
574
-    }
575
-
576
-
577
-    /**
578
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
579
-     *
580
-     * @param array $datetime_strings
581
-     * @return string
582
-     */
583
-    public function generateDisplayForDateTimes(array $datetime_strings)
584
-    {
585
-        $content       = '<div class="ee-registration-event-datetimes-container">';
586
-        $expand_toggle = count($datetime_strings) > 1
587
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
588
-              . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
589
-            : '';
590
-        // get first item for initial visibility
591
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
592
-        $content .= $expand_toggle;
593
-        if ($datetime_strings) {
594
-            $content .= '<div style="clear:both"></div>';
595
-            $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
596
-            $content .= implode("<br />", $datetime_strings);
597
-            $content .= '</div>';
598
-        }
599
-        $content .= '</div>';
600
-        return $content;
601
-    }
602
-
603
-
604
-    /**
605
-     * @param EE_Registration $item
606
-     * @return string
607
-     * @throws EE_Error
608
-     * @throws InvalidArgumentException
609
-     * @throws InvalidDataTypeException
610
-     * @throws InvalidInterfaceException
611
-     * @throws ReflectionException
612
-     */
613
-    public function column_ATT_fname(EE_Registration $item)
614
-    {
615
-        $attendee      = $item->attendee();
616
-        $edit_lnk_url  = EE_Admin_Page::add_query_args_and_nonce(
617
-            [
618
-                'action'  => 'view_registration',
619
-                '_REG_ID' => $item->ID(),
620
-            ],
621
-            REG_ADMIN_URL
622
-        );
623
-        $attendee_name = $attendee instanceof EE_Attendee
624
-            ? $attendee->full_name()
625
-            : '';
626
-        $link          = EE_Registry::instance()->CAP->current_user_can(
627
-            'ee_read_registration',
628
-            'espresso_registrations_view_registration',
629
-            $item->ID()
630
-        )
631
-            ? '<a href="'
632
-              . $edit_lnk_url
633
-              . '" title="'
634
-              . esc_attr__('View Registration Details', 'event_espresso')
635
-              . '">'
636
-              . $attendee_name
637
-              . '</a>'
638
-            : $attendee_name;
639
-        $link          .= $item->count() === 1
640
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>'
641
-            : '';
642
-        $t             = $item->get_first_related('Transaction');
643
-        $payment_count = $t instanceof EE_Transaction
644
-            ? $t->count_related('Payment')
645
-            : 0;
646
-        // append group count to name
647
-        $link .= '&nbsp;' . sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
648
-        // append reg_code
649
-        $link .= '<br>' . sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
650
-        // reg status text for accessibility
651
-        $link   .= '<br><span class="ee-status-text-small">'
652
-                   . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
653
-                   . '</span>';
654
-        $action = ['_REG_ID' => $item->ID()];
655
-        if (isset($this->_req_data['event_id'])) {
656
-            $action['event_id'] = $item->event_ID();
657
-        }
658
-        // trash/restore/delete actions
659
-        $actions = [];
660
-        if (
661
-            $this->_view !== 'trash'
662
-            && $payment_count === 0
663
-            && EE_Registry::instance()->CAP->current_user_can(
664
-                'ee_delete_registration',
665
-                'espresso_registrations_trash_registrations',
666
-                $item->ID()
667
-            )
668
-        ) {
669
-            $action['action'] = 'trash_registrations';
670
-            $trash_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
671
-                $action,
672
-                REG_ADMIN_URL
673
-            );
674
-            $actions['trash'] = '<a href="'
675
-                                . $trash_lnk_url
676
-                                . '" title="'
677
-                                . esc_attr__('Trash Registration', 'event_espresso')
678
-                                . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
679
-        } elseif ($this->_view === 'trash') {
680
-            // restore registration link
681
-            if (
682
-                EE_Registry::instance()->CAP->current_user_can(
683
-                    'ee_delete_registration',
684
-                    'espresso_registrations_restore_registrations',
685
-                    $item->ID()
686
-                )
687
-            ) {
688
-                $action['action']   = 'restore_registrations';
689
-                $restore_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
690
-                    $action,
691
-                    REG_ADMIN_URL
692
-                );
693
-                $actions['restore'] = '<a href="'
694
-                                      . $restore_lnk_url
695
-                                      . '" title="'
696
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
697
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
698
-            }
699
-            if (
700
-                EE_Registry::instance()->CAP->current_user_can(
701
-                    'ee_delete_registration',
702
-                    'espresso_registrations_ee_delete_registrations',
703
-                    $item->ID()
704
-                )
705
-            ) {
706
-                $action['action']  = 'delete_registrations';
707
-                $delete_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
708
-                    $action,
709
-                    REG_ADMIN_URL
710
-                );
711
-                $actions['delete'] = '<a href="'
712
-                                     . $delete_lnk_url
713
-                                     . '" title="'
714
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
715
-                                     . '">'
716
-                                     . esc_html__('Delete', 'event_espresso')
717
-                                     . '</a>';
718
-            }
719
-        }
720
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
721
-    }
722
-
723
-
724
-    /**
725
-     * @param EE_Registration $item
726
-     * @return string
727
-     * @throws EE_Error
728
-     * @throws InvalidArgumentException
729
-     * @throws InvalidDataTypeException
730
-     * @throws InvalidInterfaceException
731
-     * @throws ReflectionException
732
-     */
733
-    public function column_ATT_email(EE_Registration $item)
734
-    {
735
-        $attendee = $item->get_first_related('Attendee');
736
-        return ! $attendee instanceof EE_Attendee
737
-            ? esc_html__('No attached contact record.', 'event_espresso')
738
-            : $attendee->email();
739
-    }
740
-
741
-
742
-    /**
743
-     * @param EE_Registration $item
744
-     * @return string
745
-     */
746
-    public function column__REG_count(EE_Registration $item)
747
-    {
748
-        return sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
749
-    }
750
-
751
-
752
-    /**
753
-     * @param EE_Registration $item
754
-     * @return string
755
-     * @throws EE_Error
756
-     * @throws ReflectionException
757
-     */
758
-    public function column_PRC_amount(EE_Registration $item)
759
-    {
760
-        $ticket   = $item->ticket();
761
-        $req_data = $this->_admin_page->get_request_data();
762
-        $content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
763
-            ? '<span class="TKT_name">' . $ticket->name() . '</span><br />'
764
-            : '';
765
-        if ($item->final_price() > 0) {
766
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
767
-        } else {
768
-            // free event
769
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
770
-                        . esc_html__('free', 'event_espresso')
771
-                        . '</span>';
772
-        }
773
-        return $content;
774
-    }
775
-
776
-
777
-    /**
778
-     * @param EE_Registration $item
779
-     * @return string
780
-     * @throws EE_Error
781
-     * @throws ReflectionException
782
-     */
783
-    public function column__REG_final_price(EE_Registration $item)
784
-    {
785
-        $ticket   = $item->ticket();
786
-        $req_data = $this->_admin_page->get_request_data();
787
-        $content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
788
-            ? ''
789
-            : '<span class="TKT_name">' . $ticket->name() . '</span><br />';
790
-        $content  .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
791
-        return $content;
792
-    }
793
-
794
-
795
-    /**
796
-     * @param EE_Registration $item
797
-     * @return string
798
-     * @throws EE_Error
799
-     */
800
-    public function column__REG_paid(EE_Registration $item)
801
-    {
802
-        $payment_method      = $item->payment_method();
803
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
804
-            ? $payment_method->admin_name()
805
-            : esc_html__('Unknown', 'event_espresso');
806
-        $content             = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
807
-        if ($item->paid() > 0) {
808
-            $content .= '<br><span class="ee-status-text-small">'
809
-                        . sprintf(
810
-                            esc_html__('...via %s', 'event_espresso'),
811
-                            $payment_method_name
812
-                        )
813
-                        . '</span>';
814
-        }
815
-        return $content;
816
-    }
817
-
818
-
819
-    /**
820
-     * @param EE_Registration $item
821
-     * @return string
822
-     * @throws EE_Error
823
-     * @throws EntityNotFoundException
824
-     * @throws InvalidArgumentException
825
-     * @throws InvalidDataTypeException
826
-     * @throws InvalidInterfaceException
827
-     * @throws ReflectionException
828
-     */
829
-    public function column_TXN_total(EE_Registration $item)
830
-    {
831
-        if ($item->transaction()) {
832
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
833
-                [
834
-                    'action' => 'view_transaction',
835
-                    'TXN_ID' => $item->transaction_ID(),
836
-                ],
837
-                TXN_ADMIN_URL
838
-            );
839
-            return EE_Registry::instance()->CAP->current_user_can(
840
-                'ee_read_transaction',
841
-                'espresso_transactions_view_transaction',
842
-                $item->transaction_ID()
843
-            )
844
-                ? '<span class="reg-pad-rght"><a class="status-'
845
-                  . $item->transaction()->status_ID()
846
-                  . '" href="'
847
-                  . $view_txn_lnk_url
848
-                  . '"  title="'
849
-                  . esc_attr__('View Transaction', 'event_espresso')
850
-                  . '">'
851
-                  . $item->transaction()->pretty_total()
852
-                  . '</a></span>'
853
-                : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
854
-        } else {
855
-            return esc_html__("None", "event_espresso");
856
-        }
857
-    }
858
-
859
-
860
-    /**
861
-     * @param EE_Registration $item
862
-     * @return string
863
-     * @throws EE_Error
864
-     * @throws EntityNotFoundException
865
-     * @throws InvalidArgumentException
866
-     * @throws InvalidDataTypeException
867
-     * @throws InvalidInterfaceException
868
-     * @throws ReflectionException
869
-     */
870
-    public function column_TXN_paid(EE_Registration $item)
871
-    {
872
-        if ($item->count() === 1) {
873
-            $transaction = $item->transaction()
874
-                ? $item->transaction()
875
-                : EE_Transaction::new_instance();
876
-            if ($transaction->paid() >= $transaction->total()) {
877
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
878
-            } else {
879
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
880
-                    [
881
-                        'action' => 'view_transaction',
882
-                        'TXN_ID' => $item->transaction_ID(),
883
-                    ],
884
-                    TXN_ADMIN_URL
885
-                );
886
-                return EE_Registry::instance()->CAP->current_user_can(
887
-                    'ee_read_transaction',
888
-                    'espresso_transactions_view_transaction',
889
-                    $item->transaction_ID()
890
-                )
891
-                    ? '<span class="reg-pad-rght"><a class="status-'
892
-                      . $transaction->status_ID()
893
-                      . '" href="'
894
-                      . $view_txn_lnk_url
895
-                      . '"  title="'
896
-                      . esc_attr__('View Transaction', 'event_espresso')
897
-                      . '">'
898
-                      . $item->transaction()->pretty_paid()
899
-                      . '</a><span>'
900
-                    : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
901
-            }
902
-        }
903
-        return '&nbsp;';
904
-    }
905
-
906
-
907
-    /**
908
-     * column_actions
909
-     *
910
-     * @param EE_Registration $item
911
-     * @return string
912
-     * @throws EE_Error
913
-     * @throws InvalidArgumentException
914
-     * @throws InvalidDataTypeException
915
-     * @throws InvalidInterfaceException
916
-     * @throws ReflectionException
917
-     */
918
-    public function column_actions(EE_Registration $item)
919
-    {
920
-        $actions  = [];
921
-        $attendee = $item->attendee();
922
-        $this->_set_related_details($item);
923
-
924
-        // Build row actions
925
-        if (
926
-            EE_Registry::instance()->CAP->current_user_can(
927
-                'ee_read_registration',
928
-                'espresso_registrations_view_registration',
929
-                $item->ID()
930
-            )
931
-        ) {
932
-            $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
933
-                [
934
-                    'action'  => 'view_registration',
935
-                    '_REG_ID' => $item->ID(),
936
-                ],
937
-                REG_ADMIN_URL
938
-            );
939
-            $actions['view_lnk'] = '
18
+	/**
19
+	 * @var Registrations_Admin_Page
20
+	 */
21
+	protected $_admin_page;
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private $_status;
27
+
28
+	/**
29
+	 * An array of transaction details for the related transaction to the registration being processed.
30
+	 * This is set via the _set_related_details method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_transaction_details = [];
35
+
36
+	/**
37
+	 * An array of event details for the related event to the registration being processed.
38
+	 * This is set via the _set_related_details method.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected $_event_details = [];
43
+
44
+
45
+	/**
46
+	 * @param Registrations_Admin_Page $admin_page
47
+	 */
48
+	public function __construct(Registrations_Admin_Page $admin_page)
49
+	{
50
+		$req_data = $admin_page->get_request_data();
51
+		if (! empty($req_data['event_id'])) {
52
+			$extra_query_args = [];
53
+			foreach ($admin_page->get_views() as $view_details) {
54
+				$extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
+			}
56
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
+		}
58
+		parent::__construct($admin_page);
59
+		$this->_status = $this->_admin_page->get_registration_status_array();
60
+	}
61
+
62
+
63
+	/**
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 */
67
+	protected function _setup_data()
68
+	{
69
+		$this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return void
76
+	 */
77
+	protected function _set_properties()
78
+	{
79
+		$return_url          = $this->getReturnUrl();
80
+		$this->_wp_list_args = [
81
+			'singular' => esc_html__('registration', 'event_espresso'),
82
+			'plural'   => esc_html__('registrations', 'event_espresso'),
83
+			'ajax'     => true,
84
+			'screen'   => $this->_admin_page->get_current_screen()->id,
85
+		];
86
+		$ID_column_name      = esc_html__('ID', 'event_espresso');
87
+		$ID_column_name      .= ' : <span class="show-on-mobile-view-only" style="float:none">';
88
+		$ID_column_name      .= esc_html__('Registrant Name', 'event_espresso');
89
+		$ID_column_name      .= '</span> ';
90
+		$req_data            = $this->_admin_page->get_request_data();
91
+		if (isset($req_data['event_id'])) {
92
+			$this->_columns        = [
93
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
94
+				'_REG_ID'          => $ID_column_name,
95
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
96
+				'ATT_email'        => esc_html__('Email', 'event_espresso'),
97
+				'_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
98
+				'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
99
+				'_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
100
+				'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
101
+				'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
102
+				'actions'          => esc_html__('Actions', 'event_espresso'),
103
+			];
104
+			$this->_bottom_buttons = [
105
+				'report' => [
106
+					'route'         => 'registrations_report',
107
+					'extra_request' => [
108
+						'EVT_ID'     => $this->_req_data['event_id'],
109
+						'return_url' => $return_url,
110
+					],
111
+				],
112
+			];
113
+		} else {
114
+			$this->_columns        = [
115
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
116
+				'_REG_ID'          => $ID_column_name,
117
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
118
+				'_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
119
+				'event_name'       => esc_html__('Event', 'event_espresso'),
120
+				'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
121
+				'_REG_final_price' => esc_html__('Price', 'event_espresso'),
122
+				'_REG_paid'        => esc_html__('Paid', 'event_espresso'),
123
+				'actions'          => esc_html__('Actions', 'event_espresso'),
124
+			];
125
+			$this->_bottom_buttons = [
126
+				'report_all' => [
127
+					'route'         => 'registrations_report',
128
+					'extra_request' => [
129
+						'return_url' => $return_url,
130
+					],
131
+				],
132
+			];
133
+		}
134
+		$this->_primary_column   = '_REG_ID';
135
+		$this->_sortable_columns = [
136
+			'_REG_date'     => ['_REG_date' => true],   // true means its already sorted
137
+			/**
138
+			 * Allows users to change the default sort if they wish.
139
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
140
+			 * name.
141
+			 */
142
+			'ATT_fname'     => [
143
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
144
+				true,
145
+				$this,
146
+			]
147
+				? ['ATT_lname' => false]
148
+				: ['ATT_fname' => false],
149
+			'event_name'    => ['event_name' => false],
150
+			'DTT_EVT_start' => ['DTT_EVT_start' => false],
151
+			'_REG_ID'       => ['_REG_ID' => false],
152
+		];
153
+		$this->_hidden_columns   = [];
154
+	}
155
+
156
+
157
+	/**
158
+	 * This simply sets up the row class for the table rows.
159
+	 * Allows for easier overriding of child methods for setting up sorting.
160
+	 *
161
+	 * @param EE_Registration $item the current item
162
+	 * @return string
163
+	 */
164
+	protected function _get_row_class($item)
165
+	{
166
+		$class = parent::_get_row_class($item);
167
+		// add status class
168
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
169
+		if ($this->_has_checkbox_column) {
170
+			$class .= ' has-checkbox-column';
171
+		}
172
+		return $class;
173
+	}
174
+
175
+
176
+	/**
177
+	 * Set the $_transaction_details property if not set yet.
178
+	 *
179
+	 * @param EE_Registration $registration
180
+	 * @throws EE_Error
181
+	 * @throws InvalidArgumentException
182
+	 * @throws ReflectionException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	protected function _set_related_details(EE_Registration $registration)
187
+	{
188
+		$transaction                = $registration->get_first_related('Transaction');
189
+		$status                     = $transaction instanceof EE_Transaction
190
+			? $transaction->status_ID()
191
+			: EEM_Transaction::failed_status_code;
192
+		$this->_transaction_details = [
193
+			'transaction' => $transaction,
194
+			'status'      => $status,
195
+			'id'          => $transaction instanceof EE_Transaction
196
+				? $transaction->ID()
197
+				: 0,
198
+			'title_attr'  => sprintf(
199
+				esc_html__('View Transaction Details (%s)', 'event_espresso'),
200
+				EEH_Template::pretty_status($status, false, 'sentence')
201
+			),
202
+		];
203
+		try {
204
+			$event = $registration->event();
205
+		} catch (EntityNotFoundException $e) {
206
+			$event = null;
207
+		}
208
+		$status               = $event instanceof EE_Event
209
+			? $event->get_active_status()
210
+			: EE_Datetime::inactive;
211
+		$this->_event_details = [
212
+			'event'      => $event,
213
+			'status'     => $status,
214
+			'id'         => $event instanceof EE_Event
215
+				? $event->ID()
216
+				: 0,
217
+			'title_attr' => sprintf(
218
+				esc_html__('Edit Event (%s)', 'event_espresso'),
219
+				EEH_Template::pretty_status($status, false, 'sentence')
220
+			),
221
+		];
222
+	}
223
+
224
+
225
+	/**
226
+	 *    _get_table_filters
227
+	 *
228
+	 * @return array
229
+	 */
230
+	protected function _get_table_filters()
231
+	{
232
+		$filters = [];
233
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
234
+		// methods.
235
+		$cur_date     = isset($this->_req_data['month_range'])
236
+			? $this->_req_data['month_range']
237
+			: '';
238
+		$cur_category = isset($this->_req_data['EVT_CAT'])
239
+			? $this->_req_data['EVT_CAT']
240
+			: -1;
241
+		$reg_status   = isset($this->_req_data['_reg_status'])
242
+			? $this->_req_data['_reg_status']
243
+			: '';
244
+		$filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
245
+		$filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
246
+		$status       = [];
247
+		$status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
248
+		foreach ($this->_status as $key => $value) {
249
+			$status[] = ['id' => $key, 'text' => $value];
250
+		}
251
+		if ($this->_view !== 'incomplete') {
252
+			$filters[] = EEH_Form_Fields::select_input(
253
+				'_reg_status',
254
+				$status,
255
+				isset($this->_req_data['_reg_status'])
256
+					? strtoupper(sanitize_key($this->_req_data['_reg_status']))
257
+					: ''
258
+			);
259
+		}
260
+		if (isset($this->_req_data['event_id'])) {
261
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
262
+		}
263
+		return $filters;
264
+	}
265
+
266
+
267
+	/**
268
+	 * @return void
269
+	 * @throws EE_Error
270
+	 * @throws InvalidArgumentException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 */
274
+	protected function _add_view_counts()
275
+	{
276
+		$this->_views['all']['count']   = $this->_total_registrations();
277
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
278
+		$this->_views['today']['count'] = $this->_total_registrations_today();
279
+		if (
280
+			EE_Registry::instance()->CAP->current_user_can(
281
+				'ee_delete_registrations',
282
+				'espresso_registrations_trash_registrations'
283
+			)
284
+		) {
285
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
286
+			$this->_views['trash']['count']      = $this->_total_registrations('trash');
287
+		}
288
+	}
289
+
290
+
291
+	/**
292
+	 * @param string $view
293
+	 * @return int
294
+	 * @throws EE_Error
295
+	 * @throws InvalidArgumentException
296
+	 * @throws InvalidDataTypeException
297
+	 * @throws InvalidInterfaceException
298
+	 */
299
+	protected function _total_registrations($view = '')
300
+	{
301
+		$_where = [];
302
+		$EVT_ID = isset($this->_req_data['event_id'])
303
+			? absint($this->_req_data['event_id'])
304
+			: false;
305
+		if ($EVT_ID) {
306
+			$_where['EVT_ID'] = $EVT_ID;
307
+		}
308
+		switch ($view) {
309
+			case 'trash':
310
+				return EEM_Registration::instance()->count_deleted([$_where]);
311
+			case 'incomplete':
312
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
313
+				break;
314
+			default:
315
+				$_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
316
+		}
317
+		return EEM_Registration::instance()->count([$_where]);
318
+	}
319
+
320
+
321
+	/**
322
+	 * @return int
323
+	 * @throws EE_Error
324
+	 * @throws InvalidArgumentException
325
+	 * @throws InvalidDataTypeException
326
+	 * @throws InvalidInterfaceException
327
+	 */
328
+	protected function _total_registrations_this_month()
329
+	{
330
+		$EVT_ID          = isset($this->_req_data['event_id'])
331
+			? absint($this->_req_data['event_id'])
332
+			: false;
333
+		$_where          = $EVT_ID
334
+			? ['EVT_ID' => $EVT_ID]
335
+			: [];
336
+		$this_year_r     = date('Y', current_time('timestamp'));
337
+		$time_start      = ' 00:00:00';
338
+		$time_end        = ' 23:59:59';
339
+		$this_month_r    = date('m', current_time('timestamp'));
340
+		$days_this_month = date('t', current_time('timestamp'));
341
+		// setup date query.
342
+		$beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
343
+			'REG_date',
344
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
345
+			'Y-m-d H:i:s'
346
+		);
347
+		$end_string         = EEM_Registration::instance()->convert_datetime_for_query(
348
+			'REG_date',
349
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
350
+			'Y-m-d H:i:s'
351
+		);
352
+		$_where['REG_date'] = [
353
+			'BETWEEN',
354
+			[
355
+				$beginning_string,
356
+				$end_string,
357
+			],
358
+		];
359
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
360
+		return EEM_Registration::instance()->count([$_where]);
361
+	}
362
+
363
+
364
+	/**
365
+	 * @return int
366
+	 * @throws EE_Error
367
+	 * @throws InvalidArgumentException
368
+	 * @throws InvalidDataTypeException
369
+	 * @throws InvalidInterfaceException
370
+	 */
371
+	protected function _total_registrations_today()
372
+	{
373
+		$EVT_ID             = isset($this->_req_data['event_id'])
374
+			? absint($this->_req_data['event_id'])
375
+			: false;
376
+		$_where             = $EVT_ID
377
+			? ['EVT_ID' => $EVT_ID]
378
+			: [];
379
+		$current_date       = date('Y-m-d', current_time('timestamp'));
380
+		$time_start         = ' 00:00:00';
381
+		$time_end           = ' 23:59:59';
382
+		$_where['REG_date'] = [
383
+			'BETWEEN',
384
+			[
385
+				EEM_Registration::instance()->convert_datetime_for_query(
386
+					'REG_date',
387
+					$current_date . $time_start,
388
+					'Y-m-d H:i:s'
389
+				),
390
+				EEM_Registration::instance()->convert_datetime_for_query(
391
+					'REG_date',
392
+					$current_date . $time_end,
393
+					'Y-m-d H:i:s'
394
+				),
395
+			],
396
+		];
397
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
398
+		return EEM_Registration::instance()->count([$_where]);
399
+	}
400
+
401
+
402
+	/**
403
+	 * @param EE_Registration $item
404
+	 * @return string
405
+	 * @throws EE_Error
406
+	 * @throws InvalidArgumentException
407
+	 * @throws InvalidDataTypeException
408
+	 * @throws InvalidInterfaceException
409
+	 * @throws ReflectionException
410
+	 */
411
+	public function column_cb($item)
412
+	{
413
+		/** checkbox/lock **/
414
+		$transaction   = $item->get_first_related('Transaction');
415
+		$payment_count = $transaction instanceof EE_Transaction
416
+			? $transaction->count_related('Payment')
417
+			: 0;
418
+		return $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
419
+			'ee_edit_registration',
420
+			'registration_list_table_checkbox_input',
421
+			$item->ID()
422
+		)
423
+			? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
424
+			  . '<span class="ee-lock-icon"></span>'
425
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
426
+	}
427
+
428
+
429
+	/**
430
+	 * @param EE_Registration $item
431
+	 * @return string
432
+	 * @throws EE_Error
433
+	 * @throws InvalidArgumentException
434
+	 * @throws InvalidDataTypeException
435
+	 * @throws InvalidInterfaceException
436
+	 * @throws ReflectionException
437
+	 */
438
+	public function column__REG_ID(EE_Registration $item)
439
+	{
440
+		$attendee = $item->attendee();
441
+		$content  = $item->ID();
442
+		$content  .= '<div class="show-on-mobile-view-only">';
443
+		$content  .= '<br>';
444
+		$content  .= $attendee instanceof EE_Attendee
445
+			? $attendee->full_name()
446
+			: '';
447
+		$content  .= '&nbsp;';
448
+		$content  .= sprintf(
449
+			esc_html__('(%1$s / %2$s)', 'event_espresso'),
450
+			$item->count(),
451
+			$item->group_size()
452
+		);
453
+		$content  .= '<br>';
454
+		$content  .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
455
+		$content  .= '</div>';
456
+		return $content;
457
+	}
458
+
459
+
460
+	/**
461
+	 * @param EE_Registration $item
462
+	 * @return string
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws InvalidDataTypeException
466
+	 * @throws InvalidInterfaceException
467
+	 * @throws ReflectionException
468
+	 */
469
+	public function column__REG_date(EE_Registration $item)
470
+	{
471
+		$this->_set_related_details($item);
472
+		// Build row actions
473
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
474
+			[
475
+				'action' => 'view_transaction',
476
+				'TXN_ID' => $this->_transaction_details['id'],
477
+			],
478
+			TXN_ADMIN_URL
479
+		);
480
+		$view_link    = EE_Registry::instance()->CAP->current_user_can(
481
+			'ee_read_transaction',
482
+			'espresso_transactions_view_transaction'
483
+		)
484
+			? '<a class="ee-status-color-'
485
+			  . $this->_transaction_details['status']
486
+			  . '" href="'
487
+			  . $view_lnk_url
488
+			  . '" title="'
489
+			  . esc_attr($this->_transaction_details['title_attr'])
490
+			  . '">'
491
+			  . $item->get_i18n_datetime('REG_date')
492
+			  . '</a>'
493
+			: $item->get_i18n_datetime('REG_date');
494
+		$view_link    .= '<br><span class="ee-status-text-small">'
495
+						 . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
496
+						 . '</span>';
497
+		return $view_link;
498
+	}
499
+
500
+
501
+	/**
502
+	 * @param EE_Registration $item
503
+	 * @return string
504
+	 * @throws EE_Error
505
+	 * @throws InvalidArgumentException
506
+	 * @throws InvalidDataTypeException
507
+	 * @throws InvalidInterfaceException
508
+	 * @throws ReflectionException
509
+	 */
510
+	public function column_event_name(EE_Registration $item)
511
+	{
512
+		$this->_set_related_details($item);
513
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
514
+		$EVT_ID     = $item->event_ID();
515
+		$event_name = $item->event_name();
516
+		$event_name =
517
+			$event_name
518
+				?: esc_html__("No Associated Event", 'event_espresso');
519
+		$event_name = wp_trim_words($event_name, 30, '...');
520
+		if ($EVT_ID) {
521
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
522
+				['action' => 'edit', 'post' => $EVT_ID],
523
+				EVENTS_ADMIN_URL
524
+			);
525
+			$edit_event              =
526
+				EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
527
+					? '<a class="ee-status-color-'
528
+					  . $this->_event_details['status']
529
+					  . '" href="'
530
+					  . $edit_event_url
531
+					  . '" title="'
532
+					  . esc_attr($this->_event_details['title_attr'])
533
+					  . '">'
534
+					  . $event_name
535
+					  . '</a>'
536
+					: $event_name;
537
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
538
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
539
+			$actions['event_filter'] .= sprintf(
540
+				esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
541
+				$event_name
542
+			);
543
+			$actions['event_filter'] .= '">' . esc_html__('View Registrations', 'event_espresso') . '</a>';
544
+		} else {
545
+			$edit_event              = $event_name;
546
+			$actions['event_filter'] = '';
547
+		}
548
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
549
+	}
550
+
551
+
552
+	/**
553
+	 * @param EE_Registration $item
554
+	 * @return string
555
+	 * @throws EE_Error
556
+	 * @throws InvalidArgumentException
557
+	 * @throws InvalidDataTypeException
558
+	 * @throws InvalidInterfaceException
559
+	 * @throws ReflectionException
560
+	 */
561
+	public function column_DTT_EVT_start(EE_Registration $item)
562
+	{
563
+		$datetime_strings = [];
564
+		$ticket           = $item->ticket();
565
+		if ($ticket instanceof EE_Ticket) {
566
+			$remove_defaults = ['default_where_conditions' => 'none'];
567
+			$datetimes       = $ticket->datetimes($remove_defaults);
568
+			foreach ($datetimes as $datetime) {
569
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
570
+			}
571
+			return $this->generateDisplayForDatetimes($datetime_strings);
572
+		}
573
+		return esc_html__('There is no ticket on this registration', 'event_espresso');
574
+	}
575
+
576
+
577
+	/**
578
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
579
+	 *
580
+	 * @param array $datetime_strings
581
+	 * @return string
582
+	 */
583
+	public function generateDisplayForDateTimes(array $datetime_strings)
584
+	{
585
+		$content       = '<div class="ee-registration-event-datetimes-container">';
586
+		$expand_toggle = count($datetime_strings) > 1
587
+			? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
588
+			  . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
589
+			: '';
590
+		// get first item for initial visibility
591
+		$content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
592
+		$content .= $expand_toggle;
593
+		if ($datetime_strings) {
594
+			$content .= '<div style="clear:both"></div>';
595
+			$content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
596
+			$content .= implode("<br />", $datetime_strings);
597
+			$content .= '</div>';
598
+		}
599
+		$content .= '</div>';
600
+		return $content;
601
+	}
602
+
603
+
604
+	/**
605
+	 * @param EE_Registration $item
606
+	 * @return string
607
+	 * @throws EE_Error
608
+	 * @throws InvalidArgumentException
609
+	 * @throws InvalidDataTypeException
610
+	 * @throws InvalidInterfaceException
611
+	 * @throws ReflectionException
612
+	 */
613
+	public function column_ATT_fname(EE_Registration $item)
614
+	{
615
+		$attendee      = $item->attendee();
616
+		$edit_lnk_url  = EE_Admin_Page::add_query_args_and_nonce(
617
+			[
618
+				'action'  => 'view_registration',
619
+				'_REG_ID' => $item->ID(),
620
+			],
621
+			REG_ADMIN_URL
622
+		);
623
+		$attendee_name = $attendee instanceof EE_Attendee
624
+			? $attendee->full_name()
625
+			: '';
626
+		$link          = EE_Registry::instance()->CAP->current_user_can(
627
+			'ee_read_registration',
628
+			'espresso_registrations_view_registration',
629
+			$item->ID()
630
+		)
631
+			? '<a href="'
632
+			  . $edit_lnk_url
633
+			  . '" title="'
634
+			  . esc_attr__('View Registration Details', 'event_espresso')
635
+			  . '">'
636
+			  . $attendee_name
637
+			  . '</a>'
638
+			: $attendee_name;
639
+		$link          .= $item->count() === 1
640
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>'
641
+			: '';
642
+		$t             = $item->get_first_related('Transaction');
643
+		$payment_count = $t instanceof EE_Transaction
644
+			? $t->count_related('Payment')
645
+			: 0;
646
+		// append group count to name
647
+		$link .= '&nbsp;' . sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
648
+		// append reg_code
649
+		$link .= '<br>' . sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
650
+		// reg status text for accessibility
651
+		$link   .= '<br><span class="ee-status-text-small">'
652
+				   . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
653
+				   . '</span>';
654
+		$action = ['_REG_ID' => $item->ID()];
655
+		if (isset($this->_req_data['event_id'])) {
656
+			$action['event_id'] = $item->event_ID();
657
+		}
658
+		// trash/restore/delete actions
659
+		$actions = [];
660
+		if (
661
+			$this->_view !== 'trash'
662
+			&& $payment_count === 0
663
+			&& EE_Registry::instance()->CAP->current_user_can(
664
+				'ee_delete_registration',
665
+				'espresso_registrations_trash_registrations',
666
+				$item->ID()
667
+			)
668
+		) {
669
+			$action['action'] = 'trash_registrations';
670
+			$trash_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
671
+				$action,
672
+				REG_ADMIN_URL
673
+			);
674
+			$actions['trash'] = '<a href="'
675
+								. $trash_lnk_url
676
+								. '" title="'
677
+								. esc_attr__('Trash Registration', 'event_espresso')
678
+								. '">' . esc_html__('Trash', 'event_espresso') . '</a>';
679
+		} elseif ($this->_view === 'trash') {
680
+			// restore registration link
681
+			if (
682
+				EE_Registry::instance()->CAP->current_user_can(
683
+					'ee_delete_registration',
684
+					'espresso_registrations_restore_registrations',
685
+					$item->ID()
686
+				)
687
+			) {
688
+				$action['action']   = 'restore_registrations';
689
+				$restore_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
690
+					$action,
691
+					REG_ADMIN_URL
692
+				);
693
+				$actions['restore'] = '<a href="'
694
+									  . $restore_lnk_url
695
+									  . '" title="'
696
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
697
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
698
+			}
699
+			if (
700
+				EE_Registry::instance()->CAP->current_user_can(
701
+					'ee_delete_registration',
702
+					'espresso_registrations_ee_delete_registrations',
703
+					$item->ID()
704
+				)
705
+			) {
706
+				$action['action']  = 'delete_registrations';
707
+				$delete_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
708
+					$action,
709
+					REG_ADMIN_URL
710
+				);
711
+				$actions['delete'] = '<a href="'
712
+									 . $delete_lnk_url
713
+									 . '" title="'
714
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
715
+									 . '">'
716
+									 . esc_html__('Delete', 'event_espresso')
717
+									 . '</a>';
718
+			}
719
+		}
720
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
721
+	}
722
+
723
+
724
+	/**
725
+	 * @param EE_Registration $item
726
+	 * @return string
727
+	 * @throws EE_Error
728
+	 * @throws InvalidArgumentException
729
+	 * @throws InvalidDataTypeException
730
+	 * @throws InvalidInterfaceException
731
+	 * @throws ReflectionException
732
+	 */
733
+	public function column_ATT_email(EE_Registration $item)
734
+	{
735
+		$attendee = $item->get_first_related('Attendee');
736
+		return ! $attendee instanceof EE_Attendee
737
+			? esc_html__('No attached contact record.', 'event_espresso')
738
+			: $attendee->email();
739
+	}
740
+
741
+
742
+	/**
743
+	 * @param EE_Registration $item
744
+	 * @return string
745
+	 */
746
+	public function column__REG_count(EE_Registration $item)
747
+	{
748
+		return sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
749
+	}
750
+
751
+
752
+	/**
753
+	 * @param EE_Registration $item
754
+	 * @return string
755
+	 * @throws EE_Error
756
+	 * @throws ReflectionException
757
+	 */
758
+	public function column_PRC_amount(EE_Registration $item)
759
+	{
760
+		$ticket   = $item->ticket();
761
+		$req_data = $this->_admin_page->get_request_data();
762
+		$content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
763
+			? '<span class="TKT_name">' . $ticket->name() . '</span><br />'
764
+			: '';
765
+		if ($item->final_price() > 0) {
766
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
767
+		} else {
768
+			// free event
769
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
770
+						. esc_html__('free', 'event_espresso')
771
+						. '</span>';
772
+		}
773
+		return $content;
774
+	}
775
+
776
+
777
+	/**
778
+	 * @param EE_Registration $item
779
+	 * @return string
780
+	 * @throws EE_Error
781
+	 * @throws ReflectionException
782
+	 */
783
+	public function column__REG_final_price(EE_Registration $item)
784
+	{
785
+		$ticket   = $item->ticket();
786
+		$req_data = $this->_admin_page->get_request_data();
787
+		$content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
788
+			? ''
789
+			: '<span class="TKT_name">' . $ticket->name() . '</span><br />';
790
+		$content  .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
791
+		return $content;
792
+	}
793
+
794
+
795
+	/**
796
+	 * @param EE_Registration $item
797
+	 * @return string
798
+	 * @throws EE_Error
799
+	 */
800
+	public function column__REG_paid(EE_Registration $item)
801
+	{
802
+		$payment_method      = $item->payment_method();
803
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
804
+			? $payment_method->admin_name()
805
+			: esc_html__('Unknown', 'event_espresso');
806
+		$content             = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
807
+		if ($item->paid() > 0) {
808
+			$content .= '<br><span class="ee-status-text-small">'
809
+						. sprintf(
810
+							esc_html__('...via %s', 'event_espresso'),
811
+							$payment_method_name
812
+						)
813
+						. '</span>';
814
+		}
815
+		return $content;
816
+	}
817
+
818
+
819
+	/**
820
+	 * @param EE_Registration $item
821
+	 * @return string
822
+	 * @throws EE_Error
823
+	 * @throws EntityNotFoundException
824
+	 * @throws InvalidArgumentException
825
+	 * @throws InvalidDataTypeException
826
+	 * @throws InvalidInterfaceException
827
+	 * @throws ReflectionException
828
+	 */
829
+	public function column_TXN_total(EE_Registration $item)
830
+	{
831
+		if ($item->transaction()) {
832
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
833
+				[
834
+					'action' => 'view_transaction',
835
+					'TXN_ID' => $item->transaction_ID(),
836
+				],
837
+				TXN_ADMIN_URL
838
+			);
839
+			return EE_Registry::instance()->CAP->current_user_can(
840
+				'ee_read_transaction',
841
+				'espresso_transactions_view_transaction',
842
+				$item->transaction_ID()
843
+			)
844
+				? '<span class="reg-pad-rght"><a class="status-'
845
+				  . $item->transaction()->status_ID()
846
+				  . '" href="'
847
+				  . $view_txn_lnk_url
848
+				  . '"  title="'
849
+				  . esc_attr__('View Transaction', 'event_espresso')
850
+				  . '">'
851
+				  . $item->transaction()->pretty_total()
852
+				  . '</a></span>'
853
+				: '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
854
+		} else {
855
+			return esc_html__("None", "event_espresso");
856
+		}
857
+	}
858
+
859
+
860
+	/**
861
+	 * @param EE_Registration $item
862
+	 * @return string
863
+	 * @throws EE_Error
864
+	 * @throws EntityNotFoundException
865
+	 * @throws InvalidArgumentException
866
+	 * @throws InvalidDataTypeException
867
+	 * @throws InvalidInterfaceException
868
+	 * @throws ReflectionException
869
+	 */
870
+	public function column_TXN_paid(EE_Registration $item)
871
+	{
872
+		if ($item->count() === 1) {
873
+			$transaction = $item->transaction()
874
+				? $item->transaction()
875
+				: EE_Transaction::new_instance();
876
+			if ($transaction->paid() >= $transaction->total()) {
877
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
878
+			} else {
879
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
880
+					[
881
+						'action' => 'view_transaction',
882
+						'TXN_ID' => $item->transaction_ID(),
883
+					],
884
+					TXN_ADMIN_URL
885
+				);
886
+				return EE_Registry::instance()->CAP->current_user_can(
887
+					'ee_read_transaction',
888
+					'espresso_transactions_view_transaction',
889
+					$item->transaction_ID()
890
+				)
891
+					? '<span class="reg-pad-rght"><a class="status-'
892
+					  . $transaction->status_ID()
893
+					  . '" href="'
894
+					  . $view_txn_lnk_url
895
+					  . '"  title="'
896
+					  . esc_attr__('View Transaction', 'event_espresso')
897
+					  . '">'
898
+					  . $item->transaction()->pretty_paid()
899
+					  . '</a><span>'
900
+					: '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
901
+			}
902
+		}
903
+		return '&nbsp;';
904
+	}
905
+
906
+
907
+	/**
908
+	 * column_actions
909
+	 *
910
+	 * @param EE_Registration $item
911
+	 * @return string
912
+	 * @throws EE_Error
913
+	 * @throws InvalidArgumentException
914
+	 * @throws InvalidDataTypeException
915
+	 * @throws InvalidInterfaceException
916
+	 * @throws ReflectionException
917
+	 */
918
+	public function column_actions(EE_Registration $item)
919
+	{
920
+		$actions  = [];
921
+		$attendee = $item->attendee();
922
+		$this->_set_related_details($item);
923
+
924
+		// Build row actions
925
+		if (
926
+			EE_Registry::instance()->CAP->current_user_can(
927
+				'ee_read_registration',
928
+				'espresso_registrations_view_registration',
929
+				$item->ID()
930
+			)
931
+		) {
932
+			$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
933
+				[
934
+					'action'  => 'view_registration',
935
+					'_REG_ID' => $item->ID(),
936
+				],
937
+				REG_ADMIN_URL
938
+			);
939
+			$actions['view_lnk'] = '
940 940
             <li>
941 941
                 <a href="' . $view_lnk_url . '" title="'
942
-                . esc_attr__('View Registration Details', 'event_espresso')
943
-                . '" class="tiny-text">
942
+				. esc_attr__('View Registration Details', 'event_espresso')
943
+				. '" class="tiny-text">
944 944
 				    <div class="dashicons dashicons-clipboard"></div>
945 945
 			    </a>
946 946
 			</li>';
947
-        }
948
-
949
-        if (
950
-            $attendee instanceof EE_Attendee
951
-            && EE_Registry::instance()->CAP->current_user_can(
952
-                'ee_edit_contacts',
953
-                'espresso_registrations_edit_attendee'
954
-            )
955
-        ) {
956
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
957
-                [
958
-                    'action' => 'edit_attendee',
959
-                    'post'   => $item->attendee_ID(),
960
-                ],
961
-                REG_ADMIN_URL
962
-            );
963
-            $actions['edit_lnk'] = '
947
+		}
948
+
949
+		if (
950
+			$attendee instanceof EE_Attendee
951
+			&& EE_Registry::instance()->CAP->current_user_can(
952
+				'ee_edit_contacts',
953
+				'espresso_registrations_edit_attendee'
954
+			)
955
+		) {
956
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
957
+				[
958
+					'action' => 'edit_attendee',
959
+					'post'   => $item->attendee_ID(),
960
+				],
961
+				REG_ADMIN_URL
962
+			);
963
+			$actions['edit_lnk'] = '
964 964
 			<li>
965 965
                 <a href="' . $edit_lnk_url . '" title="'
966
-                . esc_attr__('Edit Contact Details', 'event_espresso')
967
-                . '" class="tiny-text">
966
+				. esc_attr__('Edit Contact Details', 'event_espresso')
967
+				. '" class="tiny-text">
968 968
                     <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
969 969
                 </a>
970 970
 			</li>';
971
-        }
972
-
973
-        if (
974
-            $attendee instanceof EE_Attendee
975
-            && EE_Registry::instance()->CAP->current_user_can(
976
-                'ee_send_message',
977
-                'espresso_registrations_resend_registration',
978
-                $item->ID()
979
-            )
980
-        ) {
981
-            $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
982
-                [
983
-                    'action'  => 'resend_registration',
984
-                    '_REG_ID' => $item->ID(),
985
-                ],
986
-                REG_ADMIN_URL,
987
-                true
988
-            );
989
-            $actions['resend_reg_lnk'] = '
971
+		}
972
+
973
+		if (
974
+			$attendee instanceof EE_Attendee
975
+			&& EE_Registry::instance()->CAP->current_user_can(
976
+				'ee_send_message',
977
+				'espresso_registrations_resend_registration',
978
+				$item->ID()
979
+			)
980
+		) {
981
+			$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
982
+				[
983
+					'action'  => 'resend_registration',
984
+					'_REG_ID' => $item->ID(),
985
+				],
986
+				REG_ADMIN_URL,
987
+				true
988
+			);
989
+			$actions['resend_reg_lnk'] = '
990 990
 			<li>
991 991
 			    <a href="' . $resend_reg_lnk_url . '" title="'
992
-                . esc_attr__('Resend Registration Details', 'event_espresso')
993
-                . '" class="tiny-text">
992
+				. esc_attr__('Resend Registration Details', 'event_espresso')
993
+				. '" class="tiny-text">
994 994
 			        <div class="dashicons dashicons-email-alt"></div>
995 995
 			    </a>
996 996
             </li>';
997
-        }
998
-
999
-        if (
1000
-            EE_Registry::instance()->CAP->current_user_can(
1001
-                'ee_read_transaction',
1002
-                'espresso_transactions_view_transaction',
1003
-                $this->_transaction_details['id']
1004
-            )
1005
-        ) {
1006
-            $view_txn_lnk_url        = EE_Admin_Page::add_query_args_and_nonce(
1007
-                [
1008
-                    'action' => 'view_transaction',
1009
-                    'TXN_ID' => $this->_transaction_details['id'],
1010
-                ],
1011
-                TXN_ADMIN_URL
1012
-            );
1013
-            $actions['view_txn_lnk'] = '
997
+		}
998
+
999
+		if (
1000
+			EE_Registry::instance()->CAP->current_user_can(
1001
+				'ee_read_transaction',
1002
+				'espresso_transactions_view_transaction',
1003
+				$this->_transaction_details['id']
1004
+			)
1005
+		) {
1006
+			$view_txn_lnk_url        = EE_Admin_Page::add_query_args_and_nonce(
1007
+				[
1008
+					'action' => 'view_transaction',
1009
+					'TXN_ID' => $this->_transaction_details['id'],
1010
+				],
1011
+				TXN_ADMIN_URL
1012
+			);
1013
+			$actions['view_txn_lnk'] = '
1014 1014
 			<li>
1015 1015
                 <a class="ee-status-color-' . $this->_transaction_details['status']
1016
-                . ' tiny-text" href="' . $view_txn_lnk_url
1017
-                . '"  title="' . $this->_transaction_details['title_attr'] . '">
1016
+				. ' tiny-text" href="' . $view_txn_lnk_url
1017
+				. '"  title="' . $this->_transaction_details['title_attr'] . '">
1018 1018
                     <div class="dashicons dashicons-cart"></div>
1019 1019
                 </a>
1020 1020
 			</li>';
1021
-        }
1022
-
1023
-        // only show invoice link if message type is active.
1024
-        if (
1025
-            $attendee instanceof EE_Attendee
1026
-            && $item->is_primary_registrant()
1027
-            && EEH_MSG_Template::is_mt_active('invoice')
1028
-        ) {
1029
-            $actions['dl_invoice_lnk'] = '
1021
+		}
1022
+
1023
+		// only show invoice link if message type is active.
1024
+		if (
1025
+			$attendee instanceof EE_Attendee
1026
+			&& $item->is_primary_registrant()
1027
+			&& EEH_MSG_Template::is_mt_active('invoice')
1028
+		) {
1029
+			$actions['dl_invoice_lnk'] = '
1030 1030
             <li>
1031 1031
                 <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1032
-                . '" target="_blank" href="' . $item->invoice_url() . '" class="tiny-text">
1032
+				. '" target="_blank" href="' . $item->invoice_url() . '" class="tiny-text">
1033 1033
                     <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1034 1034
                 </a>
1035 1035
             </li>';
1036
-        }
1036
+		}
1037 1037
 
1038
-        // message list table link (filtered by REG_ID
1039
-        if (
1040
-            EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')
1041
-        ) {
1042
-            $actions['filtered_messages_link'] = '
1038
+		// message list table link (filtered by REG_ID
1039
+		if (
1040
+			EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')
1041
+		) {
1042
+			$actions['filtered_messages_link'] = '
1043 1043
             <li>
1044 1044
                 ' . EEH_MSG_Template::get_message_action_link(
1045
-                'see_notifications_for',
1046
-                null,
1047
-                ['_REG_ID' => $item->ID()]
1048
-            ) . '
1045
+				'see_notifications_for',
1046
+				null,
1047
+				['_REG_ID' => $item->ID()]
1048
+			) . '
1049 1049
             </li>';
1050
-        }
1050
+		}
1051 1051
 
1052
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1053
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1054
-    }
1052
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1053
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1054
+	}
1055 1055
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
     public function __construct(Registrations_Admin_Page $admin_page)
49 49
     {
50 50
         $req_data = $admin_page->get_request_data();
51
-        if (! empty($req_data['event_id'])) {
51
+        if ( ! empty($req_data['event_id'])) {
52 52
             $extra_query_args = [];
53 53
             foreach ($admin_page->get_views() as $view_details) {
54
-                $extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
54
+                $extra_query_args[$view_details['slug']] = ['event_id' => $req_data['event_id']];
55 55
             }
56 56
             $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57 57
         }
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
             'ajax'     => true,
84 84
             'screen'   => $this->_admin_page->get_current_screen()->id,
85 85
         ];
86
-        $ID_column_name      = esc_html__('ID', 'event_espresso');
86
+        $ID_column_name = esc_html__('ID', 'event_espresso');
87 87
         $ID_column_name      .= ' : <span class="show-on-mobile-view-only" style="float:none">';
88 88
         $ID_column_name      .= esc_html__('Registrant Name', 'event_espresso');
89 89
         $ID_column_name      .= '</span> ';
90
-        $req_data            = $this->_admin_page->get_request_data();
90
+        $req_data = $this->_admin_page->get_request_data();
91 91
         if (isset($req_data['event_id'])) {
92
-            $this->_columns        = [
92
+            $this->_columns = [
93 93
                 'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
94 94
                 '_REG_ID'          => $ID_column_name,
95 95
                 'ATT_fname'        => esc_html__('Name', 'event_espresso'),
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
                 ],
112 112
             ];
113 113
         } else {
114
-            $this->_columns        = [
114
+            $this->_columns = [
115 115
                 'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
116 116
                 '_REG_ID'          => $ID_column_name,
117 117
                 'ATT_fname'        => esc_html__('Name', 'event_espresso'),
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         }
134 134
         $this->_primary_column   = '_REG_ID';
135 135
         $this->_sortable_columns = [
136
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
136
+            '_REG_date'     => ['_REG_date' => true], // true means its already sorted
137 137
             /**
138 138
              * Allows users to change the default sort if they wish.
139 139
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             'DTT_EVT_start' => ['DTT_EVT_start' => false],
151 151
             '_REG_ID'       => ['_REG_ID' => false],
152 152
         ];
153
-        $this->_hidden_columns   = [];
153
+        $this->_hidden_columns = [];
154 154
     }
155 155
 
156 156
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     {
166 166
         $class = parent::_get_row_class($item);
167 167
         // add status class
168
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
168
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
169 169
         if ($this->_has_checkbox_column) {
170 170
             $class .= ' has-checkbox-column';
171 171
         }
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
         $this_month_r    = date('m', current_time('timestamp'));
340 340
         $days_this_month = date('t', current_time('timestamp'));
341 341
         // setup date query.
342
-        $beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
342
+        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
343 343
             'REG_date',
344
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
344
+            $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
345 345
             'Y-m-d H:i:s'
346 346
         );
347
-        $end_string         = EEM_Registration::instance()->convert_datetime_for_query(
347
+        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
348 348
             'REG_date',
349
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
349
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
350 350
             'Y-m-d H:i:s'
351 351
         );
352 352
         $_where['REG_date'] = [
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
                 $end_string,
357 357
             ],
358 358
         ];
359
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
359
+        $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
360 360
         return EEM_Registration::instance()->count([$_where]);
361 361
     }
362 362
 
@@ -384,17 +384,17 @@  discard block
 block discarded – undo
384 384
             [
385 385
                 EEM_Registration::instance()->convert_datetime_for_query(
386 386
                     'REG_date',
387
-                    $current_date . $time_start,
387
+                    $current_date.$time_start,
388 388
                     'Y-m-d H:i:s'
389 389
                 ),
390 390
                 EEM_Registration::instance()->convert_datetime_for_query(
391 391
                     'REG_date',
392
-                    $current_date . $time_end,
392
+                    $current_date.$time_end,
393 393
                     'Y-m-d H:i:s'
394 394
                 ),
395 395
             ],
396 396
         ];
397
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
397
+        $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
398 398
         return EEM_Registration::instance()->count([$_where]);
399 399
     }
400 400
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
             ],
478 478
             TXN_ADMIN_URL
479 479
         );
480
-        $view_link    = EE_Registry::instance()->CAP->current_user_can(
480
+        $view_link = EE_Registry::instance()->CAP->current_user_can(
481 481
             'ee_read_transaction',
482 482
             'espresso_transactions_view_transaction'
483 483
         )
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
               . $item->get_i18n_datetime('REG_date')
492 492
               . '</a>'
493 493
             : $item->get_i18n_datetime('REG_date');
494
-        $view_link    .= '<br><span class="ee-status-text-small">'
494
+        $view_link .= '<br><span class="ee-status-text-small">'
495 495
                          . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
496 496
                          . '</span>';
497 497
         return $view_link;
@@ -518,11 +518,11 @@  discard block
 block discarded – undo
518 518
                 ?: esc_html__("No Associated Event", 'event_espresso');
519 519
         $event_name = wp_trim_words($event_name, 30, '...');
520 520
         if ($EVT_ID) {
521
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
521
+            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
522 522
                 ['action' => 'edit', 'post' => $EVT_ID],
523 523
                 EVENTS_ADMIN_URL
524 524
             );
525
-            $edit_event              =
525
+            $edit_event =
526 526
                 EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
527 527
                     ? '<a class="ee-status-color-'
528 528
                       . $this->_event_details['status']
@@ -535,12 +535,12 @@  discard block
 block discarded – undo
535 535
                       . '</a>'
536 536
                     : $event_name;
537 537
             $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
538
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
538
+            $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="';
539 539
             $actions['event_filter'] .= sprintf(
540 540
                 esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
541 541
                 $event_name
542 542
             );
543
-            $actions['event_filter'] .= '">' . esc_html__('View Registrations', 'event_espresso') . '</a>';
543
+            $actions['event_filter'] .= '">'.esc_html__('View Registrations', 'event_espresso').'</a>';
544 544
         } else {
545 545
             $edit_event              = $event_name;
546 546
             $actions['event_filter'] = '';
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
     {
585 585
         $content       = '<div class="ee-registration-event-datetimes-container">';
586 586
         $expand_toggle = count($datetime_strings) > 1
587
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
587
+            ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso')
588 588
               . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
589 589
             : '';
590 590
         // get first item for initial visibility
591
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
591
+        $content .= '<div class="left">'.array_shift($datetime_strings).'</div>';
592 592
         $content .= $expand_toggle;
593 593
         if ($datetime_strings) {
594 594
             $content .= '<div style="clear:both"></div>';
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
               . $attendee_name
637 637
               . '</a>'
638 638
             : $attendee_name;
639
-        $link          .= $item->count() === 1
639
+        $link .= $item->count() === 1
640 640
             ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>'
641 641
             : '';
642 642
         $t             = $item->get_first_related('Transaction');
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
             ? $t->count_related('Payment')
645 645
             : 0;
646 646
         // append group count to name
647
-        $link .= '&nbsp;' . sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
647
+        $link .= '&nbsp;'.sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
648 648
         // append reg_code
649
-        $link .= '<br>' . sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
649
+        $link .= '<br>'.sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
650 650
         // reg status text for accessibility
651
-        $link   .= '<br><span class="ee-status-text-small">'
651
+        $link .= '<br><span class="ee-status-text-small">'
652 652
                    . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
653 653
                    . '</span>';
654 654
         $action = ['_REG_ID' => $item->ID()];
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
                                 . $trash_lnk_url
676 676
                                 . '" title="'
677 677
                                 . esc_attr__('Trash Registration', 'event_espresso')
678
-                                . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
678
+                                . '">'.esc_html__('Trash', 'event_espresso').'</a>';
679 679
         } elseif ($this->_view === 'trash') {
680 680
             // restore registration link
681 681
             if (
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
                 $actions['restore'] = '<a href="'
694 694
                                       . $restore_lnk_url
695 695
                                       . '" title="'
696
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
697
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
696
+                                      . esc_attr__('Restore Registration', 'event_espresso').'">'
697
+                                      . esc_html__('Restore', 'event_espresso').'</a>';
698 698
             }
699 699
             if (
700 700
                 EE_Registry::instance()->CAP->current_user_can(
@@ -760,10 +760,10 @@  discard block
 block discarded – undo
760 760
         $ticket   = $item->ticket();
761 761
         $req_data = $this->_admin_page->get_request_data();
762 762
         $content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
763
-            ? '<span class="TKT_name">' . $ticket->name() . '</span><br />'
763
+            ? '<span class="TKT_name">'.$ticket->name().'</span><br />'
764 764
             : '';
765 765
         if ($item->final_price() > 0) {
766
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
766
+            $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
767 767
         } else {
768 768
             // free event
769 769
             $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
         $req_data = $this->_admin_page->get_request_data();
787 787
         $content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
788 788
             ? ''
789
-            : '<span class="TKT_name">' . $ticket->name() . '</span><br />';
790
-        $content  .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
789
+            : '<span class="TKT_name">'.$ticket->name().'</span><br />';
790
+        $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
791 791
         return $content;
792 792
     }
793 793
 
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         $payment_method_name = $payment_method instanceof EE_Payment_Method
804 804
             ? $payment_method->admin_name()
805 805
             : esc_html__('Unknown', 'event_espresso');
806
-        $content             = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
806
+        $content             = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>';
807 807
         if ($item->paid() > 0) {
808 808
             $content .= '<br><span class="ee-status-text-small">'
809 809
                         . sprintf(
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
                   . '">'
851 851
                   . $item->transaction()->pretty_total()
852 852
                   . '</a></span>'
853
-                : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
853
+                : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>';
854 854
         } else {
855 855
             return esc_html__("None", "event_espresso");
856 856
         }
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                       . '">'
898 898
                       . $item->transaction()->pretty_paid()
899 899
                       . '</a><span>'
900
-                    : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
900
+                    : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
901 901
             }
902 902
         }
903 903
         return '&nbsp;';
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
             );
939 939
             $actions['view_lnk'] = '
940 940
             <li>
941
-                <a href="' . $view_lnk_url . '" title="'
941
+                <a href="' . $view_lnk_url.'" title="'
942 942
                 . esc_attr__('View Registration Details', 'event_espresso')
943 943
                 . '" class="tiny-text">
944 944
 				    <div class="dashicons dashicons-clipboard"></div>
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
             );
963 963
             $actions['edit_lnk'] = '
964 964
 			<li>
965
-                <a href="' . $edit_lnk_url . '" title="'
965
+                <a href="' . $edit_lnk_url.'" title="'
966 966
                 . esc_attr__('Edit Contact Details', 'event_espresso')
967 967
                 . '" class="tiny-text">
968 968
                     <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
             );
989 989
             $actions['resend_reg_lnk'] = '
990 990
 			<li>
991
-			    <a href="' . $resend_reg_lnk_url . '" title="'
991
+			    <a href="' . $resend_reg_lnk_url.'" title="'
992 992
                 . esc_attr__('Resend Registration Details', 'event_espresso')
993 993
                 . '" class="tiny-text">
994 994
 			        <div class="dashicons dashicons-email-alt"></div>
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
                 $this->_transaction_details['id']
1004 1004
             )
1005 1005
         ) {
1006
-            $view_txn_lnk_url        = EE_Admin_Page::add_query_args_and_nonce(
1006
+            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1007 1007
                 [
1008 1008
                     'action' => 'view_transaction',
1009 1009
                     'TXN_ID' => $this->_transaction_details['id'],
@@ -1013,8 +1013,8 @@  discard block
 block discarded – undo
1013 1013
             $actions['view_txn_lnk'] = '
1014 1014
 			<li>
1015 1015
                 <a class="ee-status-color-' . $this->_transaction_details['status']
1016
-                . ' tiny-text" href="' . $view_txn_lnk_url
1017
-                . '"  title="' . $this->_transaction_details['title_attr'] . '">
1016
+                . ' tiny-text" href="'.$view_txn_lnk_url
1017
+                . '"  title="'.$this->_transaction_details['title_attr'].'">
1018 1018
                     <div class="dashicons dashicons-cart"></div>
1019 1019
                 </a>
1020 1020
 			</li>';
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
             $actions['dl_invoice_lnk'] = '
1030 1030
             <li>
1031 1031
                 <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1032
-                . '" target="_blank" href="' . $item->invoice_url() . '" class="tiny-text">
1032
+                . '" target="_blank" href="'.$item->invoice_url().'" class="tiny-text">
1033 1033
                     <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1034 1034
                 </a>
1035 1035
             </li>';
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
                 'see_notifications_for',
1046 1046
                 null,
1047 1047
                 ['_REG_ID' => $item->ID()]
1048
-            ) . '
1048
+            ).'
1049 1049
             </li>';
1050 1050
         }
1051 1051
 
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 1 patch
Indentation   +554 added lines, -554 removed lines patch added patch discarded remove patch
@@ -12,563 +12,563 @@
 block discarded – undo
12 12
 class EE_Event_Registrations_List_Table extends EE_Admin_List_Table
13 13
 {
14 14
 
15
-    /**
16
-     * This property will hold the related Datetimes on an event IF the event id is included in the request.
17
-     *
18
-     * @var EE_Datetime[]
19
-     */
20
-    protected $_dtts_for_event = array();
21
-
22
-
23
-    /**
24
-     * The event if one is specified in the request
25
-     *
26
-     * @var EE_Event
27
-     */
28
-    protected $_evt = null;
29
-
30
-
31
-    /**
32
-     * The DTT_ID if the current view has a specified datetime.
33
-     *
34
-     * @var int $_cur_dtt_id
35
-     */
36
-    protected $_cur_dtt_id = 0;
37
-
38
-
39
-    /**
40
-     * EE_Event_Registrations_List_Table constructor.
41
-     *
42
-     * @param \Registrations_Admin_Page $admin_page
43
-     */
44
-    public function __construct($admin_page)
45
-    {
46
-        parent::__construct($admin_page);
47
-        $this->_status = $this->_admin_page->get_registration_status_array();
48
-    }
49
-
50
-
51
-    protected function _setup_data()
52
-    {
53
-        $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
-            : $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55
-        $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56
-            $this->_per_page,
57
-            true
58
-        ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59
-    }
60
-
61
-
62
-    protected function _set_properties()
63
-    {
64
-        $return_url = $this->getReturnUrl();
65
-
66
-        $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
67
-        $DTT_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
68
-        $this->_wp_list_args = array(
69
-            'singular' => esc_html__('registrant', 'event_espresso'),
70
-            'plural'   => esc_html__('registrants', 'event_espresso'),
71
-            'ajax'     => true,
72
-            'screen'   => $this->_admin_page->get_current_screen()->id,
73
-        );
74
-        $columns = array();
75
-        // $columns['_Reg_Status'] = '';
76
-        $this->_columns = array(
77
-            '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
78
-            'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
79
-            'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
80
-            'Event'               => esc_html__('Event', 'event_espresso'),
81
-            'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
82
-            '_REG_final_price'    => esc_html__('Price', 'event_espresso'),
83
-            'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
84
-            'TXN_total'           => esc_html__('Total', 'event_espresso'),
85
-        );
86
-        // Add/remove columns when an event has been selected
87
-        if (! empty($evt_id)) {
88
-            // Render a checkbox column
89
-            $columns['cb'] = '<input type="checkbox" />';
90
-            $this->_has_checkbox_column = true;
91
-            // Remove the 'Event' column
92
-            unset($this->_columns['Event']);
93
-        }
94
-        $this->_columns = array_merge($columns, $this->_columns);
95
-        $this->_primary_column = '_REG_att_checked_in';
96
-        if (
97
-            ! empty($evt_id)
98
-            && EE_Registry::instance()->CAP->current_user_can(
99
-                'ee_read_registrations',
100
-                'espresso_registrations_registrations_reports',
101
-                $evt_id
102
-            )
103
-        ) {
104
-            if ($DTT_id) {
105
-                $this->_bottom_buttons = array(
106
-                    'report_datetime' => array(
107
-                        'route'         => 'registrations_report',
108
-                        'extra_request' =>
109
-                            array(
110
-                                'EVT_ID'     => $evt_id,
111
-                                'DTT_ID'     => $DTT_id,
112
-                                'return_url' => $return_url,
113
-                            ),
114
-                    ),
115
-                );
116
-            } else {
117
-                $this->_bottom_buttons = array(
118
-                    'report' => array(
119
-                        'route'         => 'registrations_report',
120
-                        'extra_request' =>
121
-                            array(
122
-                                'EVT_ID'     => $evt_id,
123
-                                'return_url' => $return_url,
124
-                            ),
125
-                    ),
126
-                );
127
-            }
128
-        }
129
-        $this->_sortable_columns = array(
130
-            /**
131
-             * Allows users to change the default sort if they wish.
132
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
133
-             *
134
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
135
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
136
-             * for a specific list table you can use the provided reference to this object instance.
137
-             */
138
-            'ATT_name' => array(
139
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
140
-                true,
141
-                $this,
142
-            )
143
-                ? array('ATT_lname' => true)
144
-                : array('ATT_fname' => true),
145
-            'Event'    => array('Event.EVT_name' => false),
146
-        );
147
-        $this->_hidden_columns = array();
148
-        $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
149
-        $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
150
-    }
151
-
152
-
153
-    /**
154
-     * @param \EE_Registration $item
155
-     * @return string
156
-     */
157
-    protected function _get_row_class($item)
158
-    {
159
-        $class = parent::_get_row_class($item);
160
-        // add status class
161
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
162
-        if ($this->_has_checkbox_column) {
163
-            $class .= ' has-checkbox-column';
164
-        }
165
-        return $class;
166
-    }
167
-
168
-
169
-    /**
170
-     * @return array
171
-     * @throws \EE_Error
172
-     */
173
-    protected function _get_table_filters()
174
-    {
175
-        $filters = $where = array();
176
-        $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
177
-        if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
178
-            // this means we don't have an event so let's setup a filter dropdown for all the events to select
179
-            // note possible capability restrictions
180
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
181
-                $where['status**'] = array('!=', 'private');
182
-            }
183
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
184
-                $where['EVT_wp_user'] = get_current_user_id();
185
-            }
186
-            $events = EEM_Event::instance()->get_all(
187
-                array(
188
-                    $where,
189
-                    'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
190
-                )
191
-            );
192
-            $evts[] = array(
193
-                'id'   => 0,
194
-                'text' => esc_html__('To toggle Check-in status, select an event', 'event_espresso'),
195
-            );
196
-            $checked = 'checked';
197
-            /** @var EE_Event $evt */
198
-            foreach ($events as $evt) {
199
-                // any registrations for this event?
200
-                if (! $evt->get_count_of_all_registrations()) {
201
-                    continue;
202
-                }
203
-                $evts[] = array(
204
-                    'id'    => $evt->ID(),
205
-                    'text'  => apply_filters(
206
-                        'FHEE__EE_Event_Registrations___get_table_filters__event_name',
207
-                        $evt->get('EVT_name'),
208
-                        $evt
209
-                    ),
210
-                    'class' => $evt->is_expired() ? 'ee-expired-event' : '',
211
-                );
212
-                if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
213
-                    $checked = '';
214
-                }
215
-            }
216
-            $event_filter = '<div class="ee-event-filter">';
217
-            $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
218
-            $event_filter .= '<span class="ee-event-filter-toggle">';
219
-            $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
220
-            $event_filter .= esc_html__('Hide Expired Events', 'event_espresso');
221
-            $event_filter .= '</span>';
222
-            $event_filter .= '</div>';
223
-            $filters[] = $event_filter;
224
-        }
225
-        if (! empty($this->_dtts_for_event)) {
226
-            // DTT datetimes filter
227
-            $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
228
-            if (count($this->_dtts_for_event) > 1) {
229
-                $dtts[0] = esc_html__('To toggle check-in status, select a datetime.', 'event_espresso');
230
-                foreach ($this->_dtts_for_event as $dtt) {
231
-                    $datetime_string = $dtt->name();
232
-                    $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
233
-                    $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
234
-                    $dtts[ $dtt->ID() ] = $datetime_string;
235
-                }
236
-                $input = new EE_Select_Input(
237
-                    $dtts,
238
-                    array(
239
-                        'html_name' => 'DTT_ID',
240
-                        'html_id'   => 'DTT_ID',
241
-                        'default'   => $this->_cur_dtt_id,
242
-                    )
243
-                );
244
-                $filters[] = $input->get_html_for_input();
245
-                $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
246
-            }
247
-        }
248
-        return $filters;
249
-    }
250
-
251
-
252
-    protected function _add_view_counts()
253
-    {
254
-        $this->_views['all']['count'] = $this->_get_total_event_attendees();
255
-    }
256
-
257
-
258
-    /**
259
-     * @return int
260
-     * @throws \EE_Error
261
-     */
262
-    protected function _get_total_event_attendees()
263
-    {
264
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
265
-        $DTT_ID = $this->_cur_dtt_id;
266
-        $query_params = array();
267
-        if ($EVT_ID) {
268
-            $query_params[0]['EVT_ID'] = $EVT_ID;
269
-        }
270
-        // if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
271
-        if ($DTT_ID) {
272
-            $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
273
-        }
274
-        $status_ids_array = apply_filters(
275
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
276
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
277
-        );
278
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
279
-        return EEM_Registration::instance()->count($query_params);
280
-    }
281
-
282
-
283
-    /**
284
-     * @param \EE_Registration $item
285
-     * @return string
286
-     */
287
-    public function column__Reg_Status(EE_Registration $item)
288
-    {
289
-        return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
290
-    }
291
-
292
-
293
-    /**
294
-     * @param \EE_Registration $item
295
-     * @return string
296
-     * @throws \EE_Error
297
-     */
298
-    public function column_cb($item)
299
-    {
300
-        return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
301
-    }
302
-
303
-
304
-    /**
305
-     * column_REG_att_checked_in
306
-     *
307
-     * @param EE_Registration $item
308
-     * @return string
309
-     * @throws EE_Error
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
314
-    public function column__REG_att_checked_in(EE_Registration $item)
315
-    {
316
-        $attendee = $item->attendee();
317
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
318
-
319
-        if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
320
-            $latest_related_datetime = $item->get_latest_related_datetime();
321
-            if ($latest_related_datetime instanceof EE_Datetime) {
322
-                $this->_cur_dtt_id = $latest_related_datetime->ID();
323
-            }
324
-        }
325
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
326
-            $item,
327
-            $this->_cur_dtt_id
328
-        );
329
-        $nonce = wp_create_nonce('checkin_nonce');
330
-        $toggle_active = ! empty($this->_cur_dtt_id)
331
-                         && EE_Registry::instance()->CAP->current_user_can(
332
-                             'ee_edit_checkin',
333
-                             'espresso_registrations_toggle_checkin_status',
334
-                             $item->ID()
335
-                         )
336
-            ? ' clickable trigger-checkin'
337
-            : '';
338
-        $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
339
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
340
-               . ' data-_regid="' . $item->ID() . '"'
341
-               . ' data-dttid="' . $this->_cur_dtt_id . '"'
342
-               . ' data-nonce="' . $nonce . '">'
343
-               . '</span>'
344
-               . $mobile_view_content;
345
-    }
346
-
347
-
348
-    /**
349
-     * @param \EE_Registration $item
350
-     * @return mixed|string|void
351
-     * @throws \EE_Error
352
-     */
353
-    public function column_ATT_name(EE_Registration $item)
354
-    {
355
-        $attendee = $item->attendee();
356
-        if (! $attendee instanceof EE_Attendee) {
357
-            return esc_html__('No contact record for this registration.', 'event_espresso');
358
-        }
359
-        // edit attendee link
360
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
361
-            array('action' => 'view_registration', '_REG_ID' => $item->ID()),
362
-            REG_ADMIN_URL
363
-        );
364
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
365
-            'ee_edit_contacts',
366
-            'espresso_registrations_edit_attendee'
367
-        )
368
-            ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
369
-              . $item->attendee()->full_name()
370
-              . '</a>'
371
-            : $item->attendee()->full_name();
372
-        $name_link .= $item->count() === 1
373
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
374
-            : '';
375
-        // add group details
376
-        $name_link .= '&nbsp;' . sprintf(esc_html__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
377
-        // add regcode
378
-        $link = EE_Admin_Page::add_query_args_and_nonce(
379
-            array('action' => 'view_registration', '_REG_ID' => $item->ID()),
380
-            REG_ADMIN_URL
381
-        );
382
-        $name_link .= '<br>';
383
-        $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
384
-            'ee_read_registration',
385
-            'view_registration',
386
-            $item->ID()
387
-        )
388
-            ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
389
-              . $item->reg_code()
390
-              . '</a>'
391
-            : $item->reg_code();
392
-        // status
393
-        $name_link .= '<br><span class="ee-status-text-small">';
394
-        $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
395
-        $name_link .= '</span>';
396
-        $actions = array();
397
-        $DTT_ID = $this->_cur_dtt_id;
398
-        $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
399
-            ? $item->get_latest_related_datetime()
400
-            : null;
401
-        $DTT_ID = $latest_related_datetime instanceof EE_Datetime
402
-            ? $latest_related_datetime->ID()
403
-            : $DTT_ID;
404
-        if (
405
-            ! empty($DTT_ID)
406
-            && EE_Registry::instance()->CAP->current_user_can(
407
-                'ee_read_checkins',
408
-                'espresso_registrations_registration_checkins'
409
-            )
410
-        ) {
411
-            $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
412
-                array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID),
413
-                REG_ADMIN_URL
414
-            );
415
-            // get the timestamps for this registration's checkins, related to the selected datetime
416
-            $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
417
-            if (! empty($timestamps)) {
418
-                // get the last timestamp
419
-                $last_timestamp = end($timestamps);
420
-                // checked in or checked out?
421
-                $checkin_status = $last_timestamp->get('CHK_in')
422
-                    ? esc_html__('Checked In', 'event_espresso')
423
-                    : esc_html__('Checked Out', 'event_espresso');
424
-                // get timestamp string
425
-                $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
426
-                $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="'
427
-                                      . esc_attr__(
428
-                                          'View this registrant\'s check-ins/checkouts for the datetime',
429
-                                          'event_espresso'
430
-                                      ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
431
-            }
432
-        }
433
-        return (! empty($DTT_ID) && ! empty($timestamps))
434
-            ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
435
-            : $name_link;
436
-    }
437
-
438
-
439
-    /**
440
-     * @param \EE_Registration $item
441
-     * @return string
442
-     */
443
-    public function column_ATT_email(EE_Registration $item)
444
-    {
445
-        $attendee = $item->attendee();
446
-        return $attendee instanceof EE_Attendee ? $attendee->email() : '';
447
-    }
448
-
449
-
450
-    /**
451
-     * @param \EE_Registration $item
452
-     * @return bool|string
453
-     * @throws \EE_Error
454
-     */
455
-    public function column_Event(EE_Registration $item)
456
-    {
457
-        try {
458
-            $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
459
-            $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
460
-                array('action' => 'event_registrations', 'event_id' => $event->ID()),
461
-                REG_ADMIN_URL
462
-            );
463
-            $event_label = EE_Registry::instance()->CAP->current_user_can(
464
-                'ee_read_checkins',
465
-                'espresso_registrations_registration_checkins'
466
-            ) ? '<a href="' . $chkin_lnk_url . '" title="'
467
-                . esc_attr__(
468
-                    'View Checkins for this Event',
469
-                    'event_espresso'
470
-                ) . '">' . $event->name() . '</a>' : $event->name();
471
-        } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
472
-            $event_label = esc_html__('Unknown', 'event_espresso');
473
-        }
474
-        return $event_label;
475
-    }
476
-
477
-
478
-    /**
479
-     * @param \EE_Registration $item
480
-     * @return mixed|string|void
481
-     */
482
-    public function column_PRC_name(EE_Registration $item)
483
-    {
484
-        return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : esc_html__("Unknown", "event_espresso");
485
-    }
486
-
487
-
488
-    /**
489
-     * column_REG_final_price
490
-     *
491
-     * @param \EE_Registration $item
492
-     * @return string
493
-     */
494
-    public function column__REG_final_price(EE_Registration $item)
495
-    {
496
-        return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
497
-    }
498
-
499
-
500
-    /**
501
-     * column_TXN_paid
502
-     *
503
-     * @param \EE_Registration $item
504
-     * @return string
505
-     * @throws \EE_Error
506
-     */
507
-    public function column_TXN_paid(EE_Registration $item)
508
-    {
509
-        if ($item->count() === 1) {
510
-            if ($item->transaction()->paid() >= $item->transaction()->total()) {
511
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
512
-            } else {
513
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
514
-                    array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
515
-                    TXN_ADMIN_URL
516
-                );
517
-                return EE_Registry::instance()->CAP->current_user_can(
518
-                    'ee_read_transaction',
519
-                    'espresso_transactions_view_transaction'
520
-                ) ? '
15
+	/**
16
+	 * This property will hold the related Datetimes on an event IF the event id is included in the request.
17
+	 *
18
+	 * @var EE_Datetime[]
19
+	 */
20
+	protected $_dtts_for_event = array();
21
+
22
+
23
+	/**
24
+	 * The event if one is specified in the request
25
+	 *
26
+	 * @var EE_Event
27
+	 */
28
+	protected $_evt = null;
29
+
30
+
31
+	/**
32
+	 * The DTT_ID if the current view has a specified datetime.
33
+	 *
34
+	 * @var int $_cur_dtt_id
35
+	 */
36
+	protected $_cur_dtt_id = 0;
37
+
38
+
39
+	/**
40
+	 * EE_Event_Registrations_List_Table constructor.
41
+	 *
42
+	 * @param \Registrations_Admin_Page $admin_page
43
+	 */
44
+	public function __construct($admin_page)
45
+	{
46
+		parent::__construct($admin_page);
47
+		$this->_status = $this->_admin_page->get_registration_status_array();
48
+	}
49
+
50
+
51
+	protected function _setup_data()
52
+	{
53
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55
+		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56
+			$this->_per_page,
57
+			true
58
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59
+	}
60
+
61
+
62
+	protected function _set_properties()
63
+	{
64
+		$return_url = $this->getReturnUrl();
65
+
66
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
67
+		$DTT_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
68
+		$this->_wp_list_args = array(
69
+			'singular' => esc_html__('registrant', 'event_espresso'),
70
+			'plural'   => esc_html__('registrants', 'event_espresso'),
71
+			'ajax'     => true,
72
+			'screen'   => $this->_admin_page->get_current_screen()->id,
73
+		);
74
+		$columns = array();
75
+		// $columns['_Reg_Status'] = '';
76
+		$this->_columns = array(
77
+			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
78
+			'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
79
+			'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
80
+			'Event'               => esc_html__('Event', 'event_espresso'),
81
+			'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
82
+			'_REG_final_price'    => esc_html__('Price', 'event_espresso'),
83
+			'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
84
+			'TXN_total'           => esc_html__('Total', 'event_espresso'),
85
+		);
86
+		// Add/remove columns when an event has been selected
87
+		if (! empty($evt_id)) {
88
+			// Render a checkbox column
89
+			$columns['cb'] = '<input type="checkbox" />';
90
+			$this->_has_checkbox_column = true;
91
+			// Remove the 'Event' column
92
+			unset($this->_columns['Event']);
93
+		}
94
+		$this->_columns = array_merge($columns, $this->_columns);
95
+		$this->_primary_column = '_REG_att_checked_in';
96
+		if (
97
+			! empty($evt_id)
98
+			&& EE_Registry::instance()->CAP->current_user_can(
99
+				'ee_read_registrations',
100
+				'espresso_registrations_registrations_reports',
101
+				$evt_id
102
+			)
103
+		) {
104
+			if ($DTT_id) {
105
+				$this->_bottom_buttons = array(
106
+					'report_datetime' => array(
107
+						'route'         => 'registrations_report',
108
+						'extra_request' =>
109
+							array(
110
+								'EVT_ID'     => $evt_id,
111
+								'DTT_ID'     => $DTT_id,
112
+								'return_url' => $return_url,
113
+							),
114
+					),
115
+				);
116
+			} else {
117
+				$this->_bottom_buttons = array(
118
+					'report' => array(
119
+						'route'         => 'registrations_report',
120
+						'extra_request' =>
121
+							array(
122
+								'EVT_ID'     => $evt_id,
123
+								'return_url' => $return_url,
124
+							),
125
+					),
126
+				);
127
+			}
128
+		}
129
+		$this->_sortable_columns = array(
130
+			/**
131
+			 * Allows users to change the default sort if they wish.
132
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
133
+			 *
134
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
135
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
136
+			 * for a specific list table you can use the provided reference to this object instance.
137
+			 */
138
+			'ATT_name' => array(
139
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
140
+				true,
141
+				$this,
142
+			)
143
+				? array('ATT_lname' => true)
144
+				: array('ATT_fname' => true),
145
+			'Event'    => array('Event.EVT_name' => false),
146
+		);
147
+		$this->_hidden_columns = array();
148
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
149
+		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
150
+	}
151
+
152
+
153
+	/**
154
+	 * @param \EE_Registration $item
155
+	 * @return string
156
+	 */
157
+	protected function _get_row_class($item)
158
+	{
159
+		$class = parent::_get_row_class($item);
160
+		// add status class
161
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
162
+		if ($this->_has_checkbox_column) {
163
+			$class .= ' has-checkbox-column';
164
+		}
165
+		return $class;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return array
171
+	 * @throws \EE_Error
172
+	 */
173
+	protected function _get_table_filters()
174
+	{
175
+		$filters = $where = array();
176
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
177
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
178
+			// this means we don't have an event so let's setup a filter dropdown for all the events to select
179
+			// note possible capability restrictions
180
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
181
+				$where['status**'] = array('!=', 'private');
182
+			}
183
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
184
+				$where['EVT_wp_user'] = get_current_user_id();
185
+			}
186
+			$events = EEM_Event::instance()->get_all(
187
+				array(
188
+					$where,
189
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
190
+				)
191
+			);
192
+			$evts[] = array(
193
+				'id'   => 0,
194
+				'text' => esc_html__('To toggle Check-in status, select an event', 'event_espresso'),
195
+			);
196
+			$checked = 'checked';
197
+			/** @var EE_Event $evt */
198
+			foreach ($events as $evt) {
199
+				// any registrations for this event?
200
+				if (! $evt->get_count_of_all_registrations()) {
201
+					continue;
202
+				}
203
+				$evts[] = array(
204
+					'id'    => $evt->ID(),
205
+					'text'  => apply_filters(
206
+						'FHEE__EE_Event_Registrations___get_table_filters__event_name',
207
+						$evt->get('EVT_name'),
208
+						$evt
209
+					),
210
+					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
211
+				);
212
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
213
+					$checked = '';
214
+				}
215
+			}
216
+			$event_filter = '<div class="ee-event-filter">';
217
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
218
+			$event_filter .= '<span class="ee-event-filter-toggle">';
219
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
220
+			$event_filter .= esc_html__('Hide Expired Events', 'event_espresso');
221
+			$event_filter .= '</span>';
222
+			$event_filter .= '</div>';
223
+			$filters[] = $event_filter;
224
+		}
225
+		if (! empty($this->_dtts_for_event)) {
226
+			// DTT datetimes filter
227
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
228
+			if (count($this->_dtts_for_event) > 1) {
229
+				$dtts[0] = esc_html__('To toggle check-in status, select a datetime.', 'event_espresso');
230
+				foreach ($this->_dtts_for_event as $dtt) {
231
+					$datetime_string = $dtt->name();
232
+					$datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
233
+					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
234
+					$dtts[ $dtt->ID() ] = $datetime_string;
235
+				}
236
+				$input = new EE_Select_Input(
237
+					$dtts,
238
+					array(
239
+						'html_name' => 'DTT_ID',
240
+						'html_id'   => 'DTT_ID',
241
+						'default'   => $this->_cur_dtt_id,
242
+					)
243
+				);
244
+				$filters[] = $input->get_html_for_input();
245
+				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
246
+			}
247
+		}
248
+		return $filters;
249
+	}
250
+
251
+
252
+	protected function _add_view_counts()
253
+	{
254
+		$this->_views['all']['count'] = $this->_get_total_event_attendees();
255
+	}
256
+
257
+
258
+	/**
259
+	 * @return int
260
+	 * @throws \EE_Error
261
+	 */
262
+	protected function _get_total_event_attendees()
263
+	{
264
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
265
+		$DTT_ID = $this->_cur_dtt_id;
266
+		$query_params = array();
267
+		if ($EVT_ID) {
268
+			$query_params[0]['EVT_ID'] = $EVT_ID;
269
+		}
270
+		// if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
271
+		if ($DTT_ID) {
272
+			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
273
+		}
274
+		$status_ids_array = apply_filters(
275
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
276
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
277
+		);
278
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
279
+		return EEM_Registration::instance()->count($query_params);
280
+	}
281
+
282
+
283
+	/**
284
+	 * @param \EE_Registration $item
285
+	 * @return string
286
+	 */
287
+	public function column__Reg_Status(EE_Registration $item)
288
+	{
289
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param \EE_Registration $item
295
+	 * @return string
296
+	 * @throws \EE_Error
297
+	 */
298
+	public function column_cb($item)
299
+	{
300
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
301
+	}
302
+
303
+
304
+	/**
305
+	 * column_REG_att_checked_in
306
+	 *
307
+	 * @param EE_Registration $item
308
+	 * @return string
309
+	 * @throws EE_Error
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314
+	public function column__REG_att_checked_in(EE_Registration $item)
315
+	{
316
+		$attendee = $item->attendee();
317
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
318
+
319
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
320
+			$latest_related_datetime = $item->get_latest_related_datetime();
321
+			if ($latest_related_datetime instanceof EE_Datetime) {
322
+				$this->_cur_dtt_id = $latest_related_datetime->ID();
323
+			}
324
+		}
325
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
326
+			$item,
327
+			$this->_cur_dtt_id
328
+		);
329
+		$nonce = wp_create_nonce('checkin_nonce');
330
+		$toggle_active = ! empty($this->_cur_dtt_id)
331
+						 && EE_Registry::instance()->CAP->current_user_can(
332
+							 'ee_edit_checkin',
333
+							 'espresso_registrations_toggle_checkin_status',
334
+							 $item->ID()
335
+						 )
336
+			? ' clickable trigger-checkin'
337
+			: '';
338
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
339
+		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
340
+			   . ' data-_regid="' . $item->ID() . '"'
341
+			   . ' data-dttid="' . $this->_cur_dtt_id . '"'
342
+			   . ' data-nonce="' . $nonce . '">'
343
+			   . '</span>'
344
+			   . $mobile_view_content;
345
+	}
346
+
347
+
348
+	/**
349
+	 * @param \EE_Registration $item
350
+	 * @return mixed|string|void
351
+	 * @throws \EE_Error
352
+	 */
353
+	public function column_ATT_name(EE_Registration $item)
354
+	{
355
+		$attendee = $item->attendee();
356
+		if (! $attendee instanceof EE_Attendee) {
357
+			return esc_html__('No contact record for this registration.', 'event_espresso');
358
+		}
359
+		// edit attendee link
360
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
361
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
362
+			REG_ADMIN_URL
363
+		);
364
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
365
+			'ee_edit_contacts',
366
+			'espresso_registrations_edit_attendee'
367
+		)
368
+			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
369
+			  . $item->attendee()->full_name()
370
+			  . '</a>'
371
+			: $item->attendee()->full_name();
372
+		$name_link .= $item->count() === 1
373
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
374
+			: '';
375
+		// add group details
376
+		$name_link .= '&nbsp;' . sprintf(esc_html__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
377
+		// add regcode
378
+		$link = EE_Admin_Page::add_query_args_and_nonce(
379
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
380
+			REG_ADMIN_URL
381
+		);
382
+		$name_link .= '<br>';
383
+		$name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
384
+			'ee_read_registration',
385
+			'view_registration',
386
+			$item->ID()
387
+		)
388
+			? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
389
+			  . $item->reg_code()
390
+			  . '</a>'
391
+			: $item->reg_code();
392
+		// status
393
+		$name_link .= '<br><span class="ee-status-text-small">';
394
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
395
+		$name_link .= '</span>';
396
+		$actions = array();
397
+		$DTT_ID = $this->_cur_dtt_id;
398
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
399
+			? $item->get_latest_related_datetime()
400
+			: null;
401
+		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
402
+			? $latest_related_datetime->ID()
403
+			: $DTT_ID;
404
+		if (
405
+			! empty($DTT_ID)
406
+			&& EE_Registry::instance()->CAP->current_user_can(
407
+				'ee_read_checkins',
408
+				'espresso_registrations_registration_checkins'
409
+			)
410
+		) {
411
+			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
412
+				array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID),
413
+				REG_ADMIN_URL
414
+			);
415
+			// get the timestamps for this registration's checkins, related to the selected datetime
416
+			$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
417
+			if (! empty($timestamps)) {
418
+				// get the last timestamp
419
+				$last_timestamp = end($timestamps);
420
+				// checked in or checked out?
421
+				$checkin_status = $last_timestamp->get('CHK_in')
422
+					? esc_html__('Checked In', 'event_espresso')
423
+					: esc_html__('Checked Out', 'event_espresso');
424
+				// get timestamp string
425
+				$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
426
+				$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="'
427
+									  . esc_attr__(
428
+										  'View this registrant\'s check-ins/checkouts for the datetime',
429
+										  'event_espresso'
430
+									  ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
431
+			}
432
+		}
433
+		return (! empty($DTT_ID) && ! empty($timestamps))
434
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
435
+			: $name_link;
436
+	}
437
+
438
+
439
+	/**
440
+	 * @param \EE_Registration $item
441
+	 * @return string
442
+	 */
443
+	public function column_ATT_email(EE_Registration $item)
444
+	{
445
+		$attendee = $item->attendee();
446
+		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
447
+	}
448
+
449
+
450
+	/**
451
+	 * @param \EE_Registration $item
452
+	 * @return bool|string
453
+	 * @throws \EE_Error
454
+	 */
455
+	public function column_Event(EE_Registration $item)
456
+	{
457
+		try {
458
+			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
459
+			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
460
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
461
+				REG_ADMIN_URL
462
+			);
463
+			$event_label = EE_Registry::instance()->CAP->current_user_can(
464
+				'ee_read_checkins',
465
+				'espresso_registrations_registration_checkins'
466
+			) ? '<a href="' . $chkin_lnk_url . '" title="'
467
+				. esc_attr__(
468
+					'View Checkins for this Event',
469
+					'event_espresso'
470
+				) . '">' . $event->name() . '</a>' : $event->name();
471
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
472
+			$event_label = esc_html__('Unknown', 'event_espresso');
473
+		}
474
+		return $event_label;
475
+	}
476
+
477
+
478
+	/**
479
+	 * @param \EE_Registration $item
480
+	 * @return mixed|string|void
481
+	 */
482
+	public function column_PRC_name(EE_Registration $item)
483
+	{
484
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : esc_html__("Unknown", "event_espresso");
485
+	}
486
+
487
+
488
+	/**
489
+	 * column_REG_final_price
490
+	 *
491
+	 * @param \EE_Registration $item
492
+	 * @return string
493
+	 */
494
+	public function column__REG_final_price(EE_Registration $item)
495
+	{
496
+		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
497
+	}
498
+
499
+
500
+	/**
501
+	 * column_TXN_paid
502
+	 *
503
+	 * @param \EE_Registration $item
504
+	 * @return string
505
+	 * @throws \EE_Error
506
+	 */
507
+	public function column_TXN_paid(EE_Registration $item)
508
+	{
509
+		if ($item->count() === 1) {
510
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
511
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
512
+			} else {
513
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
514
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
515
+					TXN_ADMIN_URL
516
+				);
517
+				return EE_Registry::instance()->CAP->current_user_can(
518
+					'ee_read_transaction',
519
+					'espresso_transactions_view_transaction'
520
+				) ? '
521 521
 				<span class="reg-pad-rght">
522 522
 					<a class="status-'
523
-                    . $item->transaction()->status_ID()
524
-                    . '" href="'
525
-                    . $view_txn_lnk_url
526
-                    . '"  title="'
527
-                    . esc_attr__('View Transaction', 'event_espresso')
528
-                    . '">
523
+					. $item->transaction()->status_ID()
524
+					. '" href="'
525
+					. $view_txn_lnk_url
526
+					. '"  title="'
527
+					. esc_attr__('View Transaction', 'event_espresso')
528
+					. '">
529 529
 						'
530
-                    . $item->transaction()->pretty_paid()
531
-                    . '
530
+					. $item->transaction()->pretty_paid()
531
+					. '
532 532
 					</a>
533 533
 				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
534
-            }
535
-        } else {
536
-            return '<span class="reg-pad-rght"></span>';
537
-        }
538
-    }
539
-
540
-
541
-    /**
542
-     *        column_TXN_total
543
-     *
544
-     * @param \EE_Registration $item
545
-     * @return string
546
-     * @throws \EE_Error
547
-     */
548
-    public function column_TXN_total(EE_Registration $item)
549
-    {
550
-        $txn = $item->transaction();
551
-        $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
552
-        if ($item->get('REG_count') === 1) {
553
-            $line_total_obj = $txn->total_line_item();
554
-            $txn_total = $line_total_obj instanceof EE_Line_Item
555
-                ? $line_total_obj->get_pretty('LIN_total')
556
-                : esc_html__(
557
-                    'View Transaction',
558
-                    'event_espresso'
559
-                );
560
-            return EE_Registry::instance()->CAP->current_user_can(
561
-                'ee_read_transaction',
562
-                'espresso_transactions_view_transaction'
563
-            ) ? '<a href="'
564
-                . $view_txn_url
565
-                . '" title="'
566
-                . esc_attr__('View Transaction', 'event_espresso')
567
-                . '"><span class="reg-pad-rght">'
568
-                . $txn_total
569
-                . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
570
-        } else {
571
-            return '<span class="reg-pad-rght"></span>';
572
-        }
573
-    }
534
+			}
535
+		} else {
536
+			return '<span class="reg-pad-rght"></span>';
537
+		}
538
+	}
539
+
540
+
541
+	/**
542
+	 *        column_TXN_total
543
+	 *
544
+	 * @param \EE_Registration $item
545
+	 * @return string
546
+	 * @throws \EE_Error
547
+	 */
548
+	public function column_TXN_total(EE_Registration $item)
549
+	{
550
+		$txn = $item->transaction();
551
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
552
+		if ($item->get('REG_count') === 1) {
553
+			$line_total_obj = $txn->total_line_item();
554
+			$txn_total = $line_total_obj instanceof EE_Line_Item
555
+				? $line_total_obj->get_pretty('LIN_total')
556
+				: esc_html__(
557
+					'View Transaction',
558
+					'event_espresso'
559
+				);
560
+			return EE_Registry::instance()->CAP->current_user_can(
561
+				'ee_read_transaction',
562
+				'espresso_transactions_view_transaction'
563
+			) ? '<a href="'
564
+				. $view_txn_url
565
+				. '" title="'
566
+				. esc_attr__('View Transaction', 'event_espresso')
567
+				. '"><span class="reg-pad-rght">'
568
+				. $txn_total
569
+				. '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
570
+		} else {
571
+			return '<span class="reg-pad-rght"></span>';
572
+		}
573
+	}
574 574
 }
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/RegistrationsReport.php 2 patches
Indentation   +635 added lines, -635 removed lines patch added patch discarded remove patch
@@ -33,654 +33,654 @@
 block discarded – undo
33 33
  */
34 34
 class RegistrationsReport extends JobHandlerFile
35 35
 {
36
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
37
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
38
-    /**
39
-     * Performs any necessary setup for starting the job. This is also a good
40
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
41
-     * when continue_job will be called
42
-     *
43
-     * @param JobParameters $job_parameters
44
-     * @throws BatchRequestException
45
-     * @return JobStepResponse
46
-     */
47
-    public function create_job(JobParameters $job_parameters)
48
-    {
49
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
50
-        $DTT_id = intval($job_parameters->request_datum('DTT_ID', '0'));
51
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
52
-            throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso'));
53
-        }
54
-        $filepath = $this->create_file_from_job_with_name(
55
-            $job_parameters->job_id(),
56
-            $this->get_filename($event_id)
57
-        );
58
-        $job_parameters->add_extra_data('filepath', $filepath);
59
-        $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
-            array(
61
-                'OR'                 => array(
62
-                    // don't include registrations from failed or abandoned transactions...
63
-                    'Transaction.STS_ID' => array(
64
-                        'NOT IN',
65
-                        array(
66
-                            EEM_Transaction::failed_status_code,
67
-                            EEM_Transaction::abandoned_status_code,
68
-                        ),
69
-                    ),
70
-                    // unless the registration is approved, in which case include it regardless of transaction status
71
-                    'STS_ID'             => \EEM_Registration::status_id_approved,
72
-                ),
73
-                'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
-            ),
75
-            'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
-            'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
-            'caps'       => \EEM_Base::caps_read_admin,
78
-        ), $event_id);
79
-        if ($event_id) {
80
-            $query_params[0]['EVT_ID'] = $event_id;
81
-        } else {
82
-            $query_params['force_join'][] = 'Event';
83
-        }
84
-        if (! isset($query_params['force_join'])) {
85
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
86
-        }
87
-        $job_parameters->add_extra_data('query_params', $query_params);
88
-        $question_labels = $this->_get_question_labels($query_params);
89
-        $job_parameters->add_extra_data('question_labels', $question_labels);
90
-        $job_parameters->set_job_size(
91
-            \EEM_Registration::instance()->count(
92
-                array_diff_key(
93
-                    $query_params,
94
-                    array_flip(
95
-                        array('limit')
96
-                    )
97
-                )
98
-            )
99
-        );
100
-        // we should also set the header columns
101
-        $csv_data_for_row = $this->get_csv_data_for(
102
-            $event_id,
103
-            0,
104
-            1,
105
-            $job_parameters->extra_datum('question_labels'),
106
-            $job_parameters->extra_datum('query_params'),
107
-            $DTT_id
108
-        );
109
-        EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
-        // if we actually processed a row there, record it
111
-        if ($job_parameters->job_size()) {
112
-            $job_parameters->mark_processed(1);
113
-        }
114
-        return new JobStepResponse(
115
-            $job_parameters,
116
-            esc_html__('Registrations report started successfully...', 'event_espresso')
117
-        );
118
-    }
36
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
37
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
38
+	/**
39
+	 * Performs any necessary setup for starting the job. This is also a good
40
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
41
+	 * when continue_job will be called
42
+	 *
43
+	 * @param JobParameters $job_parameters
44
+	 * @throws BatchRequestException
45
+	 * @return JobStepResponse
46
+	 */
47
+	public function create_job(JobParameters $job_parameters)
48
+	{
49
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
50
+		$DTT_id = intval($job_parameters->request_datum('DTT_ID', '0'));
51
+		if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
52
+			throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso'));
53
+		}
54
+		$filepath = $this->create_file_from_job_with_name(
55
+			$job_parameters->job_id(),
56
+			$this->get_filename($event_id)
57
+		);
58
+		$job_parameters->add_extra_data('filepath', $filepath);
59
+		$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
+			array(
61
+				'OR'                 => array(
62
+					// don't include registrations from failed or abandoned transactions...
63
+					'Transaction.STS_ID' => array(
64
+						'NOT IN',
65
+						array(
66
+							EEM_Transaction::failed_status_code,
67
+							EEM_Transaction::abandoned_status_code,
68
+						),
69
+					),
70
+					// unless the registration is approved, in which case include it regardless of transaction status
71
+					'STS_ID'             => \EEM_Registration::status_id_approved,
72
+				),
73
+				'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
+			),
75
+			'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
+			'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
+			'caps'       => \EEM_Base::caps_read_admin,
78
+		), $event_id);
79
+		if ($event_id) {
80
+			$query_params[0]['EVT_ID'] = $event_id;
81
+		} else {
82
+			$query_params['force_join'][] = 'Event';
83
+		}
84
+		if (! isset($query_params['force_join'])) {
85
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
86
+		}
87
+		$job_parameters->add_extra_data('query_params', $query_params);
88
+		$question_labels = $this->_get_question_labels($query_params);
89
+		$job_parameters->add_extra_data('question_labels', $question_labels);
90
+		$job_parameters->set_job_size(
91
+			\EEM_Registration::instance()->count(
92
+				array_diff_key(
93
+					$query_params,
94
+					array_flip(
95
+						array('limit')
96
+					)
97
+				)
98
+			)
99
+		);
100
+		// we should also set the header columns
101
+		$csv_data_for_row = $this->get_csv_data_for(
102
+			$event_id,
103
+			0,
104
+			1,
105
+			$job_parameters->extra_datum('question_labels'),
106
+			$job_parameters->extra_datum('query_params'),
107
+			$DTT_id
108
+		);
109
+		EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
+		// if we actually processed a row there, record it
111
+		if ($job_parameters->job_size()) {
112
+			$job_parameters->mark_processed(1);
113
+		}
114
+		return new JobStepResponse(
115
+			$job_parameters,
116
+			esc_html__('Registrations report started successfully...', 'event_espresso')
117
+		);
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * Gets the filename
123
-     *
124
-     * @return string
125
-     */
126
-    protected function get_filename()
127
-    {
128
-        return apply_filters(
129
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
-            sprintf(
131
-                "event-espresso-registrations-%s.csv",
132
-                str_replace(array(':', ' '), '-', current_time('mysql'))
133
-            )
134
-        );
135
-    }
121
+	/**
122
+	 * Gets the filename
123
+	 *
124
+	 * @return string
125
+	 */
126
+	protected function get_filename()
127
+	{
128
+		return apply_filters(
129
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
+			sprintf(
131
+				"event-espresso-registrations-%s.csv",
132
+				str_replace(array(':', ' '), '-', current_time('mysql'))
133
+			)
134
+		);
135
+	}
136 136
 
137 137
 
138
-    /**
139
-     * Gets the questions which are to be used for this report, so they
140
-     * can be remembered for later
141
-     *
142
-     * @param array $registration_query_params
143
-     * @return array question admin labels to be used for this report
144
-     */
145
-    protected function _get_question_labels($registration_query_params)
146
-    {
147
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
-        $question_query_params = array();
149
-        if ($where !== null) {
150
-            $question_query_params = array(
151
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
-            );
153
-        }
154
-        // Make sure it's not a system question
155
-        $question_query_params[0]['OR*not-system-questions'] = [
156
-            'QST_system' => '',
157
-            'QST_system*null' => ['IS_NULL']
158
-        ];
159
-        if (
160
-            apply_filters(
161
-                'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
162
-                false,
163
-                $registration_query_params
164
-            )
165
-        ) {
166
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
167
-        }
168
-        $question_query_params['group_by'] = array('QST_ID');
169
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
170
-    }
138
+	/**
139
+	 * Gets the questions which are to be used for this report, so they
140
+	 * can be remembered for later
141
+	 *
142
+	 * @param array $registration_query_params
143
+	 * @return array question admin labels to be used for this report
144
+	 */
145
+	protected function _get_question_labels($registration_query_params)
146
+	{
147
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
+		$question_query_params = array();
149
+		if ($where !== null) {
150
+			$question_query_params = array(
151
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
+			);
153
+		}
154
+		// Make sure it's not a system question
155
+		$question_query_params[0]['OR*not-system-questions'] = [
156
+			'QST_system' => '',
157
+			'QST_system*null' => ['IS_NULL']
158
+		];
159
+		if (
160
+			apply_filters(
161
+				'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
162
+				false,
163
+				$registration_query_params
164
+			)
165
+		) {
166
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
167
+		}
168
+		$question_query_params['group_by'] = array('QST_ID');
169
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * Takes where params meant for registrations and changes them to work for questions
175
-     *
176
-     * @param array $reg_where_params
177
-     * @return array
178
-     */
179
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
180
-    {
181
-        $question_where_params = array();
182
-        foreach ($reg_where_params as $key => $val) {
183
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
185
-            } else {
186
-                // it's a normal where condition
187
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
188
-            }
189
-        }
190
-        return $question_where_params;
191
-    }
173
+	/**
174
+	 * Takes where params meant for registrations and changes them to work for questions
175
+	 *
176
+	 * @param array $reg_where_params
177
+	 * @return array
178
+	 */
179
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
180
+	{
181
+		$question_where_params = array();
182
+		foreach ($reg_where_params as $key => $val) {
183
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
+				$question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
185
+			} else {
186
+				// it's a normal where condition
187
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
188
+			}
189
+		}
190
+		return $question_where_params;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * Performs another step of the job
196
-     *
197
-     * @param JobParameters $job_parameters
198
-     * @param int           $batch_size
199
-     * @return JobStepResponse
200
-     * @throws \EE_Error
201
-     */
202
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
203
-    {
204
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
205
-            $csv_data = $this->get_csv_data_for(
206
-                $job_parameters->request_datum('EVT_ID', '0'),
207
-                $job_parameters->units_processed(),
208
-                $batch_size,
209
-                $job_parameters->extra_datum('question_labels'),
210
-                $job_parameters->extra_datum('query_params'),
211
-                $job_parameters->request_datum('DTT_ID', '0')
212
-            );
213
-            EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
214
-            $units_processed = count($csv_data);
215
-        } else {
216
-            $csv_data = array();
217
-            $units_processed = 0;
218
-        }
219
-        $job_parameters->mark_processed($units_processed);
220
-        $extra_response_data = array(
221
-            'file_url' => '',
222
-        );
223
-        if ($units_processed < $batch_size) {
224
-            $job_parameters->set_status(JobParameters::status_complete);
225
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
226
-        }
194
+	/**
195
+	 * Performs another step of the job
196
+	 *
197
+	 * @param JobParameters $job_parameters
198
+	 * @param int           $batch_size
199
+	 * @return JobStepResponse
200
+	 * @throws \EE_Error
201
+	 */
202
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
203
+	{
204
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
205
+			$csv_data = $this->get_csv_data_for(
206
+				$job_parameters->request_datum('EVT_ID', '0'),
207
+				$job_parameters->units_processed(),
208
+				$batch_size,
209
+				$job_parameters->extra_datum('question_labels'),
210
+				$job_parameters->extra_datum('query_params'),
211
+				$job_parameters->request_datum('DTT_ID', '0')
212
+			);
213
+			EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
214
+			$units_processed = count($csv_data);
215
+		} else {
216
+			$csv_data = array();
217
+			$units_processed = 0;
218
+		}
219
+		$job_parameters->mark_processed($units_processed);
220
+		$extra_response_data = array(
221
+			'file_url' => '',
222
+		);
223
+		if ($units_processed < $batch_size) {
224
+			$job_parameters->set_status(JobParameters::status_complete);
225
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
226
+		}
227 227
 
228
-        return new JobStepResponse(
229
-            $job_parameters,
230
-            sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
231
-            $extra_response_data
232
-        );
233
-    }
228
+		return new JobStepResponse(
229
+			$job_parameters,
230
+			sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
231
+			$extra_response_data
232
+		);
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * Gets the csv data for a batch of registrations
238
-     *
239
-     * @param int|null $event_id
240
-     * @param int $offset
241
-     * @param int $limit
242
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
243
-     * @param array $query_params for using where querying the model
244
-     * @param int|null $DTT_id
245
-     * @return array top-level keys are numeric, next-level keys are column headers
246
-     * @throws \EE_Error
247
-     * @throws \ReflectionException
248
-     */
249
-    public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params, $DTT_id = null)
250
-    {
251
-        $reg_fields_to_include = [
252
-            'REG_ID',
253
-            'TXN_ID',
254
-            'ATT_ID',
255
-            'REG_date',
256
-            'REG_code',
257
-            'REG_count',
258
-            'REG_final_price',
259
-        ];
260
-        $att_fields_to_include = [
261
-            'ATT_fname',
262
-            'ATT_lname',
263
-            'ATT_email',
264
-            'ATT_address',
265
-            'ATT_address2',
266
-            'ATT_city',
267
-            'STA_ID',
268
-            'CNT_ISO',
269
-            'ATT_zip',
270
-            'ATT_phone',
271
-        ];
272
-        $registrations_csv_ready_array = [];
273
-        $reg_model = EE_Registry::instance()->load_model('Registration');
274
-        $query_params['limit'] = [$offset, $limit];
275
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
276
-        foreach ($registration_rows as $reg_row) {
277
-            if (!is_array($reg_row)) {
278
-                continue;
279
-            }
280
-            $reg_csv_array = [];
281
-            if (! $event_id) {
282
-                // get the event's name and Id
283
-                $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf(
284
-                    /* translators: 1: event name, 2: event ID */
285
-                    esc_html__('%1$s (%2$s)', 'event_espresso'),
286
-                    EEH_Export::prepare_value_from_db_for_display(
287
-                        EEM_Event::instance(),
288
-                        'EVT_name',
289
-                        $reg_row['Event_CPT.post_title']
290
-                    ),
291
-                    $reg_row['Event_CPT.ID']
292
-                );
293
-            }
294
-            $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
295
-            /*@var $reg_row EE_Registration */
296
-            foreach ($reg_fields_to_include as $field_name) {
297
-                $field = $reg_model->field_settings_for($field_name);
298
-                if ($field_name == 'REG_final_price') {
299
-                    $value = EEH_Export::prepare_value_from_db_for_display(
300
-                        $reg_model,
301
-                        $field_name,
302
-                        $reg_row['Registration.REG_final_price'],
303
-                        'localized_float'
304
-                    );
305
-                } elseif ($field_name == 'REG_count') {
306
-                    $value = sprintf(
307
-                        /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
308
-                        esc_html__('%1$s of %2$s', 'event_espresso'),
309
-                        EEH_Export::prepare_value_from_db_for_display(
310
-                            $reg_model,
311
-                            'REG_count',
312
-                            $reg_row['Registration.REG_count']
313
-                        ),
314
-                        EEH_Export::prepare_value_from_db_for_display(
315
-                            $reg_model,
316
-                            'REG_group_size',
317
-                            $reg_row['Registration.REG_group_size']
318
-                        )
319
-                    );
320
-                } elseif ($field_name == 'REG_date') {
321
-                    $value = EEH_Export::prepare_value_from_db_for_display(
322
-                        $reg_model,
323
-                        $field_name,
324
-                        $reg_row['Registration.REG_date'],
325
-                        'no_html'
326
-                    );
327
-                } else {
328
-                    $value = EEH_Export::prepare_value_from_db_for_display(
329
-                        $reg_model,
330
-                        $field_name,
331
-                        $reg_row[ $field->get_qualified_column() ]
332
-                    );
333
-                }
334
-                $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
335
-                if ($field_name == 'REG_final_price') {
336
-                    // add a column named Currency after the final price
337
-                    $reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
338
-                }
339
-            }
340
-            // get pretty status
341
-            $stati = EEM_Status::instance()->localized_status(
342
-                [
343
-                    $reg_row['Registration.STS_ID']     => esc_html__('unknown', 'event_espresso'),
344
-                    $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'),
345
-                ],
346
-                false,
347
-                'sentence'
348
-            );
349
-            $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
350
-            // get pretty transaction status
351
-            $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
352
-            $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
353
-                ? EEH_Export::prepare_value_from_db_for_display(
354
-                    EEM_Transaction::instance(),
355
-                    'TXN_total',
356
-                    $reg_row['TransactionTable.TXN_total'],
357
-                    'localized_float'
358
-                ) : '0.00';
359
-            $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
360
-                ? EEH_Export::prepare_value_from_db_for_display(
361
-                    EEM_Transaction::instance(),
362
-                    'TXN_paid',
363
-                    $reg_row['TransactionTable.TXN_paid'],
364
-                    'localized_float'
365
-                ) : '0.00';
366
-            $payment_methods = [];
367
-            $gateway_txn_ids_etc = [];
368
-            $payment_times = [];
369
-            if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
370
-                $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
371
-                    [
372
-                        [
373
-                            'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
374
-                            'STS_ID' => EEM_Payment::status_id_approved,
375
-                        ],
376
-                        'force_join' => ['Payment_Method'],
377
-                    ],
378
-                    ARRAY_A,
379
-                    'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
380
-                );
381
-                foreach ($payments_info as $payment_method_and_gateway_txn_id) {
382
-                    $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
383
-                        ? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso');
384
-                    $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
385
-                        ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
386
-                    $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
387
-                        ? $payment_method_and_gateway_txn_id['payment_time'] : '';
388
-                }
389
-            }
390
-            $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
391
-            $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
392
-            $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
393
-                ',',
394
-                $gateway_txn_ids_etc
395
-            );
396
-            // get ticket of registration and its price
397
-            $ticket_model = EE_Registry::instance()->load_model('Ticket');
398
-            if ($reg_row['Ticket.TKT_ID']) {
399
-                $ticket_name = EEH_Export::prepare_value_from_db_for_display(
400
-                    $ticket_model,
401
-                    'TKT_name',
402
-                    $reg_row['Ticket.TKT_name']
403
-                );
404
-                $datetimes_strings = [];
405
-                foreach (
406
-                    EEM_Datetime::instance()->get_all_wpdb_results(
407
-                        [
408
-                            ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']],
409
-                            'order_by' => ['DTT_EVT_start' => 'ASC'],
410
-                            'default_where_conditions' => 'none',
411
-                        ]
412
-                    ) as $datetime
413
-                ) {
414
-                    $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
415
-                        EEM_Datetime::instance(),
416
-                        'DTT_EVT_start',
417
-                        $datetime['Datetime.DTT_EVT_start']
418
-                    );
419
-                }
420
-            } else {
421
-                $ticket_name = esc_html__('Unknown', 'event_espresso');
422
-                $datetimes_strings = [esc_html__('Unknown', 'event_espresso')];
423
-            }
424
-            $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
425
-            $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
426
-            // get datetime(s) of registration
427
-            // add attendee columns
428
-            foreach ($att_fields_to_include as $att_field_name) {
429
-                $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
430
-                if ($reg_row['Attendee_CPT.ID']) {
431
-                    if ($att_field_name == 'STA_ID') {
432
-                        $value = EEM_State::instance()->get_var(
433
-                            [
434
-                                ['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]
435
-                            ],
436
-                            'STA_name'
437
-                        );
438
-                    } elseif ($att_field_name == 'CNT_ISO') {
439
-                        $value = EEM_Country::instance()->get_var(
440
-                            [
441
-                                ['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]
442
-                            ],
443
-                            'CNT_name'
444
-                        );
445
-                    } else {
446
-                        $value = EEH_Export::prepare_value_from_db_for_display(
447
-                            EEM_Attendee::instance(),
448
-                            $att_field_name,
449
-                            $reg_row[ $field_obj->get_qualified_column() ]
450
-                        );
451
-                    }
452
-                } else {
453
-                    $value = '';
454
-                }
455
-                $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
456
-            }
457
-            // make sure each registration has the same questions in the same order
458
-            foreach ($question_labels as $question_label) {
459
-                if (! isset($reg_csv_array[ $question_label ])) {
460
-                    $reg_csv_array[ $question_label ] = null;
461
-                }
462
-            }
463
-            $answers = EEM_Answer::instance()->get_all_wpdb_results([
464
-                ['REG_ID' => $reg_row['Registration.REG_ID']],
465
-                'force_join' => ['Question'],
466
-            ]);
467
-            // now fill out the questions THEY answered
468
-            foreach ($answers as $answer_row) {
469
-                if ($answer_row['Question.QST_system']) {
470
-                    // it's an answer to a system question. That was already displayed as part of the attendee
471
-                    // fields, so don't write it out again thanks.
472
-                    continue;
473
-                }
474
-                if ($answer_row['Question.QST_ID']) {
475
-                    $question_label = EEH_Export::prepare_value_from_db_for_display(
476
-                        EEM_Question::instance(),
477
-                        'QST_admin_label',
478
-                        $answer_row['Question.QST_admin_label']
479
-                    );
480
-                } else {
481
-                    $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
482
-                }
483
-                if (
484
-                    isset($answer_row['Question.QST_type'])
485
-                    && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
486
-                ) {
487
-                    $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
488
-                        $answer_row['Answer.ANS_value']
489
-                    );
490
-                } else {
491
-                    // this isn't for html, so don't show html entities
492
-                    $reg_csv_array[ $question_label ] = html_entity_decode(
493
-                        EEH_Export::prepare_value_from_db_for_display(
494
-                            EEM_Answer::instance(),
495
-                            'ANS_value',
496
-                            $answer_row['Answer.ANS_value']
497
-                        )
498
-                    );
499
-                }
500
-            }
501
-            // Include check-in data for datetime
502
-            if ($event_id && $DTT_id) {
503
-                // get whether or not the user has checked in
504
-                $reg_csv_array[ (string) esc_html__('Datetime Check-ins #', 'event_espresso') ] = $reg_model->count_related(
505
-                    $reg_row['Registration.REG_ID'],
506
-                    'Checkin',
507
-                    [
508
-                        [
509
-                            'DTT_ID' => $DTT_id
510
-                        ]
511
-                    ]
512
-                );
513
-                $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_id);
514
-                $checkin_rows = EEM_Checkin::instance()->get_all_wpdb_results(
515
-                    [
516
-                        [
517
-                            'REG_ID' => $reg_row['Registration.REG_ID'],
518
-                            'DTT_ID' => $datetime->get('DTT_ID'),
519
-                        ],
520
-                    ]
521
-                );
522
-                if (trim($datetime->get('DTT_name'))) {
523
-                    /* translators: 1: datetime name, 2: datetime ID */
524
-                    $datetime_name = sprintf(
525
-                        esc_html__('Check-ins for %1$s - ID: %2$s', 'event_espresso'),
526
-                        esc_html($datetime->get('DTT_name')),
527
-                        esc_html($datetime->get('DTT_ID'))
528
-                    );
529
-                } else {
530
-                    /* translators: %s: datetime ID */
531
-                    $datetime_name = sprintf(
532
-                        esc_html__('ID: %1$s', 'event_espresso'),
533
-                        esc_html($datetime->get('DTT_ID'))
534
-                    );
535
-                }
536
-                $checkins = [];
537
-                foreach ($checkin_rows as $checkin_row) {
538
-                    if ((int) $checkin_row['Checkin.CHK_in'] === 1) {
539
-                        /* translators: 1: check-in status, 2: check-in timestamp */
540
-                        $checkin_value = sprintf(
541
-                            esc_html__('%1$s: %2$s', 'event_espresso'),
542
-                            esc_html__('IN', 'event_espresso'),
543
-                            date('Y-m-d g:i a', strtotime($checkin_row['Checkin.CHK_timestamp']))
544
-                        );
545
-                        $checkins[] = $checkin_value;
546
-                    } elseif ((int) $checkin_row['Checkin.CHK_in'] === 0) {
547
-                        /* translators: 1: check-in status, 2: check-in timestamp */
548
-                        $checkin_value = sprintf(
549
-                            esc_html__('%1$s: %2$s', 'event_espresso'),
550
-                            esc_html__('OUT', 'event_espresso'),
551
-                            date('Y-m-d g:i a', strtotime($checkin_row['Checkin.CHK_timestamp']))
552
-                        );
553
-                        $checkins[] = $checkin_value;
554
-                    }
555
-                }
556
-                $reg_csv_array[ (string) $datetime_name ] = implode(' --- ', $checkins);
557
-            } elseif ($event_id) {
558
-                // get whether or not the user has checked in
559
-                $reg_csv_array[ (string) esc_html__('Event Check-ins #', 'event_espresso') ] = $reg_model->count_related(
560
-                    $reg_row['Registration.REG_ID'],
561
-                    'Checkin'
562
-                );
563
-                $datetimes = EEM_Datetime::instance()->get_all_wpdb_results(
564
-                    [
565
-                        [
566
-                            'Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID'],
567
-                        ],
568
-                        'order_by' => ['DTT_EVT_start' => 'ASC'],
569
-                        'default_where_conditions' => 'none',
570
-                    ]
571
-                );
572
-                foreach ($datetimes as $datetime) {
573
-                    $checkin_row = EEM_Checkin::instance()->get_one(
574
-                        [
575
-                            [
576
-                                'REG_ID' => $reg_row['Registration.REG_ID'],
577
-                                'DTT_ID' => $datetime['Datetime.DTT_ID'],
578
-                            ],
579
-                            'limit' => 1,
580
-                            'order_by' => [
581
-                                'CHK_ID' => 'DESC'
582
-                            ]
583
-                        ]
584
-                    );
585
-                    if (trim($datetime['Datetime.DTT_name'])) {
586
-                        /* translators: 1: datetime name, 2: datetime ID */
587
-                        $datetime_name = sprintf(
588
-                            esc_html__('Check-ins for %1$s - ID: %2$s', 'event_espresso'),
589
-                            esc_html($datetime['Datetime.DTT_name']),
590
-                            esc_html($datetime['Datetime.DTT_ID'])
591
-                        );
592
-                    } else {
593
-                        /* translators: %s: datetime ID */
594
-                        $datetime_name = sprintf(
595
-                            esc_html__('ID: %1$s', 'event_espresso'),
596
-                            esc_html($datetime['Datetime.DTT_ID'])
597
-                        );
598
-                    }
599
-                    $checkin_value = '';
600
-                    if ($checkin_row instanceof EE_Checkin && $checkin_row->get('CHK_in') === true) {
601
-                        /* translators: 1: check-in status, 2: check-in timestamp */
602
-                        $checkin_value = sprintf(
603
-                            esc_html__('%1$s: %2$s', 'event_espresso'),
604
-                            esc_html__('IN', 'event_espresso'),
605
-                            $checkin_row->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a')
606
-                        );
607
-                    } elseif ($checkin_row instanceof EE_Checkin && $checkin_row->get('CHK_in') === false) {
608
-                        /* translators: 1: check-in status, 2: check-in timestamp */
609
-                        $checkin_value = sprintf(
610
-                            esc_html__('%1$s: %2$s', 'event_espresso'),
611
-                            esc_html__('OUT', 'event_espresso'),
612
-                            $checkin_row->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a')
613
-                        );
614
-                    }
615
-                    $reg_csv_array[ (string) $datetime_name ] = $checkin_value;
616
-                }
617
-            }
618
-            /**
619
-             * Filter to change the contents of each row of the registrations report CSV file.
620
-             * This can be used to add or remote columns from the CSV file, or change their values.
621
-             * Note when using: all rows in the CSV should have the same columns.
622
-             * @param array $reg_csv_array keys are the column names, values are their cell values
623
-             * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
624
-             */
625
-            $registrations_csv_ready_array[] = apply_filters(
626
-                'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
627
-                $reg_csv_array,
628
-                $reg_row
629
-            );
630
-        }
631
-        // if we couldn't export anything, we want to at least show the column headers
632
-        if (empty($registrations_csv_ready_array)) {
633
-            $reg_csv_array = [];
634
-            $model_and_fields_to_include = [
635
-                'Registration' => $reg_fields_to_include,
636
-                'Attendee'     => $att_fields_to_include,
637
-            ];
638
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
639
-                $model = EE_Registry::instance()->load_model($model_name);
640
-                foreach ($field_list as $field_name) {
641
-                    $field = $model->field_settings_for($field_name);
642
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
643
-                }
644
-            }
645
-            $registrations_csv_ready_array[] = $reg_csv_array;
646
-        }
647
-        return $registrations_csv_ready_array;
648
-    }
236
+	/**
237
+	 * Gets the csv data for a batch of registrations
238
+	 *
239
+	 * @param int|null $event_id
240
+	 * @param int $offset
241
+	 * @param int $limit
242
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
243
+	 * @param array $query_params for using where querying the model
244
+	 * @param int|null $DTT_id
245
+	 * @return array top-level keys are numeric, next-level keys are column headers
246
+	 * @throws \EE_Error
247
+	 * @throws \ReflectionException
248
+	 */
249
+	public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params, $DTT_id = null)
250
+	{
251
+		$reg_fields_to_include = [
252
+			'REG_ID',
253
+			'TXN_ID',
254
+			'ATT_ID',
255
+			'REG_date',
256
+			'REG_code',
257
+			'REG_count',
258
+			'REG_final_price',
259
+		];
260
+		$att_fields_to_include = [
261
+			'ATT_fname',
262
+			'ATT_lname',
263
+			'ATT_email',
264
+			'ATT_address',
265
+			'ATT_address2',
266
+			'ATT_city',
267
+			'STA_ID',
268
+			'CNT_ISO',
269
+			'ATT_zip',
270
+			'ATT_phone',
271
+		];
272
+		$registrations_csv_ready_array = [];
273
+		$reg_model = EE_Registry::instance()->load_model('Registration');
274
+		$query_params['limit'] = [$offset, $limit];
275
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
276
+		foreach ($registration_rows as $reg_row) {
277
+			if (!is_array($reg_row)) {
278
+				continue;
279
+			}
280
+			$reg_csv_array = [];
281
+			if (! $event_id) {
282
+				// get the event's name and Id
283
+				$reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf(
284
+					/* translators: 1: event name, 2: event ID */
285
+					esc_html__('%1$s (%2$s)', 'event_espresso'),
286
+					EEH_Export::prepare_value_from_db_for_display(
287
+						EEM_Event::instance(),
288
+						'EVT_name',
289
+						$reg_row['Event_CPT.post_title']
290
+					),
291
+					$reg_row['Event_CPT.ID']
292
+				);
293
+			}
294
+			$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
295
+			/*@var $reg_row EE_Registration */
296
+			foreach ($reg_fields_to_include as $field_name) {
297
+				$field = $reg_model->field_settings_for($field_name);
298
+				if ($field_name == 'REG_final_price') {
299
+					$value = EEH_Export::prepare_value_from_db_for_display(
300
+						$reg_model,
301
+						$field_name,
302
+						$reg_row['Registration.REG_final_price'],
303
+						'localized_float'
304
+					);
305
+				} elseif ($field_name == 'REG_count') {
306
+					$value = sprintf(
307
+						/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
308
+						esc_html__('%1$s of %2$s', 'event_espresso'),
309
+						EEH_Export::prepare_value_from_db_for_display(
310
+							$reg_model,
311
+							'REG_count',
312
+							$reg_row['Registration.REG_count']
313
+						),
314
+						EEH_Export::prepare_value_from_db_for_display(
315
+							$reg_model,
316
+							'REG_group_size',
317
+							$reg_row['Registration.REG_group_size']
318
+						)
319
+					);
320
+				} elseif ($field_name == 'REG_date') {
321
+					$value = EEH_Export::prepare_value_from_db_for_display(
322
+						$reg_model,
323
+						$field_name,
324
+						$reg_row['Registration.REG_date'],
325
+						'no_html'
326
+					);
327
+				} else {
328
+					$value = EEH_Export::prepare_value_from_db_for_display(
329
+						$reg_model,
330
+						$field_name,
331
+						$reg_row[ $field->get_qualified_column() ]
332
+					);
333
+				}
334
+				$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
335
+				if ($field_name == 'REG_final_price') {
336
+					// add a column named Currency after the final price
337
+					$reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
338
+				}
339
+			}
340
+			// get pretty status
341
+			$stati = EEM_Status::instance()->localized_status(
342
+				[
343
+					$reg_row['Registration.STS_ID']     => esc_html__('unknown', 'event_espresso'),
344
+					$reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'),
345
+				],
346
+				false,
347
+				'sentence'
348
+			);
349
+			$reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
350
+			// get pretty transaction status
351
+			$reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
352
+			$reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
353
+				? EEH_Export::prepare_value_from_db_for_display(
354
+					EEM_Transaction::instance(),
355
+					'TXN_total',
356
+					$reg_row['TransactionTable.TXN_total'],
357
+					'localized_float'
358
+				) : '0.00';
359
+			$reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
360
+				? EEH_Export::prepare_value_from_db_for_display(
361
+					EEM_Transaction::instance(),
362
+					'TXN_paid',
363
+					$reg_row['TransactionTable.TXN_paid'],
364
+					'localized_float'
365
+				) : '0.00';
366
+			$payment_methods = [];
367
+			$gateway_txn_ids_etc = [];
368
+			$payment_times = [];
369
+			if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
370
+				$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
371
+					[
372
+						[
373
+							'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
374
+							'STS_ID' => EEM_Payment::status_id_approved,
375
+						],
376
+						'force_join' => ['Payment_Method'],
377
+					],
378
+					ARRAY_A,
379
+					'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
380
+				);
381
+				foreach ($payments_info as $payment_method_and_gateway_txn_id) {
382
+					$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
383
+						? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso');
384
+					$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
385
+						? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
386
+					$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
387
+						? $payment_method_and_gateway_txn_id['payment_time'] : '';
388
+				}
389
+			}
390
+			$reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
391
+			$reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
392
+			$reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
393
+				',',
394
+				$gateway_txn_ids_etc
395
+			);
396
+			// get ticket of registration and its price
397
+			$ticket_model = EE_Registry::instance()->load_model('Ticket');
398
+			if ($reg_row['Ticket.TKT_ID']) {
399
+				$ticket_name = EEH_Export::prepare_value_from_db_for_display(
400
+					$ticket_model,
401
+					'TKT_name',
402
+					$reg_row['Ticket.TKT_name']
403
+				);
404
+				$datetimes_strings = [];
405
+				foreach (
406
+					EEM_Datetime::instance()->get_all_wpdb_results(
407
+						[
408
+							['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']],
409
+							'order_by' => ['DTT_EVT_start' => 'ASC'],
410
+							'default_where_conditions' => 'none',
411
+						]
412
+					) as $datetime
413
+				) {
414
+					$datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
415
+						EEM_Datetime::instance(),
416
+						'DTT_EVT_start',
417
+						$datetime['Datetime.DTT_EVT_start']
418
+					);
419
+				}
420
+			} else {
421
+				$ticket_name = esc_html__('Unknown', 'event_espresso');
422
+				$datetimes_strings = [esc_html__('Unknown', 'event_espresso')];
423
+			}
424
+			$reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
425
+			$reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
426
+			// get datetime(s) of registration
427
+			// add attendee columns
428
+			foreach ($att_fields_to_include as $att_field_name) {
429
+				$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
430
+				if ($reg_row['Attendee_CPT.ID']) {
431
+					if ($att_field_name == 'STA_ID') {
432
+						$value = EEM_State::instance()->get_var(
433
+							[
434
+								['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]
435
+							],
436
+							'STA_name'
437
+						);
438
+					} elseif ($att_field_name == 'CNT_ISO') {
439
+						$value = EEM_Country::instance()->get_var(
440
+							[
441
+								['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]
442
+							],
443
+							'CNT_name'
444
+						);
445
+					} else {
446
+						$value = EEH_Export::prepare_value_from_db_for_display(
447
+							EEM_Attendee::instance(),
448
+							$att_field_name,
449
+							$reg_row[ $field_obj->get_qualified_column() ]
450
+						);
451
+					}
452
+				} else {
453
+					$value = '';
454
+				}
455
+				$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
456
+			}
457
+			// make sure each registration has the same questions in the same order
458
+			foreach ($question_labels as $question_label) {
459
+				if (! isset($reg_csv_array[ $question_label ])) {
460
+					$reg_csv_array[ $question_label ] = null;
461
+				}
462
+			}
463
+			$answers = EEM_Answer::instance()->get_all_wpdb_results([
464
+				['REG_ID' => $reg_row['Registration.REG_ID']],
465
+				'force_join' => ['Question'],
466
+			]);
467
+			// now fill out the questions THEY answered
468
+			foreach ($answers as $answer_row) {
469
+				if ($answer_row['Question.QST_system']) {
470
+					// it's an answer to a system question. That was already displayed as part of the attendee
471
+					// fields, so don't write it out again thanks.
472
+					continue;
473
+				}
474
+				if ($answer_row['Question.QST_ID']) {
475
+					$question_label = EEH_Export::prepare_value_from_db_for_display(
476
+						EEM_Question::instance(),
477
+						'QST_admin_label',
478
+						$answer_row['Question.QST_admin_label']
479
+					);
480
+				} else {
481
+					$question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
482
+				}
483
+				if (
484
+					isset($answer_row['Question.QST_type'])
485
+					&& $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
486
+				) {
487
+					$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
488
+						$answer_row['Answer.ANS_value']
489
+					);
490
+				} else {
491
+					// this isn't for html, so don't show html entities
492
+					$reg_csv_array[ $question_label ] = html_entity_decode(
493
+						EEH_Export::prepare_value_from_db_for_display(
494
+							EEM_Answer::instance(),
495
+							'ANS_value',
496
+							$answer_row['Answer.ANS_value']
497
+						)
498
+					);
499
+				}
500
+			}
501
+			// Include check-in data for datetime
502
+			if ($event_id && $DTT_id) {
503
+				// get whether or not the user has checked in
504
+				$reg_csv_array[ (string) esc_html__('Datetime Check-ins #', 'event_espresso') ] = $reg_model->count_related(
505
+					$reg_row['Registration.REG_ID'],
506
+					'Checkin',
507
+					[
508
+						[
509
+							'DTT_ID' => $DTT_id
510
+						]
511
+					]
512
+				);
513
+				$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_id);
514
+				$checkin_rows = EEM_Checkin::instance()->get_all_wpdb_results(
515
+					[
516
+						[
517
+							'REG_ID' => $reg_row['Registration.REG_ID'],
518
+							'DTT_ID' => $datetime->get('DTT_ID'),
519
+						],
520
+					]
521
+				);
522
+				if (trim($datetime->get('DTT_name'))) {
523
+					/* translators: 1: datetime name, 2: datetime ID */
524
+					$datetime_name = sprintf(
525
+						esc_html__('Check-ins for %1$s - ID: %2$s', 'event_espresso'),
526
+						esc_html($datetime->get('DTT_name')),
527
+						esc_html($datetime->get('DTT_ID'))
528
+					);
529
+				} else {
530
+					/* translators: %s: datetime ID */
531
+					$datetime_name = sprintf(
532
+						esc_html__('ID: %1$s', 'event_espresso'),
533
+						esc_html($datetime->get('DTT_ID'))
534
+					);
535
+				}
536
+				$checkins = [];
537
+				foreach ($checkin_rows as $checkin_row) {
538
+					if ((int) $checkin_row['Checkin.CHK_in'] === 1) {
539
+						/* translators: 1: check-in status, 2: check-in timestamp */
540
+						$checkin_value = sprintf(
541
+							esc_html__('%1$s: %2$s', 'event_espresso'),
542
+							esc_html__('IN', 'event_espresso'),
543
+							date('Y-m-d g:i a', strtotime($checkin_row['Checkin.CHK_timestamp']))
544
+						);
545
+						$checkins[] = $checkin_value;
546
+					} elseif ((int) $checkin_row['Checkin.CHK_in'] === 0) {
547
+						/* translators: 1: check-in status, 2: check-in timestamp */
548
+						$checkin_value = sprintf(
549
+							esc_html__('%1$s: %2$s', 'event_espresso'),
550
+							esc_html__('OUT', 'event_espresso'),
551
+							date('Y-m-d g:i a', strtotime($checkin_row['Checkin.CHK_timestamp']))
552
+						);
553
+						$checkins[] = $checkin_value;
554
+					}
555
+				}
556
+				$reg_csv_array[ (string) $datetime_name ] = implode(' --- ', $checkins);
557
+			} elseif ($event_id) {
558
+				// get whether or not the user has checked in
559
+				$reg_csv_array[ (string) esc_html__('Event Check-ins #', 'event_espresso') ] = $reg_model->count_related(
560
+					$reg_row['Registration.REG_ID'],
561
+					'Checkin'
562
+				);
563
+				$datetimes = EEM_Datetime::instance()->get_all_wpdb_results(
564
+					[
565
+						[
566
+							'Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID'],
567
+						],
568
+						'order_by' => ['DTT_EVT_start' => 'ASC'],
569
+						'default_where_conditions' => 'none',
570
+					]
571
+				);
572
+				foreach ($datetimes as $datetime) {
573
+					$checkin_row = EEM_Checkin::instance()->get_one(
574
+						[
575
+							[
576
+								'REG_ID' => $reg_row['Registration.REG_ID'],
577
+								'DTT_ID' => $datetime['Datetime.DTT_ID'],
578
+							],
579
+							'limit' => 1,
580
+							'order_by' => [
581
+								'CHK_ID' => 'DESC'
582
+							]
583
+						]
584
+					);
585
+					if (trim($datetime['Datetime.DTT_name'])) {
586
+						/* translators: 1: datetime name, 2: datetime ID */
587
+						$datetime_name = sprintf(
588
+							esc_html__('Check-ins for %1$s - ID: %2$s', 'event_espresso'),
589
+							esc_html($datetime['Datetime.DTT_name']),
590
+							esc_html($datetime['Datetime.DTT_ID'])
591
+						);
592
+					} else {
593
+						/* translators: %s: datetime ID */
594
+						$datetime_name = sprintf(
595
+							esc_html__('ID: %1$s', 'event_espresso'),
596
+							esc_html($datetime['Datetime.DTT_ID'])
597
+						);
598
+					}
599
+					$checkin_value = '';
600
+					if ($checkin_row instanceof EE_Checkin && $checkin_row->get('CHK_in') === true) {
601
+						/* translators: 1: check-in status, 2: check-in timestamp */
602
+						$checkin_value = sprintf(
603
+							esc_html__('%1$s: %2$s', 'event_espresso'),
604
+							esc_html__('IN', 'event_espresso'),
605
+							$checkin_row->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a')
606
+						);
607
+					} elseif ($checkin_row instanceof EE_Checkin && $checkin_row->get('CHK_in') === false) {
608
+						/* translators: 1: check-in status, 2: check-in timestamp */
609
+						$checkin_value = sprintf(
610
+							esc_html__('%1$s: %2$s', 'event_espresso'),
611
+							esc_html__('OUT', 'event_espresso'),
612
+							$checkin_row->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a')
613
+						);
614
+					}
615
+					$reg_csv_array[ (string) $datetime_name ] = $checkin_value;
616
+				}
617
+			}
618
+			/**
619
+			 * Filter to change the contents of each row of the registrations report CSV file.
620
+			 * This can be used to add or remote columns from the CSV file, or change their values.
621
+			 * Note when using: all rows in the CSV should have the same columns.
622
+			 * @param array $reg_csv_array keys are the column names, values are their cell values
623
+			 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
624
+			 */
625
+			$registrations_csv_ready_array[] = apply_filters(
626
+				'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
627
+				$reg_csv_array,
628
+				$reg_row
629
+			);
630
+		}
631
+		// if we couldn't export anything, we want to at least show the column headers
632
+		if (empty($registrations_csv_ready_array)) {
633
+			$reg_csv_array = [];
634
+			$model_and_fields_to_include = [
635
+				'Registration' => $reg_fields_to_include,
636
+				'Attendee'     => $att_fields_to_include,
637
+			];
638
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
639
+				$model = EE_Registry::instance()->load_model($model_name);
640
+				foreach ($field_list as $field_name) {
641
+					$field = $model->field_settings_for($field_name);
642
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
643
+				}
644
+			}
645
+			$registrations_csv_ready_array[] = $reg_csv_array;
646
+		}
647
+		return $registrations_csv_ready_array;
648
+	}
649 649
 
650 650
 
651
-    /**
652
-     * Counts total unit to process
653
-     *
654
-     * @deprecated since 4.9.19
655
-     * @param int|array $event_id
656
-     * @return int
657
-     */
658
-    public function count_units_to_process($event_id)
659
-    {
660
-        // use the legacy filter
661
-        if ($event_id) {
662
-            $query_params[0]['EVT_ID'] = $event_id;
663
-        } else {
664
-            $query_params['force_join'][] = 'Event';
665
-        }
666
-        return \EEM_Registration::instance()->count($query_params);
667
-    }
651
+	/**
652
+	 * Counts total unit to process
653
+	 *
654
+	 * @deprecated since 4.9.19
655
+	 * @param int|array $event_id
656
+	 * @return int
657
+	 */
658
+	public function count_units_to_process($event_id)
659
+	{
660
+		// use the legacy filter
661
+		if ($event_id) {
662
+			$query_params[0]['EVT_ID'] = $event_id;
663
+		} else {
664
+			$query_params['force_join'][] = 'Event';
665
+		}
666
+		return \EEM_Registration::instance()->count($query_params);
667
+	}
668 668
 
669 669
 
670
-    /**
671
-     * Performs any clean-up logic when we know the job is completed.
672
-     * In this case, we delete the temporary file
673
-     *
674
-     * @param JobParameters $job_parameters
675
-     * @return boolean
676
-     */
677
-    public function cleanup_job(JobParameters $job_parameters)
678
-    {
679
-        $this->_file_helper->delete(
680
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
681
-            true,
682
-            'd'
683
-        );
684
-        return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso'));
685
-    }
670
+	/**
671
+	 * Performs any clean-up logic when we know the job is completed.
672
+	 * In this case, we delete the temporary file
673
+	 *
674
+	 * @param JobParameters $job_parameters
675
+	 * @return boolean
676
+	 */
677
+	public function cleanup_job(JobParameters $job_parameters)
678
+	{
679
+		$this->_file_helper->delete(
680
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
681
+			true,
682
+			'd'
683
+		);
684
+		return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso'));
685
+	}
686 686
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     {
49 49
         $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
50 50
         $DTT_id = intval($job_parameters->request_datum('DTT_ID', '0'));
51
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
51
+        if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
52 52
             throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso'));
53 53
         }
54 54
         $filepath = $this->create_file_from_job_with_name(
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         } else {
82 82
             $query_params['force_join'][] = 'Event';
83 83
         }
84
-        if (! isset($query_params['force_join'])) {
84
+        if ( ! isset($query_params['force_join'])) {
85 85
             $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
86 86
         }
87 87
         $job_parameters->add_extra_data('query_params', $query_params);
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
         $question_where_params = array();
182 182
         foreach ($reg_where_params as $key => $val) {
183 183
             if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
184
+                $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
185 185
             } else {
186 186
                 // it's a normal where condition
187
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
187
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
188 188
             }
189 189
         }
190 190
         return $question_where_params;
@@ -274,13 +274,13 @@  discard block
 block discarded – undo
274 274
         $query_params['limit'] = [$offset, $limit];
275 275
         $registration_rows = $reg_model->get_all_wpdb_results($query_params);
276 276
         foreach ($registration_rows as $reg_row) {
277
-            if (!is_array($reg_row)) {
277
+            if ( ! is_array($reg_row)) {
278 278
                 continue;
279 279
             }
280 280
             $reg_csv_array = [];
281
-            if (! $event_id) {
281
+            if ( ! $event_id) {
282 282
                 // get the event's name and Id
283
-                $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf(
283
+                $reg_csv_array[(string) esc_html__('Event', 'event_espresso')] = sprintf(
284 284
                     /* translators: 1: event name, 2: event ID */
285 285
                     esc_html__('%1$s (%2$s)', 'event_espresso'),
286 286
                     EEH_Export::prepare_value_from_db_for_display(
@@ -328,13 +328,13 @@  discard block
 block discarded – undo
328 328
                     $value = EEH_Export::prepare_value_from_db_for_display(
329 329
                         $reg_model,
330 330
                         $field_name,
331
-                        $reg_row[ $field->get_qualified_column() ]
331
+                        $reg_row[$field->get_qualified_column()]
332 332
                     );
333 333
                 }
334
-                $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
334
+                $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value;
335 335
                 if ($field_name == 'REG_final_price') {
336 336
                     // add a column named Currency after the final price
337
-                    $reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
337
+                    $reg_csv_array[(string) esc_html__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
338 338
                 }
339 339
             }
340 340
             // get pretty status
@@ -346,17 +346,17 @@  discard block
 block discarded – undo
346 346
                 false,
347 347
                 'sentence'
348 348
             );
349
-            $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
349
+            $reg_csv_array[(string) esc_html__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
350 350
             // get pretty transaction status
351
-            $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
352
-            $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
351
+            $reg_csv_array[(string) esc_html__("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
352
+            $reg_csv_array[(string) esc_html__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
353 353
                 ? EEH_Export::prepare_value_from_db_for_display(
354 354
                     EEM_Transaction::instance(),
355 355
                     'TXN_total',
356 356
                     $reg_row['TransactionTable.TXN_total'],
357 357
                     'localized_float'
358 358
                 ) : '0.00';
359
-            $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
359
+            $reg_csv_array[(string) esc_html__('Amount Paid', 'event_espresso')] = $is_primary_reg
360 360
                 ? EEH_Export::prepare_value_from_db_for_display(
361 361
                     EEM_Transaction::instance(),
362 362
                     'TXN_paid',
@@ -387,9 +387,9 @@  discard block
 block discarded – undo
387 387
                         ? $payment_method_and_gateway_txn_id['payment_time'] : '';
388 388
                 }
389 389
             }
390
-            $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
391
-            $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
392
-            $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
390
+            $reg_csv_array[(string) esc_html__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
391
+            $reg_csv_array[(string) esc_html__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
392
+            $reg_csv_array[(string) esc_html__('Gateway Transaction ID(s)', 'event_espresso')] = implode(
393 393
                 ',',
394 394
                 $gateway_txn_ids_etc
395 395
             );
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
                 $ticket_name = esc_html__('Unknown', 'event_espresso');
422 422
                 $datetimes_strings = [esc_html__('Unknown', 'event_espresso')];
423 423
             }
424
-            $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
425
-            $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
424
+            $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
425
+            $reg_csv_array[(string) esc_html__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
426 426
             // get datetime(s) of registration
427 427
             // add attendee columns
428 428
             foreach ($att_fields_to_include as $att_field_name) {
@@ -446,18 +446,18 @@  discard block
 block discarded – undo
446 446
                         $value = EEH_Export::prepare_value_from_db_for_display(
447 447
                             EEM_Attendee::instance(),
448 448
                             $att_field_name,
449
-                            $reg_row[ $field_obj->get_qualified_column() ]
449
+                            $reg_row[$field_obj->get_qualified_column()]
450 450
                         );
451 451
                     }
452 452
                 } else {
453 453
                     $value = '';
454 454
                 }
455
-                $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
455
+                $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value;
456 456
             }
457 457
             // make sure each registration has the same questions in the same order
458 458
             foreach ($question_labels as $question_label) {
459
-                if (! isset($reg_csv_array[ $question_label ])) {
460
-                    $reg_csv_array[ $question_label ] = null;
459
+                if ( ! isset($reg_csv_array[$question_label])) {
460
+                    $reg_csv_array[$question_label] = null;
461 461
                 }
462 462
             }
463 463
             $answers = EEM_Answer::instance()->get_all_wpdb_results([
@@ -484,12 +484,12 @@  discard block
 block discarded – undo
484 484
                     isset($answer_row['Question.QST_type'])
485 485
                     && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
486 486
                 ) {
487
-                    $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
487
+                    $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID(
488 488
                         $answer_row['Answer.ANS_value']
489 489
                     );
490 490
                 } else {
491 491
                     // this isn't for html, so don't show html entities
492
-                    $reg_csv_array[ $question_label ] = html_entity_decode(
492
+                    $reg_csv_array[$question_label] = html_entity_decode(
493 493
                         EEH_Export::prepare_value_from_db_for_display(
494 494
                             EEM_Answer::instance(),
495 495
                             'ANS_value',
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
             // Include check-in data for datetime
502 502
             if ($event_id && $DTT_id) {
503 503
                 // get whether or not the user has checked in
504
-                $reg_csv_array[ (string) esc_html__('Datetime Check-ins #', 'event_espresso') ] = $reg_model->count_related(
504
+                $reg_csv_array[(string) esc_html__('Datetime Check-ins #', 'event_espresso')] = $reg_model->count_related(
505 505
                     $reg_row['Registration.REG_ID'],
506 506
                     'Checkin',
507 507
                     [
@@ -553,10 +553,10 @@  discard block
 block discarded – undo
553 553
                         $checkins[] = $checkin_value;
554 554
                     }
555 555
                 }
556
-                $reg_csv_array[ (string) $datetime_name ] = implode(' --- ', $checkins);
556
+                $reg_csv_array[(string) $datetime_name] = implode(' --- ', $checkins);
557 557
             } elseif ($event_id) {
558 558
                 // get whether or not the user has checked in
559
-                $reg_csv_array[ (string) esc_html__('Event Check-ins #', 'event_espresso') ] = $reg_model->count_related(
559
+                $reg_csv_array[(string) esc_html__('Event Check-ins #', 'event_espresso')] = $reg_model->count_related(
560 560
                     $reg_row['Registration.REG_ID'],
561 561
                     'Checkin'
562 562
                 );
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
                             $checkin_row->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a')
613 613
                         );
614 614
                     }
615
-                    $reg_csv_array[ (string) $datetime_name ] = $checkin_value;
615
+                    $reg_csv_array[(string) $datetime_name] = $checkin_value;
616 616
                 }
617 617
             }
618 618
             /**
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                 $model = EE_Registry::instance()->load_model($model_name);
640 640
                 foreach ($field_list as $field_name) {
641 641
                     $field = $model->field_settings_for($field_name);
642
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
642
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null;
643 643
                 }
644 644
             }
645 645
             $registrations_csv_ready_array[] = $reg_csv_array;
Please login to merge, or discard this patch.