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