Completed
Branch models-cleanup/main (1dbd28)
by
unknown
69:50 queued 60:09
created
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2926 added lines, -2926 removed lines patch added patch discarded remove patch
@@ -16,2930 +16,2930 @@
 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.
21
-     *
22
-     * @access protected
23
-     * @var EE_Event $_event
24
-     */
25
-    protected $_event;
26
-
27
-
28
-    /**
29
-     * This will hold the category object for category_details screen.
30
-     *
31
-     * @var stdClass $_category
32
-     */
33
-    protected $_category;
34
-
35
-
36
-    /**
37
-     * @var EEM_Event $_event_model
38
-     */
39
-    protected $_event_model;
40
-
41
-    /**
42
-     * @var EEM_Datetime $datetime_model
43
-     */
44
-    protected $datetime_model;
45
-
46
-    /**
47
-     * @var EEM_Ticket $ticket_model
48
-     */
49
-    protected $ticket_model;
50
-
51
-
52
-    /**
53
-     * @var EE_Event
54
-     */
55
-    protected $_cpt_model_obj;
56
-
57
-
58
-    /**
59
-     * Initialize page props for this admin page group.
60
-     */
61
-    protected function _init_page_props()
62
-    {
63
-        $this->page_slug = EVENTS_PG_SLUG;
64
-        $this->page_label = EVENTS_LABEL;
65
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
66
-        $this->_admin_base_path = EVENTS_ADMIN;
67
-        $this->_cpt_model_names = [
68
-            'create_new' => 'EEM_Event',
69
-            'edit'       => 'EEM_Event',
70
-        ];
71
-        $this->_cpt_edit_routes = [
72
-            'espresso_events' => 'edit',
73
-        ];
74
-        add_action(
75
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
76
-            [$this, 'verify_event_edit'],
77
-            10,
78
-            2
79
-        );
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets the ajax hooks used for this admin page group.
85
-     */
86
-    protected function _ajax_hooks()
87
-    {
88
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
89
-    }
90
-
91
-
92
-    /**
93
-     * Sets the page properties for this admin page group.
94
-     */
95
-    protected function _define_page_props()
96
-    {
97
-        $this->_admin_page_title = EVENTS_LABEL;
98
-        $this->_labels = [
99
-            'buttons'      => [
100
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
101
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
102
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
103
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
104
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
105
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
106
-            ],
107
-            'editor_title' => [
108
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
109
-            ],
110
-            'publishbox'   => [
111
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
112
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
113
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
114
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
115
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
116
-            ],
117
-        ];
118
-    }
119
-
120
-
121
-    /**
122
-     * Sets the page routes property for this admin page group.
123
-     */
124
-    protected function _set_page_routes()
125
-    {
126
-        // load formatter helper
127
-        // load field generator helper
128
-        // is there a evt_id in the request?
129
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
130
-            ? $this->_req_data['EVT_ID']
131
-            : 0;
132
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
133
-        $this->_page_routes = [
134
-            'default'                       => [
135
-                'func'       => '_events_overview_list_table',
136
-                'capability' => 'ee_read_events',
137
-            ],
138
-            'create_new'                    => [
139
-                'func'       => '_create_new_cpt_item',
140
-                'capability' => 'ee_edit_events',
141
-            ],
142
-            'edit'                          => [
143
-                'func'       => '_edit_cpt_item',
144
-                'capability' => 'ee_edit_event',
145
-                'obj_id'     => $evt_id,
146
-            ],
147
-            'copy_event'                    => [
148
-                'func'       => '_copy_events',
149
-                'capability' => 'ee_edit_event',
150
-                'obj_id'     => $evt_id,
151
-                'noheader'   => true,
152
-            ],
153
-            'trash_event'                   => [
154
-                'func'       => '_trash_or_restore_event',
155
-                'args'       => ['event_status' => 'trash'],
156
-                'capability' => 'ee_delete_event',
157
-                'obj_id'     => $evt_id,
158
-                'noheader'   => true,
159
-            ],
160
-            'trash_events'                  => [
161
-                'func'       => '_trash_or_restore_events',
162
-                'args'       => ['event_status' => 'trash'],
163
-                'capability' => 'ee_delete_events',
164
-                'noheader'   => true,
165
-            ],
166
-            'restore_event'                 => [
167
-                'func'       => '_trash_or_restore_event',
168
-                'args'       => ['event_status' => 'draft'],
169
-                'capability' => 'ee_delete_event',
170
-                'obj_id'     => $evt_id,
171
-                'noheader'   => true,
172
-            ],
173
-            'restore_events'                => [
174
-                'func'       => '_trash_or_restore_events',
175
-                'args'       => ['event_status' => 'draft'],
176
-                'capability' => 'ee_delete_events',
177
-                'noheader'   => true,
178
-            ],
179
-            'delete_event'                  => [
180
-                'func'       => '_delete_event',
181
-                'capability' => 'ee_delete_event',
182
-                'obj_id'     => $evt_id,
183
-                'noheader'   => true,
184
-            ],
185
-            'delete_events'                 => [
186
-                'func'       => '_delete_events',
187
-                'capability' => 'ee_delete_events',
188
-                'noheader'   => true,
189
-            ],
190
-            'view_report'                   => [
191
-                'func'       => '_view_report',
192
-                'capability' => 'ee_edit_events',
193
-            ],
194
-            'default_event_settings'        => [
195
-                'func'       => '_default_event_settings',
196
-                'capability' => 'manage_options',
197
-            ],
198
-            'update_default_event_settings' => [
199
-                'func'       => '_update_default_event_settings',
200
-                'capability' => 'manage_options',
201
-                'noheader'   => true,
202
-            ],
203
-            'template_settings'             => [
204
-                'func'       => '_template_settings',
205
-                'capability' => 'manage_options',
206
-            ],
207
-            // event category tab related
208
-            'add_category'                  => [
209
-                'func'       => '_category_details',
210
-                'capability' => 'ee_edit_event_category',
211
-                'args'       => ['add'],
212
-            ],
213
-            'edit_category'                 => [
214
-                'func'       => '_category_details',
215
-                'capability' => 'ee_edit_event_category',
216
-                'args'       => ['edit'],
217
-            ],
218
-            'delete_categories'             => [
219
-                'func'       => '_delete_categories',
220
-                'capability' => 'ee_delete_event_category',
221
-                'noheader'   => true,
222
-            ],
223
-            'delete_category'               => [
224
-                'func'       => '_delete_categories',
225
-                'capability' => 'ee_delete_event_category',
226
-                'noheader'   => true,
227
-            ],
228
-            'insert_category'               => [
229
-                'func'       => '_insert_or_update_category',
230
-                'args'       => ['new_category' => true],
231
-                'capability' => 'ee_edit_event_category',
232
-                'noheader'   => true,
233
-            ],
234
-            'update_category'               => [
235
-                'func'       => '_insert_or_update_category',
236
-                'args'       => ['new_category' => false],
237
-                'capability' => 'ee_edit_event_category',
238
-                'noheader'   => true,
239
-            ],
240
-            'category_list'                 => [
241
-                'func'       => '_category_list_table',
242
-                'capability' => 'ee_manage_event_categories',
243
-            ],
244
-        ];
245
-    }
246
-
247
-
248
-    /**
249
-     * Set the _page_config property for this admin page group.
250
-     */
251
-    protected function _set_page_config()
252
-    {
253
-        $this->_page_config = [
254
-            'default'                => [
255
-                'nav'           => [
256
-                    'label' => esc_html__('Overview', 'event_espresso'),
257
-                    'order' => 10,
258
-                ],
259
-                'list_table'    => 'Events_Admin_List_Table',
260
-                'help_tabs'     => [
261
-                    'events_overview_help_tab'                       => [
262
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
263
-                        'filename' => 'events_overview',
264
-                    ],
265
-                    'events_overview_table_column_headings_help_tab' => [
266
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
267
-                        'filename' => 'events_overview_table_column_headings',
268
-                    ],
269
-                    'events_overview_filters_help_tab'               => [
270
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
271
-                        'filename' => 'events_overview_filters',
272
-                    ],
273
-                    'events_overview_view_help_tab'                  => [
274
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
275
-                        'filename' => 'events_overview_views',
276
-                    ],
277
-                    'events_overview_other_help_tab'                 => [
278
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
279
-                        'filename' => 'events_overview_other',
280
-                    ],
281
-                ],
282
-                'help_tour'     => [
283
-                    'Event_Overview_Help_Tour',
284
-                    // 'New_Features_Test_Help_Tour' for testing multiple help tour
285
-                ],
286
-                'require_nonce' => false,
287
-                'qtips'         => ['EE_Event_List_Table_Tips'],
288
-            ],
289
-            'create_new'             => [
290
-                'nav'           => [
291
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
292
-                    'order'      => 5,
293
-                    'persistent' => false,
294
-                ],
295
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
296
-                'help_tabs'     => [
297
-                    'event_editor_help_tab'                            => [
298
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
299
-                        'filename' => 'event_editor',
300
-                    ],
301
-                    'event_editor_title_richtexteditor_help_tab'       => [
302
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
303
-                        'filename' => 'event_editor_title_richtexteditor',
304
-                    ],
305
-                    'event_editor_venue_details_help_tab'              => [
306
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
307
-                        'filename' => 'event_editor_venue_details',
308
-                    ],
309
-                    'event_editor_event_datetimes_help_tab'            => [
310
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
311
-                        'filename' => 'event_editor_event_datetimes',
312
-                    ],
313
-                    'event_editor_event_tickets_help_tab'              => [
314
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
315
-                        'filename' => 'event_editor_event_tickets',
316
-                    ],
317
-                    'event_editor_event_registration_options_help_tab' => [
318
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
319
-                        'filename' => 'event_editor_event_registration_options',
320
-                    ],
321
-                    'event_editor_tags_categories_help_tab'            => [
322
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
323
-                        'filename' => 'event_editor_tags_categories',
324
-                    ],
325
-                    'event_editor_questions_registrants_help_tab'      => [
326
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
327
-                        'filename' => 'event_editor_questions_registrants',
328
-                    ],
329
-                    'event_editor_save_new_event_help_tab'             => [
330
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
331
-                        'filename' => 'event_editor_save_new_event',
332
-                    ],
333
-                    'event_editor_other_help_tab'                      => [
334
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
335
-                        'filename' => 'event_editor_other',
336
-                    ],
337
-                ],
338
-                'help_tour'     => [
339
-                    'Event_Editor_Help_Tour',
340
-                ],
341
-                'require_nonce' => false,
342
-            ],
343
-            'edit'                   => [
344
-                'nav'           => [
345
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
346
-                    'order'      => 5,
347
-                    'persistent' => false,
348
-                    'url'        => isset($this->_req_data['post'])
349
-                        ? EE_Admin_Page::add_query_args_and_nonce(
350
-                            ['post' => $this->_req_data['post'], 'action' => 'edit'],
351
-                            $this->_current_page_view_url
352
-                        )
353
-                        : $this->_admin_base_url,
354
-                ],
355
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
356
-                'help_tabs'     => [
357
-                    'event_editor_help_tab'                            => [
358
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
359
-                        'filename' => 'event_editor',
360
-                    ],
361
-                    'event_editor_title_richtexteditor_help_tab'       => [
362
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
363
-                        'filename' => 'event_editor_title_richtexteditor',
364
-                    ],
365
-                    'event_editor_venue_details_help_tab'              => [
366
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
367
-                        'filename' => 'event_editor_venue_details',
368
-                    ],
369
-                    'event_editor_event_datetimes_help_tab'            => [
370
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
371
-                        'filename' => 'event_editor_event_datetimes',
372
-                    ],
373
-                    'event_editor_event_tickets_help_tab'              => [
374
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
375
-                        'filename' => 'event_editor_event_tickets',
376
-                    ],
377
-                    'event_editor_event_registration_options_help_tab' => [
378
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
379
-                        'filename' => 'event_editor_event_registration_options',
380
-                    ],
381
-                    'event_editor_tags_categories_help_tab'            => [
382
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
383
-                        'filename' => 'event_editor_tags_categories',
384
-                    ],
385
-                    'event_editor_questions_registrants_help_tab'      => [
386
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
387
-                        'filename' => 'event_editor_questions_registrants',
388
-                    ],
389
-                    'event_editor_save_new_event_help_tab'             => [
390
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
391
-                        'filename' => 'event_editor_save_new_event',
392
-                    ],
393
-                    'event_editor_other_help_tab'                      => [
394
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
395
-                        'filename' => 'event_editor_other',
396
-                    ],
397
-                ],
398
-                'require_nonce' => false,
399
-            ],
400
-            'default_event_settings' => [
401
-                'nav'           => [
402
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
403
-                    'order' => 40,
404
-                ],
405
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
406
-                'labels'        => [
407
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
408
-                ],
409
-                'help_tabs'     => [
410
-                    'default_settings_help_tab'        => [
411
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
412
-                        'filename' => 'events_default_settings',
413
-                    ],
414
-                    'default_settings_status_help_tab' => [
415
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
416
-                        'filename' => 'events_default_settings_status',
417
-                    ],
418
-                    'default_maximum_tickets_help_tab' => [
419
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
420
-                        'filename' => 'events_default_settings_max_tickets',
421
-                    ],
422
-                ],
423
-                'help_tour'     => ['Event_Default_Settings_Help_Tour'],
424
-                'require_nonce' => false,
425
-            ],
426
-            // template settings
427
-            'template_settings'      => [
428
-                'nav'           => [
429
-                    'label' => esc_html__('Templates', 'event_espresso'),
430
-                    'order' => 30,
431
-                ],
432
-                'metaboxes'     => $this->_default_espresso_metaboxes,
433
-                'help_tabs'     => [
434
-                    'general_settings_templates_help_tab' => [
435
-                        'title'    => esc_html__('Templates', 'event_espresso'),
436
-                        'filename' => 'general_settings_templates',
437
-                    ],
438
-                ],
439
-                'help_tour'     => ['Templates_Help_Tour'],
440
-                'require_nonce' => false,
441
-            ],
442
-            // event category stuff
443
-            'add_category'           => [
444
-                'nav'           => [
445
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
446
-                    'order'      => 15,
447
-                    'persistent' => false,
448
-                ],
449
-                'help_tabs'     => [
450
-                    'add_category_help_tab' => [
451
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
452
-                        'filename' => 'events_add_category',
453
-                    ],
454
-                ],
455
-                'help_tour'     => ['Event_Add_Category_Help_Tour'],
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'        => isset($this->_req_data['EVT_CAT_ID'])
465
-                        ? add_query_arg(
466
-                            ['EVT_CAT_ID' => $this->_req_data['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
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
478
-                'metaboxes'     => ['_publish_post_box'],
479
-                'require_nonce' => false,
480
-            ],
481
-            'category_list'          => [
482
-                'nav'           => [
483
-                    'label' => esc_html__('Categories', 'event_espresso'),
484
-                    'order' => 20,
485
-                ],
486
-                'list_table'    => 'Event_Categories_Admin_List_Table',
487
-                'help_tabs'     => [
488
-                    'events_categories_help_tab'                       => [
489
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
490
-                        'filename' => 'events_categories',
491
-                    ],
492
-                    'events_categories_table_column_headings_help_tab' => [
493
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
-                        'filename' => 'events_categories_table_column_headings',
495
-                    ],
496
-                    'events_categories_view_help_tab'                  => [
497
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
-                        'filename' => 'events_categories_views',
499
-                    ],
500
-                    'events_categories_other_help_tab'                 => [
501
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
-                        'filename' => 'events_categories_other',
503
-                    ],
504
-                ],
505
-                'help_tour'     => [
506
-                    'Event_Categories_Help_Tour',
507
-                ],
508
-                'metaboxes'     => $this->_default_espresso_metaboxes,
509
-                'require_nonce' => false,
510
-            ],
511
-        ];
512
-        // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
513
-        $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
514
-        if (! $domain->isCaffeinated()) {
515
-            $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
516
-            $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
517
-        }
518
-    }
519
-
520
-
521
-    /**
522
-     * Used to register any global screen options if necessary for every route in this admin page group.
523
-     */
524
-    protected function _add_screen_options()
525
-    {
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing the screen options for the 'default' route.
531
-     *
532
-     * @throws InvalidArgumentException
533
-     * @throws InvalidDataTypeException
534
-     * @throws InvalidInterfaceException
535
-     */
536
-    protected function _add_screen_options_default()
537
-    {
538
-        $this->_per_page_screen_option();
539
-    }
540
-
541
-
542
-    /**
543
-     * Implementing screen options for the category list route.
544
-     *
545
-     * @throws InvalidArgumentException
546
-     * @throws InvalidDataTypeException
547
-     * @throws InvalidInterfaceException
548
-     */
549
-    protected function _add_screen_options_category_list()
550
-    {
551
-        $page_title = $this->_admin_page_title;
552
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
553
-        $this->_per_page_screen_option();
554
-        $this->_admin_page_title = $page_title;
555
-    }
556
-
557
-
558
-    /**
559
-     * Used to register any global feature pointers for the admin page group.
560
-     */
561
-    protected function _add_feature_pointers()
562
-    {
563
-    }
564
-
565
-
566
-    /**
567
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
568
-     */
569
-    public function load_scripts_styles()
570
-    {
571
-        wp_register_style(
572
-            'events-admin-css',
573
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
574
-            [],
575
-            EVENT_ESPRESSO_VERSION
576
-        );
577
-        wp_register_style(
578
-            'ee-cat-admin',
579
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
580
-            [],
581
-            EVENT_ESPRESSO_VERSION
582
-        );
583
-        wp_enqueue_style('events-admin-css');
584
-        wp_enqueue_style('ee-cat-admin');
585
-        // scripts
586
-        wp_register_script(
587
-            'event_editor_js',
588
-            EVENTS_ASSETS_URL . 'event_editor.js',
589
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
590
-            EVENT_ESPRESSO_VERSION,
591
-            true
592
-        );
593
-    }
594
-
595
-
596
-    /**
597
-     * Enqueuing scripts and styles specific to this view
598
-     */
599
-    public function load_scripts_styles_create_new()
600
-    {
601
-        $this->load_scripts_styles_edit();
602
-    }
603
-
604
-
605
-    /**
606
-     * Enqueuing scripts and styles specific to this view
607
-     */
608
-    public function load_scripts_styles_edit()
609
-    {
610
-        // styles
611
-        wp_enqueue_style('espresso-ui-theme');
612
-        wp_register_style(
613
-            'event-editor-css',
614
-            EVENTS_ASSETS_URL . 'event-editor.css',
615
-            ['ee-admin-css'],
616
-            EVENT_ESPRESSO_VERSION
617
-        );
618
-        wp_enqueue_style('event-editor-css');
619
-        // scripts
620
-        if (! $this->admin_config->useAdvancedEditor()) {
621
-            wp_register_script(
622
-                'event-datetime-metabox',
623
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
624
-                ['event_editor_js', 'ee-datepicker'],
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-            wp_enqueue_script('event-datetime-metabox');
628
-        }
629
-    }
630
-
631
-
632
-    /**
633
-     * Populating the _views property for the category list table view.
634
-     */
635
-    protected function _set_list_table_views_category_list()
636
-    {
637
-        $this->_views = [
638
-            'all' => [
639
-                'slug'        => 'all',
640
-                'label'       => esc_html__('All', 'event_espresso'),
641
-                'count'       => 0,
642
-                'bulk_action' => [
643
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
644
-                ],
645
-            ],
646
-        ];
647
-    }
648
-
649
-
650
-    /**
651
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
652
-     */
653
-    public function admin_init()
654
-    {
655
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
656
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
657
-            'event_espresso'
658
-        );
659
-    }
660
-
661
-
662
-    /**
663
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
664
-     * group.
665
-     */
666
-    public function admin_notices()
667
-    {
668
-    }
669
-
670
-
671
-    /**
672
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
673
-     * this admin page group.
674
-     */
675
-    public function admin_footer_scripts()
676
-    {
677
-    }
678
-
679
-
680
-    /**
681
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
682
-     * warning (via EE_Error::add_error());
683
-     *
684
-     * @param EE_Event $event Event object
685
-     * @param string   $req_type
686
-     * @return void
687
-     * @throws EE_Error
688
-     * @access public
689
-     */
690
-    public function verify_event_edit($event = null, $req_type = '')
691
-    {
692
-        // don't need to do this when processing
693
-        if (! empty($req_type)) {
694
-            return;
695
-        }
696
-        // no event?
697
-        if (! $event instanceof EE_Event) {
698
-            $event = $this->_cpt_model_obj;
699
-        }
700
-        // STILL no event?
701
-        if (! $event instanceof EE_Event) {
702
-            return;
703
-        }
704
-        $orig_status = $event->status();
705
-        // first check if event is active.
706
-        if (
707
-            $orig_status === EEM_Event::cancelled
708
-            || $orig_status === EEM_Event::postponed
709
-            || $event->is_expired()
710
-            || $event->is_inactive()
711
-        ) {
712
-            return;
713
-        }
714
-        // made it here so it IS active... next check that any of the tickets are sold.
715
-        if ($event->is_sold_out(true)) {
716
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
717
-                EE_Error::add_attention(
718
-                    sprintf(
719
-                        esc_html__(
720
-                            '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.',
721
-                            'event_espresso'
722
-                        ),
723
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
724
-                    )
725
-                );
726
-            }
727
-            return;
728
-        }
729
-        if ($orig_status === EEM_Event::sold_out) {
730
-            EE_Error::add_attention(
731
-                sprintf(
732
-                    esc_html__(
733
-                        '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.',
734
-                        'event_espresso'
735
-                    ),
736
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
737
-                )
738
-            );
739
-        }
740
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
741
-        if (! $event->tickets_on_sale()) {
742
-            return;
743
-        }
744
-        // made it here so show warning
745
-        $this->_edit_event_warning();
746
-    }
747
-
748
-
749
-    /**
750
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
751
-     * When needed, hook this into a EE_Error::add_error() notice.
752
-     *
753
-     * @access protected
754
-     * @return void
755
-     */
756
-    protected function _edit_event_warning()
757
-    {
758
-        // we don't want to add warnings during these requests
759
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
760
-            return;
761
-        }
762
-        EE_Error::add_attention(
763
-            sprintf(
764
-                esc_html__(
765
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
766
-                    'event_espresso'
767
-                ),
768
-                '<a class="espresso-help-tab-lnk">',
769
-                '</a>'
770
-            )
771
-        );
772
-    }
773
-
774
-
775
-    /**
776
-     * When a user is creating a new event, notify them if they haven't set their timezone.
777
-     * Otherwise, do the normal logic
778
-     *
779
-     * @throws EE_Error
780
-     * @throws InvalidArgumentException
781
-     * @throws InvalidDataTypeException
782
-     */
783
-    protected function _create_new_cpt_item()
784
-    {
785
-        $has_timezone_string = get_option('timezone_string');
786
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
787
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
788
-            EE_Error::add_attention(
789
-                sprintf(
790
-                    __(
791
-                        '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',
792
-                        'event_espresso'
793
-                    ),
794
-                    '<br>',
795
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
796
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
797
-                    . '</select>',
798
-                    '<button class="button button-secondary timezone-submit">',
799
-                    '</button><span class="spinner"></span>'
800
-                ),
801
-                __FILE__,
802
-                __FUNCTION__,
803
-                __LINE__
804
-            );
805
-        }
806
-        parent::_create_new_cpt_item();
807
-    }
808
-
809
-
810
-    /**
811
-     * Sets the _views property for the default route in this admin page group.
812
-     */
813
-    protected function _set_list_table_views_default()
814
-    {
815
-        $this->_views = [
816
-            'all'   => [
817
-                'slug'        => 'all',
818
-                'label'       => esc_html__('View All Events', 'event_espresso'),
819
-                'count'       => 0,
820
-                'bulk_action' => [
821
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
822
-                ],
823
-            ],
824
-            'draft' => [
825
-                'slug'        => 'draft',
826
-                'label'       => esc_html__('Draft', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => [
829
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
830
-                ],
831
-            ],
832
-        ];
833
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
834
-            $this->_views['trash'] = [
835
-                'slug'        => 'trash',
836
-                'label'       => esc_html__('Trash', 'event_espresso'),
837
-                'count'       => 0,
838
-                'bulk_action' => [
839
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
840
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
841
-                ],
842
-            ];
843
-        }
844
-    }
845
-
846
-
847
-    /**
848
-     * Provides the legend item array for the default list table view.
849
-     *
850
-     * @return array
851
-     */
852
-    protected function _event_legend_items()
853
-    {
854
-        $items = [
855
-            'view_details'   => [
856
-                'class' => 'dashicons dashicons-search',
857
-                'desc'  => esc_html__('View Event', 'event_espresso'),
858
-            ],
859
-            'edit_event'     => [
860
-                'class' => 'ee-icon ee-icon-calendar-edit',
861
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
862
-            ],
863
-            'view_attendees' => [
864
-                'class' => 'dashicons dashicons-groups',
865
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
866
-            ],
867
-        ];
868
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
869
-        $statuses = [
870
-            'sold_out_status'  => [
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
872
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
873
-            ],
874
-            'active_status'    => [
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
876
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
877
-            ],
878
-            'upcoming_status'  => [
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
880
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
881
-            ],
882
-            'postponed_status' => [
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
884
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
885
-            ],
886
-            'cancelled_status' => [
887
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
888
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
889
-            ],
890
-            'expired_status'   => [
891
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
892
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
893
-            ],
894
-            'inactive_status'  => [
895
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
896
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
897
-            ],
898
-        ];
899
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
900
-        return array_merge($items, $statuses);
901
-    }
902
-
903
-
904
-    /**
905
-     * @return EEM_Event
906
-     * @throws EE_Error
907
-     */
908
-    private function eventModel()
909
-    {
910
-        if (! $this->_event_model instanceof EEM_Event) {
911
-            $this->_event_model = EEM_Event::instance();
912
-        }
913
-        return $this->_event_model;
914
-    }
915
-
916
-
917
-    /**
918
-     * @param string $event_timezone_string
919
-     * @return EEM_Datetime
920
-     * @throws EE_Error
921
-     */
922
-    private function datetimeModel($event_timezone_string = '')
923
-    {
924
-        if (! $this->datetime_model instanceof EEM_Datetime) {
925
-            $this->datetime_model = EEM_Datetime::instance($event_timezone_string);
926
-        }
927
-        return $this->datetime_model;
928
-    }
929
-
930
-
931
-    /**
932
-     * @param string $event_timezone_string
933
-     * @return EEM_Ticket
934
-     * @throws EE_Error
935
-     */
936
-    private function ticketModel($event_timezone_string = '')
937
-    {
938
-        if (! $this->ticket_model instanceof EEM_Ticket) {
939
-            $this->ticket_model = EEM_Ticket::instance($event_timezone_string);
940
-        }
941
-        return $this->ticket_model;
942
-    }
943
-
944
-
945
-    /**
946
-     * Adds extra buttons to the WP CPT permalink field row.
947
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
948
-     *
949
-     * @param string $return    the current html
950
-     * @param int    $id        the post id for the page
951
-     * @param string $new_title What the title is
952
-     * @param string $new_slug  what the slug is
953
-     * @return string            The new html string for the permalink area
954
-     */
955
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
956
-    {
957
-        // make sure this is only when editing
958
-        if (! empty($id)) {
959
-            $post = get_post($id);
960
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
961
-                       . esc_html__('Shortcode', 'event_espresso')
962
-                       . '</a> ';
963
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
964
-                       . $post->ID
965
-                       . ']">';
966
-        }
967
-        return $return;
968
-    }
969
-
970
-
971
-    /**
972
-     * _events_overview_list_table
973
-     * This contains the logic for showing the events_overview list
974
-     *
975
-     * @access protected
976
-     * @return void
977
-     * @throws DomainException
978
-     * @throws EE_Error
979
-     * @throws InvalidArgumentException
980
-     * @throws InvalidDataTypeException
981
-     * @throws InvalidInterfaceException
982
-     */
983
-    protected function _events_overview_list_table()
984
-    {
985
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
986
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
987
-            ? (array) $this->_template_args['after_list_table']
988
-            : [];
989
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
990
-                                                                              . EEH_Template::get_button_or_link(
991
-                                                                                  get_post_type_archive_link('espresso_events'),
992
-                                                                                  esc_html__('View Event Archive Page', 'event_espresso'),
993
-                                                                                  'button'
994
-                                                                              );
995
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
996
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
997
-            'create_new',
998
-            'add',
999
-            [],
1000
-            'add-new-h2'
1001
-        );
1002
-        $this->display_admin_list_table_page_with_no_sidebar();
1003
-    }
1004
-
1005
-
1006
-    /**
1007
-     * this allows for extra misc actions in the default WP publish box
1008
-     *
1009
-     * @return void
1010
-     * @throws DomainException
1011
-     * @throws EE_Error
1012
-     * @throws InvalidArgumentException
1013
-     * @throws InvalidDataTypeException
1014
-     * @throws InvalidInterfaceException
1015
-     * @throws ReflectionException
1016
-     */
1017
-    public function extra_misc_actions_publish_box()
1018
-    {
1019
-        $this->_generate_publish_box_extra_content();
1020
-    }
1021
-
1022
-
1023
-    /**
1024
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1025
-     * saved.
1026
-     * Typically you would use this to save any additional data.
1027
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1028
-     * ALSO very important.  When a post transitions from scheduled to published,
1029
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1030
-     * other meta saves. So MAKE sure that you handle this accordingly.
1031
-     *
1032
-     * @access protected
1033
-     * @abstract
1034
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1035
-     * @param object $post    The post object of the cpt that was saved.
1036
-     * @return void
1037
-     * @throws EE_Error
1038
-     * @throws InvalidArgumentException
1039
-     * @throws InvalidDataTypeException
1040
-     * @throws InvalidInterfaceException
1041
-     * @throws ReflectionException
1042
-     */
1043
-    protected function _insert_update_cpt_item($post_id, $post)
1044
-    {
1045
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1046
-            // get out we're not processing an event save.
1047
-            return;
1048
-        }
1049
-        $event_values = [
1050
-            'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1051
-            'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1052
-            'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1053
-                ? sanitize_text_field($this->_req_data['timezone_string'])
1054
-                : null,
1055
-        ];
1056
-        /** @var FeatureFlags $flags */
1057
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1058
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1059
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1060
-            $event_values['EVT_display_ticket_selector'] =
1061
-                ! empty($this->_req_data['display_ticket_selector'])
1062
-                    ? 1
1063
-                    : 0;
1064
-            $event_values['EVT_additional_limit'] = min(
1065
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1066
-                ! empty($this->_req_data['additional_limit'])
1067
-                    ? absint($this->_req_data['additional_limit'])
1068
-                    : null
1069
-            );
1070
-            $event_values['EVT_default_registration_status'] =
1071
-                ! empty($this->_req_data['EVT_default_registration_status'])
1072
-                    ? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1073
-                    : EE_Registry::instance()->CFG->registration->default_STS_ID;
1074
-            $event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL'])
1075
-                ? esc_url_raw($this->_req_data['externalURL'])
1076
-                : null;
1077
-            $event_values['EVT_phone'] = ! empty($this->_req_data['event_phone'])
1078
-                ? sanitize_text_field($this->_req_data['event_phone'])
1079
-                : null;
1080
-        }
1081
-        // update event
1082
-        $success = $this->eventModel()->update_by_ID($event_values, $post_id);
1083
-        // get event_object for other metaboxes...
1084
-        // though it would seem to make sense to just use $this->eventModel()->get_one_by_ID( $post_id )..
1085
-        // i have to setup where conditions to override the filters in the model
1086
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1087
-        $get_one_where = [
1088
-            $this->eventModel()->primary_key_name() => $post_id,
1089
-            'OR'                                    => [
1090
-                'status'   => $post->post_status,
1091
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1092
-                // but the returned object here has a status of "publish", so use the original post status as well
1093
-                'status*1' => $this->_req_data['original_post_status'],
1094
-            ],
1095
-        ];
1096
-        $event = $this->eventModel()->get_one([$get_one_where]);
1097
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1098
-        $event_update_callbacks = apply_filters(
1099
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1100
-            [
1101
-                [$this, '_default_venue_update'],
1102
-                [$this, '_default_tickets_update'],
1103
-            ]
1104
-        );
1105
-        $att_success = true;
1106
-        foreach ($event_update_callbacks as $e_callback) {
1107
-            $_success = is_callable($e_callback)
1108
-                ? $e_callback($event, $this->_req_data)
1109
-                : false;
1110
-            // if ANY of these updates fail then we want the appropriate global error message
1111
-            $att_success = ! $att_success ? $att_success : $_success;
1112
-        }
1113
-        // any errors?
1114
-        if ($success && false === $att_success) {
1115
-            EE_Error::add_error(
1116
-                esc_html__(
1117
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1118
-                    'event_espresso'
1119
-                ),
1120
-                __FILE__,
1121
-                __FUNCTION__,
1122
-                __LINE__
1123
-            );
1124
-        } elseif ($success === false) {
1125
-            EE_Error::add_error(
1126
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1127
-                __FILE__,
1128
-                __FUNCTION__,
1129
-                __LINE__
1130
-            );
1131
-        }
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * @param int $post_id
1137
-     * @param int $revision_id
1138
-     * @throws EE_Error
1139
-     * @throws InvalidArgumentException
1140
-     * @throws InvalidDataTypeException
1141
-     * @throws InvalidInterfaceException
1142
-     * @throws ReflectionException
1143
-     * @see parent::restore_item()
1144
-     */
1145
-    protected function _restore_cpt_item($post_id, $revision_id)
1146
-    {
1147
-        // copy existing event meta to new post
1148
-        $post_evt = $this->eventModel()->get_one_by_ID($post_id);
1149
-        if ($post_evt instanceof EE_Event) {
1150
-            // meta revision restore
1151
-            $post_evt->restore_revision($revision_id);
1152
-            // related objs restore
1153
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1154
-        }
1155
-    }
1156
-
1157
-
1158
-    /**
1159
-     * Attach the venue to the Event
1160
-     *
1161
-     * @param EE_Event $evtobj Event Object to add the venue to
1162
-     * @param array    $data   The request data from the form
1163
-     * @return bool           Success or fail.
1164
-     * @throws EE_Error
1165
-     * @throws InvalidArgumentException
1166
-     * @throws InvalidDataTypeException
1167
-     * @throws InvalidInterfaceException
1168
-     * @throws ReflectionException
1169
-     */
1170
-    protected function _default_venue_update(EE_Event $evtobj, $data)
1171
-    {
1172
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1173
-        $venue_model = EEM_Venue::instance();
1174
-        $rows_affected = null;
1175
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1176
-        // very important.  If we don't have a venue name...
1177
-        // then we'll get out because not necessary to create empty venue
1178
-        if (empty($data['venue_title'])) {
1179
-            return false;
1180
-        }
1181
-        $venue_array = [
1182
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1183
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1184
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1185
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1186
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1187
-                : null,
1188
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1189
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1190
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1191
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1192
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1193
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1194
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1195
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1196
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1197
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1198
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1199
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1200
-            'status'              => 'publish',
1201
-        ];
1202
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1203
-        if (! empty($venue_id)) {
1204
-            $update_where = [$venue_model->primary_key_name() => $venue_id];
1205
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1206
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1207
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1208
-            return $rows_affected > 0;
1209
-        }
1210
-        // we insert the venue
1211
-        $venue_id = $venue_model->insert($venue_array);
1212
-        $evtobj->_add_relation_to($venue_id, 'Venue');
1213
-        return ! empty($venue_id) ? true : false;
1214
-        // when we have the ancestor come in it's already been handled by the revision save.
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1220
-     *
1221
-     * @param EE_Event $evtobj The Event object we're attaching data to
1222
-     * @param array    $data   The request data from the form
1223
-     * @return array
1224
-     * @throws EE_Error
1225
-     * @throws InvalidArgumentException
1226
-     * @throws InvalidDataTypeException
1227
-     * @throws InvalidInterfaceException
1228
-     * @throws ReflectionException
1229
-     * @throws Exception
1230
-     */
1231
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1232
-    {
1233
-        if ($this->admin_config->useAdvancedEditor()) {
1234
-            return [];
1235
-        }
1236
-        $saved_dtt = null;
1237
-        $saved_tickets = [];
1238
-        $incoming_date_formats = ['Y-m-d', 'h:i a'];
1239
-        $event_timezone_string = $evtobj->get_timezone();
1240
-        $event_timezone = new DateTimeZone($event_timezone_string);
1241
-        // let's use now in the set timezone.
1242
-        $now = new DateTime('now', $event_timezone);
1243
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1244
-            // trim all values to ensure any excess whitespace is removed.
1245
-            $dtt = array_map('trim', $dtt);
1246
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end'])
1247
-                ? $dtt['DTT_EVT_end']
1248
-                : $dtt['DTT_EVT_start'];
1249
-            $datetime_values = [
1250
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1251
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1252
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1253
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1254
-                'DTT_order'     => $row,
1255
-            ];
1256
-            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1257
-            if (! empty($dtt['DTT_ID'])) {
1258
-                $DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']);
1259
-                $DTM->set_date_format($incoming_date_formats[0]);
1260
-                $DTM->set_time_format($incoming_date_formats[1]);
1261
-                foreach ($datetime_values as $field => $value) {
1262
-                    $DTM->set($field, $value);
1263
-                }
1264
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1265
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1266
-            } else {
1267
-                $DTM = EE_Registry::instance()->load_class(
1268
-                    'Datetime',
1269
-                    [$datetime_values, $event_timezone_string, $incoming_date_formats],
1270
-                    false,
1271
-                    false
1272
-                );
1273
-                foreach ($datetime_values as $field => $value) {
1274
-                    $DTM->set($field, $value);
1275
-                }
1276
-            }
1277
-            $DTM->save();
1278
-            $DTM = $evtobj->_add_relation_to($DTM, 'Datetime');
1279
-            // load DTT helper
1280
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1281
-            if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
1282
-                $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
1283
-                $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
1284
-                $DTM->save();
1285
-            }
1286
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array
1287
-            //  because it is possible there was a new one created for the autosave.
1288
-            $saved_dtt = $DTM;
1289
-            // if ANY of these updates fail then we want the appropriate global error message.
1290
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1291
-        }
1292
-        // no dtts get deleted so we don't do any of that logic here.
1293
-        // update tickets next
1294
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1295
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1296
-            $incoming_date_formats = ['Y-m-d', 'h:i a'];
1297
-            $update_prices = false;
1298
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1299
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1300
-            // trim inputs to ensure any excess whitespace is removed.
1301
-            $tkt = array_map('trim', $tkt);
1302
-            if (empty($tkt['TKT_start_date'])) {
1303
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1304
-            }
1305
-            if (empty($tkt['TKT_end_date'])) {
1306
-                // use the start date of the first datetime
1307
-                $dtt = $evtobj->first_datetime();
1308
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1309
-                    $incoming_date_formats[0],
1310
-                    $incoming_date_formats[1]
1311
-                );
1312
-            }
1313
-            $TKT_values = [
1314
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1315
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1316
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1317
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1318
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1319
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1320
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1321
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1322
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1323
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1324
-                'TKT_row'         => $row,
1325
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1326
-                'TKT_price'       => $ticket_price,
1327
-            ];
1328
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1329
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1330
-                $TKT_values['TKT_ID'] = 0;
1331
-                $TKT_values['TKT_is_default'] = 0;
1332
-                $TKT_values['TKT_price'] = $ticket_price;
1333
-                $update_prices = true;
1334
-            }
1335
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1336
-            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1337
-            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1338
-            if (! empty($tkt['TKT_ID'])) {
1339
-                $TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']);
1340
-                if ($TKT instanceof EE_Ticket) {
1341
-                    $ticket_sold = $TKT->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
1353
-                    // total price.  if they are different then we create a new ticket (if tickets sold)
1354
-                    // if they aren't different then we go ahead and modify existing ticket.
1355
-                    $create_new_TKT = $ticket_sold && ! $TKT->deleted()
1356
-                                      && EEH_Money::compare_floats(
1357
-                                          $ticket_price,
1358
-                                          $TKT->get('TKT_price'),
1359
-                                          '!=='
1360
-                                      );
1361
-                    $TKT->set_date_format($incoming_date_formats[0]);
1362
-                    $TKT->set_time_format($incoming_date_formats[1]);
1363
-                    // set new values
1364
-                    foreach ($TKT_values as $field => $value) {
1365
-                        if ($field === 'TKT_qty') {
1366
-                            $TKT->set_qty($value);
1367
-                        } else {
1368
-                            $TKT->set($field, $value);
1369
-                        }
1370
-                    }
1371
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1372
-                    if ($create_new_TKT) {
1373
-                        // archive the old ticket first
1374
-                        $TKT->set('TKT_deleted', 1);
1375
-                        $TKT->save();
1376
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1377
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1378
-                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1379
-                        $TKT = clone $TKT;
1380
-                        $TKT->set('TKT_ID', 0);
1381
-                        $TKT->set('TKT_deleted', 0);
1382
-                        $TKT->set('TKT_price', $ticket_price);
1383
-                        $TKT->set('TKT_sold', 0);
1384
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1385
-                        $update_prices = true;
1386
-                    }
1387
-                    // make sure price is set if it hasn't been already
1388
-                    $TKT->set('TKT_price', $ticket_price);
1389
-                }
1390
-            } else {
1391
-                // no TKT_id so a new TKT
1392
-                $TKT_values['TKT_price'] = $ticket_price;
1393
-                $TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1394
-                if ($TKT instanceof EE_Ticket) {
1395
-                    // need to reset values to properly account for the date formats
1396
-                    $TKT->set_date_format($incoming_date_formats[0]);
1397
-                    $TKT->set_time_format($incoming_date_formats[1]);
1398
-                    $TKT->set_timezone($evtobj->get_timezone());
1399
-                    // set new values
1400
-                    foreach ($TKT_values as $field => $value) {
1401
-                        if ($field === 'TKT_qty') {
1402
-                            $TKT->set_qty($value);
1403
-                        } else {
1404
-                            $TKT->set($field, $value);
1405
-                        }
1406
-                    }
1407
-                    $update_prices = true;
1408
-                }
1409
-            }
1410
-            // cap ticket qty by datetime reg limits
1411
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1412
-            // update ticket.
1413
-            $TKT->save();
1414
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1415
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1416
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1417
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1418
-                $TKT->save();
1419
-            }
1420
-            // initially let's add the ticket to the dtt
1421
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1422
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1423
-            // add prices to ticket
1424
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1425
-        }
1426
-        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1427
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1428
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1429
-        foreach ($tickets_removed as $id) {
1430
-            $id = absint($id);
1431
-            // get the ticket for this id
1432
-            $tkt_to_remove = $this->ticketModel($event_timezone_string)->get_one_by_ID($id);
1433
-            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1434
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1435
-            foreach ($dtts as $dtt) {
1436
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1437
-            }
1438
-            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1439
-            $tkt_to_remove->delete_related_permanently('Price');
1440
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1441
-            $tkt_to_remove->delete_permanently();
1442
-        }
1443
-        return [$saved_dtt, $saved_tickets];
1444
-    }
1445
-
1446
-
1447
-    /**
1448
-     * This attaches a list of given prices to a ticket.
1449
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1450
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1451
-     * price info and prices are automatically "archived" via the ticket.
1452
-     *
1453
-     * @access  private
1454
-     * @param array     $prices     Array of prices from the form.
1455
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1456
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1457
-     * @return  void
1458
-     * @throws EE_Error
1459
-     * @throws InvalidArgumentException
1460
-     * @throws InvalidDataTypeException
1461
-     * @throws InvalidInterfaceException
1462
-     * @throws ReflectionException
1463
-     */
1464
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1465
-    {
1466
-        foreach ($prices as $row => $prc) {
1467
-            $PRC_values = [
1468
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1469
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1470
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1471
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1472
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1473
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1474
-                'PRC_order'      => $row,
1475
-            ];
1476
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1477
-                $PRC_values['PRC_ID'] = 0;
1478
-                $PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1479
-            } else {
1480
-                $PRC = EEM_Price::instance()->get_one_by_ID($prc['PRC_ID']);
1481
-                // update this price with new values
1482
-                foreach ($PRC_values as $field => $newprc) {
1483
-                    $PRC->set($field, $newprc);
1484
-                }
1485
-                $PRC->save();
1486
-            }
1487
-            $ticket->_add_relation_to($PRC, 'Price');
1488
-        }
1489
-    }
1490
-
1491
-
1492
-    /**
1493
-     * Add in our autosave ajax handlers
1494
-     *
1495
-     */
1496
-    protected function _ee_autosave_create_new()
1497
-    {
1498
-    }
1499
-
1500
-
1501
-    /**
1502
-     * More autosave handlers.
1503
-     */
1504
-    protected function _ee_autosave_edit()
1505
-    {
1506
-    }
1507
-
1508
-
1509
-    /**
1510
-     *    _generate_publish_box_extra_content
1511
-     *
1512
-     * @throws DomainException
1513
-     * @throws EE_Error
1514
-     * @throws InvalidArgumentException
1515
-     * @throws InvalidDataTypeException
1516
-     * @throws InvalidInterfaceException
1517
-     * @throws ReflectionException
1518
-     */
1519
-    private function _generate_publish_box_extra_content()
1520
-    {
1521
-        // load formatter helper
1522
-        // args for getting related registrations
1523
-        $approved_query_args = [
1524
-            [
1525
-                'REG_deleted' => 0,
1526
-                'STS_ID'      => EEM_Registration::status_id_approved,
1527
-            ],
1528
-        ];
1529
-        $not_approved_query_args = [
1530
-            [
1531
-                'REG_deleted' => 0,
1532
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1533
-            ],
1534
-        ];
1535
-        $pending_payment_query_args = [
1536
-            [
1537
-                'REG_deleted' => 0,
1538
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1539
-            ],
1540
-        ];
1541
-        // publish box
1542
-        $publish_box_extra_args = [
1543
-            'view_approved_reg_url'        => add_query_arg(
1544
-                [
1545
-                    'action'      => 'default',
1546
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1547
-                    '_reg_status' => EEM_Registration::status_id_approved,
1548
-                ],
1549
-                REG_ADMIN_URL
1550
-            ),
1551
-            'view_not_approved_reg_url'    => add_query_arg(
1552
-                [
1553
-                    'action'      => 'default',
1554
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1555
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1556
-                ],
1557
-                REG_ADMIN_URL
1558
-            ),
1559
-            'view_pending_payment_reg_url' => add_query_arg(
1560
-                [
1561
-                    'action'      => 'default',
1562
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1563
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1564
-                ],
1565
-                REG_ADMIN_URL
1566
-            ),
1567
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1568
-                'Registration',
1569
-                $approved_query_args
1570
-            ),
1571
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1572
-                'Registration',
1573
-                $not_approved_query_args
1574
-            ),
1575
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1576
-                'Registration',
1577
-                $pending_payment_query_args
1578
-            ),
1579
-            'misc_pub_section_class'       => apply_filters(
1580
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1581
-                'misc-pub-section'
1582
-            ),
1583
-        ];
1584
-        ob_start();
1585
-        do_action(
1586
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1587
-            $this->_cpt_model_obj
1588
-        );
1589
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1590
-        // load template
1591
-        EEH_Template::display_template(
1592
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1593
-            $publish_box_extra_args
1594
-        );
1595
-    }
1596
-
1597
-
1598
-    /**
1599
-     * @return EE_Event
1600
-     */
1601
-    public function get_event_object()
1602
-    {
1603
-        return $this->_cpt_model_obj;
1604
-    }
1605
-
1606
-
1607
-
1608
-
1609
-    /** METABOXES * */
1610
-    /**
1611
-     * _register_event_editor_meta_boxes
1612
-     * add all metaboxes related to the event_editor
1613
-     *
1614
-     * @return void
1615
-     * @throws EE_Error
1616
-     * @throws InvalidArgumentException
1617
-     * @throws InvalidDataTypeException
1618
-     * @throws InvalidInterfaceException
1619
-     * @throws ReflectionException
1620
-     */
1621
-    protected function _register_event_editor_meta_boxes()
1622
-    {
1623
-        $this->verify_cpt_object();
1624
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1625
-        /** @var FeatureFlags $flags */
1626
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1627
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1628
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1629
-            add_meta_box(
1630
-                'espresso_event_editor_event_options',
1631
-                esc_html__('Event Registration Options', 'event_espresso'),
1632
-                [$this, 'registration_options_meta_box'],
1633
-                $this->page_slug,
1634
-                'side'
1635
-            );
1636
-        }
1637
-        if (! $use_advanced_editor) {
1638
-            add_meta_box(
1639
-                'espresso_event_editor_tickets',
1640
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1641
-                [$this, 'ticket_metabox'],
1642
-                $this->page_slug,
1643
-                'normal',
1644
-                'high'
1645
-            );
1646
-        } else {
1647
-            if ($flags->featureAllowed('use_reg_options_meta_box')) {
1648
-                add_action(
1649
-                    'add_meta_boxes_espresso_events',
1650
-                    function () {
1651
-                        global $current_screen;
1652
-                        remove_meta_box('authordiv', $current_screen, 'normal');
1653
-                    },
1654
-                    99
1655
-                );
1656
-            }
1657
-        }
1658
-        // NOTE: if you're looking for other metaboxes in here,
1659
-        // where a metabox has a related management page in the admin
1660
-        // you will find it setup in the related management page's "_Hooks" file.
1661
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1662
-    }
1663
-
1664
-
1665
-    /**
1666
-     * @throws DomainException
1667
-     * @throws EE_Error
1668
-     * @throws InvalidArgumentException
1669
-     * @throws InvalidDataTypeException
1670
-     * @throws InvalidInterfaceException
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 = $this->_cpt_model_obj instanceof EE_Event ? $this->_cpt_model_obj->ID() : 0;
1690
-        $event_timezone_string = $this->_cpt_model_obj instanceof EE_Event
1691
-            ? $this->_cpt_model_obj->timezone_string()
1692
-            : '';
1693
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1694
-        /**
1695
-         * 1. Start with retrieving Datetimes
1696
-         * 2. Fore each datetime get related tickets
1697
-         * 3. For each ticket get related prices
1698
-         */
1699
-        $times = $this->datetimeModel($event_timezone_string)->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 = $this->ticketModel($event_timezone_string)->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 $ticket */
1732
-            $ticket = $this->ticketModel($event_timezone_string)->get_all_default_tickets();
1733
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[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
-            $this->ticketModel($event_timezone_string)->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 DomainException
1764
-     * @throws EE_Error
1765
-     * @throws InvalidArgumentException
1766
-     * @throws InvalidDataTypeException
1767
-     * @throws InvalidInterfaceException
1768
-     * @throws ReflectionException
1769
-     */
1770
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1771
-    {
1772
-        $template_args = [
1773
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1774
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1775
-                : '',
1776
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1777
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1778
-            'TKT_name'            => $ticket->get('TKT_name'),
1779
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1780
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1781
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1782
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1783
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1784
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1785
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1786
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1787
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1788
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1789
-                : ' disabled=disabled',
1790
-        ];
1791
-        $price = $ticket->ID() !== 0
1792
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1793
-            : EEM_Price::instance()->create_default_object();
1794
-        $price_args = [
1795
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1796
-            'PRC_amount'            => $price->get('PRC_amount'),
1797
-            'PRT_ID'                => $price->get('PRT_ID'),
1798
-            'PRC_ID'                => $price->get('PRC_ID'),
1799
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1800
-        ];
1801
-        // make sure we have default start and end dates if skeleton
1802
-        // handle rows that should NOT be empty
1803
-        if (empty($template_args['TKT_start_date'])) {
1804
-            // if empty then the start date will be now.
1805
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1806
-        }
1807
-        if (empty($template_args['TKT_end_date'])) {
1808
-            // get the earliest datetime (if present);
1809
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1810
-                ? $this->_cpt_model_obj->get_first_related(
1811
-                    'Datetime',
1812
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1813
-                )
1814
-                : null;
1815
-            if (! empty($earliest_dtt)) {
1816
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1817
-            } else {
1818
-                $template_args['TKT_end_date'] = date(
1819
-                    'Y-m-d h:i a',
1820
-                    mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1821
-                );
1822
-            }
1823
-        }
1824
-        $template_args = array_merge($template_args, $price_args);
1825
-        $template = apply_filters(
1826
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1827
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1828
-            $ticket
1829
-        );
1830
-        return EEH_Template::display_template($template, $template_args, true);
1831
-    }
1832
-
1833
-
1834
-    /**
1835
-     * @throws DomainException
1836
-     * @throws EE_Error
1837
-     */
1838
-    public function registration_options_meta_box()
1839
-    {
1840
-        $yes_no_values = [
1841
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1842
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1843
-        ];
1844
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1845
-            [
1846
-                EEM_Registration::status_id_cancelled,
1847
-                EEM_Registration::status_id_declined,
1848
-                EEM_Registration::status_id_incomplete,
1849
-            ],
1850
-            true
1851
-        );
1852
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1853
-        $template_args['_event'] = $this->_cpt_model_obj;
1854
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1855
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1856
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1857
-            'default_reg_status',
1858
-            $default_reg_status_values,
1859
-            $this->_cpt_model_obj->default_registration_status()
1860
-        );
1861
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1862
-            'display_desc',
1863
-            $yes_no_values,
1864
-            $this->_cpt_model_obj->display_description()
1865
-        );
1866
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1867
-            'display_ticket_selector',
1868
-            $yes_no_values,
1869
-            $this->_cpt_model_obj->display_ticket_selector(),
1870
-            '',
1871
-            '',
1872
-            false
1873
-        );
1874
-        $template_args['additional_registration_options'] = apply_filters(
1875
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1876
-            '',
1877
-            $template_args,
1878
-            $yes_no_values,
1879
-            $default_reg_status_values
1880
-        );
1881
-        EEH_Template::display_template(
1882
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1883
-            $template_args
1884
-        );
1885
-    }
1886
-
1887
-
1888
-    /**
1889
-     * _get_events()
1890
-     * This method simply returns all the events (for the given _view and paging)
1891
-     *
1892
-     * @access public
1893
-     * @param int  $per_page     count of items per page (20 default);
1894
-     * @param int  $current_page what is the current page being viewed.
1895
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1896
-     *                           If FALSE then we return an array of event objects
1897
-     *                           that match the given _view and paging parameters.
1898
-     * @return array an array of event objects.
1899
-     * @throws EE_Error
1900
-     * @throws InvalidArgumentException
1901
-     * @throws InvalidDataTypeException
1902
-     * @throws InvalidInterfaceException
1903
-     * @throws ReflectionException
1904
-     * @throws Exception
1905
-     * @throws Exception
1906
-     * @throws Exception
1907
-     */
1908
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1909
-    {
1910
-        $EEME = $this->eventModel();
1911
-        $offset = ($current_page - 1) * $per_page;
1912
-        $limit = $count ? null : $offset . ',' . $per_page;
1913
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1914
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1915
-        if (isset($this->_req_data['month_range'])) {
1916
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1917
-            // simulate the FIRST day of the month, that fixes issues for months like February
1918
-            // where PHP doesn't know what to assume for date.
1919
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1920
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1921
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1922
-        }
1923
-        $where = [];
1924
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1925
-        // determine what post_status our condition will have for the query.
1926
-        switch ($status) {
1927
-            case 'month':
1928
-            case 'today':
1929
-            case null:
1930
-            case 'all':
1931
-                break;
1932
-            case 'draft':
1933
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1934
-                break;
1935
-            default:
1936
-                $where['status'] = $status;
1937
-        }
1938
-        // categories?
1939
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1940
-            ? $this->_req_data['EVT_CAT'] : null;
1941
-        if (! empty($category)) {
1942
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1943
-            $where['Term_Taxonomy.term_id'] = $category;
1944
-        }
1945
-        // date where conditions
1946
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1947
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1948
-            $DateTime = new DateTime(
1949
-                $year_r . '-' . $month_r . '-01 00:00:00',
1950
-                new DateTimeZone('UTC')
1951
-            );
1952
-            $start = $DateTime->getTimestamp();
1953
-            // set the datetime to be the end of the month
1954
-            $DateTime->setDate(
1955
-                $year_r,
1956
-                $month_r,
1957
-                $DateTime->format('t')
1958
-            )->setTime(23, 59, 59);
1959
-            $end = $DateTime->getTimestamp();
1960
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1961
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1962
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1963
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1964
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1965
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1966
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1967
-            $now = date('Y-m-01');
1968
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1969
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1970
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1971
-                            ->setTime(23, 59, 59)
1972
-                            ->format(implode(' ', $start_formats));
1973
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1974
-        }
1975
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1976
-            $where['EVT_wp_user'] = get_current_user_id();
1977
-        } elseif (
1978
-            ! isset($where['status'])
1979
-                  && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
1980
-        ) {
1981
-            $where['OR'] = [
1982
-                'status*restrict_private' => ['!=', 'private'],
1983
-                'AND'                     => [
1984
-                    'status*inclusive' => ['=', 'private'],
1985
-                    'EVT_wp_user'      => get_current_user_id(),
1986
-                ],
1987
-            ];
1988
-        }
1989
-
1990
-        if (
1991
-            isset($this->_req_data['EVT_wp_user'])
1992
-            && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
1993
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1994
-        ) {
1995
-            $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1996
-        }
1997
-        // search query handling
1998
-        if (isset($this->_req_data['s'])) {
1999
-            $search_string = '%' . $this->_req_data['s'] . '%';
2000
-            $where['OR'] = [
2001
-                'EVT_name'       => ['LIKE', $search_string],
2002
-                'EVT_desc'       => ['LIKE', $search_string],
2003
-                'EVT_short_desc' => ['LIKE', $search_string],
2004
-            ];
2005
-        }
2006
-        // filter events by venue.
2007
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2008
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2009
-        }
2010
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2011
-        $query_params = apply_filters(
2012
-            'FHEE__Events_Admin_Page__get_events__query_params',
2013
-            [
2014
-                $where,
2015
-                'limit'    => $limit,
2016
-                'order_by' => $orderby,
2017
-                'order'    => $order,
2018
-                'group_by' => 'EVT_ID',
2019
-            ],
2020
-            $this->_req_data
2021
-        );
2022
-
2023
-        // let's first check if we have special requests coming in.
2024
-        if (isset($this->_req_data['active_status'])) {
2025
-            switch ($this->_req_data['active_status']) {
2026
-                case 'upcoming':
2027
-                    return $EEME->get_upcoming_events($query_params, $count);
2028
-                    break;
2029
-                case 'expired':
2030
-                    return $EEME->get_expired_events($query_params, $count);
2031
-                    break;
2032
-                case 'active':
2033
-                    return $EEME->get_active_events($query_params, $count);
2034
-                    break;
2035
-                case 'inactive':
2036
-                    return $EEME->get_inactive_events($query_params, $count);
2037
-                    break;
2038
-            }
2039
-        }
2040
-
2041
-        $events = $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2042
-        return $events;
2043
-    }
2044
-
2045
-
2046
-    /**
2047
-     * handling for WordPress CPT actions (trash, restore, delete)
2048
-     *
2049
-     * @param string $post_id
2050
-     * @throws EE_Error
2051
-     * @throws InvalidArgumentException
2052
-     * @throws InvalidDataTypeException
2053
-     * @throws InvalidInterfaceException
2054
-     * @throws ReflectionException
2055
-     */
2056
-    public function trash_cpt_item($post_id)
2057
-    {
2058
-        $this->_req_data['EVT_ID'] = $post_id;
2059
-        $this->_trash_or_restore_event('trash', false);
2060
-    }
2061
-
2062
-
2063
-    /**
2064
-     * @param string $post_id
2065
-     * @throws EE_Error
2066
-     * @throws InvalidArgumentException
2067
-     * @throws InvalidDataTypeException
2068
-     * @throws InvalidInterfaceException
2069
-     * @throws ReflectionException
2070
-     */
2071
-    public function restore_cpt_item($post_id)
2072
-    {
2073
-        $this->_req_data['EVT_ID'] = $post_id;
2074
-        $this->_trash_or_restore_event('draft', false);
2075
-    }
2076
-
2077
-
2078
-    /**
2079
-     * @param string $post_id
2080
-     * @throws EE_Error
2081
-     * @throws InvalidArgumentException
2082
-     * @throws InvalidDataTypeException
2083
-     * @throws InvalidInterfaceException
2084
-     * @throws ReflectionException
2085
-     */
2086
-    public function delete_cpt_item($post_id)
2087
-    {
2088
-        $this->_req_data['EVT_ID'] = $post_id;
2089
-        $this->_delete_event(false);
2090
-    }
2091
-
2092
-
2093
-    /**
2094
-     * _trash_or_restore_event
2095
-     *
2096
-     * @access protected
2097
-     * @param string $event_status
2098
-     * @param bool   $redirect_after
2099
-     * @throws EE_Error
2100
-     * @throws InvalidArgumentException
2101
-     * @throws InvalidDataTypeException
2102
-     * @throws InvalidInterfaceException
2103
-     * @throws ReflectionException
2104
-     */
2105
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2106
-    {
2107
-        // determine the event id and set to array.
2108
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2109
-        // loop thru events
2110
-        if ($EVT_ID) {
2111
-            // clean status
2112
-            $event_status = sanitize_key($event_status);
2113
-            // grab status
2114
-            if (! empty($event_status)) {
2115
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2116
-            } else {
2117
-                $success = false;
2118
-                $msg = esc_html__(
2119
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2120
-                    'event_espresso'
2121
-                );
2122
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2123
-            }
2124
-        } else {
2125
-            $success = false;
2126
-            $msg = esc_html__(
2127
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2128
-                'event_espresso'
2129
-            );
2130
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2131
-        }
2132
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2133
-        if ($redirect_after) {
2134
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2135
-        }
2136
-    }
2137
-
2138
-
2139
-    /**
2140
-     * _trash_or_restore_events
2141
-     *
2142
-     * @access protected
2143
-     * @param string $event_status
2144
-     * @return void
2145
-     * @throws EE_Error
2146
-     * @throws InvalidArgumentException
2147
-     * @throws InvalidDataTypeException
2148
-     * @throws InvalidInterfaceException
2149
-     * @throws ReflectionException
2150
-     */
2151
-    protected function _trash_or_restore_events($event_status = 'trash')
2152
-    {
2153
-        // clean status
2154
-        $event_status = sanitize_key($event_status);
2155
-        // grab status
2156
-        if (! empty($event_status)) {
2157
-            $success = true;
2158
-            // determine the event id and set to array.
2159
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2160
-            // loop thru events
2161
-            foreach ($EVT_IDs as $EVT_ID) {
2162
-                if ($EVT_ID = absint($EVT_ID)) {
2163
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2164
-                    $success = $results !== false ? $success : false;
2165
-                } else {
2166
-                    $msg = sprintf(
2167
-                        esc_html__(
2168
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2169
-                            'event_espresso'
2170
-                        ),
2171
-                        $EVT_ID
2172
-                    );
2173
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2174
-                    $success = false;
2175
-                }
2176
-            }
2177
-        } else {
2178
-            $success = false;
2179
-            $msg = esc_html__(
2180
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2181
-                'event_espresso'
2182
-            );
2183
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2184
-        }
2185
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2186
-        $success = $success ? 2 : false;
2187
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2188
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2189
-    }
2190
-
2191
-
2192
-    /**
2193
-     * _trash_or_restore_events
2194
-     *
2195
-     * @access  private
2196
-     * @param int    $EVT_ID
2197
-     * @param string $event_status
2198
-     * @return bool
2199
-     * @throws EE_Error
2200
-     * @throws InvalidArgumentException
2201
-     * @throws InvalidDataTypeException
2202
-     * @throws InvalidInterfaceException
2203
-     * @throws ReflectionException
2204
-     */
2205
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2206
-    {
2207
-        // grab event id
2208
-        if (! $EVT_ID) {
2209
-            $msg = esc_html__(
2210
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2211
-                'event_espresso'
2212
-            );
2213
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2214
-            return false;
2215
-        }
2216
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2217
-        // clean status
2218
-        $event_status = sanitize_key($event_status);
2219
-        // grab status
2220
-        if (empty($event_status)) {
2221
-            $msg = esc_html__(
2222
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2223
-                'event_espresso'
2224
-            );
2225
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2226
-            return false;
2227
-        }
2228
-        // was event trashed or restored ?
2229
-        switch ($event_status) {
2230
-            case 'draft':
2231
-                $action = 'restored from the trash';
2232
-                $hook = 'AHEE_event_restored_from_trash';
2233
-                break;
2234
-            case 'trash':
2235
-                $action = 'moved to the trash';
2236
-                $hook = 'AHEE_event_moved_to_trash';
2237
-                break;
2238
-            default:
2239
-                $action = 'updated';
2240
-                $hook = false;
2241
-        }
2242
-        // use class to change status
2243
-        $this->_cpt_model_obj->set_status($event_status);
2244
-        $success = $this->_cpt_model_obj->save();
2245
-        if ($success === false) {
2246
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2247
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2248
-            return false;
2249
-        }
2250
-        if ($hook) {
2251
-            do_action($hook);
2252
-        }
2253
-        return true;
2254
-    }
2255
-
2256
-
2257
-    /**
2258
-     * _delete_event
2259
-     *
2260
-     * @access protected
2261
-     * @param bool $redirect_after
2262
-     * @throws EE_Error
2263
-     * @throws InvalidArgumentException
2264
-     * @throws InvalidDataTypeException
2265
-     * @throws InvalidInterfaceException
2266
-     * @throws ReflectionException
2267
-     */
2268
-    protected function _delete_event($redirect_after = true)
2269
-    {
2270
-        // determine the event id and set to array.
2271
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2272
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2273
-        // loop thru events
2274
-        if ($EVT_ID) {
2275
-            $success = $this->_permanently_delete_event($EVT_ID);
2276
-            // get list of events with no prices
2277
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
2278
-            // remove this event from the list of events with no prices
2279
-            if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2280
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2281
-            }
2282
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2283
-        } else {
2284
-            $success = false;
2285
-            $msg = esc_html__(
2286
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2287
-                'event_espresso'
2288
-            );
2289
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2290
-        }
2291
-        if ($redirect_after) {
2292
-            $this->_redirect_after_action(
2293
-                $success,
2294
-                'Event',
2295
-                'deleted',
2296
-                ['action' => 'default', 'status' => 'trash']
2297
-            );
2298
-        }
2299
-    }
2300
-
2301
-
2302
-    /**
2303
-     * _delete_events
2304
-     *
2305
-     * @access protected
2306
-     * @return void
2307
-     * @throws EE_Error
2308
-     * @throws InvalidArgumentException
2309
-     * @throws InvalidDataTypeException
2310
-     * @throws InvalidInterfaceException
2311
-     * @throws ReflectionException
2312
-     */
2313
-    protected function _delete_events()
2314
-    {
2315
-        $success = true;
2316
-        // get list of events with no prices
2317
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
2318
-        // determine the event id and set to array.
2319
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2320
-        // loop thru events
2321
-        foreach ($EVT_IDs as $EVT_ID) {
2322
-            $EVT_ID = absint($EVT_ID);
2323
-            if ($EVT_ID) {
2324
-                $results = $this->_permanently_delete_event($EVT_ID);
2325
-                $success = $results !== false ? $success : false;
2326
-                // remove this event from the list of events with no prices
2327
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2328
-            } else {
2329
-                $success = false;
2330
-                $msg = esc_html__(
2331
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2332
-                    'event_espresso'
2333
-                );
2334
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2335
-            }
2336
-        }
2337
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2338
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2339
-        $success = $success ? 2 : false;
2340
-        $this->_redirect_after_action($success, 'Events', 'deleted', ['action' => 'default']);
2341
-    }
2342
-
2343
-
2344
-    /**
2345
-     * _permanently_delete_event
2346
-     *
2347
-     * @access  private
2348
-     * @param int $EVT_ID
2349
-     * @return bool
2350
-     * @throws EE_Error
2351
-     * @throws InvalidArgumentException
2352
-     * @throws InvalidDataTypeException
2353
-     * @throws InvalidInterfaceException
2354
-     * @throws ReflectionException
2355
-     */
2356
-    private function _permanently_delete_event($EVT_ID = 0)
2357
-    {
2358
-        // grab event id
2359
-        if (! $EVT_ID) {
2360
-            $msg = esc_html__(
2361
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2362
-                'event_espresso'
2363
-            );
2364
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2365
-            return false;
2366
-        }
2367
-        if (
2368
-            ! $this->_cpt_model_obj instanceof EE_Event
2369
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2370
-        ) {
2371
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2372
-        }
2373
-        if (! $this->_cpt_model_obj instanceof EE_Event) {
2374
-            return false;
2375
-        }
2376
-        // need to delete related tickets and prices first.
2377
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2378
-        foreach ($datetimes as $datetime) {
2379
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2380
-            $tickets = $datetime->get_many_related('Ticket');
2381
-            foreach ($tickets as $ticket) {
2382
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2383
-                $ticket->delete_related_permanently('Price');
2384
-                $ticket->delete_permanently();
2385
-            }
2386
-            $datetime->delete();
2387
-        }
2388
-        // what about related venues or terms?
2389
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2390
-        foreach ($venues as $venue) {
2391
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2392
-        }
2393
-        // any attached question groups?
2394
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2395
-        if (! empty($question_groups)) {
2396
-            foreach ($question_groups as $question_group) {
2397
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2398
-            }
2399
-        }
2400
-        // Message Template Groups
2401
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2402
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2403
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2404
-        foreach ($term_taxonomies as $term_taxonomy) {
2405
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2406
-        }
2407
-        $success = $this->_cpt_model_obj->delete_permanently();
2408
-        // did it all go as planned ?
2409
-        if ($success) {
2410
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2411
-            EE_Error::add_success($msg);
2412
-        } else {
2413
-            $msg = sprintf(
2414
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2415
-                $EVT_ID
2416
-            );
2417
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2418
-            return false;
2419
-        }
2420
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2421
-        return true;
2422
-    }
2423
-
2424
-
2425
-    /**
2426
-     * get total number of events
2427
-     *
2428
-     * @access public
2429
-     * @return int
2430
-     * @throws EE_Error
2431
-     * @throws InvalidArgumentException
2432
-     * @throws InvalidDataTypeException
2433
-     * @throws InvalidInterfaceException
2434
-     */
2435
-    public function total_events()
2436
-    {
2437
-        $count = EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2438
-        return $count;
2439
-    }
2440
-
2441
-
2442
-    /**
2443
-     * get total number of draft events
2444
-     *
2445
-     * @access public
2446
-     * @return int
2447
-     * @throws EE_Error
2448
-     * @throws InvalidArgumentException
2449
-     * @throws InvalidDataTypeException
2450
-     * @throws InvalidInterfaceException
2451
-     */
2452
-    public function total_events_draft()
2453
-    {
2454
-        $where = [
2455
-            'status' => ['IN', ['draft', 'auto-draft']],
2456
-        ];
2457
-        $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2458
-        return $count;
2459
-    }
2460
-
2461
-
2462
-    /**
2463
-     * get total number of trashed events
2464
-     *
2465
-     * @access public
2466
-     * @return int
2467
-     * @throws EE_Error
2468
-     * @throws InvalidArgumentException
2469
-     * @throws InvalidDataTypeException
2470
-     * @throws InvalidInterfaceException
2471
-     */
2472
-    public function total_trashed_events()
2473
-    {
2474
-        $where = [
2475
-            'status' => 'trash',
2476
-        ];
2477
-        $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2478
-        return $count;
2479
-    }
2480
-
2481
-
2482
-    /**
2483
-     *    _default_event_settings
2484
-     *    This generates the Default Settings Tab
2485
-     *
2486
-     * @return void
2487
-     * @throws DomainException
2488
-     * @throws EE_Error
2489
-     * @throws InvalidArgumentException
2490
-     * @throws InvalidDataTypeException
2491
-     * @throws InvalidInterfaceException
2492
-     */
2493
-    protected function _default_event_settings()
2494
-    {
2495
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2496
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2497
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2498
-        $this->display_admin_page_with_sidebar();
2499
-    }
2500
-
2501
-
2502
-    /**
2503
-     * Return the form for event settings.
2504
-     *
2505
-     * @return EE_Form_Section_Proper
2506
-     * @throws EE_Error
2507
-     */
2508
-    protected function _default_event_settings_form()
2509
-    {
2510
-        $registration_config = EE_Registry::instance()->CFG->registration;
2511
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2512
-        // exclude
2513
-            [
2514
-                EEM_Registration::status_id_cancelled,
2515
-                EEM_Registration::status_id_declined,
2516
-                EEM_Registration::status_id_incomplete,
2517
-                EEM_Registration::status_id_wait_list,
2518
-            ],
2519
-            true
2520
-        );
2521
-        return new EE_Form_Section_Proper(
2522
-            [
2523
-                'name'            => 'update_default_event_settings',
2524
-                'html_id'         => 'update_default_event_settings',
2525
-                'html_class'      => 'form-table',
2526
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2527
-                'subsections'     => apply_filters(
2528
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2529
-                    [
2530
-                        'default_reg_status'  => new EE_Select_Input(
2531
-                            $registration_stati_for_selection,
2532
-                            [
2533
-                                'default'         => isset($registration_config->default_STS_ID)
2534
-                                                     && array_key_exists(
2535
-                                                         $registration_config->default_STS_ID,
2536
-                                                         $registration_stati_for_selection
2537
-                                                     )
2538
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2539
-                                    : EEM_Registration::status_id_pending_payment,
2540
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2541
-                                                     . EEH_Template::get_help_tab_link(
2542
-                                                         'default_settings_status_help_tab'
2543
-                                                     ),
2544
-                                'html_help_text'  => esc_html__(
2545
-                                    '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.',
2546
-                                    'event_espresso'
2547
-                                ),
2548
-                            ]
2549
-                        ),
2550
-                        'default_max_tickets' => new EE_Integer_Input(
2551
-                            [
2552
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2553
-                                    ? $registration_config->default_maximum_number_of_tickets
2554
-                                    : EEM_Event::get_default_additional_limit(),
2555
-                                'html_label_text' => esc_html__(
2556
-                                    'Default Maximum Tickets Allowed Per Order:',
2557
-                                    'event_espresso'
2558
-                                )
2559
-                                                     . EEH_Template::get_help_tab_link(
2560
-                                                         'default_maximum_tickets_help_tab"'
2561
-                                                     ),
2562
-                                'html_help_text'  => esc_html__(
2563
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2564
-                                    'event_espresso'
2565
-                                ),
2566
-                            ]
2567
-                        ),
2568
-                    ]
2569
-                ),
2570
-            ]
2571
-        );
2572
-    }
2573
-
2574
-
2575
-    /**
2576
-     * @return void
2577
-     * @throws EE_Error
2578
-     * @throws InvalidArgumentException
2579
-     * @throws InvalidDataTypeException
2580
-     * @throws InvalidInterfaceException
2581
-     */
2582
-    protected function _update_default_event_settings()
2583
-    {
2584
-        $form = $this->_default_event_settings_form();
2585
-        if ($form->was_submitted()) {
2586
-            $form->receive_form_submission();
2587
-            if ($form->is_valid()) {
2588
-                $registration_config = EE_Registry::instance()->CFG->registration;
2589
-                $valid_data = $form->valid_data();
2590
-                if (isset($valid_data['default_reg_status'])) {
2591
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2592
-                }
2593
-                if (isset($valid_data['default_max_tickets'])) {
2594
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2595
-                }
2596
-                do_action(
2597
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2598
-                    $valid_data,
2599
-                    EE_Registry::instance()->CFG,
2600
-                    $this
2601
-                );
2602
-                // update because data was valid!
2603
-                EE_Registry::instance()->CFG->update_espresso_config();
2604
-                EE_Error::overwrite_success();
2605
-                EE_Error::add_success(
2606
-                    __('Default Event Settings were updated', 'event_espresso')
2607
-                );
2608
-            }
2609
-        }
2610
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2611
-    }
2612
-
2613
-
2614
-    /*************        Templates        *************/
2615
-    protected function _template_settings()
2616
-    {
2617
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2618
-        $this->_template_args['preview_img'] = '<img src="'
2619
-                                               . EVENTS_ASSETS_URL
2620
-                                               . '/images/'
2621
-                                               . 'caffeinated_template_features.jpg" alt="'
2622
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2623
-                                               . '" />';
2624
-        $this->_template_args['preview_text'] = '<strong>'
2625
-                                                . esc_html__(
2626
-                                                    '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.',
2627
-                                                    'event_espresso'
2628
-                                                ) . '</strong>';
2629
-        $this->display_admin_caf_preview_page('template_settings_tab');
2630
-    }
2631
-
2632
-
2633
-    /** Event Category Stuff **/
2634
-    /**
2635
-     * set the _category property with the category object for the loaded page.
2636
-     *
2637
-     * @access private
2638
-     * @return void
2639
-     */
2640
-    private function _set_category_object()
2641
-    {
2642
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2643
-            return;
2644
-        } //already have the category object so get out.
2645
-        // set default category object
2646
-        $this->_set_empty_category_object();
2647
-        // only set if we've got an id
2648
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2649
-            return;
2650
-        }
2651
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2652
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2653
-        if (! empty($term)) {
2654
-            $this->_category->category_name = $term->name;
2655
-            $this->_category->category_identifier = $term->slug;
2656
-            $this->_category->category_desc = $term->description;
2657
-            $this->_category->id = $term->term_id;
2658
-            $this->_category->parent = $term->parent;
2659
-        }
2660
-    }
2661
-
2662
-
2663
-    /**
2664
-     * Clears out category properties.
2665
-     */
2666
-    private function _set_empty_category_object()
2667
-    {
2668
-        $this->_category = new stdClass();
2669
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2670
-        $this->_category->id = $this->_category->parent = 0;
2671
-    }
2672
-
2673
-
2674
-    /**
2675
-     * @throws DomainException
2676
-     * @throws EE_Error
2677
-     * @throws InvalidArgumentException
2678
-     * @throws InvalidDataTypeException
2679
-     * @throws InvalidInterfaceException
2680
-     */
2681
-    protected function _category_list_table()
2682
-    {
2683
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2684
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2685
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2686
-            'add_category',
2687
-            'add_category',
2688
-            [],
2689
-            'add-new-h2'
2690
-        );
2691
-        $this->display_admin_list_table_page_with_sidebar();
2692
-    }
2693
-
2694
-
2695
-    /**
2696
-     * Output category details view.
2697
-     *
2698
-     * @param string $view
2699
-     * @throws DomainException
2700
-     * @throws EE_Error
2701
-     * @throws InvalidArgumentException
2702
-     * @throws InvalidDataTypeException
2703
-     * @throws InvalidInterfaceException
2704
-     */
2705
-    protected function _category_details($view)
2706
-    {
2707
-        // load formatter helper
2708
-        // load field generator helper
2709
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2710
-        $this->_set_add_edit_form_tags($route);
2711
-        $this->_set_category_object();
2712
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2713
-        $delete_action = 'delete_category';
2714
-        // custom redirect
2715
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2716
-            ['action' => 'category_list'],
2717
-            $this->_admin_base_url
2718
-        );
2719
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2720
-        // take care of contents
2721
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2722
-        $this->display_admin_page_with_sidebar();
2723
-    }
2724
-
2725
-
2726
-    /**
2727
-     * Output category details content.
2728
-     *
2729
-     * @throws DomainException
2730
-     */
2731
-    protected function _category_details_content()
2732
-    {
2733
-        $editor_args['category_desc'] = [
2734
-            'type'          => 'wp_editor',
2735
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2736
-            'class'         => 'my_editor_custom',
2737
-            'wpeditor_args' => ['media_buttons' => false],
2738
-        ];
2739
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2740
-        $all_terms = get_terms(
2741
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2742
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2743
-        );
2744
-        // setup category select for term parents.
2745
-        $category_select_values[] = [
2746
-            'text' => esc_html__('No Parent', 'event_espresso'),
2747
-            'id'   => 0,
2748
-        ];
2749
-        foreach ($all_terms as $term) {
2750
-            $category_select_values[] = [
2751
-                'text' => $term->name,
2752
-                'id'   => $term->term_id,
2753
-            ];
2754
-        }
2755
-        $category_select = EEH_Form_Fields::select_input(
2756
-            'category_parent',
2757
-            $category_select_values,
2758
-            $this->_category->parent
2759
-        );
2760
-        $template_args = [
2761
-            'category'                 => $this->_category,
2762
-            'category_select'          => $category_select,
2763
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2764
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2765
-            'disable'                  => '',
2766
-            'disabled_message'         => false,
2767
-        ];
2768
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2769
-        return EEH_Template::display_template($template, $template_args, true);
2770
-    }
2771
-
2772
-
2773
-    /**
2774
-     * Handles deleting categories.
2775
-     */
2776
-    protected function _delete_categories()
2777
-    {
2778
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2779
-            : (array) $this->_req_data['category_id'];
2780
-        foreach ($cat_ids as $cat_id) {
2781
-            $this->_delete_category($cat_id);
2782
-        }
2783
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2784
-        $query_args = [
2785
-            'action' => 'category_list',
2786
-        ];
2787
-        $this->_redirect_after_action(0, '', '', $query_args);
2788
-    }
2789
-
2790
-
2791
-    /**
2792
-     * Handles deleting specific category.
2793
-     *
2794
-     * @param int $cat_id
2795
-     */
2796
-    protected function _delete_category($cat_id)
2797
-    {
2798
-        $cat_id = absint($cat_id);
2799
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2800
-    }
2801
-
2802
-
2803
-    /**
2804
-     * Handles triggering the update or insertion of a new category.
2805
-     *
2806
-     * @param bool $new_category true means we're triggering the insert of a new category.
2807
-     * @throws EE_Error
2808
-     * @throws InvalidArgumentException
2809
-     * @throws InvalidDataTypeException
2810
-     * @throws InvalidInterfaceException
2811
-     */
2812
-    protected function _insert_or_update_category($new_category)
2813
-    {
2814
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2815
-        $success = 0; // we already have a success message so lets not send another.
2816
-        if ($cat_id) {
2817
-            $query_args = [
2818
-                'action'     => 'edit_category',
2819
-                'EVT_CAT_ID' => $cat_id,
2820
-            ];
2821
-        } else {
2822
-            $query_args = ['action' => 'add_category'];
2823
-        }
2824
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2825
-    }
2826
-
2827
-
2828
-    /**
2829
-     * Inserts or updates category
2830
-     *
2831
-     * @param bool $update (true indicates we're updating a category).
2832
-     * @return bool|mixed|string
2833
-     */
2834
-    private function _insert_category($update = false)
2835
-    {
2836
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2837
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2838
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2839
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2840
-        if (empty($category_name)) {
2841
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2842
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2843
-            return false;
2844
-        }
2845
-        $term_args = [
2846
-            'name'        => $category_name,
2847
-            'description' => $category_desc,
2848
-            'parent'      => $category_parent,
2849
-        ];
2850
-        // was the category_identifier input disabled?
2851
-        if (isset($this->_req_data['category_identifier'])) {
2852
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2853
-        }
2854
-        $insert_ids = $update
2855
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2856
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2857
-        if (! is_array($insert_ids)) {
2858
-            $msg = esc_html__(
2859
-                'An error occurred and the category has not been saved to the database.',
2860
-                'event_espresso'
2861
-            );
2862
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2863
-        } else {
2864
-            $cat_id = $insert_ids['term_id'];
2865
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2866
-            EE_Error::add_success($msg);
2867
-        }
2868
-        return $cat_id;
2869
-    }
2870
-
2871
-
2872
-    /**
2873
-     * Gets categories or count of categories matching the arguments in the request.
2874
-     *
2875
-     * @param int  $per_page
2876
-     * @param int  $current_page
2877
-     * @param bool $count
2878
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2879
-     * @throws EE_Error
2880
-     * @throws InvalidArgumentException
2881
-     * @throws InvalidDataTypeException
2882
-     * @throws InvalidInterfaceException
2883
-     */
2884
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2885
-    {
2886
-        // testing term stuff
2887
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2888
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2889
-        $limit = ($current_page - 1) * $per_page;
2890
-        $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2891
-        if (isset($this->_req_data['s'])) {
2892
-            $sstr = '%' . $this->_req_data['s'] . '%';
2893
-            $where['OR'] = [
2894
-                'Term.name'   => ['LIKE', $sstr],
2895
-                'description' => ['LIKE', $sstr],
2896
-            ];
2897
-        }
2898
-        $query_params = [
2899
-            $where,
2900
-            'order_by'   => [$orderby => $order],
2901
-            'limit'      => $limit . ',' . $per_page,
2902
-            'force_join' => ['Term'],
2903
-        ];
2904
-        $categories = $count
2905
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2906
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2907
-        return $categories;
2908
-    }
2909
-
2910
-    /* end category stuff */
2911
-    /**************/
2912
-
2913
-
2914
-    /**
2915
-     * Callback for the `ee_save_timezone_setting` ajax action.
2916
-     *
2917
-     * @throws EE_Error
2918
-     * @throws InvalidArgumentException
2919
-     * @throws InvalidDataTypeException
2920
-     * @throws InvalidInterfaceException
2921
-     */
2922
-    public function save_timezonestring_setting()
2923
-    {
2924
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2925
-            ? $this->_req_data['timezone_selected']
2926
-            : '';
2927
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2928
-            EE_Error::add_error(
2929
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2930
-                __FILE__,
2931
-                __FUNCTION__,
2932
-                __LINE__
2933
-            );
2934
-            $this->_template_args['error'] = true;
2935
-            $this->_return_json();
2936
-        }
2937
-
2938
-        update_option('timezone_string', $timezone_string);
2939
-        EE_Error::add_success(
2940
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2941
-        );
2942
-        $this->_template_args['success'] = true;
2943
-        $this->_return_json(true, ['action' => 'create_new']);
2944
-    }
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @access protected
23
+	 * @var EE_Event $_event
24
+	 */
25
+	protected $_event;
26
+
27
+
28
+	/**
29
+	 * This will hold the category object for category_details screen.
30
+	 *
31
+	 * @var stdClass $_category
32
+	 */
33
+	protected $_category;
34
+
35
+
36
+	/**
37
+	 * @var EEM_Event $_event_model
38
+	 */
39
+	protected $_event_model;
40
+
41
+	/**
42
+	 * @var EEM_Datetime $datetime_model
43
+	 */
44
+	protected $datetime_model;
45
+
46
+	/**
47
+	 * @var EEM_Ticket $ticket_model
48
+	 */
49
+	protected $ticket_model;
50
+
51
+
52
+	/**
53
+	 * @var EE_Event
54
+	 */
55
+	protected $_cpt_model_obj;
56
+
57
+
58
+	/**
59
+	 * Initialize page props for this admin page group.
60
+	 */
61
+	protected function _init_page_props()
62
+	{
63
+		$this->page_slug = EVENTS_PG_SLUG;
64
+		$this->page_label = EVENTS_LABEL;
65
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
66
+		$this->_admin_base_path = EVENTS_ADMIN;
67
+		$this->_cpt_model_names = [
68
+			'create_new' => 'EEM_Event',
69
+			'edit'       => 'EEM_Event',
70
+		];
71
+		$this->_cpt_edit_routes = [
72
+			'espresso_events' => 'edit',
73
+		];
74
+		add_action(
75
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
76
+			[$this, 'verify_event_edit'],
77
+			10,
78
+			2
79
+		);
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets the ajax hooks used for this admin page group.
85
+	 */
86
+	protected function _ajax_hooks()
87
+	{
88
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
89
+	}
90
+
91
+
92
+	/**
93
+	 * Sets the page properties for this admin page group.
94
+	 */
95
+	protected function _define_page_props()
96
+	{
97
+		$this->_admin_page_title = EVENTS_LABEL;
98
+		$this->_labels = [
99
+			'buttons'      => [
100
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
101
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
102
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
103
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
104
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
105
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
106
+			],
107
+			'editor_title' => [
108
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
109
+			],
110
+			'publishbox'   => [
111
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
112
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
113
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
114
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
115
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
116
+			],
117
+		];
118
+	}
119
+
120
+
121
+	/**
122
+	 * Sets the page routes property for this admin page group.
123
+	 */
124
+	protected function _set_page_routes()
125
+	{
126
+		// load formatter helper
127
+		// load field generator helper
128
+		// is there a evt_id in the request?
129
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
130
+			? $this->_req_data['EVT_ID']
131
+			: 0;
132
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
133
+		$this->_page_routes = [
134
+			'default'                       => [
135
+				'func'       => '_events_overview_list_table',
136
+				'capability' => 'ee_read_events',
137
+			],
138
+			'create_new'                    => [
139
+				'func'       => '_create_new_cpt_item',
140
+				'capability' => 'ee_edit_events',
141
+			],
142
+			'edit'                          => [
143
+				'func'       => '_edit_cpt_item',
144
+				'capability' => 'ee_edit_event',
145
+				'obj_id'     => $evt_id,
146
+			],
147
+			'copy_event'                    => [
148
+				'func'       => '_copy_events',
149
+				'capability' => 'ee_edit_event',
150
+				'obj_id'     => $evt_id,
151
+				'noheader'   => true,
152
+			],
153
+			'trash_event'                   => [
154
+				'func'       => '_trash_or_restore_event',
155
+				'args'       => ['event_status' => 'trash'],
156
+				'capability' => 'ee_delete_event',
157
+				'obj_id'     => $evt_id,
158
+				'noheader'   => true,
159
+			],
160
+			'trash_events'                  => [
161
+				'func'       => '_trash_or_restore_events',
162
+				'args'       => ['event_status' => 'trash'],
163
+				'capability' => 'ee_delete_events',
164
+				'noheader'   => true,
165
+			],
166
+			'restore_event'                 => [
167
+				'func'       => '_trash_or_restore_event',
168
+				'args'       => ['event_status' => 'draft'],
169
+				'capability' => 'ee_delete_event',
170
+				'obj_id'     => $evt_id,
171
+				'noheader'   => true,
172
+			],
173
+			'restore_events'                => [
174
+				'func'       => '_trash_or_restore_events',
175
+				'args'       => ['event_status' => 'draft'],
176
+				'capability' => 'ee_delete_events',
177
+				'noheader'   => true,
178
+			],
179
+			'delete_event'                  => [
180
+				'func'       => '_delete_event',
181
+				'capability' => 'ee_delete_event',
182
+				'obj_id'     => $evt_id,
183
+				'noheader'   => true,
184
+			],
185
+			'delete_events'                 => [
186
+				'func'       => '_delete_events',
187
+				'capability' => 'ee_delete_events',
188
+				'noheader'   => true,
189
+			],
190
+			'view_report'                   => [
191
+				'func'       => '_view_report',
192
+				'capability' => 'ee_edit_events',
193
+			],
194
+			'default_event_settings'        => [
195
+				'func'       => '_default_event_settings',
196
+				'capability' => 'manage_options',
197
+			],
198
+			'update_default_event_settings' => [
199
+				'func'       => '_update_default_event_settings',
200
+				'capability' => 'manage_options',
201
+				'noheader'   => true,
202
+			],
203
+			'template_settings'             => [
204
+				'func'       => '_template_settings',
205
+				'capability' => 'manage_options',
206
+			],
207
+			// event category tab related
208
+			'add_category'                  => [
209
+				'func'       => '_category_details',
210
+				'capability' => 'ee_edit_event_category',
211
+				'args'       => ['add'],
212
+			],
213
+			'edit_category'                 => [
214
+				'func'       => '_category_details',
215
+				'capability' => 'ee_edit_event_category',
216
+				'args'       => ['edit'],
217
+			],
218
+			'delete_categories'             => [
219
+				'func'       => '_delete_categories',
220
+				'capability' => 'ee_delete_event_category',
221
+				'noheader'   => true,
222
+			],
223
+			'delete_category'               => [
224
+				'func'       => '_delete_categories',
225
+				'capability' => 'ee_delete_event_category',
226
+				'noheader'   => true,
227
+			],
228
+			'insert_category'               => [
229
+				'func'       => '_insert_or_update_category',
230
+				'args'       => ['new_category' => true],
231
+				'capability' => 'ee_edit_event_category',
232
+				'noheader'   => true,
233
+			],
234
+			'update_category'               => [
235
+				'func'       => '_insert_or_update_category',
236
+				'args'       => ['new_category' => false],
237
+				'capability' => 'ee_edit_event_category',
238
+				'noheader'   => true,
239
+			],
240
+			'category_list'                 => [
241
+				'func'       => '_category_list_table',
242
+				'capability' => 'ee_manage_event_categories',
243
+			],
244
+		];
245
+	}
246
+
247
+
248
+	/**
249
+	 * Set the _page_config property for this admin page group.
250
+	 */
251
+	protected function _set_page_config()
252
+	{
253
+		$this->_page_config = [
254
+			'default'                => [
255
+				'nav'           => [
256
+					'label' => esc_html__('Overview', 'event_espresso'),
257
+					'order' => 10,
258
+				],
259
+				'list_table'    => 'Events_Admin_List_Table',
260
+				'help_tabs'     => [
261
+					'events_overview_help_tab'                       => [
262
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
263
+						'filename' => 'events_overview',
264
+					],
265
+					'events_overview_table_column_headings_help_tab' => [
266
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
267
+						'filename' => 'events_overview_table_column_headings',
268
+					],
269
+					'events_overview_filters_help_tab'               => [
270
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
271
+						'filename' => 'events_overview_filters',
272
+					],
273
+					'events_overview_view_help_tab'                  => [
274
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
275
+						'filename' => 'events_overview_views',
276
+					],
277
+					'events_overview_other_help_tab'                 => [
278
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
279
+						'filename' => 'events_overview_other',
280
+					],
281
+				],
282
+				'help_tour'     => [
283
+					'Event_Overview_Help_Tour',
284
+					// 'New_Features_Test_Help_Tour' for testing multiple help tour
285
+				],
286
+				'require_nonce' => false,
287
+				'qtips'         => ['EE_Event_List_Table_Tips'],
288
+			],
289
+			'create_new'             => [
290
+				'nav'           => [
291
+					'label'      => esc_html__('Add Event', 'event_espresso'),
292
+					'order'      => 5,
293
+					'persistent' => false,
294
+				],
295
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
296
+				'help_tabs'     => [
297
+					'event_editor_help_tab'                            => [
298
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
299
+						'filename' => 'event_editor',
300
+					],
301
+					'event_editor_title_richtexteditor_help_tab'       => [
302
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
303
+						'filename' => 'event_editor_title_richtexteditor',
304
+					],
305
+					'event_editor_venue_details_help_tab'              => [
306
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
307
+						'filename' => 'event_editor_venue_details',
308
+					],
309
+					'event_editor_event_datetimes_help_tab'            => [
310
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
311
+						'filename' => 'event_editor_event_datetimes',
312
+					],
313
+					'event_editor_event_tickets_help_tab'              => [
314
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
315
+						'filename' => 'event_editor_event_tickets',
316
+					],
317
+					'event_editor_event_registration_options_help_tab' => [
318
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
319
+						'filename' => 'event_editor_event_registration_options',
320
+					],
321
+					'event_editor_tags_categories_help_tab'            => [
322
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
323
+						'filename' => 'event_editor_tags_categories',
324
+					],
325
+					'event_editor_questions_registrants_help_tab'      => [
326
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
327
+						'filename' => 'event_editor_questions_registrants',
328
+					],
329
+					'event_editor_save_new_event_help_tab'             => [
330
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
331
+						'filename' => 'event_editor_save_new_event',
332
+					],
333
+					'event_editor_other_help_tab'                      => [
334
+						'title'    => esc_html__('Event Other', 'event_espresso'),
335
+						'filename' => 'event_editor_other',
336
+					],
337
+				],
338
+				'help_tour'     => [
339
+					'Event_Editor_Help_Tour',
340
+				],
341
+				'require_nonce' => false,
342
+			],
343
+			'edit'                   => [
344
+				'nav'           => [
345
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
346
+					'order'      => 5,
347
+					'persistent' => false,
348
+					'url'        => isset($this->_req_data['post'])
349
+						? EE_Admin_Page::add_query_args_and_nonce(
350
+							['post' => $this->_req_data['post'], 'action' => 'edit'],
351
+							$this->_current_page_view_url
352
+						)
353
+						: $this->_admin_base_url,
354
+				],
355
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
356
+				'help_tabs'     => [
357
+					'event_editor_help_tab'                            => [
358
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
359
+						'filename' => 'event_editor',
360
+					],
361
+					'event_editor_title_richtexteditor_help_tab'       => [
362
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
363
+						'filename' => 'event_editor_title_richtexteditor',
364
+					],
365
+					'event_editor_venue_details_help_tab'              => [
366
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
367
+						'filename' => 'event_editor_venue_details',
368
+					],
369
+					'event_editor_event_datetimes_help_tab'            => [
370
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
371
+						'filename' => 'event_editor_event_datetimes',
372
+					],
373
+					'event_editor_event_tickets_help_tab'              => [
374
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
375
+						'filename' => 'event_editor_event_tickets',
376
+					],
377
+					'event_editor_event_registration_options_help_tab' => [
378
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
379
+						'filename' => 'event_editor_event_registration_options',
380
+					],
381
+					'event_editor_tags_categories_help_tab'            => [
382
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
383
+						'filename' => 'event_editor_tags_categories',
384
+					],
385
+					'event_editor_questions_registrants_help_tab'      => [
386
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
387
+						'filename' => 'event_editor_questions_registrants',
388
+					],
389
+					'event_editor_save_new_event_help_tab'             => [
390
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
391
+						'filename' => 'event_editor_save_new_event',
392
+					],
393
+					'event_editor_other_help_tab'                      => [
394
+						'title'    => esc_html__('Event Other', 'event_espresso'),
395
+						'filename' => 'event_editor_other',
396
+					],
397
+				],
398
+				'require_nonce' => false,
399
+			],
400
+			'default_event_settings' => [
401
+				'nav'           => [
402
+					'label' => esc_html__('Default Settings', 'event_espresso'),
403
+					'order' => 40,
404
+				],
405
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
406
+				'labels'        => [
407
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
408
+				],
409
+				'help_tabs'     => [
410
+					'default_settings_help_tab'        => [
411
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
412
+						'filename' => 'events_default_settings',
413
+					],
414
+					'default_settings_status_help_tab' => [
415
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
416
+						'filename' => 'events_default_settings_status',
417
+					],
418
+					'default_maximum_tickets_help_tab' => [
419
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
420
+						'filename' => 'events_default_settings_max_tickets',
421
+					],
422
+				],
423
+				'help_tour'     => ['Event_Default_Settings_Help_Tour'],
424
+				'require_nonce' => false,
425
+			],
426
+			// template settings
427
+			'template_settings'      => [
428
+				'nav'           => [
429
+					'label' => esc_html__('Templates', 'event_espresso'),
430
+					'order' => 30,
431
+				],
432
+				'metaboxes'     => $this->_default_espresso_metaboxes,
433
+				'help_tabs'     => [
434
+					'general_settings_templates_help_tab' => [
435
+						'title'    => esc_html__('Templates', 'event_espresso'),
436
+						'filename' => 'general_settings_templates',
437
+					],
438
+				],
439
+				'help_tour'     => ['Templates_Help_Tour'],
440
+				'require_nonce' => false,
441
+			],
442
+			// event category stuff
443
+			'add_category'           => [
444
+				'nav'           => [
445
+					'label'      => esc_html__('Add Category', 'event_espresso'),
446
+					'order'      => 15,
447
+					'persistent' => false,
448
+				],
449
+				'help_tabs'     => [
450
+					'add_category_help_tab' => [
451
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
452
+						'filename' => 'events_add_category',
453
+					],
454
+				],
455
+				'help_tour'     => ['Event_Add_Category_Help_Tour'],
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'        => isset($this->_req_data['EVT_CAT_ID'])
465
+						? add_query_arg(
466
+							['EVT_CAT_ID' => $this->_req_data['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
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
478
+				'metaboxes'     => ['_publish_post_box'],
479
+				'require_nonce' => false,
480
+			],
481
+			'category_list'          => [
482
+				'nav'           => [
483
+					'label' => esc_html__('Categories', 'event_espresso'),
484
+					'order' => 20,
485
+				],
486
+				'list_table'    => 'Event_Categories_Admin_List_Table',
487
+				'help_tabs'     => [
488
+					'events_categories_help_tab'                       => [
489
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
490
+						'filename' => 'events_categories',
491
+					],
492
+					'events_categories_table_column_headings_help_tab' => [
493
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
+						'filename' => 'events_categories_table_column_headings',
495
+					],
496
+					'events_categories_view_help_tab'                  => [
497
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
+						'filename' => 'events_categories_views',
499
+					],
500
+					'events_categories_other_help_tab'                 => [
501
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
+						'filename' => 'events_categories_other',
503
+					],
504
+				],
505
+				'help_tour'     => [
506
+					'Event_Categories_Help_Tour',
507
+				],
508
+				'metaboxes'     => $this->_default_espresso_metaboxes,
509
+				'require_nonce' => false,
510
+			],
511
+		];
512
+		// only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
513
+		$domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
514
+		if (! $domain->isCaffeinated()) {
515
+			$this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
516
+			$this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
517
+		}
518
+	}
519
+
520
+
521
+	/**
522
+	 * Used to register any global screen options if necessary for every route in this admin page group.
523
+	 */
524
+	protected function _add_screen_options()
525
+	{
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing the screen options for the 'default' route.
531
+	 *
532
+	 * @throws InvalidArgumentException
533
+	 * @throws InvalidDataTypeException
534
+	 * @throws InvalidInterfaceException
535
+	 */
536
+	protected function _add_screen_options_default()
537
+	{
538
+		$this->_per_page_screen_option();
539
+	}
540
+
541
+
542
+	/**
543
+	 * Implementing screen options for the category list route.
544
+	 *
545
+	 * @throws InvalidArgumentException
546
+	 * @throws InvalidDataTypeException
547
+	 * @throws InvalidInterfaceException
548
+	 */
549
+	protected function _add_screen_options_category_list()
550
+	{
551
+		$page_title = $this->_admin_page_title;
552
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
553
+		$this->_per_page_screen_option();
554
+		$this->_admin_page_title = $page_title;
555
+	}
556
+
557
+
558
+	/**
559
+	 * Used to register any global feature pointers for the admin page group.
560
+	 */
561
+	protected function _add_feature_pointers()
562
+	{
563
+	}
564
+
565
+
566
+	/**
567
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
568
+	 */
569
+	public function load_scripts_styles()
570
+	{
571
+		wp_register_style(
572
+			'events-admin-css',
573
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
574
+			[],
575
+			EVENT_ESPRESSO_VERSION
576
+		);
577
+		wp_register_style(
578
+			'ee-cat-admin',
579
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
580
+			[],
581
+			EVENT_ESPRESSO_VERSION
582
+		);
583
+		wp_enqueue_style('events-admin-css');
584
+		wp_enqueue_style('ee-cat-admin');
585
+		// scripts
586
+		wp_register_script(
587
+			'event_editor_js',
588
+			EVENTS_ASSETS_URL . 'event_editor.js',
589
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
590
+			EVENT_ESPRESSO_VERSION,
591
+			true
592
+		);
593
+	}
594
+
595
+
596
+	/**
597
+	 * Enqueuing scripts and styles specific to this view
598
+	 */
599
+	public function load_scripts_styles_create_new()
600
+	{
601
+		$this->load_scripts_styles_edit();
602
+	}
603
+
604
+
605
+	/**
606
+	 * Enqueuing scripts and styles specific to this view
607
+	 */
608
+	public function load_scripts_styles_edit()
609
+	{
610
+		// styles
611
+		wp_enqueue_style('espresso-ui-theme');
612
+		wp_register_style(
613
+			'event-editor-css',
614
+			EVENTS_ASSETS_URL . 'event-editor.css',
615
+			['ee-admin-css'],
616
+			EVENT_ESPRESSO_VERSION
617
+		);
618
+		wp_enqueue_style('event-editor-css');
619
+		// scripts
620
+		if (! $this->admin_config->useAdvancedEditor()) {
621
+			wp_register_script(
622
+				'event-datetime-metabox',
623
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
624
+				['event_editor_js', 'ee-datepicker'],
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+			wp_enqueue_script('event-datetime-metabox');
628
+		}
629
+	}
630
+
631
+
632
+	/**
633
+	 * Populating the _views property for the category list table view.
634
+	 */
635
+	protected function _set_list_table_views_category_list()
636
+	{
637
+		$this->_views = [
638
+			'all' => [
639
+				'slug'        => 'all',
640
+				'label'       => esc_html__('All', 'event_espresso'),
641
+				'count'       => 0,
642
+				'bulk_action' => [
643
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
644
+				],
645
+			],
646
+		];
647
+	}
648
+
649
+
650
+	/**
651
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
652
+	 */
653
+	public function admin_init()
654
+	{
655
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
656
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
657
+			'event_espresso'
658
+		);
659
+	}
660
+
661
+
662
+	/**
663
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
664
+	 * group.
665
+	 */
666
+	public function admin_notices()
667
+	{
668
+	}
669
+
670
+
671
+	/**
672
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
673
+	 * this admin page group.
674
+	 */
675
+	public function admin_footer_scripts()
676
+	{
677
+	}
678
+
679
+
680
+	/**
681
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
682
+	 * warning (via EE_Error::add_error());
683
+	 *
684
+	 * @param EE_Event $event Event object
685
+	 * @param string   $req_type
686
+	 * @return void
687
+	 * @throws EE_Error
688
+	 * @access public
689
+	 */
690
+	public function verify_event_edit($event = null, $req_type = '')
691
+	{
692
+		// don't need to do this when processing
693
+		if (! empty($req_type)) {
694
+			return;
695
+		}
696
+		// no event?
697
+		if (! $event instanceof EE_Event) {
698
+			$event = $this->_cpt_model_obj;
699
+		}
700
+		// STILL no event?
701
+		if (! $event instanceof EE_Event) {
702
+			return;
703
+		}
704
+		$orig_status = $event->status();
705
+		// first check if event is active.
706
+		if (
707
+			$orig_status === EEM_Event::cancelled
708
+			|| $orig_status === EEM_Event::postponed
709
+			|| $event->is_expired()
710
+			|| $event->is_inactive()
711
+		) {
712
+			return;
713
+		}
714
+		// made it here so it IS active... next check that any of the tickets are sold.
715
+		if ($event->is_sold_out(true)) {
716
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
717
+				EE_Error::add_attention(
718
+					sprintf(
719
+						esc_html__(
720
+							'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.',
721
+							'event_espresso'
722
+						),
723
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
724
+					)
725
+				);
726
+			}
727
+			return;
728
+		}
729
+		if ($orig_status === EEM_Event::sold_out) {
730
+			EE_Error::add_attention(
731
+				sprintf(
732
+					esc_html__(
733
+						'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.',
734
+						'event_espresso'
735
+					),
736
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
737
+				)
738
+			);
739
+		}
740
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
741
+		if (! $event->tickets_on_sale()) {
742
+			return;
743
+		}
744
+		// made it here so show warning
745
+		$this->_edit_event_warning();
746
+	}
747
+
748
+
749
+	/**
750
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
751
+	 * When needed, hook this into a EE_Error::add_error() notice.
752
+	 *
753
+	 * @access protected
754
+	 * @return void
755
+	 */
756
+	protected function _edit_event_warning()
757
+	{
758
+		// we don't want to add warnings during these requests
759
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
760
+			return;
761
+		}
762
+		EE_Error::add_attention(
763
+			sprintf(
764
+				esc_html__(
765
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
766
+					'event_espresso'
767
+				),
768
+				'<a class="espresso-help-tab-lnk">',
769
+				'</a>'
770
+			)
771
+		);
772
+	}
773
+
774
+
775
+	/**
776
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
777
+	 * Otherwise, do the normal logic
778
+	 *
779
+	 * @throws EE_Error
780
+	 * @throws InvalidArgumentException
781
+	 * @throws InvalidDataTypeException
782
+	 */
783
+	protected function _create_new_cpt_item()
784
+	{
785
+		$has_timezone_string = get_option('timezone_string');
786
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
787
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
788
+			EE_Error::add_attention(
789
+				sprintf(
790
+					__(
791
+						'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',
792
+						'event_espresso'
793
+					),
794
+					'<br>',
795
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
796
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
797
+					. '</select>',
798
+					'<button class="button button-secondary timezone-submit">',
799
+					'</button><span class="spinner"></span>'
800
+				),
801
+				__FILE__,
802
+				__FUNCTION__,
803
+				__LINE__
804
+			);
805
+		}
806
+		parent::_create_new_cpt_item();
807
+	}
808
+
809
+
810
+	/**
811
+	 * Sets the _views property for the default route in this admin page group.
812
+	 */
813
+	protected function _set_list_table_views_default()
814
+	{
815
+		$this->_views = [
816
+			'all'   => [
817
+				'slug'        => 'all',
818
+				'label'       => esc_html__('View All Events', 'event_espresso'),
819
+				'count'       => 0,
820
+				'bulk_action' => [
821
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
822
+				],
823
+			],
824
+			'draft' => [
825
+				'slug'        => 'draft',
826
+				'label'       => esc_html__('Draft', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => [
829
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
830
+				],
831
+			],
832
+		];
833
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
834
+			$this->_views['trash'] = [
835
+				'slug'        => 'trash',
836
+				'label'       => esc_html__('Trash', 'event_espresso'),
837
+				'count'       => 0,
838
+				'bulk_action' => [
839
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
840
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
841
+				],
842
+			];
843
+		}
844
+	}
845
+
846
+
847
+	/**
848
+	 * Provides the legend item array for the default list table view.
849
+	 *
850
+	 * @return array
851
+	 */
852
+	protected function _event_legend_items()
853
+	{
854
+		$items = [
855
+			'view_details'   => [
856
+				'class' => 'dashicons dashicons-search',
857
+				'desc'  => esc_html__('View Event', 'event_espresso'),
858
+			],
859
+			'edit_event'     => [
860
+				'class' => 'ee-icon ee-icon-calendar-edit',
861
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
862
+			],
863
+			'view_attendees' => [
864
+				'class' => 'dashicons dashicons-groups',
865
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
866
+			],
867
+		];
868
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
869
+		$statuses = [
870
+			'sold_out_status'  => [
871
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
872
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
873
+			],
874
+			'active_status'    => [
875
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
876
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
877
+			],
878
+			'upcoming_status'  => [
879
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
880
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
881
+			],
882
+			'postponed_status' => [
883
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
884
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
885
+			],
886
+			'cancelled_status' => [
887
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
888
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
889
+			],
890
+			'expired_status'   => [
891
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
892
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
893
+			],
894
+			'inactive_status'  => [
895
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
896
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
897
+			],
898
+		];
899
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
900
+		return array_merge($items, $statuses);
901
+	}
902
+
903
+
904
+	/**
905
+	 * @return EEM_Event
906
+	 * @throws EE_Error
907
+	 */
908
+	private function eventModel()
909
+	{
910
+		if (! $this->_event_model instanceof EEM_Event) {
911
+			$this->_event_model = EEM_Event::instance();
912
+		}
913
+		return $this->_event_model;
914
+	}
915
+
916
+
917
+	/**
918
+	 * @param string $event_timezone_string
919
+	 * @return EEM_Datetime
920
+	 * @throws EE_Error
921
+	 */
922
+	private function datetimeModel($event_timezone_string = '')
923
+	{
924
+		if (! $this->datetime_model instanceof EEM_Datetime) {
925
+			$this->datetime_model = EEM_Datetime::instance($event_timezone_string);
926
+		}
927
+		return $this->datetime_model;
928
+	}
929
+
930
+
931
+	/**
932
+	 * @param string $event_timezone_string
933
+	 * @return EEM_Ticket
934
+	 * @throws EE_Error
935
+	 */
936
+	private function ticketModel($event_timezone_string = '')
937
+	{
938
+		if (! $this->ticket_model instanceof EEM_Ticket) {
939
+			$this->ticket_model = EEM_Ticket::instance($event_timezone_string);
940
+		}
941
+		return $this->ticket_model;
942
+	}
943
+
944
+
945
+	/**
946
+	 * Adds extra buttons to the WP CPT permalink field row.
947
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
948
+	 *
949
+	 * @param string $return    the current html
950
+	 * @param int    $id        the post id for the page
951
+	 * @param string $new_title What the title is
952
+	 * @param string $new_slug  what the slug is
953
+	 * @return string            The new html string for the permalink area
954
+	 */
955
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
956
+	{
957
+		// make sure this is only when editing
958
+		if (! empty($id)) {
959
+			$post = get_post($id);
960
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
961
+					   . esc_html__('Shortcode', 'event_espresso')
962
+					   . '</a> ';
963
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
964
+					   . $post->ID
965
+					   . ']">';
966
+		}
967
+		return $return;
968
+	}
969
+
970
+
971
+	/**
972
+	 * _events_overview_list_table
973
+	 * This contains the logic for showing the events_overview list
974
+	 *
975
+	 * @access protected
976
+	 * @return void
977
+	 * @throws DomainException
978
+	 * @throws EE_Error
979
+	 * @throws InvalidArgumentException
980
+	 * @throws InvalidDataTypeException
981
+	 * @throws InvalidInterfaceException
982
+	 */
983
+	protected function _events_overview_list_table()
984
+	{
985
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
986
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
987
+			? (array) $this->_template_args['after_list_table']
988
+			: [];
989
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
990
+																			  . EEH_Template::get_button_or_link(
991
+																				  get_post_type_archive_link('espresso_events'),
992
+																				  esc_html__('View Event Archive Page', 'event_espresso'),
993
+																				  'button'
994
+																			  );
995
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
996
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
997
+			'create_new',
998
+			'add',
999
+			[],
1000
+			'add-new-h2'
1001
+		);
1002
+		$this->display_admin_list_table_page_with_no_sidebar();
1003
+	}
1004
+
1005
+
1006
+	/**
1007
+	 * this allows for extra misc actions in the default WP publish box
1008
+	 *
1009
+	 * @return void
1010
+	 * @throws DomainException
1011
+	 * @throws EE_Error
1012
+	 * @throws InvalidArgumentException
1013
+	 * @throws InvalidDataTypeException
1014
+	 * @throws InvalidInterfaceException
1015
+	 * @throws ReflectionException
1016
+	 */
1017
+	public function extra_misc_actions_publish_box()
1018
+	{
1019
+		$this->_generate_publish_box_extra_content();
1020
+	}
1021
+
1022
+
1023
+	/**
1024
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1025
+	 * saved.
1026
+	 * Typically you would use this to save any additional data.
1027
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1028
+	 * ALSO very important.  When a post transitions from scheduled to published,
1029
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1030
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1031
+	 *
1032
+	 * @access protected
1033
+	 * @abstract
1034
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1035
+	 * @param object $post    The post object of the cpt that was saved.
1036
+	 * @return void
1037
+	 * @throws EE_Error
1038
+	 * @throws InvalidArgumentException
1039
+	 * @throws InvalidDataTypeException
1040
+	 * @throws InvalidInterfaceException
1041
+	 * @throws ReflectionException
1042
+	 */
1043
+	protected function _insert_update_cpt_item($post_id, $post)
1044
+	{
1045
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1046
+			// get out we're not processing an event save.
1047
+			return;
1048
+		}
1049
+		$event_values = [
1050
+			'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1051
+			'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1052
+			'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1053
+				? sanitize_text_field($this->_req_data['timezone_string'])
1054
+				: null,
1055
+		];
1056
+		/** @var FeatureFlags $flags */
1057
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1058
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1059
+		if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1060
+			$event_values['EVT_display_ticket_selector'] =
1061
+				! empty($this->_req_data['display_ticket_selector'])
1062
+					? 1
1063
+					: 0;
1064
+			$event_values['EVT_additional_limit'] = min(
1065
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1066
+				! empty($this->_req_data['additional_limit'])
1067
+					? absint($this->_req_data['additional_limit'])
1068
+					: null
1069
+			);
1070
+			$event_values['EVT_default_registration_status'] =
1071
+				! empty($this->_req_data['EVT_default_registration_status'])
1072
+					? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1073
+					: EE_Registry::instance()->CFG->registration->default_STS_ID;
1074
+			$event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL'])
1075
+				? esc_url_raw($this->_req_data['externalURL'])
1076
+				: null;
1077
+			$event_values['EVT_phone'] = ! empty($this->_req_data['event_phone'])
1078
+				? sanitize_text_field($this->_req_data['event_phone'])
1079
+				: null;
1080
+		}
1081
+		// update event
1082
+		$success = $this->eventModel()->update_by_ID($event_values, $post_id);
1083
+		// get event_object for other metaboxes...
1084
+		// though it would seem to make sense to just use $this->eventModel()->get_one_by_ID( $post_id )..
1085
+		// i have to setup where conditions to override the filters in the model
1086
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1087
+		$get_one_where = [
1088
+			$this->eventModel()->primary_key_name() => $post_id,
1089
+			'OR'                                    => [
1090
+				'status'   => $post->post_status,
1091
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1092
+				// but the returned object here has a status of "publish", so use the original post status as well
1093
+				'status*1' => $this->_req_data['original_post_status'],
1094
+			],
1095
+		];
1096
+		$event = $this->eventModel()->get_one([$get_one_where]);
1097
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1098
+		$event_update_callbacks = apply_filters(
1099
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1100
+			[
1101
+				[$this, '_default_venue_update'],
1102
+				[$this, '_default_tickets_update'],
1103
+			]
1104
+		);
1105
+		$att_success = true;
1106
+		foreach ($event_update_callbacks as $e_callback) {
1107
+			$_success = is_callable($e_callback)
1108
+				? $e_callback($event, $this->_req_data)
1109
+				: false;
1110
+			// if ANY of these updates fail then we want the appropriate global error message
1111
+			$att_success = ! $att_success ? $att_success : $_success;
1112
+		}
1113
+		// any errors?
1114
+		if ($success && false === $att_success) {
1115
+			EE_Error::add_error(
1116
+				esc_html__(
1117
+					'Event Details saved successfully but something went wrong with saving attachments.',
1118
+					'event_espresso'
1119
+				),
1120
+				__FILE__,
1121
+				__FUNCTION__,
1122
+				__LINE__
1123
+			);
1124
+		} elseif ($success === false) {
1125
+			EE_Error::add_error(
1126
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1127
+				__FILE__,
1128
+				__FUNCTION__,
1129
+				__LINE__
1130
+			);
1131
+		}
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * @param int $post_id
1137
+	 * @param int $revision_id
1138
+	 * @throws EE_Error
1139
+	 * @throws InvalidArgumentException
1140
+	 * @throws InvalidDataTypeException
1141
+	 * @throws InvalidInterfaceException
1142
+	 * @throws ReflectionException
1143
+	 * @see parent::restore_item()
1144
+	 */
1145
+	protected function _restore_cpt_item($post_id, $revision_id)
1146
+	{
1147
+		// copy existing event meta to new post
1148
+		$post_evt = $this->eventModel()->get_one_by_ID($post_id);
1149
+		if ($post_evt instanceof EE_Event) {
1150
+			// meta revision restore
1151
+			$post_evt->restore_revision($revision_id);
1152
+			// related objs restore
1153
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1154
+		}
1155
+	}
1156
+
1157
+
1158
+	/**
1159
+	 * Attach the venue to the Event
1160
+	 *
1161
+	 * @param EE_Event $evtobj Event Object to add the venue to
1162
+	 * @param array    $data   The request data from the form
1163
+	 * @return bool           Success or fail.
1164
+	 * @throws EE_Error
1165
+	 * @throws InvalidArgumentException
1166
+	 * @throws InvalidDataTypeException
1167
+	 * @throws InvalidInterfaceException
1168
+	 * @throws ReflectionException
1169
+	 */
1170
+	protected function _default_venue_update(EE_Event $evtobj, $data)
1171
+	{
1172
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1173
+		$venue_model = EEM_Venue::instance();
1174
+		$rows_affected = null;
1175
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1176
+		// very important.  If we don't have a venue name...
1177
+		// then we'll get out because not necessary to create empty venue
1178
+		if (empty($data['venue_title'])) {
1179
+			return false;
1180
+		}
1181
+		$venue_array = [
1182
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1183
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1184
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1185
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1186
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1187
+				: null,
1188
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1189
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1190
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1191
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1192
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1193
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1194
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1195
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1196
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1197
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1198
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1199
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1200
+			'status'              => 'publish',
1201
+		];
1202
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1203
+		if (! empty($venue_id)) {
1204
+			$update_where = [$venue_model->primary_key_name() => $venue_id];
1205
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1206
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1207
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1208
+			return $rows_affected > 0;
1209
+		}
1210
+		// we insert the venue
1211
+		$venue_id = $venue_model->insert($venue_array);
1212
+		$evtobj->_add_relation_to($venue_id, 'Venue');
1213
+		return ! empty($venue_id) ? true : false;
1214
+		// when we have the ancestor come in it's already been handled by the revision save.
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1220
+	 *
1221
+	 * @param EE_Event $evtobj The Event object we're attaching data to
1222
+	 * @param array    $data   The request data from the form
1223
+	 * @return array
1224
+	 * @throws EE_Error
1225
+	 * @throws InvalidArgumentException
1226
+	 * @throws InvalidDataTypeException
1227
+	 * @throws InvalidInterfaceException
1228
+	 * @throws ReflectionException
1229
+	 * @throws Exception
1230
+	 */
1231
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1232
+	{
1233
+		if ($this->admin_config->useAdvancedEditor()) {
1234
+			return [];
1235
+		}
1236
+		$saved_dtt = null;
1237
+		$saved_tickets = [];
1238
+		$incoming_date_formats = ['Y-m-d', 'h:i a'];
1239
+		$event_timezone_string = $evtobj->get_timezone();
1240
+		$event_timezone = new DateTimeZone($event_timezone_string);
1241
+		// let's use now in the set timezone.
1242
+		$now = new DateTime('now', $event_timezone);
1243
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1244
+			// trim all values to ensure any excess whitespace is removed.
1245
+			$dtt = array_map('trim', $dtt);
1246
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end'])
1247
+				? $dtt['DTT_EVT_end']
1248
+				: $dtt['DTT_EVT_start'];
1249
+			$datetime_values = [
1250
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1251
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1252
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1253
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1254
+				'DTT_order'     => $row,
1255
+			];
1256
+			// if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1257
+			if (! empty($dtt['DTT_ID'])) {
1258
+				$DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']);
1259
+				$DTM->set_date_format($incoming_date_formats[0]);
1260
+				$DTM->set_time_format($incoming_date_formats[1]);
1261
+				foreach ($datetime_values as $field => $value) {
1262
+					$DTM->set($field, $value);
1263
+				}
1264
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1265
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1266
+			} else {
1267
+				$DTM = EE_Registry::instance()->load_class(
1268
+					'Datetime',
1269
+					[$datetime_values, $event_timezone_string, $incoming_date_formats],
1270
+					false,
1271
+					false
1272
+				);
1273
+				foreach ($datetime_values as $field => $value) {
1274
+					$DTM->set($field, $value);
1275
+				}
1276
+			}
1277
+			$DTM->save();
1278
+			$DTM = $evtobj->_add_relation_to($DTM, 'Datetime');
1279
+			// load DTT helper
1280
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1281
+			if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
1282
+				$DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
1283
+				$DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
1284
+				$DTM->save();
1285
+			}
1286
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array
1287
+			//  because it is possible there was a new one created for the autosave.
1288
+			$saved_dtt = $DTM;
1289
+			// if ANY of these updates fail then we want the appropriate global error message.
1290
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1291
+		}
1292
+		// no dtts get deleted so we don't do any of that logic here.
1293
+		// update tickets next
1294
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1295
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1296
+			$incoming_date_formats = ['Y-m-d', 'h:i a'];
1297
+			$update_prices = false;
1298
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1299
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1300
+			// trim inputs to ensure any excess whitespace is removed.
1301
+			$tkt = array_map('trim', $tkt);
1302
+			if (empty($tkt['TKT_start_date'])) {
1303
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1304
+			}
1305
+			if (empty($tkt['TKT_end_date'])) {
1306
+				// use the start date of the first datetime
1307
+				$dtt = $evtobj->first_datetime();
1308
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1309
+					$incoming_date_formats[0],
1310
+					$incoming_date_formats[1]
1311
+				);
1312
+			}
1313
+			$TKT_values = [
1314
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1315
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1316
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1317
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1318
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1319
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1320
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1321
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1322
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1323
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1324
+				'TKT_row'         => $row,
1325
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1326
+				'TKT_price'       => $ticket_price,
1327
+			];
1328
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1329
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1330
+				$TKT_values['TKT_ID'] = 0;
1331
+				$TKT_values['TKT_is_default'] = 0;
1332
+				$TKT_values['TKT_price'] = $ticket_price;
1333
+				$update_prices = true;
1334
+			}
1335
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1336
+			// we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1337
+			// keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1338
+			if (! empty($tkt['TKT_ID'])) {
1339
+				$TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']);
1340
+				if ($TKT instanceof EE_Ticket) {
1341
+					$ticket_sold = $TKT->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
1353
+					// total price.  if they are different then we create a new ticket (if tickets sold)
1354
+					// if they aren't different then we go ahead and modify existing ticket.
1355
+					$create_new_TKT = $ticket_sold && ! $TKT->deleted()
1356
+									  && EEH_Money::compare_floats(
1357
+										  $ticket_price,
1358
+										  $TKT->get('TKT_price'),
1359
+										  '!=='
1360
+									  );
1361
+					$TKT->set_date_format($incoming_date_formats[0]);
1362
+					$TKT->set_time_format($incoming_date_formats[1]);
1363
+					// set new values
1364
+					foreach ($TKT_values as $field => $value) {
1365
+						if ($field === 'TKT_qty') {
1366
+							$TKT->set_qty($value);
1367
+						} else {
1368
+							$TKT->set($field, $value);
1369
+						}
1370
+					}
1371
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1372
+					if ($create_new_TKT) {
1373
+						// archive the old ticket first
1374
+						$TKT->set('TKT_deleted', 1);
1375
+						$TKT->save();
1376
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1377
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1378
+						// create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1379
+						$TKT = clone $TKT;
1380
+						$TKT->set('TKT_ID', 0);
1381
+						$TKT->set('TKT_deleted', 0);
1382
+						$TKT->set('TKT_price', $ticket_price);
1383
+						$TKT->set('TKT_sold', 0);
1384
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1385
+						$update_prices = true;
1386
+					}
1387
+					// make sure price is set if it hasn't been already
1388
+					$TKT->set('TKT_price', $ticket_price);
1389
+				}
1390
+			} else {
1391
+				// no TKT_id so a new TKT
1392
+				$TKT_values['TKT_price'] = $ticket_price;
1393
+				$TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1394
+				if ($TKT instanceof EE_Ticket) {
1395
+					// need to reset values to properly account for the date formats
1396
+					$TKT->set_date_format($incoming_date_formats[0]);
1397
+					$TKT->set_time_format($incoming_date_formats[1]);
1398
+					$TKT->set_timezone($evtobj->get_timezone());
1399
+					// set new values
1400
+					foreach ($TKT_values as $field => $value) {
1401
+						if ($field === 'TKT_qty') {
1402
+							$TKT->set_qty($value);
1403
+						} else {
1404
+							$TKT->set($field, $value);
1405
+						}
1406
+					}
1407
+					$update_prices = true;
1408
+				}
1409
+			}
1410
+			// cap ticket qty by datetime reg limits
1411
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1412
+			// update ticket.
1413
+			$TKT->save();
1414
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1415
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1416
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1417
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1418
+				$TKT->save();
1419
+			}
1420
+			// initially let's add the ticket to the dtt
1421
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1422
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1423
+			// add prices to ticket
1424
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1425
+		}
1426
+		// however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1427
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1428
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1429
+		foreach ($tickets_removed as $id) {
1430
+			$id = absint($id);
1431
+			// get the ticket for this id
1432
+			$tkt_to_remove = $this->ticketModel($event_timezone_string)->get_one_by_ID($id);
1433
+			// need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1434
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1435
+			foreach ($dtts as $dtt) {
1436
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1437
+			}
1438
+			// need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1439
+			$tkt_to_remove->delete_related_permanently('Price');
1440
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1441
+			$tkt_to_remove->delete_permanently();
1442
+		}
1443
+		return [$saved_dtt, $saved_tickets];
1444
+	}
1445
+
1446
+
1447
+	/**
1448
+	 * This attaches a list of given prices to a ticket.
1449
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1450
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1451
+	 * price info and prices are automatically "archived" via the ticket.
1452
+	 *
1453
+	 * @access  private
1454
+	 * @param array     $prices     Array of prices from the form.
1455
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1456
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1457
+	 * @return  void
1458
+	 * @throws EE_Error
1459
+	 * @throws InvalidArgumentException
1460
+	 * @throws InvalidDataTypeException
1461
+	 * @throws InvalidInterfaceException
1462
+	 * @throws ReflectionException
1463
+	 */
1464
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1465
+	{
1466
+		foreach ($prices as $row => $prc) {
1467
+			$PRC_values = [
1468
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1469
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1470
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1471
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1472
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1473
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1474
+				'PRC_order'      => $row,
1475
+			];
1476
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1477
+				$PRC_values['PRC_ID'] = 0;
1478
+				$PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1479
+			} else {
1480
+				$PRC = EEM_Price::instance()->get_one_by_ID($prc['PRC_ID']);
1481
+				// update this price with new values
1482
+				foreach ($PRC_values as $field => $newprc) {
1483
+					$PRC->set($field, $newprc);
1484
+				}
1485
+				$PRC->save();
1486
+			}
1487
+			$ticket->_add_relation_to($PRC, 'Price');
1488
+		}
1489
+	}
1490
+
1491
+
1492
+	/**
1493
+	 * Add in our autosave ajax handlers
1494
+	 *
1495
+	 */
1496
+	protected function _ee_autosave_create_new()
1497
+	{
1498
+	}
1499
+
1500
+
1501
+	/**
1502
+	 * More autosave handlers.
1503
+	 */
1504
+	protected function _ee_autosave_edit()
1505
+	{
1506
+	}
1507
+
1508
+
1509
+	/**
1510
+	 *    _generate_publish_box_extra_content
1511
+	 *
1512
+	 * @throws DomainException
1513
+	 * @throws EE_Error
1514
+	 * @throws InvalidArgumentException
1515
+	 * @throws InvalidDataTypeException
1516
+	 * @throws InvalidInterfaceException
1517
+	 * @throws ReflectionException
1518
+	 */
1519
+	private function _generate_publish_box_extra_content()
1520
+	{
1521
+		// load formatter helper
1522
+		// args for getting related registrations
1523
+		$approved_query_args = [
1524
+			[
1525
+				'REG_deleted' => 0,
1526
+				'STS_ID'      => EEM_Registration::status_id_approved,
1527
+			],
1528
+		];
1529
+		$not_approved_query_args = [
1530
+			[
1531
+				'REG_deleted' => 0,
1532
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1533
+			],
1534
+		];
1535
+		$pending_payment_query_args = [
1536
+			[
1537
+				'REG_deleted' => 0,
1538
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1539
+			],
1540
+		];
1541
+		// publish box
1542
+		$publish_box_extra_args = [
1543
+			'view_approved_reg_url'        => add_query_arg(
1544
+				[
1545
+					'action'      => 'default',
1546
+					'event_id'    => $this->_cpt_model_obj->ID(),
1547
+					'_reg_status' => EEM_Registration::status_id_approved,
1548
+				],
1549
+				REG_ADMIN_URL
1550
+			),
1551
+			'view_not_approved_reg_url'    => add_query_arg(
1552
+				[
1553
+					'action'      => 'default',
1554
+					'event_id'    => $this->_cpt_model_obj->ID(),
1555
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1556
+				],
1557
+				REG_ADMIN_URL
1558
+			),
1559
+			'view_pending_payment_reg_url' => add_query_arg(
1560
+				[
1561
+					'action'      => 'default',
1562
+					'event_id'    => $this->_cpt_model_obj->ID(),
1563
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1564
+				],
1565
+				REG_ADMIN_URL
1566
+			),
1567
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1568
+				'Registration',
1569
+				$approved_query_args
1570
+			),
1571
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1572
+				'Registration',
1573
+				$not_approved_query_args
1574
+			),
1575
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1576
+				'Registration',
1577
+				$pending_payment_query_args
1578
+			),
1579
+			'misc_pub_section_class'       => apply_filters(
1580
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1581
+				'misc-pub-section'
1582
+			),
1583
+		];
1584
+		ob_start();
1585
+		do_action(
1586
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1587
+			$this->_cpt_model_obj
1588
+		);
1589
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1590
+		// load template
1591
+		EEH_Template::display_template(
1592
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1593
+			$publish_box_extra_args
1594
+		);
1595
+	}
1596
+
1597
+
1598
+	/**
1599
+	 * @return EE_Event
1600
+	 */
1601
+	public function get_event_object()
1602
+	{
1603
+		return $this->_cpt_model_obj;
1604
+	}
1605
+
1606
+
1607
+
1608
+
1609
+	/** METABOXES * */
1610
+	/**
1611
+	 * _register_event_editor_meta_boxes
1612
+	 * add all metaboxes related to the event_editor
1613
+	 *
1614
+	 * @return void
1615
+	 * @throws EE_Error
1616
+	 * @throws InvalidArgumentException
1617
+	 * @throws InvalidDataTypeException
1618
+	 * @throws InvalidInterfaceException
1619
+	 * @throws ReflectionException
1620
+	 */
1621
+	protected function _register_event_editor_meta_boxes()
1622
+	{
1623
+		$this->verify_cpt_object();
1624
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1625
+		/** @var FeatureFlags $flags */
1626
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1627
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1628
+		if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1629
+			add_meta_box(
1630
+				'espresso_event_editor_event_options',
1631
+				esc_html__('Event Registration Options', 'event_espresso'),
1632
+				[$this, 'registration_options_meta_box'],
1633
+				$this->page_slug,
1634
+				'side'
1635
+			);
1636
+		}
1637
+		if (! $use_advanced_editor) {
1638
+			add_meta_box(
1639
+				'espresso_event_editor_tickets',
1640
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1641
+				[$this, 'ticket_metabox'],
1642
+				$this->page_slug,
1643
+				'normal',
1644
+				'high'
1645
+			);
1646
+		} else {
1647
+			if ($flags->featureAllowed('use_reg_options_meta_box')) {
1648
+				add_action(
1649
+					'add_meta_boxes_espresso_events',
1650
+					function () {
1651
+						global $current_screen;
1652
+						remove_meta_box('authordiv', $current_screen, 'normal');
1653
+					},
1654
+					99
1655
+				);
1656
+			}
1657
+		}
1658
+		// NOTE: if you're looking for other metaboxes in here,
1659
+		// where a metabox has a related management page in the admin
1660
+		// you will find it setup in the related management page's "_Hooks" file.
1661
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1662
+	}
1663
+
1664
+
1665
+	/**
1666
+	 * @throws DomainException
1667
+	 * @throws EE_Error
1668
+	 * @throws InvalidArgumentException
1669
+	 * @throws InvalidDataTypeException
1670
+	 * @throws InvalidInterfaceException
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 = $this->_cpt_model_obj instanceof EE_Event ? $this->_cpt_model_obj->ID() : 0;
1690
+		$event_timezone_string = $this->_cpt_model_obj instanceof EE_Event
1691
+			? $this->_cpt_model_obj->timezone_string()
1692
+			: '';
1693
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1694
+		/**
1695
+		 * 1. Start with retrieving Datetimes
1696
+		 * 2. Fore each datetime get related tickets
1697
+		 * 3. For each ticket get related prices
1698
+		 */
1699
+		$times = $this->datetimeModel($event_timezone_string)->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 = $this->ticketModel($event_timezone_string)->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 $ticket */
1732
+			$ticket = $this->ticketModel($event_timezone_string)->get_all_default_tickets();
1733
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[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
+			$this->ticketModel($event_timezone_string)->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 DomainException
1764
+	 * @throws EE_Error
1765
+	 * @throws InvalidArgumentException
1766
+	 * @throws InvalidDataTypeException
1767
+	 * @throws InvalidInterfaceException
1768
+	 * @throws ReflectionException
1769
+	 */
1770
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1771
+	{
1772
+		$template_args = [
1773
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1774
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1775
+				: '',
1776
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1777
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1778
+			'TKT_name'            => $ticket->get('TKT_name'),
1779
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1780
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1781
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1782
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1783
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1784
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1785
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1786
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1787
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1788
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1789
+				: ' disabled=disabled',
1790
+		];
1791
+		$price = $ticket->ID() !== 0
1792
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1793
+			: EEM_Price::instance()->create_default_object();
1794
+		$price_args = [
1795
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1796
+			'PRC_amount'            => $price->get('PRC_amount'),
1797
+			'PRT_ID'                => $price->get('PRT_ID'),
1798
+			'PRC_ID'                => $price->get('PRC_ID'),
1799
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1800
+		];
1801
+		// make sure we have default start and end dates if skeleton
1802
+		// handle rows that should NOT be empty
1803
+		if (empty($template_args['TKT_start_date'])) {
1804
+			// if empty then the start date will be now.
1805
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1806
+		}
1807
+		if (empty($template_args['TKT_end_date'])) {
1808
+			// get the earliest datetime (if present);
1809
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1810
+				? $this->_cpt_model_obj->get_first_related(
1811
+					'Datetime',
1812
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1813
+				)
1814
+				: null;
1815
+			if (! empty($earliest_dtt)) {
1816
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1817
+			} else {
1818
+				$template_args['TKT_end_date'] = date(
1819
+					'Y-m-d h:i a',
1820
+					mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1821
+				);
1822
+			}
1823
+		}
1824
+		$template_args = array_merge($template_args, $price_args);
1825
+		$template = apply_filters(
1826
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1827
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1828
+			$ticket
1829
+		);
1830
+		return EEH_Template::display_template($template, $template_args, true);
1831
+	}
1832
+
1833
+
1834
+	/**
1835
+	 * @throws DomainException
1836
+	 * @throws EE_Error
1837
+	 */
1838
+	public function registration_options_meta_box()
1839
+	{
1840
+		$yes_no_values = [
1841
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1842
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1843
+		];
1844
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1845
+			[
1846
+				EEM_Registration::status_id_cancelled,
1847
+				EEM_Registration::status_id_declined,
1848
+				EEM_Registration::status_id_incomplete,
1849
+			],
1850
+			true
1851
+		);
1852
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1853
+		$template_args['_event'] = $this->_cpt_model_obj;
1854
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1855
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1856
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1857
+			'default_reg_status',
1858
+			$default_reg_status_values,
1859
+			$this->_cpt_model_obj->default_registration_status()
1860
+		);
1861
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1862
+			'display_desc',
1863
+			$yes_no_values,
1864
+			$this->_cpt_model_obj->display_description()
1865
+		);
1866
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1867
+			'display_ticket_selector',
1868
+			$yes_no_values,
1869
+			$this->_cpt_model_obj->display_ticket_selector(),
1870
+			'',
1871
+			'',
1872
+			false
1873
+		);
1874
+		$template_args['additional_registration_options'] = apply_filters(
1875
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1876
+			'',
1877
+			$template_args,
1878
+			$yes_no_values,
1879
+			$default_reg_status_values
1880
+		);
1881
+		EEH_Template::display_template(
1882
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1883
+			$template_args
1884
+		);
1885
+	}
1886
+
1887
+
1888
+	/**
1889
+	 * _get_events()
1890
+	 * This method simply returns all the events (for the given _view and paging)
1891
+	 *
1892
+	 * @access public
1893
+	 * @param int  $per_page     count of items per page (20 default);
1894
+	 * @param int  $current_page what is the current page being viewed.
1895
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1896
+	 *                           If FALSE then we return an array of event objects
1897
+	 *                           that match the given _view and paging parameters.
1898
+	 * @return array an array of event objects.
1899
+	 * @throws EE_Error
1900
+	 * @throws InvalidArgumentException
1901
+	 * @throws InvalidDataTypeException
1902
+	 * @throws InvalidInterfaceException
1903
+	 * @throws ReflectionException
1904
+	 * @throws Exception
1905
+	 * @throws Exception
1906
+	 * @throws Exception
1907
+	 */
1908
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1909
+	{
1910
+		$EEME = $this->eventModel();
1911
+		$offset = ($current_page - 1) * $per_page;
1912
+		$limit = $count ? null : $offset . ',' . $per_page;
1913
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1914
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1915
+		if (isset($this->_req_data['month_range'])) {
1916
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1917
+			// simulate the FIRST day of the month, that fixes issues for months like February
1918
+			// where PHP doesn't know what to assume for date.
1919
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1920
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1921
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1922
+		}
1923
+		$where = [];
1924
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1925
+		// determine what post_status our condition will have for the query.
1926
+		switch ($status) {
1927
+			case 'month':
1928
+			case 'today':
1929
+			case null:
1930
+			case 'all':
1931
+				break;
1932
+			case 'draft':
1933
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1934
+				break;
1935
+			default:
1936
+				$where['status'] = $status;
1937
+		}
1938
+		// categories?
1939
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1940
+			? $this->_req_data['EVT_CAT'] : null;
1941
+		if (! empty($category)) {
1942
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1943
+			$where['Term_Taxonomy.term_id'] = $category;
1944
+		}
1945
+		// date where conditions
1946
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1947
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1948
+			$DateTime = new DateTime(
1949
+				$year_r . '-' . $month_r . '-01 00:00:00',
1950
+				new DateTimeZone('UTC')
1951
+			);
1952
+			$start = $DateTime->getTimestamp();
1953
+			// set the datetime to be the end of the month
1954
+			$DateTime->setDate(
1955
+				$year_r,
1956
+				$month_r,
1957
+				$DateTime->format('t')
1958
+			)->setTime(23, 59, 59);
1959
+			$end = $DateTime->getTimestamp();
1960
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1961
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1962
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1963
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1964
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1965
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1966
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1967
+			$now = date('Y-m-01');
1968
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1969
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1970
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1971
+							->setTime(23, 59, 59)
1972
+							->format(implode(' ', $start_formats));
1973
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1974
+		}
1975
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1976
+			$where['EVT_wp_user'] = get_current_user_id();
1977
+		} elseif (
1978
+			! isset($where['status'])
1979
+				  && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
1980
+		) {
1981
+			$where['OR'] = [
1982
+				'status*restrict_private' => ['!=', 'private'],
1983
+				'AND'                     => [
1984
+					'status*inclusive' => ['=', 'private'],
1985
+					'EVT_wp_user'      => get_current_user_id(),
1986
+				],
1987
+			];
1988
+		}
1989
+
1990
+		if (
1991
+			isset($this->_req_data['EVT_wp_user'])
1992
+			&& (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
1993
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1994
+		) {
1995
+			$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1996
+		}
1997
+		// search query handling
1998
+		if (isset($this->_req_data['s'])) {
1999
+			$search_string = '%' . $this->_req_data['s'] . '%';
2000
+			$where['OR'] = [
2001
+				'EVT_name'       => ['LIKE', $search_string],
2002
+				'EVT_desc'       => ['LIKE', $search_string],
2003
+				'EVT_short_desc' => ['LIKE', $search_string],
2004
+			];
2005
+		}
2006
+		// filter events by venue.
2007
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2008
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2009
+		}
2010
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2011
+		$query_params = apply_filters(
2012
+			'FHEE__Events_Admin_Page__get_events__query_params',
2013
+			[
2014
+				$where,
2015
+				'limit'    => $limit,
2016
+				'order_by' => $orderby,
2017
+				'order'    => $order,
2018
+				'group_by' => 'EVT_ID',
2019
+			],
2020
+			$this->_req_data
2021
+		);
2022
+
2023
+		// let's first check if we have special requests coming in.
2024
+		if (isset($this->_req_data['active_status'])) {
2025
+			switch ($this->_req_data['active_status']) {
2026
+				case 'upcoming':
2027
+					return $EEME->get_upcoming_events($query_params, $count);
2028
+					break;
2029
+				case 'expired':
2030
+					return $EEME->get_expired_events($query_params, $count);
2031
+					break;
2032
+				case 'active':
2033
+					return $EEME->get_active_events($query_params, $count);
2034
+					break;
2035
+				case 'inactive':
2036
+					return $EEME->get_inactive_events($query_params, $count);
2037
+					break;
2038
+			}
2039
+		}
2040
+
2041
+		$events = $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2042
+		return $events;
2043
+	}
2044
+
2045
+
2046
+	/**
2047
+	 * handling for WordPress CPT actions (trash, restore, delete)
2048
+	 *
2049
+	 * @param string $post_id
2050
+	 * @throws EE_Error
2051
+	 * @throws InvalidArgumentException
2052
+	 * @throws InvalidDataTypeException
2053
+	 * @throws InvalidInterfaceException
2054
+	 * @throws ReflectionException
2055
+	 */
2056
+	public function trash_cpt_item($post_id)
2057
+	{
2058
+		$this->_req_data['EVT_ID'] = $post_id;
2059
+		$this->_trash_or_restore_event('trash', false);
2060
+	}
2061
+
2062
+
2063
+	/**
2064
+	 * @param string $post_id
2065
+	 * @throws EE_Error
2066
+	 * @throws InvalidArgumentException
2067
+	 * @throws InvalidDataTypeException
2068
+	 * @throws InvalidInterfaceException
2069
+	 * @throws ReflectionException
2070
+	 */
2071
+	public function restore_cpt_item($post_id)
2072
+	{
2073
+		$this->_req_data['EVT_ID'] = $post_id;
2074
+		$this->_trash_or_restore_event('draft', false);
2075
+	}
2076
+
2077
+
2078
+	/**
2079
+	 * @param string $post_id
2080
+	 * @throws EE_Error
2081
+	 * @throws InvalidArgumentException
2082
+	 * @throws InvalidDataTypeException
2083
+	 * @throws InvalidInterfaceException
2084
+	 * @throws ReflectionException
2085
+	 */
2086
+	public function delete_cpt_item($post_id)
2087
+	{
2088
+		$this->_req_data['EVT_ID'] = $post_id;
2089
+		$this->_delete_event(false);
2090
+	}
2091
+
2092
+
2093
+	/**
2094
+	 * _trash_or_restore_event
2095
+	 *
2096
+	 * @access protected
2097
+	 * @param string $event_status
2098
+	 * @param bool   $redirect_after
2099
+	 * @throws EE_Error
2100
+	 * @throws InvalidArgumentException
2101
+	 * @throws InvalidDataTypeException
2102
+	 * @throws InvalidInterfaceException
2103
+	 * @throws ReflectionException
2104
+	 */
2105
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2106
+	{
2107
+		// determine the event id and set to array.
2108
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2109
+		// loop thru events
2110
+		if ($EVT_ID) {
2111
+			// clean status
2112
+			$event_status = sanitize_key($event_status);
2113
+			// grab status
2114
+			if (! empty($event_status)) {
2115
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2116
+			} else {
2117
+				$success = false;
2118
+				$msg = esc_html__(
2119
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2120
+					'event_espresso'
2121
+				);
2122
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2123
+			}
2124
+		} else {
2125
+			$success = false;
2126
+			$msg = esc_html__(
2127
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2128
+				'event_espresso'
2129
+			);
2130
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2131
+		}
2132
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2133
+		if ($redirect_after) {
2134
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2135
+		}
2136
+	}
2137
+
2138
+
2139
+	/**
2140
+	 * _trash_or_restore_events
2141
+	 *
2142
+	 * @access protected
2143
+	 * @param string $event_status
2144
+	 * @return void
2145
+	 * @throws EE_Error
2146
+	 * @throws InvalidArgumentException
2147
+	 * @throws InvalidDataTypeException
2148
+	 * @throws InvalidInterfaceException
2149
+	 * @throws ReflectionException
2150
+	 */
2151
+	protected function _trash_or_restore_events($event_status = 'trash')
2152
+	{
2153
+		// clean status
2154
+		$event_status = sanitize_key($event_status);
2155
+		// grab status
2156
+		if (! empty($event_status)) {
2157
+			$success = true;
2158
+			// determine the event id and set to array.
2159
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2160
+			// loop thru events
2161
+			foreach ($EVT_IDs as $EVT_ID) {
2162
+				if ($EVT_ID = absint($EVT_ID)) {
2163
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2164
+					$success = $results !== false ? $success : false;
2165
+				} else {
2166
+					$msg = sprintf(
2167
+						esc_html__(
2168
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2169
+							'event_espresso'
2170
+						),
2171
+						$EVT_ID
2172
+					);
2173
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2174
+					$success = false;
2175
+				}
2176
+			}
2177
+		} else {
2178
+			$success = false;
2179
+			$msg = esc_html__(
2180
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2181
+				'event_espresso'
2182
+			);
2183
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2184
+		}
2185
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2186
+		$success = $success ? 2 : false;
2187
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2188
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2189
+	}
2190
+
2191
+
2192
+	/**
2193
+	 * _trash_or_restore_events
2194
+	 *
2195
+	 * @access  private
2196
+	 * @param int    $EVT_ID
2197
+	 * @param string $event_status
2198
+	 * @return bool
2199
+	 * @throws EE_Error
2200
+	 * @throws InvalidArgumentException
2201
+	 * @throws InvalidDataTypeException
2202
+	 * @throws InvalidInterfaceException
2203
+	 * @throws ReflectionException
2204
+	 */
2205
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2206
+	{
2207
+		// grab event id
2208
+		if (! $EVT_ID) {
2209
+			$msg = esc_html__(
2210
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2211
+				'event_espresso'
2212
+			);
2213
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2214
+			return false;
2215
+		}
2216
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2217
+		// clean status
2218
+		$event_status = sanitize_key($event_status);
2219
+		// grab status
2220
+		if (empty($event_status)) {
2221
+			$msg = esc_html__(
2222
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2223
+				'event_espresso'
2224
+			);
2225
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2226
+			return false;
2227
+		}
2228
+		// was event trashed or restored ?
2229
+		switch ($event_status) {
2230
+			case 'draft':
2231
+				$action = 'restored from the trash';
2232
+				$hook = 'AHEE_event_restored_from_trash';
2233
+				break;
2234
+			case 'trash':
2235
+				$action = 'moved to the trash';
2236
+				$hook = 'AHEE_event_moved_to_trash';
2237
+				break;
2238
+			default:
2239
+				$action = 'updated';
2240
+				$hook = false;
2241
+		}
2242
+		// use class to change status
2243
+		$this->_cpt_model_obj->set_status($event_status);
2244
+		$success = $this->_cpt_model_obj->save();
2245
+		if ($success === false) {
2246
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2247
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2248
+			return false;
2249
+		}
2250
+		if ($hook) {
2251
+			do_action($hook);
2252
+		}
2253
+		return true;
2254
+	}
2255
+
2256
+
2257
+	/**
2258
+	 * _delete_event
2259
+	 *
2260
+	 * @access protected
2261
+	 * @param bool $redirect_after
2262
+	 * @throws EE_Error
2263
+	 * @throws InvalidArgumentException
2264
+	 * @throws InvalidDataTypeException
2265
+	 * @throws InvalidInterfaceException
2266
+	 * @throws ReflectionException
2267
+	 */
2268
+	protected function _delete_event($redirect_after = true)
2269
+	{
2270
+		// determine the event id and set to array.
2271
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2272
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2273
+		// loop thru events
2274
+		if ($EVT_ID) {
2275
+			$success = $this->_permanently_delete_event($EVT_ID);
2276
+			// get list of events with no prices
2277
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
2278
+			// remove this event from the list of events with no prices
2279
+			if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2280
+				unset($espresso_no_ticket_prices[ $EVT_ID ]);
2281
+			}
2282
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2283
+		} else {
2284
+			$success = false;
2285
+			$msg = esc_html__(
2286
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2287
+				'event_espresso'
2288
+			);
2289
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2290
+		}
2291
+		if ($redirect_after) {
2292
+			$this->_redirect_after_action(
2293
+				$success,
2294
+				'Event',
2295
+				'deleted',
2296
+				['action' => 'default', 'status' => 'trash']
2297
+			);
2298
+		}
2299
+	}
2300
+
2301
+
2302
+	/**
2303
+	 * _delete_events
2304
+	 *
2305
+	 * @access protected
2306
+	 * @return void
2307
+	 * @throws EE_Error
2308
+	 * @throws InvalidArgumentException
2309
+	 * @throws InvalidDataTypeException
2310
+	 * @throws InvalidInterfaceException
2311
+	 * @throws ReflectionException
2312
+	 */
2313
+	protected function _delete_events()
2314
+	{
2315
+		$success = true;
2316
+		// get list of events with no prices
2317
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
2318
+		// determine the event id and set to array.
2319
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2320
+		// loop thru events
2321
+		foreach ($EVT_IDs as $EVT_ID) {
2322
+			$EVT_ID = absint($EVT_ID);
2323
+			if ($EVT_ID) {
2324
+				$results = $this->_permanently_delete_event($EVT_ID);
2325
+				$success = $results !== false ? $success : false;
2326
+				// remove this event from the list of events with no prices
2327
+				unset($espresso_no_ticket_prices[ $EVT_ID ]);
2328
+			} else {
2329
+				$success = false;
2330
+				$msg = esc_html__(
2331
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2332
+					'event_espresso'
2333
+				);
2334
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2335
+			}
2336
+		}
2337
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2338
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2339
+		$success = $success ? 2 : false;
2340
+		$this->_redirect_after_action($success, 'Events', 'deleted', ['action' => 'default']);
2341
+	}
2342
+
2343
+
2344
+	/**
2345
+	 * _permanently_delete_event
2346
+	 *
2347
+	 * @access  private
2348
+	 * @param int $EVT_ID
2349
+	 * @return bool
2350
+	 * @throws EE_Error
2351
+	 * @throws InvalidArgumentException
2352
+	 * @throws InvalidDataTypeException
2353
+	 * @throws InvalidInterfaceException
2354
+	 * @throws ReflectionException
2355
+	 */
2356
+	private function _permanently_delete_event($EVT_ID = 0)
2357
+	{
2358
+		// grab event id
2359
+		if (! $EVT_ID) {
2360
+			$msg = esc_html__(
2361
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2362
+				'event_espresso'
2363
+			);
2364
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2365
+			return false;
2366
+		}
2367
+		if (
2368
+			! $this->_cpt_model_obj instanceof EE_Event
2369
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2370
+		) {
2371
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2372
+		}
2373
+		if (! $this->_cpt_model_obj instanceof EE_Event) {
2374
+			return false;
2375
+		}
2376
+		// need to delete related tickets and prices first.
2377
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2378
+		foreach ($datetimes as $datetime) {
2379
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2380
+			$tickets = $datetime->get_many_related('Ticket');
2381
+			foreach ($tickets as $ticket) {
2382
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2383
+				$ticket->delete_related_permanently('Price');
2384
+				$ticket->delete_permanently();
2385
+			}
2386
+			$datetime->delete();
2387
+		}
2388
+		// what about related venues or terms?
2389
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2390
+		foreach ($venues as $venue) {
2391
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2392
+		}
2393
+		// any attached question groups?
2394
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2395
+		if (! empty($question_groups)) {
2396
+			foreach ($question_groups as $question_group) {
2397
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2398
+			}
2399
+		}
2400
+		// Message Template Groups
2401
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2402
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2403
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2404
+		foreach ($term_taxonomies as $term_taxonomy) {
2405
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2406
+		}
2407
+		$success = $this->_cpt_model_obj->delete_permanently();
2408
+		// did it all go as planned ?
2409
+		if ($success) {
2410
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2411
+			EE_Error::add_success($msg);
2412
+		} else {
2413
+			$msg = sprintf(
2414
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2415
+				$EVT_ID
2416
+			);
2417
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2418
+			return false;
2419
+		}
2420
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2421
+		return true;
2422
+	}
2423
+
2424
+
2425
+	/**
2426
+	 * get total number of events
2427
+	 *
2428
+	 * @access public
2429
+	 * @return int
2430
+	 * @throws EE_Error
2431
+	 * @throws InvalidArgumentException
2432
+	 * @throws InvalidDataTypeException
2433
+	 * @throws InvalidInterfaceException
2434
+	 */
2435
+	public function total_events()
2436
+	{
2437
+		$count = EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2438
+		return $count;
2439
+	}
2440
+
2441
+
2442
+	/**
2443
+	 * get total number of draft events
2444
+	 *
2445
+	 * @access public
2446
+	 * @return int
2447
+	 * @throws EE_Error
2448
+	 * @throws InvalidArgumentException
2449
+	 * @throws InvalidDataTypeException
2450
+	 * @throws InvalidInterfaceException
2451
+	 */
2452
+	public function total_events_draft()
2453
+	{
2454
+		$where = [
2455
+			'status' => ['IN', ['draft', 'auto-draft']],
2456
+		];
2457
+		$count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2458
+		return $count;
2459
+	}
2460
+
2461
+
2462
+	/**
2463
+	 * get total number of trashed events
2464
+	 *
2465
+	 * @access public
2466
+	 * @return int
2467
+	 * @throws EE_Error
2468
+	 * @throws InvalidArgumentException
2469
+	 * @throws InvalidDataTypeException
2470
+	 * @throws InvalidInterfaceException
2471
+	 */
2472
+	public function total_trashed_events()
2473
+	{
2474
+		$where = [
2475
+			'status' => 'trash',
2476
+		];
2477
+		$count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2478
+		return $count;
2479
+	}
2480
+
2481
+
2482
+	/**
2483
+	 *    _default_event_settings
2484
+	 *    This generates the Default Settings Tab
2485
+	 *
2486
+	 * @return void
2487
+	 * @throws DomainException
2488
+	 * @throws EE_Error
2489
+	 * @throws InvalidArgumentException
2490
+	 * @throws InvalidDataTypeException
2491
+	 * @throws InvalidInterfaceException
2492
+	 */
2493
+	protected function _default_event_settings()
2494
+	{
2495
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2496
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2497
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2498
+		$this->display_admin_page_with_sidebar();
2499
+	}
2500
+
2501
+
2502
+	/**
2503
+	 * Return the form for event settings.
2504
+	 *
2505
+	 * @return EE_Form_Section_Proper
2506
+	 * @throws EE_Error
2507
+	 */
2508
+	protected function _default_event_settings_form()
2509
+	{
2510
+		$registration_config = EE_Registry::instance()->CFG->registration;
2511
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2512
+		// exclude
2513
+			[
2514
+				EEM_Registration::status_id_cancelled,
2515
+				EEM_Registration::status_id_declined,
2516
+				EEM_Registration::status_id_incomplete,
2517
+				EEM_Registration::status_id_wait_list,
2518
+			],
2519
+			true
2520
+		);
2521
+		return new EE_Form_Section_Proper(
2522
+			[
2523
+				'name'            => 'update_default_event_settings',
2524
+				'html_id'         => 'update_default_event_settings',
2525
+				'html_class'      => 'form-table',
2526
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2527
+				'subsections'     => apply_filters(
2528
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2529
+					[
2530
+						'default_reg_status'  => new EE_Select_Input(
2531
+							$registration_stati_for_selection,
2532
+							[
2533
+								'default'         => isset($registration_config->default_STS_ID)
2534
+													 && array_key_exists(
2535
+														 $registration_config->default_STS_ID,
2536
+														 $registration_stati_for_selection
2537
+													 )
2538
+									? sanitize_text_field($registration_config->default_STS_ID)
2539
+									: EEM_Registration::status_id_pending_payment,
2540
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2541
+													 . EEH_Template::get_help_tab_link(
2542
+														 'default_settings_status_help_tab'
2543
+													 ),
2544
+								'html_help_text'  => esc_html__(
2545
+									'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.',
2546
+									'event_espresso'
2547
+								),
2548
+							]
2549
+						),
2550
+						'default_max_tickets' => new EE_Integer_Input(
2551
+							[
2552
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2553
+									? $registration_config->default_maximum_number_of_tickets
2554
+									: EEM_Event::get_default_additional_limit(),
2555
+								'html_label_text' => esc_html__(
2556
+									'Default Maximum Tickets Allowed Per Order:',
2557
+									'event_espresso'
2558
+								)
2559
+													 . EEH_Template::get_help_tab_link(
2560
+														 'default_maximum_tickets_help_tab"'
2561
+													 ),
2562
+								'html_help_text'  => esc_html__(
2563
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2564
+									'event_espresso'
2565
+								),
2566
+							]
2567
+						),
2568
+					]
2569
+				),
2570
+			]
2571
+		);
2572
+	}
2573
+
2574
+
2575
+	/**
2576
+	 * @return void
2577
+	 * @throws EE_Error
2578
+	 * @throws InvalidArgumentException
2579
+	 * @throws InvalidDataTypeException
2580
+	 * @throws InvalidInterfaceException
2581
+	 */
2582
+	protected function _update_default_event_settings()
2583
+	{
2584
+		$form = $this->_default_event_settings_form();
2585
+		if ($form->was_submitted()) {
2586
+			$form->receive_form_submission();
2587
+			if ($form->is_valid()) {
2588
+				$registration_config = EE_Registry::instance()->CFG->registration;
2589
+				$valid_data = $form->valid_data();
2590
+				if (isset($valid_data['default_reg_status'])) {
2591
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2592
+				}
2593
+				if (isset($valid_data['default_max_tickets'])) {
2594
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2595
+				}
2596
+				do_action(
2597
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2598
+					$valid_data,
2599
+					EE_Registry::instance()->CFG,
2600
+					$this
2601
+				);
2602
+				// update because data was valid!
2603
+				EE_Registry::instance()->CFG->update_espresso_config();
2604
+				EE_Error::overwrite_success();
2605
+				EE_Error::add_success(
2606
+					__('Default Event Settings were updated', 'event_espresso')
2607
+				);
2608
+			}
2609
+		}
2610
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2611
+	}
2612
+
2613
+
2614
+	/*************        Templates        *************/
2615
+	protected function _template_settings()
2616
+	{
2617
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2618
+		$this->_template_args['preview_img'] = '<img src="'
2619
+											   . EVENTS_ASSETS_URL
2620
+											   . '/images/'
2621
+											   . 'caffeinated_template_features.jpg" alt="'
2622
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2623
+											   . '" />';
2624
+		$this->_template_args['preview_text'] = '<strong>'
2625
+												. esc_html__(
2626
+													'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.',
2627
+													'event_espresso'
2628
+												) . '</strong>';
2629
+		$this->display_admin_caf_preview_page('template_settings_tab');
2630
+	}
2631
+
2632
+
2633
+	/** Event Category Stuff **/
2634
+	/**
2635
+	 * set the _category property with the category object for the loaded page.
2636
+	 *
2637
+	 * @access private
2638
+	 * @return void
2639
+	 */
2640
+	private function _set_category_object()
2641
+	{
2642
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2643
+			return;
2644
+		} //already have the category object so get out.
2645
+		// set default category object
2646
+		$this->_set_empty_category_object();
2647
+		// only set if we've got an id
2648
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2649
+			return;
2650
+		}
2651
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2652
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2653
+		if (! empty($term)) {
2654
+			$this->_category->category_name = $term->name;
2655
+			$this->_category->category_identifier = $term->slug;
2656
+			$this->_category->category_desc = $term->description;
2657
+			$this->_category->id = $term->term_id;
2658
+			$this->_category->parent = $term->parent;
2659
+		}
2660
+	}
2661
+
2662
+
2663
+	/**
2664
+	 * Clears out category properties.
2665
+	 */
2666
+	private function _set_empty_category_object()
2667
+	{
2668
+		$this->_category = new stdClass();
2669
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2670
+		$this->_category->id = $this->_category->parent = 0;
2671
+	}
2672
+
2673
+
2674
+	/**
2675
+	 * @throws DomainException
2676
+	 * @throws EE_Error
2677
+	 * @throws InvalidArgumentException
2678
+	 * @throws InvalidDataTypeException
2679
+	 * @throws InvalidInterfaceException
2680
+	 */
2681
+	protected function _category_list_table()
2682
+	{
2683
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2684
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2685
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2686
+			'add_category',
2687
+			'add_category',
2688
+			[],
2689
+			'add-new-h2'
2690
+		);
2691
+		$this->display_admin_list_table_page_with_sidebar();
2692
+	}
2693
+
2694
+
2695
+	/**
2696
+	 * Output category details view.
2697
+	 *
2698
+	 * @param string $view
2699
+	 * @throws DomainException
2700
+	 * @throws EE_Error
2701
+	 * @throws InvalidArgumentException
2702
+	 * @throws InvalidDataTypeException
2703
+	 * @throws InvalidInterfaceException
2704
+	 */
2705
+	protected function _category_details($view)
2706
+	{
2707
+		// load formatter helper
2708
+		// load field generator helper
2709
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2710
+		$this->_set_add_edit_form_tags($route);
2711
+		$this->_set_category_object();
2712
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2713
+		$delete_action = 'delete_category';
2714
+		// custom redirect
2715
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2716
+			['action' => 'category_list'],
2717
+			$this->_admin_base_url
2718
+		);
2719
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2720
+		// take care of contents
2721
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2722
+		$this->display_admin_page_with_sidebar();
2723
+	}
2724
+
2725
+
2726
+	/**
2727
+	 * Output category details content.
2728
+	 *
2729
+	 * @throws DomainException
2730
+	 */
2731
+	protected function _category_details_content()
2732
+	{
2733
+		$editor_args['category_desc'] = [
2734
+			'type'          => 'wp_editor',
2735
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2736
+			'class'         => 'my_editor_custom',
2737
+			'wpeditor_args' => ['media_buttons' => false],
2738
+		];
2739
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2740
+		$all_terms = get_terms(
2741
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2742
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2743
+		);
2744
+		// setup category select for term parents.
2745
+		$category_select_values[] = [
2746
+			'text' => esc_html__('No Parent', 'event_espresso'),
2747
+			'id'   => 0,
2748
+		];
2749
+		foreach ($all_terms as $term) {
2750
+			$category_select_values[] = [
2751
+				'text' => $term->name,
2752
+				'id'   => $term->term_id,
2753
+			];
2754
+		}
2755
+		$category_select = EEH_Form_Fields::select_input(
2756
+			'category_parent',
2757
+			$category_select_values,
2758
+			$this->_category->parent
2759
+		);
2760
+		$template_args = [
2761
+			'category'                 => $this->_category,
2762
+			'category_select'          => $category_select,
2763
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2764
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2765
+			'disable'                  => '',
2766
+			'disabled_message'         => false,
2767
+		];
2768
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2769
+		return EEH_Template::display_template($template, $template_args, true);
2770
+	}
2771
+
2772
+
2773
+	/**
2774
+	 * Handles deleting categories.
2775
+	 */
2776
+	protected function _delete_categories()
2777
+	{
2778
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2779
+			: (array) $this->_req_data['category_id'];
2780
+		foreach ($cat_ids as $cat_id) {
2781
+			$this->_delete_category($cat_id);
2782
+		}
2783
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2784
+		$query_args = [
2785
+			'action' => 'category_list',
2786
+		];
2787
+		$this->_redirect_after_action(0, '', '', $query_args);
2788
+	}
2789
+
2790
+
2791
+	/**
2792
+	 * Handles deleting specific category.
2793
+	 *
2794
+	 * @param int $cat_id
2795
+	 */
2796
+	protected function _delete_category($cat_id)
2797
+	{
2798
+		$cat_id = absint($cat_id);
2799
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2800
+	}
2801
+
2802
+
2803
+	/**
2804
+	 * Handles triggering the update or insertion of a new category.
2805
+	 *
2806
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2807
+	 * @throws EE_Error
2808
+	 * @throws InvalidArgumentException
2809
+	 * @throws InvalidDataTypeException
2810
+	 * @throws InvalidInterfaceException
2811
+	 */
2812
+	protected function _insert_or_update_category($new_category)
2813
+	{
2814
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2815
+		$success = 0; // we already have a success message so lets not send another.
2816
+		if ($cat_id) {
2817
+			$query_args = [
2818
+				'action'     => 'edit_category',
2819
+				'EVT_CAT_ID' => $cat_id,
2820
+			];
2821
+		} else {
2822
+			$query_args = ['action' => 'add_category'];
2823
+		}
2824
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2825
+	}
2826
+
2827
+
2828
+	/**
2829
+	 * Inserts or updates category
2830
+	 *
2831
+	 * @param bool $update (true indicates we're updating a category).
2832
+	 * @return bool|mixed|string
2833
+	 */
2834
+	private function _insert_category($update = false)
2835
+	{
2836
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2837
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2838
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2839
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2840
+		if (empty($category_name)) {
2841
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2842
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2843
+			return false;
2844
+		}
2845
+		$term_args = [
2846
+			'name'        => $category_name,
2847
+			'description' => $category_desc,
2848
+			'parent'      => $category_parent,
2849
+		];
2850
+		// was the category_identifier input disabled?
2851
+		if (isset($this->_req_data['category_identifier'])) {
2852
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2853
+		}
2854
+		$insert_ids = $update
2855
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2856
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2857
+		if (! is_array($insert_ids)) {
2858
+			$msg = esc_html__(
2859
+				'An error occurred and the category has not been saved to the database.',
2860
+				'event_espresso'
2861
+			);
2862
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2863
+		} else {
2864
+			$cat_id = $insert_ids['term_id'];
2865
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2866
+			EE_Error::add_success($msg);
2867
+		}
2868
+		return $cat_id;
2869
+	}
2870
+
2871
+
2872
+	/**
2873
+	 * Gets categories or count of categories matching the arguments in the request.
2874
+	 *
2875
+	 * @param int  $per_page
2876
+	 * @param int  $current_page
2877
+	 * @param bool $count
2878
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2879
+	 * @throws EE_Error
2880
+	 * @throws InvalidArgumentException
2881
+	 * @throws InvalidDataTypeException
2882
+	 * @throws InvalidInterfaceException
2883
+	 */
2884
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2885
+	{
2886
+		// testing term stuff
2887
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2888
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2889
+		$limit = ($current_page - 1) * $per_page;
2890
+		$where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2891
+		if (isset($this->_req_data['s'])) {
2892
+			$sstr = '%' . $this->_req_data['s'] . '%';
2893
+			$where['OR'] = [
2894
+				'Term.name'   => ['LIKE', $sstr],
2895
+				'description' => ['LIKE', $sstr],
2896
+			];
2897
+		}
2898
+		$query_params = [
2899
+			$where,
2900
+			'order_by'   => [$orderby => $order],
2901
+			'limit'      => $limit . ',' . $per_page,
2902
+			'force_join' => ['Term'],
2903
+		];
2904
+		$categories = $count
2905
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2906
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2907
+		return $categories;
2908
+	}
2909
+
2910
+	/* end category stuff */
2911
+	/**************/
2912
+
2913
+
2914
+	/**
2915
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2916
+	 *
2917
+	 * @throws EE_Error
2918
+	 * @throws InvalidArgumentException
2919
+	 * @throws InvalidDataTypeException
2920
+	 * @throws InvalidInterfaceException
2921
+	 */
2922
+	public function save_timezonestring_setting()
2923
+	{
2924
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2925
+			? $this->_req_data['timezone_selected']
2926
+			: '';
2927
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2928
+			EE_Error::add_error(
2929
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2930
+				__FILE__,
2931
+				__FUNCTION__,
2932
+				__LINE__
2933
+			);
2934
+			$this->_template_args['error'] = true;
2935
+			$this->_return_json();
2936
+		}
2937
+
2938
+		update_option('timezone_string', $timezone_string);
2939
+		EE_Error::add_success(
2940
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2941
+		);
2942
+		$this->_template_args['success'] = true;
2943
+		$this->_return_json(true, ['action' => 'create_new']);
2944
+	}
2945 2945
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
         ];
