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