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