512 512
         // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
513 513
         $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
514
-        if (! $domain->isCaffeinated()) {
514
+        if ( ! $domain->isCaffeinated()) {
515 515
             $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
516 516
             $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
517 517
         }
@@ -570,13 +570,13 @@  discard block
 block discarded – undo
570 570
     {
571 571
         wp_register_style(
572 572
             'events-admin-css',
573
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
573
+            EVENTS_ASSETS_URL.'events-admin-page.css',
574 574
             [],
575 575
             EVENT_ESPRESSO_VERSION
576 576
         );
577 577
         wp_register_style(
578 578
             'ee-cat-admin',
579
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
579
+            EVENTS_ASSETS_URL.'ee-cat-admin.css',
580 580
             [],
581 581
             EVENT_ESPRESSO_VERSION
582 582
         );
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         // scripts
586 586
         wp_register_script(
587 587
             'event_editor_js',
588
-            EVENTS_ASSETS_URL . 'event_editor.js',
588
+            EVENTS_ASSETS_URL.'event_editor.js',
589 589
             ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
590 590
             EVENT_ESPRESSO_VERSION,
591 591
             true
@@ -611,16 +611,16 @@  discard block
 block discarded – undo
611 611
         wp_enqueue_style('espresso-ui-theme');
612 612
         wp_register_style(
613 613
             'event-editor-css',
614
-            EVENTS_ASSETS_URL . 'event-editor.css',
614
+            EVENTS_ASSETS_URL.'event-editor.css',
615 615
             ['ee-admin-css'],
616 616
             EVENT_ESPRESSO_VERSION
617 617
         );
618 618
         wp_enqueue_style('event-editor-css');
619 619
         // scripts
620
-        if (! $this->admin_config->useAdvancedEditor()) {
620
+        if ( ! $this->admin_config->useAdvancedEditor()) {
621 621
             wp_register_script(
622 622
                 'event-datetime-metabox',
623
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
623
+                EVENTS_ASSETS_URL.'event-datetime-metabox.js',
624 624
                 ['event_editor_js', 'ee-datepicker'],
625 625
                 EVENT_ESPRESSO_VERSION
626 626
             );
@@ -690,15 +690,15 @@  discard block
 block discarded – undo
690 690
     public function verify_event_edit($event = null, $req_type = '')
691 691
     {
692 692
         // don't need to do this when processing
693
-        if (! empty($req_type)) {
693
+        if ( ! empty($req_type)) {
694 694
             return;
695 695
         }
696 696
         // no event?
697
-        if (! $event instanceof EE_Event) {
697
+        if ( ! $event instanceof EE_Event) {
698 698
             $event = $this->_cpt_model_obj;
699 699
         }
700 700
         // STILL no event?
701
-        if (! $event instanceof EE_Event) {
701
+        if ( ! $event instanceof EE_Event) {
702 702
             return;
703 703
         }
704 704
         $orig_status = $event->status();
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
             );
739 739
         }
740 740
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
741
-        if (! $event->tickets_on_sale()) {
741
+        if ( ! $event->tickets_on_sale()) {
742 742
             return;
743 743
         }
744 744
         // made it here so show warning
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
     {
785 785
         $has_timezone_string = get_option('timezone_string');
786 786
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
787
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
787
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
788 788
             EE_Error::add_attention(
789 789
                 sprintf(
790 790
                     __(
@@ -868,31 +868,31 @@  discard block
 block discarded – undo
868 868
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
869 869
         $statuses = [
870 870
             'sold_out_status'  => [
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
871
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
872 872
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
873 873
             ],
874 874
             'active_status'    => [
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
875
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
876 876
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
877 877
             ],
878 878
             'upcoming_status'  => [
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
879
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
880 880
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
881 881
             ],
882 882
             'postponed_status' => [
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
883
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
884 884
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
885 885
             ],
886 886
             'cancelled_status' => [
887
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
887
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
888 888
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
889 889
             ],
890 890
             'expired_status'   => [
891
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
891
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
892 892
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
893 893
             ],
894 894
             'inactive_status'  => [
895
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
895
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
896 896
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
897 897
             ],
898 898
         ];
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
      */
908 908
     private function eventModel()
909 909
     {
910
-        if (! $this->_event_model instanceof EEM_Event) {
910
+        if ( ! $this->_event_model instanceof EEM_Event) {
911 911
             $this->_event_model = EEM_Event::instance();
912 912
         }
913 913
         return $this->_event_model;
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
      */
922 922
     private function datetimeModel($event_timezone_string = '')
923 923
     {
924
-        if (! $this->datetime_model instanceof EEM_Datetime) {
924
+        if ( ! $this->datetime_model instanceof EEM_Datetime) {
925 925
             $this->datetime_model = EEM_Datetime::instance($event_timezone_string);
926 926
         }
927 927
         return $this->datetime_model;
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
      */
936 936
     private function ticketModel($event_timezone_string = '')
937 937
     {
938
-        if (! $this->ticket_model instanceof EEM_Ticket) {
938
+        if ( ! $this->ticket_model instanceof EEM_Ticket) {
939 939
             $this->ticket_model = EEM_Ticket::instance($event_timezone_string);
940 940
         }
941 941
         return $this->ticket_model;
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
956 956
     {
957 957
         // make sure this is only when editing
958
-        if (! empty($id)) {
958
+        if ( ! empty($id)) {
959 959
             $post = get_post($id);
960 960
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
961 961
                        . esc_html__('Shortcode', 'event_espresso')
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
                                                                                   'button'
994 994
                                                                               );
995 995
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
996
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
996
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
997 997
             'create_new',
998 998
             'add',
999 999
             [],
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
         /** @var FeatureFlags $flags */
1057 1057
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1058 1058
         // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1059
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1059
+        if ( ! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1060 1060
             $event_values['EVT_display_ticket_selector'] =
1061 1061
                 ! empty($this->_req_data['display_ticket_selector'])
1062 1062
                     ? 1
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
      */
1170 1170
     protected function _default_venue_update(EE_Event $evtobj, $data)
1171 1171
     {
1172
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1172
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1173 1173
         $venue_model = EEM_Venue::instance();
1174 1174
         $rows_affected = null;
1175 1175
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
             'status'              => 'publish',
1201 1201
         ];
1202 1202
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1203
-        if (! empty($venue_id)) {
1203
+        if ( ! empty($venue_id)) {
1204 1204
             $update_where = [$venue_model->primary_key_name() => $venue_id];
1205 1205
             $rows_affected = $venue_model->update($venue_array, [$update_where]);
1206 1206
             // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
                 'DTT_order'     => $row,
1255 1255
             ];
1256 1256
             // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1257
-            if (! empty($dtt['DTT_ID'])) {
1257
+            if ( ! empty($dtt['DTT_ID'])) {
1258 1258
                 $DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']);
1259 1259
                 $DTM->set_date_format($incoming_date_formats[0]);
1260 1260
                 $DTM->set_time_format($incoming_date_formats[1]);
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
                     $DTM->set($field, $value);
1263 1263
                 }
1264 1264
                 // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1265
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1265
+                $saved_dtts[$DTM->ID()] = $DTM;
1266 1266
             } else {
1267 1267
                 $DTM = EE_Registry::instance()->load_class(
1268 1268
                     'Datetime',
@@ -1295,12 +1295,12 @@  discard block
 block discarded – undo
1295 1295
         foreach ($data['edit_tickets'] as $row => $tkt) {
1296 1296
             $incoming_date_formats = ['Y-m-d', 'h:i a'];
1297 1297
             $update_prices = false;
1298
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1299
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1298
+            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1299
+                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1300 1300
             // trim inputs to ensure any excess whitespace is removed.
1301 1301
             $tkt = array_map('trim', $tkt);
1302 1302
             if (empty($tkt['TKT_start_date'])) {
1303
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1303
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1304 1304
             }
1305 1305
             if (empty($tkt['TKT_end_date'])) {
1306 1306
                 // use the start date of the first datetime
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
             // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1336 1336
             // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1337 1337
             // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1338
-            if (! empty($tkt['TKT_ID'])) {
1338
+            if ( ! empty($tkt['TKT_ID'])) {
1339 1339
                 $TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']);
1340 1340
                 if ($TKT instanceof EE_Ticket) {
1341 1341
                     $ticket_sold = $TKT->count_related(
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
                         $TKT->set('TKT_deleted', 1);
1375 1375
                         $TKT->save();
1376 1376
                         // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1377
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1377
+                        $saved_tickets[$TKT->ID()] = $TKT;
1378 1378
                         // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1379 1379
                         $TKT = clone $TKT;
1380 1380
                         $TKT->set('TKT_ID', 0);
@@ -1419,9 +1419,9 @@  discard block
 block discarded – undo
1419 1419
             }
1420 1420
             // initially let's add the ticket to the dtt
1421 1421
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1422
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1422
+            $saved_tickets[$TKT->ID()] = $TKT;
1423 1423
             // add prices to ticket
1424
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1424
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1425 1425
         }
1426 1426
         // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1427 1427
         $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1590 1590
         // load template
1591 1591
         EEH_Template::display_template(
1592
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1592
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1593 1593
             $publish_box_extra_args
1594 1594
         );
1595 1595
     }
@@ -1625,7 +1625,7 @@  discard block
 block discarded – undo
1625 1625
         /** @var FeatureFlags $flags */
1626 1626
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1627 1627
         // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1628
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1628
+        if ( ! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1629 1629
             add_meta_box(
1630 1630
                 'espresso_event_editor_event_options',
1631 1631
                 esc_html__('Event Registration Options', 'event_espresso'),
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
                 'side'
1635 1635
             );
1636 1636
         }
1637
-        if (! $use_advanced_editor) {
1637
+        if ( ! $use_advanced_editor) {
1638 1638
             add_meta_box(
1639 1639
                 'espresso_event_editor_tickets',
1640 1640
                 esc_html__('Event Datetime & Ticket', 'event_espresso'),
@@ -1647,7 +1647,7 @@  discard block
 block discarded – undo
1647 1647
             if ($flags->featureAllowed('use_reg_options_meta_box')) {
1648 1648
                 add_action(
1649 1649
                     'add_meta_boxes_espresso_events',
1650
-                    function () {
1650
+                    function() {
1651 1651
                         global $current_screen;
1652 1652
                         remove_meta_box('authordiv', $current_screen, 'normal');
1653 1653
                     },
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
                     'default_where_conditions' => 'none',
1713 1713
                 ]
1714 1714
             );
1715
-            if (! empty($related_tickets)) {
1715
+            if ( ! empty($related_tickets)) {
1716 1716
                 $template_args['total_ticket_rows'] = count($related_tickets);
1717 1717
                 $row = 0;
1718 1718
                 foreach ($related_tickets as $ticket) {
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
         );
1747 1747
         $template = apply_filters(
1748 1748
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1749
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1749
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1750 1750
         );
1751 1751
         EEH_Template::display_template($template, $template_args);
1752 1752
     }
@@ -1770,7 +1770,7 @@  discard block
 block discarded – undo
1770 1770
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1771 1771
     {
1772 1772
         $template_args = [
1773
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1773
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1774 1774
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1775 1775
                 : '',
1776 1776
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1782,10 +1782,10 @@  discard block
 block discarded – undo
1782 1782
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1783 1783
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1784 1784
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1785
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1786
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1785
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1786
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1787 1787
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1788
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1788
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1789 1789
                 : ' disabled=disabled',
1790 1790
         ];
1791 1791
         $price = $ticket->ID() !== 0
@@ -1812,7 +1812,7 @@  discard block
 block discarded – undo
1812 1812
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
1813 1813
                 )
1814 1814
                 : null;
1815
-            if (! empty($earliest_dtt)) {
1815
+            if ( ! empty($earliest_dtt)) {
1816 1816
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1817 1817
             } else {
1818 1818
                 $template_args['TKT_end_date'] = date(
@@ -1824,7 +1824,7 @@  discard block
 block discarded – undo
1824 1824
         $template_args = array_merge($template_args, $price_args);
1825 1825
         $template = apply_filters(
1826 1826
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1827
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1827
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1828 1828
             $ticket
1829 1829
         );
1830 1830
         return EEH_Template::display_template($template, $template_args, true);
@@ -1879,7 +1879,7 @@  discard block
 block discarded – undo
1879 1879
             $default_reg_status_values
1880 1880
         );
1881 1881
         EEH_Template::display_template(
1882
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1882
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1883 1883
             $template_args
1884 1884
         );
1885 1885
     }
@@ -1909,7 +1909,7 @@  discard block
 block discarded – undo
1909 1909
     {
1910 1910
         $EEME = $this->eventModel();
1911 1911
         $offset = ($current_page - 1) * $per_page;
1912
-        $limit = $count ? null : $offset . ',' . $per_page;
1912
+        $limit = $count ? null : $offset.','.$per_page;
1913 1913
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1914 1914
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1915 1915
         if (isset($this->_req_data['month_range'])) {
@@ -1938,7 +1938,7 @@  discard block
 block discarded – undo
1938 1938
         // categories?
1939 1939
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1940 1940
             ? $this->_req_data['EVT_CAT'] : null;
1941
-        if (! empty($category)) {
1941
+        if ( ! empty($category)) {
1942 1942
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1943 1943
             $where['Term_Taxonomy.term_id'] = $category;
1944 1944
         }
@@ -1946,7 +1946,7 @@  discard block
 block discarded – undo
1946 1946
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1947 1947
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1948 1948
             $DateTime = new DateTime(
1949
-                $year_r . '-' . $month_r . '-01 00:00:00',
1949
+                $year_r.'-'.$month_r.'-01 00:00:00',
1950 1950
                 new DateTimeZone('UTC')
1951 1951
             );
1952 1952
             $start = $DateTime->getTimestamp();
@@ -1972,7 +1972,7 @@  discard block
 block discarded – undo
1972 1972
                             ->format(implode(' ', $start_formats));
1973 1973
             $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1974 1974
         }
1975
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1975
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1976 1976
             $where['EVT_wp_user'] = get_current_user_id();
1977 1977
         } elseif (
1978 1978
             ! isset($where['status'])
@@ -1996,7 +1996,7 @@  discard block
 block discarded – undo
1996 1996
         }
1997 1997
         // search query handling
1998 1998
         if (isset($this->_req_data['s'])) {
1999
-            $search_string = '%' . $this->_req_data['s'] . '%';
1999
+            $search_string = '%'.$this->_req_data['s'].'%';
2000 2000
             $where['OR'] = [
2001 2001
                 'EVT_name'       => ['LIKE', $search_string],
2002 2002
                 'EVT_desc'       => ['LIKE', $search_string],
@@ -2111,7 +2111,7 @@  discard block
 block discarded – undo
2111 2111
             // clean status
2112 2112
             $event_status = sanitize_key($event_status);
2113 2113
             // grab status
2114
-            if (! empty($event_status)) {
2114
+            if ( ! empty($event_status)) {
2115 2115
                 $success = $this->_change_event_status($EVT_ID, $event_status);
2116 2116
             } else {
2117 2117
                 $success = false;
@@ -2153,7 +2153,7 @@  discard block
 block discarded – undo
2153 2153
         // clean status
2154 2154
         $event_status = sanitize_key($event_status);
2155 2155
         // grab status
2156
-        if (! empty($event_status)) {
2156
+        if ( ! empty($event_status)) {
2157 2157
             $success = true;
2158 2158
             // determine the event id and set to array.
2159 2159
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
@@ -2205,7 +2205,7 @@  discard block
 block discarded – undo
2205 2205
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2206 2206
     {
2207 2207
         // grab event id
2208
-        if (! $EVT_ID) {
2208
+        if ( ! $EVT_ID) {
2209 2209
             $msg = esc_html__(
2210 2210
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2211 2211
                 'event_espresso'
@@ -2276,8 +2276,8 @@  discard block
 block discarded – undo
2276 2276
             // get list of events with no prices
2277 2277
             $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
2278 2278
             // remove this event from the list of events with no prices
2279
-            if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2280
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2279
+            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2280
+                unset($espresso_no_ticket_prices[$EVT_ID]);
2281 2281
             }
2282 2282
             update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2283 2283
         } else {
@@ -2324,7 +2324,7 @@  discard block
 block discarded – undo
2324 2324
                 $results = $this->_permanently_delete_event($EVT_ID);
2325 2325
                 $success = $results !== false ? $success : false;
2326 2326
                 // remove this event from the list of events with no prices
2327
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2327
+                unset($espresso_no_ticket_prices[$EVT_ID]);
2328 2328
             } else {
2329 2329
                 $success = false;
2330 2330
                 $msg = esc_html__(
@@ -2356,7 +2356,7 @@  discard block
 block discarded – undo
2356 2356
     private function _permanently_delete_event($EVT_ID = 0)
2357 2357
     {
2358 2358
         // grab event id
2359
-        if (! $EVT_ID) {
2359
+        if ( ! $EVT_ID) {
2360 2360
             $msg = esc_html__(
2361 2361
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2362 2362
                 'event_espresso'
@@ -2370,7 +2370,7 @@  discard block
 block discarded – undo
2370 2370
         ) {
2371 2371
             $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2372 2372
         }
2373
-        if (! $this->_cpt_model_obj instanceof EE_Event) {
2373
+        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2374 2374
             return false;
2375 2375
         }
2376 2376
         // need to delete related tickets and prices first.
@@ -2392,7 +2392,7 @@  discard block
 block discarded – undo
2392 2392
         }
2393 2393
         // any attached question groups?
2394 2394
         $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2395
-        if (! empty($question_groups)) {
2395
+        if ( ! empty($question_groups)) {
2396 2396
             foreach ($question_groups as $question_group) {
2397 2397
                 $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2398 2398
             }
@@ -2625,7 +2625,7 @@  discard block
 block discarded – undo
2625 2625
                                                 . esc_html__(
2626 2626
                                                     '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.',
2627 2627
                                                     'event_espresso'
2628
-                                                ) . '</strong>';
2628
+                                                ).'</strong>';
2629 2629
         $this->display_admin_caf_preview_page('template_settings_tab');
2630 2630
     }
2631 2631
 
@@ -2645,12 +2645,12 @@  discard block
 block discarded – undo
2645 2645
         // set default category object
2646 2646
         $this->_set_empty_category_object();
2647 2647
         // only set if we've got an id
2648
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2648
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2649 2649
             return;
2650 2650
         }
2651 2651
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2652 2652
         $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2653
-        if (! empty($term)) {
2653
+        if ( ! empty($term)) {
2654 2654
             $this->_category->category_name = $term->name;
2655 2655
             $this->_category->category_identifier = $term->slug;
2656 2656
             $this->_category->category_desc = $term->description;
@@ -2682,7 +2682,7 @@  discard block
 block discarded – undo
2682 2682
     {
2683 2683
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2684 2684
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2685
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2685
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2686 2686
             'add_category',
2687 2687
             'add_category',
2688 2688
             [],
@@ -2765,7 +2765,7 @@  discard block
 block discarded – undo
2765 2765
             'disable'                  => '',
2766 2766
             'disabled_message'         => false,
2767 2767
         ];
2768
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2768
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2769 2769
         return EEH_Template::display_template($template, $template_args, true);
2770 2770
     }
2771 2771
 
@@ -2854,7 +2854,7 @@  discard block
 block discarded – undo
2854 2854
         $insert_ids = $update
2855 2855
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2856 2856
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2857
-        if (! is_array($insert_ids)) {
2857
+        if ( ! is_array($insert_ids)) {
2858 2858
             $msg = esc_html__(
2859 2859
                 'An error occurred and the category has not been saved to the database.',
2860 2860
                 'event_espresso'
@@ -2889,7 +2889,7 @@  discard block
 block discarded – undo
2889 2889
         $limit = ($current_page - 1) * $per_page;
2890 2890
         $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2891 2891
         if (isset($this->_req_data['s'])) {
2892
-            $sstr = '%' . $this->_req_data['s'] . '%';
2892
+            $sstr = '%'.$this->_req_data['s'].'%';
2893 2893
             $where['OR'] = [
2894 2894
                 'Term.name'   => ['LIKE', $sstr],
2895 2895
                 'description' => ['LIKE', $sstr],
@@ -2898,7 +2898,7 @@  discard block
 block discarded – undo
2898 2898
         $query_params = [
2899 2899
             $where,
2900 2900
             'order_by'   => [$orderby => $order],
2901
-            'limit'      => $limit . ',' . $per_page,
2901
+            'limit'      => $limit.','.$per_page,
2902 2902
             'force_join' => ['Term'],
2903 2903
         ];
2904 2904
         $categories = $count
Please login to merge, or discard this patch.