Completed
Branch dev (fa0aa1)
by
unknown
10:28 queued 08:10
created
admin_pages/events/help_tabs/events_add_category.help_tab.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@
 block discarded – undo
14 14
     <li>
15 15
         <strong><?php esc_html_e('Category Description', 'event_espresso'); ?></strong><br />
16 16
         <?php esc_html_e(
17
-            'The rich text editor can be used to create a description for your event category.',
18
-            'event_espresso'
19
-        ); ?>
17
+			'The rich text editor can be used to create a description for your event category.',
18
+			'event_espresso'
19
+		); ?>
20 20
     </li>
21 21
 </ul>
22 22
 <p>
23 23
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br />
24 24
     <?php esc_html_e(
25
-        'You can customize the information that is shown on this page by toggling the screen options tab. Then you can add or remove checkmarks to hide or show certain content.',
26
-        'event_espresso'
27
-    ); ?>
25
+		'You can customize the information that is shown on this page by toggling the screen options tab. Then you can add or remove checkmarks to hide or show certain content.',
26
+		'event_espresso'
27
+	); ?>
28 28
 </p>
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3679 added lines, -3679 removed lines patch added patch discarded remove patch
@@ -19,2229 +19,2229 @@  discard block
 block discarded – undo
19 19
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * @var EE_Registration
24
-     */
25
-    private $_registration;
26
-
27
-    /**
28
-     * @var EE_Event
29
-     */
30
-    private $_reg_event;
31
-
32
-    /**
33
-     * @var EE_Session
34
-     */
35
-    private $_session;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private static $_reg_status;
41
-
42
-    /**
43
-     * Form for displaying the custom questions for this registration.
44
-     * This gets used a few times throughout the request so its best to cache it
45
-     *
46
-     * @var EE_Registration_Custom_Questions_Form
47
-     */
48
-    protected $_reg_custom_questions_form;
49
-
50
-    /**
51
-     * @var EEM_Registration $registration_model
52
-     */
53
-    private $registration_model;
54
-
55
-    /**
56
-     * @var EEM_Attendee $attendee_model
57
-     */
58
-    private $attendee_model;
59
-
60
-    /**
61
-     * @var EEM_Event $event_model
62
-     */
63
-    private $event_model;
64
-
65
-    /**
66
-     * @var EEM_Status $status_model
67
-     */
68
-    private $status_model;
69
-
70
-
71
-    /**
72
-     * @param bool $routing
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws ReflectionException
78
-     */
79
-    public function __construct($routing = true)
80
-    {
81
-        parent::__construct($routing);
82
-        add_action('wp_loaded', [$this, 'wp_loaded']);
83
-    }
84
-
85
-
86
-    /**
87
-     * @return EEM_Registration
88
-     * @throws InvalidArgumentException
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @since 4.10.2.p
92
-     */
93
-    protected function getRegistrationModel()
94
-    {
95
-        if (! $this->registration_model instanceof EEM_Registration) {
96
-            $this->registration_model = $this->loader->getShared('EEM_Registration');
97
-        }
98
-        return $this->registration_model;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return EEM_Attendee
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @since 4.10.2.p
108
-     */
109
-    protected function getAttendeeModel()
110
-    {
111
-        if (! $this->attendee_model instanceof EEM_Attendee) {
112
-            $this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
-        }
114
-        return $this->attendee_model;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return EEM_Event
120
-     * @throws InvalidArgumentException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     * @since 4.10.2.p
124
-     */
125
-    protected function getEventModel()
126
-    {
127
-        if (! $this->event_model instanceof EEM_Event) {
128
-            $this->event_model = $this->loader->getShared('EEM_Event');
129
-        }
130
-        return $this->event_model;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return EEM_Status
136
-     * @throws InvalidArgumentException
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @since 4.10.2.p
140
-     */
141
-    protected function getStatusModel()
142
-    {
143
-        if (! $this->status_model instanceof EEM_Status) {
144
-            $this->status_model = $this->loader->getShared('EEM_Status');
145
-        }
146
-        return $this->status_model;
147
-    }
148
-
149
-
150
-    public function wp_loaded()
151
-    {
152
-        // when adding a new registration...
153
-        $action = $this->request->getRequestParam('action');
154
-        if ($action === 'new_registration') {
155
-            EE_System::do_not_cache();
156
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
-                // and it's NOT the attendee information reg step
158
-                // force cookie expiration by setting time to last week
159
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
-                // and update the global
161
-                $_COOKIE['ee_registration_added'] = 0;
162
-            }
163
-        }
164
-    }
165
-
166
-
167
-    protected function _init_page_props()
168
-    {
169
-        $this->page_slug        = REG_PG_SLUG;
170
-        $this->_admin_base_url  = REG_ADMIN_URL;
171
-        $this->_admin_base_path = REG_ADMIN;
172
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
173
-        $this->_cpt_routes      = [
174
-            'add_new_attendee' => 'espresso_attendees',
175
-            'edit_attendee'    => 'espresso_attendees',
176
-            'insert_attendee'  => 'espresso_attendees',
177
-            'update_attendee'  => 'espresso_attendees',
178
-        ];
179
-        $this->_cpt_model_names = [
180
-            'add_new_attendee' => 'EEM_Attendee',
181
-            'edit_attendee'    => 'EEM_Attendee',
182
-        ];
183
-        $this->_cpt_edit_routes = [
184
-            'espresso_attendees' => 'edit_attendee',
185
-        ];
186
-        $this->_pagenow_map     = [
187
-            'add_new_attendee' => 'post-new.php',
188
-            'edit_attendee'    => 'post.php',
189
-            'trash'            => 'post.php',
190
-        ];
191
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
-        // add filters so that the comment urls don't take users to a confusing 404 page
193
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
-    }
195
-
196
-
197
-    /**
198
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
199
-     * @param WP_Comment $comment The current comment object.
200
-     * @return string
201
-     */
202
-    public function clear_comment_link($link, WP_Comment $comment)
203
-    {
204
-        // gotta make sure this only happens on this route
205
-        $post_type = get_post_type($comment->comment_post_ID);
206
-        if ($post_type === 'espresso_attendees') {
207
-            return '#commentsdiv';
208
-        }
209
-        return $link;
210
-    }
211
-
212
-
213
-    protected function _ajax_hooks()
214
-    {
215
-        // todo: all hooks for registrations ajax goes in here
216
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
-    }
218
-
219
-
220
-    protected function _define_page_props()
221
-    {
222
-        $this->_admin_page_title = $this->page_label;
223
-        $this->_labels           = [
224
-            'buttons'                      => [
225
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
-            ],
234
-            'publishbox'                   => [
235
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
-            ],
238
-            'hide_add_button_on_cpt_route' => [
239
-                'edit_attendee' => true,
240
-            ],
241
-        ];
242
-    }
243
-
244
-
245
-    /**
246
-     * grab url requests and route them
247
-     *
248
-     * @return void
249
-     * @throws EE_Error
250
-     */
251
-    public function _set_page_routes()
252
-    {
253
-        $this->_get_registration_status_array();
254
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
-        $this->_page_routes = [
259
-            'default'                             => [
260
-                'func'       => '_registrations_overview_list_table',
261
-                'capability' => 'ee_read_registrations',
262
-            ],
263
-            'view_registration'                   => [
264
-                'func'       => '_registration_details',
265
-                'capability' => 'ee_read_registration',
266
-                'obj_id'     => $REG_ID,
267
-            ],
268
-            'edit_registration'                   => [
269
-                'func'               => '_update_attendee_registration_form',
270
-                'noheader'           => true,
271
-                'headers_sent_route' => 'view_registration',
272
-                'capability'         => 'ee_edit_registration',
273
-                'obj_id'             => $REG_ID,
274
-                '_REG_ID'            => $REG_ID,
275
-            ],
276
-            'trash_registrations'                 => [
277
-                'func'       => '_trash_or_restore_registrations',
278
-                'args'       => ['trash' => true],
279
-                'noheader'   => true,
280
-                'capability' => 'ee_delete_registrations',
281
-            ],
282
-            'restore_registrations'               => [
283
-                'func'       => '_trash_or_restore_registrations',
284
-                'args'       => ['trash' => false],
285
-                'noheader'   => true,
286
-                'capability' => 'ee_delete_registrations',
287
-            ],
288
-            'delete_registrations'                => [
289
-                'func'       => '_delete_registrations',
290
-                'noheader'   => true,
291
-                'capability' => 'ee_delete_registrations',
292
-            ],
293
-            'new_registration'                    => [
294
-                'func'       => 'new_registration',
295
-                'capability' => 'ee_edit_registrations',
296
-            ],
297
-            'process_reg_step'                    => [
298
-                'func'       => 'process_reg_step',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-            ],
302
-            'redirect_to_txn'                     => [
303
-                'func'       => 'redirect_to_txn',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-            ],
307
-            'change_reg_status'                   => [
308
-                'func'       => '_change_reg_status',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $REG_ID,
312
-            ],
313
-            'approve_registration'                => [
314
-                'func'       => 'approve_registration',
315
-                'noheader'   => true,
316
-                'capability' => 'ee_edit_registration',
317
-                'obj_id'     => $REG_ID,
318
-            ],
319
-            'approve_and_notify_registration'     => [
320
-                'func'       => 'approve_registration',
321
-                'noheader'   => true,
322
-                'args'       => [true],
323
-                'capability' => 'ee_edit_registration',
324
-                'obj_id'     => $REG_ID,
325
-            ],
326
-            'approve_registrations'               => [
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args'       => ['approve'],
331
-            ],
332
-            'approve_and_notify_registrations'    => [
333
-                'func'       => 'bulk_action_on_registrations',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registrations',
336
-                'args'       => ['approve', true],
337
-            ],
338
-            'decline_registration'                => [
339
-                'func'       => 'decline_registration',
340
-                'noheader'   => true,
341
-                'capability' => 'ee_edit_registration',
342
-                'obj_id'     => $REG_ID,
343
-            ],
344
-            'decline_and_notify_registration'     => [
345
-                'func'       => 'decline_registration',
346
-                'noheader'   => true,
347
-                'args'       => [true],
348
-                'capability' => 'ee_edit_registration',
349
-                'obj_id'     => $REG_ID,
350
-            ],
351
-            'decline_registrations'               => [
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args'       => ['decline'],
356
-            ],
357
-            'decline_and_notify_registrations'    => [
358
-                'func'       => 'bulk_action_on_registrations',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registrations',
361
-                'args'       => ['decline', true],
362
-            ],
363
-            'pending_registration'                => [
364
-                'func'       => 'pending_registration',
365
-                'noheader'   => true,
366
-                'capability' => 'ee_edit_registration',
367
-                'obj_id'     => $REG_ID,
368
-            ],
369
-            'pending_and_notify_registration'     => [
370
-                'func'       => 'pending_registration',
371
-                'noheader'   => true,
372
-                'args'       => [true],
373
-                'capability' => 'ee_edit_registration',
374
-                'obj_id'     => $REG_ID,
375
-            ],
376
-            'pending_registrations'               => [
377
-                'func'       => 'bulk_action_on_registrations',
378
-                'noheader'   => true,
379
-                'capability' => 'ee_edit_registrations',
380
-                'args'       => ['pending'],
381
-            ],
382
-            'pending_and_notify_registrations'    => [
383
-                'func'       => 'bulk_action_on_registrations',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_registrations',
386
-                'args'       => ['pending', true],
387
-            ],
388
-            'no_approve_registration'             => [
389
-                'func'       => 'not_approve_registration',
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_registration',
392
-                'obj_id'     => $REG_ID,
393
-            ],
394
-            'no_approve_and_notify_registration'  => [
395
-                'func'       => 'not_approve_registration',
396
-                'noheader'   => true,
397
-                'args'       => [true],
398
-                'capability' => 'ee_edit_registration',
399
-                'obj_id'     => $REG_ID,
400
-            ],
401
-            'no_approve_registrations'            => [
402
-                'func'       => 'bulk_action_on_registrations',
403
-                'noheader'   => true,
404
-                'capability' => 'ee_edit_registrations',
405
-                'args'       => ['not_approve'],
406
-            ],
407
-            'no_approve_and_notify_registrations' => [
408
-                'func'       => 'bulk_action_on_registrations',
409
-                'noheader'   => true,
410
-                'capability' => 'ee_edit_registrations',
411
-                'args'       => ['not_approve', true],
412
-            ],
413
-            'cancel_registration'                 => [
414
-                'func'       => 'cancel_registration',
415
-                'noheader'   => true,
416
-                'capability' => 'ee_edit_registration',
417
-                'obj_id'     => $REG_ID,
418
-            ],
419
-            'cancel_and_notify_registration'      => [
420
-                'func'       => 'cancel_registration',
421
-                'noheader'   => true,
422
-                'args'       => [true],
423
-                'capability' => 'ee_edit_registration',
424
-                'obj_id'     => $REG_ID,
425
-            ],
426
-            'cancel_registrations'                => [
427
-                'func'       => 'bulk_action_on_registrations',
428
-                'noheader'   => true,
429
-                'capability' => 'ee_edit_registrations',
430
-                'args'       => ['cancel'],
431
-            ],
432
-            'cancel_and_notify_registrations'     => [
433
-                'func'       => 'bulk_action_on_registrations',
434
-                'noheader'   => true,
435
-                'capability' => 'ee_edit_registrations',
436
-                'args'       => ['cancel', true],
437
-            ],
438
-            'wait_list_registration'              => [
439
-                'func'       => 'wait_list_registration',
440
-                'noheader'   => true,
441
-                'capability' => 'ee_edit_registration',
442
-                'obj_id'     => $REG_ID,
443
-            ],
444
-            'wait_list_and_notify_registration'   => [
445
-                'func'       => 'wait_list_registration',
446
-                'noheader'   => true,
447
-                'args'       => [true],
448
-                'capability' => 'ee_edit_registration',
449
-                'obj_id'     => $REG_ID,
450
-            ],
451
-            'contact_list'                        => [
452
-                'func'       => '_attendee_contact_list_table',
453
-                'capability' => 'ee_read_contacts',
454
-            ],
455
-            'add_new_attendee'                    => [
456
-                'func' => '_create_new_cpt_item',
457
-                'args' => [
458
-                    'new_attendee' => true,
459
-                    'capability'   => 'ee_edit_contacts',
460
-                ],
461
-            ],
462
-            'edit_attendee'                       => [
463
-                'func'       => '_edit_cpt_item',
464
-                'capability' => 'ee_edit_contacts',
465
-                'obj_id'     => $ATT_ID,
466
-            ],
467
-            'duplicate_attendee'                  => [
468
-                'func'       => '_duplicate_attendee',
469
-                'noheader'   => true,
470
-                'capability' => 'ee_edit_contacts',
471
-                'obj_id'     => $ATT_ID,
472
-            ],
473
-            'insert_attendee'                     => [
474
-                'func'       => '_insert_or_update_attendee',
475
-                'args'       => [
476
-                    'new_attendee' => true,
477
-                ],
478
-                'noheader'   => true,
479
-                'capability' => 'ee_edit_contacts',
480
-            ],
481
-            'update_attendee'                     => [
482
-                'func'       => '_insert_or_update_attendee',
483
-                'args'       => [
484
-                    'new_attendee' => false,
485
-                ],
486
-                'noheader'   => true,
487
-                'capability' => 'ee_edit_contacts',
488
-                'obj_id'     => $ATT_ID,
489
-            ],
490
-            'trash_attendees'                     => [
491
-                'func'       => '_trash_or_restore_attendees',
492
-                'args'       => [
493
-                    'trash' => 'true',
494
-                ],
495
-                'noheader'   => true,
496
-                'capability' => 'ee_delete_contacts',
497
-            ],
498
-            'trash_attendee'                      => [
499
-                'func'       => '_trash_or_restore_attendees',
500
-                'args'       => [
501
-                    'trash' => true,
502
-                ],
503
-                'noheader'   => true,
504
-                'capability' => 'ee_delete_contacts',
505
-                'obj_id'     => $ATT_ID,
506
-            ],
507
-            'restore_attendees'                   => [
508
-                'func'       => '_trash_or_restore_attendees',
509
-                'args'       => [
510
-                    'trash' => false,
511
-                ],
512
-                'noheader'   => true,
513
-                'capability' => 'ee_delete_contacts',
514
-                'obj_id'     => $ATT_ID,
515
-            ],
516
-            'resend_registration'                 => [
517
-                'func'       => '_resend_registration',
518
-                'noheader'   => true,
519
-                'capability' => 'ee_send_message',
520
-            ],
521
-            'registrations_report'                => [
522
-                'func'       => '_registrations_report',
523
-                'noheader'   => true,
524
-                'capability' => 'ee_read_registrations',
525
-            ],
526
-            'contact_list_export'                 => [
527
-                'func'       => '_contact_list_export',
528
-                'noheader'   => true,
529
-                'capability' => 'export',
530
-            ],
531
-            'contact_list_report'                 => [
532
-                'func'       => '_contact_list_report',
533
-                'noheader'   => true,
534
-                'capability' => 'ee_read_contacts',
535
-            ],
536
-        ];
537
-    }
538
-
539
-
540
-    protected function _set_page_config()
541
-    {
542
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
-        $this->_page_config = [
545
-            'default'           => [
546
-                'nav'           => [
547
-                    'label' => esc_html__('Overview', 'event_espresso'),
548
-                    'order' => 5,
549
-                ],
550
-                'help_tabs'     => [
551
-                    'registrations_overview_help_tab'                       => [
552
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
-                        'filename' => 'registrations_overview',
554
-                    ],
555
-                    'registrations_overview_table_column_headings_help_tab' => [
556
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
-                        'filename' => 'registrations_overview_table_column_headings',
558
-                    ],
559
-                    'registrations_overview_filters_help_tab'               => [
560
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
-                        'filename' => 'registrations_overview_filters',
562
-                    ],
563
-                    'registrations_overview_views_help_tab'                 => [
564
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
565
-                        'filename' => 'registrations_overview_views',
566
-                    ],
567
-                    'registrations_regoverview_other_help_tab'              => [
568
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
-                        'filename' => 'registrations_overview_other',
570
-                    ],
571
-                ],
572
-                'qtips'         => ['Registration_List_Table_Tips'],
573
-                'list_table'    => 'EE_Registrations_List_Table',
574
-                'require_nonce' => false,
575
-            ],
576
-            'view_registration' => [
577
-                'nav'           => [
578
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
579
-                    'order'      => 15,
580
-                    'url'        => $REG_ID
581
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
-                        : $this->_admin_base_url,
583
-                    'persistent' => false,
584
-                ],
585
-                'help_tabs'     => [
586
-                    'registrations_details_help_tab'                    => [
587
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
588
-                        'filename' => 'registrations_details',
589
-                    ],
590
-                    'registrations_details_table_help_tab'              => [
591
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
-                        'filename' => 'registrations_details_table',
593
-                    ],
594
-                    'registrations_details_form_answers_help_tab'       => [
595
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
-                        'filename' => 'registrations_details_form_answers',
597
-                    ],
598
-                    'registrations_details_registrant_details_help_tab' => [
599
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
600
-                        'filename' => 'registrations_details_registrant_details',
601
-                    ],
602
-                ],
603
-                'metaboxes'     => array_merge(
604
-                    $this->_default_espresso_metaboxes,
605
-                    ['_registration_details_metaboxes']
606
-                ),
607
-                'require_nonce' => false,
608
-            ],
609
-            'new_registration'  => [
610
-                'nav'           => [
611
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
-                    'url'        => '#',
613
-                    'order'      => 15,
614
-                    'persistent' => false,
615
-                ],
616
-                'metaboxes'     => $this->_default_espresso_metaboxes,
617
-                'labels'        => [
618
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
-                ],
620
-                'require_nonce' => false,
621
-            ],
622
-            'add_new_attendee'  => [
623
-                'nav'           => [
624
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
625
-                    'order'      => 15,
626
-                    'persistent' => false,
627
-                ],
628
-                'metaboxes'     => array_merge(
629
-                    $this->_default_espresso_metaboxes,
630
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
631
-                ),
632
-                'require_nonce' => false,
633
-            ],
634
-            'edit_attendee'     => [
635
-                'nav'           => [
636
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
-                    'order'      => 15,
638
-                    'persistent' => false,
639
-                    'url'        => $ATT_ID
640
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
-                        : $this->_admin_base_url,
642
-                ],
643
-                'metaboxes'     => ['attendee_editor_metaboxes'],
644
-                'require_nonce' => false,
645
-            ],
646
-            'contact_list'      => [
647
-                'nav'           => [
648
-                    'label' => esc_html__('Contact List', 'event_espresso'),
649
-                    'order' => 20,
650
-                ],
651
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
652
-                'help_tabs'     => [
653
-                    'registrations_contact_list_help_tab'                       => [
654
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
655
-                        'filename' => 'registrations_contact_list',
656
-                    ],
657
-                    'registrations_contact-list_table_column_headings_help_tab' => [
658
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
659
-                        'filename' => 'registrations_contact_list_table_column_headings',
660
-                    ],
661
-                    'registrations_contact_list_views_help_tab'                 => [
662
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
663
-                        'filename' => 'registrations_contact_list_views',
664
-                    ],
665
-                    'registrations_contact_list_other_help_tab'                 => [
666
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
667
-                        'filename' => 'registrations_contact_list_other',
668
-                    ],
669
-                ],
670
-                'metaboxes'     => [],
671
-                'require_nonce' => false,
672
-            ],
673
-            // override default cpt routes
674
-            'create_new'        => '',
675
-            'edit'              => '',
676
-        ];
677
-    }
678
-
679
-
680
-    /**
681
-     * The below methods aren't used by this class currently
682
-     */
683
-    protected function _add_screen_options()
684
-    {
685
-    }
686
-
687
-
688
-    protected function _add_feature_pointers()
689
-    {
690
-    }
691
-
692
-
693
-    public function admin_init()
694
-    {
695
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
696
-            'click "Update Registration Questions" to save your changes',
697
-            'event_espresso'
698
-        );
699
-    }
700
-
701
-
702
-    public function admin_notices()
703
-    {
704
-    }
705
-
706
-
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
710
-
711
-
712
-    /**
713
-     * get list of registration statuses
714
-     *
715
-     * @return void
716
-     * @throws EE_Error
717
-     */
718
-    private function _get_registration_status_array()
719
-    {
720
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
721
-    }
722
-
723
-
724
-    /**
725
-     * @throws InvalidArgumentException
726
-     * @throws InvalidDataTypeException
727
-     * @throws InvalidInterfaceException
728
-     * @since 4.10.2.p
729
-     */
730
-    protected function _add_screen_options_default()
731
-    {
732
-        $this->_per_page_screen_option();
733
-    }
734
-
735
-
736
-    /**
737
-     * @throws InvalidArgumentException
738
-     * @throws InvalidDataTypeException
739
-     * @throws InvalidInterfaceException
740
-     * @since 4.10.2.p
741
-     */
742
-    protected function _add_screen_options_contact_list()
743
-    {
744
-        $page_title              = $this->_admin_page_title;
745
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
746
-        $this->_per_page_screen_option();
747
-        $this->_admin_page_title = $page_title;
748
-    }
749
-
750
-
751
-    public function load_scripts_styles()
752
-    {
753
-        // style
754
-        wp_register_style(
755
-            'espresso_reg',
756
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
757
-            ['ee-admin-css'],
758
-            EVENT_ESPRESSO_VERSION
759
-        );
760
-        wp_enqueue_style('espresso_reg');
761
-        // script
762
-        wp_register_script(
763
-            'espresso_reg',
764
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
765
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
766
-            EVENT_ESPRESSO_VERSION,
767
-            true
768
-        );
769
-        wp_enqueue_script('espresso_reg');
770
-    }
771
-
772
-
773
-    /**
774
-     * @throws EE_Error
775
-     * @throws InvalidArgumentException
776
-     * @throws InvalidDataTypeException
777
-     * @throws InvalidInterfaceException
778
-     * @throws ReflectionException
779
-     * @since 4.10.2.p
780
-     */
781
-    public function load_scripts_styles_edit_attendee()
782
-    {
783
-        // stuff to only show up on our attendee edit details page.
784
-        $attendee_details_translations = [
785
-            'att_publish_text' => sprintf(
786
-            /* translators: The date and time */
787
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
788
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
789
-            ),
790
-        ];
791
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
792
-        wp_enqueue_script('jquery-validate');
793
-    }
794
-
795
-
796
-    /**
797
-     * @throws EE_Error
798
-     * @throws InvalidArgumentException
799
-     * @throws InvalidDataTypeException
800
-     * @throws InvalidInterfaceException
801
-     * @throws ReflectionException
802
-     * @since 4.10.2.p
803
-     */
804
-    public function load_scripts_styles_view_registration()
805
-    {
806
-        // styles
807
-        wp_enqueue_style('espresso-ui-theme');
808
-        // scripts
809
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
810
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
811
-    }
812
-
813
-
814
-    public function load_scripts_styles_contact_list()
815
-    {
816
-        wp_dequeue_style('espresso_reg');
817
-        wp_register_style(
818
-            'espresso_att',
819
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
820
-            ['ee-admin-css'],
821
-            EVENT_ESPRESSO_VERSION
822
-        );
823
-        wp_enqueue_style('espresso_att');
824
-    }
825
-
826
-
827
-    public function load_scripts_styles_new_registration()
828
-    {
829
-        wp_register_script(
830
-            'ee-spco-for-admin',
831
-            REG_ASSETS_URL . 'spco_for_admin.js',
832
-            ['underscore', 'jquery'],
833
-            EVENT_ESPRESSO_VERSION,
834
-            true
835
-        );
836
-        wp_enqueue_script('ee-spco-for-admin');
837
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
838
-        EE_Form_Section_Proper::wp_enqueue_scripts();
839
-        EED_Ticket_Selector::load_tckt_slctr_assets();
840
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
841
-    }
842
-
843
-
844
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
845
-    {
846
-        add_filter('FHEE_load_EE_messages', '__return_true');
847
-    }
848
-
849
-
850
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
851
-    {
852
-        add_filter('FHEE_load_EE_messages', '__return_true');
853
-    }
854
-
855
-
856
-    /**
857
-     * @throws EE_Error
858
-     * @throws InvalidArgumentException
859
-     * @throws InvalidDataTypeException
860
-     * @throws InvalidInterfaceException
861
-     * @throws ReflectionException
862
-     * @since 4.10.2.p
863
-     */
864
-    protected function _set_list_table_views_default()
865
-    {
866
-        // for notification related bulk actions we need to make sure only active messengers have an option.
867
-        EED_Messages::set_autoloaders();
868
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
869
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
870
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
871
-        // key= bulk_action_slug, value= message type.
872
-        $match_array = [
873
-            'approve_registrations'    => 'registration',
874
-            'decline_registrations'    => 'declined_registration',
875
-            'pending_registrations'    => 'pending_approval',
876
-            'no_approve_registrations' => 'not_approved_registration',
877
-            'cancel_registrations'     => 'cancelled_registration',
878
-        ];
879
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
880
-            'ee_send_message',
881
-            'batch_send_messages'
882
-        );
883
-        /** setup reg status bulk actions **/
884
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
885
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
886
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
887
-                'Approve and Notify Registrations',
888
-                'event_espresso'
889
-            );
890
-        }
891
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
892
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
893
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
894
-                'Decline and Notify Registrations',
895
-                'event_espresso'
896
-            );
897
-        }
898
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
899
-            'Set Registrations to Pending Payment',
900
-            'event_espresso'
901
-        );
902
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
903
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
904
-                'Set Registrations to Pending Payment and Notify',
905
-                'event_espresso'
906
-            );
907
-        }
908
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
909
-            'Set Registrations to Not Approved',
910
-            'event_espresso'
911
-        );
912
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
913
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
914
-                'Set Registrations to Not Approved and Notify',
915
-                'event_espresso'
916
-            );
917
-        }
918
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
919
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
920
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
921
-                'Cancel Registrations and Notify',
922
-                'event_espresso'
923
-            );
924
-        }
925
-        $def_reg_status_actions = apply_filters(
926
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
927
-            $def_reg_status_actions,
928
-            $active_mts,
929
-            $can_send
930
-        );
931
-
932
-        $this->_views = [
933
-            'all'   => [
934
-                'slug'        => 'all',
935
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
936
-                'count'       => 0,
937
-                'bulk_action' => array_merge(
938
-                    $def_reg_status_actions,
939
-                    [
940
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
941
-                    ]
942
-                ),
943
-            ],
944
-            'month' => [
945
-                'slug'        => 'month',
946
-                'label'       => esc_html__('This Month', 'event_espresso'),
947
-                'count'       => 0,
948
-                'bulk_action' => array_merge(
949
-                    $def_reg_status_actions,
950
-                    [
951
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
952
-                    ]
953
-                ),
954
-            ],
955
-            'today' => [
956
-                'slug'        => 'today',
957
-                'label'       => sprintf(
958
-                    esc_html__('Today - %s', 'event_espresso'),
959
-                    date('M d, Y', current_time('timestamp'))
960
-                ),
961
-                'count'       => 0,
962
-                'bulk_action' => array_merge(
963
-                    $def_reg_status_actions,
964
-                    [
965
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
966
-                    ]
967
-                ),
968
-            ],
969
-        ];
970
-        if (
971
-            EE_Registry::instance()->CAP->current_user_can(
972
-                'ee_delete_registrations',
973
-                'espresso_registrations_delete_registration'
974
-            )
975
-        ) {
976
-            $this->_views['incomplete'] = [
977
-                'slug'        => 'incomplete',
978
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
979
-                'count'       => 0,
980
-                'bulk_action' => [
981
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
-                ],
983
-            ];
984
-            $this->_views['trash']      = [
985
-                'slug'        => 'trash',
986
-                'label'       => esc_html__('Trash', 'event_espresso'),
987
-                'count'       => 0,
988
-                'bulk_action' => [
989
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
-                ],
992
-            ];
993
-        }
994
-    }
995
-
996
-
997
-    protected function _set_list_table_views_contact_list()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'        => 'in_use',
1002
-                'label'       => esc_html__('In Use', 'event_espresso'),
1003
-                'count'       => 0,
1004
-                'bulk_action' => [
1005
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
-                ],
1007
-            ],
1008
-        ];
1009
-        if (
1010
-            EE_Registry::instance()->CAP->current_user_can(
1011
-                'ee_delete_contacts',
1012
-                'espresso_registrations_trash_attendees'
1013
-            )
1014
-        ) {
1015
-            $this->_views['trash'] = [
1016
-                'slug'        => 'trash',
1017
-                'label'       => esc_html__('Trash', 'event_espresso'),
1018
-                'count'       => 0,
1019
-                'bulk_action' => [
1020
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1021
-                ],
1022
-            ];
1023
-        }
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * @return array
1029
-     * @throws EE_Error
1030
-     */
1031
-    protected function _registration_legend_items()
1032
-    {
1033
-        $fc_items = [
1034
-            'star-icon'        => [
1035
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1037
-            ],
1038
-            'view_details'     => [
1039
-                'class' => 'dashicons dashicons-clipboard',
1040
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1041
-            ],
1042
-            'edit_attendee'    => [
1043
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1044
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1045
-            ],
1046
-            'view_transaction' => [
1047
-                'class' => 'dashicons dashicons-cart',
1048
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1049
-            ],
1050
-            'view_invoice'     => [
1051
-                'class' => 'dashicons dashicons-media-spreadsheet',
1052
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1053
-            ],
1054
-        ];
1055
-        if (
1056
-            EE_Registry::instance()->CAP->current_user_can(
1057
-                'ee_send_message',
1058
-                'espresso_registrations_resend_registration'
1059
-            )
1060
-        ) {
1061
-            $fc_items['resend_registration'] = [
1062
-                'class' => 'dashicons dashicons-email-alt',
1063
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1064
-            ];
1065
-        } else {
1066
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1067
-        }
1068
-        if (
1069
-            EE_Registry::instance()->CAP->current_user_can(
1070
-                'ee_read_global_messages',
1071
-                'view_filtered_messages'
1072
-            )
1073
-        ) {
1074
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1075
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1076
-                $fc_items['view_related_messages'] = [
1077
-                    'class' => $related_for_icon['css_class'],
1078
-                    'desc'  => $related_for_icon['label'],
1079
-                ];
1080
-            }
1081
-        }
1082
-        $sc_items = [
1083
-            'approved_status'   => [
1084
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1085
-                'desc'  => EEH_Template::pretty_status(
1086
-                    EEM_Registration::status_id_approved,
1087
-                    false,
1088
-                    'sentence'
1089
-                ),
1090
-            ],
1091
-            'pending_status'    => [
1092
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1093
-                'desc'  => EEH_Template::pretty_status(
1094
-                    EEM_Registration::status_id_pending_payment,
1095
-                    false,
1096
-                    'sentence'
1097
-                ),
1098
-            ],
1099
-            'wait_list'         => [
1100
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1101
-                'desc'  => EEH_Template::pretty_status(
1102
-                    EEM_Registration::status_id_wait_list,
1103
-                    false,
1104
-                    'sentence'
1105
-                ),
1106
-            ],
1107
-            'incomplete_status' => [
1108
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1109
-                'desc'  => EEH_Template::pretty_status(
1110
-                    EEM_Registration::status_id_incomplete,
1111
-                    false,
1112
-                    'sentence'
1113
-                ),
1114
-            ],
1115
-            'not_approved'      => [
1116
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1117
-                'desc'  => EEH_Template::pretty_status(
1118
-                    EEM_Registration::status_id_not_approved,
1119
-                    false,
1120
-                    'sentence'
1121
-                ),
1122
-            ],
1123
-            'declined_status'   => [
1124
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1125
-                'desc'  => EEH_Template::pretty_status(
1126
-                    EEM_Registration::status_id_declined,
1127
-                    false,
1128
-                    'sentence'
1129
-                ),
1130
-            ],
1131
-            'cancelled_status'  => [
1132
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1133
-                'desc'  => EEH_Template::pretty_status(
1134
-                    EEM_Registration::status_id_cancelled,
1135
-                    false,
1136
-                    'sentence'
1137
-                ),
1138
-            ],
1139
-        ];
1140
-        return array_merge($fc_items, $sc_items);
1141
-    }
1142
-
1143
-
1144
-
1145
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1146
-
1147
-
1148
-    /**
1149
-     * @throws DomainException
1150
-     * @throws EE_Error
1151
-     * @throws InvalidArgumentException
1152
-     * @throws InvalidDataTypeException
1153
-     * @throws InvalidInterfaceException
1154
-     */
1155
-    protected function _registrations_overview_list_table()
1156
-    {
1157
-        $this->appendAddNewRegistrationButtonToPageTitle();
1158
-        $header_text                  = '';
1159
-        $admin_page_header_decorators = [
1160
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
-        ];
1165
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
-            $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1167
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1168
-        }
1169
-        $this->_template_args['admin_page_header'] = $header_text;
1170
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1171
-        $this->display_admin_list_table_page_with_no_sidebar();
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * @throws EE_Error
1177
-     * @throws InvalidArgumentException
1178
-     * @throws InvalidDataTypeException
1179
-     * @throws InvalidInterfaceException
1180
-     */
1181
-    private function appendAddNewRegistrationButtonToPageTitle()
1182
-    {
1183
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1184
-        if (
1185
-            $EVT_ID
1186
-            && EE_Registry::instance()->CAP->current_user_can(
1187
-                'ee_edit_registrations',
1188
-                'espresso_registrations_new_registration',
1189
-                $EVT_ID
1190
-            )
1191
-        ) {
1192
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1193
-                'new_registration',
1194
-                'add-registrant',
1195
-                ['event_id' => $EVT_ID],
1196
-                'add-new-h2'
1197
-            );
1198
-        }
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * This sets the _registration property for the registration details screen
1204
-     *
1205
-     * @return void
1206
-     * @throws EE_Error
1207
-     * @throws InvalidArgumentException
1208
-     * @throws InvalidDataTypeException
1209
-     * @throws InvalidInterfaceException
1210
-     */
1211
-    private function _set_registration_object()
1212
-    {
1213
-        // get out if we've already set the object
1214
-        if ($this->_registration instanceof EE_Registration) {
1215
-            return;
1216
-        }
1217
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1218
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1219
-            return;
1220
-        }
1221
-        $error_msg = sprintf(
1222
-            esc_html__(
1223
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1224
-                'event_espresso'
1225
-            ),
1226
-            $REG_ID
1227
-        );
1228
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1229
-        $this->_registration = null;
1230
-    }
1231
-
1232
-
1233
-    /**
1234
-     * Used to retrieve registrations for the list table.
1235
-     *
1236
-     * @param int  $per_page
1237
-     * @param bool $count
1238
-     * @param bool $this_month
1239
-     * @param bool $today
1240
-     * @return EE_Registration[]|int
1241
-     * @throws EE_Error
1242
-     * @throws InvalidArgumentException
1243
-     * @throws InvalidDataTypeException
1244
-     * @throws InvalidInterfaceException
1245
-     */
1246
-    public function get_registrations(
1247
-        $per_page = 10,
1248
-        $count = false,
1249
-        $this_month = false,
1250
-        $today = false
1251
-    ) {
1252
-        if ($this_month) {
1253
-            $this->request->setRequestParam('status', 'month');
1254
-        }
1255
-        if ($today) {
1256
-            $this->request->setRequestParam('status', 'today');
1257
-        }
1258
-        $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1259
-        /**
1260
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1261
-         *
1262
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1263
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1264
-         *                      or if you have the development copy of EE you can view this at the path:
1265
-         *                      /docs/G--Model-System/model-query-params.md
1266
-         */
1267
-        $query_params['group_by'] = '';
1268
-
1269
-        return $count
1270
-            ? $this->getRegistrationModel()->count($query_params)
1271
-            /** @type EE_Registration[] */
1272
-            : $this->getRegistrationModel()->get_all($query_params);
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1278
-     * Note: this listens to values on the request for some of the query parameters.
1279
-     *
1280
-     * @param array $request
1281
-     * @param int   $per_page
1282
-     * @param bool  $count
1283
-     * @return array
1284
-     * @throws EE_Error
1285
-     * @throws InvalidArgumentException
1286
-     * @throws InvalidDataTypeException
1287
-     * @throws InvalidInterfaceException
1288
-     */
1289
-    protected function _get_registration_query_parameters(
1290
-        $request = [],
1291
-        $per_page = 10,
1292
-        $count = false
1293
-    ) {
1294
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1295
-        $list_table_query_builder = $this->loader->getNew(
1296
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1297
-            [null, null, $request]
1298
-        );
1299
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1300
-    }
1301
-
1302
-
1303
-    public function get_registration_status_array()
1304
-    {
1305
-        return self::$_reg_status;
1306
-    }
1307
-
1308
-
1309
-
1310
-
1311
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1312
-    /**
1313
-     * generates HTML for the View Registration Details Admin page
1314
-     *
1315
-     * @return void
1316
-     * @throws DomainException
1317
-     * @throws EE_Error
1318
-     * @throws InvalidArgumentException
1319
-     * @throws InvalidDataTypeException
1320
-     * @throws InvalidInterfaceException
1321
-     * @throws EntityNotFoundException
1322
-     * @throws ReflectionException
1323
-     */
1324
-    protected function _registration_details()
1325
-    {
1326
-        $this->_template_args = [];
1327
-        $this->_set_registration_object();
1328
-        if (is_object($this->_registration)) {
1329
-            $transaction                                   = $this->_registration->transaction()
1330
-                ? $this->_registration->transaction()
1331
-                : EE_Transaction::new_instance();
1332
-            $this->_session                                = $transaction->session_data();
1333
-            $event_id                                      = $this->_registration->event_ID();
1334
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1335
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1336
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1337
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1338
-            $this->_template_args['grand_total']           = $transaction->total();
1339
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1340
-            // link back to overview
1341
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1342
-            $this->_template_args['registration']                = $this->_registration;
1343
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
-                [
1345
-                    'action'   => 'default',
1346
-                    'event_id' => $event_id,
1347
-                ],
1348
-                REG_ADMIN_URL
1349
-            );
1350
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1351
-                [
1352
-                    'action' => 'default',
1353
-                    'EVT_ID' => $event_id,
1354
-                    'page'   => 'espresso_transactions',
1355
-                ],
1356
-                admin_url('admin.php')
1357
-            );
1358
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1359
-                [
1360
-                    'page'   => 'espresso_events',
1361
-                    'action' => 'edit',
1362
-                    'post'   => $event_id,
1363
-                ],
1364
-                admin_url('admin.php')
1365
-            );
1366
-            // next and previous links
1367
-            $next_reg                                      = $this->_registration->next(
1368
-                null,
1369
-                [],
1370
-                'REG_ID'
1371
-            );
1372
-            $this->_template_args['next_registration']     = $next_reg
1373
-                ? $this->_next_link(
1374
-                    EE_Admin_Page::add_query_args_and_nonce(
1375
-                        [
1376
-                            'action'  => 'view_registration',
1377
-                            '_REG_ID' => $next_reg['REG_ID'],
1378
-                        ],
1379
-                        REG_ADMIN_URL
1380
-                    ),
1381
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1382
-                )
1383
-                : '';
1384
-            $previous_reg                                  = $this->_registration->previous(
1385
-                null,
1386
-                [],
1387
-                'REG_ID'
1388
-            );
1389
-            $this->_template_args['previous_registration'] = $previous_reg
1390
-                ? $this->_previous_link(
1391
-                    EE_Admin_Page::add_query_args_and_nonce(
1392
-                        [
1393
-                            'action'  => 'view_registration',
1394
-                            '_REG_ID' => $previous_reg['REG_ID'],
1395
-                        ],
1396
-                        REG_ADMIN_URL
1397
-                    ),
1398
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1399
-                )
1400
-                : '';
1401
-            // grab header
1402
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1403
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1404
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1405
-                $template_path,
1406
-                $this->_template_args,
1407
-                true
1408
-            );
1409
-        } else {
1410
-            $this->_template_args['admin_page_header'] = '';
1411
-            $this->_display_espresso_notices();
1412
-        }
1413
-        // the details template wrapper
1414
-        $this->display_admin_page_with_sidebar();
1415
-    }
1416
-
1417
-
1418
-    /**
1419
-     * @throws EE_Error
1420
-     * @throws InvalidArgumentException
1421
-     * @throws InvalidDataTypeException
1422
-     * @throws InvalidInterfaceException
1423
-     * @throws ReflectionException
1424
-     * @since 4.10.2.p
1425
-     */
1426
-    protected function _registration_details_metaboxes()
1427
-    {
1428
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1429
-        $this->_set_registration_object();
1430
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1431
-        add_meta_box(
1432
-            'edit-reg-status-mbox',
1433
-            esc_html__('Registration Status', 'event_espresso'),
1434
-            [$this, 'set_reg_status_buttons_metabox'],
1435
-            $this->_wp_page_slug,
1436
-            'normal',
1437
-            'high'
1438
-        );
1439
-        add_meta_box(
1440
-            'edit-reg-details-mbox',
1441
-            esc_html__('Registration Details', 'event_espresso'),
1442
-            [$this, '_reg_details_meta_box'],
1443
-            $this->_wp_page_slug,
1444
-            'normal',
1445
-            'high'
1446
-        );
1447
-        if (
1448
-            $attendee instanceof EE_Attendee
1449
-            && EE_Registry::instance()->CAP->current_user_can(
1450
-                'ee_read_registration',
1451
-                'edit-reg-questions-mbox',
1452
-                $this->_registration->ID()
1453
-            )
1454
-        ) {
1455
-            add_meta_box(
1456
-                'edit-reg-questions-mbox',
1457
-                esc_html__('Registration Form Answers', 'event_espresso'),
1458
-                [$this, '_reg_questions_meta_box'],
1459
-                $this->_wp_page_slug,
1460
-                'normal',
1461
-                'high'
1462
-            );
1463
-        }
1464
-        add_meta_box(
1465
-            'edit-reg-registrant-mbox',
1466
-            esc_html__('Contact Details', 'event_espresso'),
1467
-            [$this, '_reg_registrant_side_meta_box'],
1468
-            $this->_wp_page_slug,
1469
-            'side',
1470
-            'high'
1471
-        );
1472
-        if ($this->_registration->group_size() > 1) {
1473
-            add_meta_box(
1474
-                'edit-reg-attendees-mbox',
1475
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1476
-                [$this, '_reg_attendees_meta_box'],
1477
-                $this->_wp_page_slug,
1478
-                'normal',
1479
-                'high'
1480
-            );
1481
-        }
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * set_reg_status_buttons_metabox
1487
-     *
1488
-     * @return void
1489
-     * @throws EE_Error
1490
-     * @throws EntityNotFoundException
1491
-     * @throws InvalidArgumentException
1492
-     * @throws InvalidDataTypeException
1493
-     * @throws InvalidInterfaceException
1494
-     * @throws ReflectionException
1495
-     */
1496
-    public function set_reg_status_buttons_metabox()
1497
-    {
1498
-        $this->_set_registration_object();
1499
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1500
-        $output                 = $change_reg_status_form->form_open(
1501
-            self::add_query_args_and_nonce(
1502
-                [
1503
-                    'action' => 'change_reg_status',
1504
-                ],
1505
-                REG_ADMIN_URL
1506
-            )
1507
-        );
1508
-        $output                 .= $change_reg_status_form->get_html();
1509
-        $output                 .= $change_reg_status_form->form_close();
1510
-        echo $output; // already escaped
1511
-    }
1512
-
1513
-
1514
-    /**
1515
-     * @return EE_Form_Section_Proper
1516
-     * @throws EE_Error
1517
-     * @throws InvalidArgumentException
1518
-     * @throws InvalidDataTypeException
1519
-     * @throws InvalidInterfaceException
1520
-     * @throws EntityNotFoundException
1521
-     * @throws ReflectionException
1522
-     */
1523
-    protected function _generate_reg_status_change_form()
1524
-    {
1525
-        $reg_status_change_form_array = [
1526
-            'name'            => 'reg_status_change_form',
1527
-            'html_id'         => 'reg-status-change-form',
1528
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1529
-            'subsections'     => [
1530
-                'return'         => new EE_Hidden_Input(
1531
-                    [
1532
-                        'name'    => 'return',
1533
-                        'default' => 'view_registration',
1534
-                    ]
1535
-                ),
1536
-                'REG_ID'         => new EE_Hidden_Input(
1537
-                    [
1538
-                        'name'    => 'REG_ID',
1539
-                        'default' => $this->_registration->ID(),
1540
-                    ]
1541
-                ),
1542
-                'current_status' => new EE_Form_Section_HTML(
1543
-                    EEH_HTML::table(
1544
-                        EEH_HTML::tr(
1545
-                            EEH_HTML::th(
1546
-                                EEH_HTML::label(
1547
-                                    EEH_HTML::strong(
1548
-                                        esc_html__('Current Registration Status', 'event_espresso')
1549
-                                    )
1550
-                                )
1551
-                            )
1552
-                            . EEH_HTML::td(
1553
-                                EEH_HTML::strong(
1554
-                                    $this->_registration->pretty_status(),
1555
-                                    '',
1556
-                                    'status-' . $this->_registration->status_ID(),
1557
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1558
-                                )
1559
-                            )
1560
-                        )
1561
-                    )
1562
-                ),
1563
-            ],
1564
-        ];
1565
-        if (
1566
-            EE_Registry::instance()->CAP->current_user_can(
1567
-                'ee_edit_registration',
1568
-                'toggle_registration_status',
1569
-                $this->_registration->ID()
1570
-            )
1571
-        ) {
1572
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1573
-                $this->_get_reg_statuses(),
1574
-                [
1575
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1576
-                    'default'         => $this->_registration->status_ID(),
1577
-                ]
1578
-            );
1579
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1580
-                [
1581
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1582
-                    'default'         => false,
1583
-                    'html_help_text'  => esc_html__(
1584
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1585
-                        'event_espresso'
1586
-                    ),
1587
-                ]
1588
-            );
1589
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1590
-                [
1591
-                    'html_class'      => 'button-primary',
1592
-                    'html_label_text' => '&nbsp;',
1593
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1594
-                ]
1595
-            );
1596
-        }
1597
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     * Returns an array of all the buttons for the various statuses and switch status actions
1603
-     *
1604
-     * @return array
1605
-     * @throws EE_Error
1606
-     * @throws InvalidArgumentException
1607
-     * @throws InvalidDataTypeException
1608
-     * @throws InvalidInterfaceException
1609
-     * @throws EntityNotFoundException
1610
-     */
1611
-    protected function _get_reg_statuses()
1612
-    {
1613
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1614
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1615
-        // get current reg status
1616
-        $current_status = $this->_registration->status_ID();
1617
-        // is registration for free event? This will determine whether to display the pending payment option
1618
-        if (
1619
-            $current_status !== EEM_Registration::status_id_pending_payment
1620
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1621
-        ) {
1622
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1623
-        }
1624
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1625
-    }
1626
-
1627
-
1628
-    /**
1629
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1630
-     *
1631
-     * @param bool $status REG status given for changing registrations to.
1632
-     * @param bool $notify Whether to send messages notifications or not.
1633
-     * @return array (array with reg_id(s) updated and whether update was successful.
1634
-     * @throws DomainException
1635
-     * @throws EE_Error
1636
-     * @throws EntityNotFoundException
1637
-     * @throws InvalidArgumentException
1638
-     * @throws InvalidDataTypeException
1639
-     * @throws InvalidInterfaceException
1640
-     * @throws ReflectionException
1641
-     * @throws RuntimeException
1642
-     */
1643
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1644
-    {
1645
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1646
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1647
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1648
-
1649
-        // sanitize $REG_IDs
1650
-        $REG_IDs = array_map('absint', $REG_IDs);
1651
-        // and remove empty entries
1652
-        $REG_IDs = array_filter($REG_IDs);
1653
-
1654
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1655
-
1656
-        /**
1657
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1658
-         * Currently this value is used downstream by the _process_resend_registration method.
1659
-         *
1660
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1661
-         * @param bool                     $status           The status registrations were changed to.
1662
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1663
-         * @param Registrations_Admin_Page $admin_page_object
1664
-         */
1665
-        $REG_ID = apply_filters(
1666
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1667
-            $result['REG_ID'],
1668
-            $status,
1669
-            $result['success'],
1670
-            $this
1671
-        );
1672
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1673
-
1674
-        // notify?
1675
-        if (
1676
-            $notify
1677
-            && $result['success']
1678
-            && ! empty($REG_ID)
1679
-            && EE_Registry::instance()->CAP->current_user_can(
1680
-                'ee_send_message',
1681
-                'espresso_registrations_resend_registration'
1682
-            )
1683
-        ) {
1684
-            $this->_process_resend_registration();
1685
-        }
1686
-        return $result;
1687
-    }
1688
-
1689
-
1690
-    /**
1691
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1692
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1693
-     *
1694
-     * @param array  $REG_IDs
1695
-     * @param string $status
1696
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1697
-     *                       slug sent with setting the registration status.
1698
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1699
-     * @throws EE_Error
1700
-     * @throws InvalidArgumentException
1701
-     * @throws InvalidDataTypeException
1702
-     * @throws InvalidInterfaceException
1703
-     * @throws ReflectionException
1704
-     * @throws RuntimeException
1705
-     * @throws EntityNotFoundException
1706
-     * @throws DomainException
1707
-     */
1708
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1709
-    {
1710
-        $success = false;
1711
-        // typecast $REG_IDs
1712
-        $REG_IDs = (array) $REG_IDs;
1713
-        if (! empty($REG_IDs)) {
1714
-            $success = true;
1715
-            // set default status if none is passed
1716
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1717
-            $status_context = $notify
1718
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1719
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1720
-            // loop through REG_ID's and change status
1721
-            foreach ($REG_IDs as $REG_ID) {
1722
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1723
-                if ($registration instanceof EE_Registration) {
1724
-                    $registration->set_status(
1725
-                        $status,
1726
-                        false,
1727
-                        new Context(
1728
-                            $status_context,
1729
-                            esc_html__(
1730
-                                'Manually triggered status change on a Registration Admin Page route.',
1731
-                                'event_espresso'
1732
-                            )
1733
-                        )
1734
-                    );
1735
-                    $result = $registration->save();
1736
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1737
-                    $success = $result !== false ? $success : false;
1738
-                }
1739
-            }
1740
-        }
1741
-
1742
-        // return $success and processed registrations
1743
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1744
-    }
1745
-
1746
-
1747
-    /**
1748
-     * Common logic for setting up success message and redirecting to appropriate route
1749
-     *
1750
-     * @param string $STS_ID status id for the registration changed to
1751
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1752
-     * @return void
1753
-     * @throws DomainException
1754
-     * @throws EE_Error
1755
-     * @throws EntityNotFoundException
1756
-     * @throws InvalidArgumentException
1757
-     * @throws InvalidDataTypeException
1758
-     * @throws InvalidInterfaceException
1759
-     * @throws ReflectionException
1760
-     * @throws RuntimeException
1761
-     */
1762
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1763
-    {
1764
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1765
-            : ['success' => false];
1766
-        $success = isset($result['success']) && $result['success'];
1767
-        // setup success message
1768
-        if ($success) {
1769
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1770
-                $msg = sprintf(
1771
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1772
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
-                );
1774
-            } else {
1775
-                $msg = sprintf(
1776
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1777
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1778
-                );
1779
-            }
1780
-            EE_Error::add_success($msg);
1781
-        } else {
1782
-            EE_Error::add_error(
1783
-                esc_html__(
1784
-                    'Something went wrong, and the status was not changed',
1785
-                    'event_espresso'
1786
-                ),
1787
-                __FILE__,
1788
-                __LINE__,
1789
-                __FUNCTION__
1790
-            );
1791
-        }
1792
-        $return = $this->request->getRequestParam('return');
1793
-        $route  = $return === 'view_registration'
1794
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1795
-            : ['action' => 'default'];
1796
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1797
-        $this->_redirect_after_action($success, '', '', $route, true);
1798
-    }
1799
-
1800
-
1801
-    /**
1802
-     * incoming reg status change from reg details page.
1803
-     *
1804
-     * @return void
1805
-     * @throws EE_Error
1806
-     * @throws EntityNotFoundException
1807
-     * @throws InvalidArgumentException
1808
-     * @throws InvalidDataTypeException
1809
-     * @throws InvalidInterfaceException
1810
-     * @throws ReflectionException
1811
-     * @throws RuntimeException
1812
-     * @throws DomainException
1813
-     */
1814
-    protected function _change_reg_status()
1815
-    {
1816
-        $this->request->setRequestParam('return', 'view_registration');
1817
-        // set notify based on whether the send notifications toggle is set or not
1818
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1819
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1820
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1821
-        switch ($reg_status) {
1822
-            case EEM_Registration::status_id_approved:
1823
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1824
-                $this->approve_registration($notify);
1825
-                break;
1826
-            case EEM_Registration::status_id_pending_payment:
1827
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1828
-                $this->pending_registration($notify);
1829
-                break;
1830
-            case EEM_Registration::status_id_not_approved:
1831
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1832
-                $this->not_approve_registration($notify);
1833
-                break;
1834
-            case EEM_Registration::status_id_declined:
1835
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1836
-                $this->decline_registration($notify);
1837
-                break;
1838
-            case EEM_Registration::status_id_cancelled:
1839
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1840
-                $this->cancel_registration($notify);
1841
-                break;
1842
-            case EEM_Registration::status_id_wait_list:
1843
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1844
-                $this->wait_list_registration($notify);
1845
-                break;
1846
-            case EEM_Registration::status_id_incomplete:
1847
-            default:
1848
-                $this->request->unSetRequestParam('return');
1849
-                $this->_reg_status_change_return('');
1850
-                break;
1851
-        }
1852
-    }
1853
-
1854
-
1855
-    /**
1856
-     * Callback for bulk action routes.
1857
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1858
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1859
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1860
-     * when an action is happening on just a single registration).
1861
-     *
1862
-     * @param      $action
1863
-     * @param bool $notify
1864
-     */
1865
-    protected function bulk_action_on_registrations($action, $notify = false)
1866
-    {
1867
-        do_action(
1868
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1869
-            $this,
1870
-            $action,
1871
-            $notify
1872
-        );
1873
-        $method = $action . '_registration';
1874
-        if (method_exists($this, $method)) {
1875
-            $this->$method($notify);
1876
-        }
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * approve_registration
1882
-     *
1883
-     * @param bool $notify whether or not to notify the registrant about their approval.
1884
-     * @return void
1885
-     * @throws EE_Error
1886
-     * @throws EntityNotFoundException
1887
-     * @throws InvalidArgumentException
1888
-     * @throws InvalidDataTypeException
1889
-     * @throws InvalidInterfaceException
1890
-     * @throws ReflectionException
1891
-     * @throws RuntimeException
1892
-     * @throws DomainException
1893
-     */
1894
-    protected function approve_registration($notify = false)
1895
-    {
1896
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     * decline_registration
1902
-     *
1903
-     * @param bool $notify whether or not to notify the registrant about their status change.
1904
-     * @return void
1905
-     * @throws EE_Error
1906
-     * @throws EntityNotFoundException
1907
-     * @throws InvalidArgumentException
1908
-     * @throws InvalidDataTypeException
1909
-     * @throws InvalidInterfaceException
1910
-     * @throws ReflectionException
1911
-     * @throws RuntimeException
1912
-     * @throws DomainException
1913
-     */
1914
-    protected function decline_registration($notify = false)
1915
-    {
1916
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     * cancel_registration
1922
-     *
1923
-     * @param bool $notify whether or not to notify the registrant about their status change.
1924
-     * @return void
1925
-     * @throws EE_Error
1926
-     * @throws EntityNotFoundException
1927
-     * @throws InvalidArgumentException
1928
-     * @throws InvalidDataTypeException
1929
-     * @throws InvalidInterfaceException
1930
-     * @throws ReflectionException
1931
-     * @throws RuntimeException
1932
-     * @throws DomainException
1933
-     */
1934
-    protected function cancel_registration($notify = false)
1935
-    {
1936
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1937
-    }
1938
-
1939
-
1940
-    /**
1941
-     * not_approve_registration
1942
-     *
1943
-     * @param bool $notify whether or not to notify the registrant about their status change.
1944
-     * @return void
1945
-     * @throws EE_Error
1946
-     * @throws EntityNotFoundException
1947
-     * @throws InvalidArgumentException
1948
-     * @throws InvalidDataTypeException
1949
-     * @throws InvalidInterfaceException
1950
-     * @throws ReflectionException
1951
-     * @throws RuntimeException
1952
-     * @throws DomainException
1953
-     */
1954
-    protected function not_approve_registration($notify = false)
1955
-    {
1956
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1957
-    }
1958
-
1959
-
1960
-    /**
1961
-     * decline_registration
1962
-     *
1963
-     * @param bool $notify whether or not to notify the registrant about their status change.
1964
-     * @return void
1965
-     * @throws EE_Error
1966
-     * @throws EntityNotFoundException
1967
-     * @throws InvalidArgumentException
1968
-     * @throws InvalidDataTypeException
1969
-     * @throws InvalidInterfaceException
1970
-     * @throws ReflectionException
1971
-     * @throws RuntimeException
1972
-     * @throws DomainException
1973
-     */
1974
-    protected function pending_registration($notify = false)
1975
-    {
1976
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1977
-    }
1978
-
1979
-
1980
-    /**
1981
-     * waitlist_registration
1982
-     *
1983
-     * @param bool $notify whether or not to notify the registrant about their status change.
1984
-     * @return void
1985
-     * @throws EE_Error
1986
-     * @throws EntityNotFoundException
1987
-     * @throws InvalidArgumentException
1988
-     * @throws InvalidDataTypeException
1989
-     * @throws InvalidInterfaceException
1990
-     * @throws ReflectionException
1991
-     * @throws RuntimeException
1992
-     * @throws DomainException
1993
-     */
1994
-    protected function wait_list_registration($notify = false)
1995
-    {
1996
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
-    }
1998
-
1999
-
2000
-    /**
2001
-     * generates HTML for the Registration main meta box
2002
-     *
2003
-     * @return void
2004
-     * @throws DomainException
2005
-     * @throws EE_Error
2006
-     * @throws InvalidArgumentException
2007
-     * @throws InvalidDataTypeException
2008
-     * @throws InvalidInterfaceException
2009
-     * @throws ReflectionException
2010
-     * @throws EntityNotFoundException
2011
-     */
2012
-    public function _reg_details_meta_box()
2013
-    {
2014
-        EEH_Autoloader::register_line_item_display_autoloaders();
2015
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2016
-        EE_Registry::instance()->load_helper('Line_Item');
2017
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2018
-            : EE_Transaction::new_instance();
2019
-        $this->_session = $transaction->session_data();
2020
-        $filters        = new EE_Line_Item_Filter_Collection();
2021
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2022
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2023
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2024
-            $filters,
2025
-            $transaction->total_line_item()
2026
-        );
2027
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2028
-        $line_item_display                       = new EE_Line_Item_Display(
2029
-            'reg_admin_table',
2030
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2031
-        );
2032
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2033
-            $filtered_line_item_tree,
2034
-            ['EE_Registration' => $this->_registration]
2035
-        );
2036
-        $attendee                                = $this->_registration->attendee();
2037
-        if (
2038
-            EE_Registry::instance()->CAP->current_user_can(
2039
-                'ee_read_transaction',
2040
-                'espresso_transactions_view_transaction'
2041
-            )
2042
-        ) {
2043
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2044
-                EE_Admin_Page::add_query_args_and_nonce(
2045
-                    [
2046
-                        'action' => 'view_transaction',
2047
-                        'TXN_ID' => $transaction->ID(),
2048
-                    ],
2049
-                    TXN_ADMIN_URL
2050
-                ),
2051
-                esc_html__(' View Transaction', 'event_espresso'),
2052
-                'button secondary-button right',
2053
-                'dashicons dashicons-cart'
2054
-            );
2055
-        } else {
2056
-            $this->_template_args['view_transaction_button'] = '';
2057
-        }
2058
-        if (
2059
-            $attendee instanceof EE_Attendee
2060
-            && EE_Registry::instance()->CAP->current_user_can(
2061
-                'ee_send_message',
2062
-                'espresso_registrations_resend_registration'
2063
-            )
2064
-        ) {
2065
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2066
-                EE_Admin_Page::add_query_args_and_nonce(
2067
-                    [
2068
-                        'action'      => 'resend_registration',
2069
-                        '_REG_ID'     => $this->_registration->ID(),
2070
-                        'redirect_to' => 'view_registration',
2071
-                    ],
2072
-                    REG_ADMIN_URL
2073
-                ),
2074
-                esc_html__(' Resend Registration', 'event_espresso'),
2075
-                'button secondary-button right',
2076
-                'dashicons dashicons-email-alt'
2077
-            );
2078
-        } else {
2079
-            $this->_template_args['resend_registration_button'] = '';
2080
-        }
2081
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2082
-        $payment                               = $transaction->get_first_related('Payment');
2083
-        $payment                               = ! $payment instanceof EE_Payment
2084
-            ? EE_Payment::new_instance()
2085
-            : $payment;
2086
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2087
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2088
-            ? EE_Payment_Method::new_instance()
2089
-            : $payment_method;
2090
-        $reg_details                           = [
2091
-            'payment_method'       => $payment_method->name(),
2092
-            'response_msg'         => $payment->gateway_response(),
2093
-            'registration_id'      => $this->_registration->get('REG_code'),
2094
-            'registration_session' => $this->_registration->session_ID(),
2095
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2096
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2097
-        ];
2098
-        if (isset($reg_details['registration_id'])) {
2099
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2100
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2101
-                'Registration ID',
2102
-                'event_espresso'
2103
-            );
2104
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2105
-        }
2106
-        if (isset($reg_details['payment_method'])) {
2107
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2108
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2109
-                'Most Recent Payment Method',
2110
-                'event_espresso'
2111
-            );
2112
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2113
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2114
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2115
-                'Payment method response',
2116
-                'event_espresso'
2117
-            );
2118
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2119
-        }
2120
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2121
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2122
-            'Registration Session',
2123
-            'event_espresso'
2124
-        );
2125
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2126
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2127
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2128
-            'Registration placed from IP',
2129
-            'event_espresso'
2130
-        );
2131
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2132
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2133
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2134
-            'Registrant User Agent',
2135
-            'event_espresso'
2136
-        );
2137
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2138
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2139
-            [
2140
-                'action'   => 'default',
2141
-                'event_id' => $this->_registration->event_ID(),
2142
-            ],
2143
-            REG_ADMIN_URL
2144
-        );
2145
-
2146
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2147
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2148
-
2149
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2150
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2151
-    }
2152
-
2153
-
2154
-    /**
2155
-     * generates HTML for the Registration Questions meta box.
2156
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2157
-     * otherwise uses new forms system
2158
-     *
2159
-     * @return void
2160
-     * @throws DomainException
2161
-     * @throws EE_Error
2162
-     * @throws InvalidArgumentException
2163
-     * @throws InvalidDataTypeException
2164
-     * @throws InvalidInterfaceException
2165
-     * @throws ReflectionException
2166
-     */
2167
-    public function _reg_questions_meta_box()
2168
-    {
2169
-        // allow someone to override this method entirely
2170
-        if (
2171
-            apply_filters(
2172
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2173
-                true,
2174
-                $this,
2175
-                $this->_registration
2176
-            )
2177
-        ) {
2178
-            $form = $this->_get_reg_custom_questions_form(
2179
-                $this->_registration->ID()
2180
-            );
2181
-
2182
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2183
-                ? $form->get_html_and_js()
2184
-                : '';
2185
-
2186
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2187
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2188
-            $template_path = 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 '
22
+	/**
23
+	 * @var EE_Registration
24
+	 */
25
+	private $_registration;
26
+
27
+	/**
28
+	 * @var EE_Event
29
+	 */
30
+	private $_reg_event;
31
+
32
+	/**
33
+	 * @var EE_Session
34
+	 */
35
+	private $_session;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private static $_reg_status;
41
+
42
+	/**
43
+	 * Form for displaying the custom questions for this registration.
44
+	 * This gets used a few times throughout the request so its best to cache it
45
+	 *
46
+	 * @var EE_Registration_Custom_Questions_Form
47
+	 */
48
+	protected $_reg_custom_questions_form;
49
+
50
+	/**
51
+	 * @var EEM_Registration $registration_model
52
+	 */
53
+	private $registration_model;
54
+
55
+	/**
56
+	 * @var EEM_Attendee $attendee_model
57
+	 */
58
+	private $attendee_model;
59
+
60
+	/**
61
+	 * @var EEM_Event $event_model
62
+	 */
63
+	private $event_model;
64
+
65
+	/**
66
+	 * @var EEM_Status $status_model
67
+	 */
68
+	private $status_model;
69
+
70
+
71
+	/**
72
+	 * @param bool $routing
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws ReflectionException
78
+	 */
79
+	public function __construct($routing = true)
80
+	{
81
+		parent::__construct($routing);
82
+		add_action('wp_loaded', [$this, 'wp_loaded']);
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return EEM_Registration
88
+	 * @throws InvalidArgumentException
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @since 4.10.2.p
92
+	 */
93
+	protected function getRegistrationModel()
94
+	{
95
+		if (! $this->registration_model instanceof EEM_Registration) {
96
+			$this->registration_model = $this->loader->getShared('EEM_Registration');
97
+		}
98
+		return $this->registration_model;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return EEM_Attendee
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @since 4.10.2.p
108
+	 */
109
+	protected function getAttendeeModel()
110
+	{
111
+		if (! $this->attendee_model instanceof EEM_Attendee) {
112
+			$this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
+		}
114
+		return $this->attendee_model;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return EEM_Event
120
+	 * @throws InvalidArgumentException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 * @since 4.10.2.p
124
+	 */
125
+	protected function getEventModel()
126
+	{
127
+		if (! $this->event_model instanceof EEM_Event) {
128
+			$this->event_model = $this->loader->getShared('EEM_Event');
129
+		}
130
+		return $this->event_model;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return EEM_Status
136
+	 * @throws InvalidArgumentException
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @since 4.10.2.p
140
+	 */
141
+	protected function getStatusModel()
142
+	{
143
+		if (! $this->status_model instanceof EEM_Status) {
144
+			$this->status_model = $this->loader->getShared('EEM_Status');
145
+		}
146
+		return $this->status_model;
147
+	}
148
+
149
+
150
+	public function wp_loaded()
151
+	{
152
+		// when adding a new registration...
153
+		$action = $this->request->getRequestParam('action');
154
+		if ($action === 'new_registration') {
155
+			EE_System::do_not_cache();
156
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
+				// and it's NOT the attendee information reg step
158
+				// force cookie expiration by setting time to last week
159
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
+				// and update the global
161
+				$_COOKIE['ee_registration_added'] = 0;
162
+			}
163
+		}
164
+	}
165
+
166
+
167
+	protected function _init_page_props()
168
+	{
169
+		$this->page_slug        = REG_PG_SLUG;
170
+		$this->_admin_base_url  = REG_ADMIN_URL;
171
+		$this->_admin_base_path = REG_ADMIN;
172
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
173
+		$this->_cpt_routes      = [
174
+			'add_new_attendee' => 'espresso_attendees',
175
+			'edit_attendee'    => 'espresso_attendees',
176
+			'insert_attendee'  => 'espresso_attendees',
177
+			'update_attendee'  => 'espresso_attendees',
178
+		];
179
+		$this->_cpt_model_names = [
180
+			'add_new_attendee' => 'EEM_Attendee',
181
+			'edit_attendee'    => 'EEM_Attendee',
182
+		];
183
+		$this->_cpt_edit_routes = [
184
+			'espresso_attendees' => 'edit_attendee',
185
+		];
186
+		$this->_pagenow_map     = [
187
+			'add_new_attendee' => 'post-new.php',
188
+			'edit_attendee'    => 'post.php',
189
+			'trash'            => 'post.php',
190
+		];
191
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
+		// add filters so that the comment urls don't take users to a confusing 404 page
193
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
199
+	 * @param WP_Comment $comment The current comment object.
200
+	 * @return string
201
+	 */
202
+	public function clear_comment_link($link, WP_Comment $comment)
203
+	{
204
+		// gotta make sure this only happens on this route
205
+		$post_type = get_post_type($comment->comment_post_ID);
206
+		if ($post_type === 'espresso_attendees') {
207
+			return '#commentsdiv';
208
+		}
209
+		return $link;
210
+	}
211
+
212
+
213
+	protected function _ajax_hooks()
214
+	{
215
+		// todo: all hooks for registrations ajax goes in here
216
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
+	}
218
+
219
+
220
+	protected function _define_page_props()
221
+	{
222
+		$this->_admin_page_title = $this->page_label;
223
+		$this->_labels           = [
224
+			'buttons'                      => [
225
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
+			],
234
+			'publishbox'                   => [
235
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
+			],
238
+			'hide_add_button_on_cpt_route' => [
239
+				'edit_attendee' => true,
240
+			],
241
+		];
242
+	}
243
+
244
+
245
+	/**
246
+	 * grab url requests and route them
247
+	 *
248
+	 * @return void
249
+	 * @throws EE_Error
250
+	 */
251
+	public function _set_page_routes()
252
+	{
253
+		$this->_get_registration_status_array();
254
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
+		$this->_page_routes = [
259
+			'default'                             => [
260
+				'func'       => '_registrations_overview_list_table',
261
+				'capability' => 'ee_read_registrations',
262
+			],
263
+			'view_registration'                   => [
264
+				'func'       => '_registration_details',
265
+				'capability' => 'ee_read_registration',
266
+				'obj_id'     => $REG_ID,
267
+			],
268
+			'edit_registration'                   => [
269
+				'func'               => '_update_attendee_registration_form',
270
+				'noheader'           => true,
271
+				'headers_sent_route' => 'view_registration',
272
+				'capability'         => 'ee_edit_registration',
273
+				'obj_id'             => $REG_ID,
274
+				'_REG_ID'            => $REG_ID,
275
+			],
276
+			'trash_registrations'                 => [
277
+				'func'       => '_trash_or_restore_registrations',
278
+				'args'       => ['trash' => true],
279
+				'noheader'   => true,
280
+				'capability' => 'ee_delete_registrations',
281
+			],
282
+			'restore_registrations'               => [
283
+				'func'       => '_trash_or_restore_registrations',
284
+				'args'       => ['trash' => false],
285
+				'noheader'   => true,
286
+				'capability' => 'ee_delete_registrations',
287
+			],
288
+			'delete_registrations'                => [
289
+				'func'       => '_delete_registrations',
290
+				'noheader'   => true,
291
+				'capability' => 'ee_delete_registrations',
292
+			],
293
+			'new_registration'                    => [
294
+				'func'       => 'new_registration',
295
+				'capability' => 'ee_edit_registrations',
296
+			],
297
+			'process_reg_step'                    => [
298
+				'func'       => 'process_reg_step',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+			],
302
+			'redirect_to_txn'                     => [
303
+				'func'       => 'redirect_to_txn',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+			],
307
+			'change_reg_status'                   => [
308
+				'func'       => '_change_reg_status',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $REG_ID,
312
+			],
313
+			'approve_registration'                => [
314
+				'func'       => 'approve_registration',
315
+				'noheader'   => true,
316
+				'capability' => 'ee_edit_registration',
317
+				'obj_id'     => $REG_ID,
318
+			],
319
+			'approve_and_notify_registration'     => [
320
+				'func'       => 'approve_registration',
321
+				'noheader'   => true,
322
+				'args'       => [true],
323
+				'capability' => 'ee_edit_registration',
324
+				'obj_id'     => $REG_ID,
325
+			],
326
+			'approve_registrations'               => [
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args'       => ['approve'],
331
+			],
332
+			'approve_and_notify_registrations'    => [
333
+				'func'       => 'bulk_action_on_registrations',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registrations',
336
+				'args'       => ['approve', true],
337
+			],
338
+			'decline_registration'                => [
339
+				'func'       => 'decline_registration',
340
+				'noheader'   => true,
341
+				'capability' => 'ee_edit_registration',
342
+				'obj_id'     => $REG_ID,
343
+			],
344
+			'decline_and_notify_registration'     => [
345
+				'func'       => 'decline_registration',
346
+				'noheader'   => true,
347
+				'args'       => [true],
348
+				'capability' => 'ee_edit_registration',
349
+				'obj_id'     => $REG_ID,
350
+			],
351
+			'decline_registrations'               => [
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args'       => ['decline'],
356
+			],
357
+			'decline_and_notify_registrations'    => [
358
+				'func'       => 'bulk_action_on_registrations',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registrations',
361
+				'args'       => ['decline', true],
362
+			],
363
+			'pending_registration'                => [
364
+				'func'       => 'pending_registration',
365
+				'noheader'   => true,
366
+				'capability' => 'ee_edit_registration',
367
+				'obj_id'     => $REG_ID,
368
+			],
369
+			'pending_and_notify_registration'     => [
370
+				'func'       => 'pending_registration',
371
+				'noheader'   => true,
372
+				'args'       => [true],
373
+				'capability' => 'ee_edit_registration',
374
+				'obj_id'     => $REG_ID,
375
+			],
376
+			'pending_registrations'               => [
377
+				'func'       => 'bulk_action_on_registrations',
378
+				'noheader'   => true,
379
+				'capability' => 'ee_edit_registrations',
380
+				'args'       => ['pending'],
381
+			],
382
+			'pending_and_notify_registrations'    => [
383
+				'func'       => 'bulk_action_on_registrations',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_registrations',
386
+				'args'       => ['pending', true],
387
+			],
388
+			'no_approve_registration'             => [
389
+				'func'       => 'not_approve_registration',
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_registration',
392
+				'obj_id'     => $REG_ID,
393
+			],
394
+			'no_approve_and_notify_registration'  => [
395
+				'func'       => 'not_approve_registration',
396
+				'noheader'   => true,
397
+				'args'       => [true],
398
+				'capability' => 'ee_edit_registration',
399
+				'obj_id'     => $REG_ID,
400
+			],
401
+			'no_approve_registrations'            => [
402
+				'func'       => 'bulk_action_on_registrations',
403
+				'noheader'   => true,
404
+				'capability' => 'ee_edit_registrations',
405
+				'args'       => ['not_approve'],
406
+			],
407
+			'no_approve_and_notify_registrations' => [
408
+				'func'       => 'bulk_action_on_registrations',
409
+				'noheader'   => true,
410
+				'capability' => 'ee_edit_registrations',
411
+				'args'       => ['not_approve', true],
412
+			],
413
+			'cancel_registration'                 => [
414
+				'func'       => 'cancel_registration',
415
+				'noheader'   => true,
416
+				'capability' => 'ee_edit_registration',
417
+				'obj_id'     => $REG_ID,
418
+			],
419
+			'cancel_and_notify_registration'      => [
420
+				'func'       => 'cancel_registration',
421
+				'noheader'   => true,
422
+				'args'       => [true],
423
+				'capability' => 'ee_edit_registration',
424
+				'obj_id'     => $REG_ID,
425
+			],
426
+			'cancel_registrations'                => [
427
+				'func'       => 'bulk_action_on_registrations',
428
+				'noheader'   => true,
429
+				'capability' => 'ee_edit_registrations',
430
+				'args'       => ['cancel'],
431
+			],
432
+			'cancel_and_notify_registrations'     => [
433
+				'func'       => 'bulk_action_on_registrations',
434
+				'noheader'   => true,
435
+				'capability' => 'ee_edit_registrations',
436
+				'args'       => ['cancel', true],
437
+			],
438
+			'wait_list_registration'              => [
439
+				'func'       => 'wait_list_registration',
440
+				'noheader'   => true,
441
+				'capability' => 'ee_edit_registration',
442
+				'obj_id'     => $REG_ID,
443
+			],
444
+			'wait_list_and_notify_registration'   => [
445
+				'func'       => 'wait_list_registration',
446
+				'noheader'   => true,
447
+				'args'       => [true],
448
+				'capability' => 'ee_edit_registration',
449
+				'obj_id'     => $REG_ID,
450
+			],
451
+			'contact_list'                        => [
452
+				'func'       => '_attendee_contact_list_table',
453
+				'capability' => 'ee_read_contacts',
454
+			],
455
+			'add_new_attendee'                    => [
456
+				'func' => '_create_new_cpt_item',
457
+				'args' => [
458
+					'new_attendee' => true,
459
+					'capability'   => 'ee_edit_contacts',
460
+				],
461
+			],
462
+			'edit_attendee'                       => [
463
+				'func'       => '_edit_cpt_item',
464
+				'capability' => 'ee_edit_contacts',
465
+				'obj_id'     => $ATT_ID,
466
+			],
467
+			'duplicate_attendee'                  => [
468
+				'func'       => '_duplicate_attendee',
469
+				'noheader'   => true,
470
+				'capability' => 'ee_edit_contacts',
471
+				'obj_id'     => $ATT_ID,
472
+			],
473
+			'insert_attendee'                     => [
474
+				'func'       => '_insert_or_update_attendee',
475
+				'args'       => [
476
+					'new_attendee' => true,
477
+				],
478
+				'noheader'   => true,
479
+				'capability' => 'ee_edit_contacts',
480
+			],
481
+			'update_attendee'                     => [
482
+				'func'       => '_insert_or_update_attendee',
483
+				'args'       => [
484
+					'new_attendee' => false,
485
+				],
486
+				'noheader'   => true,
487
+				'capability' => 'ee_edit_contacts',
488
+				'obj_id'     => $ATT_ID,
489
+			],
490
+			'trash_attendees'                     => [
491
+				'func'       => '_trash_or_restore_attendees',
492
+				'args'       => [
493
+					'trash' => 'true',
494
+				],
495
+				'noheader'   => true,
496
+				'capability' => 'ee_delete_contacts',
497
+			],
498
+			'trash_attendee'                      => [
499
+				'func'       => '_trash_or_restore_attendees',
500
+				'args'       => [
501
+					'trash' => true,
502
+				],
503
+				'noheader'   => true,
504
+				'capability' => 'ee_delete_contacts',
505
+				'obj_id'     => $ATT_ID,
506
+			],
507
+			'restore_attendees'                   => [
508
+				'func'       => '_trash_or_restore_attendees',
509
+				'args'       => [
510
+					'trash' => false,
511
+				],
512
+				'noheader'   => true,
513
+				'capability' => 'ee_delete_contacts',
514
+				'obj_id'     => $ATT_ID,
515
+			],
516
+			'resend_registration'                 => [
517
+				'func'       => '_resend_registration',
518
+				'noheader'   => true,
519
+				'capability' => 'ee_send_message',
520
+			],
521
+			'registrations_report'                => [
522
+				'func'       => '_registrations_report',
523
+				'noheader'   => true,
524
+				'capability' => 'ee_read_registrations',
525
+			],
526
+			'contact_list_export'                 => [
527
+				'func'       => '_contact_list_export',
528
+				'noheader'   => true,
529
+				'capability' => 'export',
530
+			],
531
+			'contact_list_report'                 => [
532
+				'func'       => '_contact_list_report',
533
+				'noheader'   => true,
534
+				'capability' => 'ee_read_contacts',
535
+			],
536
+		];
537
+	}
538
+
539
+
540
+	protected function _set_page_config()
541
+	{
542
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
+		$this->_page_config = [
545
+			'default'           => [
546
+				'nav'           => [
547
+					'label' => esc_html__('Overview', 'event_espresso'),
548
+					'order' => 5,
549
+				],
550
+				'help_tabs'     => [
551
+					'registrations_overview_help_tab'                       => [
552
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
+						'filename' => 'registrations_overview',
554
+					],
555
+					'registrations_overview_table_column_headings_help_tab' => [
556
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
+						'filename' => 'registrations_overview_table_column_headings',
558
+					],
559
+					'registrations_overview_filters_help_tab'               => [
560
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
+						'filename' => 'registrations_overview_filters',
562
+					],
563
+					'registrations_overview_views_help_tab'                 => [
564
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
565
+						'filename' => 'registrations_overview_views',
566
+					],
567
+					'registrations_regoverview_other_help_tab'              => [
568
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
+						'filename' => 'registrations_overview_other',
570
+					],
571
+				],
572
+				'qtips'         => ['Registration_List_Table_Tips'],
573
+				'list_table'    => 'EE_Registrations_List_Table',
574
+				'require_nonce' => false,
575
+			],
576
+			'view_registration' => [
577
+				'nav'           => [
578
+					'label'      => esc_html__('REG Details', 'event_espresso'),
579
+					'order'      => 15,
580
+					'url'        => $REG_ID
581
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
+						: $this->_admin_base_url,
583
+					'persistent' => false,
584
+				],
585
+				'help_tabs'     => [
586
+					'registrations_details_help_tab'                    => [
587
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
588
+						'filename' => 'registrations_details',
589
+					],
590
+					'registrations_details_table_help_tab'              => [
591
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
+						'filename' => 'registrations_details_table',
593
+					],
594
+					'registrations_details_form_answers_help_tab'       => [
595
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
+						'filename' => 'registrations_details_form_answers',
597
+					],
598
+					'registrations_details_registrant_details_help_tab' => [
599
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
600
+						'filename' => 'registrations_details_registrant_details',
601
+					],
602
+				],
603
+				'metaboxes'     => array_merge(
604
+					$this->_default_espresso_metaboxes,
605
+					['_registration_details_metaboxes']
606
+				),
607
+				'require_nonce' => false,
608
+			],
609
+			'new_registration'  => [
610
+				'nav'           => [
611
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
+					'url'        => '#',
613
+					'order'      => 15,
614
+					'persistent' => false,
615
+				],
616
+				'metaboxes'     => $this->_default_espresso_metaboxes,
617
+				'labels'        => [
618
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
+				],
620
+				'require_nonce' => false,
621
+			],
622
+			'add_new_attendee'  => [
623
+				'nav'           => [
624
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
625
+					'order'      => 15,
626
+					'persistent' => false,
627
+				],
628
+				'metaboxes'     => array_merge(
629
+					$this->_default_espresso_metaboxes,
630
+					['_publish_post_box', 'attendee_editor_metaboxes']
631
+				),
632
+				'require_nonce' => false,
633
+			],
634
+			'edit_attendee'     => [
635
+				'nav'           => [
636
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
+					'order'      => 15,
638
+					'persistent' => false,
639
+					'url'        => $ATT_ID
640
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
+						: $this->_admin_base_url,
642
+				],
643
+				'metaboxes'     => ['attendee_editor_metaboxes'],
644
+				'require_nonce' => false,
645
+			],
646
+			'contact_list'      => [
647
+				'nav'           => [
648
+					'label' => esc_html__('Contact List', 'event_espresso'),
649
+					'order' => 20,
650
+				],
651
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
652
+				'help_tabs'     => [
653
+					'registrations_contact_list_help_tab'                       => [
654
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
655
+						'filename' => 'registrations_contact_list',
656
+					],
657
+					'registrations_contact-list_table_column_headings_help_tab' => [
658
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
659
+						'filename' => 'registrations_contact_list_table_column_headings',
660
+					],
661
+					'registrations_contact_list_views_help_tab'                 => [
662
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
663
+						'filename' => 'registrations_contact_list_views',
664
+					],
665
+					'registrations_contact_list_other_help_tab'                 => [
666
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
667
+						'filename' => 'registrations_contact_list_other',
668
+					],
669
+				],
670
+				'metaboxes'     => [],
671
+				'require_nonce' => false,
672
+			],
673
+			// override default cpt routes
674
+			'create_new'        => '',
675
+			'edit'              => '',
676
+		];
677
+	}
678
+
679
+
680
+	/**
681
+	 * The below methods aren't used by this class currently
682
+	 */
683
+	protected function _add_screen_options()
684
+	{
685
+	}
686
+
687
+
688
+	protected function _add_feature_pointers()
689
+	{
690
+	}
691
+
692
+
693
+	public function admin_init()
694
+	{
695
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
696
+			'click "Update Registration Questions" to save your changes',
697
+			'event_espresso'
698
+		);
699
+	}
700
+
701
+
702
+	public function admin_notices()
703
+	{
704
+	}
705
+
706
+
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710
+
711
+
712
+	/**
713
+	 * get list of registration statuses
714
+	 *
715
+	 * @return void
716
+	 * @throws EE_Error
717
+	 */
718
+	private function _get_registration_status_array()
719
+	{
720
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
721
+	}
722
+
723
+
724
+	/**
725
+	 * @throws InvalidArgumentException
726
+	 * @throws InvalidDataTypeException
727
+	 * @throws InvalidInterfaceException
728
+	 * @since 4.10.2.p
729
+	 */
730
+	protected function _add_screen_options_default()
731
+	{
732
+		$this->_per_page_screen_option();
733
+	}
734
+
735
+
736
+	/**
737
+	 * @throws InvalidArgumentException
738
+	 * @throws InvalidDataTypeException
739
+	 * @throws InvalidInterfaceException
740
+	 * @since 4.10.2.p
741
+	 */
742
+	protected function _add_screen_options_contact_list()
743
+	{
744
+		$page_title              = $this->_admin_page_title;
745
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
746
+		$this->_per_page_screen_option();
747
+		$this->_admin_page_title = $page_title;
748
+	}
749
+
750
+
751
+	public function load_scripts_styles()
752
+	{
753
+		// style
754
+		wp_register_style(
755
+			'espresso_reg',
756
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
757
+			['ee-admin-css'],
758
+			EVENT_ESPRESSO_VERSION
759
+		);
760
+		wp_enqueue_style('espresso_reg');
761
+		// script
762
+		wp_register_script(
763
+			'espresso_reg',
764
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
765
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
766
+			EVENT_ESPRESSO_VERSION,
767
+			true
768
+		);
769
+		wp_enqueue_script('espresso_reg');
770
+	}
771
+
772
+
773
+	/**
774
+	 * @throws EE_Error
775
+	 * @throws InvalidArgumentException
776
+	 * @throws InvalidDataTypeException
777
+	 * @throws InvalidInterfaceException
778
+	 * @throws ReflectionException
779
+	 * @since 4.10.2.p
780
+	 */
781
+	public function load_scripts_styles_edit_attendee()
782
+	{
783
+		// stuff to only show up on our attendee edit details page.
784
+		$attendee_details_translations = [
785
+			'att_publish_text' => sprintf(
786
+			/* translators: The date and time */
787
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
788
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
789
+			),
790
+		];
791
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
792
+		wp_enqueue_script('jquery-validate');
793
+	}
794
+
795
+
796
+	/**
797
+	 * @throws EE_Error
798
+	 * @throws InvalidArgumentException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws InvalidInterfaceException
801
+	 * @throws ReflectionException
802
+	 * @since 4.10.2.p
803
+	 */
804
+	public function load_scripts_styles_view_registration()
805
+	{
806
+		// styles
807
+		wp_enqueue_style('espresso-ui-theme');
808
+		// scripts
809
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
810
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
811
+	}
812
+
813
+
814
+	public function load_scripts_styles_contact_list()
815
+	{
816
+		wp_dequeue_style('espresso_reg');
817
+		wp_register_style(
818
+			'espresso_att',
819
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
820
+			['ee-admin-css'],
821
+			EVENT_ESPRESSO_VERSION
822
+		);
823
+		wp_enqueue_style('espresso_att');
824
+	}
825
+
826
+
827
+	public function load_scripts_styles_new_registration()
828
+	{
829
+		wp_register_script(
830
+			'ee-spco-for-admin',
831
+			REG_ASSETS_URL . 'spco_for_admin.js',
832
+			['underscore', 'jquery'],
833
+			EVENT_ESPRESSO_VERSION,
834
+			true
835
+		);
836
+		wp_enqueue_script('ee-spco-for-admin');
837
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
838
+		EE_Form_Section_Proper::wp_enqueue_scripts();
839
+		EED_Ticket_Selector::load_tckt_slctr_assets();
840
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
841
+	}
842
+
843
+
844
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
845
+	{
846
+		add_filter('FHEE_load_EE_messages', '__return_true');
847
+	}
848
+
849
+
850
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
851
+	{
852
+		add_filter('FHEE_load_EE_messages', '__return_true');
853
+	}
854
+
855
+
856
+	/**
857
+	 * @throws EE_Error
858
+	 * @throws InvalidArgumentException
859
+	 * @throws InvalidDataTypeException
860
+	 * @throws InvalidInterfaceException
861
+	 * @throws ReflectionException
862
+	 * @since 4.10.2.p
863
+	 */
864
+	protected function _set_list_table_views_default()
865
+	{
866
+		// for notification related bulk actions we need to make sure only active messengers have an option.
867
+		EED_Messages::set_autoloaders();
868
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
869
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
870
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
871
+		// key= bulk_action_slug, value= message type.
872
+		$match_array = [
873
+			'approve_registrations'    => 'registration',
874
+			'decline_registrations'    => 'declined_registration',
875
+			'pending_registrations'    => 'pending_approval',
876
+			'no_approve_registrations' => 'not_approved_registration',
877
+			'cancel_registrations'     => 'cancelled_registration',
878
+		];
879
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
880
+			'ee_send_message',
881
+			'batch_send_messages'
882
+		);
883
+		/** setup reg status bulk actions **/
884
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
885
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
886
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
887
+				'Approve and Notify Registrations',
888
+				'event_espresso'
889
+			);
890
+		}
891
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
892
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
893
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
894
+				'Decline and Notify Registrations',
895
+				'event_espresso'
896
+			);
897
+		}
898
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
899
+			'Set Registrations to Pending Payment',
900
+			'event_espresso'
901
+		);
902
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
903
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
904
+				'Set Registrations to Pending Payment and Notify',
905
+				'event_espresso'
906
+			);
907
+		}
908
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
909
+			'Set Registrations to Not Approved',
910
+			'event_espresso'
911
+		);
912
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
913
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
914
+				'Set Registrations to Not Approved and Notify',
915
+				'event_espresso'
916
+			);
917
+		}
918
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
919
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
920
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
921
+				'Cancel Registrations and Notify',
922
+				'event_espresso'
923
+			);
924
+		}
925
+		$def_reg_status_actions = apply_filters(
926
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
927
+			$def_reg_status_actions,
928
+			$active_mts,
929
+			$can_send
930
+		);
931
+
932
+		$this->_views = [
933
+			'all'   => [
934
+				'slug'        => 'all',
935
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
936
+				'count'       => 0,
937
+				'bulk_action' => array_merge(
938
+					$def_reg_status_actions,
939
+					[
940
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
941
+					]
942
+				),
943
+			],
944
+			'month' => [
945
+				'slug'        => 'month',
946
+				'label'       => esc_html__('This Month', 'event_espresso'),
947
+				'count'       => 0,
948
+				'bulk_action' => array_merge(
949
+					$def_reg_status_actions,
950
+					[
951
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
952
+					]
953
+				),
954
+			],
955
+			'today' => [
956
+				'slug'        => 'today',
957
+				'label'       => sprintf(
958
+					esc_html__('Today - %s', 'event_espresso'),
959
+					date('M d, Y', current_time('timestamp'))
960
+				),
961
+				'count'       => 0,
962
+				'bulk_action' => array_merge(
963
+					$def_reg_status_actions,
964
+					[
965
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
966
+					]
967
+				),
968
+			],
969
+		];
970
+		if (
971
+			EE_Registry::instance()->CAP->current_user_can(
972
+				'ee_delete_registrations',
973
+				'espresso_registrations_delete_registration'
974
+			)
975
+		) {
976
+			$this->_views['incomplete'] = [
977
+				'slug'        => 'incomplete',
978
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
979
+				'count'       => 0,
980
+				'bulk_action' => [
981
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
+				],
983
+			];
984
+			$this->_views['trash']      = [
985
+				'slug'        => 'trash',
986
+				'label'       => esc_html__('Trash', 'event_espresso'),
987
+				'count'       => 0,
988
+				'bulk_action' => [
989
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
+				],
992
+			];
993
+		}
994
+	}
995
+
996
+
997
+	protected function _set_list_table_views_contact_list()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'        => 'in_use',
1002
+				'label'       => esc_html__('In Use', 'event_espresso'),
1003
+				'count'       => 0,
1004
+				'bulk_action' => [
1005
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
+				],
1007
+			],
1008
+		];
1009
+		if (
1010
+			EE_Registry::instance()->CAP->current_user_can(
1011
+				'ee_delete_contacts',
1012
+				'espresso_registrations_trash_attendees'
1013
+			)
1014
+		) {
1015
+			$this->_views['trash'] = [
1016
+				'slug'        => 'trash',
1017
+				'label'       => esc_html__('Trash', 'event_espresso'),
1018
+				'count'       => 0,
1019
+				'bulk_action' => [
1020
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1021
+				],
1022
+			];
1023
+		}
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * @return array
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	protected function _registration_legend_items()
1032
+	{
1033
+		$fc_items = [
1034
+			'star-icon'        => [
1035
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1037
+			],
1038
+			'view_details'     => [
1039
+				'class' => 'dashicons dashicons-clipboard',
1040
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1041
+			],
1042
+			'edit_attendee'    => [
1043
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1044
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1045
+			],
1046
+			'view_transaction' => [
1047
+				'class' => 'dashicons dashicons-cart',
1048
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1049
+			],
1050
+			'view_invoice'     => [
1051
+				'class' => 'dashicons dashicons-media-spreadsheet',
1052
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1053
+			],
1054
+		];
1055
+		if (
1056
+			EE_Registry::instance()->CAP->current_user_can(
1057
+				'ee_send_message',
1058
+				'espresso_registrations_resend_registration'
1059
+			)
1060
+		) {
1061
+			$fc_items['resend_registration'] = [
1062
+				'class' => 'dashicons dashicons-email-alt',
1063
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1064
+			];
1065
+		} else {
1066
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1067
+		}
1068
+		if (
1069
+			EE_Registry::instance()->CAP->current_user_can(
1070
+				'ee_read_global_messages',
1071
+				'view_filtered_messages'
1072
+			)
1073
+		) {
1074
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1075
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1076
+				$fc_items['view_related_messages'] = [
1077
+					'class' => $related_for_icon['css_class'],
1078
+					'desc'  => $related_for_icon['label'],
1079
+				];
1080
+			}
1081
+		}
1082
+		$sc_items = [
1083
+			'approved_status'   => [
1084
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1085
+				'desc'  => EEH_Template::pretty_status(
1086
+					EEM_Registration::status_id_approved,
1087
+					false,
1088
+					'sentence'
1089
+				),
1090
+			],
1091
+			'pending_status'    => [
1092
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1093
+				'desc'  => EEH_Template::pretty_status(
1094
+					EEM_Registration::status_id_pending_payment,
1095
+					false,
1096
+					'sentence'
1097
+				),
1098
+			],
1099
+			'wait_list'         => [
1100
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1101
+				'desc'  => EEH_Template::pretty_status(
1102
+					EEM_Registration::status_id_wait_list,
1103
+					false,
1104
+					'sentence'
1105
+				),
1106
+			],
1107
+			'incomplete_status' => [
1108
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1109
+				'desc'  => EEH_Template::pretty_status(
1110
+					EEM_Registration::status_id_incomplete,
1111
+					false,
1112
+					'sentence'
1113
+				),
1114
+			],
1115
+			'not_approved'      => [
1116
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1117
+				'desc'  => EEH_Template::pretty_status(
1118
+					EEM_Registration::status_id_not_approved,
1119
+					false,
1120
+					'sentence'
1121
+				),
1122
+			],
1123
+			'declined_status'   => [
1124
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1125
+				'desc'  => EEH_Template::pretty_status(
1126
+					EEM_Registration::status_id_declined,
1127
+					false,
1128
+					'sentence'
1129
+				),
1130
+			],
1131
+			'cancelled_status'  => [
1132
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1133
+				'desc'  => EEH_Template::pretty_status(
1134
+					EEM_Registration::status_id_cancelled,
1135
+					false,
1136
+					'sentence'
1137
+				),
1138
+			],
1139
+		];
1140
+		return array_merge($fc_items, $sc_items);
1141
+	}
1142
+
1143
+
1144
+
1145
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1146
+
1147
+
1148
+	/**
1149
+	 * @throws DomainException
1150
+	 * @throws EE_Error
1151
+	 * @throws InvalidArgumentException
1152
+	 * @throws InvalidDataTypeException
1153
+	 * @throws InvalidInterfaceException
1154
+	 */
1155
+	protected function _registrations_overview_list_table()
1156
+	{
1157
+		$this->appendAddNewRegistrationButtonToPageTitle();
1158
+		$header_text                  = '';
1159
+		$admin_page_header_decorators = [
1160
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
+		];
1165
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
+			$filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1167
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1168
+		}
1169
+		$this->_template_args['admin_page_header'] = $header_text;
1170
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1171
+		$this->display_admin_list_table_page_with_no_sidebar();
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * @throws EE_Error
1177
+	 * @throws InvalidArgumentException
1178
+	 * @throws InvalidDataTypeException
1179
+	 * @throws InvalidInterfaceException
1180
+	 */
1181
+	private function appendAddNewRegistrationButtonToPageTitle()
1182
+	{
1183
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1184
+		if (
1185
+			$EVT_ID
1186
+			&& EE_Registry::instance()->CAP->current_user_can(
1187
+				'ee_edit_registrations',
1188
+				'espresso_registrations_new_registration',
1189
+				$EVT_ID
1190
+			)
1191
+		) {
1192
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1193
+				'new_registration',
1194
+				'add-registrant',
1195
+				['event_id' => $EVT_ID],
1196
+				'add-new-h2'
1197
+			);
1198
+		}
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * This sets the _registration property for the registration details screen
1204
+	 *
1205
+	 * @return void
1206
+	 * @throws EE_Error
1207
+	 * @throws InvalidArgumentException
1208
+	 * @throws InvalidDataTypeException
1209
+	 * @throws InvalidInterfaceException
1210
+	 */
1211
+	private function _set_registration_object()
1212
+	{
1213
+		// get out if we've already set the object
1214
+		if ($this->_registration instanceof EE_Registration) {
1215
+			return;
1216
+		}
1217
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1218
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1219
+			return;
1220
+		}
1221
+		$error_msg = sprintf(
1222
+			esc_html__(
1223
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1224
+				'event_espresso'
1225
+			),
1226
+			$REG_ID
1227
+		);
1228
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1229
+		$this->_registration = null;
1230
+	}
1231
+
1232
+
1233
+	/**
1234
+	 * Used to retrieve registrations for the list table.
1235
+	 *
1236
+	 * @param int  $per_page
1237
+	 * @param bool $count
1238
+	 * @param bool $this_month
1239
+	 * @param bool $today
1240
+	 * @return EE_Registration[]|int
1241
+	 * @throws EE_Error
1242
+	 * @throws InvalidArgumentException
1243
+	 * @throws InvalidDataTypeException
1244
+	 * @throws InvalidInterfaceException
1245
+	 */
1246
+	public function get_registrations(
1247
+		$per_page = 10,
1248
+		$count = false,
1249
+		$this_month = false,
1250
+		$today = false
1251
+	) {
1252
+		if ($this_month) {
1253
+			$this->request->setRequestParam('status', 'month');
1254
+		}
1255
+		if ($today) {
1256
+			$this->request->setRequestParam('status', 'today');
1257
+		}
1258
+		$query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1259
+		/**
1260
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1261
+		 *
1262
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1263
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1264
+		 *                      or if you have the development copy of EE you can view this at the path:
1265
+		 *                      /docs/G--Model-System/model-query-params.md
1266
+		 */
1267
+		$query_params['group_by'] = '';
1268
+
1269
+		return $count
1270
+			? $this->getRegistrationModel()->count($query_params)
1271
+			/** @type EE_Registration[] */
1272
+			: $this->getRegistrationModel()->get_all($query_params);
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1278
+	 * Note: this listens to values on the request for some of the query parameters.
1279
+	 *
1280
+	 * @param array $request
1281
+	 * @param int   $per_page
1282
+	 * @param bool  $count
1283
+	 * @return array
1284
+	 * @throws EE_Error
1285
+	 * @throws InvalidArgumentException
1286
+	 * @throws InvalidDataTypeException
1287
+	 * @throws InvalidInterfaceException
1288
+	 */
1289
+	protected function _get_registration_query_parameters(
1290
+		$request = [],
1291
+		$per_page = 10,
1292
+		$count = false
1293
+	) {
1294
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1295
+		$list_table_query_builder = $this->loader->getNew(
1296
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1297
+			[null, null, $request]
1298
+		);
1299
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1300
+	}
1301
+
1302
+
1303
+	public function get_registration_status_array()
1304
+	{
1305
+		return self::$_reg_status;
1306
+	}
1307
+
1308
+
1309
+
1310
+
1311
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1312
+	/**
1313
+	 * generates HTML for the View Registration Details Admin page
1314
+	 *
1315
+	 * @return void
1316
+	 * @throws DomainException
1317
+	 * @throws EE_Error
1318
+	 * @throws InvalidArgumentException
1319
+	 * @throws InvalidDataTypeException
1320
+	 * @throws InvalidInterfaceException
1321
+	 * @throws EntityNotFoundException
1322
+	 * @throws ReflectionException
1323
+	 */
1324
+	protected function _registration_details()
1325
+	{
1326
+		$this->_template_args = [];
1327
+		$this->_set_registration_object();
1328
+		if (is_object($this->_registration)) {
1329
+			$transaction                                   = $this->_registration->transaction()
1330
+				? $this->_registration->transaction()
1331
+				: EE_Transaction::new_instance();
1332
+			$this->_session                                = $transaction->session_data();
1333
+			$event_id                                      = $this->_registration->event_ID();
1334
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1335
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1336
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1337
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1338
+			$this->_template_args['grand_total']           = $transaction->total();
1339
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1340
+			// link back to overview
1341
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1342
+			$this->_template_args['registration']                = $this->_registration;
1343
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
+				[
1345
+					'action'   => 'default',
1346
+					'event_id' => $event_id,
1347
+				],
1348
+				REG_ADMIN_URL
1349
+			);
1350
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1351
+				[
1352
+					'action' => 'default',
1353
+					'EVT_ID' => $event_id,
1354
+					'page'   => 'espresso_transactions',
1355
+				],
1356
+				admin_url('admin.php')
1357
+			);
1358
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1359
+				[
1360
+					'page'   => 'espresso_events',
1361
+					'action' => 'edit',
1362
+					'post'   => $event_id,
1363
+				],
1364
+				admin_url('admin.php')
1365
+			);
1366
+			// next and previous links
1367
+			$next_reg                                      = $this->_registration->next(
1368
+				null,
1369
+				[],
1370
+				'REG_ID'
1371
+			);
1372
+			$this->_template_args['next_registration']     = $next_reg
1373
+				? $this->_next_link(
1374
+					EE_Admin_Page::add_query_args_and_nonce(
1375
+						[
1376
+							'action'  => 'view_registration',
1377
+							'_REG_ID' => $next_reg['REG_ID'],
1378
+						],
1379
+						REG_ADMIN_URL
1380
+					),
1381
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1382
+				)
1383
+				: '';
1384
+			$previous_reg                                  = $this->_registration->previous(
1385
+				null,
1386
+				[],
1387
+				'REG_ID'
1388
+			);
1389
+			$this->_template_args['previous_registration'] = $previous_reg
1390
+				? $this->_previous_link(
1391
+					EE_Admin_Page::add_query_args_and_nonce(
1392
+						[
1393
+							'action'  => 'view_registration',
1394
+							'_REG_ID' => $previous_reg['REG_ID'],
1395
+						],
1396
+						REG_ADMIN_URL
1397
+					),
1398
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1399
+				)
1400
+				: '';
1401
+			// grab header
1402
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1403
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1404
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1405
+				$template_path,
1406
+				$this->_template_args,
1407
+				true
1408
+			);
1409
+		} else {
1410
+			$this->_template_args['admin_page_header'] = '';
1411
+			$this->_display_espresso_notices();
1412
+		}
1413
+		// the details template wrapper
1414
+		$this->display_admin_page_with_sidebar();
1415
+	}
1416
+
1417
+
1418
+	/**
1419
+	 * @throws EE_Error
1420
+	 * @throws InvalidArgumentException
1421
+	 * @throws InvalidDataTypeException
1422
+	 * @throws InvalidInterfaceException
1423
+	 * @throws ReflectionException
1424
+	 * @since 4.10.2.p
1425
+	 */
1426
+	protected function _registration_details_metaboxes()
1427
+	{
1428
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1429
+		$this->_set_registration_object();
1430
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1431
+		add_meta_box(
1432
+			'edit-reg-status-mbox',
1433
+			esc_html__('Registration Status', 'event_espresso'),
1434
+			[$this, 'set_reg_status_buttons_metabox'],
1435
+			$this->_wp_page_slug,
1436
+			'normal',
1437
+			'high'
1438
+		);
1439
+		add_meta_box(
1440
+			'edit-reg-details-mbox',
1441
+			esc_html__('Registration Details', 'event_espresso'),
1442
+			[$this, '_reg_details_meta_box'],
1443
+			$this->_wp_page_slug,
1444
+			'normal',
1445
+			'high'
1446
+		);
1447
+		if (
1448
+			$attendee instanceof EE_Attendee
1449
+			&& EE_Registry::instance()->CAP->current_user_can(
1450
+				'ee_read_registration',
1451
+				'edit-reg-questions-mbox',
1452
+				$this->_registration->ID()
1453
+			)
1454
+		) {
1455
+			add_meta_box(
1456
+				'edit-reg-questions-mbox',
1457
+				esc_html__('Registration Form Answers', 'event_espresso'),
1458
+				[$this, '_reg_questions_meta_box'],
1459
+				$this->_wp_page_slug,
1460
+				'normal',
1461
+				'high'
1462
+			);
1463
+		}
1464
+		add_meta_box(
1465
+			'edit-reg-registrant-mbox',
1466
+			esc_html__('Contact Details', 'event_espresso'),
1467
+			[$this, '_reg_registrant_side_meta_box'],
1468
+			$this->_wp_page_slug,
1469
+			'side',
1470
+			'high'
1471
+		);
1472
+		if ($this->_registration->group_size() > 1) {
1473
+			add_meta_box(
1474
+				'edit-reg-attendees-mbox',
1475
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1476
+				[$this, '_reg_attendees_meta_box'],
1477
+				$this->_wp_page_slug,
1478
+				'normal',
1479
+				'high'
1480
+			);
1481
+		}
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * set_reg_status_buttons_metabox
1487
+	 *
1488
+	 * @return void
1489
+	 * @throws EE_Error
1490
+	 * @throws EntityNotFoundException
1491
+	 * @throws InvalidArgumentException
1492
+	 * @throws InvalidDataTypeException
1493
+	 * @throws InvalidInterfaceException
1494
+	 * @throws ReflectionException
1495
+	 */
1496
+	public function set_reg_status_buttons_metabox()
1497
+	{
1498
+		$this->_set_registration_object();
1499
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1500
+		$output                 = $change_reg_status_form->form_open(
1501
+			self::add_query_args_and_nonce(
1502
+				[
1503
+					'action' => 'change_reg_status',
1504
+				],
1505
+				REG_ADMIN_URL
1506
+			)
1507
+		);
1508
+		$output                 .= $change_reg_status_form->get_html();
1509
+		$output                 .= $change_reg_status_form->form_close();
1510
+		echo $output; // already escaped
1511
+	}
1512
+
1513
+
1514
+	/**
1515
+	 * @return EE_Form_Section_Proper
1516
+	 * @throws EE_Error
1517
+	 * @throws InvalidArgumentException
1518
+	 * @throws InvalidDataTypeException
1519
+	 * @throws InvalidInterfaceException
1520
+	 * @throws EntityNotFoundException
1521
+	 * @throws ReflectionException
1522
+	 */
1523
+	protected function _generate_reg_status_change_form()
1524
+	{
1525
+		$reg_status_change_form_array = [
1526
+			'name'            => 'reg_status_change_form',
1527
+			'html_id'         => 'reg-status-change-form',
1528
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1529
+			'subsections'     => [
1530
+				'return'         => new EE_Hidden_Input(
1531
+					[
1532
+						'name'    => 'return',
1533
+						'default' => 'view_registration',
1534
+					]
1535
+				),
1536
+				'REG_ID'         => new EE_Hidden_Input(
1537
+					[
1538
+						'name'    => 'REG_ID',
1539
+						'default' => $this->_registration->ID(),
1540
+					]
1541
+				),
1542
+				'current_status' => new EE_Form_Section_HTML(
1543
+					EEH_HTML::table(
1544
+						EEH_HTML::tr(
1545
+							EEH_HTML::th(
1546
+								EEH_HTML::label(
1547
+									EEH_HTML::strong(
1548
+										esc_html__('Current Registration Status', 'event_espresso')
1549
+									)
1550
+								)
1551
+							)
1552
+							. EEH_HTML::td(
1553
+								EEH_HTML::strong(
1554
+									$this->_registration->pretty_status(),
1555
+									'',
1556
+									'status-' . $this->_registration->status_ID(),
1557
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1558
+								)
1559
+							)
1560
+						)
1561
+					)
1562
+				),
1563
+			],
1564
+		];
1565
+		if (
1566
+			EE_Registry::instance()->CAP->current_user_can(
1567
+				'ee_edit_registration',
1568
+				'toggle_registration_status',
1569
+				$this->_registration->ID()
1570
+			)
1571
+		) {
1572
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1573
+				$this->_get_reg_statuses(),
1574
+				[
1575
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1576
+					'default'         => $this->_registration->status_ID(),
1577
+				]
1578
+			);
1579
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1580
+				[
1581
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1582
+					'default'         => false,
1583
+					'html_help_text'  => esc_html__(
1584
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1585
+						'event_espresso'
1586
+					),
1587
+				]
1588
+			);
1589
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1590
+				[
1591
+					'html_class'      => 'button-primary',
1592
+					'html_label_text' => '&nbsp;',
1593
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1594
+				]
1595
+			);
1596
+		}
1597
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1603
+	 *
1604
+	 * @return array
1605
+	 * @throws EE_Error
1606
+	 * @throws InvalidArgumentException
1607
+	 * @throws InvalidDataTypeException
1608
+	 * @throws InvalidInterfaceException
1609
+	 * @throws EntityNotFoundException
1610
+	 */
1611
+	protected function _get_reg_statuses()
1612
+	{
1613
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1614
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1615
+		// get current reg status
1616
+		$current_status = $this->_registration->status_ID();
1617
+		// is registration for free event? This will determine whether to display the pending payment option
1618
+		if (
1619
+			$current_status !== EEM_Registration::status_id_pending_payment
1620
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1621
+		) {
1622
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1623
+		}
1624
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1625
+	}
1626
+
1627
+
1628
+	/**
1629
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1630
+	 *
1631
+	 * @param bool $status REG status given for changing registrations to.
1632
+	 * @param bool $notify Whether to send messages notifications or not.
1633
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1634
+	 * @throws DomainException
1635
+	 * @throws EE_Error
1636
+	 * @throws EntityNotFoundException
1637
+	 * @throws InvalidArgumentException
1638
+	 * @throws InvalidDataTypeException
1639
+	 * @throws InvalidInterfaceException
1640
+	 * @throws ReflectionException
1641
+	 * @throws RuntimeException
1642
+	 */
1643
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1644
+	{
1645
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1646
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1647
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1648
+
1649
+		// sanitize $REG_IDs
1650
+		$REG_IDs = array_map('absint', $REG_IDs);
1651
+		// and remove empty entries
1652
+		$REG_IDs = array_filter($REG_IDs);
1653
+
1654
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1655
+
1656
+		/**
1657
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1658
+		 * Currently this value is used downstream by the _process_resend_registration method.
1659
+		 *
1660
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1661
+		 * @param bool                     $status           The status registrations were changed to.
1662
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1663
+		 * @param Registrations_Admin_Page $admin_page_object
1664
+		 */
1665
+		$REG_ID = apply_filters(
1666
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1667
+			$result['REG_ID'],
1668
+			$status,
1669
+			$result['success'],
1670
+			$this
1671
+		);
1672
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1673
+
1674
+		// notify?
1675
+		if (
1676
+			$notify
1677
+			&& $result['success']
1678
+			&& ! empty($REG_ID)
1679
+			&& EE_Registry::instance()->CAP->current_user_can(
1680
+				'ee_send_message',
1681
+				'espresso_registrations_resend_registration'
1682
+			)
1683
+		) {
1684
+			$this->_process_resend_registration();
1685
+		}
1686
+		return $result;
1687
+	}
1688
+
1689
+
1690
+	/**
1691
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1692
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1693
+	 *
1694
+	 * @param array  $REG_IDs
1695
+	 * @param string $status
1696
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1697
+	 *                       slug sent with setting the registration status.
1698
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1699
+	 * @throws EE_Error
1700
+	 * @throws InvalidArgumentException
1701
+	 * @throws InvalidDataTypeException
1702
+	 * @throws InvalidInterfaceException
1703
+	 * @throws ReflectionException
1704
+	 * @throws RuntimeException
1705
+	 * @throws EntityNotFoundException
1706
+	 * @throws DomainException
1707
+	 */
1708
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1709
+	{
1710
+		$success = false;
1711
+		// typecast $REG_IDs
1712
+		$REG_IDs = (array) $REG_IDs;
1713
+		if (! empty($REG_IDs)) {
1714
+			$success = true;
1715
+			// set default status if none is passed
1716
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1717
+			$status_context = $notify
1718
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1719
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1720
+			// loop through REG_ID's and change status
1721
+			foreach ($REG_IDs as $REG_ID) {
1722
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1723
+				if ($registration instanceof EE_Registration) {
1724
+					$registration->set_status(
1725
+						$status,
1726
+						false,
1727
+						new Context(
1728
+							$status_context,
1729
+							esc_html__(
1730
+								'Manually triggered status change on a Registration Admin Page route.',
1731
+								'event_espresso'
1732
+							)
1733
+						)
1734
+					);
1735
+					$result = $registration->save();
1736
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1737
+					$success = $result !== false ? $success : false;
1738
+				}
1739
+			}
1740
+		}
1741
+
1742
+		// return $success and processed registrations
1743
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1744
+	}
1745
+
1746
+
1747
+	/**
1748
+	 * Common logic for setting up success message and redirecting to appropriate route
1749
+	 *
1750
+	 * @param string $STS_ID status id for the registration changed to
1751
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1752
+	 * @return void
1753
+	 * @throws DomainException
1754
+	 * @throws EE_Error
1755
+	 * @throws EntityNotFoundException
1756
+	 * @throws InvalidArgumentException
1757
+	 * @throws InvalidDataTypeException
1758
+	 * @throws InvalidInterfaceException
1759
+	 * @throws ReflectionException
1760
+	 * @throws RuntimeException
1761
+	 */
1762
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1763
+	{
1764
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1765
+			: ['success' => false];
1766
+		$success = isset($result['success']) && $result['success'];
1767
+		// setup success message
1768
+		if ($success) {
1769
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1770
+				$msg = sprintf(
1771
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1772
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
+				);
1774
+			} else {
1775
+				$msg = sprintf(
1776
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1777
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1778
+				);
1779
+			}
1780
+			EE_Error::add_success($msg);
1781
+		} else {
1782
+			EE_Error::add_error(
1783
+				esc_html__(
1784
+					'Something went wrong, and the status was not changed',
1785
+					'event_espresso'
1786
+				),
1787
+				__FILE__,
1788
+				__LINE__,
1789
+				__FUNCTION__
1790
+			);
1791
+		}
1792
+		$return = $this->request->getRequestParam('return');
1793
+		$route  = $return === 'view_registration'
1794
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1795
+			: ['action' => 'default'];
1796
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1797
+		$this->_redirect_after_action($success, '', '', $route, true);
1798
+	}
1799
+
1800
+
1801
+	/**
1802
+	 * incoming reg status change from reg details page.
1803
+	 *
1804
+	 * @return void
1805
+	 * @throws EE_Error
1806
+	 * @throws EntityNotFoundException
1807
+	 * @throws InvalidArgumentException
1808
+	 * @throws InvalidDataTypeException
1809
+	 * @throws InvalidInterfaceException
1810
+	 * @throws ReflectionException
1811
+	 * @throws RuntimeException
1812
+	 * @throws DomainException
1813
+	 */
1814
+	protected function _change_reg_status()
1815
+	{
1816
+		$this->request->setRequestParam('return', 'view_registration');
1817
+		// set notify based on whether the send notifications toggle is set or not
1818
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1819
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1820
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1821
+		switch ($reg_status) {
1822
+			case EEM_Registration::status_id_approved:
1823
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1824
+				$this->approve_registration($notify);
1825
+				break;
1826
+			case EEM_Registration::status_id_pending_payment:
1827
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1828
+				$this->pending_registration($notify);
1829
+				break;
1830
+			case EEM_Registration::status_id_not_approved:
1831
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1832
+				$this->not_approve_registration($notify);
1833
+				break;
1834
+			case EEM_Registration::status_id_declined:
1835
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1836
+				$this->decline_registration($notify);
1837
+				break;
1838
+			case EEM_Registration::status_id_cancelled:
1839
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1840
+				$this->cancel_registration($notify);
1841
+				break;
1842
+			case EEM_Registration::status_id_wait_list:
1843
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1844
+				$this->wait_list_registration($notify);
1845
+				break;
1846
+			case EEM_Registration::status_id_incomplete:
1847
+			default:
1848
+				$this->request->unSetRequestParam('return');
1849
+				$this->_reg_status_change_return('');
1850
+				break;
1851
+		}
1852
+	}
1853
+
1854
+
1855
+	/**
1856
+	 * Callback for bulk action routes.
1857
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1858
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1859
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1860
+	 * when an action is happening on just a single registration).
1861
+	 *
1862
+	 * @param      $action
1863
+	 * @param bool $notify
1864
+	 */
1865
+	protected function bulk_action_on_registrations($action, $notify = false)
1866
+	{
1867
+		do_action(
1868
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1869
+			$this,
1870
+			$action,
1871
+			$notify
1872
+		);
1873
+		$method = $action . '_registration';
1874
+		if (method_exists($this, $method)) {
1875
+			$this->$method($notify);
1876
+		}
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * approve_registration
1882
+	 *
1883
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1884
+	 * @return void
1885
+	 * @throws EE_Error
1886
+	 * @throws EntityNotFoundException
1887
+	 * @throws InvalidArgumentException
1888
+	 * @throws InvalidDataTypeException
1889
+	 * @throws InvalidInterfaceException
1890
+	 * @throws ReflectionException
1891
+	 * @throws RuntimeException
1892
+	 * @throws DomainException
1893
+	 */
1894
+	protected function approve_registration($notify = false)
1895
+	{
1896
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 * decline_registration
1902
+	 *
1903
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1904
+	 * @return void
1905
+	 * @throws EE_Error
1906
+	 * @throws EntityNotFoundException
1907
+	 * @throws InvalidArgumentException
1908
+	 * @throws InvalidDataTypeException
1909
+	 * @throws InvalidInterfaceException
1910
+	 * @throws ReflectionException
1911
+	 * @throws RuntimeException
1912
+	 * @throws DomainException
1913
+	 */
1914
+	protected function decline_registration($notify = false)
1915
+	{
1916
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 * cancel_registration
1922
+	 *
1923
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1924
+	 * @return void
1925
+	 * @throws EE_Error
1926
+	 * @throws EntityNotFoundException
1927
+	 * @throws InvalidArgumentException
1928
+	 * @throws InvalidDataTypeException
1929
+	 * @throws InvalidInterfaceException
1930
+	 * @throws ReflectionException
1931
+	 * @throws RuntimeException
1932
+	 * @throws DomainException
1933
+	 */
1934
+	protected function cancel_registration($notify = false)
1935
+	{
1936
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1937
+	}
1938
+
1939
+
1940
+	/**
1941
+	 * not_approve_registration
1942
+	 *
1943
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1944
+	 * @return void
1945
+	 * @throws EE_Error
1946
+	 * @throws EntityNotFoundException
1947
+	 * @throws InvalidArgumentException
1948
+	 * @throws InvalidDataTypeException
1949
+	 * @throws InvalidInterfaceException
1950
+	 * @throws ReflectionException
1951
+	 * @throws RuntimeException
1952
+	 * @throws DomainException
1953
+	 */
1954
+	protected function not_approve_registration($notify = false)
1955
+	{
1956
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1957
+	}
1958
+
1959
+
1960
+	/**
1961
+	 * decline_registration
1962
+	 *
1963
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1964
+	 * @return void
1965
+	 * @throws EE_Error
1966
+	 * @throws EntityNotFoundException
1967
+	 * @throws InvalidArgumentException
1968
+	 * @throws InvalidDataTypeException
1969
+	 * @throws InvalidInterfaceException
1970
+	 * @throws ReflectionException
1971
+	 * @throws RuntimeException
1972
+	 * @throws DomainException
1973
+	 */
1974
+	protected function pending_registration($notify = false)
1975
+	{
1976
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1977
+	}
1978
+
1979
+
1980
+	/**
1981
+	 * waitlist_registration
1982
+	 *
1983
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1984
+	 * @return void
1985
+	 * @throws EE_Error
1986
+	 * @throws EntityNotFoundException
1987
+	 * @throws InvalidArgumentException
1988
+	 * @throws InvalidDataTypeException
1989
+	 * @throws InvalidInterfaceException
1990
+	 * @throws ReflectionException
1991
+	 * @throws RuntimeException
1992
+	 * @throws DomainException
1993
+	 */
1994
+	protected function wait_list_registration($notify = false)
1995
+	{
1996
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
+	}
1998
+
1999
+
2000
+	/**
2001
+	 * generates HTML for the Registration main meta box
2002
+	 *
2003
+	 * @return void
2004
+	 * @throws DomainException
2005
+	 * @throws EE_Error
2006
+	 * @throws InvalidArgumentException
2007
+	 * @throws InvalidDataTypeException
2008
+	 * @throws InvalidInterfaceException
2009
+	 * @throws ReflectionException
2010
+	 * @throws EntityNotFoundException
2011
+	 */
2012
+	public function _reg_details_meta_box()
2013
+	{
2014
+		EEH_Autoloader::register_line_item_display_autoloaders();
2015
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2016
+		EE_Registry::instance()->load_helper('Line_Item');
2017
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2018
+			: EE_Transaction::new_instance();
2019
+		$this->_session = $transaction->session_data();
2020
+		$filters        = new EE_Line_Item_Filter_Collection();
2021
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2022
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2023
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2024
+			$filters,
2025
+			$transaction->total_line_item()
2026
+		);
2027
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2028
+		$line_item_display                       = new EE_Line_Item_Display(
2029
+			'reg_admin_table',
2030
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2031
+		);
2032
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2033
+			$filtered_line_item_tree,
2034
+			['EE_Registration' => $this->_registration]
2035
+		);
2036
+		$attendee                                = $this->_registration->attendee();
2037
+		if (
2038
+			EE_Registry::instance()->CAP->current_user_can(
2039
+				'ee_read_transaction',
2040
+				'espresso_transactions_view_transaction'
2041
+			)
2042
+		) {
2043
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2044
+				EE_Admin_Page::add_query_args_and_nonce(
2045
+					[
2046
+						'action' => 'view_transaction',
2047
+						'TXN_ID' => $transaction->ID(),
2048
+					],
2049
+					TXN_ADMIN_URL
2050
+				),
2051
+				esc_html__(' View Transaction', 'event_espresso'),
2052
+				'button secondary-button right',
2053
+				'dashicons dashicons-cart'
2054
+			);
2055
+		} else {
2056
+			$this->_template_args['view_transaction_button'] = '';
2057
+		}
2058
+		if (
2059
+			$attendee instanceof EE_Attendee
2060
+			&& EE_Registry::instance()->CAP->current_user_can(
2061
+				'ee_send_message',
2062
+				'espresso_registrations_resend_registration'
2063
+			)
2064
+		) {
2065
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2066
+				EE_Admin_Page::add_query_args_and_nonce(
2067
+					[
2068
+						'action'      => 'resend_registration',
2069
+						'_REG_ID'     => $this->_registration->ID(),
2070
+						'redirect_to' => 'view_registration',
2071
+					],
2072
+					REG_ADMIN_URL
2073
+				),
2074
+				esc_html__(' Resend Registration', 'event_espresso'),
2075
+				'button secondary-button right',
2076
+				'dashicons dashicons-email-alt'
2077
+			);
2078
+		} else {
2079
+			$this->_template_args['resend_registration_button'] = '';
2080
+		}
2081
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2082
+		$payment                               = $transaction->get_first_related('Payment');
2083
+		$payment                               = ! $payment instanceof EE_Payment
2084
+			? EE_Payment::new_instance()
2085
+			: $payment;
2086
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2087
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2088
+			? EE_Payment_Method::new_instance()
2089
+			: $payment_method;
2090
+		$reg_details                           = [
2091
+			'payment_method'       => $payment_method->name(),
2092
+			'response_msg'         => $payment->gateway_response(),
2093
+			'registration_id'      => $this->_registration->get('REG_code'),
2094
+			'registration_session' => $this->_registration->session_ID(),
2095
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2096
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2097
+		];
2098
+		if (isset($reg_details['registration_id'])) {
2099
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2100
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2101
+				'Registration ID',
2102
+				'event_espresso'
2103
+			);
2104
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2105
+		}
2106
+		if (isset($reg_details['payment_method'])) {
2107
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2108
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2109
+				'Most Recent Payment Method',
2110
+				'event_espresso'
2111
+			);
2112
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2113
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2114
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2115
+				'Payment method response',
2116
+				'event_espresso'
2117
+			);
2118
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2119
+		}
2120
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2121
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2122
+			'Registration Session',
2123
+			'event_espresso'
2124
+		);
2125
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2126
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2127
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2128
+			'Registration placed from IP',
2129
+			'event_espresso'
2130
+		);
2131
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2132
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2133
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2134
+			'Registrant User Agent',
2135
+			'event_espresso'
2136
+		);
2137
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2138
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2139
+			[
2140
+				'action'   => 'default',
2141
+				'event_id' => $this->_registration->event_ID(),
2142
+			],
2143
+			REG_ADMIN_URL
2144
+		);
2145
+
2146
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2147
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2148
+
2149
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2150
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2151
+	}
2152
+
2153
+
2154
+	/**
2155
+	 * generates HTML for the Registration Questions meta box.
2156
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2157
+	 * otherwise uses new forms system
2158
+	 *
2159
+	 * @return void
2160
+	 * @throws DomainException
2161
+	 * @throws EE_Error
2162
+	 * @throws InvalidArgumentException
2163
+	 * @throws InvalidDataTypeException
2164
+	 * @throws InvalidInterfaceException
2165
+	 * @throws ReflectionException
2166
+	 */
2167
+	public function _reg_questions_meta_box()
2168
+	{
2169
+		// allow someone to override this method entirely
2170
+		if (
2171
+			apply_filters(
2172
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2173
+				true,
2174
+				$this,
2175
+				$this->_registration
2176
+			)
2177
+		) {
2178
+			$form = $this->_get_reg_custom_questions_form(
2179
+				$this->_registration->ID()
2180
+			);
2181
+
2182
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2183
+				? $form->get_html_and_js()
2184
+				: '';
2185
+
2186
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2187
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2188
+			$template_path = 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,635 +2249,635 @@  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 = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2553
-        EEH_Template::display_template($template_path, $this->_template_args);
2554
-    }
2555
-
2556
-
2557
-    /**
2558
-     * trash or restore registrations
2559
-     *
2560
-     * @param boolean $trash whether to archive or restore
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     * @throws InvalidArgumentException
2564
-     * @throws InvalidDataTypeException
2565
-     * @throws InvalidInterfaceException
2566
-     * @throws RuntimeException
2567
-     */
2568
-    protected function _trash_or_restore_registrations($trash = true)
2569
-    {
2570
-        // if empty _REG_ID then get out because there's nothing to do
2571
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2572
-        if (empty($REG_IDs)) {
2573
-            EE_Error::add_error(
2574
-                sprintf(
2575
-                    esc_html__(
2576
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2577
-                        'event_espresso'
2578
-                    ),
2579
-                    $trash ? 'trash' : 'restore'
2580
-                ),
2581
-                __FILE__,
2582
-                __LINE__,
2583
-                __FUNCTION__
2584
-            );
2585
-            $this->_redirect_after_action(false, '', '', [], true);
2586
-        }
2587
-        $success        = 0;
2588
-        $overwrite_msgs = false;
2589
-        // Checkboxes
2590
-        $reg_count = count($REG_IDs);
2591
-        // cycle thru checkboxes
2592
-        foreach ($REG_IDs as $REG_ID) {
2593
-            /** @var EE_Registration $REG */
2594
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2595
-            $payments = $REG->registration_payments();
2596
-            if (! empty($payments)) {
2597
-                $name           = $REG->attendee() instanceof EE_Attendee
2598
-                    ? $REG->attendee()->full_name()
2599
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2600
-                $overwrite_msgs = true;
2601
-                EE_Error::add_error(
2602
-                    sprintf(
2603
-                        esc_html__(
2604
-                            '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.',
2605
-                            'event_espresso'
2606
-                        ),
2607
-                        $name
2608
-                    ),
2609
-                    __FILE__,
2610
-                    __FUNCTION__,
2611
-                    __LINE__
2612
-                );
2613
-                // can't trash this registration because it has payments.
2614
-                continue;
2615
-            }
2616
-            $updated = $trash ? $REG->delete() : $REG->restore();
2617
-            if ($updated) {
2618
-                $success++;
2619
-            }
2620
-        }
2621
-        $this->_redirect_after_action(
2622
-            $success === $reg_count, // were ALL registrations affected?
2623
-            $success > 1
2624
-                ? esc_html__('Registrations', 'event_espresso')
2625
-                : esc_html__('Registration', 'event_espresso'),
2626
-            $trash
2627
-                ? esc_html__('moved to the trash', 'event_espresso')
2628
-                : esc_html__('restored', 'event_espresso'),
2629
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2630
-            $overwrite_msgs
2631
-        );
2632
-    }
2633
-
2634
-
2635
-    /**
2636
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2637
-     * registration but also.
2638
-     * 1. Removing relations to EE_Attendee
2639
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2640
-     * ALSO trashed.
2641
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2642
-     * 4. Removing relationships between all tickets and the related registrations
2643
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2644
-     * 6. Deleting permanently any related Checkins.
2645
-     *
2646
-     * @return void
2647
-     * @throws EE_Error
2648
-     * @throws InvalidArgumentException
2649
-     * @throws InvalidDataTypeException
2650
-     * @throws InvalidInterfaceException
2651
-     * @throws ReflectionException
2652
-     */
2653
-    protected function _delete_registrations()
2654
-    {
2655
-        $REG_MDL = $this->getRegistrationModel();
2656
-        $success = 0;
2657
-        // Checkboxes
2658
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2659
-
2660
-        if (! empty($REG_IDs)) {
2661
-            // if array has more than one element than success message should be plural
2662
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2663
-            // cycle thru checkboxes
2664
-            foreach ($REG_IDs as $REG_ID) {
2665
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
-                if (! $REG instanceof EE_Registration) {
2667
-                    continue;
2668
-                }
2669
-                $deleted = $this->_delete_registration($REG);
2670
-                if (! $deleted) {
2671
-                    $success = 0;
2672
-                }
2673
-            }
2674
-        }
2675
-
2676
-        $what        = $success > 1
2677
-            ? esc_html__('Registrations', 'event_espresso')
2678
-            : esc_html__('Registration', 'event_espresso');
2679
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2680
-        $this->_redirect_after_action(
2681
-            $success,
2682
-            $what,
2683
-            $action_desc,
2684
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2685
-            true
2686
-        );
2687
-    }
2688
-
2689
-
2690
-    /**
2691
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2692
-     * models get affected.
2693
-     *
2694
-     * @param EE_Registration $REG registration to be deleted permanently
2695
-     * @return bool true = successful deletion, false = fail.
2696
-     * @throws EE_Error
2697
-     * @throws InvalidArgumentException
2698
-     * @throws InvalidDataTypeException
2699
-     * @throws InvalidInterfaceException
2700
-     * @throws ReflectionException
2701
-     */
2702
-    protected function _delete_registration(EE_Registration $REG)
2703
-    {
2704
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2705
-        // registrations on the transaction that are NOT trashed.
2706
-        $TXN = $REG->get_first_related('Transaction');
2707
-        if (! $TXN instanceof EE_Transaction) {
2708
-            EE_Error::add_error(
2709
-                sprintf(
2710
-                    esc_html__(
2711
-                        '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.',
2712
-                        'event_espresso'
2713
-                    ),
2714
-                    $REG->id()
2715
-                ),
2716
-                __FILE__,
2717
-                __FUNCTION__,
2718
-                __LINE__
2719
-            );
2720
-            return false;
2721
-        }
2722
-        $REGS        = $TXN->get_many_related('Registration');
2723
-        $all_trashed = true;
2724
-        foreach ($REGS as $registration) {
2725
-            if (! $registration->get('REG_deleted')) {
2726
-                $all_trashed = false;
2727
-            }
2728
-        }
2729
-        if (! $all_trashed) {
2730
-            EE_Error::add_error(
2731
-                esc_html__(
2732
-                    '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.',
2733
-                    'event_espresso'
2734
-                ),
2735
-                __FILE__,
2736
-                __FUNCTION__,
2737
-                __LINE__
2738
-            );
2739
-            return false;
2740
-        }
2741
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2742
-        // separately from THIS one).
2743
-        foreach ($REGS as $registration) {
2744
-            // delete related answers
2745
-            $registration->delete_related_permanently('Answer');
2746
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2747
-            $attendee = $registration->get_first_related('Attendee');
2748
-            if ($attendee instanceof EE_Attendee) {
2749
-                $registration->_remove_relation_to($attendee, 'Attendee');
2750
-            }
2751
-            // now remove relationships to tickets on this registration.
2752
-            $registration->_remove_relations('Ticket');
2753
-            // now delete permanently the checkins related to this registration.
2754
-            $registration->delete_related_permanently('Checkin');
2755
-            if ($registration->ID() === $REG->ID()) {
2756
-                continue;
2757
-            } //we don't want to delete permanently the existing registration just yet.
2758
-            // remove relation to transaction for these registrations if NOT the existing registrations
2759
-            $registration->_remove_relations('Transaction');
2760
-            // delete permanently any related messages.
2761
-            $registration->delete_related_permanently('Message');
2762
-            // now delete this registration permanently
2763
-            $registration->delete_permanently();
2764
-        }
2765
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2766
-        // (the transaction and line items should be all that's left).
2767
-        // delete the line items related to the transaction for this registration.
2768
-        $TXN->delete_related_permanently('Line_Item');
2769
-        // we need to remove all the relationships on the transaction
2770
-        $TXN->delete_related_permanently('Payment');
2771
-        $TXN->delete_related_permanently('Extra_Meta');
2772
-        $TXN->delete_related_permanently('Message');
2773
-        // now we can delete this REG permanently (and the transaction of course)
2774
-        $REG->delete_related_permanently('Transaction');
2775
-        return $REG->delete_permanently();
2776
-    }
2777
-
2778
-
2779
-    /**
2780
-     *    generates HTML for the Register New Attendee Admin page
2781
-     *
2782
-     * @throws DomainException
2783
-     * @throws EE_Error
2784
-     * @throws InvalidArgumentException
2785
-     * @throws InvalidDataTypeException
2786
-     * @throws InvalidInterfaceException
2787
-     * @throws ReflectionException
2788
-     */
2789
-    public function new_registration()
2790
-    {
2791
-        if (! $this->_set_reg_event()) {
2792
-            throw new EE_Error(
2793
-                esc_html__(
2794
-                    'Unable to continue with registering because there is no Event ID in the request',
2795
-                    'event_espresso'
2796
-                )
2797
-            );
2798
-        }
2799
-        /** @var CurrentPage $current_page */
2800
-        $current_page = $this->loader->getShared(CurrentPage::class);
2801
-        $current_page->setEspressoPage(true);
2802
-        // gotta start with a clean slate if we're not coming here via ajax
2803
-        if (
2804
-            ! $this->request->isAjax()
2805
-            && (
2806
-                ! $this->request->requestParamIsSet('processing_registration')
2807
-                || $this->request->requestParamIsSet('step_error')
2808
-            )
2809
-        ) {
2810
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2811
-        }
2812
-        $this->_template_args['event_name'] = '';
2813
-        // event name
2814
-        if ($this->_reg_event) {
2815
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2816
-            $edit_event_url                     = self::add_query_args_and_nonce(
2817
-                [
2818
-                    'action' => 'edit',
2819
-                    'post'   => $this->_reg_event->ID(),
2820
-                ],
2821
-                EVENTS_ADMIN_URL
2822
-            );
2823
-            $edit_event_lnk                     = '<a href="'
2824
-                                                  . $edit_event_url
2825
-                                                  . '" title="'
2826
-                                                  . esc_attr__('Edit ', 'event_espresso')
2827
-                                                  . $this->_reg_event->name()
2828
-                                                  . '">'
2829
-                                                  . esc_html__('Edit Event', 'event_espresso')
2830
-                                                  . '</a>';
2831
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2832
-                                                   . $edit_event_lnk
2833
-                                                   . '</span>';
2834
-        }
2835
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2836
-        if ($this->request->isAjax()) {
2837
-            $this->_return_json();
2838
-        }
2839
-        // grab header
2840
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2841
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2842
-            $template_path,
2843
-            $this->_template_args,
2844
-            true
2845
-        );
2846
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2847
-        // the details template wrapper
2848
-        $this->display_admin_page_with_sidebar();
2849
-    }
2850
-
2851
-
2852
-    /**
2853
-     * This returns the content for a registration step
2854
-     *
2855
-     * @return string html
2856
-     * @throws DomainException
2857
-     * @throws EE_Error
2858
-     * @throws InvalidArgumentException
2859
-     * @throws InvalidDataTypeException
2860
-     * @throws InvalidInterfaceException
2861
-     * @throws ReflectionException
2862
-     */
2863
-    protected function _get_registration_step_content()
2864
-    {
2865
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2866
-            $warning_msg = sprintf(
2867
-                esc_html__(
2868
-                    '%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',
2869
-                    'event_espresso'
2870
-                ),
2871
-                '<br />',
2872
-                '<h3 class="important-notice">',
2873
-                '</h3>',
2874
-                '<div class="float-right">',
2875
-                '<span id="redirect_timer" class="important-notice">30</span>',
2876
-                '</div>',
2877
-                '<b>',
2878
-                '</b>'
2879
-            );
2880
-            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 = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2553
+		EEH_Template::display_template($template_path, $this->_template_args);
2554
+	}
2555
+
2556
+
2557
+	/**
2558
+	 * trash or restore registrations
2559
+	 *
2560
+	 * @param boolean $trash whether to archive or restore
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 * @throws InvalidArgumentException
2564
+	 * @throws InvalidDataTypeException
2565
+	 * @throws InvalidInterfaceException
2566
+	 * @throws RuntimeException
2567
+	 */
2568
+	protected function _trash_or_restore_registrations($trash = true)
2569
+	{
2570
+		// if empty _REG_ID then get out because there's nothing to do
2571
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2572
+		if (empty($REG_IDs)) {
2573
+			EE_Error::add_error(
2574
+				sprintf(
2575
+					esc_html__(
2576
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2577
+						'event_espresso'
2578
+					),
2579
+					$trash ? 'trash' : 'restore'
2580
+				),
2581
+				__FILE__,
2582
+				__LINE__,
2583
+				__FUNCTION__
2584
+			);
2585
+			$this->_redirect_after_action(false, '', '', [], true);
2586
+		}
2587
+		$success        = 0;
2588
+		$overwrite_msgs = false;
2589
+		// Checkboxes
2590
+		$reg_count = count($REG_IDs);
2591
+		// cycle thru checkboxes
2592
+		foreach ($REG_IDs as $REG_ID) {
2593
+			/** @var EE_Registration $REG */
2594
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2595
+			$payments = $REG->registration_payments();
2596
+			if (! empty($payments)) {
2597
+				$name           = $REG->attendee() instanceof EE_Attendee
2598
+					? $REG->attendee()->full_name()
2599
+					: esc_html__('Unknown Attendee', 'event_espresso');
2600
+				$overwrite_msgs = true;
2601
+				EE_Error::add_error(
2602
+					sprintf(
2603
+						esc_html__(
2604
+							'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.',
2605
+							'event_espresso'
2606
+						),
2607
+						$name
2608
+					),
2609
+					__FILE__,
2610
+					__FUNCTION__,
2611
+					__LINE__
2612
+				);
2613
+				// can't trash this registration because it has payments.
2614
+				continue;
2615
+			}
2616
+			$updated = $trash ? $REG->delete() : $REG->restore();
2617
+			if ($updated) {
2618
+				$success++;
2619
+			}
2620
+		}
2621
+		$this->_redirect_after_action(
2622
+			$success === $reg_count, // were ALL registrations affected?
2623
+			$success > 1
2624
+				? esc_html__('Registrations', 'event_espresso')
2625
+				: esc_html__('Registration', 'event_espresso'),
2626
+			$trash
2627
+				? esc_html__('moved to the trash', 'event_espresso')
2628
+				: esc_html__('restored', 'event_espresso'),
2629
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2630
+			$overwrite_msgs
2631
+		);
2632
+	}
2633
+
2634
+
2635
+	/**
2636
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2637
+	 * registration but also.
2638
+	 * 1. Removing relations to EE_Attendee
2639
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2640
+	 * ALSO trashed.
2641
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2642
+	 * 4. Removing relationships between all tickets and the related registrations
2643
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2644
+	 * 6. Deleting permanently any related Checkins.
2645
+	 *
2646
+	 * @return void
2647
+	 * @throws EE_Error
2648
+	 * @throws InvalidArgumentException
2649
+	 * @throws InvalidDataTypeException
2650
+	 * @throws InvalidInterfaceException
2651
+	 * @throws ReflectionException
2652
+	 */
2653
+	protected function _delete_registrations()
2654
+	{
2655
+		$REG_MDL = $this->getRegistrationModel();
2656
+		$success = 0;
2657
+		// Checkboxes
2658
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2659
+
2660
+		if (! empty($REG_IDs)) {
2661
+			// if array has more than one element than success message should be plural
2662
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2663
+			// cycle thru checkboxes
2664
+			foreach ($REG_IDs as $REG_ID) {
2665
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
+				if (! $REG instanceof EE_Registration) {
2667
+					continue;
2668
+				}
2669
+				$deleted = $this->_delete_registration($REG);
2670
+				if (! $deleted) {
2671
+					$success = 0;
2672
+				}
2673
+			}
2674
+		}
2675
+
2676
+		$what        = $success > 1
2677
+			? esc_html__('Registrations', 'event_espresso')
2678
+			: esc_html__('Registration', 'event_espresso');
2679
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2680
+		$this->_redirect_after_action(
2681
+			$success,
2682
+			$what,
2683
+			$action_desc,
2684
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2685
+			true
2686
+		);
2687
+	}
2688
+
2689
+
2690
+	/**
2691
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2692
+	 * models get affected.
2693
+	 *
2694
+	 * @param EE_Registration $REG registration to be deleted permanently
2695
+	 * @return bool true = successful deletion, false = fail.
2696
+	 * @throws EE_Error
2697
+	 * @throws InvalidArgumentException
2698
+	 * @throws InvalidDataTypeException
2699
+	 * @throws InvalidInterfaceException
2700
+	 * @throws ReflectionException
2701
+	 */
2702
+	protected function _delete_registration(EE_Registration $REG)
2703
+	{
2704
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2705
+		// registrations on the transaction that are NOT trashed.
2706
+		$TXN = $REG->get_first_related('Transaction');
2707
+		if (! $TXN instanceof EE_Transaction) {
2708
+			EE_Error::add_error(
2709
+				sprintf(
2710
+					esc_html__(
2711
+						'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.',
2712
+						'event_espresso'
2713
+					),
2714
+					$REG->id()
2715
+				),
2716
+				__FILE__,
2717
+				__FUNCTION__,
2718
+				__LINE__
2719
+			);
2720
+			return false;
2721
+		}
2722
+		$REGS        = $TXN->get_many_related('Registration');
2723
+		$all_trashed = true;
2724
+		foreach ($REGS as $registration) {
2725
+			if (! $registration->get('REG_deleted')) {
2726
+				$all_trashed = false;
2727
+			}
2728
+		}
2729
+		if (! $all_trashed) {
2730
+			EE_Error::add_error(
2731
+				esc_html__(
2732
+					'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.',
2733
+					'event_espresso'
2734
+				),
2735
+				__FILE__,
2736
+				__FUNCTION__,
2737
+				__LINE__
2738
+			);
2739
+			return false;
2740
+		}
2741
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2742
+		// separately from THIS one).
2743
+		foreach ($REGS as $registration) {
2744
+			// delete related answers
2745
+			$registration->delete_related_permanently('Answer');
2746
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2747
+			$attendee = $registration->get_first_related('Attendee');
2748
+			if ($attendee instanceof EE_Attendee) {
2749
+				$registration->_remove_relation_to($attendee, 'Attendee');
2750
+			}
2751
+			// now remove relationships to tickets on this registration.
2752
+			$registration->_remove_relations('Ticket');
2753
+			// now delete permanently the checkins related to this registration.
2754
+			$registration->delete_related_permanently('Checkin');
2755
+			if ($registration->ID() === $REG->ID()) {
2756
+				continue;
2757
+			} //we don't want to delete permanently the existing registration just yet.
2758
+			// remove relation to transaction for these registrations if NOT the existing registrations
2759
+			$registration->_remove_relations('Transaction');
2760
+			// delete permanently any related messages.
2761
+			$registration->delete_related_permanently('Message');
2762
+			// now delete this registration permanently
2763
+			$registration->delete_permanently();
2764
+		}
2765
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2766
+		// (the transaction and line items should be all that's left).
2767
+		// delete the line items related to the transaction for this registration.
2768
+		$TXN->delete_related_permanently('Line_Item');
2769
+		// we need to remove all the relationships on the transaction
2770
+		$TXN->delete_related_permanently('Payment');
2771
+		$TXN->delete_related_permanently('Extra_Meta');
2772
+		$TXN->delete_related_permanently('Message');
2773
+		// now we can delete this REG permanently (and the transaction of course)
2774
+		$REG->delete_related_permanently('Transaction');
2775
+		return $REG->delete_permanently();
2776
+	}
2777
+
2778
+
2779
+	/**
2780
+	 *    generates HTML for the Register New Attendee Admin page
2781
+	 *
2782
+	 * @throws DomainException
2783
+	 * @throws EE_Error
2784
+	 * @throws InvalidArgumentException
2785
+	 * @throws InvalidDataTypeException
2786
+	 * @throws InvalidInterfaceException
2787
+	 * @throws ReflectionException
2788
+	 */
2789
+	public function new_registration()
2790
+	{
2791
+		if (! $this->_set_reg_event()) {
2792
+			throw new EE_Error(
2793
+				esc_html__(
2794
+					'Unable to continue with registering because there is no Event ID in the request',
2795
+					'event_espresso'
2796
+				)
2797
+			);
2798
+		}
2799
+		/** @var CurrentPage $current_page */
2800
+		$current_page = $this->loader->getShared(CurrentPage::class);
2801
+		$current_page->setEspressoPage(true);
2802
+		// gotta start with a clean slate if we're not coming here via ajax
2803
+		if (
2804
+			! $this->request->isAjax()
2805
+			&& (
2806
+				! $this->request->requestParamIsSet('processing_registration')
2807
+				|| $this->request->requestParamIsSet('step_error')
2808
+			)
2809
+		) {
2810
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2811
+		}
2812
+		$this->_template_args['event_name'] = '';
2813
+		// event name
2814
+		if ($this->_reg_event) {
2815
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2816
+			$edit_event_url                     = self::add_query_args_and_nonce(
2817
+				[
2818
+					'action' => 'edit',
2819
+					'post'   => $this->_reg_event->ID(),
2820
+				],
2821
+				EVENTS_ADMIN_URL
2822
+			);
2823
+			$edit_event_lnk                     = '<a href="'
2824
+												  . $edit_event_url
2825
+												  . '" title="'
2826
+												  . esc_attr__('Edit ', 'event_espresso')
2827
+												  . $this->_reg_event->name()
2828
+												  . '">'
2829
+												  . esc_html__('Edit Event', 'event_espresso')
2830
+												  . '</a>';
2831
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2832
+												   . $edit_event_lnk
2833
+												   . '</span>';
2834
+		}
2835
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2836
+		if ($this->request->isAjax()) {
2837
+			$this->_return_json();
2838
+		}
2839
+		// grab header
2840
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2841
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2842
+			$template_path,
2843
+			$this->_template_args,
2844
+			true
2845
+		);
2846
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2847
+		// the details template wrapper
2848
+		$this->display_admin_page_with_sidebar();
2849
+	}
2850
+
2851
+
2852
+	/**
2853
+	 * This returns the content for a registration step
2854
+	 *
2855
+	 * @return string html
2856
+	 * @throws DomainException
2857
+	 * @throws EE_Error
2858
+	 * @throws InvalidArgumentException
2859
+	 * @throws InvalidDataTypeException
2860
+	 * @throws InvalidInterfaceException
2861
+	 * @throws ReflectionException
2862
+	 */
2863
+	protected function _get_registration_step_content()
2864
+	{
2865
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2866
+			$warning_msg = sprintf(
2867
+				esc_html__(
2868
+					'%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',
2869
+					'event_espresso'
2870
+				),
2871
+				'<br />',
2872
+				'<h3 class="important-notice">',
2873
+				'</h3>',
2874
+				'<div class="float-right">',
2875
+				'<span id="redirect_timer" class="important-notice">30</span>',
2876
+				'</div>',
2877
+				'<b>',
2878
+				'</b>'
2879
+			);
2880
+			return '
2881 2881
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2882 2882
 	<script >
2883 2883
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2890,847 +2890,847 @@  discard block
 block discarded – undo
2890 2890
 	        }
2891 2891
 	    }, 800 );
2892 2892
 	</script >';
2893
-        }
2894
-        $template_args = [
2895
-            'title'                    => '',
2896
-            'content'                  => '',
2897
-            'step_button_text'         => '',
2898
-            'show_notification_toggle' => false,
2899
-        ];
2900
-        // to indicate we're processing a new registration
2901
-        $hidden_fields = [
2902
-            'processing_registration' => [
2903
-                'type'  => 'hidden',
2904
-                'value' => 0,
2905
-            ],
2906
-            'event_id'                => [
2907
-                'type'  => 'hidden',
2908
-                'value' => $this->_reg_event->ID(),
2909
-            ],
2910
-        ];
2911
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2912
-        $cart = EE_Registry::instance()->SSN->cart();
2913
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2914
-        switch ($step) {
2915
-            case 'ticket':
2916
-                $hidden_fields['processing_registration']['value'] = 1;
2917
-                $template_args['title']                            = esc_html__(
2918
-                    'Step One: Select the Ticket for this registration',
2919
-                    'event_espresso'
2920
-                );
2921
-                $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2922
-                $template_args['content'] .= '</div>';
2923
-                $template_args['step_button_text'] = esc_html__(
2924
-                    'Add Tickets and Continue to Registrant Details',
2925
-                    'event_espresso'
2926
-                );
2927
-                $template_args['show_notification_toggle']         = false;
2928
-                break;
2929
-            case 'questions':
2930
-                $hidden_fields['processing_registration']['value'] = 2;
2931
-                $template_args['title']                            = esc_html__(
2932
-                    'Step Two: Add Registrant Details for this Registration',
2933
-                    'event_espresso'
2934
-                );
2935
-                // in theory, we should be able to run EED_SPCO at this point
2936
-                // because the cart should have been set up properly by the first process_reg_step run.
2937
-                $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2938
-                $template_args['step_button_text'] = esc_html__(
2939
-                    'Save Registration and Continue to Details',
2940
-                    'event_espresso'
2941
-                );
2942
-                $template_args['show_notification_toggle'] = true;
2943
-                break;
2944
-        }
2945
-        // we come back to the process_registration_step route.
2946
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2947
-        return EEH_Template::display_template(
2948
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2949
-            $template_args,
2950
-            true
2951
-        );
2952
-    }
2953
-
2954
-
2955
-    /**
2956
-     * set_reg_event
2957
-     *
2958
-     * @return bool
2959
-     * @throws EE_Error
2960
-     * @throws InvalidArgumentException
2961
-     * @throws InvalidDataTypeException
2962
-     * @throws InvalidInterfaceException
2963
-     */
2964
-    private function _set_reg_event()
2965
-    {
2966
-        if (is_object($this->_reg_event)) {
2967
-            return true;
2968
-        }
2969
-
2970
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2971
-        if (! $EVT_ID) {
2972
-            return false;
2973
-        }
2974
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2975
-        return true;
2976
-    }
2977
-
2978
-
2979
-    /**
2980
-     * process_reg_step
2981
-     *
2982
-     * @return void
2983
-     * @throws DomainException
2984
-     * @throws EE_Error
2985
-     * @throws InvalidArgumentException
2986
-     * @throws InvalidDataTypeException
2987
-     * @throws InvalidInterfaceException
2988
-     * @throws ReflectionException
2989
-     * @throws RuntimeException
2990
-     */
2991
-    public function process_reg_step()
2992
-    {
2993
-        EE_System::do_not_cache();
2994
-        $this->_set_reg_event();
2995
-        /** @var CurrentPage $current_page */
2996
-        $current_page = $this->loader->getShared(CurrentPage::class);
2997
-        $current_page->setEspressoPage(true);
2998
-        $this->request->setRequestParam('uts', time());
2999
-        // what step are we on?
3000
-        $cart = EE_Registry::instance()->SSN->cart();
3001
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3002
-        // if doing ajax then we need to verify the nonce
3003
-        if ($this->request->isAjax()) {
3004
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
3005
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3006
-        }
3007
-        switch ($step) {
3008
-            case 'ticket':
3009
-                // process ticket selection
3010
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3011
-                if ($success) {
3012
-                    EE_Error::add_success(
3013
-                        esc_html__(
3014
-                            'Tickets Selected. Now complete the registration.',
3015
-                            'event_espresso'
3016
-                        )
3017
-                    );
3018
-                } else {
3019
-                    $this->request->setRequestParam('step_error', true);
3020
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3021
-                }
3022
-                if ($this->request->isAjax()) {
3023
-                    $this->new_registration(); // display next step
3024
-                } else {
3025
-                    $query_args = [
3026
-                        'action'                  => 'new_registration',
3027
-                        'processing_registration' => 1,
3028
-                        'event_id'                => $this->_reg_event->ID(),
3029
-                        'uts'                     => time(),
3030
-                    ];
3031
-                    $this->_redirect_after_action(
3032
-                        false,
3033
-                        '',
3034
-                        '',
3035
-                        $query_args,
3036
-                        true
3037
-                    );
3038
-                }
3039
-                break;
3040
-            case 'questions':
3041
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3042
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3043
-                }
3044
-                // process registration
3045
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3046
-                if ($cart instanceof EE_Cart) {
3047
-                    $grand_total = $cart->get_grand_total();
3048
-                    if ($grand_total instanceof EE_Line_Item) {
3049
-                        $grand_total->save_this_and_descendants_to_txn();
3050
-                    }
3051
-                }
3052
-                if (! $transaction instanceof EE_Transaction) {
3053
-                    $query_args = [
3054
-                        'action'                  => 'new_registration',
3055
-                        'processing_registration' => 2,
3056
-                        'event_id'                => $this->_reg_event->ID(),
3057
-                        'uts'                     => time(),
3058
-                    ];
3059
-                    if ($this->request->isAjax()) {
3060
-                        // display registration form again because there are errors (maybe validation?)
3061
-                        $this->new_registration();
3062
-                        return;
3063
-                    }
3064
-                    $this->_redirect_after_action(
3065
-                        false,
3066
-                        '',
3067
-                        '',
3068
-                        $query_args,
3069
-                        true
3070
-                    );
3071
-                    return;
3072
-                }
3073
-                // maybe update status, and make sure to save transaction if not done already
3074
-                if (! $transaction->update_status_based_on_total_paid()) {
3075
-                    $transaction->save();
3076
-                }
3077
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3078
-                $query_args = [
3079
-                    'action'        => 'redirect_to_txn',
3080
-                    'TXN_ID'        => $transaction->ID(),
3081
-                    'EVT_ID'        => $this->_reg_event->ID(),
3082
-                    'event_name'    => urlencode($this->_reg_event->name()),
3083
-                    'redirect_from' => 'new_registration',
3084
-                ];
3085
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3086
-                break;
3087
-        }
3088
-        // what are you looking here for?  Should be nothing to do at this point.
3089
-    }
3090
-
3091
-
3092
-    /**
3093
-     * redirect_to_txn
3094
-     *
3095
-     * @return void
3096
-     * @throws EE_Error
3097
-     * @throws InvalidArgumentException
3098
-     * @throws InvalidDataTypeException
3099
-     * @throws InvalidInterfaceException
3100
-     * @throws ReflectionException
3101
-     */
3102
-    public function redirect_to_txn()
3103
-    {
3104
-        EE_System::do_not_cache();
3105
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3106
-        $query_args = [
3107
-            'action' => 'view_transaction',
3108
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3109
-            'page'   => 'espresso_transactions',
3110
-        ];
3111
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3112
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3113
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3114
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3115
-        }
3116
-        EE_Error::add_success(
3117
-            esc_html__(
3118
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3119
-                'event_espresso'
3120
-            )
3121
-        );
3122
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3123
-    }
3124
-
3125
-
3126
-    /**
3127
-     * generates HTML for the Attendee Contact List
3128
-     *
3129
-     * @return void
3130
-     * @throws DomainException
3131
-     * @throws EE_Error
3132
-     */
3133
-    protected function _attendee_contact_list_table()
3134
-    {
3135
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3136
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3137
-        $this->display_admin_list_table_page_with_no_sidebar();
3138
-    }
3139
-
3140
-
3141
-    /**
3142
-     * get_attendees
3143
-     *
3144
-     * @param      $per_page
3145
-     * @param bool $count whether to return count or data.
3146
-     * @param bool $trash
3147
-     * @return array|int
3148
-     * @throws EE_Error
3149
-     * @throws InvalidArgumentException
3150
-     * @throws InvalidDataTypeException
3151
-     * @throws InvalidInterfaceException
3152
-     */
3153
-    public function get_attendees($per_page, $count = false, $trash = false)
3154
-    {
3155
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3156
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3157
-        $orderby = $this->request->getRequestParam('orderby');
3158
-        switch ($orderby) {
3159
-            case 'ATT_ID':
3160
-            case 'ATT_fname':
3161
-            case 'ATT_email':
3162
-            case 'ATT_city':
3163
-            case 'STA_ID':
3164
-            case 'CNT_ID':
3165
-                break;
3166
-            case 'Registration_Count':
3167
-                $orderby = 'Registration_Count';
3168
-                break;
3169
-            default:
3170
-                $orderby = 'ATT_lname';
3171
-        }
3172
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3173
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3174
-        $per_page     = absint($per_page) ? $per_page : 10;
3175
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3176
-        $_where       = [];
3177
-        $search_term  = $this->request->getRequestParam('s');
3178
-        if ($search_term) {
3179
-            $search_term  = '%' . $search_term . '%';
3180
-            $_where['OR'] = [
3181
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3182
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3183
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3184
-                'ATT_fname'                         => ['LIKE', $search_term],
3185
-                'ATT_lname'                         => ['LIKE', $search_term],
3186
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3187
-                'ATT_email'                         => ['LIKE', $search_term],
3188
-                'ATT_address'                       => ['LIKE', $search_term],
3189
-                'ATT_address2'                      => ['LIKE', $search_term],
3190
-                'ATT_city'                          => ['LIKE', $search_term],
3191
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3192
-                'State.STA_name'                    => ['LIKE', $search_term],
3193
-                'ATT_phone'                         => ['LIKE', $search_term],
3194
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3195
-                'Registration.REG_code'             => ['LIKE', $search_term],
3196
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3197
-            ];
3198
-        }
3199
-        $offset     = ($current_page - 1) * $per_page;
3200
-        $limit      = $count ? null : [$offset, $per_page];
3201
-        $query_args = [
3202
-            $_where,
3203
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3204
-            'limit'         => $limit,
3205
-        ];
3206
-        if (! $count) {
3207
-            $query_args['order_by'] = [$orderby => $sort];
3208
-        }
3209
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3210
-        return $count
3211
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3212
-            : $this->getAttendeeModel()->get_all($query_args);
3213
-    }
3214
-
3215
-
3216
-    /**
3217
-     * This is just taking care of resending the registration confirmation
3218
-     *
3219
-     * @return void
3220
-     * @throws EE_Error
3221
-     * @throws InvalidArgumentException
3222
-     * @throws InvalidDataTypeException
3223
-     * @throws InvalidInterfaceException
3224
-     * @throws ReflectionException
3225
-     */
3226
-    protected function _resend_registration()
3227
-    {
3228
-        $this->_process_resend_registration();
3229
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3230
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3231
-        $query_args  = $redirect_to
3232
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3233
-            : ['action' => 'default'];
3234
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3235
-    }
3236
-
3237
-
3238
-    /**
3239
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3240
-     * to use when selecting registrations
3241
-     *
3242
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3243
-     *                                                     the query parameters from the request
3244
-     * @return void ends the request with a redirect or download
3245
-     */
3246
-    public function _registrations_report_base($method_name_for_getting_query_params)
3247
-    {
3248
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3249
-            ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3250
-            : null;
3251
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3252
-            $request_params = $this->request->requestParams();
3253
-            wp_redirect(
3254
-                EE_Admin_Page::add_query_args_and_nonce(
3255
-                    [
3256
-                        'page'        => 'espresso_batch',
3257
-                        'batch'       => 'file',
3258
-                        'EVT_ID'      => $EVT_ID,
3259
-                        'filters'     => urlencode(
3260
-                            serialize(
3261
-                                $this->$method_name_for_getting_query_params(
3262
-                                    EEH_Array::is_set($request_params, 'filters', [])
3263
-                                )
3264
-                            )
3265
-                        ),
3266
-                        'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3267
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3268
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3269
-                    ]
3270
-                )
3271
-            );
3272
-        } else {
3273
-            // Pull the current request params
3274
-            $request_args = $this->request->requestParams();
3275
-            // Set the required request_args to be passed to the export
3276
-            $required_request_args = [
3277
-                'export' => 'report',
3278
-                'action' => 'registrations_report_for_event',
3279
-                'EVT_ID' => $EVT_ID,
3280
-            ];
3281
-            // Merge required request args, overriding any currently set
3282
-            $request_args = array_merge($request_args, $required_request_args);
3283
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3284
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3285
-                $EE_Export = EE_Export::instance($request_args);
3286
-                $EE_Export->export();
3287
-            }
3288
-        }
3289
-    }
3290
-
3291
-
3292
-    /**
3293
-     * Creates a registration report using only query parameters in the request
3294
-     *
3295
-     * @return void
3296
-     */
3297
-    public function _registrations_report()
3298
-    {
3299
-        $this->_registrations_report_base('_get_registration_query_parameters');
3300
-    }
3301
-
3302
-
3303
-    public function _contact_list_export()
3304
-    {
3305
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3306
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3307
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3308
-            $EE_Export->export_attendees();
3309
-        }
3310
-    }
3311
-
3312
-
3313
-    public function _contact_list_report()
3314
-    {
3315
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3316
-            wp_redirect(
3317
-                EE_Admin_Page::add_query_args_and_nonce(
3318
-                    [
3319
-                        'page'        => 'espresso_batch',
3320
-                        'batch'       => 'file',
3321
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3322
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3323
-                    ]
3324
-                )
3325
-            );
3326
-        } else {
3327
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3328
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3329
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3330
-                $EE_Export->report_attendees();
3331
-            }
3332
-        }
3333
-    }
3334
-
3335
-
3336
-
3337
-
3338
-
3339
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3340
-    /**
3341
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3342
-     *
3343
-     * @return void
3344
-     * @throws EE_Error
3345
-     * @throws InvalidArgumentException
3346
-     * @throws InvalidDataTypeException
3347
-     * @throws InvalidInterfaceException
3348
-     * @throws ReflectionException
3349
-     */
3350
-    protected function _duplicate_attendee()
3351
-    {
3352
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3353
-        $action = $this->request->getRequestParam('return', 'default');
3354
-        // verify we have necessary info
3355
-        if (! $REG_ID) {
3356
-            EE_Error::add_error(
3357
-                esc_html__(
3358
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3359
-                    'event_espresso'
3360
-                ),
3361
-                __FILE__,
3362
-                __LINE__,
3363
-                __FUNCTION__
3364
-            );
3365
-            $query_args = ['action' => $action];
3366
-            $this->_redirect_after_action('', '', '', $query_args, true);
3367
-        }
3368
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3369
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3370
-        if (! $registration instanceof EE_Registration) {
3371
-            throw new RuntimeException(
3372
-                sprintf(
3373
-                    esc_html__(
3374
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3375
-                        'event_espresso'
3376
-                    ),
3377
-                    $REG_ID
3378
-                )
3379
-            );
3380
-        }
3381
-        $attendee = $registration->attendee();
3382
-        // remove relation of existing attendee on registration
3383
-        $registration->_remove_relation_to($attendee, 'Attendee');
3384
-        // new attendee
3385
-        $new_attendee = clone $attendee;
3386
-        $new_attendee->set('ATT_ID', 0);
3387
-        $new_attendee->save();
3388
-        // add new attendee to reg
3389
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3390
-        EE_Error::add_success(
3391
-            esc_html__(
3392
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3393
-                'event_espresso'
3394
-            )
3395
-        );
3396
-        // redirect to edit page for attendee
3397
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3398
-        $this->_redirect_after_action('', '', '', $query_args, true);
3399
-    }
3400
-
3401
-
3402
-    /**
3403
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3404
-     *
3405
-     * @param int     $post_id
3406
-     * @param WP_POST $post
3407
-     * @throws DomainException
3408
-     * @throws EE_Error
3409
-     * @throws InvalidArgumentException
3410
-     * @throws InvalidDataTypeException
3411
-     * @throws InvalidInterfaceException
3412
-     * @throws LogicException
3413
-     * @throws InvalidFormSubmissionException
3414
-     * @throws ReflectionException
3415
-     */
3416
-    protected function _insert_update_cpt_item($post_id, $post)
3417
-    {
3418
-        $success  = true;
3419
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3420
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3421
-            : null;
3422
-        // for attendee updates
3423
-        if ($attendee instanceof EE_Attendee) {
3424
-            // note we should only be UPDATING attendees at this point.
3425
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3426
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3427
-            $updated_fields = [
3428
-                'ATT_fname'     => $fname,
3429
-                'ATT_lname'     => $lname,
3430
-                'ATT_full_name' => "{$fname} {$lname}",
3431
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3432
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3433
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3434
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3435
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3436
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3437
-            ];
3438
-            foreach ($updated_fields as $field => $value) {
3439
-                $attendee->set($field, $value);
3440
-            }
3441
-
3442
-            // process contact details metabox form handler (which will also save the attendee)
3443
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3444
-            $success              = $contact_details_form->process($this->request->requestParams());
3445
-
3446
-            $attendee_update_callbacks = apply_filters(
3447
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3448
-                []
3449
-            );
3450
-            foreach ($attendee_update_callbacks as $a_callback) {
3451
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3452
-                    throw new EE_Error(
3453
-                        sprintf(
3454
-                            esc_html__(
3455
-                                '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.',
3456
-                                'event_espresso'
3457
-                            ),
3458
-                            $a_callback
3459
-                        )
3460
-                    );
3461
-                }
3462
-            }
3463
-        }
3464
-
3465
-        if ($success === false) {
3466
-            EE_Error::add_error(
3467
-                esc_html__(
3468
-                    'Something went wrong with updating the meta table data for the registration.',
3469
-                    'event_espresso'
3470
-                ),
3471
-                __FILE__,
3472
-                __FUNCTION__,
3473
-                __LINE__
3474
-            );
3475
-        }
3476
-    }
3477
-
3478
-
3479
-    public function trash_cpt_item($post_id)
3480
-    {
3481
-    }
3482
-
3483
-
3484
-    public function delete_cpt_item($post_id)
3485
-    {
3486
-    }
3487
-
3488
-
3489
-    public function restore_cpt_item($post_id)
3490
-    {
3491
-    }
3492
-
3493
-
3494
-    protected function _restore_cpt_item($post_id, $revision_id)
3495
-    {
3496
-    }
3497
-
3498
-
3499
-    /**
3500
-     * @throws EE_Error
3501
-     * @throws ReflectionException
3502
-     * @since 4.10.2.p
3503
-     */
3504
-    public function attendee_editor_metaboxes()
3505
-    {
3506
-        $this->verify_cpt_object();
3507
-        remove_meta_box(
3508
-            'postexcerpt',
3509
-            $this->_cpt_routes[ $this->_req_action ],
3510
-            'normal'
3511
-        );
3512
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3513
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3514
-            add_meta_box(
3515
-                'postexcerpt',
3516
-                esc_html__('Short Biography', 'event_espresso'),
3517
-                'post_excerpt_meta_box',
3518
-                $this->_cpt_routes[ $this->_req_action ],
3519
-                'normal'
3520
-            );
3521
-        }
3522
-        if (post_type_supports('espresso_attendees', 'comments')) {
3523
-            add_meta_box(
3524
-                'commentsdiv',
3525
-                esc_html__('Notes on the Contact', 'event_espresso'),
3526
-                'post_comment_meta_box',
3527
-                $this->_cpt_routes[ $this->_req_action ],
3528
-                'normal',
3529
-                'core'
3530
-            );
3531
-        }
3532
-        add_meta_box(
3533
-            'attendee_contact_info',
3534
-            esc_html__('Contact Info', 'event_espresso'),
3535
-            [$this, 'attendee_contact_info'],
3536
-            $this->_cpt_routes[ $this->_req_action ],
3537
-            'side',
3538
-            'core'
3539
-        );
3540
-        add_meta_box(
3541
-            'attendee_details_address',
3542
-            esc_html__('Address Details', 'event_espresso'),
3543
-            [$this, 'attendee_address_details'],
3544
-            $this->_cpt_routes[ $this->_req_action ],
3545
-            'normal',
3546
-            'core'
3547
-        );
3548
-        add_meta_box(
3549
-            'attendee_registrations',
3550
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3551
-            [$this, 'attendee_registrations_meta_box'],
3552
-            $this->_cpt_routes[ $this->_req_action ],
3553
-            'normal',
3554
-            'high'
3555
-        );
3556
-    }
3557
-
3558
-
3559
-    /**
3560
-     * Metabox for attendee contact info
3561
-     *
3562
-     * @param WP_Post $post wp post object
3563
-     * @return void attendee contact info ( and form )
3564
-     * @throws EE_Error
3565
-     * @throws InvalidArgumentException
3566
-     * @throws InvalidDataTypeException
3567
-     * @throws InvalidInterfaceException
3568
-     * @throws LogicException
3569
-     * @throws DomainException
3570
-     */
3571
-    public function attendee_contact_info($post)
3572
-    {
3573
-        // get attendee object ( should already have it )
3574
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3575
-        $form->enqueueStylesAndScripts();
3576
-        echo $form->display(); // already escaped
3577
-    }
3578
-
3579
-
3580
-    /**
3581
-     * Return form handler for the contact details metabox
3582
-     *
3583
-     * @param EE_Attendee $attendee
3584
-     * @return AttendeeContactDetailsMetaboxFormHandler
3585
-     * @throws DomainException
3586
-     * @throws InvalidArgumentException
3587
-     * @throws InvalidDataTypeException
3588
-     * @throws InvalidInterfaceException
3589
-     */
3590
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3591
-    {
3592
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3593
-    }
3594
-
3595
-
3596
-    /**
3597
-     * Metabox for attendee details
3598
-     *
3599
-     * @param WP_Post $post wp post object
3600
-     * @throws EE_Error
3601
-     * @throws ReflectionException
3602
-     */
3603
-    public function attendee_address_details($post)
3604
-    {
3605
-        // get attendee object (should already have it)
3606
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3607
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3608
-            new EE_Question_Form_Input(
3609
-                EE_Question::new_instance(
3610
-                    [
3611
-                        'QST_ID'           => 0,
3612
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3613
-                        'QST_system'       => 'admin-state',
3614
-                    ]
3615
-                ),
3616
-                EE_Answer::new_instance(
3617
-                    [
3618
-                        'ANS_ID'    => 0,
3619
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3620
-                    ]
3621
-                ),
3622
-                [
3623
-                    'input_id'       => 'STA_ID',
3624
-                    'input_name'     => 'STA_ID',
3625
-                    'input_prefix'   => '',
3626
-                    'append_qstn_id' => false,
3627
-                ]
3628
-            )
3629
-        );
3630
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3631
-            new EE_Question_Form_Input(
3632
-                EE_Question::new_instance(
3633
-                    [
3634
-                        'QST_ID'           => 0,
3635
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3636
-                        'QST_system'       => 'admin-country',
3637
-                    ]
3638
-                ),
3639
-                EE_Answer::new_instance(
3640
-                    [
3641
-                        'ANS_ID'    => 0,
3642
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3643
-                    ]
3644
-                ),
3645
-                [
3646
-                    'input_id'       => 'CNT_ISO',
3647
-                    'input_name'     => 'CNT_ISO',
3648
-                    'input_prefix'   => '',
3649
-                    'append_qstn_id' => false,
3650
-                ]
3651
-            )
3652
-        );
3653
-        $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3654
-        EEH_Template::display_template($template, $this->_template_args);
3655
-    }
3656
-
3657
-
3658
-    /**
3659
-     * _attendee_details
3660
-     *
3661
-     * @param $post
3662
-     * @return void
3663
-     * @throws DomainException
3664
-     * @throws EE_Error
3665
-     * @throws InvalidArgumentException
3666
-     * @throws InvalidDataTypeException
3667
-     * @throws InvalidInterfaceException
3668
-     * @throws ReflectionException
3669
-     */
3670
-    public function attendee_registrations_meta_box($post)
3671
-    {
3672
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3673
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3674
-        $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3675
-        EEH_Template::display_template($template, $this->_template_args);
3676
-    }
3677
-
3678
-
3679
-    /**
3680
-     * add in the form fields for the attendee edit
3681
-     *
3682
-     * @param WP_Post $post wp post object
3683
-     * @return void echos html for new form.
3684
-     * @throws DomainException
3685
-     */
3686
-    public function after_title_form_fields($post)
3687
-    {
3688
-        if ($post->post_type === 'espresso_attendees') {
3689
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3690
-            $template_args['attendee'] = $this->_cpt_model_obj;
3691
-            EEH_Template::display_template($template, $template_args);
3692
-        }
3693
-    }
3694
-
3695
-
3696
-    /**
3697
-     * _trash_or_restore_attendee
3698
-     *
3699
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3700
-     * @return void
3701
-     * @throws EE_Error
3702
-     * @throws InvalidArgumentException
3703
-     * @throws InvalidDataTypeException
3704
-     * @throws InvalidInterfaceException
3705
-     */
3706
-    protected function _trash_or_restore_attendees($trash = true)
3707
-    {
3708
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3709
-        $status = $trash ? 'trash' : 'publish';
3710
-        // Checkboxes
3711
-        if ($this->request->requestParamIsSet('checkbox')) {
3712
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3713
-            // if array has more than one element than success message should be plural
3714
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3715
-            // cycle thru checkboxes
3716
-            foreach ($ATT_IDs as $ATT_ID) {
3717
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3718
-                if (! $updated) {
3719
-                    $success = 0;
3720
-                }
3721
-            }
3722
-        } else {
3723
-            // grab single id and delete
3724
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3725
-            // update attendee
3726
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3727
-        }
3728
-        $what        = $success > 1
3729
-            ? esc_html__('Contacts', 'event_espresso')
3730
-            : esc_html__('Contact', 'event_espresso');
3731
-        $action_desc = $trash
3732
-            ? esc_html__('moved to the trash', 'event_espresso')
3733
-            : esc_html__('restored', 'event_espresso');
3734
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3735
-    }
2893
+		}
2894
+		$template_args = [
2895
+			'title'                    => '',
2896
+			'content'                  => '',
2897
+			'step_button_text'         => '',
2898
+			'show_notification_toggle' => false,
2899
+		];
2900
+		// to indicate we're processing a new registration
2901
+		$hidden_fields = [
2902
+			'processing_registration' => [
2903
+				'type'  => 'hidden',
2904
+				'value' => 0,
2905
+			],
2906
+			'event_id'                => [
2907
+				'type'  => 'hidden',
2908
+				'value' => $this->_reg_event->ID(),
2909
+			],
2910
+		];
2911
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2912
+		$cart = EE_Registry::instance()->SSN->cart();
2913
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2914
+		switch ($step) {
2915
+			case 'ticket':
2916
+				$hidden_fields['processing_registration']['value'] = 1;
2917
+				$template_args['title']                            = esc_html__(
2918
+					'Step One: Select the Ticket for this registration',
2919
+					'event_espresso'
2920
+				);
2921
+				$template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2922
+				$template_args['content'] .= '</div>';
2923
+				$template_args['step_button_text'] = esc_html__(
2924
+					'Add Tickets and Continue to Registrant Details',
2925
+					'event_espresso'
2926
+				);
2927
+				$template_args['show_notification_toggle']         = false;
2928
+				break;
2929
+			case 'questions':
2930
+				$hidden_fields['processing_registration']['value'] = 2;
2931
+				$template_args['title']                            = esc_html__(
2932
+					'Step Two: Add Registrant Details for this Registration',
2933
+					'event_espresso'
2934
+				);
2935
+				// in theory, we should be able to run EED_SPCO at this point
2936
+				// because the cart should have been set up properly by the first process_reg_step run.
2937
+				$template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2938
+				$template_args['step_button_text'] = esc_html__(
2939
+					'Save Registration and Continue to Details',
2940
+					'event_espresso'
2941
+				);
2942
+				$template_args['show_notification_toggle'] = true;
2943
+				break;
2944
+		}
2945
+		// we come back to the process_registration_step route.
2946
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2947
+		return EEH_Template::display_template(
2948
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2949
+			$template_args,
2950
+			true
2951
+		);
2952
+	}
2953
+
2954
+
2955
+	/**
2956
+	 * set_reg_event
2957
+	 *
2958
+	 * @return bool
2959
+	 * @throws EE_Error
2960
+	 * @throws InvalidArgumentException
2961
+	 * @throws InvalidDataTypeException
2962
+	 * @throws InvalidInterfaceException
2963
+	 */
2964
+	private function _set_reg_event()
2965
+	{
2966
+		if (is_object($this->_reg_event)) {
2967
+			return true;
2968
+		}
2969
+
2970
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2971
+		if (! $EVT_ID) {
2972
+			return false;
2973
+		}
2974
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2975
+		return true;
2976
+	}
2977
+
2978
+
2979
+	/**
2980
+	 * process_reg_step
2981
+	 *
2982
+	 * @return void
2983
+	 * @throws DomainException
2984
+	 * @throws EE_Error
2985
+	 * @throws InvalidArgumentException
2986
+	 * @throws InvalidDataTypeException
2987
+	 * @throws InvalidInterfaceException
2988
+	 * @throws ReflectionException
2989
+	 * @throws RuntimeException
2990
+	 */
2991
+	public function process_reg_step()
2992
+	{
2993
+		EE_System::do_not_cache();
2994
+		$this->_set_reg_event();
2995
+		/** @var CurrentPage $current_page */
2996
+		$current_page = $this->loader->getShared(CurrentPage::class);
2997
+		$current_page->setEspressoPage(true);
2998
+		$this->request->setRequestParam('uts', time());
2999
+		// what step are we on?
3000
+		$cart = EE_Registry::instance()->SSN->cart();
3001
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3002
+		// if doing ajax then we need to verify the nonce
3003
+		if ($this->request->isAjax()) {
3004
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
3005
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3006
+		}
3007
+		switch ($step) {
3008
+			case 'ticket':
3009
+				// process ticket selection
3010
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3011
+				if ($success) {
3012
+					EE_Error::add_success(
3013
+						esc_html__(
3014
+							'Tickets Selected. Now complete the registration.',
3015
+							'event_espresso'
3016
+						)
3017
+					);
3018
+				} else {
3019
+					$this->request->setRequestParam('step_error', true);
3020
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3021
+				}
3022
+				if ($this->request->isAjax()) {
3023
+					$this->new_registration(); // display next step
3024
+				} else {
3025
+					$query_args = [
3026
+						'action'                  => 'new_registration',
3027
+						'processing_registration' => 1,
3028
+						'event_id'                => $this->_reg_event->ID(),
3029
+						'uts'                     => time(),
3030
+					];
3031
+					$this->_redirect_after_action(
3032
+						false,
3033
+						'',
3034
+						'',
3035
+						$query_args,
3036
+						true
3037
+					);
3038
+				}
3039
+				break;
3040
+			case 'questions':
3041
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3042
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3043
+				}
3044
+				// process registration
3045
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3046
+				if ($cart instanceof EE_Cart) {
3047
+					$grand_total = $cart->get_grand_total();
3048
+					if ($grand_total instanceof EE_Line_Item) {
3049
+						$grand_total->save_this_and_descendants_to_txn();
3050
+					}
3051
+				}
3052
+				if (! $transaction instanceof EE_Transaction) {
3053
+					$query_args = [
3054
+						'action'                  => 'new_registration',
3055
+						'processing_registration' => 2,
3056
+						'event_id'                => $this->_reg_event->ID(),
3057
+						'uts'                     => time(),
3058
+					];
3059
+					if ($this->request->isAjax()) {
3060
+						// display registration form again because there are errors (maybe validation?)
3061
+						$this->new_registration();
3062
+						return;
3063
+					}
3064
+					$this->_redirect_after_action(
3065
+						false,
3066
+						'',
3067
+						'',
3068
+						$query_args,
3069
+						true
3070
+					);
3071
+					return;
3072
+				}
3073
+				// maybe update status, and make sure to save transaction if not done already
3074
+				if (! $transaction->update_status_based_on_total_paid()) {
3075
+					$transaction->save();
3076
+				}
3077
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3078
+				$query_args = [
3079
+					'action'        => 'redirect_to_txn',
3080
+					'TXN_ID'        => $transaction->ID(),
3081
+					'EVT_ID'        => $this->_reg_event->ID(),
3082
+					'event_name'    => urlencode($this->_reg_event->name()),
3083
+					'redirect_from' => 'new_registration',
3084
+				];
3085
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3086
+				break;
3087
+		}
3088
+		// what are you looking here for?  Should be nothing to do at this point.
3089
+	}
3090
+
3091
+
3092
+	/**
3093
+	 * redirect_to_txn
3094
+	 *
3095
+	 * @return void
3096
+	 * @throws EE_Error
3097
+	 * @throws InvalidArgumentException
3098
+	 * @throws InvalidDataTypeException
3099
+	 * @throws InvalidInterfaceException
3100
+	 * @throws ReflectionException
3101
+	 */
3102
+	public function redirect_to_txn()
3103
+	{
3104
+		EE_System::do_not_cache();
3105
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3106
+		$query_args = [
3107
+			'action' => 'view_transaction',
3108
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3109
+			'page'   => 'espresso_transactions',
3110
+		];
3111
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3112
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3113
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3114
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3115
+		}
3116
+		EE_Error::add_success(
3117
+			esc_html__(
3118
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3119
+				'event_espresso'
3120
+			)
3121
+		);
3122
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3123
+	}
3124
+
3125
+
3126
+	/**
3127
+	 * generates HTML for the Attendee Contact List
3128
+	 *
3129
+	 * @return void
3130
+	 * @throws DomainException
3131
+	 * @throws EE_Error
3132
+	 */
3133
+	protected function _attendee_contact_list_table()
3134
+	{
3135
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3136
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3137
+		$this->display_admin_list_table_page_with_no_sidebar();
3138
+	}
3139
+
3140
+
3141
+	/**
3142
+	 * get_attendees
3143
+	 *
3144
+	 * @param      $per_page
3145
+	 * @param bool $count whether to return count or data.
3146
+	 * @param bool $trash
3147
+	 * @return array|int
3148
+	 * @throws EE_Error
3149
+	 * @throws InvalidArgumentException
3150
+	 * @throws InvalidDataTypeException
3151
+	 * @throws InvalidInterfaceException
3152
+	 */
3153
+	public function get_attendees($per_page, $count = false, $trash = false)
3154
+	{
3155
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3156
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3157
+		$orderby = $this->request->getRequestParam('orderby');
3158
+		switch ($orderby) {
3159
+			case 'ATT_ID':
3160
+			case 'ATT_fname':
3161
+			case 'ATT_email':
3162
+			case 'ATT_city':
3163
+			case 'STA_ID':
3164
+			case 'CNT_ID':
3165
+				break;
3166
+			case 'Registration_Count':
3167
+				$orderby = 'Registration_Count';
3168
+				break;
3169
+			default:
3170
+				$orderby = 'ATT_lname';
3171
+		}
3172
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3173
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3174
+		$per_page     = absint($per_page) ? $per_page : 10;
3175
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3176
+		$_where       = [];
3177
+		$search_term  = $this->request->getRequestParam('s');
3178
+		if ($search_term) {
3179
+			$search_term  = '%' . $search_term . '%';
3180
+			$_where['OR'] = [
3181
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3182
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3183
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3184
+				'ATT_fname'                         => ['LIKE', $search_term],
3185
+				'ATT_lname'                         => ['LIKE', $search_term],
3186
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3187
+				'ATT_email'                         => ['LIKE', $search_term],
3188
+				'ATT_address'                       => ['LIKE', $search_term],
3189
+				'ATT_address2'                      => ['LIKE', $search_term],
3190
+				'ATT_city'                          => ['LIKE', $search_term],
3191
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3192
+				'State.STA_name'                    => ['LIKE', $search_term],
3193
+				'ATT_phone'                         => ['LIKE', $search_term],
3194
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3195
+				'Registration.REG_code'             => ['LIKE', $search_term],
3196
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3197
+			];
3198
+		}
3199
+		$offset     = ($current_page - 1) * $per_page;
3200
+		$limit      = $count ? null : [$offset, $per_page];
3201
+		$query_args = [
3202
+			$_where,
3203
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3204
+			'limit'         => $limit,
3205
+		];
3206
+		if (! $count) {
3207
+			$query_args['order_by'] = [$orderby => $sort];
3208
+		}
3209
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3210
+		return $count
3211
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3212
+			: $this->getAttendeeModel()->get_all($query_args);
3213
+	}
3214
+
3215
+
3216
+	/**
3217
+	 * This is just taking care of resending the registration confirmation
3218
+	 *
3219
+	 * @return void
3220
+	 * @throws EE_Error
3221
+	 * @throws InvalidArgumentException
3222
+	 * @throws InvalidDataTypeException
3223
+	 * @throws InvalidInterfaceException
3224
+	 * @throws ReflectionException
3225
+	 */
3226
+	protected function _resend_registration()
3227
+	{
3228
+		$this->_process_resend_registration();
3229
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3230
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3231
+		$query_args  = $redirect_to
3232
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3233
+			: ['action' => 'default'];
3234
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3235
+	}
3236
+
3237
+
3238
+	/**
3239
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3240
+	 * to use when selecting registrations
3241
+	 *
3242
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3243
+	 *                                                     the query parameters from the request
3244
+	 * @return void ends the request with a redirect or download
3245
+	 */
3246
+	public function _registrations_report_base($method_name_for_getting_query_params)
3247
+	{
3248
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3249
+			? $this->request->getRequestParam('EVT_ID', 0, 'int')
3250
+			: null;
3251
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3252
+			$request_params = $this->request->requestParams();
3253
+			wp_redirect(
3254
+				EE_Admin_Page::add_query_args_and_nonce(
3255
+					[
3256
+						'page'        => 'espresso_batch',
3257
+						'batch'       => 'file',
3258
+						'EVT_ID'      => $EVT_ID,
3259
+						'filters'     => urlencode(
3260
+							serialize(
3261
+								$this->$method_name_for_getting_query_params(
3262
+									EEH_Array::is_set($request_params, 'filters', [])
3263
+								)
3264
+							)
3265
+						),
3266
+						'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3267
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3268
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3269
+					]
3270
+				)
3271
+			);
3272
+		} else {
3273
+			// Pull the current request params
3274
+			$request_args = $this->request->requestParams();
3275
+			// Set the required request_args to be passed to the export
3276
+			$required_request_args = [
3277
+				'export' => 'report',
3278
+				'action' => 'registrations_report_for_event',
3279
+				'EVT_ID' => $EVT_ID,
3280
+			];
3281
+			// Merge required request args, overriding any currently set
3282
+			$request_args = array_merge($request_args, $required_request_args);
3283
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3284
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3285
+				$EE_Export = EE_Export::instance($request_args);
3286
+				$EE_Export->export();
3287
+			}
3288
+		}
3289
+	}
3290
+
3291
+
3292
+	/**
3293
+	 * Creates a registration report using only query parameters in the request
3294
+	 *
3295
+	 * @return void
3296
+	 */
3297
+	public function _registrations_report()
3298
+	{
3299
+		$this->_registrations_report_base('_get_registration_query_parameters');
3300
+	}
3301
+
3302
+
3303
+	public function _contact_list_export()
3304
+	{
3305
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3306
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3307
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3308
+			$EE_Export->export_attendees();
3309
+		}
3310
+	}
3311
+
3312
+
3313
+	public function _contact_list_report()
3314
+	{
3315
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3316
+			wp_redirect(
3317
+				EE_Admin_Page::add_query_args_and_nonce(
3318
+					[
3319
+						'page'        => 'espresso_batch',
3320
+						'batch'       => 'file',
3321
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3322
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3323
+					]
3324
+				)
3325
+			);
3326
+		} else {
3327
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3328
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3329
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3330
+				$EE_Export->report_attendees();
3331
+			}
3332
+		}
3333
+	}
3334
+
3335
+
3336
+
3337
+
3338
+
3339
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3340
+	/**
3341
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3342
+	 *
3343
+	 * @return void
3344
+	 * @throws EE_Error
3345
+	 * @throws InvalidArgumentException
3346
+	 * @throws InvalidDataTypeException
3347
+	 * @throws InvalidInterfaceException
3348
+	 * @throws ReflectionException
3349
+	 */
3350
+	protected function _duplicate_attendee()
3351
+	{
3352
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3353
+		$action = $this->request->getRequestParam('return', 'default');
3354
+		// verify we have necessary info
3355
+		if (! $REG_ID) {
3356
+			EE_Error::add_error(
3357
+				esc_html__(
3358
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3359
+					'event_espresso'
3360
+				),
3361
+				__FILE__,
3362
+				__LINE__,
3363
+				__FUNCTION__
3364
+			);
3365
+			$query_args = ['action' => $action];
3366
+			$this->_redirect_after_action('', '', '', $query_args, true);
3367
+		}
3368
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3369
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3370
+		if (! $registration instanceof EE_Registration) {
3371
+			throw new RuntimeException(
3372
+				sprintf(
3373
+					esc_html__(
3374
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3375
+						'event_espresso'
3376
+					),
3377
+					$REG_ID
3378
+				)
3379
+			);
3380
+		}
3381
+		$attendee = $registration->attendee();
3382
+		// remove relation of existing attendee on registration
3383
+		$registration->_remove_relation_to($attendee, 'Attendee');
3384
+		// new attendee
3385
+		$new_attendee = clone $attendee;
3386
+		$new_attendee->set('ATT_ID', 0);
3387
+		$new_attendee->save();
3388
+		// add new attendee to reg
3389
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3390
+		EE_Error::add_success(
3391
+			esc_html__(
3392
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3393
+				'event_espresso'
3394
+			)
3395
+		);
3396
+		// redirect to edit page for attendee
3397
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3398
+		$this->_redirect_after_action('', '', '', $query_args, true);
3399
+	}
3400
+
3401
+
3402
+	/**
3403
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3404
+	 *
3405
+	 * @param int     $post_id
3406
+	 * @param WP_POST $post
3407
+	 * @throws DomainException
3408
+	 * @throws EE_Error
3409
+	 * @throws InvalidArgumentException
3410
+	 * @throws InvalidDataTypeException
3411
+	 * @throws InvalidInterfaceException
3412
+	 * @throws LogicException
3413
+	 * @throws InvalidFormSubmissionException
3414
+	 * @throws ReflectionException
3415
+	 */
3416
+	protected function _insert_update_cpt_item($post_id, $post)
3417
+	{
3418
+		$success  = true;
3419
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3420
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3421
+			: null;
3422
+		// for attendee updates
3423
+		if ($attendee instanceof EE_Attendee) {
3424
+			// note we should only be UPDATING attendees at this point.
3425
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3426
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3427
+			$updated_fields = [
3428
+				'ATT_fname'     => $fname,
3429
+				'ATT_lname'     => $lname,
3430
+				'ATT_full_name' => "{$fname} {$lname}",
3431
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3432
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3433
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3434
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3435
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3436
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3437
+			];
3438
+			foreach ($updated_fields as $field => $value) {
3439
+				$attendee->set($field, $value);
3440
+			}
3441
+
3442
+			// process contact details metabox form handler (which will also save the attendee)
3443
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3444
+			$success              = $contact_details_form->process($this->request->requestParams());
3445
+
3446
+			$attendee_update_callbacks = apply_filters(
3447
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3448
+				[]
3449
+			);
3450
+			foreach ($attendee_update_callbacks as $a_callback) {
3451
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3452
+					throw new EE_Error(
3453
+						sprintf(
3454
+							esc_html__(
3455
+								'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.',
3456
+								'event_espresso'
3457
+							),
3458
+							$a_callback
3459
+						)
3460
+					);
3461
+				}
3462
+			}
3463
+		}
3464
+
3465
+		if ($success === false) {
3466
+			EE_Error::add_error(
3467
+				esc_html__(
3468
+					'Something went wrong with updating the meta table data for the registration.',
3469
+					'event_espresso'
3470
+				),
3471
+				__FILE__,
3472
+				__FUNCTION__,
3473
+				__LINE__
3474
+			);
3475
+		}
3476
+	}
3477
+
3478
+
3479
+	public function trash_cpt_item($post_id)
3480
+	{
3481
+	}
3482
+
3483
+
3484
+	public function delete_cpt_item($post_id)
3485
+	{
3486
+	}
3487
+
3488
+
3489
+	public function restore_cpt_item($post_id)
3490
+	{
3491
+	}
3492
+
3493
+
3494
+	protected function _restore_cpt_item($post_id, $revision_id)
3495
+	{
3496
+	}
3497
+
3498
+
3499
+	/**
3500
+	 * @throws EE_Error
3501
+	 * @throws ReflectionException
3502
+	 * @since 4.10.2.p
3503
+	 */
3504
+	public function attendee_editor_metaboxes()
3505
+	{
3506
+		$this->verify_cpt_object();
3507
+		remove_meta_box(
3508
+			'postexcerpt',
3509
+			$this->_cpt_routes[ $this->_req_action ],
3510
+			'normal'
3511
+		);
3512
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3513
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3514
+			add_meta_box(
3515
+				'postexcerpt',
3516
+				esc_html__('Short Biography', 'event_espresso'),
3517
+				'post_excerpt_meta_box',
3518
+				$this->_cpt_routes[ $this->_req_action ],
3519
+				'normal'
3520
+			);
3521
+		}
3522
+		if (post_type_supports('espresso_attendees', 'comments')) {
3523
+			add_meta_box(
3524
+				'commentsdiv',
3525
+				esc_html__('Notes on the Contact', 'event_espresso'),
3526
+				'post_comment_meta_box',
3527
+				$this->_cpt_routes[ $this->_req_action ],
3528
+				'normal',
3529
+				'core'
3530
+			);
3531
+		}
3532
+		add_meta_box(
3533
+			'attendee_contact_info',
3534
+			esc_html__('Contact Info', 'event_espresso'),
3535
+			[$this, 'attendee_contact_info'],
3536
+			$this->_cpt_routes[ $this->_req_action ],
3537
+			'side',
3538
+			'core'
3539
+		);
3540
+		add_meta_box(
3541
+			'attendee_details_address',
3542
+			esc_html__('Address Details', 'event_espresso'),
3543
+			[$this, 'attendee_address_details'],
3544
+			$this->_cpt_routes[ $this->_req_action ],
3545
+			'normal',
3546
+			'core'
3547
+		);
3548
+		add_meta_box(
3549
+			'attendee_registrations',
3550
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3551
+			[$this, 'attendee_registrations_meta_box'],
3552
+			$this->_cpt_routes[ $this->_req_action ],
3553
+			'normal',
3554
+			'high'
3555
+		);
3556
+	}
3557
+
3558
+
3559
+	/**
3560
+	 * Metabox for attendee contact info
3561
+	 *
3562
+	 * @param WP_Post $post wp post object
3563
+	 * @return void attendee contact info ( and form )
3564
+	 * @throws EE_Error
3565
+	 * @throws InvalidArgumentException
3566
+	 * @throws InvalidDataTypeException
3567
+	 * @throws InvalidInterfaceException
3568
+	 * @throws LogicException
3569
+	 * @throws DomainException
3570
+	 */
3571
+	public function attendee_contact_info($post)
3572
+	{
3573
+		// get attendee object ( should already have it )
3574
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3575
+		$form->enqueueStylesAndScripts();
3576
+		echo $form->display(); // already escaped
3577
+	}
3578
+
3579
+
3580
+	/**
3581
+	 * Return form handler for the contact details metabox
3582
+	 *
3583
+	 * @param EE_Attendee $attendee
3584
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3585
+	 * @throws DomainException
3586
+	 * @throws InvalidArgumentException
3587
+	 * @throws InvalidDataTypeException
3588
+	 * @throws InvalidInterfaceException
3589
+	 */
3590
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3591
+	{
3592
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3593
+	}
3594
+
3595
+
3596
+	/**
3597
+	 * Metabox for attendee details
3598
+	 *
3599
+	 * @param WP_Post $post wp post object
3600
+	 * @throws EE_Error
3601
+	 * @throws ReflectionException
3602
+	 */
3603
+	public function attendee_address_details($post)
3604
+	{
3605
+		// get attendee object (should already have it)
3606
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3607
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3608
+			new EE_Question_Form_Input(
3609
+				EE_Question::new_instance(
3610
+					[
3611
+						'QST_ID'           => 0,
3612
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3613
+						'QST_system'       => 'admin-state',
3614
+					]
3615
+				),
3616
+				EE_Answer::new_instance(
3617
+					[
3618
+						'ANS_ID'    => 0,
3619
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3620
+					]
3621
+				),
3622
+				[
3623
+					'input_id'       => 'STA_ID',
3624
+					'input_name'     => 'STA_ID',
3625
+					'input_prefix'   => '',
3626
+					'append_qstn_id' => false,
3627
+				]
3628
+			)
3629
+		);
3630
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3631
+			new EE_Question_Form_Input(
3632
+				EE_Question::new_instance(
3633
+					[
3634
+						'QST_ID'           => 0,
3635
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3636
+						'QST_system'       => 'admin-country',
3637
+					]
3638
+				),
3639
+				EE_Answer::new_instance(
3640
+					[
3641
+						'ANS_ID'    => 0,
3642
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3643
+					]
3644
+				),
3645
+				[
3646
+					'input_id'       => 'CNT_ISO',
3647
+					'input_name'     => 'CNT_ISO',
3648
+					'input_prefix'   => '',
3649
+					'append_qstn_id' => false,
3650
+				]
3651
+			)
3652
+		);
3653
+		$template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3654
+		EEH_Template::display_template($template, $this->_template_args);
3655
+	}
3656
+
3657
+
3658
+	/**
3659
+	 * _attendee_details
3660
+	 *
3661
+	 * @param $post
3662
+	 * @return void
3663
+	 * @throws DomainException
3664
+	 * @throws EE_Error
3665
+	 * @throws InvalidArgumentException
3666
+	 * @throws InvalidDataTypeException
3667
+	 * @throws InvalidInterfaceException
3668
+	 * @throws ReflectionException
3669
+	 */
3670
+	public function attendee_registrations_meta_box($post)
3671
+	{
3672
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3673
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3674
+		$template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3675
+		EEH_Template::display_template($template, $this->_template_args);
3676
+	}
3677
+
3678
+
3679
+	/**
3680
+	 * add in the form fields for the attendee edit
3681
+	 *
3682
+	 * @param WP_Post $post wp post object
3683
+	 * @return void echos html for new form.
3684
+	 * @throws DomainException
3685
+	 */
3686
+	public function after_title_form_fields($post)
3687
+	{
3688
+		if ($post->post_type === 'espresso_attendees') {
3689
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3690
+			$template_args['attendee'] = $this->_cpt_model_obj;
3691
+			EEH_Template::display_template($template, $template_args);
3692
+		}
3693
+	}
3694
+
3695
+
3696
+	/**
3697
+	 * _trash_or_restore_attendee
3698
+	 *
3699
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3700
+	 * @return void
3701
+	 * @throws EE_Error
3702
+	 * @throws InvalidArgumentException
3703
+	 * @throws InvalidDataTypeException
3704
+	 * @throws InvalidInterfaceException
3705
+	 */
3706
+	protected function _trash_or_restore_attendees($trash = true)
3707
+	{
3708
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3709
+		$status = $trash ? 'trash' : 'publish';
3710
+		// Checkboxes
3711
+		if ($this->request->requestParamIsSet('checkbox')) {
3712
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3713
+			// if array has more than one element than success message should be plural
3714
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3715
+			// cycle thru checkboxes
3716
+			foreach ($ATT_IDs as $ATT_ID) {
3717
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3718
+				if (! $updated) {
3719
+					$success = 0;
3720
+				}
3721
+			}
3722
+		} else {
3723
+			// grab single id and delete
3724
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3725
+			// update attendee
3726
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3727
+		}
3728
+		$what        = $success > 1
3729
+			? esc_html__('Contacts', 'event_espresso')
3730
+			: esc_html__('Contact', 'event_espresso');
3731
+		$action_desc = $trash
3732
+			? esc_html__('moved to the trash', 'event_espresso')
3733
+			: esc_html__('restored', 'event_espresso');
3734
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3735
+	}
3736 3736
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2875 added lines, -2875 removed lines patch added patch discarded remove patch
@@ -16,2882 +16,2882 @@
 block discarded – undo
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18 18
 
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+
55
+	/**
56
+	 * Initialize page props for this admin page group.
57
+	 */
58
+	protected function _init_page_props()
59
+	{
60
+		$this->page_slug        = EVENTS_PG_SLUG;
61
+		$this->page_label       = EVENTS_LABEL;
62
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
63
+		$this->_admin_base_path = EVENTS_ADMIN;
64
+		$this->_cpt_model_names = [
65
+			'create_new' => 'EEM_Event',
66
+			'edit'       => 'EEM_Event',
67
+		];
68
+		$this->_cpt_edit_routes = [
69
+			'espresso_events' => 'edit',
70
+		];
71
+		add_action(
72
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
+			[$this, 'verify_event_edit'],
74
+			10,
75
+			2
76
+		);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the ajax hooks used for this admin page group.
82
+	 */
83
+	protected function _ajax_hooks()
84
+	{
85
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Sets the page properties for this admin page group.
91
+	 */
92
+	protected function _define_page_props()
93
+	{
94
+		$this->_admin_page_title = EVENTS_LABEL;
95
+		$this->_labels           = [
96
+			'buttons'      => [
97
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
98
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
+			],
104
+			'editor_title' => [
105
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
+			],
107
+			'publishbox'   => [
108
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
110
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
+			],
114
+		];
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the page routes property for this admin page group.
120
+	 */
121
+	protected function _set_page_routes()
122
+	{
123
+		// load formatter helper
124
+		// load field generator helper
125
+		// is there a evt_id in the request?
126
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
+
129
+		$this->_page_routes = [
130
+			'default'                       => [
131
+				'func'       => '_events_overview_list_table',
132
+				'capability' => 'ee_read_events',
133
+			],
134
+			'create_new'                    => [
135
+				'func'       => '_create_new_cpt_item',
136
+				'capability' => 'ee_edit_events',
137
+			],
138
+			'edit'                          => [
139
+				'func'       => '_edit_cpt_item',
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $EVT_ID,
142
+			],
143
+			'copy_event'                    => [
144
+				'func'       => '_copy_events',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+				'noheader'   => true,
148
+			],
149
+			'trash_event'                   => [
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => ['event_status' => 'trash'],
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $EVT_ID,
154
+				'noheader'   => true,
155
+			],
156
+			'trash_events'                  => [
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => ['event_status' => 'trash'],
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			],
162
+			'restore_event'                 => [
163
+				'func'       => '_trash_or_restore_event',
164
+				'args'       => ['event_status' => 'draft'],
165
+				'capability' => 'ee_delete_event',
166
+				'obj_id'     => $EVT_ID,
167
+				'noheader'   => true,
168
+			],
169
+			'restore_events'                => [
170
+				'func'       => '_trash_or_restore_events',
171
+				'args'       => ['event_status' => 'draft'],
172
+				'capability' => 'ee_delete_events',
173
+				'noheader'   => true,
174
+			],
175
+			'delete_event'                  => [
176
+				'func'       => '_delete_event',
177
+				'capability' => 'ee_delete_event',
178
+				'obj_id'     => $EVT_ID,
179
+				'noheader'   => true,
180
+			],
181
+			'delete_events'                 => [
182
+				'func'       => '_delete_events',
183
+				'capability' => 'ee_delete_events',
184
+				'noheader'   => true,
185
+			],
186
+			'view_report'                   => [
187
+				'func'       => '_view_report',
188
+				'capability' => 'ee_edit_events',
189
+			],
190
+			'default_event_settings'        => [
191
+				'func'       => '_default_event_settings',
192
+				'capability' => 'manage_options',
193
+			],
194
+			'update_default_event_settings' => [
195
+				'func'       => '_update_default_event_settings',
196
+				'capability' => 'manage_options',
197
+				'noheader'   => true,
198
+			],
199
+			'template_settings'             => [
200
+				'func'       => '_template_settings',
201
+				'capability' => 'manage_options',
202
+			],
203
+			// event category tab related
204
+			'add_category'                  => [
205
+				'func'       => '_category_details',
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => ['add'],
208
+			],
209
+			'edit_category'                 => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['edit'],
213
+			],
214
+			'delete_categories'             => [
215
+				'func'       => '_delete_categories',
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			],
219
+			'delete_category'               => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'insert_category'               => [
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => ['new_category' => true],
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			],
230
+			'update_category'               => [
231
+				'func'       => '_insert_or_update_category',
232
+				'args'       => ['new_category' => false],
233
+				'capability' => 'ee_edit_event_category',
234
+				'noheader'   => true,
235
+			],
236
+			'category_list'                 => [
237
+				'func'       => '_category_list_table',
238
+				'capability' => 'ee_manage_event_categories',
239
+			],
240
+			'preview_deletion'              => [
241
+				'func'       => 'previewDeletion',
242
+				'capability' => 'ee_delete_events',
243
+			],
244
+			'confirm_deletion'              => [
245
+				'func'       => 'confirmDeletion',
246
+				'capability' => 'ee_delete_events',
247
+				'noheader'   => true,
248
+			],
249
+		];
250
+	}
251
+
252
+
253
+	/**
254
+	 * Set the _page_config property for this admin page group.
255
+	 */
256
+	protected function _set_page_config()
257
+	{
258
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
259
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
+		$this->_page_config = [
261
+			'default'                => [
262
+				'nav'           => [
263
+					'label' => esc_html__('Overview', 'event_espresso'),
264
+					'order' => 10,
265
+				],
266
+				'list_table'    => 'Events_Admin_List_Table',
267
+				'help_tabs'     => [
268
+					'events_overview_help_tab'                       => [
269
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
270
+						'filename' => 'events_overview',
271
+					],
272
+					'events_overview_table_column_headings_help_tab' => [
273
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
+						'filename' => 'events_overview_table_column_headings',
275
+					],
276
+					'events_overview_filters_help_tab'               => [
277
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
+						'filename' => 'events_overview_filters',
279
+					],
280
+					'events_overview_view_help_tab'                  => [
281
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
+						'filename' => 'events_overview_views',
283
+					],
284
+					'events_overview_other_help_tab'                 => [
285
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
+						'filename' => 'events_overview_other',
287
+					],
288
+				],
289
+				'qtips'         => [
290
+					'EE_Event_List_Table_Tips',
291
+				],
292
+				'require_nonce' => false,
293
+			],
294
+			'create_new'             => [
295
+				'nav'           => [
296
+					'label'      => esc_html__('Add Event', 'event_espresso'),
297
+					'order'      => 5,
298
+					'persistent' => false,
299
+				],
300
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
+				'help_tabs'     => [
302
+					'event_editor_help_tab'                            => [
303
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
304
+						'filename' => 'event_editor',
305
+					],
306
+					'event_editor_title_richtexteditor_help_tab'       => [
307
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
+						'filename' => 'event_editor_title_richtexteditor',
309
+					],
310
+					'event_editor_venue_details_help_tab'              => [
311
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
+						'filename' => 'event_editor_venue_details',
313
+					],
314
+					'event_editor_event_datetimes_help_tab'            => [
315
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
+						'filename' => 'event_editor_event_datetimes',
317
+					],
318
+					'event_editor_event_tickets_help_tab'              => [
319
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
+						'filename' => 'event_editor_event_tickets',
321
+					],
322
+					'event_editor_event_registration_options_help_tab' => [
323
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
+						'filename' => 'event_editor_event_registration_options',
325
+					],
326
+					'event_editor_tags_categories_help_tab'            => [
327
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
+						'filename' => 'event_editor_tags_categories',
329
+					],
330
+					'event_editor_questions_registrants_help_tab'      => [
331
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
+						'filename' => 'event_editor_questions_registrants',
333
+					],
334
+					'event_editor_save_new_event_help_tab'             => [
335
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
336
+						'filename' => 'event_editor_save_new_event',
337
+					],
338
+					'event_editor_other_help_tab'                      => [
339
+						'title'    => esc_html__('Event Other', 'event_espresso'),
340
+						'filename' => 'event_editor_other',
341
+					],
342
+				],
343
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
+				'require_nonce' => false,
345
+			],
346
+			'edit'                   => [
347
+				'nav'           => [
348
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
349
+					'order'      => 5,
350
+					'persistent' => false,
351
+					'url'        => $post_id
352
+						? EE_Admin_Page::add_query_args_and_nonce(
353
+							['post' => $post_id, 'action' => 'edit'],
354
+							$this->_current_page_view_url
355
+						)
356
+						: $this->_admin_base_url,
357
+				],
358
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
+				'help_tabs'     => [
360
+					'event_editor_help_tab'                            => [
361
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
362
+						'filename' => 'event_editor',
363
+					],
364
+					'event_editor_title_richtexteditor_help_tab'       => [
365
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
+						'filename' => 'event_editor_title_richtexteditor',
367
+					],
368
+					'event_editor_venue_details_help_tab'              => [
369
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
+						'filename' => 'event_editor_venue_details',
371
+					],
372
+					'event_editor_event_datetimes_help_tab'            => [
373
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
+						'filename' => 'event_editor_event_datetimes',
375
+					],
376
+					'event_editor_event_tickets_help_tab'              => [
377
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
+						'filename' => 'event_editor_event_tickets',
379
+					],
380
+					'event_editor_event_registration_options_help_tab' => [
381
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
+						'filename' => 'event_editor_event_registration_options',
383
+					],
384
+					'event_editor_tags_categories_help_tab'            => [
385
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
+						'filename' => 'event_editor_tags_categories',
387
+					],
388
+					'event_editor_questions_registrants_help_tab'      => [
389
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
+						'filename' => 'event_editor_questions_registrants',
391
+					],
392
+					'event_editor_save_new_event_help_tab'             => [
393
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
394
+						'filename' => 'event_editor_save_new_event',
395
+					],
396
+					'event_editor_other_help_tab'                      => [
397
+						'title'    => esc_html__('Event Other', 'event_espresso'),
398
+						'filename' => 'event_editor_other',
399
+					],
400
+				],
401
+				'require_nonce' => false,
402
+			],
403
+			'default_event_settings' => [
404
+				'nav'           => [
405
+					'label' => esc_html__('Default Settings', 'event_espresso'),
406
+					'order' => 40,
407
+				],
408
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
409
+				'labels'        => [
410
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
411
+				],
412
+				'help_tabs'     => [
413
+					'default_settings_help_tab'        => [
414
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
415
+						'filename' => 'events_default_settings',
416
+					],
417
+					'default_settings_status_help_tab' => [
418
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
419
+						'filename' => 'events_default_settings_status',
420
+					],
421
+					'default_maximum_tickets_help_tab' => [
422
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
423
+						'filename' => 'events_default_settings_max_tickets',
424
+					],
425
+				],
426
+				'require_nonce' => false,
427
+			],
428
+			// template settings
429
+			'template_settings'      => [
430
+				'nav'           => [
431
+					'label' => esc_html__('Templates', 'event_espresso'),
432
+					'order' => 30,
433
+				],
434
+				'metaboxes'     => $this->_default_espresso_metaboxes,
435
+				'help_tabs'     => [
436
+					'general_settings_templates_help_tab' => [
437
+						'title'    => esc_html__('Templates', 'event_espresso'),
438
+						'filename' => 'general_settings_templates',
439
+					],
440
+				],
441
+				'require_nonce' => false,
442
+			],
443
+			// event category stuff
444
+			'add_category'           => [
445
+				'nav'           => [
446
+					'label'      => esc_html__('Add Category', 'event_espresso'),
447
+					'order'      => 15,
448
+					'persistent' => false,
449
+				],
450
+				'help_tabs'     => [
451
+					'add_category_help_tab' => [
452
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
+						'filename' => 'events_add_category',
454
+					],
455
+				],
456
+				'metaboxes'     => ['_publish_post_box'],
457
+				'require_nonce' => false,
458
+			],
459
+			'edit_category'          => [
460
+				'nav'           => [
461
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
462
+					'order'      => 15,
463
+					'persistent' => false,
464
+					'url'        => $EVT_CAT_ID
465
+						? add_query_arg(
466
+							['EVT_CAT_ID' => $EVT_CAT_ID],
467
+							$this->_current_page_view_url
468
+						)
469
+						: $this->_admin_base_url,
470
+				],
471
+				'help_tabs'     => [
472
+					'edit_category_help_tab' => [
473
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
474
+						'filename' => 'events_edit_category',
475
+					],
476
+				],
477
+				'metaboxes'     => ['_publish_post_box'],
478
+				'require_nonce' => false,
479
+			],
480
+			'category_list'          => [
481
+				'nav'           => [
482
+					'label' => esc_html__('Categories', 'event_espresso'),
483
+					'order' => 20,
484
+				],
485
+				'list_table'    => 'Event_Categories_Admin_List_Table',
486
+				'help_tabs'     => [
487
+					'events_categories_help_tab'                       => [
488
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
489
+						'filename' => 'events_categories',
490
+					],
491
+					'events_categories_table_column_headings_help_tab' => [
492
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
+						'filename' => 'events_categories_table_column_headings',
494
+					],
495
+					'events_categories_view_help_tab'                  => [
496
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
+						'filename' => 'events_categories_views',
498
+					],
499
+					'events_categories_other_help_tab'                 => [
500
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
+						'filename' => 'events_categories_other',
502
+					],
503
+				],
504
+				'metaboxes'     => $this->_default_espresso_metaboxes,
505
+				'require_nonce' => false,
506
+			],
507
+			'preview_deletion'       => [
508
+				'nav'           => [
509
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
+					'order'      => 15,
511
+					'persistent' => false,
512
+					'url'        => '',
513
+				],
514
+				'require_nonce' => false,
515
+			],
516
+		];
517
+	}
518
+
519
+
520
+	/**
521
+	 * Used to register any global screen options if necessary for every route in this admin page group.
522
+	 */
523
+	protected function _add_screen_options()
524
+	{
525
+	}
526
+
527
+
528
+	/**
529
+	 * Implementing the screen options for the 'default' route.
530
+	 *
531
+	 * @throws InvalidArgumentException
532
+	 * @throws InvalidDataTypeException
533
+	 * @throws InvalidInterfaceException
534
+	 */
535
+	protected function _add_screen_options_default()
536
+	{
537
+		$this->_per_page_screen_option();
538
+	}
539
+
540
+
541
+	/**
542
+	 * Implementing screen options for the category list route.
543
+	 *
544
+	 * @throws InvalidArgumentException
545
+	 * @throws InvalidDataTypeException
546
+	 * @throws InvalidInterfaceException
547
+	 */
548
+	protected function _add_screen_options_category_list()
549
+	{
550
+		$page_title              = $this->_admin_page_title;
551
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
552
+		$this->_per_page_screen_option();
553
+		$this->_admin_page_title = $page_title;
554
+	}
555
+
556
+
557
+	/**
558
+	 * Used to register any global feature pointers for the admin page group.
559
+	 */
560
+	protected function _add_feature_pointers()
561
+	{
562
+	}
563
+
564
+
565
+	/**
566
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
567
+	 */
568
+	public function load_scripts_styles()
569
+	{
570
+		wp_register_style(
571
+			'events-admin-css',
572
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
573
+			[],
574
+			EVENT_ESPRESSO_VERSION
575
+		);
576
+		wp_register_style(
577
+			'ee-cat-admin',
578
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
579
+			[],
580
+			EVENT_ESPRESSO_VERSION
581
+		);
582
+		wp_enqueue_style('events-admin-css');
583
+		wp_enqueue_style('ee-cat-admin');
584
+		// scripts
585
+		wp_register_script(
586
+			'event_editor_js',
587
+			EVENTS_ASSETS_URL . 'event_editor.js',
588
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
589
+			EVENT_ESPRESSO_VERSION,
590
+			true
591
+		);
592
+	}
593
+
594
+
595
+	/**
596
+	 * Enqueuing scripts and styles specific to this view
597
+	 */
598
+	public function load_scripts_styles_create_new()
599
+	{
600
+		$this->load_scripts_styles_edit();
601
+	}
602
+
603
+
604
+	/**
605
+	 * Enqueuing scripts and styles specific to this view
606
+	 */
607
+	public function load_scripts_styles_edit()
608
+	{
609
+		// styles
610
+		wp_enqueue_style('espresso-ui-theme');
611
+		wp_register_style(
612
+			'event-editor-css',
613
+			EVENTS_ASSETS_URL . 'event-editor.css',
614
+			['ee-admin-css'],
615
+			EVENT_ESPRESSO_VERSION
616
+		);
617
+		wp_enqueue_style('event-editor-css');
618
+		// scripts
619
+		if (! $this->admin_config->useAdvancedEditor()) {
620
+			wp_register_script(
621
+				'event-datetime-metabox',
622
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
623
+				['event_editor_js', 'ee-datepicker'],
624
+				EVENT_ESPRESSO_VERSION
625
+			);
626
+			wp_enqueue_script('event-datetime-metabox');
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Populating the _views property for the category list table view.
633
+	 */
634
+	protected function _set_list_table_views_category_list()
635
+	{
636
+		$this->_views = [
637
+			'all' => [
638
+				'slug'        => 'all',
639
+				'label'       => esc_html__('All', 'event_espresso'),
640
+				'count'       => 0,
641
+				'bulk_action' => [
642
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
643
+				],
644
+			],
645
+		];
646
+	}
647
+
648
+
649
+	/**
650
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
651
+	 */
652
+	public function admin_init()
653
+	{
654
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
655
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
656
+			'event_espresso'
657
+		);
658
+	}
659
+
660
+
661
+	/**
662
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
663
+	 * group.
664
+	 */
665
+	public function admin_notices()
666
+	{
667
+	}
668
+
669
+
670
+	/**
671
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
672
+	 * this admin page group.
673
+	 */
674
+	public function admin_footer_scripts()
675
+	{
676
+	}
677
+
678
+
679
+	/**
680
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
681
+	 * warning (via EE_Error::add_error());
682
+	 *
683
+	 * @param EE_Event $event Event object
684
+	 * @param string   $req_type
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 * @throws ReflectionException
688
+	 */
689
+	public function verify_event_edit($event = null, $req_type = '')
690
+	{
691
+		// don't need to do this when processing
692
+		if (! empty($req_type)) {
693
+			return;
694
+		}
695
+		// no event?
696
+		if (! $event instanceof EE_Event) {
697
+			$event = $this->_cpt_model_obj;
698
+		}
699
+		// STILL no event?
700
+		if (! $event instanceof EE_Event) {
701
+			return;
702
+		}
703
+		$orig_status = $event->status();
704
+		// first check if event is active.
705
+		if (
706
+			$orig_status === EEM_Event::cancelled
707
+			|| $orig_status === EEM_Event::postponed
708
+			|| $event->is_expired()
709
+			|| $event->is_inactive()
710
+		) {
711
+			return;
712
+		}
713
+		// made it here so it IS active... next check that any of the tickets are sold.
714
+		if ($event->is_sold_out(true)) {
715
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
716
+				EE_Error::add_attention(
717
+					sprintf(
718
+						esc_html__(
719
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
720
+							'event_espresso'
721
+						),
722
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
723
+					)
724
+				);
725
+			}
726
+			return;
727
+		}
728
+		if ($orig_status === EEM_Event::sold_out) {
729
+			EE_Error::add_attention(
730
+				sprintf(
731
+					esc_html__(
732
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
733
+						'event_espresso'
734
+					),
735
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
736
+				)
737
+			);
738
+		}
739
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
740
+		if (! $event->tickets_on_sale()) {
741
+			return;
742
+		}
743
+		// made it here so show warning
744
+		$this->_edit_event_warning();
745
+	}
746
+
747
+
748
+	/**
749
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
750
+	 * When needed, hook this into a EE_Error::add_error() notice.
751
+	 *
752
+	 * @access protected
753
+	 * @return void
754
+	 */
755
+	protected function _edit_event_warning()
756
+	{
757
+		// we don't want to add warnings during these requests
758
+		if ($this->request->getRequestParam('action') === 'editpost') {
759
+			return;
760
+		}
761
+		EE_Error::add_attention(
762
+			sprintf(
763
+				esc_html__(
764
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
765
+					'event_espresso'
766
+				),
767
+				'<a class="espresso-help-tab-lnk">',
768
+				'</a>'
769
+			)
770
+		);
771
+	}
772
+
773
+
774
+	/**
775
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
776
+	 * Otherwise, do the normal logic
777
+	 *
778
+	 * @return void
779
+	 * @throws EE_Error
780
+	 * @throws InvalidArgumentException
781
+	 * @throws InvalidDataTypeException
782
+	 * @throws InvalidInterfaceException
783
+	 */
784
+	protected function _create_new_cpt_item()
785
+	{
786
+		$has_timezone_string = get_option('timezone_string');
787
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
788
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
789
+			EE_Error::add_attention(
790
+				sprintf(
791
+					esc_html__(
792
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
793
+						'event_espresso'
794
+					),
795
+					'<br>',
796
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
797
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
798
+					. '</select>',
799
+					'<button class="button button-secondary timezone-submit">',
800
+					'</button><span class="spinner"></span>'
801
+				),
802
+				__FILE__,
803
+				__FUNCTION__,
804
+				__LINE__
805
+			);
806
+		}
807
+		parent::_create_new_cpt_item();
808
+	}
809
+
810
+
811
+	/**
812
+	 * Sets the _views property for the default route in this admin page group.
813
+	 */
814
+	protected function _set_list_table_views_default()
815
+	{
816
+		$this->_views = [
817
+			'all'   => [
818
+				'slug'        => 'all',
819
+				'label'       => esc_html__('View All Events', 'event_espresso'),
820
+				'count'       => 0,
821
+				'bulk_action' => [
822
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
823
+				],
824
+			],
825
+			'draft' => [
826
+				'slug'        => 'draft',
827
+				'label'       => esc_html__('Draft', 'event_espresso'),
828
+				'count'       => 0,
829
+				'bulk_action' => [
830
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
831
+				],
832
+			],
833
+		];
834
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
835
+			$this->_views['trash'] = [
836
+				'slug'        => 'trash',
837
+				'label'       => esc_html__('Trash', 'event_espresso'),
838
+				'count'       => 0,
839
+				'bulk_action' => [
840
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
841
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
842
+				],
843
+			];
844
+		}
845
+	}
846
+
847
+
848
+	/**
849
+	 * Provides the legend item array for the default list table view.
850
+	 *
851
+	 * @return array
852
+	 * @throws EE_Error
853
+	 * @throws EE_Error
854
+	 */
855
+	protected function _event_legend_items()
856
+	{
857
+		$items    = [
858
+			'view_details'   => [
859
+				'class' => 'dashicons dashicons-search',
860
+				'desc'  => esc_html__('View Event', 'event_espresso'),
861
+			],
862
+			'edit_event'     => [
863
+				'class' => 'ee-icon ee-icon-calendar-edit',
864
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
865
+			],
866
+			'view_attendees' => [
867
+				'class' => 'dashicons dashicons-groups',
868
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
869
+			],
870
+		];
871
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
872
+		$statuses = [
873
+			'sold_out_status'  => [
874
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
875
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
876
+			],
877
+			'active_status'    => [
878
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
879
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
880
+			],
881
+			'upcoming_status'  => [
882
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
883
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
884
+			],
885
+			'postponed_status' => [
886
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
887
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
888
+			],
889
+			'cancelled_status' => [
890
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
891
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
892
+			],
893
+			'expired_status'   => [
894
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
895
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
896
+			],
897
+			'inactive_status'  => [
898
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
899
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
900
+			],
901
+		];
902
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
903
+		return array_merge($items, $statuses);
904
+	}
905
+
906
+
907
+	/**
908
+	 * @return EEM_Event
909
+	 * @throws EE_Error
910
+	 * @throws InvalidArgumentException
911
+	 * @throws InvalidDataTypeException
912
+	 * @throws InvalidInterfaceException
913
+	 * @throws ReflectionException
914
+	 */
915
+	private function _event_model()
916
+	{
917
+		if (! $this->_event_model instanceof EEM_Event) {
918
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
919
+		}
920
+		return $this->_event_model;
921
+	}
922
+
923
+
924
+	/**
925
+	 * Adds extra buttons to the WP CPT permalink field row.
926
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
927
+	 *
928
+	 * @param string $return    the current html
929
+	 * @param int    $id        the post id for the page
930
+	 * @param string $new_title What the title is
931
+	 * @param string $new_slug  what the slug is
932
+	 * @return string            The new html string for the permalink area
933
+	 */
934
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
935
+	{
936
+		// make sure this is only when editing
937
+		if (! empty($id)) {
938
+			$post   = get_post($id);
939
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
940
+					   . esc_html__('Shortcode', 'event_espresso')
941
+					   . '</a> ';
942
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
943
+					   . $post->ID
944
+					   . ']">';
945
+		}
946
+		return $return;
947
+	}
948
+
949
+
950
+	/**
951
+	 * _events_overview_list_table
952
+	 * This contains the logic for showing the events_overview list
953
+	 *
954
+	 * @access protected
955
+	 * @return void
956
+	 * @throws DomainException
957
+	 * @throws EE_Error
958
+	 * @throws InvalidArgumentException
959
+	 * @throws InvalidDataTypeException
960
+	 * @throws InvalidInterfaceException
961
+	 */
962
+	protected function _events_overview_list_table()
963
+	{
964
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
965
+		$after_list_table                           = [];
966
+		$after_list_table['view_event_list_button'] = EEH_HTML::br();
967
+		$after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link(
968
+			get_post_type_archive_link('espresso_events'),
969
+			esc_html__('View Event Archive Page', 'event_espresso'),
970
+			'button'
971
+		);
972
+		$after_list_table['legend']                 = $this->_display_legend($this->_event_legend_items());
973
+		$this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
974
+			'create_new',
975
+			'add',
976
+			[],
977
+			'add-new-h2'
978
+		);
979
+		$this->_template_args['after_list_table']   = array_merge(
980
+			(array) $this->_template_args['after_list_table'],
981
+			$after_list_table
982
+		);
983
+		$this->display_admin_list_table_page_with_no_sidebar();
984
+	}
985
+
986
+
987
+	/**
988
+	 * this allows for extra misc actions in the default WP publish box
989
+	 *
990
+	 * @return void
991
+	 * @throws DomainException
992
+	 * @throws EE_Error
993
+	 * @throws InvalidArgumentException
994
+	 * @throws InvalidDataTypeException
995
+	 * @throws InvalidInterfaceException
996
+	 * @throws ReflectionException
997
+	 */
998
+	public function extra_misc_actions_publish_box()
999
+	{
1000
+		$this->_generate_publish_box_extra_content();
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1006
+	 * saved.
1007
+	 * Typically you would use this to save any additional data.
1008
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1009
+	 * ALSO very important.  When a post transitions from scheduled to published,
1010
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1011
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1012
+	 *
1013
+	 * @access protected
1014
+	 * @abstract
1015
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1016
+	 * @param object $post    The post object of the cpt that was saved.
1017
+	 * @return void
1018
+	 * @throws EE_Error
1019
+	 * @throws InvalidArgumentException
1020
+	 * @throws InvalidDataTypeException
1021
+	 * @throws InvalidInterfaceException
1022
+	 * @throws ReflectionException
1023
+	 */
1024
+	protected function _insert_update_cpt_item($post_id, $post)
1025
+	{
1026
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1027
+			// get out we're not processing an event save.
1028
+			return;
1029
+		}
1030
+		$event_values = [
1031
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1032
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1033
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1034
+		];
1035
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1036
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1037
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1038
+				'display_ticket_selector',
1039
+				false,
1040
+				'bool'
1041
+			);
1042
+			$event_values['EVT_additional_limit']            = min(
1043
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1044
+				$this->request->getRequestParam('additional_limit', null, 'int')
1045
+			);
1046
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1047
+				'EVT_default_registration_status',
1048
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1049
+			);
1050
+
1051
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1052
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1053
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1054
+		}
1055
+		// update event
1056
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1057
+		// get event_object for other metaboxes...
1058
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1059
+		// i have to setup where conditions to override the filters in the model
1060
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1061
+		$event = $this->_event_model()->get_one(
1062
+			[
1063
+				[
1064
+					$this->_event_model()->primary_key_name() => $post_id,
1065
+					'OR'                                      => [
1066
+						'status'   => $post->post_status,
1067
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1068
+						// but the returned object here has a status of "publish", so use the original post status as well
1069
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1070
+					],
1071
+				],
1072
+			]
1073
+		);
1074
+
1075
+		// the following are default callbacks for event attachment updates
1076
+		// that can be overridden by caffeinated functionality and/or addons.
1077
+		$event_update_callbacks = [];
1078
+		if (! $this->admin_config->useAdvancedEditor()) {
1079
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1080
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1081
+		}
1082
+		$event_update_callbacks = apply_filters(
1083
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1084
+			$event_update_callbacks
1085
+		);
1086
+
1087
+		$att_success = true;
1088
+		foreach ($event_update_callbacks as $e_callback) {
1089
+			$_success = is_callable($e_callback)
1090
+				? $e_callback($event, $this->request->requestParams())
1091
+				: false;
1092
+			// if ANY of these updates fail then we want the appropriate global error message
1093
+			$att_success = $_success !== false ? $att_success : false;
1094
+		}
1095
+		// any errors?
1096
+		if ($success && $att_success === false) {
1097
+			EE_Error::add_error(
1098
+				esc_html__(
1099
+					'Event Details saved successfully but something went wrong with saving attachments.',
1100
+					'event_espresso'
1101
+				),
1102
+				__FILE__,
1103
+				__FUNCTION__,
1104
+				__LINE__
1105
+			);
1106
+		} elseif ($success === false) {
1107
+			EE_Error::add_error(
1108
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1109
+				__FILE__,
1110
+				__FUNCTION__,
1111
+				__LINE__
1112
+			);
1113
+		}
1114
+	}
1115
+
1116
+
1117
+	/**
1118
+	 * @param int $post_id
1119
+	 * @param int $revision_id
1120
+	 * @throws EE_Error
1121
+	 * @throws EE_Error
1122
+	 * @throws ReflectionException
1123
+	 * @see parent::restore_item()
1124
+	 */
1125
+	protected function _restore_cpt_item($post_id, $revision_id)
1126
+	{
1127
+		// copy existing event meta to new post
1128
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1129
+		if ($post_evt instanceof EE_Event) {
1130
+			// meta revision restore
1131
+			$post_evt->restore_revision($revision_id);
1132
+			// related objs restore
1133
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1134
+		}
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * Attach the venue to the Event
1140
+	 *
1141
+	 * @param EE_Event $event Event Object to add the venue to
1142
+	 * @param array    $data  The request data from the form
1143
+	 * @return bool           Success or fail.
1144
+	 * @throws EE_Error
1145
+	 * @throws ReflectionException
1146
+	 */
1147
+	protected function _default_venue_update(EE_Event $event, $data)
1148
+	{
1149
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1150
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1151
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1152
+		// very important.  If we don't have a venue name...
1153
+		// then we'll get out because not necessary to create empty venue
1154
+		if (empty($data['venue_title'])) {
1155
+			return false;
1156
+		}
1157
+		$venue_array = [
1158
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1159
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1160
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1161
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1162
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1163
+				? $data['venue_short_description']
1164
+				: null,
1165
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1166
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1167
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1168
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1169
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1170
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1171
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1172
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1173
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1174
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1175
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1176
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1177
+			'status'              => 'publish',
1178
+		];
1179
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1180
+		if (! empty($venue_id)) {
1181
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1182
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1183
+			// we've gotta make sure that the venue is always attached to a revision..
1184
+			// add_relation_to should take care of making sure that the relation is already present.
1185
+			$event->_add_relation_to($venue_id, 'Venue');
1186
+			return $rows_affected > 0;
1187
+		}
1188
+		// we insert the venue
1189
+		$venue_id = $venue_model->insert($venue_array);
1190
+		$event->_add_relation_to($venue_id, 'Venue');
1191
+		return ! empty($venue_id);
1192
+		// when we have the ancestor come in it's already been handled by the revision save.
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1198
+	 *
1199
+	 * @param EE_Event $event The Event object we're attaching data to
1200
+	 * @param array    $data  The request data from the form
1201
+	 * @return array
1202
+	 * @throws EE_Error
1203
+	 * @throws ReflectionException
1204
+	 * @throws Exception
1205
+	 */
1206
+	protected function _default_tickets_update(EE_Event $event, $data)
1207
+	{
1208
+		if ($this->admin_config->useAdvancedEditor()) {
1209
+			return [];
1210
+		}
1211
+		$datetime       = null;
1212
+		$saved_tickets  = [];
1213
+		$event_timezone = $event->get_timezone();
1214
+		$date_formats   = ['Y-m-d', 'h:i a'];
1215
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1216
+			// trim all values to ensure any excess whitespace is removed.
1217
+			$datetime_data                = array_map('trim', $datetime_data);
1218
+			$datetime_data['DTT_EVT_end'] =
1219
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1220
+					? $datetime_data['DTT_EVT_end']
1221
+					: $datetime_data['DTT_EVT_start'];
1222
+			$datetime_values              = [
1223
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1224
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1225
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1226
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1227
+				'DTT_order'     => $row,
1228
+			];
1229
+			// if we have an id then let's get existing object first and then set the new values.
1230
+			//  Otherwise we instantiate a new object for save.
1231
+			if (! empty($datetime_data['DTT_ID'])) {
1232
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1233
+				if (! $datetime instanceof EE_Datetime) {
1234
+					throw new RuntimeException(
1235
+						sprintf(
1236
+							esc_html__(
1237
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1238
+								'event_espresso'
1239
+							),
1240
+							$datetime_data['DTT_ID']
1241
+						)
1242
+					);
1243
+				}
1244
+				$datetime->set_date_format($date_formats[0]);
1245
+				$datetime->set_time_format($date_formats[1]);
1246
+				foreach ($datetime_values as $field => $value) {
1247
+					$datetime->set($field, $value);
1248
+				}
1249
+			} else {
1250
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1251
+			}
1252
+			if (! $datetime instanceof EE_Datetime) {
1253
+				throw new RuntimeException(
1254
+					sprintf(
1255
+						esc_html__(
1256
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1257
+							'event_espresso'
1258
+						),
1259
+						print_r($datetime_values, true)
1260
+					)
1261
+				);
1262
+			}
1263
+			// before going any further make sure our dates are setup correctly
1264
+			// so that the end date is always equal or greater than the start date.
1265
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1266
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1267
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1268
+			}
1269
+			$datetime->save();
1270
+			$event->_add_relation_to($datetime, 'Datetime');
1271
+		}
1272
+		// no datetimes get deleted so we don't do any of that logic here.
1273
+		// update tickets next
1274
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1275
+
1276
+		// set up some default start and end dates in case those are not present in the incoming data
1277
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1278
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1279
+		// use the start date of the first datetime for the end date
1280
+		$first_datetime   = $event->first_datetime();
1281
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1282
+
1283
+		// now process the incoming data
1284
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1285
+			$update_prices = false;
1286
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1287
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1288
+				: 0;
1289
+			// trim inputs to ensure any excess whitespace is removed.
1290
+			$ticket_data   = array_map('trim', $ticket_data);
1291
+			$ticket_values = [
1292
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1293
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1294
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1295
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1296
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1297
+					? $ticket_data['TKT_start_date']
1298
+					: $default_start_date,
1299
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1300
+					? $ticket_data['TKT_end_date']
1301
+					: $default_end_date,
1302
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1303
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1304
+					? $ticket_data['TKT_qty']
1305
+					: EE_INF,
1306
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1307
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1308
+					? $ticket_data['TKT_uses']
1309
+					: EE_INF,
1310
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1311
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1312
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1313
+				'TKT_price'       => $ticket_price,
1314
+				'TKT_row'         => $row,
1315
+			];
1316
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1317
+			// which means in turn that the prices will become new prices as well.
1318
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1319
+				$ticket_values['TKT_ID']         = 0;
1320
+				$ticket_values['TKT_is_default'] = 0;
1321
+				$update_prices                   = true;
1322
+			}
1323
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1324
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1325
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1326
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1327
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1328
+			if (! empty($ticket_data['TKT_ID'])) {
1329
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1330
+				if (! $existing_ticket instanceof EE_Ticket) {
1331
+					throw new RuntimeException(
1332
+						sprintf(
1333
+							esc_html__(
1334
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1335
+								'event_espresso'
1336
+							),
1337
+							$ticket_data['TKT_ID']
1338
+						)
1339
+					);
1340
+				}
1341
+				$ticket_sold = $existing_ticket->count_related(
1342
+					'Registration',
1343
+					[
1344
+							[
1345
+								'STS_ID' => [
1346
+									'NOT IN',
1347
+									[EEM_Registration::status_id_incomplete],
1348
+								],
1349
+							],
1350
+						]
1351
+				) > 0;
1352
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1353
+				// if they are different then we create a new ticket (if $ticket_sold)
1354
+				// if they aren't different then we go ahead and modify existing ticket.
1355
+				$create_new_ticket = $ticket_sold
1356
+									 && $ticket_price !== $existing_ticket->price()
1357
+									 && ! $existing_ticket->deleted();
1358
+				$existing_ticket->set_date_format($date_formats[0]);
1359
+				$existing_ticket->set_time_format($date_formats[1]);
1360
+				// set new values
1361
+				foreach ($ticket_values as $field => $value) {
1362
+					if ($field == 'TKT_qty') {
1363
+						$existing_ticket->set_qty($value);
1364
+					} elseif ($field == 'TKT_price') {
1365
+						$existing_ticket->set('TKT_price', $ticket_price);
1366
+					} else {
1367
+						$existing_ticket->set($field, $value);
1368
+					}
1369
+				}
1370
+				$ticket = $existing_ticket;
1371
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1372
+				//  Otherwise we have to create a new ticket.
1373
+				if ($create_new_ticket) {
1374
+					// archive the old ticket first
1375
+					$existing_ticket->set('TKT_deleted', 1);
1376
+					$existing_ticket->save();
1377
+					// make sure this ticket is still recorded in our $saved_tickets
1378
+					// so we don't run it through the regular trash routine.
1379
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1380
+					// create new ticket that's a copy of the existing except,
1381
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1382
+					$new_ticket = clone $existing_ticket;
1383
+					$new_ticket->set('TKT_ID', 0);
1384
+					$new_ticket->set('TKT_deleted', 0);
1385
+					$new_ticket->set('TKT_sold', 0);
1386
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1387
+					$update_prices = true;
1388
+					$ticket        = $new_ticket;
1389
+				}
1390
+			} else {
1391
+				// no TKT_id so a new ticket
1392
+				$ticket_values['TKT_price'] = $ticket_price;
1393
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1394
+				$update_prices              = true;
1395
+			}
1396
+			if (! $ticket instanceof EE_Ticket) {
1397
+				throw new RuntimeException(
1398
+					sprintf(
1399
+						esc_html__(
1400
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1401
+							'event_espresso'
1402
+						),
1403
+						print_r($ticket_values, true)
1404
+					)
1405
+				);
1406
+			}
1407
+			// cap ticket qty by datetime reg limits
1408
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1409
+			// update ticket.
1410
+			$ticket->save();
1411
+			// before going any further make sure our dates are setup correctly
1412
+			// so that the end date is always equal or greater than the start date.
1413
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1414
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1415
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1416
+				$ticket->save();
1417
+			}
1418
+			// initially let's add the ticket to the datetime
1419
+			$datetime->_add_relation_to($ticket, 'Ticket');
1420
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1421
+			// add prices to ticket
1422
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1423
+		}
1424
+		// however now we need to handle permanently deleting tickets via the ui.
1425
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1426
+		//  However, it does allow for deleting tickets that have no tickets sold,
1427
+		// in which case we want to get rid of permanently because there is no need to save in db.
1428
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1429
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1430
+		foreach ($tickets_removed as $id) {
1431
+			$id = absint($id);
1432
+			// get the ticket for this id
1433
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1434
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1435
+				continue;
1436
+			}
1437
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1438
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1439
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1440
+			foreach ($related_datetimes as $related_datetime) {
1441
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1442
+			}
1443
+			// need to do the same for prices (except these prices can also be deleted because again,
1444
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1445
+			$ticket_to_remove->delete_related_permanently('Price');
1446
+			// finally let's delete this ticket
1447
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1448
+			$ticket_to_remove->delete_permanently();
1449
+		}
1450
+		return [$datetime, $saved_tickets];
1451
+	}
1452
+
1453
+
1454
+	/**
1455
+	 * This attaches a list of given prices to a ticket.
1456
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1457
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1458
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1459
+	 *
1460
+	 * @access  private
1461
+	 * @param array     $prices_data Array of prices from the form.
1462
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1463
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1464
+	 * @return  void
1465
+	 * @throws EE_Error
1466
+	 * @throws ReflectionException
1467
+	 */
1468
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1469
+	{
1470
+		$timezone = $ticket->get_timezone();
1471
+		foreach ($prices_data as $row => $price_data) {
1472
+			$price_values = [
1473
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1474
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1475
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1476
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1477
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1478
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1479
+				'PRC_order'      => $row,
1480
+			];
1481
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1482
+				$price_values['PRC_ID'] = 0;
1483
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1484
+			} else {
1485
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1486
+				// update this price with new values
1487
+				foreach ($price_values as $field => $new_price) {
1488
+					$price->set($field, $new_price);
1489
+				}
1490
+			}
1491
+			if (! $price instanceof EE_Price) {
1492
+				throw new RuntimeException(
1493
+					sprintf(
1494
+						esc_html__(
1495
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1496
+							'event_espresso'
1497
+						),
1498
+						print_r($price_values, true)
1499
+					)
1500
+				);
1501
+			}
1502
+			$price->save();
1503
+			$ticket->_add_relation_to($price, 'Price');
1504
+		}
1505
+	}
1506
+
1507
+
1508
+	/**
1509
+	 * Add in our autosave ajax handlers
1510
+	 *
1511
+	 */
1512
+	protected function _ee_autosave_create_new()
1513
+	{
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * More autosave handlers.
1519
+	 */
1520
+	protected function _ee_autosave_edit()
1521
+	{
1522
+	}
1523
+
1524
+
1525
+	/**
1526
+	 * @throws EE_Error
1527
+	 * @throws ReflectionException
1528
+	 */
1529
+	private function _generate_publish_box_extra_content()
1530
+	{
1531
+		// load formatter helper
1532
+		// args for getting related registrations
1533
+		$approved_query_args        = [
1534
+			[
1535
+				'REG_deleted' => 0,
1536
+				'STS_ID'      => EEM_Registration::status_id_approved,
1537
+			],
1538
+		];
1539
+		$not_approved_query_args    = [
1540
+			[
1541
+				'REG_deleted' => 0,
1542
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1543
+			],
1544
+		];
1545
+		$pending_payment_query_args = [
1546
+			[
1547
+				'REG_deleted' => 0,
1548
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1549
+			],
1550
+		];
1551
+		// publish box
1552
+		$publish_box_extra_args = [
1553
+			'view_approved_reg_url'        => add_query_arg(
1554
+				[
1555
+					'action'      => 'default',
1556
+					'event_id'    => $this->_cpt_model_obj->ID(),
1557
+					'_reg_status' => EEM_Registration::status_id_approved,
1558
+				],
1559
+				REG_ADMIN_URL
1560
+			),
1561
+			'view_not_approved_reg_url'    => add_query_arg(
1562
+				[
1563
+					'action'      => 'default',
1564
+					'event_id'    => $this->_cpt_model_obj->ID(),
1565
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1566
+				],
1567
+				REG_ADMIN_URL
1568
+			),
1569
+			'view_pending_payment_reg_url' => add_query_arg(
1570
+				[
1571
+					'action'      => 'default',
1572
+					'event_id'    => $this->_cpt_model_obj->ID(),
1573
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1574
+				],
1575
+				REG_ADMIN_URL
1576
+			),
1577
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1578
+				'Registration',
1579
+				$approved_query_args
1580
+			),
1581
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1582
+				'Registration',
1583
+				$not_approved_query_args
1584
+			),
1585
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1586
+				'Registration',
1587
+				$pending_payment_query_args
1588
+			),
1589
+			'misc_pub_section_class'       => apply_filters(
1590
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1591
+				'misc-pub-section'
1592
+			),
1593
+		];
1594
+		ob_start();
1595
+		do_action(
1596
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1597
+			$this->_cpt_model_obj
1598
+		);
1599
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1600
+		// load template
1601
+		EEH_Template::display_template(
1602
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1603
+			$publish_box_extra_args
1604
+		);
1605
+	}
1606
+
1607
+
1608
+	/**
1609
+	 * @return EE_Event
1610
+	 */
1611
+	public function get_event_object()
1612
+	{
1613
+		return $this->_cpt_model_obj;
1614
+	}
1615
+
1616
+
1617
+
1618
+
1619
+	/** METABOXES * */
1620
+	/**
1621
+	 * _register_event_editor_meta_boxes
1622
+	 * add all metaboxes related to the event_editor
1623
+	 *
1624
+	 * @return void
1625
+	 * @throws EE_Error
1626
+	 * @throws ReflectionException
1627
+	 */
1628
+	protected function _register_event_editor_meta_boxes()
1629
+	{
1630
+		$this->verify_cpt_object();
1631
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1632
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1633
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1634
+			add_meta_box(
1635
+				'espresso_event_editor_event_options',
1636
+				esc_html__('Event Registration Options', 'event_espresso'),
1637
+				[$this, 'registration_options_meta_box'],
1638
+				$this->page_slug,
1639
+				'side'
1640
+			);
1641
+		}
1642
+		if (! $use_advanced_editor) {
1643
+			add_meta_box(
1644
+				'espresso_event_editor_tickets',
1645
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1646
+				[$this, 'ticket_metabox'],
1647
+				$this->page_slug,
1648
+				'normal',
1649
+				'high'
1650
+			);
1651
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1652
+			add_action(
1653
+				'add_meta_boxes_espresso_events',
1654
+				function () {
1655
+					global $current_screen;
1656
+					remove_meta_box('authordiv', $current_screen, 'normal');
1657
+				},
1658
+				99
1659
+			);
1660
+		}
1661
+		// NOTE: if you're looking for other metaboxes in here,
1662
+		// where a metabox has a related management page in the admin
1663
+		// you will find it setup in the related management page's "_Hooks" file.
1664
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1665
+	}
1666
+
1667
+
1668
+	/**
1669
+	 * @throws DomainException
1670
+	 * @throws EE_Error
1671
+	 * @throws ReflectionException
1672
+	 */
1673
+	public function ticket_metabox()
1674
+	{
1675
+		$existing_datetime_ids = $existing_ticket_ids = [];
1676
+		// defaults for template args
1677
+		$template_args = [
1678
+			'existing_datetime_ids'    => '',
1679
+			'event_datetime_help_link' => '',
1680
+			'ticket_options_help_link' => '',
1681
+			'time'                     => null,
1682
+			'ticket_rows'              => '',
1683
+			'existing_ticket_ids'      => '',
1684
+			'total_ticket_rows'        => 1,
1685
+			'ticket_js_structure'      => '',
1686
+			'trash_icon'               => 'ee-lock-icon',
1687
+			'disabled'                 => '',
1688
+		];
1689
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1690
+		/**
1691
+		 * 1. Start with retrieving Datetimes
1692
+		 * 2. Fore each datetime get related tickets
1693
+		 * 3. For each ticket get related prices
1694
+		 */
1695
+		/** @var EEM_Datetime $datetime_model */
1696
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1697
+		/** @var EEM_Ticket $datetime_model */
1698
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1699
+		$times        = $datetime_model->get_all_event_dates($event_id);
1700
+		/** @type EE_Datetime $first_datetime */
1701
+		$first_datetime = reset($times);
1702
+		// do we get related tickets?
1703
+		if (
1704
+			$first_datetime instanceof EE_Datetime
1705
+			&& $first_datetime->ID() !== 0
1706
+		) {
1707
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1708
+			$template_args['time']   = $first_datetime;
1709
+			$related_tickets         = $first_datetime->tickets(
1710
+				[
1711
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1712
+					'default_where_conditions' => 'none',
1713
+				]
1714
+			);
1715
+			if (! empty($related_tickets)) {
1716
+				$template_args['total_ticket_rows'] = count($related_tickets);
1717
+				$row                                = 0;
1718
+				foreach ($related_tickets as $ticket) {
1719
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1720
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1721
+					$row++;
1722
+				}
1723
+			} else {
1724
+				$template_args['total_ticket_rows'] = 1;
1725
+				/** @type EE_Ticket $ticket */
1726
+				$ticket                       = $ticket_model->create_default_object();
1727
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1728
+			}
1729
+		} else {
1730
+			$template_args['time'] = $times[0];
1731
+			/** @type EE_Ticket[] $tickets */
1732
+			$tickets                      = $ticket_model->get_all_default_tickets();
1733
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1734
+			// NOTE: we're just sending the first default row
1735
+			// (decaf can't manage default tickets so this should be sufficient);
1736
+		}
1737
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1738
+			'event_editor_event_datetimes_help_tab'
1739
+		);
1740
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1741
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1742
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1743
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1744
+			$ticket_model->create_default_object(),
1745
+			true
1746
+		);
1747
+		$template                                  = apply_filters(
1748
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1749
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1750
+		);
1751
+		EEH_Template::display_template($template, $template_args);
1752
+	}
1753
+
1754
+
1755
+	/**
1756
+	 * Setup an individual ticket form for the decaf event editor page
1757
+	 *
1758
+	 * @access private
1759
+	 * @param EE_Ticket $ticket   the ticket object
1760
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1761
+	 * @param int       $row
1762
+	 * @return string generated html for the ticket row.
1763
+	 * @throws EE_Error
1764
+	 * @throws ReflectionException
1765
+	 */
1766
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1767
+	{
1768
+		$template_args = [
1769
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1770
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1771
+				: '',
1772
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1773
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1774
+			'TKT_name'            => $ticket->get('TKT_name'),
1775
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1776
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1777
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1778
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1779
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1780
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1781
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1782
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1783
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1784
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1785
+				: ' disabled=disabled',
1786
+		];
1787
+		$price         = $ticket->ID() !== 0
1788
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1789
+			: null;
1790
+		$price         = $price instanceof EE_Price
1791
+			? $price
1792
+			: EEM_Price::instance()->create_default_object();
1793
+		$price_args    = [
1794
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1795
+			'PRC_amount'            => $price->get('PRC_amount'),
1796
+			'PRT_ID'                => $price->get('PRT_ID'),
1797
+			'PRC_ID'                => $price->get('PRC_ID'),
1798
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1799
+		];
1800
+		// make sure we have default start and end dates if skeleton
1801
+		// handle rows that should NOT be empty
1802
+		if (empty($template_args['TKT_start_date'])) {
1803
+			// if empty then the start date will be now.
1804
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1805
+		}
1806
+		if (empty($template_args['TKT_end_date'])) {
1807
+			// get the earliest datetime (if present);
1808
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1809
+				? $this->_cpt_model_obj->get_first_related(
1810
+					'Datetime',
1811
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1812
+				)
1813
+				: null;
1814
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1815
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1816
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1817
+		}
1818
+		$template_args = array_merge($template_args, $price_args);
1819
+		$template      = apply_filters(
1820
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1821
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1822
+			$ticket
1823
+		);
1824
+		return EEH_Template::display_template($template, $template_args, true);
1825
+	}
1826
+
1827
+
1828
+	/**
1829
+	 * @throws EE_Error
1830
+	 * @throws ReflectionException
1831
+	 */
1832
+	public function registration_options_meta_box()
1833
+	{
1834
+		$yes_no_values             = [
1835
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1836
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1837
+		];
1838
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1839
+			[
1840
+				EEM_Registration::status_id_cancelled,
1841
+				EEM_Registration::status_id_declined,
1842
+				EEM_Registration::status_id_incomplete,
1843
+			],
1844
+			true
1845
+		);
1846
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1847
+		$template_args['_event']                          = $this->_cpt_model_obj;
1848
+		$template_args['event']                           = $this->_cpt_model_obj;
1849
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1850
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1851
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1852
+			'default_reg_status',
1853
+			$default_reg_status_values,
1854
+			$this->_cpt_model_obj->default_registration_status()
1855
+		);
1856
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1857
+			'display_desc',
1858
+			$yes_no_values,
1859
+			$this->_cpt_model_obj->display_description()
1860
+		);
1861
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1862
+			'display_ticket_selector',
1863
+			$yes_no_values,
1864
+			$this->_cpt_model_obj->display_ticket_selector(),
1865
+			'',
1866
+			'',
1867
+			false
1868
+		);
1869
+		$template_args['additional_registration_options'] = apply_filters(
1870
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1871
+			'',
1872
+			$template_args,
1873
+			$yes_no_values,
1874
+			$default_reg_status_values
1875
+		);
1876
+		EEH_Template::display_template(
1877
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1878
+			$template_args
1879
+		);
1880
+	}
1881
+
1882
+
1883
+	/**
1884
+	 * _get_events()
1885
+	 * This method simply returns all the events (for the given _view and paging)
1886
+	 *
1887
+	 * @access public
1888
+	 * @param int  $per_page     count of items per page (20 default);
1889
+	 * @param int  $current_page what is the current page being viewed.
1890
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1891
+	 *                           If FALSE then we return an array of event objects
1892
+	 *                           that match the given _view and paging parameters.
1893
+	 * @return array|int         an array of event objects or a count of them.
1894
+	 * @throws Exception
1895
+	 */
1896
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1897
+	{
1898
+		$EEM_Event   = $this->_event_model();
1899
+		$offset      = ($current_page - 1) * $per_page;
1900
+		$limit       = $count ? null : $offset . ',' . $per_page;
1901
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1902
+		$order       = $this->request->getRequestParam('order', 'DESC');
1903
+		$month_range = $this->request->getRequestParam('month_range');
1904
+		if ($month_range) {
1905
+			$pieces = explode(' ', $month_range, 3);
1906
+			// simulate the FIRST day of the month, that fixes issues for months like February
1907
+			// where PHP doesn't know what to assume for date.
1908
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1909
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1910
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1911
+		}
1912
+		$where  = [];
1913
+		$status = $this->request->getRequestParam('status');
1914
+		// determine what post_status our condition will have for the query.
1915
+		switch ($status) {
1916
+			case 'month':
1917
+			case 'today':
1918
+			case null:
1919
+			case 'all':
1920
+				break;
1921
+			case 'draft':
1922
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1923
+				break;
1924
+			default:
1925
+				$where['status'] = $status;
1926
+		}
1927
+		// categories? The default for all categories is -1
1928
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1929
+		if ($category !== -1) {
1930
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1931
+			$where['Term_Taxonomy.term_id']  = $category;
1932
+		}
1933
+		// date where conditions
1934
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1935
+		if ($month_range) {
1936
+			$DateTime = new DateTime(
1937
+				$year_r . '-' . $month_r . '-01 00:00:00',
1938
+				new DateTimeZone('UTC')
1939
+			);
1940
+			$start    = $DateTime->getTimestamp();
1941
+			// set the datetime to be the end of the month
1942
+			$DateTime->setDate(
1943
+				$year_r,
1944
+				$month_r,
1945
+				$DateTime->format('t')
1946
+			)->setTime(23, 59, 59);
1947
+			$end                             = $DateTime->getTimestamp();
1948
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1949
+		} elseif ($status === 'today') {
1950
+			$DateTime                        =
1951
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1952
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1953
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1954
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1955
+		} elseif ($status === 'month') {
1956
+			$now                             = date('Y-m-01');
1957
+			$DateTime                        =
1958
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1959
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1960
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1961
+														->setTime(23, 59, 59)
1962
+														->format(implode(' ', $start_formats));
1963
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1964
+		}
1965
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1966
+			$where['EVT_wp_user'] = get_current_user_id();
1967
+		} else {
1968
+			if (! isset($where['status'])) {
1969
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1970
+					$where['OR'] = [
1971
+						'status*restrict_private' => ['!=', 'private'],
1972
+						'AND'                     => [
1973
+							'status*inclusive' => ['=', 'private'],
1974
+							'EVT_wp_user'      => get_current_user_id(),
1975
+						],
1976
+					];
1977
+				}
1978
+			}
1979
+		}
1980
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1981
+		if (
1982
+			$wp_user
1983
+			&& $wp_user !== get_current_user_id()
1984
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1985
+		) {
1986
+			$where['EVT_wp_user'] = $wp_user;
1987
+		}
1988
+		// search query handling
1989
+		$search_term = $this->request->getRequestParam('s');
1990
+		if ($search_term) {
1991
+			$search_term = '%' . $search_term . '%';
1992
+			$where['OR'] = [
1993
+				'EVT_name'       => ['LIKE', $search_term],
1994
+				'EVT_desc'       => ['LIKE', $search_term],
1995
+				'EVT_short_desc' => ['LIKE', $search_term],
1996
+			];
1997
+		}
1998
+		// filter events by venue.
1999
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
2000
+		if ($venue) {
2001
+			$where['Venue.VNU_ID'] = $venue;
2002
+		}
2003
+		$request_params = $this->request->requestParams();
2004
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2005
+		$query_params   = apply_filters(
2006
+			'FHEE__Events_Admin_Page__get_events__query_params',
2007
+			[
2008
+				$where,
2009
+				'limit'    => $limit,
2010
+				'order_by' => $orderby,
2011
+				'order'    => $order,
2012
+				'group_by' => 'EVT_ID',
2013
+			],
2014
+			$request_params
2015
+		);
2016
+
2017
+		// let's first check if we have special requests coming in.
2018
+		$active_status = $this->request->getRequestParam('active_status');
2019
+		if ($active_status) {
2020
+			switch ($active_status) {
2021
+				case 'upcoming':
2022
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2023
+				case 'expired':
2024
+					return $EEM_Event->get_expired_events($query_params, $count);
2025
+				case 'active':
2026
+					return $EEM_Event->get_active_events($query_params, $count);
2027
+				case 'inactive':
2028
+					return $EEM_Event->get_inactive_events($query_params, $count);
2029
+			}
2030
+		}
2031
+
2032
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2033
+	}
2034
+
2035
+
2036
+	/**
2037
+	 * handling for WordPress CPT actions (trash, restore, delete)
2038
+	 *
2039
+	 * @param string $post_id
2040
+	 * @throws EE_Error
2041
+	 * @throws ReflectionException
2042
+	 */
2043
+	public function trash_cpt_item($post_id)
2044
+	{
2045
+		$this->request->setRequestParam('EVT_ID', $post_id);
2046
+		$this->_trash_or_restore_event('trash', false);
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 * @param string $post_id
2052
+	 * @throws EE_Error
2053
+	 * @throws ReflectionException
2054
+	 */
2055
+	public function restore_cpt_item($post_id)
2056
+	{
2057
+		$this->request->setRequestParam('EVT_ID', $post_id);
2058
+		$this->_trash_or_restore_event('draft', false);
2059
+	}
2060
+
2061
+
2062
+	/**
2063
+	 * @param string $post_id
2064
+	 * @throws EE_Error
2065
+	 * @throws EE_Error
2066
+	 */
2067
+	public function delete_cpt_item($post_id)
2068
+	{
2069
+		throw new EE_Error(
2070
+			esc_html__(
2071
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2072
+				'event_espresso'
2073
+			)
2074
+		);
2075
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2076
+		// $this->_delete_event();
2077
+	}
2078
+
2079
+
2080
+	/**
2081
+	 * _trash_or_restore_event
2082
+	 *
2083
+	 * @access protected
2084
+	 * @param string $event_status
2085
+	 * @param bool   $redirect_after
2086
+	 * @throws EE_Error
2087
+	 * @throws EE_Error
2088
+	 * @throws ReflectionException
2089
+	 */
2090
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2091
+	{
2092
+		// determine the event id and set to array.
2093
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2094
+		// loop thru events
2095
+		if ($EVT_ID) {
2096
+			// clean status
2097
+			$event_status = sanitize_key($event_status);
2098
+			// grab status
2099
+			if (! empty($event_status)) {
2100
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2101
+			} else {
2102
+				$success = false;
2103
+				$msg     = esc_html__(
2104
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2105
+					'event_espresso'
2106
+				);
2107
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2108
+			}
2109
+		} else {
2110
+			$success = false;
2111
+			$msg     = esc_html__(
2112
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2113
+				'event_espresso'
2114
+			);
2115
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2116
+		}
2117
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2118
+		if ($redirect_after) {
2119
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2120
+		}
2121
+	}
2122
+
2123
+
2124
+	/**
2125
+	 * _trash_or_restore_events
2126
+	 *
2127
+	 * @access protected
2128
+	 * @param string $event_status
2129
+	 * @return void
2130
+	 * @throws EE_Error
2131
+	 * @throws EE_Error
2132
+	 * @throws ReflectionException
2133
+	 */
2134
+	protected function _trash_or_restore_events($event_status = 'trash')
2135
+	{
2136
+		// clean status
2137
+		$event_status = sanitize_key($event_status);
2138
+		// grab status
2139
+		if (! empty($event_status)) {
2140
+			$success = true;
2141
+			// determine the event id and set to array.
2142
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2143
+			// loop thru events
2144
+			foreach ($EVT_IDs as $EVT_ID) {
2145
+				if ($EVT_ID = absint($EVT_ID)) {
2146
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2147
+					$success = $results !== false ? $success : false;
2148
+				} else {
2149
+					$msg = sprintf(
2150
+						esc_html__(
2151
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2152
+							'event_espresso'
2153
+						),
2154
+						$EVT_ID
2155
+					);
2156
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2157
+					$success = false;
2158
+				}
2159
+			}
2160
+		} else {
2161
+			$success = false;
2162
+			$msg     = esc_html__(
2163
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2164
+				'event_espresso'
2165
+			);
2166
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2167
+		}
2168
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2169
+		$success = $success ? 2 : false;
2170
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2171
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2172
+	}
2173
+
2174
+
2175
+	/**
2176
+	 * @param int    $EVT_ID
2177
+	 * @param string $event_status
2178
+	 * @return bool
2179
+	 * @throws EE_Error
2180
+	 * @throws ReflectionException
2181
+	 */
2182
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2183
+	{
2184
+		// grab event id
2185
+		if (! $EVT_ID) {
2186
+			$msg = esc_html__(
2187
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2188
+				'event_espresso'
2189
+			);
2190
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2191
+			return false;
2192
+		}
2193
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2194
+		// clean status
2195
+		$event_status = sanitize_key($event_status);
2196
+		// grab status
2197
+		if (empty($event_status)) {
2198
+			$msg = esc_html__(
2199
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2200
+				'event_espresso'
2201
+			);
2202
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2203
+			return false;
2204
+		}
2205
+		// was event trashed or restored ?
2206
+		switch ($event_status) {
2207
+			case 'draft':
2208
+				$action = 'restored from the trash';
2209
+				$hook   = 'AHEE_event_restored_from_trash';
2210
+				break;
2211
+			case 'trash':
2212
+				$action = 'moved to the trash';
2213
+				$hook   = 'AHEE_event_moved_to_trash';
2214
+				break;
2215
+			default:
2216
+				$action = 'updated';
2217
+				$hook   = false;
2218
+		}
2219
+		// use class to change status
2220
+		$this->_cpt_model_obj->set_status($event_status);
2221
+		$success = $this->_cpt_model_obj->save();
2222
+		if (! $success) {
2223
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2224
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2225
+			return false;
2226
+		}
2227
+		if ($hook) {
2228
+			do_action($hook);
2229
+		}
2230
+		return true;
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 * @param array $event_ids
2236
+	 * @return array
2237
+	 * @since   4.10.23.p
2238
+	 */
2239
+	private function cleanEventIds(array $event_ids)
2240
+	{
2241
+		return array_map('absint', $event_ids);
2242
+	}
2243
+
2244
+
2245
+	/**
2246
+	 * @return array
2247
+	 * @since   4.10.23.p
2248
+	 */
2249
+	private function getEventIdsFromRequest()
2250
+	{
2251
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2252
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2253
+		} else {
2254
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2255
+		}
2256
+	}
2257
+
2258
+
2259
+	/**
2260
+	 * @param bool $preview_delete
2261
+	 * @throws EE_Error
2262
+	 */
2263
+	protected function _delete_event($preview_delete = true)
2264
+	{
2265
+		$this->_delete_events($preview_delete);
2266
+	}
2267
+
2268
+
2269
+	/**
2270
+	 * Gets the tree traversal batch persister.
2271
+	 *
2272
+	 * @return NodeGroupDao
2273
+	 * @throws InvalidArgumentException
2274
+	 * @throws InvalidDataTypeException
2275
+	 * @throws InvalidInterfaceException
2276
+	 * @since 4.10.12.p
2277
+	 */
2278
+	protected function getModelObjNodeGroupPersister()
2279
+	{
2280
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2281
+			$this->model_obj_node_group_persister =
2282
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2283
+		}
2284
+		return $this->model_obj_node_group_persister;
2285
+	}
2286
+
2287
+
2288
+	/**
2289
+	 * @param bool $preview_delete
2290
+	 * @return void
2291
+	 * @throws EE_Error
2292
+	 */
2293
+	protected function _delete_events($preview_delete = true)
2294
+	{
2295
+		$event_ids = $this->getEventIdsFromRequest();
2296
+		if ($preview_delete) {
2297
+			$this->generateDeletionPreview($event_ids);
2298
+		} else {
2299
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2300
+		}
2301
+	}
2302
+
2303
+
2304
+	/**
2305
+	 * @param array $event_ids
2306
+	 */
2307
+	protected function generateDeletionPreview(array $event_ids)
2308
+	{
2309
+		$event_ids = $this->cleanEventIds($event_ids);
2310
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2311
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2312
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2313
+			[
2314
+				'action'            => 'preview_deletion',
2315
+				'deletion_job_code' => $deletion_job_code,
2316
+			],
2317
+			$this->_admin_base_url
2318
+		);
2319
+		EEH_URL::safeRedirectAndExit(
2320
+			EE_Admin_Page::add_query_args_and_nonce(
2321
+				[
2322
+					'page'              => 'espresso_batch',
2323
+					'batch'             => EED_Batch::batch_job,
2324
+					'EVT_IDs'           => $event_ids,
2325
+					'deletion_job_code' => $deletion_job_code,
2326
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2327
+					'return_url'        => urlencode($return_url),
2328
+				],
2329
+				admin_url()
2330
+			)
2331
+		);
2332
+	}
2333
+
2334
+
2335
+	/**
2336
+	 * Checks for a POST submission
2337
+	 *
2338
+	 * @since 4.10.12.p
2339
+	 */
2340
+	protected function confirmDeletion()
2341
+	{
2342
+		$deletion_redirect_logic =
2343
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2344
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2345
+	}
2346
+
2347
+
2348
+	/**
2349
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2350
+	 *
2351
+	 * @throws EE_Error
2352
+	 * @since 4.10.12.p
2353
+	 */
2354
+	protected function previewDeletion()
2355
+	{
2356
+		$preview_deletion_logic =
2357
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2358
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2359
+		$this->display_admin_page_with_no_sidebar();
2360
+	}
2361
+
2362
+
2363
+	/**
2364
+	 * get total number of events
2365
+	 *
2366
+	 * @access public
2367
+	 * @return int
2368
+	 * @throws EE_Error
2369
+	 * @throws EE_Error
2370
+	 */
2371
+	public function total_events()
2372
+	{
2373
+		return EEM_Event::instance()->count(
2374
+			['caps' => 'read_admin'],
2375
+			'EVT_ID',
2376
+			true
2377
+		);
2378
+	}
2379
+
2380
+
2381
+	/**
2382
+	 * get total number of draft events
2383
+	 *
2384
+	 * @access public
2385
+	 * @return int
2386
+	 * @throws EE_Error
2387
+	 * @throws EE_Error
2388
+	 */
2389
+	public function total_events_draft()
2390
+	{
2391
+		return EEM_Event::instance()->count(
2392
+			[
2393
+				['status' => ['IN', ['draft', 'auto-draft']]],
2394
+				'caps' => 'read_admin',
2395
+			],
2396
+			'EVT_ID',
2397
+			true
2398
+		);
2399
+	}
2400
+
2401
+
2402
+	/**
2403
+	 * get total number of trashed events
2404
+	 *
2405
+	 * @access public
2406
+	 * @return int
2407
+	 * @throws EE_Error
2408
+	 * @throws EE_Error
2409
+	 */
2410
+	public function total_trashed_events()
2411
+	{
2412
+		return EEM_Event::instance()->count(
2413
+			[
2414
+				['status' => 'trash'],
2415
+				'caps' => 'read_admin',
2416
+			],
2417
+			'EVT_ID',
2418
+			true
2419
+		);
2420
+	}
2421
+
2422
+
2423
+	/**
2424
+	 *    _default_event_settings
2425
+	 *    This generates the Default Settings Tab
2426
+	 *
2427
+	 * @return void
2428
+	 * @throws DomainException
2429
+	 * @throws EE_Error
2430
+	 * @throws InvalidArgumentException
2431
+	 * @throws InvalidDataTypeException
2432
+	 * @throws InvalidInterfaceException
2433
+	 */
2434
+	protected function _default_event_settings()
2435
+	{
2436
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2437
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2438
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2439
+		$this->display_admin_page_with_sidebar();
2440
+	}
2441
+
2442
+
2443
+	/**
2444
+	 * Return the form for event settings.
2445
+	 *
2446
+	 * @return EE_Form_Section_Proper
2447
+	 * @throws EE_Error
2448
+	 */
2449
+	protected function _default_event_settings_form()
2450
+	{
2451
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2452
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2453
+		// exclude
2454
+			[
2455
+				EEM_Registration::status_id_cancelled,
2456
+				EEM_Registration::status_id_declined,
2457
+				EEM_Registration::status_id_incomplete,
2458
+				EEM_Registration::status_id_wait_list,
2459
+			],
2460
+			true
2461
+		);
2462
+		return new EE_Form_Section_Proper(
2463
+			[
2464
+				'name'            => 'update_default_event_settings',
2465
+				'html_id'         => 'update_default_event_settings',
2466
+				'html_class'      => 'form-table',
2467
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2468
+				'subsections'     => apply_filters(
2469
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2470
+					[
2471
+						'default_reg_status'  => new EE_Select_Input(
2472
+							$registration_stati_for_selection,
2473
+							[
2474
+								'default'         => isset($registration_config->default_STS_ID)
2475
+													 && array_key_exists(
2476
+														 $registration_config->default_STS_ID,
2477
+														 $registration_stati_for_selection
2478
+													 )
2479
+									? sanitize_text_field($registration_config->default_STS_ID)
2480
+									: EEM_Registration::status_id_pending_payment,
2481
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2482
+													 . EEH_Template::get_help_tab_link(
2483
+														 'default_settings_status_help_tab'
2484
+													 ),
2485
+								'html_help_text'  => esc_html__(
2486
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2487
+									'event_espresso'
2488
+								),
2489
+							]
2490
+						),
2491
+						'default_max_tickets' => new EE_Integer_Input(
2492
+							[
2493
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2494
+									? $registration_config->default_maximum_number_of_tickets
2495
+									: EEM_Event::get_default_additional_limit(),
2496
+								'html_label_text' => esc_html__(
2497
+									'Default Maximum Tickets Allowed Per Order:',
2498
+									'event_espresso'
2499
+								)
2500
+													 . EEH_Template::get_help_tab_link(
2501
+														 'default_maximum_tickets_help_tab"'
2502
+													 ),
2503
+								'html_help_text'  => esc_html__(
2504
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2505
+									'event_espresso'
2506
+								),
2507
+							]
2508
+						),
2509
+					]
2510
+				),
2511
+			]
2512
+		);
2513
+	}
2514
+
2515
+
2516
+	/**
2517
+	 * @return void
2518
+	 * @throws EE_Error
2519
+	 * @throws InvalidArgumentException
2520
+	 * @throws InvalidDataTypeException
2521
+	 * @throws InvalidInterfaceException
2522
+	 */
2523
+	protected function _update_default_event_settings()
2524
+	{
2525
+		$form = $this->_default_event_settings_form();
2526
+		if ($form->was_submitted()) {
2527
+			$form->receive_form_submission();
2528
+			if ($form->is_valid()) {
2529
+				$registration_config = EE_Registry::instance()->CFG->registration;
2530
+				$valid_data          = $form->valid_data();
2531
+				if (isset($valid_data['default_reg_status'])) {
2532
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2533
+				}
2534
+				if (isset($valid_data['default_max_tickets'])) {
2535
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2536
+				}
2537
+				do_action(
2538
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2539
+					$valid_data,
2540
+					EE_Registry::instance()->CFG,
2541
+					$this
2542
+				);
2543
+				// update because data was valid!
2544
+				EE_Registry::instance()->CFG->update_espresso_config();
2545
+				EE_Error::overwrite_success();
2546
+				EE_Error::add_success(
2547
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2548
+				);
2549
+			}
2550
+		}
2551
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2552
+	}
2553
+
2554
+
2555
+	/*************        Templates        *************
21 2556
      *
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-
55
-    /**
56
-     * Initialize page props for this admin page group.
57
-     */
58
-    protected function _init_page_props()
59
-    {
60
-        $this->page_slug        = EVENTS_PG_SLUG;
61
-        $this->page_label       = EVENTS_LABEL;
62
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
63
-        $this->_admin_base_path = EVENTS_ADMIN;
64
-        $this->_cpt_model_names = [
65
-            'create_new' => 'EEM_Event',
66
-            'edit'       => 'EEM_Event',
67
-        ];
68
-        $this->_cpt_edit_routes = [
69
-            'espresso_events' => 'edit',
70
-        ];
71
-        add_action(
72
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
-            [$this, 'verify_event_edit'],
74
-            10,
75
-            2
76
-        );
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the ajax hooks used for this admin page group.
82
-     */
83
-    protected function _ajax_hooks()
84
-    {
85
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
-    }
87
-
88
-
89
-    /**
90
-     * Sets the page properties for this admin page group.
91
-     */
92
-    protected function _define_page_props()
93
-    {
94
-        $this->_admin_page_title = EVENTS_LABEL;
95
-        $this->_labels           = [
96
-            'buttons'      => [
97
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
98
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
-            ],
104
-            'editor_title' => [
105
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
-            ],
107
-            'publishbox'   => [
108
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
110
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
-            ],
114
-        ];
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the page routes property for this admin page group.
120
-     */
121
-    protected function _set_page_routes()
122
-    {
123
-        // load formatter helper
124
-        // load field generator helper
125
-        // is there a evt_id in the request?
126
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
-
129
-        $this->_page_routes = [
130
-            'default'                       => [
131
-                'func'       => '_events_overview_list_table',
132
-                'capability' => 'ee_read_events',
133
-            ],
134
-            'create_new'                    => [
135
-                'func'       => '_create_new_cpt_item',
136
-                'capability' => 'ee_edit_events',
137
-            ],
138
-            'edit'                          => [
139
-                'func'       => '_edit_cpt_item',
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $EVT_ID,
142
-            ],
143
-            'copy_event'                    => [
144
-                'func'       => '_copy_events',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-                'noheader'   => true,
148
-            ],
149
-            'trash_event'                   => [
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => ['event_status' => 'trash'],
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $EVT_ID,
154
-                'noheader'   => true,
155
-            ],
156
-            'trash_events'                  => [
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => ['event_status' => 'trash'],
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ],
162
-            'restore_event'                 => [
163
-                'func'       => '_trash_or_restore_event',
164
-                'args'       => ['event_status' => 'draft'],
165
-                'capability' => 'ee_delete_event',
166
-                'obj_id'     => $EVT_ID,
167
-                'noheader'   => true,
168
-            ],
169
-            'restore_events'                => [
170
-                'func'       => '_trash_or_restore_events',
171
-                'args'       => ['event_status' => 'draft'],
172
-                'capability' => 'ee_delete_events',
173
-                'noheader'   => true,
174
-            ],
175
-            'delete_event'                  => [
176
-                'func'       => '_delete_event',
177
-                'capability' => 'ee_delete_event',
178
-                'obj_id'     => $EVT_ID,
179
-                'noheader'   => true,
180
-            ],
181
-            'delete_events'                 => [
182
-                'func'       => '_delete_events',
183
-                'capability' => 'ee_delete_events',
184
-                'noheader'   => true,
185
-            ],
186
-            'view_report'                   => [
187
-                'func'       => '_view_report',
188
-                'capability' => 'ee_edit_events',
189
-            ],
190
-            'default_event_settings'        => [
191
-                'func'       => '_default_event_settings',
192
-                'capability' => 'manage_options',
193
-            ],
194
-            'update_default_event_settings' => [
195
-                'func'       => '_update_default_event_settings',
196
-                'capability' => 'manage_options',
197
-                'noheader'   => true,
198
-            ],
199
-            'template_settings'             => [
200
-                'func'       => '_template_settings',
201
-                'capability' => 'manage_options',
202
-            ],
203
-            // event category tab related
204
-            'add_category'                  => [
205
-                'func'       => '_category_details',
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => ['add'],
208
-            ],
209
-            'edit_category'                 => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['edit'],
213
-            ],
214
-            'delete_categories'             => [
215
-                'func'       => '_delete_categories',
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ],
219
-            'delete_category'               => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'insert_category'               => [
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => ['new_category' => true],
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ],
230
-            'update_category'               => [
231
-                'func'       => '_insert_or_update_category',
232
-                'args'       => ['new_category' => false],
233
-                'capability' => 'ee_edit_event_category',
234
-                'noheader'   => true,
235
-            ],
236
-            'category_list'                 => [
237
-                'func'       => '_category_list_table',
238
-                'capability' => 'ee_manage_event_categories',
239
-            ],
240
-            'preview_deletion'              => [
241
-                'func'       => 'previewDeletion',
242
-                'capability' => 'ee_delete_events',
243
-            ],
244
-            'confirm_deletion'              => [
245
-                'func'       => 'confirmDeletion',
246
-                'capability' => 'ee_delete_events',
247
-                'noheader'   => true,
248
-            ],
249
-        ];
250
-    }
251
-
252
-
253
-    /**
254
-     * Set the _page_config property for this admin page group.
255
-     */
256
-    protected function _set_page_config()
257
-    {
258
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
259
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
-        $this->_page_config = [
261
-            'default'                => [
262
-                'nav'           => [
263
-                    'label' => esc_html__('Overview', 'event_espresso'),
264
-                    'order' => 10,
265
-                ],
266
-                'list_table'    => 'Events_Admin_List_Table',
267
-                'help_tabs'     => [
268
-                    'events_overview_help_tab'                       => [
269
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
270
-                        'filename' => 'events_overview',
271
-                    ],
272
-                    'events_overview_table_column_headings_help_tab' => [
273
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
-                        'filename' => 'events_overview_table_column_headings',
275
-                    ],
276
-                    'events_overview_filters_help_tab'               => [
277
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
-                        'filename' => 'events_overview_filters',
279
-                    ],
280
-                    'events_overview_view_help_tab'                  => [
281
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
-                        'filename' => 'events_overview_views',
283
-                    ],
284
-                    'events_overview_other_help_tab'                 => [
285
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
-                        'filename' => 'events_overview_other',
287
-                    ],
288
-                ],
289
-                'qtips'         => [
290
-                    'EE_Event_List_Table_Tips',
291
-                ],
292
-                'require_nonce' => false,
293
-            ],
294
-            'create_new'             => [
295
-                'nav'           => [
296
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
297
-                    'order'      => 5,
298
-                    'persistent' => false,
299
-                ],
300
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
-                'help_tabs'     => [
302
-                    'event_editor_help_tab'                            => [
303
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
304
-                        'filename' => 'event_editor',
305
-                    ],
306
-                    'event_editor_title_richtexteditor_help_tab'       => [
307
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
-                        'filename' => 'event_editor_title_richtexteditor',
309
-                    ],
310
-                    'event_editor_venue_details_help_tab'              => [
311
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
-                        'filename' => 'event_editor_venue_details',
313
-                    ],
314
-                    'event_editor_event_datetimes_help_tab'            => [
315
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
-                        'filename' => 'event_editor_event_datetimes',
317
-                    ],
318
-                    'event_editor_event_tickets_help_tab'              => [
319
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
-                        'filename' => 'event_editor_event_tickets',
321
-                    ],
322
-                    'event_editor_event_registration_options_help_tab' => [
323
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
-                        'filename' => 'event_editor_event_registration_options',
325
-                    ],
326
-                    'event_editor_tags_categories_help_tab'            => [
327
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
-                        'filename' => 'event_editor_tags_categories',
329
-                    ],
330
-                    'event_editor_questions_registrants_help_tab'      => [
331
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
-                        'filename' => 'event_editor_questions_registrants',
333
-                    ],
334
-                    'event_editor_save_new_event_help_tab'             => [
335
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
336
-                        'filename' => 'event_editor_save_new_event',
337
-                    ],
338
-                    'event_editor_other_help_tab'                      => [
339
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
340
-                        'filename' => 'event_editor_other',
341
-                    ],
342
-                ],
343
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
-                'require_nonce' => false,
345
-            ],
346
-            'edit'                   => [
347
-                'nav'           => [
348
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
349
-                    'order'      => 5,
350
-                    'persistent' => false,
351
-                    'url'        => $post_id
352
-                        ? EE_Admin_Page::add_query_args_and_nonce(
353
-                            ['post' => $post_id, 'action' => 'edit'],
354
-                            $this->_current_page_view_url
355
-                        )
356
-                        : $this->_admin_base_url,
357
-                ],
358
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
-                'help_tabs'     => [
360
-                    'event_editor_help_tab'                            => [
361
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
362
-                        'filename' => 'event_editor',
363
-                    ],
364
-                    'event_editor_title_richtexteditor_help_tab'       => [
365
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
-                        'filename' => 'event_editor_title_richtexteditor',
367
-                    ],
368
-                    'event_editor_venue_details_help_tab'              => [
369
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
-                        'filename' => 'event_editor_venue_details',
371
-                    ],
372
-                    'event_editor_event_datetimes_help_tab'            => [
373
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
-                        'filename' => 'event_editor_event_datetimes',
375
-                    ],
376
-                    'event_editor_event_tickets_help_tab'              => [
377
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
-                        'filename' => 'event_editor_event_tickets',
379
-                    ],
380
-                    'event_editor_event_registration_options_help_tab' => [
381
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
-                        'filename' => 'event_editor_event_registration_options',
383
-                    ],
384
-                    'event_editor_tags_categories_help_tab'            => [
385
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
-                        'filename' => 'event_editor_tags_categories',
387
-                    ],
388
-                    'event_editor_questions_registrants_help_tab'      => [
389
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
-                        'filename' => 'event_editor_questions_registrants',
391
-                    ],
392
-                    'event_editor_save_new_event_help_tab'             => [
393
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
394
-                        'filename' => 'event_editor_save_new_event',
395
-                    ],
396
-                    'event_editor_other_help_tab'                      => [
397
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
398
-                        'filename' => 'event_editor_other',
399
-                    ],
400
-                ],
401
-                'require_nonce' => false,
402
-            ],
403
-            'default_event_settings' => [
404
-                'nav'           => [
405
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
406
-                    'order' => 40,
407
-                ],
408
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
409
-                'labels'        => [
410
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
411
-                ],
412
-                'help_tabs'     => [
413
-                    'default_settings_help_tab'        => [
414
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
415
-                        'filename' => 'events_default_settings',
416
-                    ],
417
-                    'default_settings_status_help_tab' => [
418
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
419
-                        'filename' => 'events_default_settings_status',
420
-                    ],
421
-                    'default_maximum_tickets_help_tab' => [
422
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
423
-                        'filename' => 'events_default_settings_max_tickets',
424
-                    ],
425
-                ],
426
-                'require_nonce' => false,
427
-            ],
428
-            // template settings
429
-            'template_settings'      => [
430
-                'nav'           => [
431
-                    'label' => esc_html__('Templates', 'event_espresso'),
432
-                    'order' => 30,
433
-                ],
434
-                'metaboxes'     => $this->_default_espresso_metaboxes,
435
-                'help_tabs'     => [
436
-                    'general_settings_templates_help_tab' => [
437
-                        'title'    => esc_html__('Templates', 'event_espresso'),
438
-                        'filename' => 'general_settings_templates',
439
-                    ],
440
-                ],
441
-                'require_nonce' => false,
442
-            ],
443
-            // event category stuff
444
-            'add_category'           => [
445
-                'nav'           => [
446
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
447
-                    'order'      => 15,
448
-                    'persistent' => false,
449
-                ],
450
-                'help_tabs'     => [
451
-                    'add_category_help_tab' => [
452
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
-                        'filename' => 'events_add_category',
454
-                    ],
455
-                ],
456
-                'metaboxes'     => ['_publish_post_box'],
457
-                'require_nonce' => false,
458
-            ],
459
-            'edit_category'          => [
460
-                'nav'           => [
461
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
462
-                    'order'      => 15,
463
-                    'persistent' => false,
464
-                    'url'        => $EVT_CAT_ID
465
-                        ? add_query_arg(
466
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
467
-                            $this->_current_page_view_url
468
-                        )
469
-                        : $this->_admin_base_url,
470
-                ],
471
-                'help_tabs'     => [
472
-                    'edit_category_help_tab' => [
473
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
474
-                        'filename' => 'events_edit_category',
475
-                    ],
476
-                ],
477
-                'metaboxes'     => ['_publish_post_box'],
478
-                'require_nonce' => false,
479
-            ],
480
-            'category_list'          => [
481
-                'nav'           => [
482
-                    'label' => esc_html__('Categories', 'event_espresso'),
483
-                    'order' => 20,
484
-                ],
485
-                'list_table'    => 'Event_Categories_Admin_List_Table',
486
-                'help_tabs'     => [
487
-                    'events_categories_help_tab'                       => [
488
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
489
-                        'filename' => 'events_categories',
490
-                    ],
491
-                    'events_categories_table_column_headings_help_tab' => [
492
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
-                        'filename' => 'events_categories_table_column_headings',
494
-                    ],
495
-                    'events_categories_view_help_tab'                  => [
496
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
-                        'filename' => 'events_categories_views',
498
-                    ],
499
-                    'events_categories_other_help_tab'                 => [
500
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
-                        'filename' => 'events_categories_other',
502
-                    ],
503
-                ],
504
-                'metaboxes'     => $this->_default_espresso_metaboxes,
505
-                'require_nonce' => false,
506
-            ],
507
-            'preview_deletion'       => [
508
-                'nav'           => [
509
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
-                    'order'      => 15,
511
-                    'persistent' => false,
512
-                    'url'        => '',
513
-                ],
514
-                'require_nonce' => false,
515
-            ],
516
-        ];
517
-    }
518
-
519
-
520
-    /**
521
-     * Used to register any global screen options if necessary for every route in this admin page group.
522
-     */
523
-    protected function _add_screen_options()
524
-    {
525
-    }
526
-
527
-
528
-    /**
529
-     * Implementing the screen options for the 'default' route.
530
-     *
531
-     * @throws InvalidArgumentException
532
-     * @throws InvalidDataTypeException
533
-     * @throws InvalidInterfaceException
534
-     */
535
-    protected function _add_screen_options_default()
536
-    {
537
-        $this->_per_page_screen_option();
538
-    }
539
-
540
-
541
-    /**
542
-     * Implementing screen options for the category list route.
543
-     *
544
-     * @throws InvalidArgumentException
545
-     * @throws InvalidDataTypeException
546
-     * @throws InvalidInterfaceException
547
-     */
548
-    protected function _add_screen_options_category_list()
549
-    {
550
-        $page_title              = $this->_admin_page_title;
551
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
552
-        $this->_per_page_screen_option();
553
-        $this->_admin_page_title = $page_title;
554
-    }
555
-
556
-
557
-    /**
558
-     * Used to register any global feature pointers for the admin page group.
559
-     */
560
-    protected function _add_feature_pointers()
561
-    {
562
-    }
563
-
564
-
565
-    /**
566
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
567
-     */
568
-    public function load_scripts_styles()
569
-    {
570
-        wp_register_style(
571
-            'events-admin-css',
572
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
573
-            [],
574
-            EVENT_ESPRESSO_VERSION
575
-        );
576
-        wp_register_style(
577
-            'ee-cat-admin',
578
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
579
-            [],
580
-            EVENT_ESPRESSO_VERSION
581
-        );
582
-        wp_enqueue_style('events-admin-css');
583
-        wp_enqueue_style('ee-cat-admin');
584
-        // scripts
585
-        wp_register_script(
586
-            'event_editor_js',
587
-            EVENTS_ASSETS_URL . 'event_editor.js',
588
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
589
-            EVENT_ESPRESSO_VERSION,
590
-            true
591
-        );
592
-    }
593
-
594
-
595
-    /**
596
-     * Enqueuing scripts and styles specific to this view
597
-     */
598
-    public function load_scripts_styles_create_new()
599
-    {
600
-        $this->load_scripts_styles_edit();
601
-    }
602
-
603
-
604
-    /**
605
-     * Enqueuing scripts and styles specific to this view
606
-     */
607
-    public function load_scripts_styles_edit()
608
-    {
609
-        // styles
610
-        wp_enqueue_style('espresso-ui-theme');
611
-        wp_register_style(
612
-            'event-editor-css',
613
-            EVENTS_ASSETS_URL . 'event-editor.css',
614
-            ['ee-admin-css'],
615
-            EVENT_ESPRESSO_VERSION
616
-        );
617
-        wp_enqueue_style('event-editor-css');
618
-        // scripts
619
-        if (! $this->admin_config->useAdvancedEditor()) {
620
-            wp_register_script(
621
-                'event-datetime-metabox',
622
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
623
-                ['event_editor_js', 'ee-datepicker'],
624
-                EVENT_ESPRESSO_VERSION
625
-            );
626
-            wp_enqueue_script('event-datetime-metabox');
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Populating the _views property for the category list table view.
633
-     */
634
-    protected function _set_list_table_views_category_list()
635
-    {
636
-        $this->_views = [
637
-            'all' => [
638
-                'slug'        => 'all',
639
-                'label'       => esc_html__('All', 'event_espresso'),
640
-                'count'       => 0,
641
-                'bulk_action' => [
642
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
643
-                ],
644
-            ],
645
-        ];
646
-    }
647
-
648
-
649
-    /**
650
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
651
-     */
652
-    public function admin_init()
653
-    {
654
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
655
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
656
-            'event_espresso'
657
-        );
658
-    }
659
-
660
-
661
-    /**
662
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
663
-     * group.
664
-     */
665
-    public function admin_notices()
666
-    {
667
-    }
668
-
669
-
670
-    /**
671
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
672
-     * this admin page group.
673
-     */
674
-    public function admin_footer_scripts()
675
-    {
676
-    }
677
-
678
-
679
-    /**
680
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
681
-     * warning (via EE_Error::add_error());
682
-     *
683
-     * @param EE_Event $event Event object
684
-     * @param string   $req_type
685
-     * @return void
686
-     * @throws EE_Error
687
-     * @throws ReflectionException
688
-     */
689
-    public function verify_event_edit($event = null, $req_type = '')
690
-    {
691
-        // don't need to do this when processing
692
-        if (! empty($req_type)) {
693
-            return;
694
-        }
695
-        // no event?
696
-        if (! $event instanceof EE_Event) {
697
-            $event = $this->_cpt_model_obj;
698
-        }
699
-        // STILL no event?
700
-        if (! $event instanceof EE_Event) {
701
-            return;
702
-        }
703
-        $orig_status = $event->status();
704
-        // first check if event is active.
705
-        if (
706
-            $orig_status === EEM_Event::cancelled
707
-            || $orig_status === EEM_Event::postponed
708
-            || $event->is_expired()
709
-            || $event->is_inactive()
710
-        ) {
711
-            return;
712
-        }
713
-        // made it here so it IS active... next check that any of the tickets are sold.
714
-        if ($event->is_sold_out(true)) {
715
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
716
-                EE_Error::add_attention(
717
-                    sprintf(
718
-                        esc_html__(
719
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
720
-                            'event_espresso'
721
-                        ),
722
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
723
-                    )
724
-                );
725
-            }
726
-            return;
727
-        }
728
-        if ($orig_status === EEM_Event::sold_out) {
729
-            EE_Error::add_attention(
730
-                sprintf(
731
-                    esc_html__(
732
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
733
-                        'event_espresso'
734
-                    ),
735
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
736
-                )
737
-            );
738
-        }
739
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
740
-        if (! $event->tickets_on_sale()) {
741
-            return;
742
-        }
743
-        // made it here so show warning
744
-        $this->_edit_event_warning();
745
-    }
746
-
747
-
748
-    /**
749
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
750
-     * When needed, hook this into a EE_Error::add_error() notice.
751
-     *
752
-     * @access protected
753
-     * @return void
754
-     */
755
-    protected function _edit_event_warning()
756
-    {
757
-        // we don't want to add warnings during these requests
758
-        if ($this->request->getRequestParam('action') === 'editpost') {
759
-            return;
760
-        }
761
-        EE_Error::add_attention(
762
-            sprintf(
763
-                esc_html__(
764
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
765
-                    'event_espresso'
766
-                ),
767
-                '<a class="espresso-help-tab-lnk">',
768
-                '</a>'
769
-            )
770
-        );
771
-    }
772
-
773
-
774
-    /**
775
-     * When a user is creating a new event, notify them if they haven't set their timezone.
776
-     * Otherwise, do the normal logic
777
-     *
778
-     * @return void
779
-     * @throws EE_Error
780
-     * @throws InvalidArgumentException
781
-     * @throws InvalidDataTypeException
782
-     * @throws InvalidInterfaceException
783
-     */
784
-    protected function _create_new_cpt_item()
785
-    {
786
-        $has_timezone_string = get_option('timezone_string');
787
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
788
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
789
-            EE_Error::add_attention(
790
-                sprintf(
791
-                    esc_html__(
792
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
793
-                        'event_espresso'
794
-                    ),
795
-                    '<br>',
796
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
797
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
798
-                    . '</select>',
799
-                    '<button class="button button-secondary timezone-submit">',
800
-                    '</button><span class="spinner"></span>'
801
-                ),
802
-                __FILE__,
803
-                __FUNCTION__,
804
-                __LINE__
805
-            );
806
-        }
807
-        parent::_create_new_cpt_item();
808
-    }
809
-
810
-
811
-    /**
812
-     * Sets the _views property for the default route in this admin page group.
813
-     */
814
-    protected function _set_list_table_views_default()
815
-    {
816
-        $this->_views = [
817
-            'all'   => [
818
-                'slug'        => 'all',
819
-                'label'       => esc_html__('View All Events', 'event_espresso'),
820
-                'count'       => 0,
821
-                'bulk_action' => [
822
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
823
-                ],
824
-            ],
825
-            'draft' => [
826
-                'slug'        => 'draft',
827
-                'label'       => esc_html__('Draft', 'event_espresso'),
828
-                'count'       => 0,
829
-                'bulk_action' => [
830
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
831
-                ],
832
-            ],
833
-        ];
834
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
835
-            $this->_views['trash'] = [
836
-                'slug'        => 'trash',
837
-                'label'       => esc_html__('Trash', 'event_espresso'),
838
-                'count'       => 0,
839
-                'bulk_action' => [
840
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
841
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
842
-                ],
843
-            ];
844
-        }
845
-    }
846
-
847
-
848
-    /**
849
-     * Provides the legend item array for the default list table view.
850
-     *
851
-     * @return array
852
-     * @throws EE_Error
853
-     * @throws EE_Error
854
-     */
855
-    protected function _event_legend_items()
856
-    {
857
-        $items    = [
858
-            'view_details'   => [
859
-                'class' => 'dashicons dashicons-search',
860
-                'desc'  => esc_html__('View Event', 'event_espresso'),
861
-            ],
862
-            'edit_event'     => [
863
-                'class' => 'ee-icon ee-icon-calendar-edit',
864
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
865
-            ],
866
-            'view_attendees' => [
867
-                'class' => 'dashicons dashicons-groups',
868
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
869
-            ],
870
-        ];
871
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
872
-        $statuses = [
873
-            'sold_out_status'  => [
874
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
875
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
876
-            ],
877
-            'active_status'    => [
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
879
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
880
-            ],
881
-            'upcoming_status'  => [
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
883
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
884
-            ],
885
-            'postponed_status' => [
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
887
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
888
-            ],
889
-            'cancelled_status' => [
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
891
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
892
-            ],
893
-            'expired_status'   => [
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
895
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
896
-            ],
897
-            'inactive_status'  => [
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
899
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
900
-            ],
901
-        ];
902
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
903
-        return array_merge($items, $statuses);
904
-    }
905
-
906
-
907
-    /**
908
-     * @return EEM_Event
909
-     * @throws EE_Error
910
-     * @throws InvalidArgumentException
911
-     * @throws InvalidDataTypeException
912
-     * @throws InvalidInterfaceException
913
-     * @throws ReflectionException
914
-     */
915
-    private function _event_model()
916
-    {
917
-        if (! $this->_event_model instanceof EEM_Event) {
918
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
919
-        }
920
-        return $this->_event_model;
921
-    }
922
-
923
-
924
-    /**
925
-     * Adds extra buttons to the WP CPT permalink field row.
926
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
927
-     *
928
-     * @param string $return    the current html
929
-     * @param int    $id        the post id for the page
930
-     * @param string $new_title What the title is
931
-     * @param string $new_slug  what the slug is
932
-     * @return string            The new html string for the permalink area
933
-     */
934
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
935
-    {
936
-        // make sure this is only when editing
937
-        if (! empty($id)) {
938
-            $post   = get_post($id);
939
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
940
-                       . esc_html__('Shortcode', 'event_espresso')
941
-                       . '</a> ';
942
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
943
-                       . $post->ID
944
-                       . ']">';
945
-        }
946
-        return $return;
947
-    }
948
-
949
-
950
-    /**
951
-     * _events_overview_list_table
952
-     * This contains the logic for showing the events_overview list
953
-     *
954
-     * @access protected
955
-     * @return void
956
-     * @throws DomainException
957
-     * @throws EE_Error
958
-     * @throws InvalidArgumentException
959
-     * @throws InvalidDataTypeException
960
-     * @throws InvalidInterfaceException
961
-     */
962
-    protected function _events_overview_list_table()
963
-    {
964
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
965
-        $after_list_table                           = [];
966
-        $after_list_table['view_event_list_button'] = EEH_HTML::br();
967
-        $after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link(
968
-            get_post_type_archive_link('espresso_events'),
969
-            esc_html__('View Event Archive Page', 'event_espresso'),
970
-            'button'
971
-        );
972
-        $after_list_table['legend']                 = $this->_display_legend($this->_event_legend_items());
973
-        $this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
974
-            'create_new',
975
-            'add',
976
-            [],
977
-            'add-new-h2'
978
-        );
979
-        $this->_template_args['after_list_table']   = array_merge(
980
-            (array) $this->_template_args['after_list_table'],
981
-            $after_list_table
982
-        );
983
-        $this->display_admin_list_table_page_with_no_sidebar();
984
-    }
985
-
986
-
987
-    /**
988
-     * this allows for extra misc actions in the default WP publish box
989
-     *
990
-     * @return void
991
-     * @throws DomainException
992
-     * @throws EE_Error
993
-     * @throws InvalidArgumentException
994
-     * @throws InvalidDataTypeException
995
-     * @throws InvalidInterfaceException
996
-     * @throws ReflectionException
997
-     */
998
-    public function extra_misc_actions_publish_box()
999
-    {
1000
-        $this->_generate_publish_box_extra_content();
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1006
-     * saved.
1007
-     * Typically you would use this to save any additional data.
1008
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1009
-     * ALSO very important.  When a post transitions from scheduled to published,
1010
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1011
-     * other meta saves. So MAKE sure that you handle this accordingly.
1012
-     *
1013
-     * @access protected
1014
-     * @abstract
1015
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1016
-     * @param object $post    The post object of the cpt that was saved.
1017
-     * @return void
1018
-     * @throws EE_Error
1019
-     * @throws InvalidArgumentException
1020
-     * @throws InvalidDataTypeException
1021
-     * @throws InvalidInterfaceException
1022
-     * @throws ReflectionException
1023
-     */
1024
-    protected function _insert_update_cpt_item($post_id, $post)
1025
-    {
1026
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1027
-            // get out we're not processing an event save.
1028
-            return;
1029
-        }
1030
-        $event_values = [
1031
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1032
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1033
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1034
-        ];
1035
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1036
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1037
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1038
-                'display_ticket_selector',
1039
-                false,
1040
-                'bool'
1041
-            );
1042
-            $event_values['EVT_additional_limit']            = min(
1043
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1044
-                $this->request->getRequestParam('additional_limit', null, 'int')
1045
-            );
1046
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1047
-                'EVT_default_registration_status',
1048
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1049
-            );
1050
-
1051
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1052
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1053
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1054
-        }
1055
-        // update event
1056
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1057
-        // get event_object for other metaboxes...
1058
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1059
-        // i have to setup where conditions to override the filters in the model
1060
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1061
-        $event = $this->_event_model()->get_one(
1062
-            [
1063
-                [
1064
-                    $this->_event_model()->primary_key_name() => $post_id,
1065
-                    'OR'                                      => [
1066
-                        'status'   => $post->post_status,
1067
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1068
-                        // but the returned object here has a status of "publish", so use the original post status as well
1069
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1070
-                    ],
1071
-                ],
1072
-            ]
1073
-        );
1074
-
1075
-        // the following are default callbacks for event attachment updates
1076
-        // that can be overridden by caffeinated functionality and/or addons.
1077
-        $event_update_callbacks = [];
1078
-        if (! $this->admin_config->useAdvancedEditor()) {
1079
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1080
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1081
-        }
1082
-        $event_update_callbacks = apply_filters(
1083
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1084
-            $event_update_callbacks
1085
-        );
1086
-
1087
-        $att_success = true;
1088
-        foreach ($event_update_callbacks as $e_callback) {
1089
-            $_success = is_callable($e_callback)
1090
-                ? $e_callback($event, $this->request->requestParams())
1091
-                : false;
1092
-            // if ANY of these updates fail then we want the appropriate global error message
1093
-            $att_success = $_success !== false ? $att_success : false;
1094
-        }
1095
-        // any errors?
1096
-        if ($success && $att_success === false) {
1097
-            EE_Error::add_error(
1098
-                esc_html__(
1099
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1100
-                    'event_espresso'
1101
-                ),
1102
-                __FILE__,
1103
-                __FUNCTION__,
1104
-                __LINE__
1105
-            );
1106
-        } elseif ($success === false) {
1107
-            EE_Error::add_error(
1108
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1109
-                __FILE__,
1110
-                __FUNCTION__,
1111
-                __LINE__
1112
-            );
1113
-        }
1114
-    }
1115
-
1116
-
1117
-    /**
1118
-     * @param int $post_id
1119
-     * @param int $revision_id
1120
-     * @throws EE_Error
1121
-     * @throws EE_Error
1122
-     * @throws ReflectionException
1123
-     * @see parent::restore_item()
1124
-     */
1125
-    protected function _restore_cpt_item($post_id, $revision_id)
1126
-    {
1127
-        // copy existing event meta to new post
1128
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1129
-        if ($post_evt instanceof EE_Event) {
1130
-            // meta revision restore
1131
-            $post_evt->restore_revision($revision_id);
1132
-            // related objs restore
1133
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1134
-        }
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * Attach the venue to the Event
1140
-     *
1141
-     * @param EE_Event $event Event Object to add the venue to
1142
-     * @param array    $data  The request data from the form
1143
-     * @return bool           Success or fail.
1144
-     * @throws EE_Error
1145
-     * @throws ReflectionException
1146
-     */
1147
-    protected function _default_venue_update(EE_Event $event, $data)
1148
-    {
1149
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1150
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1151
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1152
-        // very important.  If we don't have a venue name...
1153
-        // then we'll get out because not necessary to create empty venue
1154
-        if (empty($data['venue_title'])) {
1155
-            return false;
1156
-        }
1157
-        $venue_array = [
1158
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1159
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1160
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1161
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1162
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1163
-                ? $data['venue_short_description']
1164
-                : null,
1165
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1166
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1167
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1168
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1169
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1170
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1171
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1172
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1173
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1174
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1175
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1176
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1177
-            'status'              => 'publish',
1178
-        ];
1179
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1180
-        if (! empty($venue_id)) {
1181
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1182
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1183
-            // we've gotta make sure that the venue is always attached to a revision..
1184
-            // add_relation_to should take care of making sure that the relation is already present.
1185
-            $event->_add_relation_to($venue_id, 'Venue');
1186
-            return $rows_affected > 0;
1187
-        }
1188
-        // we insert the venue
1189
-        $venue_id = $venue_model->insert($venue_array);
1190
-        $event->_add_relation_to($venue_id, 'Venue');
1191
-        return ! empty($venue_id);
1192
-        // when we have the ancestor come in it's already been handled by the revision save.
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1198
-     *
1199
-     * @param EE_Event $event The Event object we're attaching data to
1200
-     * @param array    $data  The request data from the form
1201
-     * @return array
1202
-     * @throws EE_Error
1203
-     * @throws ReflectionException
1204
-     * @throws Exception
1205
-     */
1206
-    protected function _default_tickets_update(EE_Event $event, $data)
1207
-    {
1208
-        if ($this->admin_config->useAdvancedEditor()) {
1209
-            return [];
1210
-        }
1211
-        $datetime       = null;
1212
-        $saved_tickets  = [];
1213
-        $event_timezone = $event->get_timezone();
1214
-        $date_formats   = ['Y-m-d', 'h:i a'];
1215
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1216
-            // trim all values to ensure any excess whitespace is removed.
1217
-            $datetime_data                = array_map('trim', $datetime_data);
1218
-            $datetime_data['DTT_EVT_end'] =
1219
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1220
-                    ? $datetime_data['DTT_EVT_end']
1221
-                    : $datetime_data['DTT_EVT_start'];
1222
-            $datetime_values              = [
1223
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1224
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1225
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1226
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1227
-                'DTT_order'     => $row,
1228
-            ];
1229
-            // if we have an id then let's get existing object first and then set the new values.
1230
-            //  Otherwise we instantiate a new object for save.
1231
-            if (! empty($datetime_data['DTT_ID'])) {
1232
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1233
-                if (! $datetime instanceof EE_Datetime) {
1234
-                    throw new RuntimeException(
1235
-                        sprintf(
1236
-                            esc_html__(
1237
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1238
-                                'event_espresso'
1239
-                            ),
1240
-                            $datetime_data['DTT_ID']
1241
-                        )
1242
-                    );
1243
-                }
1244
-                $datetime->set_date_format($date_formats[0]);
1245
-                $datetime->set_time_format($date_formats[1]);
1246
-                foreach ($datetime_values as $field => $value) {
1247
-                    $datetime->set($field, $value);
1248
-                }
1249
-            } else {
1250
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1251
-            }
1252
-            if (! $datetime instanceof EE_Datetime) {
1253
-                throw new RuntimeException(
1254
-                    sprintf(
1255
-                        esc_html__(
1256
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1257
-                            'event_espresso'
1258
-                        ),
1259
-                        print_r($datetime_values, true)
1260
-                    )
1261
-                );
1262
-            }
1263
-            // before going any further make sure our dates are setup correctly
1264
-            // so that the end date is always equal or greater than the start date.
1265
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1266
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1267
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1268
-            }
1269
-            $datetime->save();
1270
-            $event->_add_relation_to($datetime, 'Datetime');
1271
-        }
1272
-        // no datetimes get deleted so we don't do any of that logic here.
1273
-        // update tickets next
1274
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1275
-
1276
-        // set up some default start and end dates in case those are not present in the incoming data
1277
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1278
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1279
-        // use the start date of the first datetime for the end date
1280
-        $first_datetime   = $event->first_datetime();
1281
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1282
-
1283
-        // now process the incoming data
1284
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1285
-            $update_prices = false;
1286
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1287
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1288
-                : 0;
1289
-            // trim inputs to ensure any excess whitespace is removed.
1290
-            $ticket_data   = array_map('trim', $ticket_data);
1291
-            $ticket_values = [
1292
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1293
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1294
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1295
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1296
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1297
-                    ? $ticket_data['TKT_start_date']
1298
-                    : $default_start_date,
1299
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1300
-                    ? $ticket_data['TKT_end_date']
1301
-                    : $default_end_date,
1302
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1303
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1304
-                    ? $ticket_data['TKT_qty']
1305
-                    : EE_INF,
1306
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1307
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1308
-                    ? $ticket_data['TKT_uses']
1309
-                    : EE_INF,
1310
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1311
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1312
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1313
-                'TKT_price'       => $ticket_price,
1314
-                'TKT_row'         => $row,
1315
-            ];
1316
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1317
-            // which means in turn that the prices will become new prices as well.
1318
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1319
-                $ticket_values['TKT_ID']         = 0;
1320
-                $ticket_values['TKT_is_default'] = 0;
1321
-                $update_prices                   = true;
1322
-            }
1323
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1324
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1325
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1326
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1327
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1328
-            if (! empty($ticket_data['TKT_ID'])) {
1329
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1330
-                if (! $existing_ticket instanceof EE_Ticket) {
1331
-                    throw new RuntimeException(
1332
-                        sprintf(
1333
-                            esc_html__(
1334
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1335
-                                'event_espresso'
1336
-                            ),
1337
-                            $ticket_data['TKT_ID']
1338
-                        )
1339
-                    );
1340
-                }
1341
-                $ticket_sold = $existing_ticket->count_related(
1342
-                    'Registration',
1343
-                    [
1344
-                            [
1345
-                                'STS_ID' => [
1346
-                                    'NOT IN',
1347
-                                    [EEM_Registration::status_id_incomplete],
1348
-                                ],
1349
-                            ],
1350
-                        ]
1351
-                ) > 0;
1352
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1353
-                // if they are different then we create a new ticket (if $ticket_sold)
1354
-                // if they aren't different then we go ahead and modify existing ticket.
1355
-                $create_new_ticket = $ticket_sold
1356
-                                     && $ticket_price !== $existing_ticket->price()
1357
-                                     && ! $existing_ticket->deleted();
1358
-                $existing_ticket->set_date_format($date_formats[0]);
1359
-                $existing_ticket->set_time_format($date_formats[1]);
1360
-                // set new values
1361
-                foreach ($ticket_values as $field => $value) {
1362
-                    if ($field == 'TKT_qty') {
1363
-                        $existing_ticket->set_qty($value);
1364
-                    } elseif ($field == 'TKT_price') {
1365
-                        $existing_ticket->set('TKT_price', $ticket_price);
1366
-                    } else {
1367
-                        $existing_ticket->set($field, $value);
1368
-                    }
1369
-                }
1370
-                $ticket = $existing_ticket;
1371
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1372
-                //  Otherwise we have to create a new ticket.
1373
-                if ($create_new_ticket) {
1374
-                    // archive the old ticket first
1375
-                    $existing_ticket->set('TKT_deleted', 1);
1376
-                    $existing_ticket->save();
1377
-                    // make sure this ticket is still recorded in our $saved_tickets
1378
-                    // so we don't run it through the regular trash routine.
1379
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1380
-                    // create new ticket that's a copy of the existing except,
1381
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1382
-                    $new_ticket = clone $existing_ticket;
1383
-                    $new_ticket->set('TKT_ID', 0);
1384
-                    $new_ticket->set('TKT_deleted', 0);
1385
-                    $new_ticket->set('TKT_sold', 0);
1386
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1387
-                    $update_prices = true;
1388
-                    $ticket        = $new_ticket;
1389
-                }
1390
-            } else {
1391
-                // no TKT_id so a new ticket
1392
-                $ticket_values['TKT_price'] = $ticket_price;
1393
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1394
-                $update_prices              = true;
1395
-            }
1396
-            if (! $ticket instanceof EE_Ticket) {
1397
-                throw new RuntimeException(
1398
-                    sprintf(
1399
-                        esc_html__(
1400
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1401
-                            'event_espresso'
1402
-                        ),
1403
-                        print_r($ticket_values, true)
1404
-                    )
1405
-                );
1406
-            }
1407
-            // cap ticket qty by datetime reg limits
1408
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1409
-            // update ticket.
1410
-            $ticket->save();
1411
-            // before going any further make sure our dates are setup correctly
1412
-            // so that the end date is always equal or greater than the start date.
1413
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1414
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1415
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1416
-                $ticket->save();
1417
-            }
1418
-            // initially let's add the ticket to the datetime
1419
-            $datetime->_add_relation_to($ticket, 'Ticket');
1420
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1421
-            // add prices to ticket
1422
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1423
-        }
1424
-        // however now we need to handle permanently deleting tickets via the ui.
1425
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1426
-        //  However, it does allow for deleting tickets that have no tickets sold,
1427
-        // in which case we want to get rid of permanently because there is no need to save in db.
1428
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1429
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1430
-        foreach ($tickets_removed as $id) {
1431
-            $id = absint($id);
1432
-            // get the ticket for this id
1433
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1434
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1435
-                continue;
1436
-            }
1437
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1438
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1439
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1440
-            foreach ($related_datetimes as $related_datetime) {
1441
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1442
-            }
1443
-            // need to do the same for prices (except these prices can also be deleted because again,
1444
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1445
-            $ticket_to_remove->delete_related_permanently('Price');
1446
-            // finally let's delete this ticket
1447
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1448
-            $ticket_to_remove->delete_permanently();
1449
-        }
1450
-        return [$datetime, $saved_tickets];
1451
-    }
1452
-
1453
-
1454
-    /**
1455
-     * This attaches a list of given prices to a ticket.
1456
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1457
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1458
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1459
-     *
1460
-     * @access  private
1461
-     * @param array     $prices_data Array of prices from the form.
1462
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1463
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1464
-     * @return  void
1465
-     * @throws EE_Error
1466
-     * @throws ReflectionException
1467
-     */
1468
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1469
-    {
1470
-        $timezone = $ticket->get_timezone();
1471
-        foreach ($prices_data as $row => $price_data) {
1472
-            $price_values = [
1473
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1474
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1475
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1476
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1477
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1478
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1479
-                'PRC_order'      => $row,
1480
-            ];
1481
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1482
-                $price_values['PRC_ID'] = 0;
1483
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1484
-            } else {
1485
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1486
-                // update this price with new values
1487
-                foreach ($price_values as $field => $new_price) {
1488
-                    $price->set($field, $new_price);
1489
-                }
1490
-            }
1491
-            if (! $price instanceof EE_Price) {
1492
-                throw new RuntimeException(
1493
-                    sprintf(
1494
-                        esc_html__(
1495
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1496
-                            'event_espresso'
1497
-                        ),
1498
-                        print_r($price_values, true)
1499
-                    )
1500
-                );
1501
-            }
1502
-            $price->save();
1503
-            $ticket->_add_relation_to($price, 'Price');
1504
-        }
1505
-    }
1506
-
1507
-
1508
-    /**
1509
-     * Add in our autosave ajax handlers
1510
-     *
1511
-     */
1512
-    protected function _ee_autosave_create_new()
1513
-    {
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * More autosave handlers.
1519
-     */
1520
-    protected function _ee_autosave_edit()
1521
-    {
1522
-    }
1523
-
1524
-
1525
-    /**
1526
-     * @throws EE_Error
1527
-     * @throws ReflectionException
1528
-     */
1529
-    private function _generate_publish_box_extra_content()
1530
-    {
1531
-        // load formatter helper
1532
-        // args for getting related registrations
1533
-        $approved_query_args        = [
1534
-            [
1535
-                'REG_deleted' => 0,
1536
-                'STS_ID'      => EEM_Registration::status_id_approved,
1537
-            ],
1538
-        ];
1539
-        $not_approved_query_args    = [
1540
-            [
1541
-                'REG_deleted' => 0,
1542
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1543
-            ],
1544
-        ];
1545
-        $pending_payment_query_args = [
1546
-            [
1547
-                'REG_deleted' => 0,
1548
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1549
-            ],
1550
-        ];
1551
-        // publish box
1552
-        $publish_box_extra_args = [
1553
-            'view_approved_reg_url'        => add_query_arg(
1554
-                [
1555
-                    'action'      => 'default',
1556
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1557
-                    '_reg_status' => EEM_Registration::status_id_approved,
1558
-                ],
1559
-                REG_ADMIN_URL
1560
-            ),
1561
-            'view_not_approved_reg_url'    => add_query_arg(
1562
-                [
1563
-                    'action'      => 'default',
1564
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1565
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1566
-                ],
1567
-                REG_ADMIN_URL
1568
-            ),
1569
-            'view_pending_payment_reg_url' => add_query_arg(
1570
-                [
1571
-                    'action'      => 'default',
1572
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1573
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1574
-                ],
1575
-                REG_ADMIN_URL
1576
-            ),
1577
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1578
-                'Registration',
1579
-                $approved_query_args
1580
-            ),
1581
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1582
-                'Registration',
1583
-                $not_approved_query_args
1584
-            ),
1585
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1586
-                'Registration',
1587
-                $pending_payment_query_args
1588
-            ),
1589
-            'misc_pub_section_class'       => apply_filters(
1590
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1591
-                'misc-pub-section'
1592
-            ),
1593
-        ];
1594
-        ob_start();
1595
-        do_action(
1596
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1597
-            $this->_cpt_model_obj
1598
-        );
1599
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1600
-        // load template
1601
-        EEH_Template::display_template(
1602
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1603
-            $publish_box_extra_args
1604
-        );
1605
-    }
1606
-
1607
-
1608
-    /**
1609
-     * @return EE_Event
1610
-     */
1611
-    public function get_event_object()
1612
-    {
1613
-        return $this->_cpt_model_obj;
1614
-    }
1615
-
1616
-
1617
-
1618
-
1619
-    /** METABOXES * */
1620
-    /**
1621
-     * _register_event_editor_meta_boxes
1622
-     * add all metaboxes related to the event_editor
1623
-     *
1624
-     * @return void
1625
-     * @throws EE_Error
1626
-     * @throws ReflectionException
1627
-     */
1628
-    protected function _register_event_editor_meta_boxes()
1629
-    {
1630
-        $this->verify_cpt_object();
1631
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1632
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1633
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1634
-            add_meta_box(
1635
-                'espresso_event_editor_event_options',
1636
-                esc_html__('Event Registration Options', 'event_espresso'),
1637
-                [$this, 'registration_options_meta_box'],
1638
-                $this->page_slug,
1639
-                'side'
1640
-            );
1641
-        }
1642
-        if (! $use_advanced_editor) {
1643
-            add_meta_box(
1644
-                'espresso_event_editor_tickets',
1645
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1646
-                [$this, 'ticket_metabox'],
1647
-                $this->page_slug,
1648
-                'normal',
1649
-                'high'
1650
-            );
1651
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1652
-            add_action(
1653
-                'add_meta_boxes_espresso_events',
1654
-                function () {
1655
-                    global $current_screen;
1656
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1657
-                },
1658
-                99
1659
-            );
1660
-        }
1661
-        // NOTE: if you're looking for other metaboxes in here,
1662
-        // where a metabox has a related management page in the admin
1663
-        // you will find it setup in the related management page's "_Hooks" file.
1664
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1665
-    }
1666
-
1667
-
1668
-    /**
1669
-     * @throws DomainException
1670
-     * @throws EE_Error
1671
-     * @throws ReflectionException
1672
-     */
1673
-    public function ticket_metabox()
1674
-    {
1675
-        $existing_datetime_ids = $existing_ticket_ids = [];
1676
-        // defaults for template args
1677
-        $template_args = [
1678
-            'existing_datetime_ids'    => '',
1679
-            'event_datetime_help_link' => '',
1680
-            'ticket_options_help_link' => '',
1681
-            'time'                     => null,
1682
-            'ticket_rows'              => '',
1683
-            'existing_ticket_ids'      => '',
1684
-            'total_ticket_rows'        => 1,
1685
-            'ticket_js_structure'      => '',
1686
-            'trash_icon'               => 'ee-lock-icon',
1687
-            'disabled'                 => '',
1688
-        ];
1689
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1690
-        /**
1691
-         * 1. Start with retrieving Datetimes
1692
-         * 2. Fore each datetime get related tickets
1693
-         * 3. For each ticket get related prices
1694
-         */
1695
-        /** @var EEM_Datetime $datetime_model */
1696
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1697
-        /** @var EEM_Ticket $datetime_model */
1698
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1699
-        $times        = $datetime_model->get_all_event_dates($event_id);
1700
-        /** @type EE_Datetime $first_datetime */
1701
-        $first_datetime = reset($times);
1702
-        // do we get related tickets?
1703
-        if (
1704
-            $first_datetime instanceof EE_Datetime
1705
-            && $first_datetime->ID() !== 0
1706
-        ) {
1707
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1708
-            $template_args['time']   = $first_datetime;
1709
-            $related_tickets         = $first_datetime->tickets(
1710
-                [
1711
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1712
-                    'default_where_conditions' => 'none',
1713
-                ]
1714
-            );
1715
-            if (! empty($related_tickets)) {
1716
-                $template_args['total_ticket_rows'] = count($related_tickets);
1717
-                $row                                = 0;
1718
-                foreach ($related_tickets as $ticket) {
1719
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1720
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1721
-                    $row++;
1722
-                }
1723
-            } else {
1724
-                $template_args['total_ticket_rows'] = 1;
1725
-                /** @type EE_Ticket $ticket */
1726
-                $ticket                       = $ticket_model->create_default_object();
1727
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1728
-            }
1729
-        } else {
1730
-            $template_args['time'] = $times[0];
1731
-            /** @type EE_Ticket[] $tickets */
1732
-            $tickets                      = $ticket_model->get_all_default_tickets();
1733
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1734
-            // NOTE: we're just sending the first default row
1735
-            // (decaf can't manage default tickets so this should be sufficient);
1736
-        }
1737
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1738
-            'event_editor_event_datetimes_help_tab'
1739
-        );
1740
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1741
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1742
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1743
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1744
-            $ticket_model->create_default_object(),
1745
-            true
1746
-        );
1747
-        $template                                  = apply_filters(
1748
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1749
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1750
-        );
1751
-        EEH_Template::display_template($template, $template_args);
1752
-    }
1753
-
1754
-
1755
-    /**
1756
-     * Setup an individual ticket form for the decaf event editor page
1757
-     *
1758
-     * @access private
1759
-     * @param EE_Ticket $ticket   the ticket object
1760
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1761
-     * @param int       $row
1762
-     * @return string generated html for the ticket row.
1763
-     * @throws EE_Error
1764
-     * @throws ReflectionException
1765
-     */
1766
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1767
-    {
1768
-        $template_args = [
1769
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1770
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1771
-                : '',
1772
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1773
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1774
-            'TKT_name'            => $ticket->get('TKT_name'),
1775
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1776
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1777
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1778
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1779
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1780
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1781
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1782
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1783
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1784
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1785
-                : ' disabled=disabled',
1786
-        ];
1787
-        $price         = $ticket->ID() !== 0
1788
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1789
-            : null;
1790
-        $price         = $price instanceof EE_Price
1791
-            ? $price
1792
-            : EEM_Price::instance()->create_default_object();
1793
-        $price_args    = [
1794
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1795
-            'PRC_amount'            => $price->get('PRC_amount'),
1796
-            'PRT_ID'                => $price->get('PRT_ID'),
1797
-            'PRC_ID'                => $price->get('PRC_ID'),
1798
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1799
-        ];
1800
-        // make sure we have default start and end dates if skeleton
1801
-        // handle rows that should NOT be empty
1802
-        if (empty($template_args['TKT_start_date'])) {
1803
-            // if empty then the start date will be now.
1804
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1805
-        }
1806
-        if (empty($template_args['TKT_end_date'])) {
1807
-            // get the earliest datetime (if present);
1808
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1809
-                ? $this->_cpt_model_obj->get_first_related(
1810
-                    'Datetime',
1811
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1812
-                )
1813
-                : null;
1814
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1815
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1816
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1817
-        }
1818
-        $template_args = array_merge($template_args, $price_args);
1819
-        $template      = apply_filters(
1820
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1821
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1822
-            $ticket
1823
-        );
1824
-        return EEH_Template::display_template($template, $template_args, true);
1825
-    }
1826
-
1827
-
1828
-    /**
1829
-     * @throws EE_Error
1830
-     * @throws ReflectionException
1831
-     */
1832
-    public function registration_options_meta_box()
1833
-    {
1834
-        $yes_no_values             = [
1835
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1836
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1837
-        ];
1838
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1839
-            [
1840
-                EEM_Registration::status_id_cancelled,
1841
-                EEM_Registration::status_id_declined,
1842
-                EEM_Registration::status_id_incomplete,
1843
-            ],
1844
-            true
1845
-        );
1846
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1847
-        $template_args['_event']                          = $this->_cpt_model_obj;
1848
-        $template_args['event']                           = $this->_cpt_model_obj;
1849
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1850
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1851
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1852
-            'default_reg_status',
1853
-            $default_reg_status_values,
1854
-            $this->_cpt_model_obj->default_registration_status()
1855
-        );
1856
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1857
-            'display_desc',
1858
-            $yes_no_values,
1859
-            $this->_cpt_model_obj->display_description()
1860
-        );
1861
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1862
-            'display_ticket_selector',
1863
-            $yes_no_values,
1864
-            $this->_cpt_model_obj->display_ticket_selector(),
1865
-            '',
1866
-            '',
1867
-            false
1868
-        );
1869
-        $template_args['additional_registration_options'] = apply_filters(
1870
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1871
-            '',
1872
-            $template_args,
1873
-            $yes_no_values,
1874
-            $default_reg_status_values
1875
-        );
1876
-        EEH_Template::display_template(
1877
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1878
-            $template_args
1879
-        );
1880
-    }
1881
-
1882
-
1883
-    /**
1884
-     * _get_events()
1885
-     * This method simply returns all the events (for the given _view and paging)
1886
-     *
1887
-     * @access public
1888
-     * @param int  $per_page     count of items per page (20 default);
1889
-     * @param int  $current_page what is the current page being viewed.
1890
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1891
-     *                           If FALSE then we return an array of event objects
1892
-     *                           that match the given _view and paging parameters.
1893
-     * @return array|int         an array of event objects or a count of them.
1894
-     * @throws Exception
1895
-     */
1896
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1897
-    {
1898
-        $EEM_Event   = $this->_event_model();
1899
-        $offset      = ($current_page - 1) * $per_page;
1900
-        $limit       = $count ? null : $offset . ',' . $per_page;
1901
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1902
-        $order       = $this->request->getRequestParam('order', 'DESC');
1903
-        $month_range = $this->request->getRequestParam('month_range');
1904
-        if ($month_range) {
1905
-            $pieces = explode(' ', $month_range, 3);
1906
-            // simulate the FIRST day of the month, that fixes issues for months like February
1907
-            // where PHP doesn't know what to assume for date.
1908
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1909
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1910
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1911
-        }
1912
-        $where  = [];
1913
-        $status = $this->request->getRequestParam('status');
1914
-        // determine what post_status our condition will have for the query.
1915
-        switch ($status) {
1916
-            case 'month':
1917
-            case 'today':
1918
-            case null:
1919
-            case 'all':
1920
-                break;
1921
-            case 'draft':
1922
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1923
-                break;
1924
-            default:
1925
-                $where['status'] = $status;
1926
-        }
1927
-        // categories? The default for all categories is -1
1928
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1929
-        if ($category !== -1) {
1930
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1931
-            $where['Term_Taxonomy.term_id']  = $category;
1932
-        }
1933
-        // date where conditions
1934
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1935
-        if ($month_range) {
1936
-            $DateTime = new DateTime(
1937
-                $year_r . '-' . $month_r . '-01 00:00:00',
1938
-                new DateTimeZone('UTC')
1939
-            );
1940
-            $start    = $DateTime->getTimestamp();
1941
-            // set the datetime to be the end of the month
1942
-            $DateTime->setDate(
1943
-                $year_r,
1944
-                $month_r,
1945
-                $DateTime->format('t')
1946
-            )->setTime(23, 59, 59);
1947
-            $end                             = $DateTime->getTimestamp();
1948
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1949
-        } elseif ($status === 'today') {
1950
-            $DateTime                        =
1951
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1952
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1953
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1954
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1955
-        } elseif ($status === 'month') {
1956
-            $now                             = date('Y-m-01');
1957
-            $DateTime                        =
1958
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1959
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1960
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1961
-                                                        ->setTime(23, 59, 59)
1962
-                                                        ->format(implode(' ', $start_formats));
1963
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1964
-        }
1965
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1966
-            $where['EVT_wp_user'] = get_current_user_id();
1967
-        } else {
1968
-            if (! isset($where['status'])) {
1969
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1970
-                    $where['OR'] = [
1971
-                        'status*restrict_private' => ['!=', 'private'],
1972
-                        'AND'                     => [
1973
-                            'status*inclusive' => ['=', 'private'],
1974
-                            'EVT_wp_user'      => get_current_user_id(),
1975
-                        ],
1976
-                    ];
1977
-                }
1978
-            }
1979
-        }
1980
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1981
-        if (
1982
-            $wp_user
1983
-            && $wp_user !== get_current_user_id()
1984
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1985
-        ) {
1986
-            $where['EVT_wp_user'] = $wp_user;
1987
-        }
1988
-        // search query handling
1989
-        $search_term = $this->request->getRequestParam('s');
1990
-        if ($search_term) {
1991
-            $search_term = '%' . $search_term . '%';
1992
-            $where['OR'] = [
1993
-                'EVT_name'       => ['LIKE', $search_term],
1994
-                'EVT_desc'       => ['LIKE', $search_term],
1995
-                'EVT_short_desc' => ['LIKE', $search_term],
1996
-            ];
1997
-        }
1998
-        // filter events by venue.
1999
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
2000
-        if ($venue) {
2001
-            $where['Venue.VNU_ID'] = $venue;
2002
-        }
2003
-        $request_params = $this->request->requestParams();
2004
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2005
-        $query_params   = apply_filters(
2006
-            'FHEE__Events_Admin_Page__get_events__query_params',
2007
-            [
2008
-                $where,
2009
-                'limit'    => $limit,
2010
-                'order_by' => $orderby,
2011
-                'order'    => $order,
2012
-                'group_by' => 'EVT_ID',
2013
-            ],
2014
-            $request_params
2015
-        );
2016
-
2017
-        // let's first check if we have special requests coming in.
2018
-        $active_status = $this->request->getRequestParam('active_status');
2019
-        if ($active_status) {
2020
-            switch ($active_status) {
2021
-                case 'upcoming':
2022
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2023
-                case 'expired':
2024
-                    return $EEM_Event->get_expired_events($query_params, $count);
2025
-                case 'active':
2026
-                    return $EEM_Event->get_active_events($query_params, $count);
2027
-                case 'inactive':
2028
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2029
-            }
2030
-        }
2031
-
2032
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2033
-    }
2034
-
2035
-
2036
-    /**
2037
-     * handling for WordPress CPT actions (trash, restore, delete)
2038
-     *
2039
-     * @param string $post_id
2040
-     * @throws EE_Error
2041
-     * @throws ReflectionException
2042
-     */
2043
-    public function trash_cpt_item($post_id)
2044
-    {
2045
-        $this->request->setRequestParam('EVT_ID', $post_id);
2046
-        $this->_trash_or_restore_event('trash', false);
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     * @param string $post_id
2052
-     * @throws EE_Error
2053
-     * @throws ReflectionException
2054
-     */
2055
-    public function restore_cpt_item($post_id)
2056
-    {
2057
-        $this->request->setRequestParam('EVT_ID', $post_id);
2058
-        $this->_trash_or_restore_event('draft', false);
2059
-    }
2060
-
2061
-
2062
-    /**
2063
-     * @param string $post_id
2064
-     * @throws EE_Error
2065
-     * @throws EE_Error
2066
-     */
2067
-    public function delete_cpt_item($post_id)
2068
-    {
2069
-        throw new EE_Error(
2070
-            esc_html__(
2071
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2072
-                'event_espresso'
2073
-            )
2074
-        );
2075
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2076
-        // $this->_delete_event();
2077
-    }
2078
-
2079
-
2080
-    /**
2081
-     * _trash_or_restore_event
2082
-     *
2083
-     * @access protected
2084
-     * @param string $event_status
2085
-     * @param bool   $redirect_after
2086
-     * @throws EE_Error
2087
-     * @throws EE_Error
2088
-     * @throws ReflectionException
2089
-     */
2090
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2091
-    {
2092
-        // determine the event id and set to array.
2093
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2094
-        // loop thru events
2095
-        if ($EVT_ID) {
2096
-            // clean status
2097
-            $event_status = sanitize_key($event_status);
2098
-            // grab status
2099
-            if (! empty($event_status)) {
2100
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2101
-            } else {
2102
-                $success = false;
2103
-                $msg     = esc_html__(
2104
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2105
-                    'event_espresso'
2106
-                );
2107
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2108
-            }
2109
-        } else {
2110
-            $success = false;
2111
-            $msg     = esc_html__(
2112
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2113
-                'event_espresso'
2114
-            );
2115
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2116
-        }
2117
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2118
-        if ($redirect_after) {
2119
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2120
-        }
2121
-    }
2122
-
2123
-
2124
-    /**
2125
-     * _trash_or_restore_events
2126
-     *
2127
-     * @access protected
2128
-     * @param string $event_status
2129
-     * @return void
2130
-     * @throws EE_Error
2131
-     * @throws EE_Error
2132
-     * @throws ReflectionException
2133
-     */
2134
-    protected function _trash_or_restore_events($event_status = 'trash')
2135
-    {
2136
-        // clean status
2137
-        $event_status = sanitize_key($event_status);
2138
-        // grab status
2139
-        if (! empty($event_status)) {
2140
-            $success = true;
2141
-            // determine the event id and set to array.
2142
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2143
-            // loop thru events
2144
-            foreach ($EVT_IDs as $EVT_ID) {
2145
-                if ($EVT_ID = absint($EVT_ID)) {
2146
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2147
-                    $success = $results !== false ? $success : false;
2148
-                } else {
2149
-                    $msg = sprintf(
2150
-                        esc_html__(
2151
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2152
-                            'event_espresso'
2153
-                        ),
2154
-                        $EVT_ID
2155
-                    );
2156
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2157
-                    $success = false;
2158
-                }
2159
-            }
2160
-        } else {
2161
-            $success = false;
2162
-            $msg     = esc_html__(
2163
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2164
-                'event_espresso'
2165
-            );
2166
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2167
-        }
2168
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2169
-        $success = $success ? 2 : false;
2170
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2171
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2172
-    }
2173
-
2174
-
2175
-    /**
2176
-     * @param int    $EVT_ID
2177
-     * @param string $event_status
2178
-     * @return bool
2179
-     * @throws EE_Error
2180
-     * @throws ReflectionException
2181
-     */
2182
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2183
-    {
2184
-        // grab event id
2185
-        if (! $EVT_ID) {
2186
-            $msg = esc_html__(
2187
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2188
-                'event_espresso'
2189
-            );
2190
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2191
-            return false;
2192
-        }
2193
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2194
-        // clean status
2195
-        $event_status = sanitize_key($event_status);
2196
-        // grab status
2197
-        if (empty($event_status)) {
2198
-            $msg = esc_html__(
2199
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2200
-                'event_espresso'
2201
-            );
2202
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2203
-            return false;
2204
-        }
2205
-        // was event trashed or restored ?
2206
-        switch ($event_status) {
2207
-            case 'draft':
2208
-                $action = 'restored from the trash';
2209
-                $hook   = 'AHEE_event_restored_from_trash';
2210
-                break;
2211
-            case 'trash':
2212
-                $action = 'moved to the trash';
2213
-                $hook   = 'AHEE_event_moved_to_trash';
2214
-                break;
2215
-            default:
2216
-                $action = 'updated';
2217
-                $hook   = false;
2218
-        }
2219
-        // use class to change status
2220
-        $this->_cpt_model_obj->set_status($event_status);
2221
-        $success = $this->_cpt_model_obj->save();
2222
-        if (! $success) {
2223
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2224
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2225
-            return false;
2226
-        }
2227
-        if ($hook) {
2228
-            do_action($hook);
2229
-        }
2230
-        return true;
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     * @param array $event_ids
2236
-     * @return array
2237
-     * @since   4.10.23.p
2238
-     */
2239
-    private function cleanEventIds(array $event_ids)
2240
-    {
2241
-        return array_map('absint', $event_ids);
2242
-    }
2243
-
2244
-
2245
-    /**
2246
-     * @return array
2247
-     * @since   4.10.23.p
2248
-     */
2249
-    private function getEventIdsFromRequest()
2250
-    {
2251
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2252
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2253
-        } else {
2254
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2255
-        }
2256
-    }
2257
-
2258
-
2259
-    /**
2260
-     * @param bool $preview_delete
2261
-     * @throws EE_Error
2262
-     */
2263
-    protected function _delete_event($preview_delete = true)
2264
-    {
2265
-        $this->_delete_events($preview_delete);
2266
-    }
2267
-
2268
-
2269
-    /**
2270
-     * Gets the tree traversal batch persister.
2271
-     *
2272
-     * @return NodeGroupDao
2273
-     * @throws InvalidArgumentException
2274
-     * @throws InvalidDataTypeException
2275
-     * @throws InvalidInterfaceException
2276
-     * @since 4.10.12.p
2277
-     */
2278
-    protected function getModelObjNodeGroupPersister()
2279
-    {
2280
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2281
-            $this->model_obj_node_group_persister =
2282
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2283
-        }
2284
-        return $this->model_obj_node_group_persister;
2285
-    }
2286
-
2287
-
2288
-    /**
2289
-     * @param bool $preview_delete
2290
-     * @return void
2291
-     * @throws EE_Error
2292
-     */
2293
-    protected function _delete_events($preview_delete = true)
2294
-    {
2295
-        $event_ids = $this->getEventIdsFromRequest();
2296
-        if ($preview_delete) {
2297
-            $this->generateDeletionPreview($event_ids);
2298
-        } else {
2299
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2300
-        }
2301
-    }
2302
-
2303
-
2304
-    /**
2305
-     * @param array $event_ids
2306
-     */
2307
-    protected function generateDeletionPreview(array $event_ids)
2308
-    {
2309
-        $event_ids = $this->cleanEventIds($event_ids);
2310
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2311
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2312
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2313
-            [
2314
-                'action'            => 'preview_deletion',
2315
-                'deletion_job_code' => $deletion_job_code,
2316
-            ],
2317
-            $this->_admin_base_url
2318
-        );
2319
-        EEH_URL::safeRedirectAndExit(
2320
-            EE_Admin_Page::add_query_args_and_nonce(
2321
-                [
2322
-                    'page'              => 'espresso_batch',
2323
-                    'batch'             => EED_Batch::batch_job,
2324
-                    'EVT_IDs'           => $event_ids,
2325
-                    'deletion_job_code' => $deletion_job_code,
2326
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2327
-                    'return_url'        => urlencode($return_url),
2328
-                ],
2329
-                admin_url()
2330
-            )
2331
-        );
2332
-    }
2333
-
2334
-
2335
-    /**
2336
-     * Checks for a POST submission
2337
-     *
2338
-     * @since 4.10.12.p
2339
-     */
2340
-    protected function confirmDeletion()
2341
-    {
2342
-        $deletion_redirect_logic =
2343
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2344
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2345
-    }
2346
-
2347
-
2348
-    /**
2349
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2350
-     *
2351
-     * @throws EE_Error
2352
-     * @since 4.10.12.p
2353
-     */
2354
-    protected function previewDeletion()
2355
-    {
2356
-        $preview_deletion_logic =
2357
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2358
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2359
-        $this->display_admin_page_with_no_sidebar();
2360
-    }
2361
-
2362
-
2363
-    /**
2364
-     * get total number of events
2365
-     *
2366
-     * @access public
2367
-     * @return int
2368
-     * @throws EE_Error
2369
-     * @throws EE_Error
2370
-     */
2371
-    public function total_events()
2372
-    {
2373
-        return EEM_Event::instance()->count(
2374
-            ['caps' => 'read_admin'],
2375
-            'EVT_ID',
2376
-            true
2377
-        );
2378
-    }
2379
-
2380
-
2381
-    /**
2382
-     * get total number of draft events
2383
-     *
2384
-     * @access public
2385
-     * @return int
2386
-     * @throws EE_Error
2387
-     * @throws EE_Error
2388
-     */
2389
-    public function total_events_draft()
2390
-    {
2391
-        return EEM_Event::instance()->count(
2392
-            [
2393
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2394
-                'caps' => 'read_admin',
2395
-            ],
2396
-            'EVT_ID',
2397
-            true
2398
-        );
2399
-    }
2400
-
2401
-
2402
-    /**
2403
-     * get total number of trashed events
2404
-     *
2405
-     * @access public
2406
-     * @return int
2407
-     * @throws EE_Error
2408
-     * @throws EE_Error
2409
-     */
2410
-    public function total_trashed_events()
2411
-    {
2412
-        return EEM_Event::instance()->count(
2413
-            [
2414
-                ['status' => 'trash'],
2415
-                'caps' => 'read_admin',
2416
-            ],
2417
-            'EVT_ID',
2418
-            true
2419
-        );
2420
-    }
2421
-
2422
-
2423
-    /**
2424
-     *    _default_event_settings
2425
-     *    This generates the Default Settings Tab
2426
-     *
2427
-     * @return void
2428
-     * @throws DomainException
2429
-     * @throws EE_Error
2430
-     * @throws InvalidArgumentException
2431
-     * @throws InvalidDataTypeException
2432
-     * @throws InvalidInterfaceException
2433
-     */
2434
-    protected function _default_event_settings()
2435
-    {
2436
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2437
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2438
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2439
-        $this->display_admin_page_with_sidebar();
2440
-    }
2441
-
2442
-
2443
-    /**
2444
-     * Return the form for event settings.
2445
-     *
2446
-     * @return EE_Form_Section_Proper
2447
-     * @throws EE_Error
2448
-     */
2449
-    protected function _default_event_settings_form()
2450
-    {
2451
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2452
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2453
-        // exclude
2454
-            [
2455
-                EEM_Registration::status_id_cancelled,
2456
-                EEM_Registration::status_id_declined,
2457
-                EEM_Registration::status_id_incomplete,
2458
-                EEM_Registration::status_id_wait_list,
2459
-            ],
2460
-            true
2461
-        );
2462
-        return new EE_Form_Section_Proper(
2463
-            [
2464
-                'name'            => 'update_default_event_settings',
2465
-                'html_id'         => 'update_default_event_settings',
2466
-                'html_class'      => 'form-table',
2467
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2468
-                'subsections'     => apply_filters(
2469
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2470
-                    [
2471
-                        'default_reg_status'  => new EE_Select_Input(
2472
-                            $registration_stati_for_selection,
2473
-                            [
2474
-                                'default'         => isset($registration_config->default_STS_ID)
2475
-                                                     && array_key_exists(
2476
-                                                         $registration_config->default_STS_ID,
2477
-                                                         $registration_stati_for_selection
2478
-                                                     )
2479
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2480
-                                    : EEM_Registration::status_id_pending_payment,
2481
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2482
-                                                     . EEH_Template::get_help_tab_link(
2483
-                                                         'default_settings_status_help_tab'
2484
-                                                     ),
2485
-                                'html_help_text'  => esc_html__(
2486
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2487
-                                    'event_espresso'
2488
-                                ),
2489
-                            ]
2490
-                        ),
2491
-                        'default_max_tickets' => new EE_Integer_Input(
2492
-                            [
2493
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2494
-                                    ? $registration_config->default_maximum_number_of_tickets
2495
-                                    : EEM_Event::get_default_additional_limit(),
2496
-                                'html_label_text' => esc_html__(
2497
-                                    'Default Maximum Tickets Allowed Per Order:',
2498
-                                    'event_espresso'
2499
-                                )
2500
-                                                     . EEH_Template::get_help_tab_link(
2501
-                                                         'default_maximum_tickets_help_tab"'
2502
-                                                     ),
2503
-                                'html_help_text'  => esc_html__(
2504
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2505
-                                    'event_espresso'
2506
-                                ),
2507
-                            ]
2508
-                        ),
2509
-                    ]
2510
-                ),
2511
-            ]
2512
-        );
2513
-    }
2514
-
2515
-
2516
-    /**
2517
-     * @return void
2518
-     * @throws EE_Error
2519
-     * @throws InvalidArgumentException
2520
-     * @throws InvalidDataTypeException
2521
-     * @throws InvalidInterfaceException
2522
-     */
2523
-    protected function _update_default_event_settings()
2524
-    {
2525
-        $form = $this->_default_event_settings_form();
2526
-        if ($form->was_submitted()) {
2527
-            $form->receive_form_submission();
2528
-            if ($form->is_valid()) {
2529
-                $registration_config = EE_Registry::instance()->CFG->registration;
2530
-                $valid_data          = $form->valid_data();
2531
-                if (isset($valid_data['default_reg_status'])) {
2532
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2533
-                }
2534
-                if (isset($valid_data['default_max_tickets'])) {
2535
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2536
-                }
2537
-                do_action(
2538
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2539
-                    $valid_data,
2540
-                    EE_Registry::instance()->CFG,
2541
-                    $this
2542
-                );
2543
-                // update because data was valid!
2544
-                EE_Registry::instance()->CFG->update_espresso_config();
2545
-                EE_Error::overwrite_success();
2546
-                EE_Error::add_success(
2547
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2548
-                );
2549
-            }
2550
-        }
2551
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2552
-    }
2553
-
2554
-
2555
-    /*************        Templates        *************
2556
-     *
2557
-     * @throws EE_Error
2558
-     */
2559
-    protected function _template_settings()
2560
-    {
2561
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2562
-        $this->_template_args['preview_img']  = '<img src="'
2563
-                                                . EVENTS_ASSETS_URL
2564
-                                                . '/images/'
2565
-                                                . 'caffeinated_template_features.jpg" alt="'
2566
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2567
-                                                . '" />';
2568
-        $this->_template_args['preview_text'] = '<strong>'
2569
-                                                . esc_html__(
2570
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2571
-                                                    'event_espresso'
2572
-                                                ) . '</strong>';
2573
-        $this->display_admin_caf_preview_page('template_settings_tab');
2574
-    }
2575
-
2576
-
2577
-    /** Event Category Stuff **/
2578
-    /**
2579
-     * set the _category property with the category object for the loaded page.
2580
-     *
2581
-     * @access private
2582
-     * @return void
2583
-     */
2584
-    private function _set_category_object()
2585
-    {
2586
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2587
-            return;
2588
-        } //already have the category object so get out.
2589
-        // set default category object
2590
-        $this->_set_empty_category_object();
2591
-        // only set if we've got an id
2592
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2593
-        if (! $category_ID) {
2594
-            return;
2595
-        }
2596
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2597
-        if (! empty($term)) {
2598
-            $this->_category->category_name       = $term->name;
2599
-            $this->_category->category_identifier = $term->slug;
2600
-            $this->_category->category_desc       = $term->description;
2601
-            $this->_category->id                  = $term->term_id;
2602
-            $this->_category->parent              = $term->parent;
2603
-        }
2604
-    }
2605
-
2606
-
2607
-    /**
2608
-     * Clears out category properties.
2609
-     */
2610
-    private function _set_empty_category_object()
2611
-    {
2612
-        $this->_category                = new stdClass();
2613
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2614
-        $this->_category->id            = $this->_category->parent = 0;
2615
-    }
2616
-
2617
-
2618
-    /**
2619
-     * @throws DomainException
2620
-     * @throws EE_Error
2621
-     * @throws InvalidArgumentException
2622
-     * @throws InvalidDataTypeException
2623
-     * @throws InvalidInterfaceException
2624
-     */
2625
-    protected function _category_list_table()
2626
-    {
2627
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2628
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2629
-        $this->_admin_page_title .= ' ';
2630
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2631
-            'add_category',
2632
-            'add_category',
2633
-            [],
2634
-            'add-new-h2'
2635
-        );
2636
-        $this->display_admin_list_table_page_with_sidebar();
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * Output category details view.
2642
-     *
2643
-     * @throws EE_Error
2644
-     * @throws EE_Error
2645
-     */
2646
-    protected function _category_details($view)
2647
-    {
2648
-        // load formatter helper
2649
-        // load field generator helper
2650
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2651
-        $this->_set_add_edit_form_tags($route);
2652
-        $this->_set_category_object();
2653
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2654
-        $delete_action = 'delete_category';
2655
-        // custom redirect
2656
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2657
-            ['action' => 'category_list'],
2658
-            $this->_admin_base_url
2659
-        );
2660
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2661
-        // take care of contents
2662
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2663
-        $this->display_admin_page_with_sidebar();
2664
-    }
2665
-
2666
-
2667
-    /**
2668
-     * Output category details content.
2669
-     *
2670
-     * @throws DomainException
2671
-     */
2672
-    protected function _category_details_content()
2673
-    {
2674
-        $editor_args['category_desc'] = [
2675
-            'type'          => 'wp_editor',
2676
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2677
-            'class'         => 'my_editor_custom',
2678
-            'wpeditor_args' => ['media_buttons' => false],
2679
-        ];
2680
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2681
-        $all_terms                    = get_terms(
2682
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2683
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2684
-        );
2685
-        // setup category select for term parents.
2686
-        $category_select_values[] = [
2687
-            'text' => esc_html__('No Parent', 'event_espresso'),
2688
-            'id'   => 0,
2689
-        ];
2690
-        foreach ($all_terms as $term) {
2691
-            $category_select_values[] = [
2692
-                'text' => $term->name,
2693
-                'id'   => $term->term_id,
2694
-            ];
2695
-        }
2696
-        $category_select = EEH_Form_Fields::select_input(
2697
-            'category_parent',
2698
-            $category_select_values,
2699
-            $this->_category->parent
2700
-        );
2701
-        $template_args   = [
2702
-            'category'                 => $this->_category,
2703
-            'category_select'          => $category_select,
2704
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2705
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2706
-            'disable'                  => '',
2707
-            'disabled_message'         => false,
2708
-        ];
2709
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2710
-        return EEH_Template::display_template($template, $template_args, true);
2711
-    }
2712
-
2713
-
2714
-    /**
2715
-     * Handles deleting categories.
2716
-     *
2717
-     * @throws EE_Error
2718
-     */
2719
-    protected function _delete_categories()
2720
-    {
2721
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2722
-        foreach ($category_IDs as $category_ID) {
2723
-            $this->_delete_category($category_ID);
2724
-        }
2725
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2726
-        $query_args = [
2727
-            'action' => 'category_list',
2728
-        ];
2729
-        $this->_redirect_after_action(0, '', '', $query_args);
2730
-    }
2731
-
2732
-
2733
-    /**
2734
-     * Handles deleting specific category.
2735
-     *
2736
-     * @param int $cat_id
2737
-     */
2738
-    protected function _delete_category($cat_id)
2739
-    {
2740
-        $cat_id = absint($cat_id);
2741
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2742
-    }
2743
-
2744
-
2745
-    /**
2746
-     * Handles triggering the update or insertion of a new category.
2747
-     *
2748
-     * @param bool $new_category true means we're triggering the insert of a new category.
2749
-     * @throws EE_Error
2750
-     * @throws EE_Error
2751
-     */
2752
-    protected function _insert_or_update_category($new_category)
2753
-    {
2754
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2755
-        $success = 0; // we already have a success message so lets not send another.
2756
-        if ($cat_id) {
2757
-            $query_args = [
2758
-                'action'     => 'edit_category',
2759
-                'EVT_CAT_ID' => $cat_id,
2760
-            ];
2761
-        } else {
2762
-            $query_args = ['action' => 'add_category'];
2763
-        }
2764
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2765
-    }
2766
-
2767
-
2768
-    /**
2769
-     * Inserts or updates category
2770
-     *
2771
-     * @param bool $update (true indicates we're updating a category).
2772
-     * @return bool|mixed|string
2773
-     */
2774
-    private function _insert_category($update = false)
2775
-    {
2776
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2777
-        $category_name       = $this->request->getRequestParam('category_name', '');
2778
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2779
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2780
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2781
-
2782
-        if (empty($category_name)) {
2783
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2784
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2785
-            return false;
2786
-        }
2787
-        $term_args = [
2788
-            'name'        => $category_name,
2789
-            'description' => $category_desc,
2790
-            'parent'      => $category_parent,
2791
-        ];
2792
-        // was the category_identifier input disabled?
2793
-        if ($category_identifier) {
2794
-            $term_args['slug'] = $category_identifier;
2795
-        }
2796
-        $insert_ids = $update
2797
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2798
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2799
-        if (! is_array($insert_ids)) {
2800
-            $msg = esc_html__(
2801
-                'An error occurred and the category has not been saved to the database.',
2802
-                'event_espresso'
2803
-            );
2804
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2805
-        } else {
2806
-            $category_ID = $insert_ids['term_id'];
2807
-            $msg         = sprintf(
2808
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2809
-                $category_name
2810
-            );
2811
-            EE_Error::add_success($msg);
2812
-        }
2813
-        return $category_ID;
2814
-    }
2815
-
2816
-
2817
-    /**
2818
-     * Gets categories or count of categories matching the arguments in the request.
2819
-     *
2820
-     * @param int  $per_page
2821
-     * @param int  $current_page
2822
-     * @param bool $count
2823
-     * @return EE_Term_Taxonomy[]|int
2824
-     * @throws EE_Error
2825
-     */
2826
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2827
-    {
2828
-        // testing term stuff
2829
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2830
-        $order       = $this->request->getRequestParam('order', 'DESC');
2831
-        $limit       = ($current_page - 1) * $per_page;
2832
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2833
-        $search_term = $this->request->getRequestParam('s');
2834
-        if ($search_term) {
2835
-            $search_term = '%' . $search_term . '%';
2836
-            $where['OR'] = [
2837
-                'Term.name'   => ['LIKE', $search_term],
2838
-                'description' => ['LIKE', $search_term],
2839
-            ];
2840
-        }
2841
-        $query_params = [
2842
-            $where,
2843
-            'order_by'   => [$orderby => $order],
2844
-            'limit'      => $limit . ',' . $per_page,
2845
-            'force_join' => ['Term'],
2846
-        ];
2847
-        return $count
2848
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2849
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2850
-    }
2851
-
2852
-    /* end category stuff */
2853
-
2854
-
2855
-    /**************/
2856
-
2857
-
2858
-    /**
2859
-     * Callback for the `ee_save_timezone_setting` ajax action.
2860
-     *
2861
-     * @throws EE_Error
2862
-     * @throws InvalidArgumentException
2863
-     * @throws InvalidDataTypeException
2864
-     * @throws InvalidInterfaceException
2865
-     */
2866
-    public function saveTimezoneString()
2867
-    {
2868
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2869
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2870
-            EE_Error::add_error(
2871
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2872
-                __FILE__,
2873
-                __FUNCTION__,
2874
-                __LINE__
2875
-            );
2876
-            $this->_template_args['error'] = true;
2877
-            $this->_return_json();
2878
-        }
2879
-
2880
-        update_option('timezone_string', $timezone_string);
2881
-        EE_Error::add_success(
2882
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2883
-        );
2884
-        $this->_template_args['success'] = true;
2885
-        $this->_return_json(true, ['action' => 'create_new']);
2886
-    }
2887
-
2888
-
2889
-    /**
2890 2557
      * @throws EE_Error
2891
-     * @deprecated 4.10.25.p
2892 2558
      */
2893
-    public function save_timezonestring_setting()
2894
-    {
2895
-        $this->saveTimezoneString();
2896
-    }
2559
+	protected function _template_settings()
2560
+	{
2561
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2562
+		$this->_template_args['preview_img']  = '<img src="'
2563
+												. EVENTS_ASSETS_URL
2564
+												. '/images/'
2565
+												. 'caffeinated_template_features.jpg" alt="'
2566
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2567
+												. '" />';
2568
+		$this->_template_args['preview_text'] = '<strong>'
2569
+												. esc_html__(
2570
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2571
+													'event_espresso'
2572
+												) . '</strong>';
2573
+		$this->display_admin_caf_preview_page('template_settings_tab');
2574
+	}
2575
+
2576
+
2577
+	/** Event Category Stuff **/
2578
+	/**
2579
+	 * set the _category property with the category object for the loaded page.
2580
+	 *
2581
+	 * @access private
2582
+	 * @return void
2583
+	 */
2584
+	private function _set_category_object()
2585
+	{
2586
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2587
+			return;
2588
+		} //already have the category object so get out.
2589
+		// set default category object
2590
+		$this->_set_empty_category_object();
2591
+		// only set if we've got an id
2592
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2593
+		if (! $category_ID) {
2594
+			return;
2595
+		}
2596
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2597
+		if (! empty($term)) {
2598
+			$this->_category->category_name       = $term->name;
2599
+			$this->_category->category_identifier = $term->slug;
2600
+			$this->_category->category_desc       = $term->description;
2601
+			$this->_category->id                  = $term->term_id;
2602
+			$this->_category->parent              = $term->parent;
2603
+		}
2604
+	}
2605
+
2606
+
2607
+	/**
2608
+	 * Clears out category properties.
2609
+	 */
2610
+	private function _set_empty_category_object()
2611
+	{
2612
+		$this->_category                = new stdClass();
2613
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2614
+		$this->_category->id            = $this->_category->parent = 0;
2615
+	}
2616
+
2617
+
2618
+	/**
2619
+	 * @throws DomainException
2620
+	 * @throws EE_Error
2621
+	 * @throws InvalidArgumentException
2622
+	 * @throws InvalidDataTypeException
2623
+	 * @throws InvalidInterfaceException
2624
+	 */
2625
+	protected function _category_list_table()
2626
+	{
2627
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2628
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2629
+		$this->_admin_page_title .= ' ';
2630
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2631
+			'add_category',
2632
+			'add_category',
2633
+			[],
2634
+			'add-new-h2'
2635
+		);
2636
+		$this->display_admin_list_table_page_with_sidebar();
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * Output category details view.
2642
+	 *
2643
+	 * @throws EE_Error
2644
+	 * @throws EE_Error
2645
+	 */
2646
+	protected function _category_details($view)
2647
+	{
2648
+		// load formatter helper
2649
+		// load field generator helper
2650
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2651
+		$this->_set_add_edit_form_tags($route);
2652
+		$this->_set_category_object();
2653
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2654
+		$delete_action = 'delete_category';
2655
+		// custom redirect
2656
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2657
+			['action' => 'category_list'],
2658
+			$this->_admin_base_url
2659
+		);
2660
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2661
+		// take care of contents
2662
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2663
+		$this->display_admin_page_with_sidebar();
2664
+	}
2665
+
2666
+
2667
+	/**
2668
+	 * Output category details content.
2669
+	 *
2670
+	 * @throws DomainException
2671
+	 */
2672
+	protected function _category_details_content()
2673
+	{
2674
+		$editor_args['category_desc'] = [
2675
+			'type'          => 'wp_editor',
2676
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2677
+			'class'         => 'my_editor_custom',
2678
+			'wpeditor_args' => ['media_buttons' => false],
2679
+		];
2680
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2681
+		$all_terms                    = get_terms(
2682
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2683
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2684
+		);
2685
+		// setup category select for term parents.
2686
+		$category_select_values[] = [
2687
+			'text' => esc_html__('No Parent', 'event_espresso'),
2688
+			'id'   => 0,
2689
+		];
2690
+		foreach ($all_terms as $term) {
2691
+			$category_select_values[] = [
2692
+				'text' => $term->name,
2693
+				'id'   => $term->term_id,
2694
+			];
2695
+		}
2696
+		$category_select = EEH_Form_Fields::select_input(
2697
+			'category_parent',
2698
+			$category_select_values,
2699
+			$this->_category->parent
2700
+		);
2701
+		$template_args   = [
2702
+			'category'                 => $this->_category,
2703
+			'category_select'          => $category_select,
2704
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2705
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2706
+			'disable'                  => '',
2707
+			'disabled_message'         => false,
2708
+		];
2709
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2710
+		return EEH_Template::display_template($template, $template_args, true);
2711
+	}
2712
+
2713
+
2714
+	/**
2715
+	 * Handles deleting categories.
2716
+	 *
2717
+	 * @throws EE_Error
2718
+	 */
2719
+	protected function _delete_categories()
2720
+	{
2721
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2722
+		foreach ($category_IDs as $category_ID) {
2723
+			$this->_delete_category($category_ID);
2724
+		}
2725
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2726
+		$query_args = [
2727
+			'action' => 'category_list',
2728
+		];
2729
+		$this->_redirect_after_action(0, '', '', $query_args);
2730
+	}
2731
+
2732
+
2733
+	/**
2734
+	 * Handles deleting specific category.
2735
+	 *
2736
+	 * @param int $cat_id
2737
+	 */
2738
+	protected function _delete_category($cat_id)
2739
+	{
2740
+		$cat_id = absint($cat_id);
2741
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2742
+	}
2743
+
2744
+
2745
+	/**
2746
+	 * Handles triggering the update or insertion of a new category.
2747
+	 *
2748
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2749
+	 * @throws EE_Error
2750
+	 * @throws EE_Error
2751
+	 */
2752
+	protected function _insert_or_update_category($new_category)
2753
+	{
2754
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2755
+		$success = 0; // we already have a success message so lets not send another.
2756
+		if ($cat_id) {
2757
+			$query_args = [
2758
+				'action'     => 'edit_category',
2759
+				'EVT_CAT_ID' => $cat_id,
2760
+			];
2761
+		} else {
2762
+			$query_args = ['action' => 'add_category'];
2763
+		}
2764
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2765
+	}
2766
+
2767
+
2768
+	/**
2769
+	 * Inserts or updates category
2770
+	 *
2771
+	 * @param bool $update (true indicates we're updating a category).
2772
+	 * @return bool|mixed|string
2773
+	 */
2774
+	private function _insert_category($update = false)
2775
+	{
2776
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2777
+		$category_name       = $this->request->getRequestParam('category_name', '');
2778
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2779
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2780
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2781
+
2782
+		if (empty($category_name)) {
2783
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2784
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2785
+			return false;
2786
+		}
2787
+		$term_args = [
2788
+			'name'        => $category_name,
2789
+			'description' => $category_desc,
2790
+			'parent'      => $category_parent,
2791
+		];
2792
+		// was the category_identifier input disabled?
2793
+		if ($category_identifier) {
2794
+			$term_args['slug'] = $category_identifier;
2795
+		}
2796
+		$insert_ids = $update
2797
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2798
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2799
+		if (! is_array($insert_ids)) {
2800
+			$msg = esc_html__(
2801
+				'An error occurred and the category has not been saved to the database.',
2802
+				'event_espresso'
2803
+			);
2804
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2805
+		} else {
2806
+			$category_ID = $insert_ids['term_id'];
2807
+			$msg         = sprintf(
2808
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2809
+				$category_name
2810
+			);
2811
+			EE_Error::add_success($msg);
2812
+		}
2813
+		return $category_ID;
2814
+	}
2815
+
2816
+
2817
+	/**
2818
+	 * Gets categories or count of categories matching the arguments in the request.
2819
+	 *
2820
+	 * @param int  $per_page
2821
+	 * @param int  $current_page
2822
+	 * @param bool $count
2823
+	 * @return EE_Term_Taxonomy[]|int
2824
+	 * @throws EE_Error
2825
+	 */
2826
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2827
+	{
2828
+		// testing term stuff
2829
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2830
+		$order       = $this->request->getRequestParam('order', 'DESC');
2831
+		$limit       = ($current_page - 1) * $per_page;
2832
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2833
+		$search_term = $this->request->getRequestParam('s');
2834
+		if ($search_term) {
2835
+			$search_term = '%' . $search_term . '%';
2836
+			$where['OR'] = [
2837
+				'Term.name'   => ['LIKE', $search_term],
2838
+				'description' => ['LIKE', $search_term],
2839
+			];
2840
+		}
2841
+		$query_params = [
2842
+			$where,
2843
+			'order_by'   => [$orderby => $order],
2844
+			'limit'      => $limit . ',' . $per_page,
2845
+			'force_join' => ['Term'],
2846
+		];
2847
+		return $count
2848
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2849
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2850
+	}
2851
+
2852
+	/* end category stuff */
2853
+
2854
+
2855
+	/**************/
2856
+
2857
+
2858
+	/**
2859
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2860
+	 *
2861
+	 * @throws EE_Error
2862
+	 * @throws InvalidArgumentException
2863
+	 * @throws InvalidDataTypeException
2864
+	 * @throws InvalidInterfaceException
2865
+	 */
2866
+	public function saveTimezoneString()
2867
+	{
2868
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2869
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2870
+			EE_Error::add_error(
2871
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2872
+				__FILE__,
2873
+				__FUNCTION__,
2874
+				__LINE__
2875
+			);
2876
+			$this->_template_args['error'] = true;
2877
+			$this->_return_json();
2878
+		}
2879
+
2880
+		update_option('timezone_string', $timezone_string);
2881
+		EE_Error::add_success(
2882
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2883
+		);
2884
+		$this->_template_args['success'] = true;
2885
+		$this->_return_json(true, ['action' => 'create_new']);
2886
+	}
2887
+
2888
+
2889
+	/**
2890
+	 * @throws EE_Error
2891
+	 * @deprecated 4.10.25.p
2892
+	 */
2893
+	public function save_timezonestring_setting()
2894
+	{
2895
+		$this->saveTimezoneString();
2896
+	}
2897 2897
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 1 patch
Indentation   +1217 added lines, -1217 removed lines patch added patch discarded remove patch
@@ -16,1274 +16,1274 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25 25
 
26 26
 
27
-    /**
28
-     * Extend_Registrations_Admin_Page constructor.
29
-     *
30
-     * @param bool $routing
31
-     */
32
-    public function __construct($routing = true)
33
-    {
34
-        parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
-        }
40
-    }
27
+	/**
28
+	 * Extend_Registrations_Admin_Page constructor.
29
+	 *
30
+	 * @param bool $routing
31
+	 */
32
+	public function __construct($routing = true)
33
+	{
34
+		parent::__construct($routing);
35
+		if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
+		}
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Extending page configuration.
45
-     */
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        $new_page_routes = array(
53
-            'reports'                      => array(
54
-                'func'       => '_registration_reports',
55
-                'capability' => 'ee_read_registrations',
56
-            ),
57
-            'registration_checkins'        => array(
58
-                'func'       => '_registration_checkin_list_table',
59
-                'capability' => 'ee_read_checkins',
60
-            ),
61
-            'newsletter_selected_send'     => array(
62
-                'func'       => '_newsletter_selected_send',
63
-                'noheader'   => true,
64
-                'capability' => 'ee_send_message',
65
-            ),
66
-            'delete_checkin_rows'          => array(
67
-                'func'       => '_delete_checkin_rows',
68
-                'noheader'   => true,
69
-                'capability' => 'ee_delete_checkins',
70
-            ),
71
-            'delete_checkin_row'           => array(
72
-                'func'       => '_delete_checkin_row',
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_checkin',
75
-                'obj_id'     => $reg_id,
76
-            ),
77
-            'toggle_checkin_status'        => array(
78
-                'func'       => '_toggle_checkin_status',
79
-                'noheader'   => true,
80
-                'capability' => 'ee_edit_checkin',
81
-                'obj_id'     => $reg_id,
82
-            ),
83
-            'toggle_checkin_status_bulk'   => array(
84
-                'func'       => '_toggle_checkin_status',
85
-                'noheader'   => true,
86
-                'capability' => 'ee_edit_checkins',
87
-            ),
88
-            'event_registrations'          => array(
89
-                'func'       => '_event_registrations_list_table',
90
-                'capability' => 'ee_read_checkins',
91
-            ),
92
-            'registrations_checkin_report' => array(
93
-                'func'       => '_registrations_checkin_report',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_read_registrations',
96
-            ),
97
-        );
98
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
-        $new_page_config = array(
100
-            'reports'               => array(
101
-                'nav'           => array(
102
-                    'label' => esc_html__('Reports', 'event_espresso'),
103
-                    'order' => 30,
104
-                ),
105
-                'help_tabs'     => array(
106
-                    'registrations_reports_help_tab' => array(
107
-                        'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
-                        'filename' => 'registrations_reports',
109
-                    ),
110
-                ),
111
-                'require_nonce' => false,
112
-            ),
113
-            'event_registrations'   => array(
114
-                'nav'           => array(
115
-                    'label'      => esc_html__('Event Check-In', 'event_espresso'),
116
-                    'order'      => 10,
117
-                    'persistent' => true,
118
-                ),
119
-                'help_tabs'     => array(
120
-                    'registrations_event_checkin_help_tab'                       => array(
121
-                        'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
122
-                        'filename' => 'registrations_event_checkin',
123
-                    ),
124
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
125
-                        'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
126
-                        'filename' => 'registrations_event_checkin_table_column_headings',
127
-                    ),
128
-                    'registrations_event_checkin_filters_help_tab'               => array(
129
-                        'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
130
-                        'filename' => 'registrations_event_checkin_filters',
131
-                    ),
132
-                    'registrations_event_checkin_views_help_tab'                 => array(
133
-                        'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
134
-                        'filename' => 'registrations_event_checkin_views',
135
-                    ),
136
-                    'registrations_event_checkin_other_help_tab'                 => array(
137
-                        'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
138
-                        'filename' => 'registrations_event_checkin_other',
139
-                    ),
140
-                ),
141
-                'qtips'         => array('Registration_List_Table_Tips'),
142
-                'list_table'    => 'EE_Event_Registrations_List_Table',
143
-                'metaboxes'     => array(),
144
-                'require_nonce' => false,
145
-            ),
146
-            'registration_checkins' => array(
147
-                'nav'           => array(
148
-                    'label'      => esc_html__('Check-In Records', 'event_espresso'),
149
-                    'order'      => 15,
150
-                    'persistent' => false,
151
-                    'url'        => '',
152
-                ),
153
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
154
-                'metaboxes'     => array(),
155
-                'require_nonce' => false,
156
-            ),
157
-        );
158
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
159
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
-    }
43
+	/**
44
+	 * Extending page configuration.
45
+	 */
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		$new_page_routes = array(
53
+			'reports'                      => array(
54
+				'func'       => '_registration_reports',
55
+				'capability' => 'ee_read_registrations',
56
+			),
57
+			'registration_checkins'        => array(
58
+				'func'       => '_registration_checkin_list_table',
59
+				'capability' => 'ee_read_checkins',
60
+			),
61
+			'newsletter_selected_send'     => array(
62
+				'func'       => '_newsletter_selected_send',
63
+				'noheader'   => true,
64
+				'capability' => 'ee_send_message',
65
+			),
66
+			'delete_checkin_rows'          => array(
67
+				'func'       => '_delete_checkin_rows',
68
+				'noheader'   => true,
69
+				'capability' => 'ee_delete_checkins',
70
+			),
71
+			'delete_checkin_row'           => array(
72
+				'func'       => '_delete_checkin_row',
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_checkin',
75
+				'obj_id'     => $reg_id,
76
+			),
77
+			'toggle_checkin_status'        => array(
78
+				'func'       => '_toggle_checkin_status',
79
+				'noheader'   => true,
80
+				'capability' => 'ee_edit_checkin',
81
+				'obj_id'     => $reg_id,
82
+			),
83
+			'toggle_checkin_status_bulk'   => array(
84
+				'func'       => '_toggle_checkin_status',
85
+				'noheader'   => true,
86
+				'capability' => 'ee_edit_checkins',
87
+			),
88
+			'event_registrations'          => array(
89
+				'func'       => '_event_registrations_list_table',
90
+				'capability' => 'ee_read_checkins',
91
+			),
92
+			'registrations_checkin_report' => array(
93
+				'func'       => '_registrations_checkin_report',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_read_registrations',
96
+			),
97
+		);
98
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
+		$new_page_config = array(
100
+			'reports'               => array(
101
+				'nav'           => array(
102
+					'label' => esc_html__('Reports', 'event_espresso'),
103
+					'order' => 30,
104
+				),
105
+				'help_tabs'     => array(
106
+					'registrations_reports_help_tab' => array(
107
+						'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
+						'filename' => 'registrations_reports',
109
+					),
110
+				),
111
+				'require_nonce' => false,
112
+			),
113
+			'event_registrations'   => array(
114
+				'nav'           => array(
115
+					'label'      => esc_html__('Event Check-In', 'event_espresso'),
116
+					'order'      => 10,
117
+					'persistent' => true,
118
+				),
119
+				'help_tabs'     => array(
120
+					'registrations_event_checkin_help_tab'                       => array(
121
+						'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
122
+						'filename' => 'registrations_event_checkin',
123
+					),
124
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
125
+						'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
126
+						'filename' => 'registrations_event_checkin_table_column_headings',
127
+					),
128
+					'registrations_event_checkin_filters_help_tab'               => array(
129
+						'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
130
+						'filename' => 'registrations_event_checkin_filters',
131
+					),
132
+					'registrations_event_checkin_views_help_tab'                 => array(
133
+						'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
134
+						'filename' => 'registrations_event_checkin_views',
135
+					),
136
+					'registrations_event_checkin_other_help_tab'                 => array(
137
+						'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
138
+						'filename' => 'registrations_event_checkin_other',
139
+					),
140
+				),
141
+				'qtips'         => array('Registration_List_Table_Tips'),
142
+				'list_table'    => 'EE_Event_Registrations_List_Table',
143
+				'metaboxes'     => array(),
144
+				'require_nonce' => false,
145
+			),
146
+			'registration_checkins' => array(
147
+				'nav'           => array(
148
+					'label'      => esc_html__('Check-In Records', 'event_espresso'),
149
+					'order'      => 15,
150
+					'persistent' => false,
151
+					'url'        => '',
152
+				),
153
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
154
+				'metaboxes'     => array(),
155
+				'require_nonce' => false,
156
+			),
157
+		);
158
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
159
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
+	}
162 162
 
163 163
 
164
-    /**
165
-     * Ajax hooks for all routes in this page.
166
-     */
167
-    protected function _ajax_hooks()
168
-    {
169
-        parent::_ajax_hooks();
170
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
171
-    }
164
+	/**
165
+	 * Ajax hooks for all routes in this page.
166
+	 */
167
+	protected function _ajax_hooks()
168
+	{
169
+		parent::_ajax_hooks();
170
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * Global scripts for all routes in this page.
176
-     */
177
-    public function load_scripts_styles()
178
-    {
179
-        parent::load_scripts_styles();
180
-        // if newsletter message type is active then let's add filter and load js for it.
181
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
182
-            // enqueue newsletter js
183
-            wp_enqueue_script(
184
-                'ee-newsletter-trigger',
185
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
186
-                array('ee-dialog'),
187
-                EVENT_ESPRESSO_VERSION,
188
-                true
189
-            );
190
-            wp_enqueue_style(
191
-                'ee-newsletter-trigger-css',
192
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
193
-                array(),
194
-                EVENT_ESPRESSO_VERSION
195
-            );
196
-            // hook in buttons for newsletter message type trigger.
197
-            add_action(
198
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
199
-                array($this, 'add_newsletter_action_buttons'),
200
-                10
201
-            );
202
-        }
203
-    }
174
+	/**
175
+	 * Global scripts for all routes in this page.
176
+	 */
177
+	public function load_scripts_styles()
178
+	{
179
+		parent::load_scripts_styles();
180
+		// if newsletter message type is active then let's add filter and load js for it.
181
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
182
+			// enqueue newsletter js
183
+			wp_enqueue_script(
184
+				'ee-newsletter-trigger',
185
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
186
+				array('ee-dialog'),
187
+				EVENT_ESPRESSO_VERSION,
188
+				true
189
+			);
190
+			wp_enqueue_style(
191
+				'ee-newsletter-trigger-css',
192
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
193
+				array(),
194
+				EVENT_ESPRESSO_VERSION
195
+			);
196
+			// hook in buttons for newsletter message type trigger.
197
+			add_action(
198
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
199
+				array($this, 'add_newsletter_action_buttons'),
200
+				10
201
+			);
202
+		}
203
+	}
204 204
 
205 205
 
206
-    /**
207
-     * Scripts and styles for just the reports route.
208
-     */
209
-    public function load_scripts_styles_reports()
210
-    {
211
-        wp_register_script(
212
-            'ee-reg-reports-js',
213
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
214
-            array('google-charts'),
215
-            EVENT_ESPRESSO_VERSION,
216
-            true
217
-        );
218
-        wp_enqueue_script('ee-reg-reports-js');
219
-        $this->_registration_reports_js_setup();
220
-    }
206
+	/**
207
+	 * Scripts and styles for just the reports route.
208
+	 */
209
+	public function load_scripts_styles_reports()
210
+	{
211
+		wp_register_script(
212
+			'ee-reg-reports-js',
213
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
214
+			array('google-charts'),
215
+			EVENT_ESPRESSO_VERSION,
216
+			true
217
+		);
218
+		wp_enqueue_script('ee-reg-reports-js');
219
+		$this->_registration_reports_js_setup();
220
+	}
221 221
 
222 222
 
223
-    /**
224
-     * Register screen options for event_registrations route.
225
-     */
226
-    protected function _add_screen_options_event_registrations()
227
-    {
228
-        $this->_per_page_screen_option();
229
-    }
223
+	/**
224
+	 * Register screen options for event_registrations route.
225
+	 */
226
+	protected function _add_screen_options_event_registrations()
227
+	{
228
+		$this->_per_page_screen_option();
229
+	}
230 230
 
231 231
 
232
-    /**
233
-     * Register screen options for registration_checkins route
234
-     */
235
-    protected function _add_screen_options_registration_checkins()
236
-    {
237
-        $page_title = $this->_admin_page_title;
238
-        $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
239
-        $this->_per_page_screen_option();
240
-        $this->_admin_page_title = $page_title;
241
-    }
232
+	/**
233
+	 * Register screen options for registration_checkins route
234
+	 */
235
+	protected function _add_screen_options_registration_checkins()
236
+	{
237
+		$page_title = $this->_admin_page_title;
238
+		$this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
239
+		$this->_per_page_screen_option();
240
+		$this->_admin_page_title = $page_title;
241
+	}
242 242
 
243 243
 
244
-    /**
245
-     * Set views property for event_registrations route.
246
-     */
247
-    protected function _set_list_table_views_event_registrations()
248
-    {
249
-        $this->_views = array(
250
-            'all' => array(
251
-                'slug'        => 'all',
252
-                'label'       => esc_html__('All', 'event_espresso'),
253
-                'count'       => 0,
254
-                'bulk_action' => ! isset($this->_req_data['event_id'])
255
-                    ? array()
256
-                    : array(
257
-                        'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
258
-                    ),
259
-            ),
260
-        );
261
-    }
244
+	/**
245
+	 * Set views property for event_registrations route.
246
+	 */
247
+	protected function _set_list_table_views_event_registrations()
248
+	{
249
+		$this->_views = array(
250
+			'all' => array(
251
+				'slug'        => 'all',
252
+				'label'       => esc_html__('All', 'event_espresso'),
253
+				'count'       => 0,
254
+				'bulk_action' => ! isset($this->_req_data['event_id'])
255
+					? array()
256
+					: array(
257
+						'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
258
+					),
259
+			),
260
+		);
261
+	}
262 262
 
263 263
 
264
-    /**
265
-     * Set views property for registration_checkins route.
266
-     */
267
-    protected function _set_list_table_views_registration_checkins()
268
-    {
269
-        $this->_views = array(
270
-            'all' => array(
271
-                'slug'        => 'all',
272
-                'label'       => esc_html__('All', 'event_espresso'),
273
-                'count'       => 0,
274
-                'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
275
-            ),
276
-        );
277
-    }
264
+	/**
265
+	 * Set views property for registration_checkins route.
266
+	 */
267
+	protected function _set_list_table_views_registration_checkins()
268
+	{
269
+		$this->_views = array(
270
+			'all' => array(
271
+				'slug'        => 'all',
272
+				'label'       => esc_html__('All', 'event_espresso'),
273
+				'count'       => 0,
274
+				'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
275
+			),
276
+		);
277
+	}
278 278
 
279 279
 
280
-    /**
281
-     * callback for ajax action.
282
-     *
283
-     * @since 4.3.0
284
-     * @return void (JSON)
285
-     * @throws EE_Error
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidDataTypeException
288
-     * @throws InvalidInterfaceException
289
-     */
290
-    public function get_newsletter_form_content()
291
-    {
292
-        // do a nonce check cause we're not coming in from an normal route here.
293
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
294
-            $this->_req_data['get_newsletter_form_content_nonce']
295
-        ) : '';
296
-        $nonce_ref = 'get_newsletter_form_content_nonce';
297
-        $this->_verify_nonce($nonce, $nonce_ref);
298
-        // let's get the mtp for the incoming MTP_ ID
299
-        if (! isset($this->_req_data['GRP_ID'])) {
300
-            EE_Error::add_error(
301
-                esc_html__(
302
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
303
-                    'event_espresso'
304
-                ),
305
-                __FILE__,
306
-                __FUNCTION__,
307
-                __LINE__
308
-            );
309
-            $this->_template_args['success'] = false;
310
-            $this->_template_args['error'] = true;
311
-            $this->_return_json();
312
-        }
313
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
314
-        if (! $MTPG instanceof EE_Message_Template_Group) {
315
-            EE_Error::add_error(
316
-                sprintf(
317
-                    esc_html__(
318
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
319
-                        'event_espresso'
320
-                    ),
321
-                    $this->_req_data['GRP_ID']
322
-                ),
323
-                __FILE__,
324
-                __FUNCTION__,
325
-                __LINE__
326
-            );
327
-            $this->_template_args['success'] = false;
328
-            $this->_template_args['error'] = true;
329
-            $this->_return_json();
330
-        }
331
-        $MTPs = $MTPG->context_templates();
332
-        $MTPs = $MTPs['attendee'];
333
-        $template_fields = array();
334
-        /** @var EE_Message_Template $MTP */
335
-        foreach ($MTPs as $MTP) {
336
-            $field = $MTP->get('MTP_template_field');
337
-            if ($field === 'content') {
338
-                $content = $MTP->get('MTP_content');
339
-                if (! empty($content['newsletter_content'])) {
340
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
341
-                }
342
-                continue;
343
-            }
344
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
345
-        }
346
-        $this->_template_args['success'] = true;
347
-        $this->_template_args['error'] = false;
348
-        $this->_template_args['data'] = array(
349
-            'batch_message_from'    => isset($template_fields['from'])
350
-                ? $template_fields['from']
351
-                : '',
352
-            'batch_message_subject' => isset($template_fields['subject'])
353
-                ? $template_fields['subject']
354
-                : '',
355
-            'batch_message_content' => isset($template_fields['newsletter_content'])
356
-                ? $template_fields['newsletter_content']
357
-                : '',
358
-        );
359
-        $this->_return_json();
360
-    }
280
+	/**
281
+	 * callback for ajax action.
282
+	 *
283
+	 * @since 4.3.0
284
+	 * @return void (JSON)
285
+	 * @throws EE_Error
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidDataTypeException
288
+	 * @throws InvalidInterfaceException
289
+	 */
290
+	public function get_newsletter_form_content()
291
+	{
292
+		// do a nonce check cause we're not coming in from an normal route here.
293
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
294
+			$this->_req_data['get_newsletter_form_content_nonce']
295
+		) : '';
296
+		$nonce_ref = 'get_newsletter_form_content_nonce';
297
+		$this->_verify_nonce($nonce, $nonce_ref);
298
+		// let's get the mtp for the incoming MTP_ ID
299
+		if (! isset($this->_req_data['GRP_ID'])) {
300
+			EE_Error::add_error(
301
+				esc_html__(
302
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
303
+					'event_espresso'
304
+				),
305
+				__FILE__,
306
+				__FUNCTION__,
307
+				__LINE__
308
+			);
309
+			$this->_template_args['success'] = false;
310
+			$this->_template_args['error'] = true;
311
+			$this->_return_json();
312
+		}
313
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
314
+		if (! $MTPG instanceof EE_Message_Template_Group) {
315
+			EE_Error::add_error(
316
+				sprintf(
317
+					esc_html__(
318
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
319
+						'event_espresso'
320
+					),
321
+					$this->_req_data['GRP_ID']
322
+				),
323
+				__FILE__,
324
+				__FUNCTION__,
325
+				__LINE__
326
+			);
327
+			$this->_template_args['success'] = false;
328
+			$this->_template_args['error'] = true;
329
+			$this->_return_json();
330
+		}
331
+		$MTPs = $MTPG->context_templates();
332
+		$MTPs = $MTPs['attendee'];
333
+		$template_fields = array();
334
+		/** @var EE_Message_Template $MTP */
335
+		foreach ($MTPs as $MTP) {
336
+			$field = $MTP->get('MTP_template_field');
337
+			if ($field === 'content') {
338
+				$content = $MTP->get('MTP_content');
339
+				if (! empty($content['newsletter_content'])) {
340
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
341
+				}
342
+				continue;
343
+			}
344
+			$template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
345
+		}
346
+		$this->_template_args['success'] = true;
347
+		$this->_template_args['error'] = false;
348
+		$this->_template_args['data'] = array(
349
+			'batch_message_from'    => isset($template_fields['from'])
350
+				? $template_fields['from']
351
+				: '',
352
+			'batch_message_subject' => isset($template_fields['subject'])
353
+				? $template_fields['subject']
354
+				: '',
355
+			'batch_message_content' => isset($template_fields['newsletter_content'])
356
+				? $template_fields['newsletter_content']
357
+				: '',
358
+		);
359
+		$this->_return_json();
360
+	}
361 361
 
362 362
 
363
-    /**
364
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
365
-     *
366
-     * @since 4.3.0
367
-     * @param EE_Admin_List_Table $list_table
368
-     * @return void
369
-     * @throws InvalidArgumentException
370
-     * @throws InvalidDataTypeException
371
-     * @throws InvalidInterfaceException
372
-     */
373
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
374
-    {
375
-        if (
376
-            ! EE_Registry::instance()->CAP->current_user_can(
377
-                'ee_send_message',
378
-                'espresso_registrations_newsletter_selected_send'
379
-            )
380
-        ) {
381
-            return;
382
-        }
383
-        $routes_to_add_to = array(
384
-            'contact_list',
385
-            'event_registrations',
386
-            'default',
387
-        );
388
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
389
-            if (
390
-                ($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
391
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
392
-            ) {
393
-                echo '';
394
-            } else {
395
-                $button_text = sprintf(
396
-                    esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
397
-                    '<span class="send-selected-newsletter-count">0</span>'
398
-                );
399
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
400
-                     . '<span class="dashicons dashicons-email "></span>'
401
-                     . $button_text
402
-                     . '</button>';
403
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
404
-            }
405
-        }
406
-    }
363
+	/**
364
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
365
+	 *
366
+	 * @since 4.3.0
367
+	 * @param EE_Admin_List_Table $list_table
368
+	 * @return void
369
+	 * @throws InvalidArgumentException
370
+	 * @throws InvalidDataTypeException
371
+	 * @throws InvalidInterfaceException
372
+	 */
373
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
374
+	{
375
+		if (
376
+			! EE_Registry::instance()->CAP->current_user_can(
377
+				'ee_send_message',
378
+				'espresso_registrations_newsletter_selected_send'
379
+			)
380
+		) {
381
+			return;
382
+		}
383
+		$routes_to_add_to = array(
384
+			'contact_list',
385
+			'event_registrations',
386
+			'default',
387
+		);
388
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
389
+			if (
390
+				($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
391
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
392
+			) {
393
+				echo '';
394
+			} else {
395
+				$button_text = sprintf(
396
+					esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
397
+					'<span class="send-selected-newsletter-count">0</span>'
398
+				);
399
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
400
+					 . '<span class="dashicons dashicons-email "></span>'
401
+					 . $button_text
402
+					 . '</button>';
403
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
404
+			}
405
+		}
406
+	}
407 407
 
408 408
 
409
-    /**
410
-     * @throws DomainException
411
-     * @throws EE_Error
412
-     * @throws InvalidArgumentException
413
-     * @throws InvalidDataTypeException
414
-     * @throws InvalidInterfaceException
415
-     */
416
-    public function newsletter_send_form_skeleton()
417
-    {
418
-        $list_table = $this->_list_table_object;
419
-        $codes = array();
420
-        // need to templates for the newsletter message type for the template selector.
421
-        $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
422
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
423
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
424
-        );
425
-        foreach ($mtps as $mtp) {
426
-            $name = $mtp->name();
427
-            $values[] = array(
428
-                'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
429
-                'id'   => $mtp->ID(),
430
-            );
431
-        }
432
-        // need to get a list of shortcodes that are available for the newsletter message type.
433
-        $shortcodes = EEH_MSG_Template::get_shortcodes(
434
-            'newsletter',
435
-            'email',
436
-            array(),
437
-            'attendee',
438
-            false
439
-        );
440
-        foreach ($shortcodes as $field => $shortcode_array) {
441
-            $available_shortcodes = array();
442
-            foreach ($shortcode_array as $shortcode => $shortcode_details) {
443
-                $field_id = $field === '[NEWSLETTER_CONTENT]'
444
-                    ? 'content'
445
-                    : $field;
446
-                $field_id = 'batch-message-' . strtolower($field_id);
447
-                $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
448
-                                          . $shortcode
449
-                                          . '" data-linked-input-id="' . $field_id . '">'
450
-                                          . $shortcode
451
-                                          . '</span>';
452
-            }
453
-            $codes[ $field ] = implode(', ', $available_shortcodes);
454
-        }
455
-        $shortcodes = $codes;
456
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
457
-        $form_template_args = array(
458
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
459
-            'form_route'        => 'newsletter_selected_send',
460
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
461
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
462
-            'redirect_back_to'  => $this->_req_action,
463
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
464
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
465
-            'shortcodes'        => $shortcodes,
466
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
467
-        );
468
-        EEH_Template::display_template($form_template, $form_template_args);
469
-    }
409
+	/**
410
+	 * @throws DomainException
411
+	 * @throws EE_Error
412
+	 * @throws InvalidArgumentException
413
+	 * @throws InvalidDataTypeException
414
+	 * @throws InvalidInterfaceException
415
+	 */
416
+	public function newsletter_send_form_skeleton()
417
+	{
418
+		$list_table = $this->_list_table_object;
419
+		$codes = array();
420
+		// need to templates for the newsletter message type for the template selector.
421
+		$values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
422
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
423
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
424
+		);
425
+		foreach ($mtps as $mtp) {
426
+			$name = $mtp->name();
427
+			$values[] = array(
428
+				'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
429
+				'id'   => $mtp->ID(),
430
+			);
431
+		}
432
+		// need to get a list of shortcodes that are available for the newsletter message type.
433
+		$shortcodes = EEH_MSG_Template::get_shortcodes(
434
+			'newsletter',
435
+			'email',
436
+			array(),
437
+			'attendee',
438
+			false
439
+		);
440
+		foreach ($shortcodes as $field => $shortcode_array) {
441
+			$available_shortcodes = array();
442
+			foreach ($shortcode_array as $shortcode => $shortcode_details) {
443
+				$field_id = $field === '[NEWSLETTER_CONTENT]'
444
+					? 'content'
445
+					: $field;
446
+				$field_id = 'batch-message-' . strtolower($field_id);
447
+				$available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
448
+										  . $shortcode
449
+										  . '" data-linked-input-id="' . $field_id . '">'
450
+										  . $shortcode
451
+										  . '</span>';
452
+			}
453
+			$codes[ $field ] = implode(', ', $available_shortcodes);
454
+		}
455
+		$shortcodes = $codes;
456
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
457
+		$form_template_args = array(
458
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
459
+			'form_route'        => 'newsletter_selected_send',
460
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
461
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
462
+			'redirect_back_to'  => $this->_req_action,
463
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
464
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
465
+			'shortcodes'        => $shortcodes,
466
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
467
+		);
468
+		EEH_Template::display_template($form_template, $form_template_args);
469
+	}
470 470
 
471 471
 
472
-    /**
473
-     * Handles sending selected registrations/contacts a newsletter.
474
-     *
475
-     * @since  4.3.0
476
-     * @return void
477
-     * @throws EE_Error
478
-     * @throws InvalidArgumentException
479
-     * @throws InvalidDataTypeException
480
-     * @throws InvalidInterfaceException
481
-     */
482
-    protected function _newsletter_selected_send()
483
-    {
484
-        $success = true;
485
-        // first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
486
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
487
-            EE_Error::add_error(
488
-                esc_html__(
489
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
490
-                    'event_espresso'
491
-                ),
492
-                __FILE__,
493
-                __FUNCTION__,
494
-                __LINE__
495
-            );
496
-            $success = false;
497
-        }
498
-        if ($success) {
499
-            // update Message template in case there are any changes
500
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
501
-                $this->_req_data['newsletter_mtp_selected']
502
-            );
503
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
504
-                ? $Message_Template_Group->context_templates()
505
-                : array();
506
-            if (empty($Message_Templates)) {
507
-                EE_Error::add_error(
508
-                    esc_html__(
509
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
510
-                        'event_espresso'
511
-                    ),
512
-                    __FILE__,
513
-                    __FUNCTION__,
514
-                    __LINE__
515
-                );
516
-            }
517
-            // let's just update the specific fields
518
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
519
-                if ($Message_Template instanceof EE_Message_Template) {
520
-                    $field = $Message_Template->get('MTP_template_field');
521
-                    $content = $Message_Template->get('MTP_content');
522
-                    $new_content = $content;
523
-                    switch ($field) {
524
-                        case 'from':
525
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
526
-                                ? $this->_req_data['batch_message']['from']
527
-                                : $content;
528
-                            break;
529
-                        case 'subject':
530
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
531
-                                ? $this->_req_data['batch_message']['subject']
532
-                                : $content;
533
-                            break;
534
-                        case 'content':
535
-                            $new_content = $content;
536
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
537
-                                ? $this->_req_data['batch_message']['content']
538
-                                : $content['newsletter_content'];
539
-                            break;
540
-                        default:
541
-                            // continue the foreach loop, we don't want to set $new_content nor save.
542
-                            continue 2;
543
-                    }
544
-                    $Message_Template->set('MTP_content', $new_content);
545
-                    $Message_Template->save();
546
-                }
547
-            }
548
-            // great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
549
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
550
-                ? $this->_req_data['batch_message']['id_type']
551
-                : 'registration';
552
-            // id_type will affect how we assemble the ids.
553
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
554
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
555
-                : array();
556
-            $registrations_used_for_contact_data = array();
557
-            // using switch because eventually we'll have other contexts that will be used for generating messages.
558
-            switch ($id_type) {
559
-                case 'registration':
560
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
561
-                        array(
562
-                            array(
563
-                                'REG_ID' => array('IN', $ids),
564
-                            ),
565
-                        )
566
-                    );
567
-                    break;
568
-                case 'contact':
569
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
570
-                                                                           ->get_latest_registration_for_each_of_given_contacts(
571
-                                                                               $ids
572
-                                                                           );
573
-                    break;
574
-            }
575
-            do_action_ref_array(
576
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
577
-                array(
578
-                    $registrations_used_for_contact_data,
579
-                    $Message_Template_Group->ID(),
580
-                )
581
-            );
582
-            // kept for backward compat, internally we no longer use this action.
583
-            // @deprecated 4.8.36.rc.002
584
-            $contacts = $id_type === 'registration'
585
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
586
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
587
-            do_action_ref_array(
588
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
589
-                array(
590
-                    $contacts,
591
-                    $Message_Template_Group->ID(),
592
-                )
593
-            );
594
-        }
595
-        $query_args = array(
596
-            'action' => ! empty($this->_req_data['redirect_back_to'])
597
-                ? $this->_req_data['redirect_back_to']
598
-                : 'default',
599
-        );
600
-        $this->_redirect_after_action(false, '', '', $query_args, true);
601
-    }
472
+	/**
473
+	 * Handles sending selected registrations/contacts a newsletter.
474
+	 *
475
+	 * @since  4.3.0
476
+	 * @return void
477
+	 * @throws EE_Error
478
+	 * @throws InvalidArgumentException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws InvalidInterfaceException
481
+	 */
482
+	protected function _newsletter_selected_send()
483
+	{
484
+		$success = true;
485
+		// first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
486
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
487
+			EE_Error::add_error(
488
+				esc_html__(
489
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
490
+					'event_espresso'
491
+				),
492
+				__FILE__,
493
+				__FUNCTION__,
494
+				__LINE__
495
+			);
496
+			$success = false;
497
+		}
498
+		if ($success) {
499
+			// update Message template in case there are any changes
500
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
501
+				$this->_req_data['newsletter_mtp_selected']
502
+			);
503
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
504
+				? $Message_Template_Group->context_templates()
505
+				: array();
506
+			if (empty($Message_Templates)) {
507
+				EE_Error::add_error(
508
+					esc_html__(
509
+						'Unable to retrieve message template fields from the db. Messages not sent.',
510
+						'event_espresso'
511
+					),
512
+					__FILE__,
513
+					__FUNCTION__,
514
+					__LINE__
515
+				);
516
+			}
517
+			// let's just update the specific fields
518
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
519
+				if ($Message_Template instanceof EE_Message_Template) {
520
+					$field = $Message_Template->get('MTP_template_field');
521
+					$content = $Message_Template->get('MTP_content');
522
+					$new_content = $content;
523
+					switch ($field) {
524
+						case 'from':
525
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
526
+								? $this->_req_data['batch_message']['from']
527
+								: $content;
528
+							break;
529
+						case 'subject':
530
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
531
+								? $this->_req_data['batch_message']['subject']
532
+								: $content;
533
+							break;
534
+						case 'content':
535
+							$new_content = $content;
536
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
537
+								? $this->_req_data['batch_message']['content']
538
+								: $content['newsletter_content'];
539
+							break;
540
+						default:
541
+							// continue the foreach loop, we don't want to set $new_content nor save.
542
+							continue 2;
543
+					}
544
+					$Message_Template->set('MTP_content', $new_content);
545
+					$Message_Template->save();
546
+				}
547
+			}
548
+			// great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
549
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
550
+				? $this->_req_data['batch_message']['id_type']
551
+				: 'registration';
552
+			// id_type will affect how we assemble the ids.
553
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
554
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
555
+				: array();
556
+			$registrations_used_for_contact_data = array();
557
+			// using switch because eventually we'll have other contexts that will be used for generating messages.
558
+			switch ($id_type) {
559
+				case 'registration':
560
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
561
+						array(
562
+							array(
563
+								'REG_ID' => array('IN', $ids),
564
+							),
565
+						)
566
+					);
567
+					break;
568
+				case 'contact':
569
+					$registrations_used_for_contact_data = EEM_Registration::instance()
570
+																		   ->get_latest_registration_for_each_of_given_contacts(
571
+																			   $ids
572
+																		   );
573
+					break;
574
+			}
575
+			do_action_ref_array(
576
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
577
+				array(
578
+					$registrations_used_for_contact_data,
579
+					$Message_Template_Group->ID(),
580
+				)
581
+			);
582
+			// kept for backward compat, internally we no longer use this action.
583
+			// @deprecated 4.8.36.rc.002
584
+			$contacts = $id_type === 'registration'
585
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
586
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
587
+			do_action_ref_array(
588
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
589
+				array(
590
+					$contacts,
591
+					$Message_Template_Group->ID(),
592
+				)
593
+			);
594
+		}
595
+		$query_args = array(
596
+			'action' => ! empty($this->_req_data['redirect_back_to'])
597
+				? $this->_req_data['redirect_back_to']
598
+				: 'default',
599
+		);
600
+		$this->_redirect_after_action(false, '', '', $query_args, true);
601
+	}
602 602
 
603 603
 
604
-    /**
605
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
606
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
607
-     */
608
-    protected function _registration_reports_js_setup()
609
-    {
610
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
611
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
612
-    }
604
+	/**
605
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
606
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
607
+	 */
608
+	protected function _registration_reports_js_setup()
609
+	{
610
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
611
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
612
+	}
613 613
 
614 614
 
615
-    /**
616
-     *        generates Business Reports regarding Registrations
617
-     *
618
-     * @access protected
619
-     * @return void
620
-     * @throws DomainException
621
-     */
622
-    protected function _registration_reports()
623
-    {
624
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
625
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
626
-            $template_path,
627
-            $this->_reports_template_data,
628
-            true
629
-        );
630
-        // the final template wrapper
631
-        $this->display_admin_page_with_no_sidebar();
632
-    }
615
+	/**
616
+	 *        generates Business Reports regarding Registrations
617
+	 *
618
+	 * @access protected
619
+	 * @return void
620
+	 * @throws DomainException
621
+	 */
622
+	protected function _registration_reports()
623
+	{
624
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
625
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
626
+			$template_path,
627
+			$this->_reports_template_data,
628
+			true
629
+		);
630
+		// the final template wrapper
631
+		$this->display_admin_page_with_no_sidebar();
632
+	}
633 633
 
634 634
 
635
-    /**
636
-     * Generates Business Report showing total registrations per day.
637
-     *
638
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
639
-     * @return string
640
-     * @throws EE_Error
641
-     * @throws InvalidArgumentException
642
-     * @throws InvalidDataTypeException
643
-     * @throws InvalidInterfaceException
644
-     */
645
-    private function _registrations_per_day_report($period = '-1 month')
646
-    {
647
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
648
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
649
-        $results = (array) $results;
650
-        $regs = array();
651
-        $subtitle = '';
652
-        if ($results) {
653
-            $column_titles = array();
654
-            $tracker = 0;
655
-            foreach ($results as $result) {
656
-                $report_column_values = array();
657
-                foreach ($result as $property_name => $property_value) {
658
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
659
-                        : (int) $property_value;
660
-                    $report_column_values[] = $property_value;
661
-                    if ($tracker === 0) {
662
-                        if ($property_name === 'Registration_REG_date') {
663
-                            $column_titles[] = esc_html__(
664
-                                'Date (only days with registrations are shown)',
665
-                                'event_espresso'
666
-                            );
667
-                        } else {
668
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
669
-                        }
670
-                    }
671
-                }
672
-                $tracker++;
673
-                $regs[] = $report_column_values;
674
-            }
675
-            // make sure the column_titles is pushed to the beginning of the array
676
-            array_unshift($regs, $column_titles);
677
-            // setup the date range.
678
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
679
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
680
-            $ending_date = new DateTime("now", $DateTimeZone);
681
-            $subtitle = sprintf(
682
-                wp_strip_all_tags(
683
-                    _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
684
-                ),
685
-                $beginning_date->format('Y-m-d'),
686
-                $ending_date->format('Y-m-d')
687
-            );
688
-        }
689
-        $report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso'));
690
-        $report_params = array(
691
-            'title'     => $report_title,
692
-            'subtitle'  => $subtitle,
693
-            'id'        => $report_ID,
694
-            'regs'      => $regs,
695
-            'noResults' => empty($regs),
696
-            'noRegsMsg' => sprintf(
697
-                wp_strip_all_tags(
698
-                    __(
699
-                        '%sThere are currently no registration records in the last month for this report.%s',
700
-                        'event_espresso'
701
-                    )
702
-                ),
703
-                '<h2>' . $report_title . '</h2><p>',
704
-                '</p>'
705
-            ),
706
-        );
707
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
708
-        return $report_ID;
709
-    }
635
+	/**
636
+	 * Generates Business Report showing total registrations per day.
637
+	 *
638
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
639
+	 * @return string
640
+	 * @throws EE_Error
641
+	 * @throws InvalidArgumentException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws InvalidInterfaceException
644
+	 */
645
+	private function _registrations_per_day_report($period = '-1 month')
646
+	{
647
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
648
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
649
+		$results = (array) $results;
650
+		$regs = array();
651
+		$subtitle = '';
652
+		if ($results) {
653
+			$column_titles = array();
654
+			$tracker = 0;
655
+			foreach ($results as $result) {
656
+				$report_column_values = array();
657
+				foreach ($result as $property_name => $property_value) {
658
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
659
+						: (int) $property_value;
660
+					$report_column_values[] = $property_value;
661
+					if ($tracker === 0) {
662
+						if ($property_name === 'Registration_REG_date') {
663
+							$column_titles[] = esc_html__(
664
+								'Date (only days with registrations are shown)',
665
+								'event_espresso'
666
+							);
667
+						} else {
668
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
669
+						}
670
+					}
671
+				}
672
+				$tracker++;
673
+				$regs[] = $report_column_values;
674
+			}
675
+			// make sure the column_titles is pushed to the beginning of the array
676
+			array_unshift($regs, $column_titles);
677
+			// setup the date range.
678
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
679
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
680
+			$ending_date = new DateTime("now", $DateTimeZone);
681
+			$subtitle = sprintf(
682
+				wp_strip_all_tags(
683
+					_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
684
+				),
685
+				$beginning_date->format('Y-m-d'),
686
+				$ending_date->format('Y-m-d')
687
+			);
688
+		}
689
+		$report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso'));
690
+		$report_params = array(
691
+			'title'     => $report_title,
692
+			'subtitle'  => $subtitle,
693
+			'id'        => $report_ID,
694
+			'regs'      => $regs,
695
+			'noResults' => empty($regs),
696
+			'noRegsMsg' => sprintf(
697
+				wp_strip_all_tags(
698
+					__(
699
+						'%sThere are currently no registration records in the last month for this report.%s',
700
+						'event_espresso'
701
+					)
702
+				),
703
+				'<h2>' . $report_title . '</h2><p>',
704
+				'</p>'
705
+			),
706
+		);
707
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
708
+		return $report_ID;
709
+	}
710 710
 
711 711
 
712
-    /**
713
-     * Generates Business Report showing total registrations per event.
714
-     *
715
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
716
-     * @return string
717
-     * @throws EE_Error
718
-     * @throws InvalidArgumentException
719
-     * @throws InvalidDataTypeException
720
-     * @throws InvalidInterfaceException
721
-     */
722
-    private function _registrations_per_event_report($period = '-1 month')
723
-    {
724
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
725
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
726
-        $results = (array) $results;
727
-        $regs = array();
728
-        $subtitle = '';
729
-        if ($results) {
730
-            $column_titles = array();
731
-            $tracker = 0;
732
-            foreach ($results as $result) {
733
-                $report_column_values = array();
734
-                foreach ($result as $property_name => $property_value) {
735
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
736
-                        $property_value,
737
-                        4,
738
-                        '...'
739
-                    ) : (int) $property_value;
740
-                    $report_column_values[] = $property_value;
741
-                    if ($tracker === 0) {
742
-                        if ($property_name === 'Registration_Event') {
743
-                            $column_titles[] = esc_html__('Event', 'event_espresso');
744
-                        } else {
745
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
746
-                        }
747
-                    }
748
-                }
749
-                $tracker++;
750
-                $regs[] = $report_column_values;
751
-            }
752
-            // make sure the column_titles is pushed to the beginning of the array
753
-            array_unshift($regs, $column_titles);
754
-            // setup the date range.
755
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
756
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
757
-            $ending_date = new DateTime("now", $DateTimeZone);
758
-            $subtitle = sprintf(
759
-                wp_strip_all_tags(
760
-                    _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
761
-                ),
762
-                $beginning_date->format('Y-m-d'),
763
-                $ending_date->format('Y-m-d')
764
-            );
765
-        }
766
-        $report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso'));
767
-        $report_params = array(
768
-            'title'     => $report_title,
769
-            'subtitle'  => $subtitle,
770
-            'id'        => $report_ID,
771
-            'regs'      => $regs,
772
-            'noResults' => empty($regs),
773
-            'noRegsMsg' => sprintf(
774
-                wp_strip_all_tags(
775
-                    __(
776
-                        '%sThere are currently no registration records in the last month for this report.%s',
777
-                        'event_espresso'
778
-                    )
779
-                ),
780
-                '<h2>' . $report_title . '</h2><p>',
781
-                '</p>'
782
-            ),
783
-        );
784
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
785
-        return $report_ID;
786
-    }
712
+	/**
713
+	 * Generates Business Report showing total registrations per event.
714
+	 *
715
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
716
+	 * @return string
717
+	 * @throws EE_Error
718
+	 * @throws InvalidArgumentException
719
+	 * @throws InvalidDataTypeException
720
+	 * @throws InvalidInterfaceException
721
+	 */
722
+	private function _registrations_per_event_report($period = '-1 month')
723
+	{
724
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
725
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
726
+		$results = (array) $results;
727
+		$regs = array();
728
+		$subtitle = '';
729
+		if ($results) {
730
+			$column_titles = array();
731
+			$tracker = 0;
732
+			foreach ($results as $result) {
733
+				$report_column_values = array();
734
+				foreach ($result as $property_name => $property_value) {
735
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
736
+						$property_value,
737
+						4,
738
+						'...'
739
+					) : (int) $property_value;
740
+					$report_column_values[] = $property_value;
741
+					if ($tracker === 0) {
742
+						if ($property_name === 'Registration_Event') {
743
+							$column_titles[] = esc_html__('Event', 'event_espresso');
744
+						} else {
745
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
746
+						}
747
+					}
748
+				}
749
+				$tracker++;
750
+				$regs[] = $report_column_values;
751
+			}
752
+			// make sure the column_titles is pushed to the beginning of the array
753
+			array_unshift($regs, $column_titles);
754
+			// setup the date range.
755
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
756
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
757
+			$ending_date = new DateTime("now", $DateTimeZone);
758
+			$subtitle = sprintf(
759
+				wp_strip_all_tags(
760
+					_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
761
+				),
762
+				$beginning_date->format('Y-m-d'),
763
+				$ending_date->format('Y-m-d')
764
+			);
765
+		}
766
+		$report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso'));
767
+		$report_params = array(
768
+			'title'     => $report_title,
769
+			'subtitle'  => $subtitle,
770
+			'id'        => $report_ID,
771
+			'regs'      => $regs,
772
+			'noResults' => empty($regs),
773
+			'noRegsMsg' => sprintf(
774
+				wp_strip_all_tags(
775
+					__(
776
+						'%sThere are currently no registration records in the last month for this report.%s',
777
+						'event_espresso'
778
+					)
779
+				),
780
+				'<h2>' . $report_title . '</h2><p>',
781
+				'</p>'
782
+			),
783
+		);
784
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
785
+		return $report_ID;
786
+	}
787 787
 
788 788
 
789
-    /**
790
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
791
-     *
792
-     * @access protected
793
-     * @return void
794
-     * @throws EE_Error
795
-     * @throws InvalidArgumentException
796
-     * @throws InvalidDataTypeException
797
-     * @throws InvalidInterfaceException
798
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
799
-     */
800
-    protected function _registration_checkin_list_table()
801
-    {
802
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
803
-        $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
804
-        /** @var EE_Registration $registration */
805
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
806
-        if (! $registration instanceof EE_Registration) {
807
-            throw new EE_Error(
808
-                sprintf(
809
-                    esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
810
-                    $reg_id
811
-                )
812
-            );
813
-        }
814
-        $attendee = $registration->attendee();
815
-        $this->_admin_page_title .= $this->get_action_link_or_button(
816
-            'new_registration',
817
-            'add-registrant',
818
-            array('event_id' => $registration->event_ID()),
819
-            'add-new-h2'
820
-        );
821
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
822
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
823
-        $legend_items = array(
824
-            'checkin'  => array(
825
-                'class' => $checked_in->cssClasses(),
826
-                'desc'  => $checked_in->legendLabel(),
827
-            ),
828
-            'checkout' => array(
829
-                'class' => $checked_out->cssClasses(),
830
-                'desc'  => $checked_out->legendLabel(),
831
-            ),
832
-        );
833
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
834
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
835
-        /** @var EE_Datetime $datetime */
836
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
837
-        $datetime_label = '';
838
-        if ($datetime instanceof EE_Datetime) {
839
-            $datetime_label = $datetime->get_dtt_display_name(true);
840
-            $datetime_label .= ! empty($datetime_label)
841
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
842
-                : $datetime->get_dtt_display_name();
843
-        }
844
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
845
-            ? EE_Admin_Page::add_query_args_and_nonce(
846
-                array(
847
-                    'action'   => 'event_registrations',
848
-                    'event_id' => $registration->event_ID(),
849
-                    'DTT_ID'   => $dtt_id,
850
-                ),
851
-                $this->_admin_base_url
852
-            )
853
-            : '';
854
-        $datetime_link = ! empty($datetime_link)
855
-            ? '<a href="' . $datetime_link . '">'
856
-              . '<span id="checkin-dtt">'
857
-              . $datetime_label
858
-              . '</span></a>'
859
-            : $datetime_label;
860
-        $attendee_name = $attendee instanceof EE_Attendee
861
-            ? $attendee->full_name()
862
-            : '';
863
-        $attendee_link = $attendee instanceof EE_Attendee
864
-            ? $attendee->get_admin_details_link()
865
-            : '';
866
-        $attendee_link = ! empty($attendee_link)
867
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
868
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
869
-              . '<span id="checkin-attendee-name">'
870
-              . $attendee_name
871
-              . '</span></a>'
872
-            : '';
873
-        $event_link = $registration->event() instanceof EE_Event
874
-            ? $registration->event()->get_admin_details_link()
875
-            : '';
876
-        $event_link = ! empty($event_link)
877
-            ? '<a href="' . $event_link . '"'
878
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
879
-              . '<span id="checkin-event-name">'
880
-              . $registration->event_name()
881
-              . '</span>'
882
-              . '</a>'
883
-            : '';
884
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
885
-            ? '<h2>' . sprintf(
886
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
887
-                $attendee_link,
888
-                $datetime_link,
889
-                $event_link
890
-            ) . '</h2>'
891
-            : '';
892
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
893
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
894
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
895
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
896
-        $this->display_admin_list_table_page_with_no_sidebar();
897
-    }
789
+	/**
790
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
791
+	 *
792
+	 * @access protected
793
+	 * @return void
794
+	 * @throws EE_Error
795
+	 * @throws InvalidArgumentException
796
+	 * @throws InvalidDataTypeException
797
+	 * @throws InvalidInterfaceException
798
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
799
+	 */
800
+	protected function _registration_checkin_list_table()
801
+	{
802
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
803
+		$reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
804
+		/** @var EE_Registration $registration */
805
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
806
+		if (! $registration instanceof EE_Registration) {
807
+			throw new EE_Error(
808
+				sprintf(
809
+					esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
810
+					$reg_id
811
+				)
812
+			);
813
+		}
814
+		$attendee = $registration->attendee();
815
+		$this->_admin_page_title .= $this->get_action_link_or_button(
816
+			'new_registration',
817
+			'add-registrant',
818
+			array('event_id' => $registration->event_ID()),
819
+			'add-new-h2'
820
+		);
821
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
822
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
823
+		$legend_items = array(
824
+			'checkin'  => array(
825
+				'class' => $checked_in->cssClasses(),
826
+				'desc'  => $checked_in->legendLabel(),
827
+			),
828
+			'checkout' => array(
829
+				'class' => $checked_out->cssClasses(),
830
+				'desc'  => $checked_out->legendLabel(),
831
+			),
832
+		);
833
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
834
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
835
+		/** @var EE_Datetime $datetime */
836
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
837
+		$datetime_label = '';
838
+		if ($datetime instanceof EE_Datetime) {
839
+			$datetime_label = $datetime->get_dtt_display_name(true);
840
+			$datetime_label .= ! empty($datetime_label)
841
+				? ' (' . $datetime->get_dtt_display_name() . ')'
842
+				: $datetime->get_dtt_display_name();
843
+		}
844
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
845
+			? EE_Admin_Page::add_query_args_and_nonce(
846
+				array(
847
+					'action'   => 'event_registrations',
848
+					'event_id' => $registration->event_ID(),
849
+					'DTT_ID'   => $dtt_id,
850
+				),
851
+				$this->_admin_base_url
852
+			)
853
+			: '';
854
+		$datetime_link = ! empty($datetime_link)
855
+			? '<a href="' . $datetime_link . '">'
856
+			  . '<span id="checkin-dtt">'
857
+			  . $datetime_label
858
+			  . '</span></a>'
859
+			: $datetime_label;
860
+		$attendee_name = $attendee instanceof EE_Attendee
861
+			? $attendee->full_name()
862
+			: '';
863
+		$attendee_link = $attendee instanceof EE_Attendee
864
+			? $attendee->get_admin_details_link()
865
+			: '';
866
+		$attendee_link = ! empty($attendee_link)
867
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
868
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
869
+			  . '<span id="checkin-attendee-name">'
870
+			  . $attendee_name
871
+			  . '</span></a>'
872
+			: '';
873
+		$event_link = $registration->event() instanceof EE_Event
874
+			? $registration->event()->get_admin_details_link()
875
+			: '';
876
+		$event_link = ! empty($event_link)
877
+			? '<a href="' . $event_link . '"'
878
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
879
+			  . '<span id="checkin-event-name">'
880
+			  . $registration->event_name()
881
+			  . '</span>'
882
+			  . '</a>'
883
+			: '';
884
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
885
+			? '<h2>' . sprintf(
886
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
887
+				$attendee_link,
888
+				$datetime_link,
889
+				$event_link
890
+			) . '</h2>'
891
+			: '';
892
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
893
+			? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
894
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
895
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
896
+		$this->display_admin_list_table_page_with_no_sidebar();
897
+	}
898 898
 
899 899
 
900
-    /**
901
-     * toggle the Check-in status for the given registration (coming from ajax)
902
-     *
903
-     * @return void (JSON)
904
-     * @throws EE_Error
905
-     * @throws InvalidArgumentException
906
-     * @throws InvalidDataTypeException
907
-     * @throws InvalidInterfaceException
908
-     */
909
-    public function toggle_checkin_status()
910
-    {
911
-        // first make sure we have the necessary data
912
-        if (! isset($this->_req_data['_regid'])) {
913
-            EE_Error::add_error(
914
-                esc_html__(
915
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
916
-                    'event_espresso'
917
-                ),
918
-                __FILE__,
919
-                __FUNCTION__,
920
-                __LINE__
921
-            );
922
-            $this->_template_args['success'] = false;
923
-            $this->_template_args['error'] = true;
924
-            $this->_return_json();
925
-        };
926
-        // do a nonce check cause we're not coming in from an normal route here.
927
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
928
-            : '';
929
-        $nonce_ref = 'checkin_nonce';
930
-        $this->_verify_nonce($nonce, $nonce_ref);
931
-        // beautiful! Made it this far so let's get the status.
932
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
933
-        // setup new class to return via ajax
934
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
935
-        $this->_template_args['success'] = true;
936
-        $this->_return_json();
937
-    }
900
+	/**
901
+	 * toggle the Check-in status for the given registration (coming from ajax)
902
+	 *
903
+	 * @return void (JSON)
904
+	 * @throws EE_Error
905
+	 * @throws InvalidArgumentException
906
+	 * @throws InvalidDataTypeException
907
+	 * @throws InvalidInterfaceException
908
+	 */
909
+	public function toggle_checkin_status()
910
+	{
911
+		// first make sure we have the necessary data
912
+		if (! isset($this->_req_data['_regid'])) {
913
+			EE_Error::add_error(
914
+				esc_html__(
915
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
916
+					'event_espresso'
917
+				),
918
+				__FILE__,
919
+				__FUNCTION__,
920
+				__LINE__
921
+			);
922
+			$this->_template_args['success'] = false;
923
+			$this->_template_args['error'] = true;
924
+			$this->_return_json();
925
+		};
926
+		// do a nonce check cause we're not coming in from an normal route here.
927
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
928
+			: '';
929
+		$nonce_ref = 'checkin_nonce';
930
+		$this->_verify_nonce($nonce, $nonce_ref);
931
+		// beautiful! Made it this far so let's get the status.
932
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
933
+		// setup new class to return via ajax
934
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
935
+		$this->_template_args['success'] = true;
936
+		$this->_return_json();
937
+	}
938 938
 
939 939
 
940
-    /**
941
-     * handles toggling the checkin status for the registration,
942
-     *
943
-     * @access protected
944
-     * @return int|void
945
-     * @throws EE_Error
946
-     * @throws InvalidArgumentException
947
-     * @throws InvalidDataTypeException
948
-     * @throws InvalidInterfaceException
949
-     */
950
-    protected function _toggle_checkin_status()
951
-    {
952
-        // first let's get the query args out of the way for the redirect
953
-        $query_args = array(
954
-            'action'   => 'event_registrations',
955
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
956
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
957
-        );
958
-        $new_status = false;
959
-        // bulk action check in toggle
960
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
961
-            // cycle thru checkboxes
962
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
963
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
964
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
965
-            }
966
-        } elseif (isset($this->_req_data['_regid'])) {
967
-            // coming from ajax request
968
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
969
-            $query_args['DTT_ID'] = $DTT_ID;
970
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
971
-        } else {
972
-            EE_Error::add_error(
973
-                esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
974
-                __FILE__,
975
-                __FUNCTION__,
976
-                __LINE__
977
-            );
978
-        }
979
-        if (defined('DOING_AJAX')) {
980
-            return $new_status;
981
-        }
982
-        $this->_redirect_after_action(false, '', '', $query_args, true);
983
-    }
940
+	/**
941
+	 * handles toggling the checkin status for the registration,
942
+	 *
943
+	 * @access protected
944
+	 * @return int|void
945
+	 * @throws EE_Error
946
+	 * @throws InvalidArgumentException
947
+	 * @throws InvalidDataTypeException
948
+	 * @throws InvalidInterfaceException
949
+	 */
950
+	protected function _toggle_checkin_status()
951
+	{
952
+		// first let's get the query args out of the way for the redirect
953
+		$query_args = array(
954
+			'action'   => 'event_registrations',
955
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
956
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
957
+		);
958
+		$new_status = false;
959
+		// bulk action check in toggle
960
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
961
+			// cycle thru checkboxes
962
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
963
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
964
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
965
+			}
966
+		} elseif (isset($this->_req_data['_regid'])) {
967
+			// coming from ajax request
968
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
969
+			$query_args['DTT_ID'] = $DTT_ID;
970
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
971
+		} else {
972
+			EE_Error::add_error(
973
+				esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
974
+				__FILE__,
975
+				__FUNCTION__,
976
+				__LINE__
977
+			);
978
+		}
979
+		if (defined('DOING_AJAX')) {
980
+			return $new_status;
981
+		}
982
+		$this->_redirect_after_action(false, '', '', $query_args, true);
983
+	}
984 984
 
985 985
 
986
-    /**
987
-     * This is toggles a single Check-in for the given registration and datetime.
988
-     *
989
-     * @param  int $REG_ID The registration we're toggling
990
-     * @param  int $DTT_ID The datetime we're toggling
991
-     * @return int The new status toggled to.
992
-     * @throws EE_Error
993
-     * @throws InvalidArgumentException
994
-     * @throws InvalidDataTypeException
995
-     * @throws InvalidInterfaceException
996
-     */
997
-    private function _toggle_checkin($REG_ID, $DTT_ID)
998
-    {
999
-        /** @var EE_Registration $REG */
1000
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1001
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
1002
-        if ($new_status !== false) {
1003
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
1004
-        } else {
1005
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1006
-            $new_status = false;
1007
-        }
1008
-        return $new_status;
1009
-    }
986
+	/**
987
+	 * This is toggles a single Check-in for the given registration and datetime.
988
+	 *
989
+	 * @param  int $REG_ID The registration we're toggling
990
+	 * @param  int $DTT_ID The datetime we're toggling
991
+	 * @return int The new status toggled to.
992
+	 * @throws EE_Error
993
+	 * @throws InvalidArgumentException
994
+	 * @throws InvalidDataTypeException
995
+	 * @throws InvalidInterfaceException
996
+	 */
997
+	private function _toggle_checkin($REG_ID, $DTT_ID)
998
+	{
999
+		/** @var EE_Registration $REG */
1000
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1001
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
1002
+		if ($new_status !== false) {
1003
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
1004
+		} else {
1005
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1006
+			$new_status = false;
1007
+		}
1008
+		return $new_status;
1009
+	}
1010 1010
 
1011 1011
 
1012
-    /**
1013
-     * Takes care of deleting multiple EE_Checkin table rows
1014
-     *
1015
-     * @access protected
1016
-     * @return void
1017
-     * @throws EE_Error
1018
-     * @throws InvalidArgumentException
1019
-     * @throws InvalidDataTypeException
1020
-     * @throws InvalidInterfaceException
1021
-     */
1022
-    protected function _delete_checkin_rows()
1023
-    {
1024
-        $query_args = array(
1025
-            'action'  => 'registration_checkins',
1026
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1027
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1028
-        );
1029
-        $errors = 0;
1030
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1031
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1032
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1033
-                    $errors++;
1034
-                }
1035
-            }
1036
-        } else {
1037
-            EE_Error::add_error(
1038
-                esc_html__(
1039
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1040
-                    'event_espresso'
1041
-                ),
1042
-                __FILE__,
1043
-                __FUNCTION__,
1044
-                __LINE__
1045
-            );
1046
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1047
-        }
1048
-        if ($errors > 0) {
1049
-            EE_Error::add_error(
1050
-                sprintf(esc_html__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1051
-                __FILE__,
1052
-                __FUNCTION__,
1053
-                __LINE__
1054
-            );
1055
-        } else {
1056
-            EE_Error::add_success(esc_html__('Records were successfully deleted', 'event_espresso'));
1057
-        }
1058
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1059
-    }
1012
+	/**
1013
+	 * Takes care of deleting multiple EE_Checkin table rows
1014
+	 *
1015
+	 * @access protected
1016
+	 * @return void
1017
+	 * @throws EE_Error
1018
+	 * @throws InvalidArgumentException
1019
+	 * @throws InvalidDataTypeException
1020
+	 * @throws InvalidInterfaceException
1021
+	 */
1022
+	protected function _delete_checkin_rows()
1023
+	{
1024
+		$query_args = array(
1025
+			'action'  => 'registration_checkins',
1026
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1027
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1028
+		);
1029
+		$errors = 0;
1030
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1031
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1032
+				if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1033
+					$errors++;
1034
+				}
1035
+			}
1036
+		} else {
1037
+			EE_Error::add_error(
1038
+				esc_html__(
1039
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1040
+					'event_espresso'
1041
+				),
1042
+				__FILE__,
1043
+				__FUNCTION__,
1044
+				__LINE__
1045
+			);
1046
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1047
+		}
1048
+		if ($errors > 0) {
1049
+			EE_Error::add_error(
1050
+				sprintf(esc_html__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1051
+				__FILE__,
1052
+				__FUNCTION__,
1053
+				__LINE__
1054
+			);
1055
+		} else {
1056
+			EE_Error::add_success(esc_html__('Records were successfully deleted', 'event_espresso'));
1057
+		}
1058
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1059
+	}
1060 1060
 
1061 1061
 
1062
-    /**
1063
-     * Deletes a single EE_Checkin row
1064
-     *
1065
-     * @return void
1066
-     * @throws EE_Error
1067
-     * @throws InvalidArgumentException
1068
-     * @throws InvalidDataTypeException
1069
-     * @throws InvalidInterfaceException
1070
-     */
1071
-    protected function _delete_checkin_row()
1072
-    {
1073
-        $query_args = array(
1074
-            'action'  => 'registration_checkins',
1075
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1076
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1077
-        );
1078
-        if (! empty($this->_req_data['CHK_ID'])) {
1079
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1080
-                EE_Error::add_error(
1081
-                    esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1082
-                    __FILE__,
1083
-                    __FUNCTION__,
1084
-                    __LINE__
1085
-                );
1086
-            } else {
1087
-                EE_Error::add_success(esc_html__('Check-In record successfully deleted', 'event_espresso'));
1088
-            }
1089
-        } else {
1090
-            EE_Error::add_error(
1091
-                esc_html__(
1092
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1093
-                    'event_espresso'
1094
-                ),
1095
-                __FILE__,
1096
-                __FUNCTION__,
1097
-                __LINE__
1098
-            );
1099
-        }
1100
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1101
-    }
1062
+	/**
1063
+	 * Deletes a single EE_Checkin row
1064
+	 *
1065
+	 * @return void
1066
+	 * @throws EE_Error
1067
+	 * @throws InvalidArgumentException
1068
+	 * @throws InvalidDataTypeException
1069
+	 * @throws InvalidInterfaceException
1070
+	 */
1071
+	protected function _delete_checkin_row()
1072
+	{
1073
+		$query_args = array(
1074
+			'action'  => 'registration_checkins',
1075
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1076
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1077
+		);
1078
+		if (! empty($this->_req_data['CHK_ID'])) {
1079
+			if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1080
+				EE_Error::add_error(
1081
+					esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1082
+					__FILE__,
1083
+					__FUNCTION__,
1084
+					__LINE__
1085
+				);
1086
+			} else {
1087
+				EE_Error::add_success(esc_html__('Check-In record successfully deleted', 'event_espresso'));
1088
+			}
1089
+		} else {
1090
+			EE_Error::add_error(
1091
+				esc_html__(
1092
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1093
+					'event_espresso'
1094
+				),
1095
+				__FILE__,
1096
+				__FUNCTION__,
1097
+				__LINE__
1098
+			);
1099
+		}
1100
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1101
+	}
1102 1102
 
1103 1103
 
1104
-    /**
1105
-     *        generates HTML for the Event Registrations List Table
1106
-     *
1107
-     * @access protected
1108
-     * @return void
1109
-     * @throws EE_Error
1110
-     * @throws InvalidArgumentException
1111
-     * @throws InvalidDataTypeException
1112
-     * @throws InvalidInterfaceException
1113
-     */
1114
-    protected function _event_registrations_list_table()
1115
-    {
1116
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1117
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1118
-            ? $this->get_action_link_or_button(
1119
-                'new_registration',
1120
-                'add-registrant',
1121
-                array('event_id' => $this->_req_data['event_id']),
1122
-                'add-new-h2',
1123
-                '',
1124
-                false
1125
-            )
1126
-            : '';
1127
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1128
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1129
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1130
-        $legend_items = array(
1131
-            'star-icon'        => array(
1132
-                'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1133
-                'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1134
-            ),
1135
-            'checkin'          => array(
1136
-                'class' => $checked_in->cssClasses(),
1137
-                'desc'  => $checked_in->legendLabel(),
1138
-            ),
1139
-            'checkout'         => array(
1140
-                'class' => $checked_out->cssClasses(),
1141
-                'desc'  => $checked_out->legendLabel(),
1142
-            ),
1143
-            'nocheckinrecord'  => array(
1144
-                'class' => $checked_never->cssClasses(),
1145
-                'desc'  => $checked_never->legendLabel(),
1146
-            ),
1147
-            'approved_status'  => array(
1148
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1149
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1150
-            ),
1151
-            'cancelled_status' => array(
1152
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1153
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1154
-            ),
1155
-            'declined_status'  => array(
1156
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1157
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1158
-            ),
1159
-            'not_approved'     => array(
1160
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1161
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1162
-            ),
1163
-            'pending_status'   => array(
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1165
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1166
-            ),
1167
-            'wait_list'        => array(
1168
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1169
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1170
-            ),
1171
-        );
1172
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1173
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1174
-        /** @var EE_Event $event */
1175
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1176
-        $this->_template_args['before_list_table'] = $event instanceof EE_Event
1177
-            ? '<h2>' . sprintf(
1178
-                esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1179
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1180
-            ) . '</h2>'
1181
-            : '';
1182
-        // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1183
-        // the event.
1184
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1185
-        $datetime = null;
1186
-        if ($event instanceof EE_Event) {
1187
-            $datetimes_on_event = $event->datetimes();
1188
-            if (count($datetimes_on_event) === 1) {
1189
-                $datetime = reset($datetimes_on_event);
1190
-            }
1191
-        }
1192
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1193
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1194
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1195
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1196
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1197
-            $this->_template_args['before_list_table'] .= $datetime->name();
1198
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1199
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1200
-        }
1201
-        // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1202
-        // column represents
1203
-        if (! $datetime instanceof EE_Datetime) {
1204
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1205
-                                                          . esc_html__(
1206
-                                                              'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1207
-                                                              'event_espresso'
1208
-                                                          )
1209
-                                                          . '</p>';
1210
-        }
1211
-        $this->display_admin_list_table_page_with_no_sidebar();
1212
-    }
1104
+	/**
1105
+	 *        generates HTML for the Event Registrations List Table
1106
+	 *
1107
+	 * @access protected
1108
+	 * @return void
1109
+	 * @throws EE_Error
1110
+	 * @throws InvalidArgumentException
1111
+	 * @throws InvalidDataTypeException
1112
+	 * @throws InvalidInterfaceException
1113
+	 */
1114
+	protected function _event_registrations_list_table()
1115
+	{
1116
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1117
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1118
+			? $this->get_action_link_or_button(
1119
+				'new_registration',
1120
+				'add-registrant',
1121
+				array('event_id' => $this->_req_data['event_id']),
1122
+				'add-new-h2',
1123
+				'',
1124
+				false
1125
+			)
1126
+			: '';
1127
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1128
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1129
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1130
+		$legend_items = array(
1131
+			'star-icon'        => array(
1132
+				'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1133
+				'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1134
+			),
1135
+			'checkin'          => array(
1136
+				'class' => $checked_in->cssClasses(),
1137
+				'desc'  => $checked_in->legendLabel(),
1138
+			),
1139
+			'checkout'         => array(
1140
+				'class' => $checked_out->cssClasses(),
1141
+				'desc'  => $checked_out->legendLabel(),
1142
+			),
1143
+			'nocheckinrecord'  => array(
1144
+				'class' => $checked_never->cssClasses(),
1145
+				'desc'  => $checked_never->legendLabel(),
1146
+			),
1147
+			'approved_status'  => array(
1148
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1149
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1150
+			),
1151
+			'cancelled_status' => array(
1152
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1153
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1154
+			),
1155
+			'declined_status'  => array(
1156
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1157
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1158
+			),
1159
+			'not_approved'     => array(
1160
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1161
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1162
+			),
1163
+			'pending_status'   => array(
1164
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1165
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1166
+			),
1167
+			'wait_list'        => array(
1168
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1169
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1170
+			),
1171
+		);
1172
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1173
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1174
+		/** @var EE_Event $event */
1175
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1176
+		$this->_template_args['before_list_table'] = $event instanceof EE_Event
1177
+			? '<h2>' . sprintf(
1178
+				esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1179
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1180
+			) . '</h2>'
1181
+			: '';
1182
+		// need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1183
+		// the event.
1184
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1185
+		$datetime = null;
1186
+		if ($event instanceof EE_Event) {
1187
+			$datetimes_on_event = $event->datetimes();
1188
+			if (count($datetimes_on_event) === 1) {
1189
+				$datetime = reset($datetimes_on_event);
1190
+			}
1191
+		}
1192
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1193
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1194
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1195
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1196
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1197
+			$this->_template_args['before_list_table'] .= $datetime->name();
1198
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1199
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1200
+		}
1201
+		// if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1202
+		// column represents
1203
+		if (! $datetime instanceof EE_Datetime) {
1204
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1205
+														  . esc_html__(
1206
+															  'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1207
+															  'event_espresso'
1208
+														  )
1209
+														  . '</p>';
1210
+		}
1211
+		$this->display_admin_list_table_page_with_no_sidebar();
1212
+	}
1213 1213
 
1214
-    /**
1215
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1216
-     * conditions)
1217
-     *
1218
-     * @return void ends the request by a redirect or download
1219
-     */
1220
-    public function _registrations_checkin_report()
1221
-    {
1222
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1223
-    }
1214
+	/**
1215
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1216
+	 * conditions)
1217
+	 *
1218
+	 * @return void ends the request by a redirect or download
1219
+	 */
1220
+	public function _registrations_checkin_report()
1221
+	{
1222
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1223
+	}
1224 1224
 
1225
-    /**
1226
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1227
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1228
-     *
1229
-     * @param array $request
1230
-     * @param int   $per_page
1231
-     * @param bool  $count
1232
-     * @return array
1233
-     * @throws EE_Error
1234
-     */
1235
-    protected function _get_checkin_query_params_from_request(
1236
-        $request,
1237
-        $per_page = 10,
1238
-        $count = false
1239
-    ) {
1240
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1241
-        // unlike the regular registrations list table,
1242
-        $status_ids_array = apply_filters(
1243
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1244
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1245
-        );
1246
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1247
-        return $query_params;
1248
-    }
1225
+	/**
1226
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1227
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1228
+	 *
1229
+	 * @param array $request
1230
+	 * @param int   $per_page
1231
+	 * @param bool  $count
1232
+	 * @return array
1233
+	 * @throws EE_Error
1234
+	 */
1235
+	protected function _get_checkin_query_params_from_request(
1236
+		$request,
1237
+		$per_page = 10,
1238
+		$count = false
1239
+	) {
1240
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1241
+		// unlike the regular registrations list table,
1242
+		$status_ids_array = apply_filters(
1243
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1244
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1245
+		);
1246
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1247
+		return $query_params;
1248
+	}
1249 1249
 
1250 1250
 
1251
-    /**
1252
-     * Gets registrations for an event
1253
-     *
1254
-     * @param int    $per_page
1255
-     * @param bool   $count whether to return count or data.
1256
-     * @param bool   $trash
1257
-     * @param string $orderby
1258
-     * @return EE_Registration[]|int
1259
-     * @throws EE_Error
1260
-     * @throws InvalidArgumentException
1261
-     * @throws InvalidDataTypeException
1262
-     * @throws InvalidInterfaceException
1263
-     */
1264
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1265
-    {
1266
-        // normalize some request params that get setup by the parent `get_registrations` method.
1267
-        $request = $this->_req_data;
1268
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1269
-        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1270
-        if ($trash) {
1271
-            $request['status'] = 'trash';
1272
-        }
1273
-        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1274
-        /**
1275
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1276
-         *
1277
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1278
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1279
-         *                             or if you have the development copy of EE you can view this at the path:
1280
-         *                             /docs/G--Model-System/model-query-params.md
1281
-         */
1282
-        $query_params['group_by'] = '';
1251
+	/**
1252
+	 * Gets registrations for an event
1253
+	 *
1254
+	 * @param int    $per_page
1255
+	 * @param bool   $count whether to return count or data.
1256
+	 * @param bool   $trash
1257
+	 * @param string $orderby
1258
+	 * @return EE_Registration[]|int
1259
+	 * @throws EE_Error
1260
+	 * @throws InvalidArgumentException
1261
+	 * @throws InvalidDataTypeException
1262
+	 * @throws InvalidInterfaceException
1263
+	 */
1264
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1265
+	{
1266
+		// normalize some request params that get setup by the parent `get_registrations` method.
1267
+		$request = $this->_req_data;
1268
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1269
+		$request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1270
+		if ($trash) {
1271
+			$request['status'] = 'trash';
1272
+		}
1273
+		$query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1274
+		/**
1275
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1276
+		 *
1277
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1278
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1279
+		 *                             or if you have the development copy of EE you can view this at the path:
1280
+		 *                             /docs/G--Model-System/model-query-params.md
1281
+		 */
1282
+		$query_params['group_by'] = '';
1283 1283
 
1284
-        return $count
1285
-            ? EEM_Registration::instance()->count($query_params)
1286
-            /** @type EE_Registration[] */
1287
-            : EEM_Registration::instance()->get_all($query_params);
1288
-    }
1284
+		return $count
1285
+			? EEM_Registration::instance()->count($query_params)
1286
+			/** @type EE_Registration[] */
1287
+			: EEM_Registration::instance()->get_all($query_params);
1288
+	}
1289 1289
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 2 patches
Indentation   +1388 added lines, -1388 removed lines patch added patch discarded remove patch
@@ -16,1392 +16,1392 @@
 block discarded – undo
16 16
 class Extend_Events_Admin_Page extends Events_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Admin_Config
21
-     */
22
-    protected $admin_config;
23
-
24
-    /**
25
-     * @var AdvancedEditorAdminFormSection
26
-     */
27
-    protected $advanced_editor_admin_form;
28
-
29
-
30
-    /**
31
-     * Extend_Events_Admin_Page constructor.
32
-     *
33
-     * @param bool $routing
34
-     * @throws EE_Error
35
-     * @throws ReflectionException
36
-     */
37
-    public function __construct($routing = true)
38
-    {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
-        }
44
-        parent::__construct($routing);
45
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
-    }
47
-
48
-
49
-    /**
50
-     * Sets routes.
51
-     *
52
-     * @throws EE_Error
53
-     */
54
-    protected function _extend_page_config()
55
-    {
56
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
57
-        // is there a evt_id in the request?
58
-        $EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59
-        $EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
60
-        $TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
61
-        $new_page_routes    = [
62
-            'duplicate_event'          => [
63
-                'func'       => '_duplicate_event',
64
-                'capability' => 'ee_edit_event',
65
-                'obj_id'     => $EVT_ID,
66
-                'noheader'   => true,
67
-            ],
68
-            'import_page'              => [
69
-                'func'       => '_import_page',
70
-                'capability' => 'import',
71
-            ],
72
-            'import'                   => [
73
-                'func'       => '_import_events',
74
-                'capability' => 'import',
75
-                'noheader'   => true,
76
-            ],
77
-            'import_events'            => [
78
-                'func'       => '_import_events',
79
-                'capability' => 'import',
80
-                'noheader'   => true,
81
-            ],
82
-            'export_events'            => [
83
-                'func'       => '_events_export',
84
-                'capability' => 'export',
85
-                'noheader'   => true,
86
-            ],
87
-            'export_categories'        => [
88
-                'func'       => '_categories_export',
89
-                'capability' => 'export',
90
-                'noheader'   => true,
91
-            ],
92
-            'sample_export_file'       => [
93
-                'func'       => '_sample_export_file',
94
-                'capability' => 'export',
95
-                'noheader'   => true,
96
-            ],
97
-            'update_template_settings' => [
98
-                'func'       => '_update_template_settings',
99
-                'capability' => 'manage_options',
100
-                'noheader'   => true,
101
-            ],
102
-            'ticket_list_table'        => [
103
-                'func'       => '_tickets_overview_list_table',
104
-                'capability' => 'ee_read_default_tickets',
105
-            ],
106
-        ];
107
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
108
-        $this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
109
-        // don't load these meta boxes if using the advanced editor
110
-        if (
111
-            ! $this->admin_config->useAdvancedEditor()
112
-            || ! $this->feature->allowed('use_default_ticket_manager')
113
-        ) {
114
-            $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
115
-            $this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
116
-
117
-            $legacy_editor_page_routes = [
118
-                'trash_ticket'    => [
119
-                    'func'       => '_trash_or_restore_ticket',
120
-                    'capability' => 'ee_delete_default_ticket',
121
-                    'obj_id'     => $TKT_ID,
122
-                    'noheader'   => true,
123
-                    'args'       => ['trash' => true],
124
-                ],
125
-                'trash_tickets'   => [
126
-                    'func'       => '_trash_or_restore_ticket',
127
-                    'capability' => 'ee_delete_default_tickets',
128
-                    'noheader'   => true,
129
-                    'args'       => ['trash' => true],
130
-                ],
131
-                'restore_ticket'  => [
132
-                    'func'       => '_trash_or_restore_ticket',
133
-                    'capability' => 'ee_delete_default_ticket',
134
-                    'obj_id'     => $TKT_ID,
135
-                    'noheader'   => true,
136
-                ],
137
-                'restore_tickets' => [
138
-                    'func'       => '_trash_or_restore_ticket',
139
-                    'capability' => 'ee_delete_default_tickets',
140
-                    'noheader'   => true,
141
-                ],
142
-                'delete_ticket'   => [
143
-                    'func'       => '_delete_ticket',
144
-                    'capability' => 'ee_delete_default_ticket',
145
-                    'obj_id'     => $TKT_ID,
146
-                    'noheader'   => true,
147
-                ],
148
-                'delete_tickets'  => [
149
-                    'func'       => '_delete_ticket',
150
-                    'capability' => 'ee_delete_default_tickets',
151
-                    'noheader'   => true,
152
-                ],
153
-            ];
154
-            $new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
155
-        }
156
-
157
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
158
-        // partial route/config override
159
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
160
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
161
-        // add tickets tab but only if there are more than one default ticket!
162
-        $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
163
-            [['TKT_is_default' => 1]],
164
-            'TKT_ID',
165
-            true
166
-        );
167
-        if ($ticket_count > 1) {
168
-            $new_page_config = [
169
-                'ticket_list_table' => [
170
-                    'nav'           => [
171
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
172
-                        'order' => 60,
173
-                    ],
174
-                    'list_table'    => 'Tickets_List_Table',
175
-                    'require_nonce' => false,
176
-                ],
177
-            ];
178
-        }
179
-        // template settings
180
-        $new_page_config['template_settings'] = [
181
-            'nav'           => [
182
-                'label' => esc_html__('Templates', 'event_espresso'),
183
-                'order' => 30,
184
-            ],
185
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
-            'help_tabs'     => [
187
-                'general_settings_templates_help_tab' => [
188
-                    'title'    => esc_html__('Templates', 'event_espresso'),
189
-                    'filename' => 'general_settings_templates',
190
-                ],
191
-            ],
192
-            'require_nonce' => false,
193
-        ];
194
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
195
-        // add filters and actions
196
-        // modifying _views
197
-        add_filter(
198
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
199
-            [$this, 'add_additional_datetime_button'],
200
-            10,
201
-            2
202
-        );
203
-        add_filter(
204
-            'FHEE_event_datetime_metabox_clone_button_template',
205
-            [$this, 'add_datetime_clone_button'],
206
-            10,
207
-            2
208
-        );
209
-        add_filter(
210
-            'FHEE_event_datetime_metabox_timezones_template',
211
-            [$this, 'datetime_timezones_template'],
212
-            10,
213
-            2
214
-        );
215
-        // filters for event list table
216
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
217
-        add_filter(
218
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
219
-            [$this, 'extra_list_table_actions'],
220
-            10,
221
-            2
222
-        );
223
-        // legend item
224
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
225
-        add_action('admin_init', [$this, 'admin_init']);
226
-        // load additional handlers
227
-        $this->handleActionRequest();
228
-    }
229
-
230
-
231
-    private function getRequestAction()
232
-    {
233
-        return $this->request->getRequestParam('action');
234
-    }
235
-
236
-
237
-    /**
238
-     * @throws Exception
239
-     */
240
-    private function handleActionRequest()
241
-    {
242
-        $action = $this->getRequestAction();
243
-        if ($action) {
244
-            // setup Advanced Editor ???
245
-            if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
246
-                $this->advanced_editor_admin_form = $this->loader->getShared(
247
-                    'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
248
-                );
249
-            }
250
-        }
251
-    }
252
-
253
-
254
-    /**
255
-     * admin_init
256
-     */
257
-    public function admin_init()
258
-    {
259
-        EE_Registry::$i18n_js_strings = array_merge(
260
-            EE_Registry::$i18n_js_strings,
261
-            [
262
-                'image_confirm'          => esc_html__(
263
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
264
-                    'event_espresso'
265
-                ),
266
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
267
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
268
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
269
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
270
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
271
-            ]
272
-        );
273
-    }
274
-
275
-
276
-    /**
277
-     * Add per page screen options to the default ticket list table view.
278
-     *
279
-     * @throws InvalidArgumentException
280
-     * @throws InvalidDataTypeException
281
-     * @throws InvalidInterfaceException
282
-     */
283
-    protected function _add_screen_options_ticket_list_table()
284
-    {
285
-        $this->_per_page_screen_option();
286
-    }
287
-
288
-
289
-    /**
290
-     * @param string $return
291
-     * @param int    $id
292
-     * @param string $new_title
293
-     * @param string $new_slug
294
-     * @return string
295
-     */
296
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
297
-    {
298
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
299
-        // make sure this is only when editing
300
-        if (! empty($id)) {
301
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
302
-                ['action' => 'duplicate_event', 'EVT_ID' => $id],
303
-                $this->_admin_base_url
304
-            );
305
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
306
-            $return .= '<a href="'
307
-                       . $href
308
-                       . '" title="'
309
-                       . $title
310
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
311
-                       . $title
312
-                       . '</a>';
313
-        }
314
-        return $return;
315
-    }
316
-
317
-
318
-    /**
319
-     * Set the list table views for the default ticket list table view.
320
-     */
321
-    public function _set_list_table_views_ticket_list_table()
322
-    {
323
-        $this->_views = [
324
-            'all'     => [
325
-                'slug'        => 'all',
326
-                'label'       => esc_html__('All', 'event_espresso'),
327
-                'count'       => 0,
328
-                'bulk_action' => [
329
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
330
-                ],
331
-            ],
332
-            'trashed' => [
333
-                'slug'        => 'trashed',
334
-                'label'       => esc_html__('Trash', 'event_espresso'),
335
-                'count'       => 0,
336
-                'bulk_action' => [
337
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
338
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
339
-                ],
340
-            ],
341
-        ];
342
-    }
343
-
344
-
345
-    /**
346
-     * Enqueue scripts and styles for the event editor.
347
-     */
348
-    public function load_scripts_styles_edit()
349
-    {
350
-        if (! $this->admin_config->useAdvancedEditor()) {
351
-            wp_register_script(
352
-                'ee-event-editor-heartbeat',
353
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
354
-                ['ee_admin_js', 'heartbeat'],
355
-                EVENT_ESPRESSO_VERSION,
356
-                true
357
-            );
358
-            wp_enqueue_script('ee-accounting');
359
-            wp_enqueue_script('ee-event-editor-heartbeat');
360
-        }
361
-        wp_enqueue_script('event_editor_js');
362
-        // styles
363
-        wp_enqueue_style('espresso-ui-theme');
364
-    }
365
-
366
-
367
-    /**
368
-     * Returns template for the additional datetime.
369
-     *
370
-     * @param string $template
371
-     * @param array  $template_args
372
-     * @return string
373
-     * @throws DomainException
374
-     */
375
-    public function add_additional_datetime_button($template, $template_args)
376
-    {
377
-        return EEH_Template::display_template(
378
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
379
-            $template_args,
380
-            true
381
-        );
382
-    }
383
-
384
-
385
-    /**
386
-     * Returns the template for cloning a datetime.
387
-     *
388
-     * @param $template
389
-     * @param $template_args
390
-     * @return string
391
-     * @throws DomainException
392
-     */
393
-    public function add_datetime_clone_button($template, $template_args)
394
-    {
395
-        return EEH_Template::display_template(
396
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
397
-            $template_args,
398
-            true
399
-        );
400
-    }
401
-
402
-
403
-    /**
404
-     * Returns the template for datetime timezones.
405
-     *
406
-     * @param $template
407
-     * @param $template_args
408
-     * @return string
409
-     * @throws DomainException
410
-     */
411
-    public function datetime_timezones_template($template, $template_args)
412
-    {
413
-        return EEH_Template::display_template(
414
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
415
-            $template_args,
416
-            true
417
-        );
418
-    }
419
-
420
-
421
-    /**
422
-     * Sets the views for the default list table view.
423
-     *
424
-     * @throws EE_Error
425
-     */
426
-    protected function _set_list_table_views_default()
427
-    {
428
-        parent::_set_list_table_views_default();
429
-        $new_views    = [
430
-            'today' => [
431
-                'slug'        => 'today',
432
-                'label'       => esc_html__('Today', 'event_espresso'),
433
-                'count'       => $this->total_events_today(),
434
-                'bulk_action' => [
435
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
436
-                ],
437
-            ],
438
-            'month' => [
439
-                'slug'        => 'month',
440
-                'label'       => esc_html__('This Month', 'event_espresso'),
441
-                'count'       => $this->total_events_this_month(),
442
-                'bulk_action' => [
443
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
444
-                ],
445
-            ],
446
-        ];
447
-        $this->_views = array_merge($this->_views, $new_views);
448
-    }
449
-
450
-
451
-    /**
452
-     * Returns the extra action links for the default list table view.
453
-     *
454
-     * @param array    $action_links
455
-     * @param EE_Event $event
456
-     * @return array
457
-     * @throws EE_Error
458
-     * @throws ReflectionException
459
-     */
460
-    public function extra_list_table_actions(array $action_links, EE_Event $event)
461
-    {
462
-        if (
463
-            EE_Registry::instance()->CAP->current_user_can(
464
-                'ee_read_registrations',
465
-                'espresso_registrations_reports',
466
-                $event->ID()
467
-            )
468
-        ) {
469
-            $reports_query_args = [
470
-                'action' => 'reports',
471
-                'EVT_ID' => $event->ID(),
472
-            ];
473
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
474
-            $action_links[]     = '<a href="'
475
-                                  . $reports_link
476
-                                  . '" title="'
477
-                                  . esc_attr__('View Report', 'event_espresso')
478
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
479
-                                  . "\n\t";
480
-        }
481
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
482
-            EE_Registry::instance()->load_helper('MSG_Template');
483
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
484
-                'see_notifications_for',
485
-                null,
486
-                ['EVT_ID' => $event->ID()]
487
-            );
488
-        }
489
-        return $action_links;
490
-    }
491
-
492
-
493
-    /**
494
-     * @param $items
495
-     * @return mixed
496
-     */
497
-    public function additional_legend_items($items)
498
-    {
499
-        if (
500
-            EE_Registry::instance()->CAP->current_user_can(
501
-                'ee_read_registrations',
502
-                'espresso_registrations_reports'
503
-            )
504
-        ) {
505
-            $items['reports'] = [
506
-                'class' => 'dashicons dashicons-chart-bar',
507
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
508
-            ];
509
-        }
510
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
511
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
512
-            // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
513
-            // (can only use numeric offsets when treating strings as arrays)
514
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
515
-                $items['view_related_messages'] = [
516
-                    'class' => $related_for_icon['css_class'],
517
-                    'desc'  => $related_for_icon['label'],
518
-                ];
519
-            }
520
-        }
521
-        return $items;
522
-    }
523
-
524
-
525
-    /**
526
-     * This is the callback method for the duplicate event route
527
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
528
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
529
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
530
-     * After duplication the redirect is to the new event edit page.
531
-     *
532
-     * @return void
533
-     * @throws EE_Error If EE_Event is not available with given ID
534
-     * @throws ReflectionException
535
-     * @access protected
536
-     */
537
-    protected function _duplicate_event()
538
-    {
539
-        // first make sure the ID for the event is in the request.
540
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
541
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
542
-        if (! $EVT_ID) {
543
-            EE_Error::add_error(
544
-                esc_html__(
545
-                    'In order to duplicate an event an Event ID is required.  None was given.',
546
-                    'event_espresso'
547
-                ),
548
-                __FILE__,
549
-                __FUNCTION__,
550
-                __LINE__
551
-            );
552
-            $this->_redirect_after_action(false, '', '', [], true);
553
-            return;
554
-        }
555
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
556
-        $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
557
-        if (! $orig_event instanceof EE_Event) {
558
-            throw new EE_Error(
559
-                sprintf(
560
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
561
-                    $EVT_ID
562
-                )
563
-            );
564
-        }
565
-        // k now let's clone the $orig_event before getting relations
566
-        $new_event = clone $orig_event;
567
-        // original datetimes
568
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
569
-        // other original relations
570
-        $orig_ven = $orig_event->get_many_related('Venue');
571
-        // reset the ID and modify other details to make it clear this is a dupe
572
-        $new_event->set('EVT_ID', 0);
573
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
574
-        $new_event->set('EVT_name', $new_name);
575
-        $new_event->set(
576
-            'EVT_slug',
577
-            wp_unique_post_slug(
578
-                sanitize_title($orig_event->name()),
579
-                0,
580
-                'publish',
581
-                'espresso_events',
582
-                0
583
-            )
584
-        );
585
-        $new_event->set('status', 'draft');
586
-        // duplicate discussion settings
587
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
588
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
589
-        // save the new event
590
-        $new_event->save();
591
-        // venues
592
-        foreach ($orig_ven as $ven) {
593
-            $new_event->_add_relation_to($ven, 'Venue');
594
-        }
595
-        $new_event->save();
596
-        // now we need to get the question group relations and handle that
597
-        // first primary question groups
598
-        $orig_primary_qgs = $orig_event->get_many_related(
599
-            'Question_Group',
600
-            [['Event_Question_Group.EQG_primary' => true]]
601
-        );
602
-        if (! empty($orig_primary_qgs)) {
603
-            foreach ($orig_primary_qgs as $obj) {
604
-                if ($obj instanceof EE_Question_Group) {
605
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
606
-                }
607
-            }
608
-        }
609
-        // next additional attendee question groups
610
-        $orig_additional_qgs = $orig_event->get_many_related(
611
-            'Question_Group',
612
-            [['Event_Question_Group.EQG_additional' => true]]
613
-        );
614
-        if (! empty($orig_additional_qgs)) {
615
-            foreach ($orig_additional_qgs as $obj) {
616
-                if ($obj instanceof EE_Question_Group) {
617
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
618
-                }
619
-            }
620
-        }
621
-
622
-        $new_event->save();
623
-
624
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
625
-        $cloned_tickets = [];
626
-        foreach ($orig_datetimes as $orig_dtt) {
627
-            if (! $orig_dtt instanceof EE_Datetime) {
628
-                continue;
629
-            }
630
-            $new_dtt      = clone $orig_dtt;
631
-            $orig_tickets = $orig_dtt->tickets();
632
-            // save new dtt then add to event
633
-            $new_dtt->set('DTT_ID', 0);
634
-            $new_dtt->set('DTT_sold', 0);
635
-            $new_dtt->set_reserved(0);
636
-            $new_dtt->save();
637
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
638
-            $new_event->save();
639
-            // now let's get the ticket relations setup.
640
-            foreach ((array) $orig_tickets as $orig_ticket) {
641
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
642
-                if (! $orig_ticket instanceof EE_Ticket) {
643
-                    continue;
644
-                }
645
-                // is this ticket archived?  If it is then let's skip
646
-                if ($orig_ticket->get('TKT_deleted')) {
647
-                    continue;
648
-                }
649
-                // does this original ticket already exist in the clone_tickets cache?
650
-                //  If so we'll just use the new ticket from it.
651
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
652
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
653
-                } else {
654
-                    $new_ticket = clone $orig_ticket;
655
-                    // get relations on the $orig_ticket that we need to setup.
656
-                    $orig_prices = $orig_ticket->prices();
657
-                    $new_ticket->set('TKT_ID', 0);
658
-                    $new_ticket->set('TKT_sold', 0);
659
-                    $new_ticket->set('TKT_reserved', 0);
660
-                    $new_ticket->save(); // make sure new ticket has ID.
661
-                    // price relations on new ticket need to be setup.
662
-                    foreach ($orig_prices as $orig_price) {
663
-                        $new_price = clone $orig_price;
664
-                        $new_price->set('PRC_ID', 0);
665
-                        $new_price->save();
666
-                        $new_ticket->_add_relation_to($new_price, 'Price');
667
-                        $new_ticket->save();
668
-                    }
669
-
670
-                    do_action(
671
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
672
-                        $orig_ticket,
673
-                        $new_ticket,
674
-                        $orig_prices,
675
-                        $orig_event,
676
-                        $orig_dtt,
677
-                        $new_dtt
678
-                    );
679
-                }
680
-                // k now we can add the new ticket as a relation to the new datetime
681
-                // and make sure its added to our cached $cloned_tickets array
682
-                // for use with later datetimes that have the same ticket.
683
-                $new_dtt->_add_relation_to($new_ticket, 'Ticket');
684
-                $new_dtt->save();
685
-                $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
686
-            }
687
-        }
688
-        // clone taxonomy information
689
-        $taxonomies_to_clone_with = apply_filters(
690
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
691
-            ['espresso_event_categories', 'espresso_event_type', 'post_tag']
692
-        );
693
-        // get terms for original event (notice)
694
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
695
-        // loop through terms and add them to new event.
696
-        foreach ($orig_terms as $term) {
697
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
698
-        }
699
-
700
-        // duplicate other core WP_Post items for this event.
701
-        // post thumbnail (feature image).
702
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
703
-        if ($feature_image_id) {
704
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
705
-        }
706
-
707
-        // duplicate page_template setting
708
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
709
-        if ($page_template) {
710
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
711
-        }
712
-
713
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
714
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
715
-        if ($new_event->ID()) {
716
-            $redirect_args = [
717
-                'post'   => $new_event->ID(),
718
-                'action' => 'edit',
719
-            ];
720
-            EE_Error::add_success(
721
-                esc_html__(
722
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
723
-                    'event_espresso'
724
-                )
725
-            );
726
-        } else {
727
-            $redirect_args = [
728
-                'action' => 'default',
729
-            ];
730
-            EE_Error::add_error(
731
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
732
-                __FILE__,
733
-                __FUNCTION__,
734
-                __LINE__
735
-            );
736
-        }
737
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
738
-    }
739
-
740
-
741
-    /**
742
-     * Generates output for the import page.
743
-     *
744
-     * @throws EE_Error
745
-     */
746
-    protected function _import_page()
747
-    {
748
-        $title                                      = esc_html__('Import', 'event_espresso');
749
-        $intro                                      = esc_html__(
750
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
751
-            'event_espresso'
752
-        );
753
-
754
-        $form_url = EVENTS_ADMIN_URL;
755
-        $action   = 'import_events';
756
-        $type     = 'csv';
757
-
758
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
759
-            $title,
760
-            $intro,
761
-            $form_url,
762
-            $action,
763
-            $type
764
-        );
765
-
766
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
767
-            ['action' => 'sample_export_file'],
768
-            $this->_admin_base_url
769
-        );
770
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
771
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
772
-            $this->_template_args,
773
-            true
774
-        );
775
-        $this->display_admin_page_with_sidebar();
776
-    }
777
-
778
-
779
-    /**
780
-     * _import_events
781
-     * This handles displaying the screen and running imports for importing events.
782
-     *
783
-     * @return void
784
-     * @throws EE_Error
785
-     */
786
-    protected function _import_events()
787
-    {
788
-        require_once(EE_CLASSES . 'EE_Import.class.php');
789
-        $success = EE_Import::instance()->import();
790
-        $this->_redirect_after_action(
791
-            $success,
792
-            esc_html__('Import File', 'event_espresso'),
793
-            'ran',
794
-            ['action' => 'import_page'],
795
-            true
796
-        );
797
-    }
798
-
799
-
800
-    /**
801
-     * _events_export
802
-     * Will export all (or just the given event) to a Excel compatible file.
803
-     *
804
-     * @access protected
805
-     * @return void
806
-     */
807
-    protected function _events_export()
808
-    {
809
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
810
-        $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
811
-        $this->request->mergeRequestParams(
812
-            [
813
-                'export' => 'report',
814
-                'action' => 'all_event_data',
815
-                'EVT_ID' => $EVT_ID,
816
-            ]
817
-        );
818
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
819
-            require_once(EE_CLASSES . 'EE_Export.class.php');
820
-            $EE_Export = EE_Export::instance($this->request->requestParams());
821
-            $EE_Export->export();
822
-        }
823
-    }
824
-
825
-
826
-    /**
827
-     * handle category exports()
828
-     *
829
-     * @return void
830
-     */
831
-    protected function _categories_export()
832
-    {
833
-        $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
834
-        $this->request->mergeRequestParams(
835
-            [
836
-                'export' => 'report',
837
-                'action' => 'categories',
838
-                'EVT_ID' => $EVT_ID,
839
-            ]
840
-        );
841
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
842
-            require_once(EE_CLASSES . 'EE_Export.class.php');
843
-            $EE_Export = EE_Export::instance($this->request->requestParams());
844
-            $EE_Export->export();
845
-        }
846
-    }
847
-
848
-
849
-    /**
850
-     * Creates a sample CSV file for importing
851
-     */
852
-    protected function _sample_export_file()
853
-    {
854
-        $EE_Export = EE_Export::instance();
855
-        if ($EE_Export instanceof EE_Export) {
856
-            $EE_Export->export();
857
-        }
858
-    }
859
-
860
-
861
-    /*************        Template Settings        *************/
862
-    /**
863
-     * Generates template settings page output
864
-     *
865
-     * @throws DomainException
866
-     * @throws EE_Error
867
-     * @throws InvalidArgumentException
868
-     * @throws InvalidDataTypeException
869
-     * @throws InvalidInterfaceException
870
-     */
871
-    protected function _template_settings()
872
-    {
873
-        $this->_template_args['values'] = $this->_yes_no_values;
874
-        /**
875
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
876
-         * from General_Settings_Admin_Page to here.
877
-         */
878
-        $this->_template_args = apply_filters(
879
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
880
-            $this->_template_args
881
-        );
882
-        $this->_set_add_edit_form_tags('update_template_settings');
883
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
884
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
885
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
886
-            $this->_template_args,
887
-            true
888
-        );
889
-        $this->display_admin_page_with_sidebar();
890
-    }
891
-
892
-
893
-    /**
894
-     * Handler for updating template settings.
895
-     *
896
-     * @throws EE_Error
897
-     */
898
-    protected function _update_template_settings()
899
-    {
900
-        /**
901
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
902
-         * from General_Settings_Admin_Page to here.
903
-         */
904
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
905
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
906
-            EE_Registry::instance()->CFG->template_settings,
907
-            $this->request->requestParams()
908
-        );
909
-        // update custom post type slugs and detect if we need to flush rewrite rules
910
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
911
-
912
-        $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
913
-
914
-        EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
915
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
916
-            : EEH_URL::slugify($event_cpt_slug, 'events');
917
-
918
-        $what    = esc_html__('Template Settings', 'event_espresso');
919
-        $success = $this->_update_espresso_configuration(
920
-            $what,
921
-            EE_Registry::instance()->CFG->template_settings,
922
-            __FILE__,
923
-            __FUNCTION__,
924
-            __LINE__
925
-        );
926
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
927
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
928
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
929
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
930
-            );
931
-            $rewrite_rules->flush();
932
-        }
933
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
934
-    }
935
-
936
-
937
-    /**
938
-     * _premium_event_editor_meta_boxes
939
-     * add all metaboxes related to the event_editor
940
-     *
941
-     * @access protected
942
-     * @return void
943
-     * @throws EE_Error
944
-     * @throws ReflectionException
945
-     */
946
-    protected function _premium_event_editor_meta_boxes()
947
-    {
948
-        $this->verify_cpt_object();
949
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
950
-        if (
951
-            ! $this->admin_config->useAdvancedEditor()
952
-            || ! $this->feature->allowed('use_reg_options_meta_box')
953
-        ) {
954
-            add_meta_box(
955
-                'espresso_event_editor_event_options',
956
-                esc_html__('Event Registration Options', 'event_espresso'),
957
-                [$this, 'registration_options_meta_box'],
958
-                $this->page_slug,
959
-                'side',
960
-                'core'
961
-            );
962
-        }
963
-    }
964
-
965
-
966
-    /**
967
-     * override caf metabox
968
-     *
969
-     * @return void
970
-     * @throws EE_Error
971
-     * @throws ReflectionException
972
-     */
973
-    public function registration_options_meta_box()
974
-    {
975
-        $yes_no_values = [
976
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
977
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
978
-        ];
979
-
980
-        $default_reg_status_values = EEM_Registration::reg_status_array(
981
-            [
982
-                EEM_Registration::status_id_cancelled,
983
-                EEM_Registration::status_id_declined,
984
-                EEM_Registration::status_id_incomplete,
985
-                EEM_Registration::status_id_wait_list,
986
-            ],
987
-            true
988
-        );
989
-
990
-        $template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
991
-        $template_args['_event']           = $this->_cpt_model_obj;
992
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
993
-
994
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
995
-            'default_reg_status',
996
-            $default_reg_status_values,
997
-            $this->_cpt_model_obj->default_registration_status()
998
-        );
999
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1000
-            'display_desc',
1001
-            $yes_no_values,
1002
-            $this->_cpt_model_obj->display_description()
1003
-        );
1004
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1005
-            'display_ticket_selector',
1006
-            $yes_no_values,
1007
-            $this->_cpt_model_obj->display_ticket_selector(),
1008
-            '',
1009
-            '',
1010
-            false
1011
-        );
1012
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1013
-            'EVT_default_registration_status',
1014
-            $default_reg_status_values,
1015
-            $this->_cpt_model_obj->default_registration_status()
1016
-        );
1017
-        $template_args['additional_registration_options'] = apply_filters(
1018
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1019
-            '',
1020
-            $template_args,
1021
-            $yes_no_values,
1022
-            $default_reg_status_values
1023
-        );
1024
-        EEH_Template::display_template(
1025
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1026
-            $template_args
1027
-        );
1028
-    }
1029
-
1030
-
1031
-
1032
-    /**
1033
-     * wp_list_table_mods for caf
1034
-     * ============================
1035
-     */
1036
-    /**
1037
-     * hook into list table filters and provide filters for caffeinated list table
1038
-     *
1039
-     * @param array $old_filters    any existing filters present
1040
-     * @param array $list_table_obj the list table object
1041
-     * @return array                  new filters
1042
-     * @throws EE_Error
1043
-     * @throws ReflectionException
1044
-     */
1045
-    public function list_table_filters($old_filters, $list_table_obj)
1046
-    {
1047
-        $filters = [];
1048
-        // first month/year filters
1049
-        $filters[] = $this->espresso_event_months_dropdown();
1050
-        $status    = $this->request->getRequestParam('status');
1051
-        // active status dropdown
1052
-        if ($status !== 'draft') {
1053
-            $filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
1054
-            $filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
1055
-        }
1056
-        // category filter
1057
-        $filters[] = $this->category_dropdown();
1058
-        return array_merge($old_filters, $filters);
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * espresso_event_months_dropdown
1064
-     *
1065
-     * @access public
1066
-     * @return string                dropdown listing month/year selections for events.
1067
-     * @throws EE_Error
1068
-     */
1069
-    public function espresso_event_months_dropdown()
1070
-    {
1071
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1072
-        // Note we need to include any other filters that are set!
1073
-        return EEH_Form_Fields::generate_event_months_dropdown(
1074
-            $this->request->getRequestParam('month_range'),
1075
-            $this->request->getRequestParam('status'),
1076
-            $this->request->getRequestParam('EVT_CAT', 0, 'int'),
1077
-            $this->request->getRequestParam('active_status')
1078
-        );
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * returns a list of "active" statuses on the event
1084
-     *
1085
-     * @param string $current_value whatever the current active status is
1086
-     * @return string
1087
-     */
1088
-    public function active_status_dropdown($current_value = '')
1089
-    {
1090
-        $select_name = 'active_status';
1091
-        $values      = [
1092
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1093
-            'active'   => esc_html__('Active', 'event_espresso'),
1094
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1095
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1096
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1097
-        ];
1098
-
1099
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * returns a list of "venues"
1105
-     *
1106
-     * @param string $current_value whatever the current active status is
1107
-     * @return string
1108
-     * @throws EE_Error
1109
-     * @throws ReflectionException
1110
-     */
1111
-    protected function venuesDropdown($current_value = '')
1112
-    {
1113
-        $values = ['' => esc_html__('All Venues', 'event_espresso')];
1114
-        // populate the list of venues.
1115
-        $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1116
-
1117
-        foreach ($venues as $venue) {
1118
-            $values[ $venue->ID() ] = $venue->name();
1119
-        }
1120
-
1121
-        return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1122
-    }
1123
-
1124
-
1125
-    /**
1126
-     * output a dropdown of the categories for the category filter on the event admin list table
1127
-     *
1128
-     * @access  public
1129
-     * @return string html
1130
-     * @throws EE_Error
1131
-     * @throws ReflectionException
1132
-     */
1133
-    public function category_dropdown()
1134
-    {
1135
-        return EEH_Form_Fields::generate_event_category_dropdown(
1136
-            $this->request->getRequestParam('EVT_CAT', -1, 'int')
1137
-        );
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * get total number of events today
1143
-     *
1144
-     * @access public
1145
-     * @return int
1146
-     * @throws EE_Error
1147
-     * @throws InvalidArgumentException
1148
-     * @throws InvalidDataTypeException
1149
-     * @throws InvalidInterfaceException
1150
-     */
1151
-    public function total_events_today()
1152
-    {
1153
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1154
-            'DTT_EVT_start',
1155
-            date('Y-m-d') . ' 00:00:00',
1156
-            'Y-m-d H:i:s',
1157
-            'UTC'
1158
-        );
1159
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1160
-            'DTT_EVT_start',
1161
-            date('Y-m-d') . ' 23:59:59',
1162
-            'Y-m-d H:i:s',
1163
-            'UTC'
1164
-        );
1165
-        $where = [
1166
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1167
-        ];
1168
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1169
-    }
1170
-
1171
-
1172
-    /**
1173
-     * get total number of events this month
1174
-     *
1175
-     * @access public
1176
-     * @return int
1177
-     * @throws EE_Error
1178
-     * @throws InvalidArgumentException
1179
-     * @throws InvalidDataTypeException
1180
-     * @throws InvalidInterfaceException
1181
-     */
1182
-    public function total_events_this_month()
1183
-    {
1184
-        // Dates
1185
-        $this_year_r     = date('Y');
1186
-        $this_month_r    = date('m');
1187
-        $days_this_month = date('t');
1188
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1189
-            'DTT_EVT_start',
1190
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1191
-            'Y-m-d H:i:s',
1192
-            'UTC'
1193
-        );
1194
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1195
-            'DTT_EVT_start',
1196
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1197
-            'Y-m-d H:i:s',
1198
-            'UTC'
1199
-        );
1200
-        $where           = [
1201
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1202
-        ];
1203
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1204
-    }
1205
-
1206
-
1207
-    /** DEFAULT TICKETS STUFF **/
1208
-
1209
-    /**
1210
-     * Output default tickets list table view.
1211
-     *
1212
-     * @throws EE_Error
1213
-     */
1214
-    public function _tickets_overview_list_table()
1215
-    {
1216
-        if (
1217
-            $this->admin_config->useAdvancedEditor()
1218
-            && $this->feature->allowed('use_default_ticket_manager')
1219
-        ) {
1220
-            // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1221
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1222
-                EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1223
-                [],
1224
-                true
1225
-            );
1226
-            $this->display_admin_page_with_no_sidebar();
1227
-        } else {
1228
-            $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1229
-            $this->display_admin_list_table_page_with_no_sidebar();
1230
-        }
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     * @param int  $per_page
1236
-     * @param bool $count
1237
-     * @param bool $trashed
1238
-     * @return EE_Soft_Delete_Base_Class[]|int
1239
-     * @throws EE_Error
1240
-     */
1241
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1242
-    {
1243
-        $orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1244
-        $order   = $this->request->getRequestParam('order', 'ASC');
1245
-        switch ($orderby) {
1246
-            case 'TKT_name':
1247
-                $orderby = ['TKT_name' => $order];
1248
-                break;
1249
-            case 'TKT_price':
1250
-                $orderby = ['TKT_price' => $order];
1251
-                break;
1252
-            case 'TKT_uses':
1253
-                $orderby = ['TKT_uses' => $order];
1254
-                break;
1255
-            case 'TKT_min':
1256
-                $orderby = ['TKT_min' => $order];
1257
-                break;
1258
-            case 'TKT_max':
1259
-                $orderby = ['TKT_max' => $order];
1260
-                break;
1261
-            case 'TKT_qty':
1262
-                $orderby = ['TKT_qty' => $order];
1263
-                break;
1264
-        }
1265
-
1266
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1267
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1268
-        $offset       = ($current_page - 1) * $per_page;
1269
-
1270
-        $where = [
1271
-            'TKT_is_default' => 1,
1272
-            'TKT_deleted'    => $trashed,
1273
-        ];
1274
-
1275
-        $search_term = $this->request->getRequestParam('s');
1276
-        if ($search_term) {
1277
-            $search_term = '%' . $search_term . '%';
1278
-            $where['OR'] = [
1279
-                'TKT_name'        => ['LIKE', $search_term],
1280
-                'TKT_description' => ['LIKE', $search_term],
1281
-            ];
1282
-        }
1283
-
1284
-        return $count
1285
-            ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1286
-            : EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1287
-                [
1288
-                    $where,
1289
-                    'order_by' => $orderby,
1290
-                    'limit'    => [$offset, $per_page],
1291
-                    'group_by' => 'TKT_ID',
1292
-                ]
1293
-            );
1294
-    }
1295
-
1296
-
1297
-    /**
1298
-     * @param bool $trash
1299
-     * @throws EE_Error
1300
-     * @throws InvalidArgumentException
1301
-     * @throws InvalidDataTypeException
1302
-     * @throws InvalidInterfaceException
1303
-     */
1304
-    protected function _trash_or_restore_ticket($trash = false)
1305
-    {
1306
-        $success = 1;
1307
-        $TKT     = EEM_Ticket::instance();
1308
-        // checkboxes?
1309
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1310
-        if (! empty($checkboxes)) {
1311
-            // if array has more than one element then success message should be plural
1312
-            $success = count($checkboxes) > 1 ? 2 : 1;
1313
-            // cycle thru the boxes
1314
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1315
-                if ($trash) {
1316
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1317
-                        $success = 0;
1318
-                    }
1319
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1320
-                    $success = 0;
1321
-                }
1322
-            }
1323
-        } else {
1324
-            // grab single id and trash
1325
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1326
-            if ($trash) {
1327
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1328
-                    $success = 0;
1329
-                }
1330
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1331
-                $success = 0;
1332
-            }
1333
-        }
1334
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1335
-        $query_args  = [
1336
-            'action' => 'ticket_list_table',
1337
-            'status' => $trash ? '' : 'trashed',
1338
-        ];
1339
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1340
-    }
1341
-
1342
-
1343
-    /**
1344
-     * Handles trashing default ticket.
1345
-     *
1346
-     * @throws EE_Error
1347
-     * @throws ReflectionException
1348
-     */
1349
-    protected function _delete_ticket()
1350
-    {
1351
-        $success = 1;
1352
-        // checkboxes?
1353
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1354
-        if (! empty($checkboxes)) {
1355
-            // if array has more than one element then success message should be plural
1356
-            $success = count($checkboxes) > 1 ? 2 : 1;
1357
-            // cycle thru the boxes
1358
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1359
-                // delete
1360
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1361
-                    $success = 0;
1362
-                }
1363
-            }
1364
-        } else {
1365
-            // grab single id and trash
1366
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1367
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1368
-                $success = 0;
1369
-            }
1370
-        }
1371
-        $action_desc = 'deleted';
1372
-        $query_args  = [
1373
-            'action' => 'ticket_list_table',
1374
-            'status' => 'trashed',
1375
-        ];
1376
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1377
-        if (
1378
-            EEM_Ticket::instance()->count_deleted_and_undeleted(
1379
-                [['TKT_is_default' => 1]],
1380
-                'TKT_ID',
1381
-                true
1382
-            )
1383
-        ) {
1384
-            $query_args = [];
1385
-        }
1386
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * @param int $TKT_ID
1392
-     * @return bool|int
1393
-     * @throws EE_Error
1394
-     * @throws ReflectionException
1395
-     */
1396
-    protected function _delete_the_ticket($TKT_ID)
1397
-    {
1398
-        $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1399
-        if (! $ticket instanceof EE_Ticket) {
1400
-            return false;
1401
-        }
1402
-        $ticket->_remove_relations('Datetime');
1403
-        // delete all related prices first
1404
-        $ticket->delete_related_permanently('Price');
1405
-        return $ticket->delete_permanently();
1406
-    }
19
+	/**
20
+	 * @var EE_Admin_Config
21
+	 */
22
+	protected $admin_config;
23
+
24
+	/**
25
+	 * @var AdvancedEditorAdminFormSection
26
+	 */
27
+	protected $advanced_editor_admin_form;
28
+
29
+
30
+	/**
31
+	 * Extend_Events_Admin_Page constructor.
32
+	 *
33
+	 * @param bool $routing
34
+	 * @throws EE_Error
35
+	 * @throws ReflectionException
36
+	 */
37
+	public function __construct($routing = true)
38
+	{
39
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
+		}
44
+		parent::__construct($routing);
45
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
+	}
47
+
48
+
49
+	/**
50
+	 * Sets routes.
51
+	 *
52
+	 * @throws EE_Error
53
+	 */
54
+	protected function _extend_page_config()
55
+	{
56
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
57
+		// is there a evt_id in the request?
58
+		$EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59
+		$EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
60
+		$TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
61
+		$new_page_routes    = [
62
+			'duplicate_event'          => [
63
+				'func'       => '_duplicate_event',
64
+				'capability' => 'ee_edit_event',
65
+				'obj_id'     => $EVT_ID,
66
+				'noheader'   => true,
67
+			],
68
+			'import_page'              => [
69
+				'func'       => '_import_page',
70
+				'capability' => 'import',
71
+			],
72
+			'import'                   => [
73
+				'func'       => '_import_events',
74
+				'capability' => 'import',
75
+				'noheader'   => true,
76
+			],
77
+			'import_events'            => [
78
+				'func'       => '_import_events',
79
+				'capability' => 'import',
80
+				'noheader'   => true,
81
+			],
82
+			'export_events'            => [
83
+				'func'       => '_events_export',
84
+				'capability' => 'export',
85
+				'noheader'   => true,
86
+			],
87
+			'export_categories'        => [
88
+				'func'       => '_categories_export',
89
+				'capability' => 'export',
90
+				'noheader'   => true,
91
+			],
92
+			'sample_export_file'       => [
93
+				'func'       => '_sample_export_file',
94
+				'capability' => 'export',
95
+				'noheader'   => true,
96
+			],
97
+			'update_template_settings' => [
98
+				'func'       => '_update_template_settings',
99
+				'capability' => 'manage_options',
100
+				'noheader'   => true,
101
+			],
102
+			'ticket_list_table'        => [
103
+				'func'       => '_tickets_overview_list_table',
104
+				'capability' => 'ee_read_default_tickets',
105
+			],
106
+		];
107
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
108
+		$this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
109
+		// don't load these meta boxes if using the advanced editor
110
+		if (
111
+			! $this->admin_config->useAdvancedEditor()
112
+			|| ! $this->feature->allowed('use_default_ticket_manager')
113
+		) {
114
+			$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
115
+			$this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
116
+
117
+			$legacy_editor_page_routes = [
118
+				'trash_ticket'    => [
119
+					'func'       => '_trash_or_restore_ticket',
120
+					'capability' => 'ee_delete_default_ticket',
121
+					'obj_id'     => $TKT_ID,
122
+					'noheader'   => true,
123
+					'args'       => ['trash' => true],
124
+				],
125
+				'trash_tickets'   => [
126
+					'func'       => '_trash_or_restore_ticket',
127
+					'capability' => 'ee_delete_default_tickets',
128
+					'noheader'   => true,
129
+					'args'       => ['trash' => true],
130
+				],
131
+				'restore_ticket'  => [
132
+					'func'       => '_trash_or_restore_ticket',
133
+					'capability' => 'ee_delete_default_ticket',
134
+					'obj_id'     => $TKT_ID,
135
+					'noheader'   => true,
136
+				],
137
+				'restore_tickets' => [
138
+					'func'       => '_trash_or_restore_ticket',
139
+					'capability' => 'ee_delete_default_tickets',
140
+					'noheader'   => true,
141
+				],
142
+				'delete_ticket'   => [
143
+					'func'       => '_delete_ticket',
144
+					'capability' => 'ee_delete_default_ticket',
145
+					'obj_id'     => $TKT_ID,
146
+					'noheader'   => true,
147
+				],
148
+				'delete_tickets'  => [
149
+					'func'       => '_delete_ticket',
150
+					'capability' => 'ee_delete_default_tickets',
151
+					'noheader'   => true,
152
+				],
153
+			];
154
+			$new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
155
+		}
156
+
157
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
158
+		// partial route/config override
159
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
160
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
161
+		// add tickets tab but only if there are more than one default ticket!
162
+		$ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
163
+			[['TKT_is_default' => 1]],
164
+			'TKT_ID',
165
+			true
166
+		);
167
+		if ($ticket_count > 1) {
168
+			$new_page_config = [
169
+				'ticket_list_table' => [
170
+					'nav'           => [
171
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
172
+						'order' => 60,
173
+					],
174
+					'list_table'    => 'Tickets_List_Table',
175
+					'require_nonce' => false,
176
+				],
177
+			];
178
+		}
179
+		// template settings
180
+		$new_page_config['template_settings'] = [
181
+			'nav'           => [
182
+				'label' => esc_html__('Templates', 'event_espresso'),
183
+				'order' => 30,
184
+			],
185
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
+			'help_tabs'     => [
187
+				'general_settings_templates_help_tab' => [
188
+					'title'    => esc_html__('Templates', 'event_espresso'),
189
+					'filename' => 'general_settings_templates',
190
+				],
191
+			],
192
+			'require_nonce' => false,
193
+		];
194
+		$this->_page_config                   = array_merge($this->_page_config, $new_page_config);
195
+		// add filters and actions
196
+		// modifying _views
197
+		add_filter(
198
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
199
+			[$this, 'add_additional_datetime_button'],
200
+			10,
201
+			2
202
+		);
203
+		add_filter(
204
+			'FHEE_event_datetime_metabox_clone_button_template',
205
+			[$this, 'add_datetime_clone_button'],
206
+			10,
207
+			2
208
+		);
209
+		add_filter(
210
+			'FHEE_event_datetime_metabox_timezones_template',
211
+			[$this, 'datetime_timezones_template'],
212
+			10,
213
+			2
214
+		);
215
+		// filters for event list table
216
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
217
+		add_filter(
218
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
219
+			[$this, 'extra_list_table_actions'],
220
+			10,
221
+			2
222
+		);
223
+		// legend item
224
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
225
+		add_action('admin_init', [$this, 'admin_init']);
226
+		// load additional handlers
227
+		$this->handleActionRequest();
228
+	}
229
+
230
+
231
+	private function getRequestAction()
232
+	{
233
+		return $this->request->getRequestParam('action');
234
+	}
235
+
236
+
237
+	/**
238
+	 * @throws Exception
239
+	 */
240
+	private function handleActionRequest()
241
+	{
242
+		$action = $this->getRequestAction();
243
+		if ($action) {
244
+			// setup Advanced Editor ???
245
+			if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
246
+				$this->advanced_editor_admin_form = $this->loader->getShared(
247
+					'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
248
+				);
249
+			}
250
+		}
251
+	}
252
+
253
+
254
+	/**
255
+	 * admin_init
256
+	 */
257
+	public function admin_init()
258
+	{
259
+		EE_Registry::$i18n_js_strings = array_merge(
260
+			EE_Registry::$i18n_js_strings,
261
+			[
262
+				'image_confirm'          => esc_html__(
263
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
264
+					'event_espresso'
265
+				),
266
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
267
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
268
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
269
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
270
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
271
+			]
272
+		);
273
+	}
274
+
275
+
276
+	/**
277
+	 * Add per page screen options to the default ticket list table view.
278
+	 *
279
+	 * @throws InvalidArgumentException
280
+	 * @throws InvalidDataTypeException
281
+	 * @throws InvalidInterfaceException
282
+	 */
283
+	protected function _add_screen_options_ticket_list_table()
284
+	{
285
+		$this->_per_page_screen_option();
286
+	}
287
+
288
+
289
+	/**
290
+	 * @param string $return
291
+	 * @param int    $id
292
+	 * @param string $new_title
293
+	 * @param string $new_slug
294
+	 * @return string
295
+	 */
296
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
297
+	{
298
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
299
+		// make sure this is only when editing
300
+		if (! empty($id)) {
301
+			$href   = EE_Admin_Page::add_query_args_and_nonce(
302
+				['action' => 'duplicate_event', 'EVT_ID' => $id],
303
+				$this->_admin_base_url
304
+			);
305
+			$title  = esc_attr__('Duplicate Event', 'event_espresso');
306
+			$return .= '<a href="'
307
+					   . $href
308
+					   . '" title="'
309
+					   . $title
310
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
311
+					   . $title
312
+					   . '</a>';
313
+		}
314
+		return $return;
315
+	}
316
+
317
+
318
+	/**
319
+	 * Set the list table views for the default ticket list table view.
320
+	 */
321
+	public function _set_list_table_views_ticket_list_table()
322
+	{
323
+		$this->_views = [
324
+			'all'     => [
325
+				'slug'        => 'all',
326
+				'label'       => esc_html__('All', 'event_espresso'),
327
+				'count'       => 0,
328
+				'bulk_action' => [
329
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
330
+				],
331
+			],
332
+			'trashed' => [
333
+				'slug'        => 'trashed',
334
+				'label'       => esc_html__('Trash', 'event_espresso'),
335
+				'count'       => 0,
336
+				'bulk_action' => [
337
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
338
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
339
+				],
340
+			],
341
+		];
342
+	}
343
+
344
+
345
+	/**
346
+	 * Enqueue scripts and styles for the event editor.
347
+	 */
348
+	public function load_scripts_styles_edit()
349
+	{
350
+		if (! $this->admin_config->useAdvancedEditor()) {
351
+			wp_register_script(
352
+				'ee-event-editor-heartbeat',
353
+				EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
354
+				['ee_admin_js', 'heartbeat'],
355
+				EVENT_ESPRESSO_VERSION,
356
+				true
357
+			);
358
+			wp_enqueue_script('ee-accounting');
359
+			wp_enqueue_script('ee-event-editor-heartbeat');
360
+		}
361
+		wp_enqueue_script('event_editor_js');
362
+		// styles
363
+		wp_enqueue_style('espresso-ui-theme');
364
+	}
365
+
366
+
367
+	/**
368
+	 * Returns template for the additional datetime.
369
+	 *
370
+	 * @param string $template
371
+	 * @param array  $template_args
372
+	 * @return string
373
+	 * @throws DomainException
374
+	 */
375
+	public function add_additional_datetime_button($template, $template_args)
376
+	{
377
+		return EEH_Template::display_template(
378
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
379
+			$template_args,
380
+			true
381
+		);
382
+	}
383
+
384
+
385
+	/**
386
+	 * Returns the template for cloning a datetime.
387
+	 *
388
+	 * @param $template
389
+	 * @param $template_args
390
+	 * @return string
391
+	 * @throws DomainException
392
+	 */
393
+	public function add_datetime_clone_button($template, $template_args)
394
+	{
395
+		return EEH_Template::display_template(
396
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
397
+			$template_args,
398
+			true
399
+		);
400
+	}
401
+
402
+
403
+	/**
404
+	 * Returns the template for datetime timezones.
405
+	 *
406
+	 * @param $template
407
+	 * @param $template_args
408
+	 * @return string
409
+	 * @throws DomainException
410
+	 */
411
+	public function datetime_timezones_template($template, $template_args)
412
+	{
413
+		return EEH_Template::display_template(
414
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
415
+			$template_args,
416
+			true
417
+		);
418
+	}
419
+
420
+
421
+	/**
422
+	 * Sets the views for the default list table view.
423
+	 *
424
+	 * @throws EE_Error
425
+	 */
426
+	protected function _set_list_table_views_default()
427
+	{
428
+		parent::_set_list_table_views_default();
429
+		$new_views    = [
430
+			'today' => [
431
+				'slug'        => 'today',
432
+				'label'       => esc_html__('Today', 'event_espresso'),
433
+				'count'       => $this->total_events_today(),
434
+				'bulk_action' => [
435
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
436
+				],
437
+			],
438
+			'month' => [
439
+				'slug'        => 'month',
440
+				'label'       => esc_html__('This Month', 'event_espresso'),
441
+				'count'       => $this->total_events_this_month(),
442
+				'bulk_action' => [
443
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
444
+				],
445
+			],
446
+		];
447
+		$this->_views = array_merge($this->_views, $new_views);
448
+	}
449
+
450
+
451
+	/**
452
+	 * Returns the extra action links for the default list table view.
453
+	 *
454
+	 * @param array    $action_links
455
+	 * @param EE_Event $event
456
+	 * @return array
457
+	 * @throws EE_Error
458
+	 * @throws ReflectionException
459
+	 */
460
+	public function extra_list_table_actions(array $action_links, EE_Event $event)
461
+	{
462
+		if (
463
+			EE_Registry::instance()->CAP->current_user_can(
464
+				'ee_read_registrations',
465
+				'espresso_registrations_reports',
466
+				$event->ID()
467
+			)
468
+		) {
469
+			$reports_query_args = [
470
+				'action' => 'reports',
471
+				'EVT_ID' => $event->ID(),
472
+			];
473
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
474
+			$action_links[]     = '<a href="'
475
+								  . $reports_link
476
+								  . '" title="'
477
+								  . esc_attr__('View Report', 'event_espresso')
478
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
479
+								  . "\n\t";
480
+		}
481
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
482
+			EE_Registry::instance()->load_helper('MSG_Template');
483
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
484
+				'see_notifications_for',
485
+				null,
486
+				['EVT_ID' => $event->ID()]
487
+			);
488
+		}
489
+		return $action_links;
490
+	}
491
+
492
+
493
+	/**
494
+	 * @param $items
495
+	 * @return mixed
496
+	 */
497
+	public function additional_legend_items($items)
498
+	{
499
+		if (
500
+			EE_Registry::instance()->CAP->current_user_can(
501
+				'ee_read_registrations',
502
+				'espresso_registrations_reports'
503
+			)
504
+		) {
505
+			$items['reports'] = [
506
+				'class' => 'dashicons dashicons-chart-bar',
507
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
508
+			];
509
+		}
510
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
511
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
512
+			// $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
513
+			// (can only use numeric offsets when treating strings as arrays)
514
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
515
+				$items['view_related_messages'] = [
516
+					'class' => $related_for_icon['css_class'],
517
+					'desc'  => $related_for_icon['label'],
518
+				];
519
+			}
520
+		}
521
+		return $items;
522
+	}
523
+
524
+
525
+	/**
526
+	 * This is the callback method for the duplicate event route
527
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
528
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
529
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
530
+	 * After duplication the redirect is to the new event edit page.
531
+	 *
532
+	 * @return void
533
+	 * @throws EE_Error If EE_Event is not available with given ID
534
+	 * @throws ReflectionException
535
+	 * @access protected
536
+	 */
537
+	protected function _duplicate_event()
538
+	{
539
+		// first make sure the ID for the event is in the request.
540
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
541
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
542
+		if (! $EVT_ID) {
543
+			EE_Error::add_error(
544
+				esc_html__(
545
+					'In order to duplicate an event an Event ID is required.  None was given.',
546
+					'event_espresso'
547
+				),
548
+				__FILE__,
549
+				__FUNCTION__,
550
+				__LINE__
551
+			);
552
+			$this->_redirect_after_action(false, '', '', [], true);
553
+			return;
554
+		}
555
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
556
+		$orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
557
+		if (! $orig_event instanceof EE_Event) {
558
+			throw new EE_Error(
559
+				sprintf(
560
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
561
+					$EVT_ID
562
+				)
563
+			);
564
+		}
565
+		// k now let's clone the $orig_event before getting relations
566
+		$new_event = clone $orig_event;
567
+		// original datetimes
568
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
569
+		// other original relations
570
+		$orig_ven = $orig_event->get_many_related('Venue');
571
+		// reset the ID and modify other details to make it clear this is a dupe
572
+		$new_event->set('EVT_ID', 0);
573
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
574
+		$new_event->set('EVT_name', $new_name);
575
+		$new_event->set(
576
+			'EVT_slug',
577
+			wp_unique_post_slug(
578
+				sanitize_title($orig_event->name()),
579
+				0,
580
+				'publish',
581
+				'espresso_events',
582
+				0
583
+			)
584
+		);
585
+		$new_event->set('status', 'draft');
586
+		// duplicate discussion settings
587
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
588
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
589
+		// save the new event
590
+		$new_event->save();
591
+		// venues
592
+		foreach ($orig_ven as $ven) {
593
+			$new_event->_add_relation_to($ven, 'Venue');
594
+		}
595
+		$new_event->save();
596
+		// now we need to get the question group relations and handle that
597
+		// first primary question groups
598
+		$orig_primary_qgs = $orig_event->get_many_related(
599
+			'Question_Group',
600
+			[['Event_Question_Group.EQG_primary' => true]]
601
+		);
602
+		if (! empty($orig_primary_qgs)) {
603
+			foreach ($orig_primary_qgs as $obj) {
604
+				if ($obj instanceof EE_Question_Group) {
605
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
606
+				}
607
+			}
608
+		}
609
+		// next additional attendee question groups
610
+		$orig_additional_qgs = $orig_event->get_many_related(
611
+			'Question_Group',
612
+			[['Event_Question_Group.EQG_additional' => true]]
613
+		);
614
+		if (! empty($orig_additional_qgs)) {
615
+			foreach ($orig_additional_qgs as $obj) {
616
+				if ($obj instanceof EE_Question_Group) {
617
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
618
+				}
619
+			}
620
+		}
621
+
622
+		$new_event->save();
623
+
624
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
625
+		$cloned_tickets = [];
626
+		foreach ($orig_datetimes as $orig_dtt) {
627
+			if (! $orig_dtt instanceof EE_Datetime) {
628
+				continue;
629
+			}
630
+			$new_dtt      = clone $orig_dtt;
631
+			$orig_tickets = $orig_dtt->tickets();
632
+			// save new dtt then add to event
633
+			$new_dtt->set('DTT_ID', 0);
634
+			$new_dtt->set('DTT_sold', 0);
635
+			$new_dtt->set_reserved(0);
636
+			$new_dtt->save();
637
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
638
+			$new_event->save();
639
+			// now let's get the ticket relations setup.
640
+			foreach ((array) $orig_tickets as $orig_ticket) {
641
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
642
+				if (! $orig_ticket instanceof EE_Ticket) {
643
+					continue;
644
+				}
645
+				// is this ticket archived?  If it is then let's skip
646
+				if ($orig_ticket->get('TKT_deleted')) {
647
+					continue;
648
+				}
649
+				// does this original ticket already exist in the clone_tickets cache?
650
+				//  If so we'll just use the new ticket from it.
651
+				if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
652
+					$new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
653
+				} else {
654
+					$new_ticket = clone $orig_ticket;
655
+					// get relations on the $orig_ticket that we need to setup.
656
+					$orig_prices = $orig_ticket->prices();
657
+					$new_ticket->set('TKT_ID', 0);
658
+					$new_ticket->set('TKT_sold', 0);
659
+					$new_ticket->set('TKT_reserved', 0);
660
+					$new_ticket->save(); // make sure new ticket has ID.
661
+					// price relations on new ticket need to be setup.
662
+					foreach ($orig_prices as $orig_price) {
663
+						$new_price = clone $orig_price;
664
+						$new_price->set('PRC_ID', 0);
665
+						$new_price->save();
666
+						$new_ticket->_add_relation_to($new_price, 'Price');
667
+						$new_ticket->save();
668
+					}
669
+
670
+					do_action(
671
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
672
+						$orig_ticket,
673
+						$new_ticket,
674
+						$orig_prices,
675
+						$orig_event,
676
+						$orig_dtt,
677
+						$new_dtt
678
+					);
679
+				}
680
+				// k now we can add the new ticket as a relation to the new datetime
681
+				// and make sure its added to our cached $cloned_tickets array
682
+				// for use with later datetimes that have the same ticket.
683
+				$new_dtt->_add_relation_to($new_ticket, 'Ticket');
684
+				$new_dtt->save();
685
+				$cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
686
+			}
687
+		}
688
+		// clone taxonomy information
689
+		$taxonomies_to_clone_with = apply_filters(
690
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
691
+			['espresso_event_categories', 'espresso_event_type', 'post_tag']
692
+		);
693
+		// get terms for original event (notice)
694
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
695
+		// loop through terms and add them to new event.
696
+		foreach ($orig_terms as $term) {
697
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
698
+		}
699
+
700
+		// duplicate other core WP_Post items for this event.
701
+		// post thumbnail (feature image).
702
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
703
+		if ($feature_image_id) {
704
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
705
+		}
706
+
707
+		// duplicate page_template setting
708
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
709
+		if ($page_template) {
710
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
711
+		}
712
+
713
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
714
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
715
+		if ($new_event->ID()) {
716
+			$redirect_args = [
717
+				'post'   => $new_event->ID(),
718
+				'action' => 'edit',
719
+			];
720
+			EE_Error::add_success(
721
+				esc_html__(
722
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
723
+					'event_espresso'
724
+				)
725
+			);
726
+		} else {
727
+			$redirect_args = [
728
+				'action' => 'default',
729
+			];
730
+			EE_Error::add_error(
731
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
732
+				__FILE__,
733
+				__FUNCTION__,
734
+				__LINE__
735
+			);
736
+		}
737
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
738
+	}
739
+
740
+
741
+	/**
742
+	 * Generates output for the import page.
743
+	 *
744
+	 * @throws EE_Error
745
+	 */
746
+	protected function _import_page()
747
+	{
748
+		$title                                      = esc_html__('Import', 'event_espresso');
749
+		$intro                                      = esc_html__(
750
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
751
+			'event_espresso'
752
+		);
753
+
754
+		$form_url = EVENTS_ADMIN_URL;
755
+		$action   = 'import_events';
756
+		$type     = 'csv';
757
+
758
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
759
+			$title,
760
+			$intro,
761
+			$form_url,
762
+			$action,
763
+			$type
764
+		);
765
+
766
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
767
+			['action' => 'sample_export_file'],
768
+			$this->_admin_base_url
769
+		);
770
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
771
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
772
+			$this->_template_args,
773
+			true
774
+		);
775
+		$this->display_admin_page_with_sidebar();
776
+	}
777
+
778
+
779
+	/**
780
+	 * _import_events
781
+	 * This handles displaying the screen and running imports for importing events.
782
+	 *
783
+	 * @return void
784
+	 * @throws EE_Error
785
+	 */
786
+	protected function _import_events()
787
+	{
788
+		require_once(EE_CLASSES . 'EE_Import.class.php');
789
+		$success = EE_Import::instance()->import();
790
+		$this->_redirect_after_action(
791
+			$success,
792
+			esc_html__('Import File', 'event_espresso'),
793
+			'ran',
794
+			['action' => 'import_page'],
795
+			true
796
+		);
797
+	}
798
+
799
+
800
+	/**
801
+	 * _events_export
802
+	 * Will export all (or just the given event) to a Excel compatible file.
803
+	 *
804
+	 * @access protected
805
+	 * @return void
806
+	 */
807
+	protected function _events_export()
808
+	{
809
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
810
+		$EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
811
+		$this->request->mergeRequestParams(
812
+			[
813
+				'export' => 'report',
814
+				'action' => 'all_event_data',
815
+				'EVT_ID' => $EVT_ID,
816
+			]
817
+		);
818
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
819
+			require_once(EE_CLASSES . 'EE_Export.class.php');
820
+			$EE_Export = EE_Export::instance($this->request->requestParams());
821
+			$EE_Export->export();
822
+		}
823
+	}
824
+
825
+
826
+	/**
827
+	 * handle category exports()
828
+	 *
829
+	 * @return void
830
+	 */
831
+	protected function _categories_export()
832
+	{
833
+		$EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
834
+		$this->request->mergeRequestParams(
835
+			[
836
+				'export' => 'report',
837
+				'action' => 'categories',
838
+				'EVT_ID' => $EVT_ID,
839
+			]
840
+		);
841
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
842
+			require_once(EE_CLASSES . 'EE_Export.class.php');
843
+			$EE_Export = EE_Export::instance($this->request->requestParams());
844
+			$EE_Export->export();
845
+		}
846
+	}
847
+
848
+
849
+	/**
850
+	 * Creates a sample CSV file for importing
851
+	 */
852
+	protected function _sample_export_file()
853
+	{
854
+		$EE_Export = EE_Export::instance();
855
+		if ($EE_Export instanceof EE_Export) {
856
+			$EE_Export->export();
857
+		}
858
+	}
859
+
860
+
861
+	/*************        Template Settings        *************/
862
+	/**
863
+	 * Generates template settings page output
864
+	 *
865
+	 * @throws DomainException
866
+	 * @throws EE_Error
867
+	 * @throws InvalidArgumentException
868
+	 * @throws InvalidDataTypeException
869
+	 * @throws InvalidInterfaceException
870
+	 */
871
+	protected function _template_settings()
872
+	{
873
+		$this->_template_args['values'] = $this->_yes_no_values;
874
+		/**
875
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
876
+		 * from General_Settings_Admin_Page to here.
877
+		 */
878
+		$this->_template_args = apply_filters(
879
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
880
+			$this->_template_args
881
+		);
882
+		$this->_set_add_edit_form_tags('update_template_settings');
883
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
884
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
885
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
886
+			$this->_template_args,
887
+			true
888
+		);
889
+		$this->display_admin_page_with_sidebar();
890
+	}
891
+
892
+
893
+	/**
894
+	 * Handler for updating template settings.
895
+	 *
896
+	 * @throws EE_Error
897
+	 */
898
+	protected function _update_template_settings()
899
+	{
900
+		/**
901
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
902
+		 * from General_Settings_Admin_Page to here.
903
+		 */
904
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
905
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
906
+			EE_Registry::instance()->CFG->template_settings,
907
+			$this->request->requestParams()
908
+		);
909
+		// update custom post type slugs and detect if we need to flush rewrite rules
910
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
911
+
912
+		$event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
913
+
914
+		EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
915
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
916
+			: EEH_URL::slugify($event_cpt_slug, 'events');
917
+
918
+		$what    = esc_html__('Template Settings', 'event_espresso');
919
+		$success = $this->_update_espresso_configuration(
920
+			$what,
921
+			EE_Registry::instance()->CFG->template_settings,
922
+			__FILE__,
923
+			__FUNCTION__,
924
+			__LINE__
925
+		);
926
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
927
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
928
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
929
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
930
+			);
931
+			$rewrite_rules->flush();
932
+		}
933
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
934
+	}
935
+
936
+
937
+	/**
938
+	 * _premium_event_editor_meta_boxes
939
+	 * add all metaboxes related to the event_editor
940
+	 *
941
+	 * @access protected
942
+	 * @return void
943
+	 * @throws EE_Error
944
+	 * @throws ReflectionException
945
+	 */
946
+	protected function _premium_event_editor_meta_boxes()
947
+	{
948
+		$this->verify_cpt_object();
949
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
950
+		if (
951
+			! $this->admin_config->useAdvancedEditor()
952
+			|| ! $this->feature->allowed('use_reg_options_meta_box')
953
+		) {
954
+			add_meta_box(
955
+				'espresso_event_editor_event_options',
956
+				esc_html__('Event Registration Options', 'event_espresso'),
957
+				[$this, 'registration_options_meta_box'],
958
+				$this->page_slug,
959
+				'side',
960
+				'core'
961
+			);
962
+		}
963
+	}
964
+
965
+
966
+	/**
967
+	 * override caf metabox
968
+	 *
969
+	 * @return void
970
+	 * @throws EE_Error
971
+	 * @throws ReflectionException
972
+	 */
973
+	public function registration_options_meta_box()
974
+	{
975
+		$yes_no_values = [
976
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
977
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
978
+		];
979
+
980
+		$default_reg_status_values = EEM_Registration::reg_status_array(
981
+			[
982
+				EEM_Registration::status_id_cancelled,
983
+				EEM_Registration::status_id_declined,
984
+				EEM_Registration::status_id_incomplete,
985
+				EEM_Registration::status_id_wait_list,
986
+			],
987
+			true
988
+		);
989
+
990
+		$template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
991
+		$template_args['_event']           = $this->_cpt_model_obj;
992
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
993
+
994
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
995
+			'default_reg_status',
996
+			$default_reg_status_values,
997
+			$this->_cpt_model_obj->default_registration_status()
998
+		);
999
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1000
+			'display_desc',
1001
+			$yes_no_values,
1002
+			$this->_cpt_model_obj->display_description()
1003
+		);
1004
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1005
+			'display_ticket_selector',
1006
+			$yes_no_values,
1007
+			$this->_cpt_model_obj->display_ticket_selector(),
1008
+			'',
1009
+			'',
1010
+			false
1011
+		);
1012
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1013
+			'EVT_default_registration_status',
1014
+			$default_reg_status_values,
1015
+			$this->_cpt_model_obj->default_registration_status()
1016
+		);
1017
+		$template_args['additional_registration_options'] = apply_filters(
1018
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1019
+			'',
1020
+			$template_args,
1021
+			$yes_no_values,
1022
+			$default_reg_status_values
1023
+		);
1024
+		EEH_Template::display_template(
1025
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1026
+			$template_args
1027
+		);
1028
+	}
1029
+
1030
+
1031
+
1032
+	/**
1033
+	 * wp_list_table_mods for caf
1034
+	 * ============================
1035
+	 */
1036
+	/**
1037
+	 * hook into list table filters and provide filters for caffeinated list table
1038
+	 *
1039
+	 * @param array $old_filters    any existing filters present
1040
+	 * @param array $list_table_obj the list table object
1041
+	 * @return array                  new filters
1042
+	 * @throws EE_Error
1043
+	 * @throws ReflectionException
1044
+	 */
1045
+	public function list_table_filters($old_filters, $list_table_obj)
1046
+	{
1047
+		$filters = [];
1048
+		// first month/year filters
1049
+		$filters[] = $this->espresso_event_months_dropdown();
1050
+		$status    = $this->request->getRequestParam('status');
1051
+		// active status dropdown
1052
+		if ($status !== 'draft') {
1053
+			$filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
1054
+			$filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
1055
+		}
1056
+		// category filter
1057
+		$filters[] = $this->category_dropdown();
1058
+		return array_merge($old_filters, $filters);
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * espresso_event_months_dropdown
1064
+	 *
1065
+	 * @access public
1066
+	 * @return string                dropdown listing month/year selections for events.
1067
+	 * @throws EE_Error
1068
+	 */
1069
+	public function espresso_event_months_dropdown()
1070
+	{
1071
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1072
+		// Note we need to include any other filters that are set!
1073
+		return EEH_Form_Fields::generate_event_months_dropdown(
1074
+			$this->request->getRequestParam('month_range'),
1075
+			$this->request->getRequestParam('status'),
1076
+			$this->request->getRequestParam('EVT_CAT', 0, 'int'),
1077
+			$this->request->getRequestParam('active_status')
1078
+		);
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * returns a list of "active" statuses on the event
1084
+	 *
1085
+	 * @param string $current_value whatever the current active status is
1086
+	 * @return string
1087
+	 */
1088
+	public function active_status_dropdown($current_value = '')
1089
+	{
1090
+		$select_name = 'active_status';
1091
+		$values      = [
1092
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1093
+			'active'   => esc_html__('Active', 'event_espresso'),
1094
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1095
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1096
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1097
+		];
1098
+
1099
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * returns a list of "venues"
1105
+	 *
1106
+	 * @param string $current_value whatever the current active status is
1107
+	 * @return string
1108
+	 * @throws EE_Error
1109
+	 * @throws ReflectionException
1110
+	 */
1111
+	protected function venuesDropdown($current_value = '')
1112
+	{
1113
+		$values = ['' => esc_html__('All Venues', 'event_espresso')];
1114
+		// populate the list of venues.
1115
+		$venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1116
+
1117
+		foreach ($venues as $venue) {
1118
+			$values[ $venue->ID() ] = $venue->name();
1119
+		}
1120
+
1121
+		return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1122
+	}
1123
+
1124
+
1125
+	/**
1126
+	 * output a dropdown of the categories for the category filter on the event admin list table
1127
+	 *
1128
+	 * @access  public
1129
+	 * @return string html
1130
+	 * @throws EE_Error
1131
+	 * @throws ReflectionException
1132
+	 */
1133
+	public function category_dropdown()
1134
+	{
1135
+		return EEH_Form_Fields::generate_event_category_dropdown(
1136
+			$this->request->getRequestParam('EVT_CAT', -1, 'int')
1137
+		);
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * get total number of events today
1143
+	 *
1144
+	 * @access public
1145
+	 * @return int
1146
+	 * @throws EE_Error
1147
+	 * @throws InvalidArgumentException
1148
+	 * @throws InvalidDataTypeException
1149
+	 * @throws InvalidInterfaceException
1150
+	 */
1151
+	public function total_events_today()
1152
+	{
1153
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1154
+			'DTT_EVT_start',
1155
+			date('Y-m-d') . ' 00:00:00',
1156
+			'Y-m-d H:i:s',
1157
+			'UTC'
1158
+		);
1159
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1160
+			'DTT_EVT_start',
1161
+			date('Y-m-d') . ' 23:59:59',
1162
+			'Y-m-d H:i:s',
1163
+			'UTC'
1164
+		);
1165
+		$where = [
1166
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1167
+		];
1168
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1169
+	}
1170
+
1171
+
1172
+	/**
1173
+	 * get total number of events this month
1174
+	 *
1175
+	 * @access public
1176
+	 * @return int
1177
+	 * @throws EE_Error
1178
+	 * @throws InvalidArgumentException
1179
+	 * @throws InvalidDataTypeException
1180
+	 * @throws InvalidInterfaceException
1181
+	 */
1182
+	public function total_events_this_month()
1183
+	{
1184
+		// Dates
1185
+		$this_year_r     = date('Y');
1186
+		$this_month_r    = date('m');
1187
+		$days_this_month = date('t');
1188
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1189
+			'DTT_EVT_start',
1190
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1191
+			'Y-m-d H:i:s',
1192
+			'UTC'
1193
+		);
1194
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1195
+			'DTT_EVT_start',
1196
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1197
+			'Y-m-d H:i:s',
1198
+			'UTC'
1199
+		);
1200
+		$where           = [
1201
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1202
+		];
1203
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1204
+	}
1205
+
1206
+
1207
+	/** DEFAULT TICKETS STUFF **/
1208
+
1209
+	/**
1210
+	 * Output default tickets list table view.
1211
+	 *
1212
+	 * @throws EE_Error
1213
+	 */
1214
+	public function _tickets_overview_list_table()
1215
+	{
1216
+		if (
1217
+			$this->admin_config->useAdvancedEditor()
1218
+			&& $this->feature->allowed('use_default_ticket_manager')
1219
+		) {
1220
+			// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1221
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1222
+				EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1223
+				[],
1224
+				true
1225
+			);
1226
+			$this->display_admin_page_with_no_sidebar();
1227
+		} else {
1228
+			$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1229
+			$this->display_admin_list_table_page_with_no_sidebar();
1230
+		}
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 * @param int  $per_page
1236
+	 * @param bool $count
1237
+	 * @param bool $trashed
1238
+	 * @return EE_Soft_Delete_Base_Class[]|int
1239
+	 * @throws EE_Error
1240
+	 */
1241
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1242
+	{
1243
+		$orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1244
+		$order   = $this->request->getRequestParam('order', 'ASC');
1245
+		switch ($orderby) {
1246
+			case 'TKT_name':
1247
+				$orderby = ['TKT_name' => $order];
1248
+				break;
1249
+			case 'TKT_price':
1250
+				$orderby = ['TKT_price' => $order];
1251
+				break;
1252
+			case 'TKT_uses':
1253
+				$orderby = ['TKT_uses' => $order];
1254
+				break;
1255
+			case 'TKT_min':
1256
+				$orderby = ['TKT_min' => $order];
1257
+				break;
1258
+			case 'TKT_max':
1259
+				$orderby = ['TKT_max' => $order];
1260
+				break;
1261
+			case 'TKT_qty':
1262
+				$orderby = ['TKT_qty' => $order];
1263
+				break;
1264
+		}
1265
+
1266
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1267
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1268
+		$offset       = ($current_page - 1) * $per_page;
1269
+
1270
+		$where = [
1271
+			'TKT_is_default' => 1,
1272
+			'TKT_deleted'    => $trashed,
1273
+		];
1274
+
1275
+		$search_term = $this->request->getRequestParam('s');
1276
+		if ($search_term) {
1277
+			$search_term = '%' . $search_term . '%';
1278
+			$where['OR'] = [
1279
+				'TKT_name'        => ['LIKE', $search_term],
1280
+				'TKT_description' => ['LIKE', $search_term],
1281
+			];
1282
+		}
1283
+
1284
+		return $count
1285
+			? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1286
+			: EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1287
+				[
1288
+					$where,
1289
+					'order_by' => $orderby,
1290
+					'limit'    => [$offset, $per_page],
1291
+					'group_by' => 'TKT_ID',
1292
+				]
1293
+			);
1294
+	}
1295
+
1296
+
1297
+	/**
1298
+	 * @param bool $trash
1299
+	 * @throws EE_Error
1300
+	 * @throws InvalidArgumentException
1301
+	 * @throws InvalidDataTypeException
1302
+	 * @throws InvalidInterfaceException
1303
+	 */
1304
+	protected function _trash_or_restore_ticket($trash = false)
1305
+	{
1306
+		$success = 1;
1307
+		$TKT     = EEM_Ticket::instance();
1308
+		// checkboxes?
1309
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1310
+		if (! empty($checkboxes)) {
1311
+			// if array has more than one element then success message should be plural
1312
+			$success = count($checkboxes) > 1 ? 2 : 1;
1313
+			// cycle thru the boxes
1314
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1315
+				if ($trash) {
1316
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1317
+						$success = 0;
1318
+					}
1319
+				} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1320
+					$success = 0;
1321
+				}
1322
+			}
1323
+		} else {
1324
+			// grab single id and trash
1325
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1326
+			if ($trash) {
1327
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1328
+					$success = 0;
1329
+				}
1330
+			} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1331
+				$success = 0;
1332
+			}
1333
+		}
1334
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1335
+		$query_args  = [
1336
+			'action' => 'ticket_list_table',
1337
+			'status' => $trash ? '' : 'trashed',
1338
+		];
1339
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1340
+	}
1341
+
1342
+
1343
+	/**
1344
+	 * Handles trashing default ticket.
1345
+	 *
1346
+	 * @throws EE_Error
1347
+	 * @throws ReflectionException
1348
+	 */
1349
+	protected function _delete_ticket()
1350
+	{
1351
+		$success = 1;
1352
+		// checkboxes?
1353
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1354
+		if (! empty($checkboxes)) {
1355
+			// if array has more than one element then success message should be plural
1356
+			$success = count($checkboxes) > 1 ? 2 : 1;
1357
+			// cycle thru the boxes
1358
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1359
+				// delete
1360
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1361
+					$success = 0;
1362
+				}
1363
+			}
1364
+		} else {
1365
+			// grab single id and trash
1366
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1367
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1368
+				$success = 0;
1369
+			}
1370
+		}
1371
+		$action_desc = 'deleted';
1372
+		$query_args  = [
1373
+			'action' => 'ticket_list_table',
1374
+			'status' => 'trashed',
1375
+		];
1376
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1377
+		if (
1378
+			EEM_Ticket::instance()->count_deleted_and_undeleted(
1379
+				[['TKT_is_default' => 1]],
1380
+				'TKT_ID',
1381
+				true
1382
+			)
1383
+		) {
1384
+			$query_args = [];
1385
+		}
1386
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * @param int $TKT_ID
1392
+	 * @return bool|int
1393
+	 * @throws EE_Error
1394
+	 * @throws ReflectionException
1395
+	 */
1396
+	protected function _delete_the_ticket($TKT_ID)
1397
+	{
1398
+		$ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1399
+		if (! $ticket instanceof EE_Ticket) {
1400
+			return false;
1401
+		}
1402
+		$ticket->_remove_relations('Datetime');
1403
+		// delete all related prices first
1404
+		$ticket->delete_related_permanently('Price');
1405
+		return $ticket->delete_permanently();
1406
+	}
1407 1407
 }
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __construct($routing = true)
38 38
     {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
39
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
41
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
42
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
43 43
         }
44 44
         parent::__construct($routing);
45 45
         $this->admin_config = $this->loader->getShared('EE_Admin_Config');
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected function _extend_page_config()
55 55
     {
56
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
56
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
57 57
         // is there a evt_id in the request?
58 58
         $EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59 59
         $EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                     'noheader'   => true,
152 152
                 ],
153 153
             ];
154
-            $new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
154
+            $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes);
155 155
         }
156 156
 
157 157
         $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             ],
192 192
             'require_nonce' => false,
193 193
         ];
194
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
194
+        $this->_page_config = array_merge($this->_page_config, $new_page_config);
195 195
         // add filters and actions
196 196
         // modifying _views
197 197
         add_filter(
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
     {
298 298
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
299 299
         // make sure this is only when editing
300
-        if (! empty($id)) {
301
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
300
+        if ( ! empty($id)) {
301
+            $href = EE_Admin_Page::add_query_args_and_nonce(
302 302
                 ['action' => 'duplicate_event', 'EVT_ID' => $id],
303 303
                 $this->_admin_base_url
304 304
             );
305
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
305
+            $title = esc_attr__('Duplicate Event', 'event_espresso');
306 306
             $return .= '<a href="'
307 307
                        . $href
308 308
                        . '" title="'
@@ -347,10 +347,10 @@  discard block
 block discarded – undo
347 347
      */
348 348
     public function load_scripts_styles_edit()
349 349
     {
350
-        if (! $this->admin_config->useAdvancedEditor()) {
350
+        if ( ! $this->admin_config->useAdvancedEditor()) {
351 351
             wp_register_script(
352 352
                 'ee-event-editor-heartbeat',
353
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
353
+                EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
354 354
                 ['ee_admin_js', 'heartbeat'],
355 355
                 EVENT_ESPRESSO_VERSION,
356 356
                 true
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
     public function add_additional_datetime_button($template, $template_args)
376 376
     {
377 377
         return EEH_Template::display_template(
378
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
378
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
379 379
             $template_args,
380 380
             true
381 381
         );
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
     public function add_datetime_clone_button($template, $template_args)
394 394
     {
395 395
         return EEH_Template::display_template(
396
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
396
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
397 397
             $template_args,
398 398
             true
399 399
         );
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
     public function datetime_timezones_template($template, $template_args)
412 412
     {
413 413
         return EEH_Template::display_template(
414
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
414
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
415 415
             $template_args,
416 416
             true
417 417
         );
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
     protected function _set_list_table_views_default()
427 427
     {
428 428
         parent::_set_list_table_views_default();
429
-        $new_views    = [
429
+        $new_views = [
430 430
             'today' => [
431 431
                 'slug'        => 'today',
432 432
                 'label'       => esc_html__('Today', 'event_espresso'),
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         // first make sure the ID for the event is in the request.
540 540
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
541 541
         $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
542
-        if (! $EVT_ID) {
542
+        if ( ! $EVT_ID) {
543 543
             EE_Error::add_error(
544 544
                 esc_html__(
545 545
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
         }
555 555
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
556 556
         $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
557
-        if (! $orig_event instanceof EE_Event) {
557
+        if ( ! $orig_event instanceof EE_Event) {
558 558
             throw new EE_Error(
559 559
                 sprintf(
560 560
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         $orig_ven = $orig_event->get_many_related('Venue');
571 571
         // reset the ID and modify other details to make it clear this is a dupe
572 572
         $new_event->set('EVT_ID', 0);
573
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
573
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
574 574
         $new_event->set('EVT_name', $new_name);
575 575
         $new_event->set(
576 576
             'EVT_slug',
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
             'Question_Group',
600 600
             [['Event_Question_Group.EQG_primary' => true]]
601 601
         );
602
-        if (! empty($orig_primary_qgs)) {
602
+        if ( ! empty($orig_primary_qgs)) {
603 603
             foreach ($orig_primary_qgs as $obj) {
604 604
                 if ($obj instanceof EE_Question_Group) {
605 605
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
             'Question_Group',
612 612
             [['Event_Question_Group.EQG_additional' => true]]
613 613
         );
614
-        if (! empty($orig_additional_qgs)) {
614
+        if ( ! empty($orig_additional_qgs)) {
615 615
             foreach ($orig_additional_qgs as $obj) {
616 616
                 if ($obj instanceof EE_Question_Group) {
617 617
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
625 625
         $cloned_tickets = [];
626 626
         foreach ($orig_datetimes as $orig_dtt) {
627
-            if (! $orig_dtt instanceof EE_Datetime) {
627
+            if ( ! $orig_dtt instanceof EE_Datetime) {
628 628
                 continue;
629 629
             }
630 630
             $new_dtt      = clone $orig_dtt;
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
             // now let's get the ticket relations setup.
640 640
             foreach ((array) $orig_tickets as $orig_ticket) {
641 641
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
642
-                if (! $orig_ticket instanceof EE_Ticket) {
642
+                if ( ! $orig_ticket instanceof EE_Ticket) {
643 643
                     continue;
644 644
                 }
645 645
                 // is this ticket archived?  If it is then let's skip
@@ -648,8 +648,8 @@  discard block
 block discarded – undo
648 648
                 }
649 649
                 // does this original ticket already exist in the clone_tickets cache?
650 650
                 //  If so we'll just use the new ticket from it.
651
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
652
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
651
+                if (isset($cloned_tickets[$orig_ticket->ID()])) {
652
+                    $new_ticket = $cloned_tickets[$orig_ticket->ID()];
653 653
                 } else {
654 654
                     $new_ticket = clone $orig_ticket;
655 655
                     // get relations on the $orig_ticket that we need to setup.
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                 // for use with later datetimes that have the same ticket.
683 683
                 $new_dtt->_add_relation_to($new_ticket, 'Ticket');
684 684
                 $new_dtt->save();
685
-                $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
685
+                $cloned_tickets[$orig_ticket->ID()] = $new_ticket;
686 686
             }
687 687
         }
688 688
         // clone taxonomy information
@@ -763,12 +763,12 @@  discard block
 block discarded – undo
763 763
             $type
764 764
         );
765 765
 
766
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
766
+        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
767 767
             ['action' => 'sample_export_file'],
768 768
             $this->_admin_base_url
769 769
         );
770 770
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
771
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
771
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
772 772
             $this->_template_args,
773 773
             true
774 774
         );
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
      */
786 786
     protected function _import_events()
787 787
     {
788
-        require_once(EE_CLASSES . 'EE_Import.class.php');
788
+        require_once(EE_CLASSES.'EE_Import.class.php');
789 789
         $success = EE_Import::instance()->import();
790 790
         $this->_redirect_after_action(
791 791
             $success,
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
                 'EVT_ID' => $EVT_ID,
816 816
             ]
817 817
         );
818
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
819
-            require_once(EE_CLASSES . 'EE_Export.class.php');
818
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
819
+            require_once(EE_CLASSES.'EE_Export.class.php');
820 820
             $EE_Export = EE_Export::instance($this->request->requestParams());
821 821
             $EE_Export->export();
822 822
         }
@@ -838,8 +838,8 @@  discard block
 block discarded – undo
838 838
                 'EVT_ID' => $EVT_ID,
839 839
             ]
840 840
         );
841
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
842
-            require_once(EE_CLASSES . 'EE_Export.class.php');
841
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
842
+            require_once(EE_CLASSES.'EE_Export.class.php');
843 843
             $EE_Export = EE_Export::instance($this->request->requestParams());
844 844
             $EE_Export->export();
845 845
         }
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
         $this->_set_add_edit_form_tags('update_template_settings');
883 883
         $this->_set_publish_post_box_vars(null, false, false, null, false);
884 884
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
885
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
885
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
886 886
             $this->_template_args,
887 887
             true
888 888
         );
@@ -991,17 +991,17 @@  discard block
 block discarded – undo
991 991
         $template_args['_event']           = $this->_cpt_model_obj;
992 992
         $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
993 993
 
994
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
994
+        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
995 995
             'default_reg_status',
996 996
             $default_reg_status_values,
997 997
             $this->_cpt_model_obj->default_registration_status()
998 998
         );
999
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
999
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
1000 1000
             'display_desc',
1001 1001
             $yes_no_values,
1002 1002
             $this->_cpt_model_obj->display_description()
1003 1003
         );
1004
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1004
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1005 1005
             'display_ticket_selector',
1006 1006
             $yes_no_values,
1007 1007
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
             $default_reg_status_values
1023 1023
         );
1024 1024
         EEH_Template::display_template(
1025
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1025
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
1026 1026
             $template_args
1027 1027
         );
1028 1028
     }
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
         $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1116 1116
 
1117 1117
         foreach ($venues as $venue) {
1118
-            $values[ $venue->ID() ] = $venue->name();
1118
+            $values[$venue->ID()] = $venue->name();
1119 1119
         }
1120 1120
 
1121 1121
         return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
@@ -1152,13 +1152,13 @@  discard block
 block discarded – undo
1152 1152
     {
1153 1153
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1154 1154
             'DTT_EVT_start',
1155
-            date('Y-m-d') . ' 00:00:00',
1155
+            date('Y-m-d').' 00:00:00',
1156 1156
             'Y-m-d H:i:s',
1157 1157
             'UTC'
1158 1158
         );
1159
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1159
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1160 1160
             'DTT_EVT_start',
1161
-            date('Y-m-d') . ' 23:59:59',
1161
+            date('Y-m-d').' 23:59:59',
1162 1162
             'Y-m-d H:i:s',
1163 1163
             'UTC'
1164 1164
         );
@@ -1187,17 +1187,17 @@  discard block
 block discarded – undo
1187 1187
         $days_this_month = date('t');
1188 1188
         $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1189 1189
             'DTT_EVT_start',
1190
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1190
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1191 1191
             'Y-m-d H:i:s',
1192 1192
             'UTC'
1193 1193
         );
1194
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1194
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1195 1195
             'DTT_EVT_start',
1196
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1196
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1197 1197
             'Y-m-d H:i:s',
1198 1198
             'UTC'
1199 1199
         );
1200
-        $where           = [
1200
+        $where = [
1201 1201
             'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1202 1202
         ];
1203 1203
         return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
         ) {
1220 1220
             // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1221 1221
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1222
-                EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1222
+                EVENTS_CAF_TEMPLATE_PATH.'default_tickets_moved_notice.template.php',
1223 1223
                 [],
1224 1224
                 true
1225 1225
             );
@@ -1274,7 +1274,7 @@  discard block
 block discarded – undo
1274 1274
 
1275 1275
         $search_term = $this->request->getRequestParam('s');
1276 1276
         if ($search_term) {
1277
-            $search_term = '%' . $search_term . '%';
1277
+            $search_term = '%'.$search_term.'%';
1278 1278
             $where['OR'] = [
1279 1279
                 'TKT_name'        => ['LIKE', $search_term],
1280 1280
                 'TKT_description' => ['LIKE', $search_term],
@@ -1307,16 +1307,16 @@  discard block
 block discarded – undo
1307 1307
         $TKT     = EEM_Ticket::instance();
1308 1308
         // checkboxes?
1309 1309
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1310
-        if (! empty($checkboxes)) {
1310
+        if ( ! empty($checkboxes)) {
1311 1311
             // if array has more than one element then success message should be plural
1312 1312
             $success = count($checkboxes) > 1 ? 2 : 1;
1313 1313
             // cycle thru the boxes
1314 1314
             while (list($TKT_ID, $value) = each($checkboxes)) {
1315 1315
                 if ($trash) {
1316
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1316
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1317 1317
                         $success = 0;
1318 1318
                     }
1319
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1319
+                } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1320 1320
                     $success = 0;
1321 1321
                 }
1322 1322
             }
@@ -1324,10 +1324,10 @@  discard block
 block discarded – undo
1324 1324
             // grab single id and trash
1325 1325
             $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1326 1326
             if ($trash) {
1327
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1327
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1328 1328
                     $success = 0;
1329 1329
                 }
1330
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1330
+            } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1331 1331
                 $success = 0;
1332 1332
             }
1333 1333
         }
@@ -1351,20 +1351,20 @@  discard block
 block discarded – undo
1351 1351
         $success = 1;
1352 1352
         // checkboxes?
1353 1353
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1354
-        if (! empty($checkboxes)) {
1354
+        if ( ! empty($checkboxes)) {
1355 1355
             // if array has more than one element then success message should be plural
1356 1356
             $success = count($checkboxes) > 1 ? 2 : 1;
1357 1357
             // cycle thru the boxes
1358 1358
             while (list($TKT_ID, $value) = each($checkboxes)) {
1359 1359
                 // delete
1360
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1360
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1361 1361
                     $success = 0;
1362 1362
                 }
1363 1363
             }
1364 1364
         } else {
1365 1365
             // grab single id and trash
1366 1366
             $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1367
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1367
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1368 1368
                 $success = 0;
1369 1369
             }
1370 1370
         }
@@ -1396,7 +1396,7 @@  discard block
 block discarded – undo
1396 1396
     protected function _delete_the_ticket($TKT_ID)
1397 1397
     {
1398 1398
         $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1399
-        if (! $ticket instanceof EE_Ticket) {
1399
+        if ( ! $ticket instanceof EE_Ticket) {
1400 1400
             return false;
1401 1401
         }
1402 1402
         $ticket->_remove_relations('Datetime');
Please login to merge, or discard this patch.