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