Completed
Branch EDTR/plugins-page-asset-manage... (186768)
by
unknown
51:19 queued 42:53
created
admin_pages/venues/Venues_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1006,7 +1006,7 @@
 block discarded – undo
1006 1006
      * @access  private
1007 1007
      * @param  int    $VNU_ID
1008 1008
      * @param  string $venue_status
1009
-     * @return void
1009
+     * @return boolean
1010 1010
      */
1011 1011
     private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012 1012
     {
Please login to merge, or discard this patch.
Indentation   +1512 added lines, -1512 removed lines patch added patch discarded remove patch
@@ -17,1518 +17,1518 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * _venue
22
-     * This will hold the venue object for venue_details screen.
23
-     *
24
-     * @access protected
25
-     * @var object
26
-     */
27
-    protected $_venue;
28
-
29
-
30
-    /**
31
-     * This will hold the category object for category_details screen.
32
-     *
33
-     * @var object
34
-     */
35
-    protected $_category;
36
-
37
-
38
-    /**
39
-     * This property will hold the venue model instance
40
-     *
41
-     * @var object
42
-     */
43
-    protected $_venue_model;
44
-
45
-
46
-    protected function _init_page_props()
47
-    {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
49
-        $this->page_slug = EE_VENUES_PG_SLUG;
50
-        $this->_admin_base_url = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
-        $this->page_label = __('Event Venues', 'event_espresso');
53
-        $this->_cpt_model_names = array(
54
-            'create_new' => 'EEM_Venue',
55
-            'edit'       => 'EEM_Venue',
56
-        );
57
-        $this->_cpt_edit_routes = array(
58
-            'espresso_venues' => 'edit',
59
-        );
60
-        $this->_venue_model = EEM_Venue::instance();
61
-    }
62
-
63
-
64
-    protected function _ajax_hooks()
65
-    {
66
-        // todo: all hooks for ee_venues ajax goes in here.
67
-    }
68
-
69
-
70
-    protected function _define_page_props()
71
-    {
72
-        $this->_admin_page_title = $this->page_label;
73
-        $this->_labels = array(
74
-            'buttons'      => array(
75
-                'add'             => __('Add New Venue', 'event_espresso'),
76
-                'edit'            => __('Edit Venue', 'event_espresso'),
77
-                'delete'          => __('Delete Venue', 'event_espresso'),
78
-                'add_category'    => __('Add New Category', 'event_espresso'),
79
-                'edit_category'   => __('Edit Category', 'event_espresso'),
80
-                'delete_category' => __('Delete Category', 'event_espresso'),
81
-            ),
82
-            'editor_title' => array(
83
-                'espresso_venues' => __('Enter Venue name here', 'event_espresso'),
84
-            ),
85
-            'publishbox'   => array(
86
-                'create_new'          => __('Save New Venue', 'event_espresso'),
87
-                'edit'                => __('Update Venue', 'event_espresso'),
88
-                'add_category'        => __('Save New Category', 'event_espresso'),
89
-                'edit_category'       => __('Update Category', 'event_espresso'),
90
-                'google_map_settings' => __('Update Settings', 'event_espresso'),
91
-            ),
92
-        );
93
-    }
94
-
95
-
96
-    protected function _set_page_routes()
97
-    {
98
-
99
-        // load formatter helper
100
-        // load field generator helper
101
-
102
-        // is there a vnu_id in the request?
103
-        $vnu_id = ! empty($this->_req_data['VNU_ID']) && ! is_array($this->_req_data['VNU_ID'])
104
-            ? $this->_req_data['VNU_ID'] : 0;
105
-        $vnu_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $vnu_id;
106
-
107
-        $this->_page_routes = array(
108
-            'default'                    => array(
109
-                'func'       => '_overview_list_table',
110
-                'capability' => 'ee_read_venues',
111
-            ),
112
-            'create_new'                 => array(
113
-                'func'       => '_create_new_cpt_item',
114
-                'capability' => 'ee_edit_venues',
115
-            ),
116
-            'edit'                       => array(
117
-                'func'       => '_edit_cpt_item',
118
-                'capability' => 'ee_edit_venue',
119
-                'obj_id'     => $vnu_id,
120
-            ),
121
-            'trash_venue'                => array(
122
-                'func'       => '_trash_or_restore_venue',
123
-                'args'       => array('venue_status' => 'trash'),
124
-                'noheader'   => true,
125
-                'capability' => 'ee_delete_venue',
126
-                'obj_id'     => $vnu_id,
127
-            ),
128
-            'trash_venues'               => array(
129
-                'func'       => '_trash_or_restore_venues',
130
-                'args'       => array('venue_status' => 'trash'),
131
-                'noheader'   => true,
132
-                'capability' => 'ee_delete_venues',
133
-            ),
134
-            'restore_venue'              => array(
135
-                'func'       => '_trash_or_restore_venue',
136
-                'args'       => array('venue_status' => 'draft'),
137
-                'noheader'   => true,
138
-                'capability' => 'ee_delete_venue',
139
-                'obj_id'     => $vnu_id,
140
-            ),
141
-            'restore_venues'             => array(
142
-                'func'       => '_trash_or_restore_venues',
143
-                'args'       => array('venue_status' => 'draft'),
144
-                'noheader'   => true,
145
-                'capability' => 'ee_delete_venues',
146
-            ),
147
-            'delete_venues'              => array(
148
-                'func'       => '_delete_venues',
149
-                'noheader'   => true,
150
-                'capability' => 'ee_delete_venues',
151
-            ),
152
-            'delete_venue'               => array(
153
-                'func'       => '_delete_venue',
154
-                'noheader'   => true,
155
-                'capability' => 'ee_delete_venue',
156
-                'obj_id'     => $vnu_id,
157
-            ),
158
-            // settings related
159
-            'google_map_settings'        => array(
160
-                'func'       => '_google_map_settings',
161
-                'capability' => 'manage_options',
162
-            ),
163
-            'update_google_map_settings' => array(
164
-                'func'       => '_update_google_map_settings',
165
-                'capability' => 'manage_options',
166
-                'noheader'   => true,
167
-            ),
168
-            // venue category tab related
169
-            'add_category'               => array(
170
-                'func'       => '_category_details',
171
-                'args'       => array('add'),
172
-                'capability' => 'ee_edit_venue_category',
173
-            ),
174
-            'edit_category'              => array(
175
-                'func'       => '_category_details',
176
-                'args'       => array('edit'),
177
-                'capability' => 'ee_edit_venue_category',
178
-            ),
179
-            'delete_categories'          => array(
180
-                'func'       => '_delete_categories',
181
-                'noheader'   => true,
182
-                'capability' => 'ee_delete_venue_category',
183
-            ),
184
-
185
-            'delete_category' => array(
186
-                'func'       => '_delete_categories',
187
-                'noheader'   => true,
188
-                'capability' => 'ee_delete_venue_category',
189
-            ),
190
-
191
-            'insert_category' => array(
192
-                'func'       => '_insert_or_update_category',
193
-                'args'       => array('new_category' => true),
194
-                'noheader'   => true,
195
-                'capability' => 'ee_edit_venue_category',
196
-            ),
197
-
198
-            'update_category'   => array(
199
-                'func'       => '_insert_or_update_category',
200
-                'args'       => array('new_category' => false),
201
-                'noheader'   => true,
202
-                'capability' => 'ee_edit_venue_category',
203
-            ),
204
-            'export_categories' => array(
205
-                'func'       => '_categories_export',
206
-                'noheader'   => true,
207
-                'capability' => 'export',
208
-            ),
209
-            'import_categories' => array(
210
-                'func'       => '_import_categories',
211
-                'capability' => 'import',
212
-            ),
213
-            'category_list'     => array(
214
-                'func'       => '_category_list_table',
215
-                'capability' => 'ee_manage_venue_categories',
216
-            ),
217
-        );
218
-    }
219
-
220
-
221
-    protected function _set_page_config()
222
-    {
223
-        $this->_page_config = array(
224
-            'default'             => array(
225
-                'nav'           => array(
226
-                    'label' => __('Overview', 'event_espresso'),
227
-                    'order' => 10,
228
-                ),
229
-                'list_table'    => 'Venues_Admin_List_Table',
230
-                'help_tabs'     => array(
231
-                    'venues_overview_help_tab'                           => array(
232
-                        'title'    => __('Venues Overview', 'event_espresso'),
233
-                        'filename' => 'venues_overview',
234
-                    ),
235
-                    'venues_overview_table_column_headings_help_tab'     => array(
236
-                        'title'    => __('Venues Overview Table Column Headings', 'event_espresso'),
237
-                        'filename' => 'venues_overview_table_column_headings',
238
-                    ),
239
-                    'venues_overview_views_bulk_actions_search_help_tab' => array(
240
-                        'title'    => __('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
241
-                        'filename' => 'venues_overview_views_bulk_actions_search',
242
-                    ),
243
-                ),
244
-                'help_tour'     => array('Venues_Overview_Help_Tour'),
245
-                'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
246
-                'require_nonce' => false,
247
-            ),
248
-            'create_new'          => array(
249
-                'nav'           => array(
250
-                    'label'      => __('Add Venue', 'event_espresso'),
251
-                    'order'      => 5,
252
-                    'persistent' => false,
253
-                ),
254
-                'help_tabs'     => array(
255
-                    'venues_editor_help_tab'                                               => array(
256
-                        'title'    => __('Venue Editor', 'event_espresso'),
257
-                        'filename' => 'venues_editor',
258
-                    ),
259
-                    'venues_editor_title_richtexteditor_help_tab'                          => array(
260
-                        'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
261
-                        'filename' => 'venues_editor_title_richtexteditor',
262
-                    ),
263
-                    'venues_editor_tags_categories_help_tab'                               => array(
264
-                        'title'    => __('Venue Tags & Categories', 'event_espresso'),
265
-                        'filename' => 'venues_editor_tags_categories',
266
-                    ),
267
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
268
-                        'title'    => __(
269
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
270
-                            'event_espresso'
271
-                        ),
272
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
273
-                    ),
274
-                    'venues_editor_save_new_venue_help_tab'                                => array(
275
-                        'title'    => __('Save New Venue', 'event_espresso'),
276
-                        'filename' => 'venues_editor_save_new_venue',
277
-                    ),
278
-                    'venues_editor_other_help_tab'                                         => array(
279
-                        'title'    => __('Venue Editor Other', 'event_espresso'),
280
-                        'filename' => 'venues_editor_other',
281
-                    ),
282
-                ),
283
-                'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
284
-                'metaboxes'     => array('_venue_editor_metaboxes'),
285
-                'require_nonce' => false,
286
-            ),
287
-            'edit'                => array(
288
-                'nav'           => array(
289
-                    'label'      => __('Edit Venue', 'event_espresso'),
290
-                    'order'      => 5,
291
-                    'persistent' => false,
292
-                    'url'        => isset($this->_req_data['post']) ? add_query_arg(
293
-                        array('post' => $this->_req_data['post']),
294
-                        $this->_current_page_view_url
295
-                    ) : $this->_admin_base_url,
296
-                ),
297
-                'help_tabs'     => array(
298
-                    'venues_editor_help_tab'                                               => array(
299
-                        'title'    => __('Venue Editor', 'event_espresso'),
300
-                        'filename' => 'venues_editor',
301
-                    ),
302
-                    'venues_editor_title_richtexteditor_help_tab'                          => array(
303
-                        'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
304
-                        'filename' => 'venues_editor_title_richtexteditor',
305
-                    ),
306
-                    'venues_editor_tags_categories_help_tab'                               => array(
307
-                        'title'    => __('Venue Tags & Categories', 'event_espresso'),
308
-                        'filename' => 'venues_editor_tags_categories',
309
-                    ),
310
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
311
-                        'title'    => __(
312
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
313
-                            'event_espresso'
314
-                        ),
315
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
316
-                    ),
317
-                    'venues_editor_save_new_venue_help_tab'                                => array(
318
-                        'title'    => __('Save New Venue', 'event_espresso'),
319
-                        'filename' => 'venues_editor_save_new_venue',
320
-                    ),
321
-                    'venues_editor_other_help_tab'                                         => array(
322
-                        'title'    => __('Venue Editor Other', 'event_espresso'),
323
-                        'filename' => 'venues_editor_other',
324
-                    ),
325
-                ),
326
-                /*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
327
-                'metaboxes'     => array('_venue_editor_metaboxes'),
328
-                'require_nonce' => false,
329
-            ),
330
-            'google_map_settings' => array(
331
-                'nav'           => array(
332
-                    'label' => esc_html__('Google Maps', 'event_espresso'),
333
-                    'order' => 40,
334
-                ),
335
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
336
-                'help_tabs'     => array(
337
-                    'general_settings_google_maps_help_tab' => array(
338
-                        'title'    => __('Google Maps', 'event_espresso'),
339
-                        'filename' => 'general_settings_google_maps',
340
-                    ),
341
-                ),
342
-                'help_tour'     => array('Google_Maps_Help_Tour'),
343
-                'require_nonce' => false,
344
-            ),
345
-            // venue category stuff
346
-            'add_category'        => array(
347
-                'nav'           => array(
348
-                    'label'      => __('Add Category', 'event_espresso'),
349
-                    'order'      => 15,
350
-                    'persistent' => false,
351
-                ),
352
-                'metaboxes'     => array('_publish_post_box'),
353
-                'help_tabs'     => array(
354
-                    'venues_add_category_help_tab' => array(
355
-                        'title'    => __('Add New Venue Category', 'event_espresso'),
356
-                        'filename' => 'venues_add_category',
357
-                    ),
358
-                ),
359
-                'help_tour'     => array('Venues_Add_Category_Help_Tour'),
360
-                'require_nonce' => false,
361
-            ),
362
-            'edit_category'       => array(
363
-                'nav'           => array(
364
-                    'label'      => __('Edit Category', 'event_espresso'),
365
-                    'order'      => 15,
366
-                    'persistent' => false,
367
-                    'url'        => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(
368
-                        array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
369
-                        $this->_current_page_view_url
370
-                    ) : $this->_admin_base_url,
371
-                ),
372
-                'metaboxes'     => array('_publish_post_box'),
373
-                'help_tabs'     => array(
374
-                    'venues_edit_category_help_tab' => array(
375
-                        'title'    => __('Edit Venue Category', 'event_espresso'),
376
-                        'filename' => 'venues_edit_category',
377
-                    ),
378
-                ),
379
-                /*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
380
-                'require_nonce' => false,
381
-            ),
382
-            'category_list'       => array(
383
-                'nav'           => array(
384
-                    'label' => __('Categories', 'event_espresso'),
385
-                    'order' => 20,
386
-                ),
387
-                'list_table'    => 'Venue_Categories_Admin_List_Table',
388
-                'help_tabs'     => array(
389
-                    'venues_categories_help_tab'                       => array(
390
-                        'title'    => __('Venue Categories', 'event_espresso'),
391
-                        'filename' => 'venues_categories',
392
-                    ),
393
-                    'venues_categories_table_column_headings_help_tab' => array(
394
-                        'title'    => __('Venue Categories Table Column Headings', 'event_espresso'),
395
-                        'filename' => 'venues_categories_table_column_headings',
396
-                    ),
397
-                    'venues_categories_views_help_tab'                 => array(
398
-                        'title'    => __('Venue Categories Views', 'event_espresso'),
399
-                        'filename' => 'venues_categories_views',
400
-                    ),
401
-                    'venues_categories_other_help_tab'                 => array(
402
-                        'title'    => __('Venue Categories Other', 'event_espresso'),
403
-                        'filename' => 'venues_categories_other',
404
-                    ),
405
-                ),
406
-                'help_tour'     => array('Venues_Categories_Help_Tour'),
407
-                'metaboxes'     => $this->_default_espresso_metaboxes,
408
-                'require_nonce' => false,
409
-            ),
410
-        );
411
-    }
412
-
413
-
414
-    protected function _add_screen_options()
415
-    {
416
-        // todo
417
-    }
418
-
419
-
420
-    protected function _add_screen_options_default()
421
-    {
422
-        $this->_per_page_screen_option();
423
-    }
424
-
425
-
426
-    protected function _add_screen_options_category_list()
427
-    {
428
-        $page_title = $this->_admin_page_title;
429
-        $this->_admin_page_title = __('Venue Categories', 'event_espresso');
430
-        $this->_per_page_screen_option();
431
-        $this->_admin_page_title = $page_title;
432
-    }
433
-
434
-
435
-    // none of the below group are currently used for Event Venues
436
-    protected function _add_feature_pointers()
437
-    {
438
-    }
439
-
440
-    public function admin_init()
441
-    {
442
-    }
443
-
444
-    public function admin_notices()
445
-    {
446
-    }
447
-
448
-    public function admin_footer_scripts()
449
-    {
450
-    }
451
-
452
-
453
-    public function load_scripts_styles_create_new()
454
-    {
455
-        $this->load_scripts_styles_edit();
456
-    }
457
-
458
-
459
-    public function load_scripts_styles()
460
-    {
461
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
462
-        wp_enqueue_style('ee-cat-admin');
463
-    }
464
-
465
-
466
-    public function load_scripts_styles_add_category()
467
-    {
468
-        $this->load_scripts_styles_edit_category();
469
-    }
470
-
471
-
472
-    public function load_scripts_styles_edit_category()
473
-    {
474
-    }
475
-
476
-
477
-    public function load_scripts_styles_edit()
478
-    {
479
-        // styles
480
-        wp_enqueue_style('espresso-ui-theme');
481
-        wp_register_style(
482
-            'espresso_venues',
483
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
484
-            array(),
485
-            EVENT_ESPRESSO_VERSION
486
-        );
487
-        wp_enqueue_style('espresso_venues');
488
-    }
489
-
490
-
491
-    protected function _set_list_table_views_default()
492
-    {
493
-        $this->_views = array(
494
-            'all' => array(
495
-                'slug'        => 'all',
496
-                'label'       => __('View All Venues', 'event_espresso'),
497
-                'count'       => 0,
498
-                'bulk_action' => array(),
499
-            ),
500
-        );
501
-
502
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
503
-            $this->_views['all']['bulk_action'] = array(
504
-                'trash_venues' => __('Move to Trash', 'event_espresso'),
505
-            );
506
-            $this->_views['trash'] = array(
507
-                'slug'        => 'trash',
508
-                'label'       => __('Trash', 'event_espresso'),
509
-                'count'       => 0,
510
-                'bulk_action' => array(
511
-                    'restore_venues' => __('Restore from Trash', 'event_espresso'),
512
-                    'delete_venues'  => __('Delete', 'event_espresso'),
513
-                ),
514
-            );
515
-        }
516
-    }
517
-
518
-
519
-    protected function _set_list_table_views_category_list()
520
-    {
521
-        $this->_views = array(
522
-            'all' => array(
523
-                'slug'        => 'all',
524
-                'label'       => __('All', 'event_espresso'),
525
-                'count'       => 0,
526
-                'bulk_action' => array(
527
-                    'delete_categories' => __('Delete Permanently', 'event_espresso'),
528
-                ),
529
-            ),
530
-        );
531
-    }
532
-
533
-
534
-    protected function _overview_list_table()
535
-    {
536
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
537
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
538
-            get_post_type_archive_link('espresso_venues'),
539
-            __("View Venue Archive Page", "event_espresso"),
540
-            'button'
541
-        );
542
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
543
-        $this->_search_btn_label = __('Venues', 'event_espresso');
544
-        $this->display_admin_list_table_page_with_sidebar();
545
-    }
546
-
547
-
548
-    public function extra_misc_actions_publish_box()
549
-    {
550
-        $extra_rows = array(
551
-            'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
552
-            'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
553
-            'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
554
-        );
555
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
556
-        EEH_Template::display_template($template, $extra_rows);
557
-    }
558
-
559
-
560
-    /*************        Google Maps        *************/
561
-
562
-
563
-    protected function _google_map_settings()
564
-    {
565
-
566
-
567
-        $this->_template_args['values'] = $this->_yes_no_values;
568
-        $default_map_settings = new stdClass();
569
-        $default_map_settings->use_google_maps = true;
570
-        $default_map_settings->google_map_api_key = '';
571
-        // for event details pages (reg page)
572
-        $default_map_settings->event_details_map_width = 585;            // ee_map_width_single
573
-        $default_map_settings->event_details_map_height = 362;            // ee_map_height_single
574
-        $default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
575
-        $default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
576
-        $default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
577
-        $default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
578
-        $default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
579
-        // for event list pages
580
-        $default_map_settings->event_list_map_width = 300;            // ee_map_width
581
-        $default_map_settings->event_list_map_height = 185;        // ee_map_height
582
-        $default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
583
-        $default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
584
-        $default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
585
-        $default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
586
-        $default_map_settings->event_list_map_align = 'center';            // ee_map_align
587
-
588
-        $this->_template_args['map_settings'] =
589
-            isset(EE_Registry::instance()->CFG->map_settings)
590
-            && ! empty(EE_Registry::instance()->CFG->map_settings)
591
-                ? (object) array_merge(
592
-                    (array) $default_map_settings,
593
-                    (array) EE_Registry::instance()->CFG->map_settings
594
-                )
595
-                : $default_map_settings;
596
-
597
-        $this->_set_add_edit_form_tags('update_google_map_settings');
598
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
599
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
600
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
601
-            $this->_template_args,
602
-            true
603
-        );
604
-        $this->display_admin_page_with_sidebar();
605
-    }
606
-
607
-    protected function _update_google_map_settings()
608
-    {
609
-
610
-        EE_Registry::instance()->CFG->map_settings->use_google_maps =
611
-            isset($this->_req_data['use_google_maps'])
612
-                ? absint($this->_req_data['use_google_maps'])
613
-                : EE_Registry::instance()->CFG->map_settings->use_google_maps;
614
-
615
-        EE_Registry::instance()->CFG->map_settings->google_map_api_key =
616
-            isset($this->_req_data['google_map_api_key'])
617
-                ? sanitize_text_field($this->_req_data['google_map_api_key'])
618
-                : EE_Registry::instance()->CFG->map_settings->google_map_api_key;
619
-
620
-        EE_Registry::instance()->CFG->map_settings->event_details_map_width =
621
-            isset($this->_req_data['event_details_map_width'])
622
-                ? absint($this->_req_data['event_details_map_width'])
623
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_width;
624
-
625
-        EE_Registry::instance()->CFG->map_settings->event_details_map_height =
626
-            isset($this->_req_data['event_details_map_height'])
627
-                ? absint($this->_req_data['event_details_map_height'])
628
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_height;
629
-
630
-        EE_Registry::instance()->CFG->map_settings->event_details_map_zoom =
631
-            isset($this->_req_data['event_details_map_zoom'])
632
-                ? absint($this->_req_data['event_details_map_zoom'])
633
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_zoom;
634
-
635
-        EE_Registry::instance()->CFG->map_settings->event_details_display_nav =
636
-            isset($this->_req_data['event_details_display_nav'])
637
-                ? absint($this->_req_data['event_details_display_nav'])
638
-                : EE_Registry::instance()->CFG->map_settings->event_details_display_nav;
639
-
640
-        EE_Registry::instance()->CFG->map_settings->event_details_nav_size =
641
-            isset($this->_req_data['event_details_nav_size'])
642
-                ? absint($this->_req_data['event_details_nav_size'])
643
-                : EE_Registry::instance()->CFG->map_settings->event_details_nav_size;
644
-
645
-        EE_Registry::instance()->CFG->map_settings->event_details_control_type =
646
-            isset($this->_req_data['event_details_control_type'])
647
-                ? sanitize_text_field($this->_req_data['event_details_control_type'])
648
-                : EE_Registry::instance()->CFG->map_settings->event_details_control_type;
649
-
650
-        EE_Registry::instance()->CFG->map_settings->event_details_map_align =
651
-            isset($this->_req_data['event_details_map_align'])
652
-                ? sanitize_text_field($this->_req_data['event_details_map_align'])
653
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_align;
654
-
655
-        EE_Registry::instance()->CFG->map_settings->event_list_map_width =
656
-            isset($this->_req_data['event_list_map_width'])
657
-                ? absint($this->_req_data['event_list_map_width'])
658
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_width;
659
-
660
-        EE_Registry::instance()->CFG->map_settings->event_list_map_height =
661
-            isset($this->_req_data['event_list_map_height'])
662
-                ? absint($this->_req_data['event_list_map_height'])
663
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_height;
664
-
665
-        EE_Registry::instance()->CFG->map_settings->event_list_map_zoom =
666
-            isset($this->_req_data['event_list_map_zoom'])
667
-                ? absint($this->_req_data['event_list_map_zoom'])
668
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_zoom;
669
-
670
-        EE_Registry::instance()->CFG->map_settings->event_list_display_nav =
671
-            isset($this->_req_data['event_list_display_nav'])
672
-                ? absint($this->_req_data['event_list_display_nav'])
673
-                : EE_Registry::instance()->CFG->map_settings->event_list_display_nav;
674
-
675
-        EE_Registry::instance()->CFG->map_settings->event_list_nav_size =
676
-            isset($this->_req_data['event_list_nav_size'])
677
-                ? absint($this->_req_data['event_list_nav_size'])
678
-                : EE_Registry::instance()->CFG->map_settings->event_list_nav_size;
679
-
680
-        EE_Registry::instance()->CFG->map_settings->event_list_control_type =
681
-            isset($this->_req_data['event_list_control_type'])
682
-                ? sanitize_text_field($this->_req_data['event_list_control_type'])
683
-                : EE_Registry::instance()->CFG->map_settings->event_list_control_type;
684
-
685
-        EE_Registry::instance()->CFG->map_settings->event_list_map_align =
686
-            isset($this->_req_data['event_list_map_align'])
687
-                ? sanitize_text_field($this->_req_data['event_list_map_align'])
688
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_align;
689
-
690
-        EE_Registry::instance()->CFG->map_settings = apply_filters(
691
-            'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
692
-            EE_Registry::instance()->CFG->map_settings
693
-        );
694
-
695
-        $what = 'Google Map Settings';
696
-        $success = $this->_update_espresso_configuration(
697
-            $what,
698
-            EE_Registry::instance()->CFG->map_settings,
699
-            __FILE__,
700
-            __FUNCTION__,
701
-            __LINE__
702
-        );
703
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings'));
704
-    }
705
-
706
-
707
-    protected function _venue_editor_metaboxes()
708
-    {
709
-        $this->verify_cpt_object();
710
-
711
-        add_meta_box(
712
-            'espresso_venue_address_options',
713
-            __('Physical Location', 'event_espresso'),
714
-            array($this, 'venue_address_metabox'),
715
-            $this->page_slug,
716
-            'side',
717
-            'default'
718
-        );
719
-        add_meta_box(
720
-            'espresso_venue_gmap_options',
721
-            __('Google Map', 'event_espresso'),
722
-            array($this, 'venue_gmap_metabox'),
723
-            $this->page_slug,
724
-            'side',
725
-            'default'
726
-        );
727
-        add_meta_box(
728
-            'espresso_venue_virtual_loc_options',
729
-            __('Virtual Location', 'event_espresso'),
730
-            array($this, 'venue_virtual_loc_metabox'),
731
-            $this->page_slug,
732
-            'side',
733
-            'default'
734
-        );
735
-    }
736
-
737
-
738
-    public function venue_gmap_metabox()
739
-    {
740
-        $template_args = array(
741
-            'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
742
-                'vnu_enable_for_gmap',
743
-                $this->get_yes_no_values(),
744
-                $this->_cpt_model_obj->enable_for_gmap()
745
-            ),
746
-            'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
747
-        );
748
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
749
-        EEH_Template::display_template($template, $template_args);
750
-    }
751
-
752
-
753
-    public function venue_address_metabox()
754
-    {
755
-
756
-        $template_args['_venue'] = $this->_cpt_model_obj;
757
-
758
-        $template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input(
759
-            $QFI = new EE_Question_Form_Input(
760
-                EE_Question::new_instance(
761
-                    array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')
762
-                ),
763
-                EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->state_ID())),
764
-                array(
765
-                    'input_name'     => 'sta_id',
766
-                    'input_id'       => 'sta_id',
767
-                    'input_class'    => '',
768
-                    'input_prefix'   => '',
769
-                    'append_qstn_id' => false,
770
-                )
771
-            )
772
-        );
773
-        $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
774
-            $QFI = new EE_Question_Form_Input(
775
-                EE_Question::new_instance(
776
-                    array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')
777
-                ),
778
-                EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->country_ID())),
779
-                array(
780
-                    'input_name'     => 'cnt_iso',
781
-                    'input_id'       => 'cnt_iso',
782
-                    'input_class'    => '',
783
-                    'input_prefix'   => '',
784
-                    'append_qstn_id' => false,
785
-                )
786
-            )
787
-        );
788
-
789
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
790
-        EEH_Template::display_template($template, $template_args);
791
-    }
792
-
793
-
794
-    public function venue_virtual_loc_metabox()
795
-    {
796
-        $template_args = array(
797
-            '_venue' => $this->_cpt_model_obj,
798
-        );
799
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
800
-        EEH_Template::display_template($template, $template_args);
801
-    }
802
-
803
-
804
-    protected function _restore_cpt_item($post_id, $revision_id)
805
-    {
806
-        $venue_obj = $this->_venue_model->get_one_by_ID($post_id);
807
-
808
-        // meta revision restore
809
-        $venue_obj->restore_revision($revision_id);
810
-    }
811
-
812
-
813
-    /**
814
-     * Handles updates for venue cpts
815
-     *
816
-     * @param  int    $post_id ID of Venue CPT
817
-     * @param  object $post    Post object (with "blessed" WP properties)
818
-     * @return void
819
-     */
820
-    protected function _insert_update_cpt_item($post_id, $post)
821
-    {
822
-
823
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
824
-            return;// get out we're not processing the saving of venues.
825
-        }
826
-
827
-        $wheres = array($this->_venue_model->primary_key_name() => $post_id);
828
-
829
-        $venue_values = array(
830
-            'VNU_address'         => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : null,
831
-            'VNU_address2'        => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2']
832
-                : null,
833
-            'VNU_city'            => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : null,
834
-            'STA_ID'              => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : null,
835
-            'CNT_ISO'             => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : null,
836
-            'VNU_zip'             => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : null,
837
-            'VNU_phone'           => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : null,
838
-            'VNU_capacity'        => ! empty($this->_req_data['vnu_capacity']) ? str_replace(
839
-                ',',
840
-                '',
841
-                $this->_req_data['vnu_capacity']
842
-            ) : EE_INF,
843
-            'VNU_url'             => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : null,
844
-            'VNU_virtual_phone'   => ! empty($this->_req_data['vnu_virtual_phone'])
845
-                ? $this->_req_data['vnu_virtual_phone'] : null,
846
-            'VNU_virtual_url'     => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url']
847
-                : null,
848
-            'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? true : false,
849
-            'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link'])
850
-                ? $this->_req_data['vnu_google_map_link'] : null,
851
-        );
852
-
853
-        // update venue
854
-        $success = $this->_venue_model->update($venue_values, array($wheres));
855
-
856
-        // get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_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!
857
-        $get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status);
858
-        $venue = $this->_venue_model->get_one(array($get_one_where));
859
-
860
-        // notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
861
-        $venue_update_callbacks = apply_filters(
862
-            'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
863
-            array()
864
-        );
865
-
866
-        $att_success = true;
867
-
868
-        foreach ($venue_update_callbacks as $v_callback) {
869
-            $_succ = call_user_func_array($v_callback, array($venue, $this->_req_data));
870
-            $att_success = ! $att_success ? $att_success
871
-                : $_succ; // if ANY of these updates fail then we want the appropriate global error message
872
-        }
873
-
874
-        // any errors?
875
-        if ($success && ! $att_success) {
876
-            EE_Error::add_error(
877
-                __(
878
-                    'Venue Details saved successfully but something went wrong with saving attachments.',
879
-                    'event_espresso'
880
-                ),
881
-                __FILE__,
882
-                __FUNCTION__,
883
-                __LINE__
884
-            );
885
-        } elseif ($success === false) {
886
-            EE_Error::add_error(
887
-                __('Venue Details did not save successfully.', 'event_espresso'),
888
-                __FILE__,
889
-                __FUNCTION__,
890
-                __LINE__
891
-            );
892
-        }
893
-    }
894
-
895
-
896
-    public function trash_cpt_item($post_id)
897
-    {
898
-        $this->_req_data['VNU_ID'] = $post_id;
899
-        $this->_trash_or_restore_venue('trash', false);
900
-    }
901
-
902
-
903
-    public function restore_cpt_item($post_id)
904
-    {
905
-        $this->_req_data['VNU_ID'] = $post_id;
906
-        $this->_trash_or_restore_venue('draft', false);
907
-    }
908
-
909
-
910
-    public function delete_cpt_item($post_id)
911
-    {
912
-        $this->_req_data['VNU_ID'] = $post_id;
913
-        $this->_delete_venue(false);
914
-    }
915
-
916
-
917
-    public function get_venue_object()
918
-    {
919
-        return $this->_cpt_model_obj;
920
-    }
921
-
922
-
923
-    protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
924
-    {
925
-        $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : false;
926
-
927
-        // loop thru venues
928
-        if ($VNU_ID) {
929
-            // clean status
930
-            $venue_status = sanitize_key($venue_status);
931
-            // grab status
932
-            if (! empty($venue_status)) {
933
-                $success = $this->_change_venue_status($VNU_ID, $venue_status);
934
-            } else {
935
-                $success = false;
936
-                $msg = __(
937
-                    'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
938
-                    'event_espresso'
939
-                );
940
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
941
-            }
942
-        } else {
943
-            $success = false;
944
-            $msg = __(
945
-                'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
946
-                'event_espresso'
947
-            );
948
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
949
-        }
950
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
951
-
952
-        if ($redirect_after) {
953
-            $this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default'));
954
-        }
955
-    }
956
-
957
-
958
-    protected function _trash_or_restore_venues($venue_status = 'trash')
959
-    {
960
-        // clean status
961
-        $venue_status = sanitize_key($venue_status);
962
-        // grab status
963
-        if (! empty($venue_status)) {
964
-            $success = true;
965
-            // determine the event id and set to array.
966
-            $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
967
-            // loop thru events
968
-            foreach ($VNU_IDs as $VNU_ID) {
969
-                if ($VNU_ID = absint($VNU_ID)) {
970
-                    $results = $this->_change_venue_status($VNU_ID, $venue_status);
971
-                    $success = $results !== false ? $success : false;
972
-                } else {
973
-                    $msg = sprintf(
974
-                        __(
975
-                            'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
976
-                            'event_espresso'
977
-                        ),
978
-                        $VNU_ID
979
-                    );
980
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
981
-                    $success = false;
982
-                }
983
-            }
984
-        } else {
985
-            $success = false;
986
-            $msg = __(
987
-                'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
988
-                'event_espresso'
989
-            );
990
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
991
-        }
992
-        // in order to force a pluralized result message we need to send back a success status greater than 1
993
-        $success = $success ? 2 : false;
994
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
995
-        $this->_redirect_after_action($success, 'Venues', $action, array('action' => 'default'));
996
-    }
997
-
998
-
999
-    /**
1000
-     * _trash_or_restore_venues
1001
-     *
1002
-     * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1003
-     * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1004
-     * accepting a certain number of params.
1005
-     *
1006
-     * @access  private
1007
-     * @param  int    $VNU_ID
1008
-     * @param  string $venue_status
1009
-     * @return void
1010
-     */
1011
-    private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012
-    {
1013
-        // grab venue id
1014
-        if (! $VNU_ID) {
1015
-            $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1016
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1017
-            return false;
1018
-        }
1019
-
1020
-        $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1021
-
1022
-        // clean status
1023
-        $venue_status = sanitize_key($venue_status);
1024
-        // grab status
1025
-        if (! $venue_status) {
1026
-            $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1027
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028
-            return false;
1029
-        }
1030
-
1031
-        // was event trashed or restored ?
1032
-        switch ($venue_status) {
1033
-            case 'draft':
1034
-                $action = 'restored from the trash';
1035
-                $hook = 'AHEE_venue_restored_from_trash';
1036
-                break;
1037
-            case 'trash':
1038
-                $action = 'moved to the trash';
1039
-                $hook = 'AHEE_venue_moved_to_trash';
1040
-                break;
1041
-            default:
1042
-                $action = 'updated';
1043
-                $hook = false;
1044
-        }
1045
-        // use class to change status
1046
-        $this->_cpt_model_obj->set_status($venue_status);
1047
-        $success = $this->_cpt_model_obj->save();
1048
-
1049
-        if ($success === false) {
1050
-            $msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1051
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1052
-            return false;
1053
-        }
1054
-        if ($hook) {
1055
-            do_action($hook);
1056
-        }
1057
-        return true;
1058
-    }
1059
-
1060
-
1061
-    /**
1062
-     * @param  bool $redirect_after
1063
-     * @return void
1064
-     */
1065
-    protected function _delete_venue($redirect_after = true)
1066
-    {
1067
-        // determine the venue id and set to array.
1068
-        $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : null;
1069
-        $VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID;
1070
-
1071
-
1072
-        // loop thru venues
1073
-        if ($VNU_ID) {
1074
-            $success = $this->_delete_or_trash_venue($VNU_ID);
1075
-        } else {
1076
-            $success = false;
1077
-            $msg = __(
1078
-                'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1079
-                'event_espresso'
1080
-            );
1081
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1082
-        }
1083
-        if ($redirect_after) {
1084
-            $this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default'));
1085
-        }
1086
-    }
1087
-
1088
-
1089
-    protected function _delete_venues()
1090
-    {
1091
-        $success = true;
1092
-        // determine the event id and set to array.
1093
-        $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
1094
-        // loop thru events
1095
-        foreach ($VNU_IDs as $VNU_ID) {
1096
-            if ($VNU_ID = absint($VNU_ID)) {
1097
-                $results = $this->_delete_or_trash_venue($VNU_ID);
1098
-                $success = $results !== false ? $success : false;
1099
-            } else {
1100
-                $success = false;
1101
-                $msg = __(
1102
-                    'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1103
-                    'event_espresso'
1104
-                );
1105
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1106
-            }
1107
-        }
1108
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1109
-        $success = $success ? 2 : false;
1110
-        $this->_redirect_after_action(
1111
-            $success,
1112
-            __('Venues', 'event_espresso'),
1113
-            __('deleted', 'event_espresso'),
1114
-            array('action' => 'default')
1115
-        );
1116
-    }
1117
-
1118
-
1119
-    // todo: put in parent
1120
-    private function _delete_or_trash_venue($VNU_ID = false)
1121
-    {
1122
-        // grab event id
1123
-        if (! $VNU_ID = absint($VNU_ID)) {
1124
-            $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1125
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1126
-            return false;
1127
-        }
1128
-
1129
-
1130
-        $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1131
-        // first need to remove all term relationships
1132
-        $venue->_remove_relations('Term_Taxonomy');
1133
-        $success = $venue->delete_permanently();
1134
-        // did it all go as planned ?
1135
-        if ($success) {
1136
-            $msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1137
-            EE_Error::add_success($msg);
1138
-        } else {
1139
-            $msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID);
1140
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1141
-            return false;
1142
-        }
1143
-        do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1144
-        return true;
1145
-    }
1146
-
1147
-
1148
-
1149
-
1150
-    /***********/
1151
-    /* QUERIES */
1152
-
1153
-
1154
-    public function get_venues($per_page = 10, $count = false)
1155
-    {
1156
-
1157
-        $_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1158
-
1159
-        switch ($_orderby) {
1160
-            case 'id':
1161
-                $orderby = 'VNU_ID';
1162
-                break;
1163
-
1164
-            case 'capacity':
1165
-                $orderby = 'VNU_capacity';
1166
-                break;
1167
-
1168
-            case 'city':
1169
-                $orderby = 'VNU_city';
1170
-                break;
1171
-
1172
-            default:
1173
-                $orderby = 'VNU_name';
1174
-        }
1175
-
1176
-
1177
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1178
-            : 'ASC';
1179
-
1180
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1181
-            ? $this->_req_data['paged'] : 1;
1182
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
1183
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1184
-            ? $this->_req_data['perpage'] : $per_page;
1185
-
1186
-
1187
-        $offset = ($current_page - 1) * $per_page;
1188
-        $limit = array($offset, $per_page);
1189
-
1190
-        $category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0
1191
-            ? $this->_req_data['category'] : null;
1192
-        $where = array();
1193
-
1194
-        // only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1195
-        if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') {
1196
-            $where['status'] = $this->_req_data['status'];
1197
-        }
1198
-
1199
-        if (isset($this->_req_data['venue_status'])) {
1200
-            $where['status'] = $this->_req_data['venue_status'];
1201
-        }
1202
-
1203
-
1204
-        if ($category) {
1205
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1206
-            $where['Term_Taxonomy.term_id'] = $category;
1207
-        }
1208
-
1209
-
1210
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1211
-            $where['VNU_wp_user'] = get_current_user_id();
1212
-        } else {
1213
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1214
-                $where['OR'] = array(
1215
-                    'status*restrict_private' => array('!=', 'private'),
1216
-                    'AND'                     => array(
1217
-                        'status*inclusive' => array('=', 'private'),
1218
-                        'VNU_wp_user'      => get_current_user_id(),
1219
-                    ),
1220
-                );
1221
-            }
1222
-        }
1223
-
1224
-
1225
-        if (isset($this->_req_data['s'])) {
1226
-            $sstr = '%' . $this->_req_data['s'] . '%';
1227
-            $where['OR'] = array(
1228
-                'VNU_name'               => array('LIKE', $sstr),
1229
-                'VNU_desc'               => array('LIKE', $sstr),
1230
-                'VNU_short_desc'         => array('LIKE', $sstr),
1231
-                'VNU_address'            => array('LIKE', $sstr),
1232
-                'VNU_address2'           => array('LIKE', $sstr),
1233
-                'VNU_city'               => array('LIKE', $sstr),
1234
-                'VNU_zip'                => array('LIKE', $sstr),
1235
-                'VNU_phone'              => array('LIKE', $sstr),
1236
-                'VNU_url'                => array('LIKE', $sstr),
1237
-                'VNU_virtual_phone'      => array('LIKE', $sstr),
1238
-                'VNU_virtual_url'        => array('LIKE', $sstr),
1239
-                'VNU_google_map_link'    => array('LIKE', $sstr),
1240
-                'Event.EVT_name'         => array('LIKE', $sstr),
1241
-                'Event.EVT_desc'         => array('LIKE', $sstr),
1242
-                'Event.EVT_phone'        => array('LIKE', $sstr),
1243
-                'Event.EVT_external_URL' => array('LIKE', $sstr),
1244
-            );
1245
-        }
20
+	/**
21
+	 * _venue
22
+	 * This will hold the venue object for venue_details screen.
23
+	 *
24
+	 * @access protected
25
+	 * @var object
26
+	 */
27
+	protected $_venue;
28
+
29
+
30
+	/**
31
+	 * This will hold the category object for category_details screen.
32
+	 *
33
+	 * @var object
34
+	 */
35
+	protected $_category;
36
+
37
+
38
+	/**
39
+	 * This property will hold the venue model instance
40
+	 *
41
+	 * @var object
42
+	 */
43
+	protected $_venue_model;
44
+
45
+
46
+	protected function _init_page_props()
47
+	{
48
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
49
+		$this->page_slug = EE_VENUES_PG_SLUG;
50
+		$this->_admin_base_url = EE_VENUES_ADMIN_URL;
51
+		$this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
+		$this->page_label = __('Event Venues', 'event_espresso');
53
+		$this->_cpt_model_names = array(
54
+			'create_new' => 'EEM_Venue',
55
+			'edit'       => 'EEM_Venue',
56
+		);
57
+		$this->_cpt_edit_routes = array(
58
+			'espresso_venues' => 'edit',
59
+		);
60
+		$this->_venue_model = EEM_Venue::instance();
61
+	}
62
+
63
+
64
+	protected function _ajax_hooks()
65
+	{
66
+		// todo: all hooks for ee_venues ajax goes in here.
67
+	}
68
+
69
+
70
+	protected function _define_page_props()
71
+	{
72
+		$this->_admin_page_title = $this->page_label;
73
+		$this->_labels = array(
74
+			'buttons'      => array(
75
+				'add'             => __('Add New Venue', 'event_espresso'),
76
+				'edit'            => __('Edit Venue', 'event_espresso'),
77
+				'delete'          => __('Delete Venue', 'event_espresso'),
78
+				'add_category'    => __('Add New Category', 'event_espresso'),
79
+				'edit_category'   => __('Edit Category', 'event_espresso'),
80
+				'delete_category' => __('Delete Category', 'event_espresso'),
81
+			),
82
+			'editor_title' => array(
83
+				'espresso_venues' => __('Enter Venue name here', 'event_espresso'),
84
+			),
85
+			'publishbox'   => array(
86
+				'create_new'          => __('Save New Venue', 'event_espresso'),
87
+				'edit'                => __('Update Venue', 'event_espresso'),
88
+				'add_category'        => __('Save New Category', 'event_espresso'),
89
+				'edit_category'       => __('Update Category', 'event_espresso'),
90
+				'google_map_settings' => __('Update Settings', 'event_espresso'),
91
+			),
92
+		);
93
+	}
94
+
95
+
96
+	protected function _set_page_routes()
97
+	{
98
+
99
+		// load formatter helper
100
+		// load field generator helper
101
+
102
+		// is there a vnu_id in the request?
103
+		$vnu_id = ! empty($this->_req_data['VNU_ID']) && ! is_array($this->_req_data['VNU_ID'])
104
+			? $this->_req_data['VNU_ID'] : 0;
105
+		$vnu_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $vnu_id;
106
+
107
+		$this->_page_routes = array(
108
+			'default'                    => array(
109
+				'func'       => '_overview_list_table',
110
+				'capability' => 'ee_read_venues',
111
+			),
112
+			'create_new'                 => array(
113
+				'func'       => '_create_new_cpt_item',
114
+				'capability' => 'ee_edit_venues',
115
+			),
116
+			'edit'                       => array(
117
+				'func'       => '_edit_cpt_item',
118
+				'capability' => 'ee_edit_venue',
119
+				'obj_id'     => $vnu_id,
120
+			),
121
+			'trash_venue'                => array(
122
+				'func'       => '_trash_or_restore_venue',
123
+				'args'       => array('venue_status' => 'trash'),
124
+				'noheader'   => true,
125
+				'capability' => 'ee_delete_venue',
126
+				'obj_id'     => $vnu_id,
127
+			),
128
+			'trash_venues'               => array(
129
+				'func'       => '_trash_or_restore_venues',
130
+				'args'       => array('venue_status' => 'trash'),
131
+				'noheader'   => true,
132
+				'capability' => 'ee_delete_venues',
133
+			),
134
+			'restore_venue'              => array(
135
+				'func'       => '_trash_or_restore_venue',
136
+				'args'       => array('venue_status' => 'draft'),
137
+				'noheader'   => true,
138
+				'capability' => 'ee_delete_venue',
139
+				'obj_id'     => $vnu_id,
140
+			),
141
+			'restore_venues'             => array(
142
+				'func'       => '_trash_or_restore_venues',
143
+				'args'       => array('venue_status' => 'draft'),
144
+				'noheader'   => true,
145
+				'capability' => 'ee_delete_venues',
146
+			),
147
+			'delete_venues'              => array(
148
+				'func'       => '_delete_venues',
149
+				'noheader'   => true,
150
+				'capability' => 'ee_delete_venues',
151
+			),
152
+			'delete_venue'               => array(
153
+				'func'       => '_delete_venue',
154
+				'noheader'   => true,
155
+				'capability' => 'ee_delete_venue',
156
+				'obj_id'     => $vnu_id,
157
+			),
158
+			// settings related
159
+			'google_map_settings'        => array(
160
+				'func'       => '_google_map_settings',
161
+				'capability' => 'manage_options',
162
+			),
163
+			'update_google_map_settings' => array(
164
+				'func'       => '_update_google_map_settings',
165
+				'capability' => 'manage_options',
166
+				'noheader'   => true,
167
+			),
168
+			// venue category tab related
169
+			'add_category'               => array(
170
+				'func'       => '_category_details',
171
+				'args'       => array('add'),
172
+				'capability' => 'ee_edit_venue_category',
173
+			),
174
+			'edit_category'              => array(
175
+				'func'       => '_category_details',
176
+				'args'       => array('edit'),
177
+				'capability' => 'ee_edit_venue_category',
178
+			),
179
+			'delete_categories'          => array(
180
+				'func'       => '_delete_categories',
181
+				'noheader'   => true,
182
+				'capability' => 'ee_delete_venue_category',
183
+			),
184
+
185
+			'delete_category' => array(
186
+				'func'       => '_delete_categories',
187
+				'noheader'   => true,
188
+				'capability' => 'ee_delete_venue_category',
189
+			),
190
+
191
+			'insert_category' => array(
192
+				'func'       => '_insert_or_update_category',
193
+				'args'       => array('new_category' => true),
194
+				'noheader'   => true,
195
+				'capability' => 'ee_edit_venue_category',
196
+			),
197
+
198
+			'update_category'   => array(
199
+				'func'       => '_insert_or_update_category',
200
+				'args'       => array('new_category' => false),
201
+				'noheader'   => true,
202
+				'capability' => 'ee_edit_venue_category',
203
+			),
204
+			'export_categories' => array(
205
+				'func'       => '_categories_export',
206
+				'noheader'   => true,
207
+				'capability' => 'export',
208
+			),
209
+			'import_categories' => array(
210
+				'func'       => '_import_categories',
211
+				'capability' => 'import',
212
+			),
213
+			'category_list'     => array(
214
+				'func'       => '_category_list_table',
215
+				'capability' => 'ee_manage_venue_categories',
216
+			),
217
+		);
218
+	}
219
+
220
+
221
+	protected function _set_page_config()
222
+	{
223
+		$this->_page_config = array(
224
+			'default'             => array(
225
+				'nav'           => array(
226
+					'label' => __('Overview', 'event_espresso'),
227
+					'order' => 10,
228
+				),
229
+				'list_table'    => 'Venues_Admin_List_Table',
230
+				'help_tabs'     => array(
231
+					'venues_overview_help_tab'                           => array(
232
+						'title'    => __('Venues Overview', 'event_espresso'),
233
+						'filename' => 'venues_overview',
234
+					),
235
+					'venues_overview_table_column_headings_help_tab'     => array(
236
+						'title'    => __('Venues Overview Table Column Headings', 'event_espresso'),
237
+						'filename' => 'venues_overview_table_column_headings',
238
+					),
239
+					'venues_overview_views_bulk_actions_search_help_tab' => array(
240
+						'title'    => __('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
241
+						'filename' => 'venues_overview_views_bulk_actions_search',
242
+					),
243
+				),
244
+				'help_tour'     => array('Venues_Overview_Help_Tour'),
245
+				'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
246
+				'require_nonce' => false,
247
+			),
248
+			'create_new'          => array(
249
+				'nav'           => array(
250
+					'label'      => __('Add Venue', 'event_espresso'),
251
+					'order'      => 5,
252
+					'persistent' => false,
253
+				),
254
+				'help_tabs'     => array(
255
+					'venues_editor_help_tab'                                               => array(
256
+						'title'    => __('Venue Editor', 'event_espresso'),
257
+						'filename' => 'venues_editor',
258
+					),
259
+					'venues_editor_title_richtexteditor_help_tab'                          => array(
260
+						'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
261
+						'filename' => 'venues_editor_title_richtexteditor',
262
+					),
263
+					'venues_editor_tags_categories_help_tab'                               => array(
264
+						'title'    => __('Venue Tags & Categories', 'event_espresso'),
265
+						'filename' => 'venues_editor_tags_categories',
266
+					),
267
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
268
+						'title'    => __(
269
+							'Venue Editor Physical Location & Google Map & Virtual Location',
270
+							'event_espresso'
271
+						),
272
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
273
+					),
274
+					'venues_editor_save_new_venue_help_tab'                                => array(
275
+						'title'    => __('Save New Venue', 'event_espresso'),
276
+						'filename' => 'venues_editor_save_new_venue',
277
+					),
278
+					'venues_editor_other_help_tab'                                         => array(
279
+						'title'    => __('Venue Editor Other', 'event_espresso'),
280
+						'filename' => 'venues_editor_other',
281
+					),
282
+				),
283
+				'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
284
+				'metaboxes'     => array('_venue_editor_metaboxes'),
285
+				'require_nonce' => false,
286
+			),
287
+			'edit'                => array(
288
+				'nav'           => array(
289
+					'label'      => __('Edit Venue', 'event_espresso'),
290
+					'order'      => 5,
291
+					'persistent' => false,
292
+					'url'        => isset($this->_req_data['post']) ? add_query_arg(
293
+						array('post' => $this->_req_data['post']),
294
+						$this->_current_page_view_url
295
+					) : $this->_admin_base_url,
296
+				),
297
+				'help_tabs'     => array(
298
+					'venues_editor_help_tab'                                               => array(
299
+						'title'    => __('Venue Editor', 'event_espresso'),
300
+						'filename' => 'venues_editor',
301
+					),
302
+					'venues_editor_title_richtexteditor_help_tab'                          => array(
303
+						'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
304
+						'filename' => 'venues_editor_title_richtexteditor',
305
+					),
306
+					'venues_editor_tags_categories_help_tab'                               => array(
307
+						'title'    => __('Venue Tags & Categories', 'event_espresso'),
308
+						'filename' => 'venues_editor_tags_categories',
309
+					),
310
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
311
+						'title'    => __(
312
+							'Venue Editor Physical Location & Google Map & Virtual Location',
313
+							'event_espresso'
314
+						),
315
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
316
+					),
317
+					'venues_editor_save_new_venue_help_tab'                                => array(
318
+						'title'    => __('Save New Venue', 'event_espresso'),
319
+						'filename' => 'venues_editor_save_new_venue',
320
+					),
321
+					'venues_editor_other_help_tab'                                         => array(
322
+						'title'    => __('Venue Editor Other', 'event_espresso'),
323
+						'filename' => 'venues_editor_other',
324
+					),
325
+				),
326
+				/*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
327
+				'metaboxes'     => array('_venue_editor_metaboxes'),
328
+				'require_nonce' => false,
329
+			),
330
+			'google_map_settings' => array(
331
+				'nav'           => array(
332
+					'label' => esc_html__('Google Maps', 'event_espresso'),
333
+					'order' => 40,
334
+				),
335
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
336
+				'help_tabs'     => array(
337
+					'general_settings_google_maps_help_tab' => array(
338
+						'title'    => __('Google Maps', 'event_espresso'),
339
+						'filename' => 'general_settings_google_maps',
340
+					),
341
+				),
342
+				'help_tour'     => array('Google_Maps_Help_Tour'),
343
+				'require_nonce' => false,
344
+			),
345
+			// venue category stuff
346
+			'add_category'        => array(
347
+				'nav'           => array(
348
+					'label'      => __('Add Category', 'event_espresso'),
349
+					'order'      => 15,
350
+					'persistent' => false,
351
+				),
352
+				'metaboxes'     => array('_publish_post_box'),
353
+				'help_tabs'     => array(
354
+					'venues_add_category_help_tab' => array(
355
+						'title'    => __('Add New Venue Category', 'event_espresso'),
356
+						'filename' => 'venues_add_category',
357
+					),
358
+				),
359
+				'help_tour'     => array('Venues_Add_Category_Help_Tour'),
360
+				'require_nonce' => false,
361
+			),
362
+			'edit_category'       => array(
363
+				'nav'           => array(
364
+					'label'      => __('Edit Category', 'event_espresso'),
365
+					'order'      => 15,
366
+					'persistent' => false,
367
+					'url'        => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(
368
+						array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
369
+						$this->_current_page_view_url
370
+					) : $this->_admin_base_url,
371
+				),
372
+				'metaboxes'     => array('_publish_post_box'),
373
+				'help_tabs'     => array(
374
+					'venues_edit_category_help_tab' => array(
375
+						'title'    => __('Edit Venue Category', 'event_espresso'),
376
+						'filename' => 'venues_edit_category',
377
+					),
378
+				),
379
+				/*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
380
+				'require_nonce' => false,
381
+			),
382
+			'category_list'       => array(
383
+				'nav'           => array(
384
+					'label' => __('Categories', 'event_espresso'),
385
+					'order' => 20,
386
+				),
387
+				'list_table'    => 'Venue_Categories_Admin_List_Table',
388
+				'help_tabs'     => array(
389
+					'venues_categories_help_tab'                       => array(
390
+						'title'    => __('Venue Categories', 'event_espresso'),
391
+						'filename' => 'venues_categories',
392
+					),
393
+					'venues_categories_table_column_headings_help_tab' => array(
394
+						'title'    => __('Venue Categories Table Column Headings', 'event_espresso'),
395
+						'filename' => 'venues_categories_table_column_headings',
396
+					),
397
+					'venues_categories_views_help_tab'                 => array(
398
+						'title'    => __('Venue Categories Views', 'event_espresso'),
399
+						'filename' => 'venues_categories_views',
400
+					),
401
+					'venues_categories_other_help_tab'                 => array(
402
+						'title'    => __('Venue Categories Other', 'event_espresso'),
403
+						'filename' => 'venues_categories_other',
404
+					),
405
+				),
406
+				'help_tour'     => array('Venues_Categories_Help_Tour'),
407
+				'metaboxes'     => $this->_default_espresso_metaboxes,
408
+				'require_nonce' => false,
409
+			),
410
+		);
411
+	}
412
+
413
+
414
+	protected function _add_screen_options()
415
+	{
416
+		// todo
417
+	}
418
+
419
+
420
+	protected function _add_screen_options_default()
421
+	{
422
+		$this->_per_page_screen_option();
423
+	}
424
+
425
+
426
+	protected function _add_screen_options_category_list()
427
+	{
428
+		$page_title = $this->_admin_page_title;
429
+		$this->_admin_page_title = __('Venue Categories', 'event_espresso');
430
+		$this->_per_page_screen_option();
431
+		$this->_admin_page_title = $page_title;
432
+	}
433
+
434
+
435
+	// none of the below group are currently used for Event Venues
436
+	protected function _add_feature_pointers()
437
+	{
438
+	}
439
+
440
+	public function admin_init()
441
+	{
442
+	}
443
+
444
+	public function admin_notices()
445
+	{
446
+	}
447
+
448
+	public function admin_footer_scripts()
449
+	{
450
+	}
451
+
452
+
453
+	public function load_scripts_styles_create_new()
454
+	{
455
+		$this->load_scripts_styles_edit();
456
+	}
457
+
458
+
459
+	public function load_scripts_styles()
460
+	{
461
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
462
+		wp_enqueue_style('ee-cat-admin');
463
+	}
464
+
465
+
466
+	public function load_scripts_styles_add_category()
467
+	{
468
+		$this->load_scripts_styles_edit_category();
469
+	}
470
+
471
+
472
+	public function load_scripts_styles_edit_category()
473
+	{
474
+	}
475
+
476
+
477
+	public function load_scripts_styles_edit()
478
+	{
479
+		// styles
480
+		wp_enqueue_style('espresso-ui-theme');
481
+		wp_register_style(
482
+			'espresso_venues',
483
+			EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
484
+			array(),
485
+			EVENT_ESPRESSO_VERSION
486
+		);
487
+		wp_enqueue_style('espresso_venues');
488
+	}
489
+
490
+
491
+	protected function _set_list_table_views_default()
492
+	{
493
+		$this->_views = array(
494
+			'all' => array(
495
+				'slug'        => 'all',
496
+				'label'       => __('View All Venues', 'event_espresso'),
497
+				'count'       => 0,
498
+				'bulk_action' => array(),
499
+			),
500
+		);
501
+
502
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
503
+			$this->_views['all']['bulk_action'] = array(
504
+				'trash_venues' => __('Move to Trash', 'event_espresso'),
505
+			);
506
+			$this->_views['trash'] = array(
507
+				'slug'        => 'trash',
508
+				'label'       => __('Trash', 'event_espresso'),
509
+				'count'       => 0,
510
+				'bulk_action' => array(
511
+					'restore_venues' => __('Restore from Trash', 'event_espresso'),
512
+					'delete_venues'  => __('Delete', 'event_espresso'),
513
+				),
514
+			);
515
+		}
516
+	}
517
+
518
+
519
+	protected function _set_list_table_views_category_list()
520
+	{
521
+		$this->_views = array(
522
+			'all' => array(
523
+				'slug'        => 'all',
524
+				'label'       => __('All', 'event_espresso'),
525
+				'count'       => 0,
526
+				'bulk_action' => array(
527
+					'delete_categories' => __('Delete Permanently', 'event_espresso'),
528
+				),
529
+			),
530
+		);
531
+	}
532
+
533
+
534
+	protected function _overview_list_table()
535
+	{
536
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
537
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
538
+			get_post_type_archive_link('espresso_venues'),
539
+			__("View Venue Archive Page", "event_espresso"),
540
+			'button'
541
+		);
542
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
543
+		$this->_search_btn_label = __('Venues', 'event_espresso');
544
+		$this->display_admin_list_table_page_with_sidebar();
545
+	}
546
+
547
+
548
+	public function extra_misc_actions_publish_box()
549
+	{
550
+		$extra_rows = array(
551
+			'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
552
+			'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
553
+			'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
554
+		);
555
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
556
+		EEH_Template::display_template($template, $extra_rows);
557
+	}
558
+
559
+
560
+	/*************        Google Maps        *************/
561
+
562
+
563
+	protected function _google_map_settings()
564
+	{
565
+
566
+
567
+		$this->_template_args['values'] = $this->_yes_no_values;
568
+		$default_map_settings = new stdClass();
569
+		$default_map_settings->use_google_maps = true;
570
+		$default_map_settings->google_map_api_key = '';
571
+		// for event details pages (reg page)
572
+		$default_map_settings->event_details_map_width = 585;            // ee_map_width_single
573
+		$default_map_settings->event_details_map_height = 362;            // ee_map_height_single
574
+		$default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
575
+		$default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
576
+		$default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
577
+		$default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
578
+		$default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
579
+		// for event list pages
580
+		$default_map_settings->event_list_map_width = 300;            // ee_map_width
581
+		$default_map_settings->event_list_map_height = 185;        // ee_map_height
582
+		$default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
583
+		$default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
584
+		$default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
585
+		$default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
586
+		$default_map_settings->event_list_map_align = 'center';            // ee_map_align
587
+
588
+		$this->_template_args['map_settings'] =
589
+			isset(EE_Registry::instance()->CFG->map_settings)
590
+			&& ! empty(EE_Registry::instance()->CFG->map_settings)
591
+				? (object) array_merge(
592
+					(array) $default_map_settings,
593
+					(array) EE_Registry::instance()->CFG->map_settings
594
+				)
595
+				: $default_map_settings;
596
+
597
+		$this->_set_add_edit_form_tags('update_google_map_settings');
598
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
599
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
600
+			EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
601
+			$this->_template_args,
602
+			true
603
+		);
604
+		$this->display_admin_page_with_sidebar();
605
+	}
606
+
607
+	protected function _update_google_map_settings()
608
+	{
609
+
610
+		EE_Registry::instance()->CFG->map_settings->use_google_maps =
611
+			isset($this->_req_data['use_google_maps'])
612
+				? absint($this->_req_data['use_google_maps'])
613
+				: EE_Registry::instance()->CFG->map_settings->use_google_maps;
614
+
615
+		EE_Registry::instance()->CFG->map_settings->google_map_api_key =
616
+			isset($this->_req_data['google_map_api_key'])
617
+				? sanitize_text_field($this->_req_data['google_map_api_key'])
618
+				: EE_Registry::instance()->CFG->map_settings->google_map_api_key;
619
+
620
+		EE_Registry::instance()->CFG->map_settings->event_details_map_width =
621
+			isset($this->_req_data['event_details_map_width'])
622
+				? absint($this->_req_data['event_details_map_width'])
623
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_width;
624
+
625
+		EE_Registry::instance()->CFG->map_settings->event_details_map_height =
626
+			isset($this->_req_data['event_details_map_height'])
627
+				? absint($this->_req_data['event_details_map_height'])
628
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_height;
629
+
630
+		EE_Registry::instance()->CFG->map_settings->event_details_map_zoom =
631
+			isset($this->_req_data['event_details_map_zoom'])
632
+				? absint($this->_req_data['event_details_map_zoom'])
633
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_zoom;
634
+
635
+		EE_Registry::instance()->CFG->map_settings->event_details_display_nav =
636
+			isset($this->_req_data['event_details_display_nav'])
637
+				? absint($this->_req_data['event_details_display_nav'])
638
+				: EE_Registry::instance()->CFG->map_settings->event_details_display_nav;
639
+
640
+		EE_Registry::instance()->CFG->map_settings->event_details_nav_size =
641
+			isset($this->_req_data['event_details_nav_size'])
642
+				? absint($this->_req_data['event_details_nav_size'])
643
+				: EE_Registry::instance()->CFG->map_settings->event_details_nav_size;
644
+
645
+		EE_Registry::instance()->CFG->map_settings->event_details_control_type =
646
+			isset($this->_req_data['event_details_control_type'])
647
+				? sanitize_text_field($this->_req_data['event_details_control_type'])
648
+				: EE_Registry::instance()->CFG->map_settings->event_details_control_type;
649
+
650
+		EE_Registry::instance()->CFG->map_settings->event_details_map_align =
651
+			isset($this->_req_data['event_details_map_align'])
652
+				? sanitize_text_field($this->_req_data['event_details_map_align'])
653
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_align;
654
+
655
+		EE_Registry::instance()->CFG->map_settings->event_list_map_width =
656
+			isset($this->_req_data['event_list_map_width'])
657
+				? absint($this->_req_data['event_list_map_width'])
658
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_width;
659
+
660
+		EE_Registry::instance()->CFG->map_settings->event_list_map_height =
661
+			isset($this->_req_data['event_list_map_height'])
662
+				? absint($this->_req_data['event_list_map_height'])
663
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_height;
664
+
665
+		EE_Registry::instance()->CFG->map_settings->event_list_map_zoom =
666
+			isset($this->_req_data['event_list_map_zoom'])
667
+				? absint($this->_req_data['event_list_map_zoom'])
668
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_zoom;
669
+
670
+		EE_Registry::instance()->CFG->map_settings->event_list_display_nav =
671
+			isset($this->_req_data['event_list_display_nav'])
672
+				? absint($this->_req_data['event_list_display_nav'])
673
+				: EE_Registry::instance()->CFG->map_settings->event_list_display_nav;
674
+
675
+		EE_Registry::instance()->CFG->map_settings->event_list_nav_size =
676
+			isset($this->_req_data['event_list_nav_size'])
677
+				? absint($this->_req_data['event_list_nav_size'])
678
+				: EE_Registry::instance()->CFG->map_settings->event_list_nav_size;
679
+
680
+		EE_Registry::instance()->CFG->map_settings->event_list_control_type =
681
+			isset($this->_req_data['event_list_control_type'])
682
+				? sanitize_text_field($this->_req_data['event_list_control_type'])
683
+				: EE_Registry::instance()->CFG->map_settings->event_list_control_type;
684
+
685
+		EE_Registry::instance()->CFG->map_settings->event_list_map_align =
686
+			isset($this->_req_data['event_list_map_align'])
687
+				? sanitize_text_field($this->_req_data['event_list_map_align'])
688
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_align;
689
+
690
+		EE_Registry::instance()->CFG->map_settings = apply_filters(
691
+			'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
692
+			EE_Registry::instance()->CFG->map_settings
693
+		);
694
+
695
+		$what = 'Google Map Settings';
696
+		$success = $this->_update_espresso_configuration(
697
+			$what,
698
+			EE_Registry::instance()->CFG->map_settings,
699
+			__FILE__,
700
+			__FUNCTION__,
701
+			__LINE__
702
+		);
703
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings'));
704
+	}
705
+
706
+
707
+	protected function _venue_editor_metaboxes()
708
+	{
709
+		$this->verify_cpt_object();
710
+
711
+		add_meta_box(
712
+			'espresso_venue_address_options',
713
+			__('Physical Location', 'event_espresso'),
714
+			array($this, 'venue_address_metabox'),
715
+			$this->page_slug,
716
+			'side',
717
+			'default'
718
+		);
719
+		add_meta_box(
720
+			'espresso_venue_gmap_options',
721
+			__('Google Map', 'event_espresso'),
722
+			array($this, 'venue_gmap_metabox'),
723
+			$this->page_slug,
724
+			'side',
725
+			'default'
726
+		);
727
+		add_meta_box(
728
+			'espresso_venue_virtual_loc_options',
729
+			__('Virtual Location', 'event_espresso'),
730
+			array($this, 'venue_virtual_loc_metabox'),
731
+			$this->page_slug,
732
+			'side',
733
+			'default'
734
+		);
735
+	}
736
+
737
+
738
+	public function venue_gmap_metabox()
739
+	{
740
+		$template_args = array(
741
+			'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
742
+				'vnu_enable_for_gmap',
743
+				$this->get_yes_no_values(),
744
+				$this->_cpt_model_obj->enable_for_gmap()
745
+			),
746
+			'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
747
+		);
748
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
749
+		EEH_Template::display_template($template, $template_args);
750
+	}
751
+
752
+
753
+	public function venue_address_metabox()
754
+	{
755
+
756
+		$template_args['_venue'] = $this->_cpt_model_obj;
757
+
758
+		$template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input(
759
+			$QFI = new EE_Question_Form_Input(
760
+				EE_Question::new_instance(
761
+					array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')
762
+				),
763
+				EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->state_ID())),
764
+				array(
765
+					'input_name'     => 'sta_id',
766
+					'input_id'       => 'sta_id',
767
+					'input_class'    => '',
768
+					'input_prefix'   => '',
769
+					'append_qstn_id' => false,
770
+				)
771
+			)
772
+		);
773
+		$template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
774
+			$QFI = new EE_Question_Form_Input(
775
+				EE_Question::new_instance(
776
+					array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')
777
+				),
778
+				EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->country_ID())),
779
+				array(
780
+					'input_name'     => 'cnt_iso',
781
+					'input_id'       => 'cnt_iso',
782
+					'input_class'    => '',
783
+					'input_prefix'   => '',
784
+					'append_qstn_id' => false,
785
+				)
786
+			)
787
+		);
788
+
789
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
790
+		EEH_Template::display_template($template, $template_args);
791
+	}
792
+
793
+
794
+	public function venue_virtual_loc_metabox()
795
+	{
796
+		$template_args = array(
797
+			'_venue' => $this->_cpt_model_obj,
798
+		);
799
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
800
+		EEH_Template::display_template($template, $template_args);
801
+	}
802
+
803
+
804
+	protected function _restore_cpt_item($post_id, $revision_id)
805
+	{
806
+		$venue_obj = $this->_venue_model->get_one_by_ID($post_id);
807
+
808
+		// meta revision restore
809
+		$venue_obj->restore_revision($revision_id);
810
+	}
811
+
812
+
813
+	/**
814
+	 * Handles updates for venue cpts
815
+	 *
816
+	 * @param  int    $post_id ID of Venue CPT
817
+	 * @param  object $post    Post object (with "blessed" WP properties)
818
+	 * @return void
819
+	 */
820
+	protected function _insert_update_cpt_item($post_id, $post)
821
+	{
822
+
823
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
824
+			return;// get out we're not processing the saving of venues.
825
+		}
826
+
827
+		$wheres = array($this->_venue_model->primary_key_name() => $post_id);
828
+
829
+		$venue_values = array(
830
+			'VNU_address'         => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : null,
831
+			'VNU_address2'        => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2']
832
+				: null,
833
+			'VNU_city'            => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : null,
834
+			'STA_ID'              => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : null,
835
+			'CNT_ISO'             => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : null,
836
+			'VNU_zip'             => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : null,
837
+			'VNU_phone'           => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : null,
838
+			'VNU_capacity'        => ! empty($this->_req_data['vnu_capacity']) ? str_replace(
839
+				',',
840
+				'',
841
+				$this->_req_data['vnu_capacity']
842
+			) : EE_INF,
843
+			'VNU_url'             => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : null,
844
+			'VNU_virtual_phone'   => ! empty($this->_req_data['vnu_virtual_phone'])
845
+				? $this->_req_data['vnu_virtual_phone'] : null,
846
+			'VNU_virtual_url'     => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url']
847
+				: null,
848
+			'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? true : false,
849
+			'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link'])
850
+				? $this->_req_data['vnu_google_map_link'] : null,
851
+		);
852
+
853
+		// update venue
854
+		$success = $this->_venue_model->update($venue_values, array($wheres));
855
+
856
+		// get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_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!
857
+		$get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status);
858
+		$venue = $this->_venue_model->get_one(array($get_one_where));
859
+
860
+		// notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
861
+		$venue_update_callbacks = apply_filters(
862
+			'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
863
+			array()
864
+		);
865
+
866
+		$att_success = true;
867
+
868
+		foreach ($venue_update_callbacks as $v_callback) {
869
+			$_succ = call_user_func_array($v_callback, array($venue, $this->_req_data));
870
+			$att_success = ! $att_success ? $att_success
871
+				: $_succ; // if ANY of these updates fail then we want the appropriate global error message
872
+		}
873
+
874
+		// any errors?
875
+		if ($success && ! $att_success) {
876
+			EE_Error::add_error(
877
+				__(
878
+					'Venue Details saved successfully but something went wrong with saving attachments.',
879
+					'event_espresso'
880
+				),
881
+				__FILE__,
882
+				__FUNCTION__,
883
+				__LINE__
884
+			);
885
+		} elseif ($success === false) {
886
+			EE_Error::add_error(
887
+				__('Venue Details did not save successfully.', 'event_espresso'),
888
+				__FILE__,
889
+				__FUNCTION__,
890
+				__LINE__
891
+			);
892
+		}
893
+	}
894
+
895
+
896
+	public function trash_cpt_item($post_id)
897
+	{
898
+		$this->_req_data['VNU_ID'] = $post_id;
899
+		$this->_trash_or_restore_venue('trash', false);
900
+	}
901
+
902
+
903
+	public function restore_cpt_item($post_id)
904
+	{
905
+		$this->_req_data['VNU_ID'] = $post_id;
906
+		$this->_trash_or_restore_venue('draft', false);
907
+	}
908
+
909
+
910
+	public function delete_cpt_item($post_id)
911
+	{
912
+		$this->_req_data['VNU_ID'] = $post_id;
913
+		$this->_delete_venue(false);
914
+	}
915
+
916
+
917
+	public function get_venue_object()
918
+	{
919
+		return $this->_cpt_model_obj;
920
+	}
921
+
922
+
923
+	protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
924
+	{
925
+		$VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : false;
926
+
927
+		// loop thru venues
928
+		if ($VNU_ID) {
929
+			// clean status
930
+			$venue_status = sanitize_key($venue_status);
931
+			// grab status
932
+			if (! empty($venue_status)) {
933
+				$success = $this->_change_venue_status($VNU_ID, $venue_status);
934
+			} else {
935
+				$success = false;
936
+				$msg = __(
937
+					'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
938
+					'event_espresso'
939
+				);
940
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
941
+			}
942
+		} else {
943
+			$success = false;
944
+			$msg = __(
945
+				'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
946
+				'event_espresso'
947
+			);
948
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
949
+		}
950
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
951
+
952
+		if ($redirect_after) {
953
+			$this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default'));
954
+		}
955
+	}
956
+
957
+
958
+	protected function _trash_or_restore_venues($venue_status = 'trash')
959
+	{
960
+		// clean status
961
+		$venue_status = sanitize_key($venue_status);
962
+		// grab status
963
+		if (! empty($venue_status)) {
964
+			$success = true;
965
+			// determine the event id and set to array.
966
+			$VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
967
+			// loop thru events
968
+			foreach ($VNU_IDs as $VNU_ID) {
969
+				if ($VNU_ID = absint($VNU_ID)) {
970
+					$results = $this->_change_venue_status($VNU_ID, $venue_status);
971
+					$success = $results !== false ? $success : false;
972
+				} else {
973
+					$msg = sprintf(
974
+						__(
975
+							'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
976
+							'event_espresso'
977
+						),
978
+						$VNU_ID
979
+					);
980
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
981
+					$success = false;
982
+				}
983
+			}
984
+		} else {
985
+			$success = false;
986
+			$msg = __(
987
+				'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
988
+				'event_espresso'
989
+			);
990
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
991
+		}
992
+		// in order to force a pluralized result message we need to send back a success status greater than 1
993
+		$success = $success ? 2 : false;
994
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
995
+		$this->_redirect_after_action($success, 'Venues', $action, array('action' => 'default'));
996
+	}
997
+
998
+
999
+	/**
1000
+	 * _trash_or_restore_venues
1001
+	 *
1002
+	 * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1003
+	 * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1004
+	 * accepting a certain number of params.
1005
+	 *
1006
+	 * @access  private
1007
+	 * @param  int    $VNU_ID
1008
+	 * @param  string $venue_status
1009
+	 * @return void
1010
+	 */
1011
+	private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012
+	{
1013
+		// grab venue id
1014
+		if (! $VNU_ID) {
1015
+			$msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1016
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1017
+			return false;
1018
+		}
1019
+
1020
+		$this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1021
+
1022
+		// clean status
1023
+		$venue_status = sanitize_key($venue_status);
1024
+		// grab status
1025
+		if (! $venue_status) {
1026
+			$msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1027
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028
+			return false;
1029
+		}
1030
+
1031
+		// was event trashed or restored ?
1032
+		switch ($venue_status) {
1033
+			case 'draft':
1034
+				$action = 'restored from the trash';
1035
+				$hook = 'AHEE_venue_restored_from_trash';
1036
+				break;
1037
+			case 'trash':
1038
+				$action = 'moved to the trash';
1039
+				$hook = 'AHEE_venue_moved_to_trash';
1040
+				break;
1041
+			default:
1042
+				$action = 'updated';
1043
+				$hook = false;
1044
+		}
1045
+		// use class to change status
1046
+		$this->_cpt_model_obj->set_status($venue_status);
1047
+		$success = $this->_cpt_model_obj->save();
1048
+
1049
+		if ($success === false) {
1050
+			$msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1051
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1052
+			return false;
1053
+		}
1054
+		if ($hook) {
1055
+			do_action($hook);
1056
+		}
1057
+		return true;
1058
+	}
1059
+
1060
+
1061
+	/**
1062
+	 * @param  bool $redirect_after
1063
+	 * @return void
1064
+	 */
1065
+	protected function _delete_venue($redirect_after = true)
1066
+	{
1067
+		// determine the venue id and set to array.
1068
+		$VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : null;
1069
+		$VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID;
1070
+
1071
+
1072
+		// loop thru venues
1073
+		if ($VNU_ID) {
1074
+			$success = $this->_delete_or_trash_venue($VNU_ID);
1075
+		} else {
1076
+			$success = false;
1077
+			$msg = __(
1078
+				'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1079
+				'event_espresso'
1080
+			);
1081
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1082
+		}
1083
+		if ($redirect_after) {
1084
+			$this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default'));
1085
+		}
1086
+	}
1087
+
1088
+
1089
+	protected function _delete_venues()
1090
+	{
1091
+		$success = true;
1092
+		// determine the event id and set to array.
1093
+		$VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
1094
+		// loop thru events
1095
+		foreach ($VNU_IDs as $VNU_ID) {
1096
+			if ($VNU_ID = absint($VNU_ID)) {
1097
+				$results = $this->_delete_or_trash_venue($VNU_ID);
1098
+				$success = $results !== false ? $success : false;
1099
+			} else {
1100
+				$success = false;
1101
+				$msg = __(
1102
+					'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1103
+					'event_espresso'
1104
+				);
1105
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1106
+			}
1107
+		}
1108
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1109
+		$success = $success ? 2 : false;
1110
+		$this->_redirect_after_action(
1111
+			$success,
1112
+			__('Venues', 'event_espresso'),
1113
+			__('deleted', 'event_espresso'),
1114
+			array('action' => 'default')
1115
+		);
1116
+	}
1117
+
1118
+
1119
+	// todo: put in parent
1120
+	private function _delete_or_trash_venue($VNU_ID = false)
1121
+	{
1122
+		// grab event id
1123
+		if (! $VNU_ID = absint($VNU_ID)) {
1124
+			$msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1125
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1126
+			return false;
1127
+		}
1128
+
1129
+
1130
+		$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1131
+		// first need to remove all term relationships
1132
+		$venue->_remove_relations('Term_Taxonomy');
1133
+		$success = $venue->delete_permanently();
1134
+		// did it all go as planned ?
1135
+		if ($success) {
1136
+			$msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1137
+			EE_Error::add_success($msg);
1138
+		} else {
1139
+			$msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID);
1140
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1141
+			return false;
1142
+		}
1143
+		do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1144
+		return true;
1145
+	}
1146
+
1147
+
1148
+
1149
+
1150
+	/***********/
1151
+	/* QUERIES */
1152
+
1153
+
1154
+	public function get_venues($per_page = 10, $count = false)
1155
+	{
1156
+
1157
+		$_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1158
+
1159
+		switch ($_orderby) {
1160
+			case 'id':
1161
+				$orderby = 'VNU_ID';
1162
+				break;
1163
+
1164
+			case 'capacity':
1165
+				$orderby = 'VNU_capacity';
1166
+				break;
1167
+
1168
+			case 'city':
1169
+				$orderby = 'VNU_city';
1170
+				break;
1171
+
1172
+			default:
1173
+				$orderby = 'VNU_name';
1174
+		}
1175
+
1176
+
1177
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1178
+			: 'ASC';
1179
+
1180
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1181
+			? $this->_req_data['paged'] : 1;
1182
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
1183
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1184
+			? $this->_req_data['perpage'] : $per_page;
1185
+
1186
+
1187
+		$offset = ($current_page - 1) * $per_page;
1188
+		$limit = array($offset, $per_page);
1189
+
1190
+		$category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0
1191
+			? $this->_req_data['category'] : null;
1192
+		$where = array();
1193
+
1194
+		// only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1195
+		if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') {
1196
+			$where['status'] = $this->_req_data['status'];
1197
+		}
1198
+
1199
+		if (isset($this->_req_data['venue_status'])) {
1200
+			$where['status'] = $this->_req_data['venue_status'];
1201
+		}
1202
+
1203
+
1204
+		if ($category) {
1205
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1206
+			$where['Term_Taxonomy.term_id'] = $category;
1207
+		}
1208
+
1209
+
1210
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1211
+			$where['VNU_wp_user'] = get_current_user_id();
1212
+		} else {
1213
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1214
+				$where['OR'] = array(
1215
+					'status*restrict_private' => array('!=', 'private'),
1216
+					'AND'                     => array(
1217
+						'status*inclusive' => array('=', 'private'),
1218
+						'VNU_wp_user'      => get_current_user_id(),
1219
+					),
1220
+				);
1221
+			}
1222
+		}
1223
+
1224
+
1225
+		if (isset($this->_req_data['s'])) {
1226
+			$sstr = '%' . $this->_req_data['s'] . '%';
1227
+			$where['OR'] = array(
1228
+				'VNU_name'               => array('LIKE', $sstr),
1229
+				'VNU_desc'               => array('LIKE', $sstr),
1230
+				'VNU_short_desc'         => array('LIKE', $sstr),
1231
+				'VNU_address'            => array('LIKE', $sstr),
1232
+				'VNU_address2'           => array('LIKE', $sstr),
1233
+				'VNU_city'               => array('LIKE', $sstr),
1234
+				'VNU_zip'                => array('LIKE', $sstr),
1235
+				'VNU_phone'              => array('LIKE', $sstr),
1236
+				'VNU_url'                => array('LIKE', $sstr),
1237
+				'VNU_virtual_phone'      => array('LIKE', $sstr),
1238
+				'VNU_virtual_url'        => array('LIKE', $sstr),
1239
+				'VNU_google_map_link'    => array('LIKE', $sstr),
1240
+				'Event.EVT_name'         => array('LIKE', $sstr),
1241
+				'Event.EVT_desc'         => array('LIKE', $sstr),
1242
+				'Event.EVT_phone'        => array('LIKE', $sstr),
1243
+				'Event.EVT_external_URL' => array('LIKE', $sstr),
1244
+			);
1245
+		}
1246 1246
 
1247 1247
 
1248
-        $venues = $count
1249
-            ? $this->_venue_model->count(array($where), 'VNU_ID')
1250
-            : $this->_venue_model->get_all(
1251
-                array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)
1252
-            );
1253
-
1254
-        return $venues;
1255
-    }
1256
-
1257
-
1258
-
1259
-
1260
-    /** Venue Category Stuff **/
1261
-
1262
-    /**
1263
-     * set the _category property with the category object for the loaded page.
1264
-     *
1265
-     * @access private
1266
-     * @return void
1267
-     */
1268
-    private function _set_category_object()
1269
-    {
1270
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
1271
-            return;
1272
-        } // already have the category object so get out.
1273
-
1274
-        // set default category object
1275
-        $this->_set_empty_category_object();
1276
-
1277
-        // only set if we've got an id
1278
-        if (! isset($this->_req_data['VEN_CAT_ID'])) {
1279
-            return;
1280
-        }
1281
-
1282
-        $category_id = absint($this->_req_data['VEN_CAT_ID']);
1283
-        $term = get_term($category_id, 'espresso_venue_categories');
1284
-
1285
-
1286
-        if (! empty($term)) {
1287
-            $this->_category->category_name = $term->name;
1288
-            $this->_category->category_identifier = $term->slug;
1289
-            $this->_category->category_desc = $term->description;
1290
-            $this->_category->id = $term->term_id;
1291
-            $this->_category->parent = $term->parent;
1292
-        }
1293
-    }
1294
-
1295
-
1296
-    private function _set_empty_category_object()
1297
-    {
1298
-        $this->_category = new stdClass();
1299
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1300
-        $this->_category->id = $this->_category->parent = 0;
1301
-    }
1302
-
1303
-
1304
-    protected function _category_list_table()
1305
-    {
1306
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1307
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1308
-            'add_category',
1309
-            'add_category',
1310
-            array(),
1311
-            'add-new-h2'
1312
-        );
1313
-        $this->_search_btn_label = __('Venue Categories', 'event_espresso');
1314
-        $this->display_admin_list_table_page_with_sidebar();
1315
-    }
1316
-
1317
-
1318
-    protected function _category_details($view)
1319
-    {
1320
-
1321
-        // load formatter helper
1322
-        // load field generator helper
1323
-
1324
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
1325
-        $this->_set_add_edit_form_tags($route);
1326
-
1327
-        $this->_set_category_object();
1328
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
1329
-
1330
-        $delete_action = 'delete_category';
1331
-
1332
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url);
1333
-
1334
-        $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1335
-
1336
-        // take care of contents
1337
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
1338
-        $this->display_admin_page_with_sidebar();
1339
-    }
1340
-
1341
-
1342
-    protected function _category_details_content()
1343
-    {
1344
-        $editor_args['category_desc'] = array(
1345
-            'type'          => 'wp_editor',
1346
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1347
-            'class'         => 'my_editor_custom',
1348
-            'wpeditor_args' => array('media_buttons' => false),
1349
-        );
1350
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
1351
-
1352
-        $all_terms = get_terms(
1353
-            array('espresso_venue_categories'),
1354
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
1355
-        );
1356
-
1357
-        // setup category select for term parents.
1358
-        $category_select_values[] = array(
1359
-            'text' => __('No Parent', 'event_espresso'),
1360
-            'id'   => 0,
1361
-        );
1362
-        foreach ($all_terms as $term) {
1363
-            $category_select_values[] = array(
1364
-                'text' => $term->name,
1365
-                'id'   => $term->term_id,
1366
-            );
1367
-        }
1368
-
1369
-        $category_select = EEH_Form_Fields::select_input(
1370
-            'category_parent',
1371
-            $category_select_values,
1372
-            $this->_category->parent
1373
-        );
1374
-        $template_args = array(
1375
-            'category'                 => $this->_category,
1376
-            'category_select'          => $category_select,
1377
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1378
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1379
-            'disable'                  => '',
1380
-            'disabled_message'         => false,
1381
-        );
1382
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1383
-        return EEH_Template::display_template($template, $template_args, true);
1384
-    }
1385
-
1386
-
1387
-    protected function _delete_categories()
1388
-    {
1389
-        $cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID']
1390
-            : (array) $this->_req_data['category_id'];
1391
-
1392
-        foreach ($cat_ids as $cat_id) {
1393
-            $this->_delete_category($cat_id);
1394
-        }
1395
-
1396
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
1397
-        $query_args = array(
1398
-            'action' => 'category_list',
1399
-        );
1400
-        $this->_redirect_after_action(0, '', '', $query_args);
1401
-    }
1402
-
1403
-
1404
-    protected function _delete_category($cat_id)
1405
-    {
1406
-        $cat_id = absint($cat_id);
1407
-        wp_delete_term($cat_id, 'espresso_venue_categories');
1408
-    }
1409
-
1410
-
1411
-    protected function _insert_or_update_category($new_category)
1412
-    {
1413
-
1414
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1415
-        $success = 0; // we already have a success message so lets not send another.
1416
-        if ($cat_id) {
1417
-            $query_args = array(
1418
-                'action'     => 'edit_category',
1419
-                'VEN_CAT_ID' => $cat_id,
1420
-            );
1421
-        } else {
1422
-            $query_args = array('action' => 'add_category');
1423
-        }
1424
-        $this->_redirect_after_action($success, '', '', $query_args, true);
1425
-    }
1426
-
1427
-
1428
-    private function _insert_category($update = false)
1429
-    {
1430
-        $cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : '';
1431
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
1432
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
1433
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
1434
-
1435
-        if (empty($category_name)) {
1436
-            $msg = __('You must add a name for the category.', 'event_espresso');
1437
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1438
-            return false;
1439
-        }
1440
-
1441
-
1442
-        $term_args = array(
1443
-            'name'        => $category_name,
1444
-            'description' => $category_desc,
1445
-            'parent'      => $category_parent,
1446
-        );
1447
-
1448
-        $insert_ids = $update
1449
-            ? wp_update_term($cat_id, 'espresso_venue_categories', $term_args)
1450
-            : wp_insert_term(
1451
-                $category_name,
1452
-                'espresso_venue_categories',
1453
-                $term_args
1454
-            );
1455
-
1456
-        if (! is_array($insert_ids)) {
1457
-            $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1458
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1459
-        } else {
1460
-            $cat_id = $insert_ids['term_id'];
1461
-            $msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name);
1462
-            EE_Error::add_success($msg);
1463
-        }
1464
-
1465
-        return $cat_id;
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * TODO handle category exports()
1471
-     *
1472
-     * @return file export
1473
-     */
1474
-    protected function _categories_export()
1475
-    {
1476
-
1477
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
1478
-        $new_request_args = array(
1479
-            'export'       => 'report',
1480
-            'action'       => 'categories',
1481
-            'category_ids' => $this->_req_data['VEN_CAT_ID'],
1482
-        );
1483
-
1484
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
1485
-
1486
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1487
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1488
-            $EE_Export = EE_Export::instance($this->_req_data);
1489
-            $EE_Export->export();
1490
-        }
1491
-    }
1492
-
1493
-
1494
-    protected function _import_categories()
1495
-    {
1496
-
1497
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1498
-        EE_Import::instance()->import();
1499
-    }
1500
-
1501
-
1502
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
1503
-    {
1504
-
1505
-        // testing term stuff
1506
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
1507
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1508
-        $limit = ($current_page - 1) * $per_page;
1509
-        $where = array('taxonomy' => 'espresso_venue_categories');
1510
-        if (isset($this->_req_data['s'])) {
1511
-            $sstr = '%' . $this->_req_data['s'] . '%';
1512
-            $where['OR'] = array(
1513
-                'Term.name'   => array('LIKE', $sstr),
1514
-                'description' => array('LIKE', $sstr),
1515
-            );
1516
-        }
1517
-
1518
-        $query_params = array(
1519
-            $where,
1520
-            'order_by'   => array($orderby => $order),
1521
-            'limit'      => $limit . ',' . $per_page,
1522
-            'force_join' => array('Term'),
1523
-        );
1524
-
1525
-        $categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1526
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
1527
-
1528
-        return $categories;
1529
-    }
1530
-
1531
-
1532
-    /* end category stuff */
1533
-    /**************/
1248
+		$venues = $count
1249
+			? $this->_venue_model->count(array($where), 'VNU_ID')
1250
+			: $this->_venue_model->get_all(
1251
+				array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)
1252
+			);
1253
+
1254
+		return $venues;
1255
+	}
1256
+
1257
+
1258
+
1259
+
1260
+	/** Venue Category Stuff **/
1261
+
1262
+	/**
1263
+	 * set the _category property with the category object for the loaded page.
1264
+	 *
1265
+	 * @access private
1266
+	 * @return void
1267
+	 */
1268
+	private function _set_category_object()
1269
+	{
1270
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
1271
+			return;
1272
+		} // already have the category object so get out.
1273
+
1274
+		// set default category object
1275
+		$this->_set_empty_category_object();
1276
+
1277
+		// only set if we've got an id
1278
+		if (! isset($this->_req_data['VEN_CAT_ID'])) {
1279
+			return;
1280
+		}
1281
+
1282
+		$category_id = absint($this->_req_data['VEN_CAT_ID']);
1283
+		$term = get_term($category_id, 'espresso_venue_categories');
1284
+
1285
+
1286
+		if (! empty($term)) {
1287
+			$this->_category->category_name = $term->name;
1288
+			$this->_category->category_identifier = $term->slug;
1289
+			$this->_category->category_desc = $term->description;
1290
+			$this->_category->id = $term->term_id;
1291
+			$this->_category->parent = $term->parent;
1292
+		}
1293
+	}
1294
+
1295
+
1296
+	private function _set_empty_category_object()
1297
+	{
1298
+		$this->_category = new stdClass();
1299
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1300
+		$this->_category->id = $this->_category->parent = 0;
1301
+	}
1302
+
1303
+
1304
+	protected function _category_list_table()
1305
+	{
1306
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1307
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1308
+			'add_category',
1309
+			'add_category',
1310
+			array(),
1311
+			'add-new-h2'
1312
+		);
1313
+		$this->_search_btn_label = __('Venue Categories', 'event_espresso');
1314
+		$this->display_admin_list_table_page_with_sidebar();
1315
+	}
1316
+
1317
+
1318
+	protected function _category_details($view)
1319
+	{
1320
+
1321
+		// load formatter helper
1322
+		// load field generator helper
1323
+
1324
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
1325
+		$this->_set_add_edit_form_tags($route);
1326
+
1327
+		$this->_set_category_object();
1328
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
1329
+
1330
+		$delete_action = 'delete_category';
1331
+
1332
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url);
1333
+
1334
+		$this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1335
+
1336
+		// take care of contents
1337
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
1338
+		$this->display_admin_page_with_sidebar();
1339
+	}
1340
+
1341
+
1342
+	protected function _category_details_content()
1343
+	{
1344
+		$editor_args['category_desc'] = array(
1345
+			'type'          => 'wp_editor',
1346
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1347
+			'class'         => 'my_editor_custom',
1348
+			'wpeditor_args' => array('media_buttons' => false),
1349
+		);
1350
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
1351
+
1352
+		$all_terms = get_terms(
1353
+			array('espresso_venue_categories'),
1354
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
1355
+		);
1356
+
1357
+		// setup category select for term parents.
1358
+		$category_select_values[] = array(
1359
+			'text' => __('No Parent', 'event_espresso'),
1360
+			'id'   => 0,
1361
+		);
1362
+		foreach ($all_terms as $term) {
1363
+			$category_select_values[] = array(
1364
+				'text' => $term->name,
1365
+				'id'   => $term->term_id,
1366
+			);
1367
+		}
1368
+
1369
+		$category_select = EEH_Form_Fields::select_input(
1370
+			'category_parent',
1371
+			$category_select_values,
1372
+			$this->_category->parent
1373
+		);
1374
+		$template_args = array(
1375
+			'category'                 => $this->_category,
1376
+			'category_select'          => $category_select,
1377
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1378
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1379
+			'disable'                  => '',
1380
+			'disabled_message'         => false,
1381
+		);
1382
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1383
+		return EEH_Template::display_template($template, $template_args, true);
1384
+	}
1385
+
1386
+
1387
+	protected function _delete_categories()
1388
+	{
1389
+		$cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID']
1390
+			: (array) $this->_req_data['category_id'];
1391
+
1392
+		foreach ($cat_ids as $cat_id) {
1393
+			$this->_delete_category($cat_id);
1394
+		}
1395
+
1396
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
1397
+		$query_args = array(
1398
+			'action' => 'category_list',
1399
+		);
1400
+		$this->_redirect_after_action(0, '', '', $query_args);
1401
+	}
1402
+
1403
+
1404
+	protected function _delete_category($cat_id)
1405
+	{
1406
+		$cat_id = absint($cat_id);
1407
+		wp_delete_term($cat_id, 'espresso_venue_categories');
1408
+	}
1409
+
1410
+
1411
+	protected function _insert_or_update_category($new_category)
1412
+	{
1413
+
1414
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1415
+		$success = 0; // we already have a success message so lets not send another.
1416
+		if ($cat_id) {
1417
+			$query_args = array(
1418
+				'action'     => 'edit_category',
1419
+				'VEN_CAT_ID' => $cat_id,
1420
+			);
1421
+		} else {
1422
+			$query_args = array('action' => 'add_category');
1423
+		}
1424
+		$this->_redirect_after_action($success, '', '', $query_args, true);
1425
+	}
1426
+
1427
+
1428
+	private function _insert_category($update = false)
1429
+	{
1430
+		$cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : '';
1431
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
1432
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
1433
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
1434
+
1435
+		if (empty($category_name)) {
1436
+			$msg = __('You must add a name for the category.', 'event_espresso');
1437
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1438
+			return false;
1439
+		}
1440
+
1441
+
1442
+		$term_args = array(
1443
+			'name'        => $category_name,
1444
+			'description' => $category_desc,
1445
+			'parent'      => $category_parent,
1446
+		);
1447
+
1448
+		$insert_ids = $update
1449
+			? wp_update_term($cat_id, 'espresso_venue_categories', $term_args)
1450
+			: wp_insert_term(
1451
+				$category_name,
1452
+				'espresso_venue_categories',
1453
+				$term_args
1454
+			);
1455
+
1456
+		if (! is_array($insert_ids)) {
1457
+			$msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1458
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1459
+		} else {
1460
+			$cat_id = $insert_ids['term_id'];
1461
+			$msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name);
1462
+			EE_Error::add_success($msg);
1463
+		}
1464
+
1465
+		return $cat_id;
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * TODO handle category exports()
1471
+	 *
1472
+	 * @return file export
1473
+	 */
1474
+	protected function _categories_export()
1475
+	{
1476
+
1477
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
1478
+		$new_request_args = array(
1479
+			'export'       => 'report',
1480
+			'action'       => 'categories',
1481
+			'category_ids' => $this->_req_data['VEN_CAT_ID'],
1482
+		);
1483
+
1484
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
1485
+
1486
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1487
+			require_once(EE_CLASSES . 'EE_Export.class.php');
1488
+			$EE_Export = EE_Export::instance($this->_req_data);
1489
+			$EE_Export->export();
1490
+		}
1491
+	}
1492
+
1493
+
1494
+	protected function _import_categories()
1495
+	{
1496
+
1497
+		require_once(EE_CLASSES . 'EE_Import.class.php');
1498
+		EE_Import::instance()->import();
1499
+	}
1500
+
1501
+
1502
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
1503
+	{
1504
+
1505
+		// testing term stuff
1506
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
1507
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1508
+		$limit = ($current_page - 1) * $per_page;
1509
+		$where = array('taxonomy' => 'espresso_venue_categories');
1510
+		if (isset($this->_req_data['s'])) {
1511
+			$sstr = '%' . $this->_req_data['s'] . '%';
1512
+			$where['OR'] = array(
1513
+				'Term.name'   => array('LIKE', $sstr),
1514
+				'description' => array('LIKE', $sstr),
1515
+			);
1516
+		}
1517
+
1518
+		$query_params = array(
1519
+			$where,
1520
+			'order_by'   => array($orderby => $order),
1521
+			'limit'      => $limit . ',' . $per_page,
1522
+			'force_join' => array('Term'),
1523
+		);
1524
+
1525
+		$categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1526
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
1527
+
1528
+		return $categories;
1529
+	}
1530
+
1531
+
1532
+	/* end category stuff */
1533
+	/**************/
1534 1534
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 
46 46
     protected function _init_page_props()
47 47
     {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
48
+        require_once(EE_MODELS.'EEM_Venue.model.php');
49 49
         $this->page_slug = EE_VENUES_PG_SLUG;
50 50
         $this->_admin_base_url = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
51
+        $this->_admin_base_path = EE_ADMIN_PAGES.'venues';
52 52
         $this->page_label = __('Event Venues', 'event_espresso');
53 53
         $this->_cpt_model_names = array(
54 54
             'create_new' => 'EEM_Venue',
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 
459 459
     public function load_scripts_styles()
460 460
     {
461
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
461
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
462 462
         wp_enqueue_style('ee-cat-admin');
463 463
     }
464 464
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
         wp_enqueue_style('espresso-ui-theme');
481 481
         wp_register_style(
482 482
             'espresso_venues',
483
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
483
+            EE_VENUES_ASSETS_URL.'ee-venues-admin.css',
484 484
             array(),
485 485
             EVENT_ESPRESSO_VERSION
486 486
         );
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
             __("View Venue Archive Page", "event_espresso"),
540 540
             'button'
541 541
         );
542
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
542
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
543 543
         $this->_search_btn_label = __('Venues', 'event_espresso');
544 544
         $this->display_admin_list_table_page_with_sidebar();
545 545
     }
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
             'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
553 553
             'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
554 554
         );
555
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
555
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_publish_box_extras.template.php';
556 556
         EEH_Template::display_template($template, $extra_rows);
557 557
     }
558 558
 
@@ -569,21 +569,21 @@  discard block
 block discarded – undo
569 569
         $default_map_settings->use_google_maps = true;
570 570
         $default_map_settings->google_map_api_key = '';
571 571
         // for event details pages (reg page)
572
-        $default_map_settings->event_details_map_width = 585;            // ee_map_width_single
573
-        $default_map_settings->event_details_map_height = 362;            // ee_map_height_single
574
-        $default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
575
-        $default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
576
-        $default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
577
-        $default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
578
-        $default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
572
+        $default_map_settings->event_details_map_width = 585; // ee_map_width_single
573
+        $default_map_settings->event_details_map_height = 362; // ee_map_height_single
574
+        $default_map_settings->event_details_map_zoom = 14; // ee_map_zoom_single
575
+        $default_map_settings->event_details_display_nav = true; // ee_map_nav_display_single
576
+        $default_map_settings->event_details_nav_size = false; // ee_map_nav_size_single
577
+        $default_map_settings->event_details_control_type = 'default'; // ee_map_type_control_single
578
+        $default_map_settings->event_details_map_align = 'center'; // ee_map_align_single
579 579
         // for event list pages
580
-        $default_map_settings->event_list_map_width = 300;            // ee_map_width
581
-        $default_map_settings->event_list_map_height = 185;        // ee_map_height
582
-        $default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
583
-        $default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
584
-        $default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
585
-        $default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
586
-        $default_map_settings->event_list_map_align = 'center';            // ee_map_align
580
+        $default_map_settings->event_list_map_width = 300; // ee_map_width
581
+        $default_map_settings->event_list_map_height = 185; // ee_map_height
582
+        $default_map_settings->event_list_map_zoom = 12; // ee_map_zoom
583
+        $default_map_settings->event_list_display_nav = false; // ee_map_nav_display
584
+        $default_map_settings->event_list_nav_size = true; // ee_map_nav_size
585
+        $default_map_settings->event_list_control_type = 'dropdown'; // ee_map_type_control
586
+        $default_map_settings->event_list_map_align = 'center'; // ee_map_align
587 587
 
588 588
         $this->_template_args['map_settings'] =
589 589
             isset(EE_Registry::instance()->CFG->map_settings)
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
         $this->_set_add_edit_form_tags('update_google_map_settings');
598 598
         $this->_set_publish_post_box_vars(null, false, false, null, false);
599 599
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
600
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
600
+            EE_VENUES_TEMPLATE_PATH.'google_map.template.php',
601 601
             $this->_template_args,
602 602
             true
603 603
         );
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
             ),
746 746
             'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
747 747
         );
748
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
748
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_gmap_metabox_content.template.php';
749 749
         EEH_Template::display_template($template, $template_args);
750 750
     }
751 751
 
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
             )
787 787
         );
788 788
 
789
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
789
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_address_metabox_content.template.php';
790 790
         EEH_Template::display_template($template, $template_args);
791 791
     }
792 792
 
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
         $template_args = array(
797 797
             '_venue' => $this->_cpt_model_obj,
798 798
         );
799
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
799
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_virtual_location_metabox_content.template.php';
800 800
         EEH_Template::display_template($template, $template_args);
801 801
     }
802 802
 
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
     {
822 822
 
823 823
         if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
824
-            return;// get out we're not processing the saving of venues.
824
+            return; // get out we're not processing the saving of venues.
825 825
         }
826 826
 
827 827
         $wheres = array($this->_venue_model->primary_key_name() => $post_id);
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
             // clean status
930 930
             $venue_status = sanitize_key($venue_status);
931 931
             // grab status
932
-            if (! empty($venue_status)) {
932
+            if ( ! empty($venue_status)) {
933 933
                 $success = $this->_change_venue_status($VNU_ID, $venue_status);
934 934
             } else {
935 935
                 $success = false;
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
         // clean status
961 961
         $venue_status = sanitize_key($venue_status);
962 962
         // grab status
963
-        if (! empty($venue_status)) {
963
+        if ( ! empty($venue_status)) {
964 964
             $success = true;
965 965
             // determine the event id and set to array.
966 966
             $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
     private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012 1012
     {
1013 1013
         // grab venue id
1014
-        if (! $VNU_ID) {
1014
+        if ( ! $VNU_ID) {
1015 1015
             $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1016 1016
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1017 1017
             return false;
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
         // clean status
1023 1023
         $venue_status = sanitize_key($venue_status);
1024 1024
         // grab status
1025
-        if (! $venue_status) {
1025
+        if ( ! $venue_status) {
1026 1026
             $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1027 1027
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028 1028
             return false;
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
     private function _delete_or_trash_venue($VNU_ID = false)
1121 1121
     {
1122 1122
         // grab event id
1123
-        if (! $VNU_ID = absint($VNU_ID)) {
1123
+        if ( ! $VNU_ID = absint($VNU_ID)) {
1124 1124
             $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1125 1125
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1126 1126
             return false;
@@ -1207,10 +1207,10 @@  discard block
 block discarded – undo
1207 1207
         }
1208 1208
 
1209 1209
 
1210
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1210
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1211 1211
             $where['VNU_wp_user'] = get_current_user_id();
1212 1212
         } else {
1213
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1213
+            if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1214 1214
                 $where['OR'] = array(
1215 1215
                     'status*restrict_private' => array('!=', 'private'),
1216 1216
                     'AND'                     => array(
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
 
1224 1224
 
1225 1225
         if (isset($this->_req_data['s'])) {
1226
-            $sstr = '%' . $this->_req_data['s'] . '%';
1226
+            $sstr = '%'.$this->_req_data['s'].'%';
1227 1227
             $where['OR'] = array(
1228 1228
                 'VNU_name'               => array('LIKE', $sstr),
1229 1229
                 'VNU_desc'               => array('LIKE', $sstr),
@@ -1275,7 +1275,7 @@  discard block
 block discarded – undo
1275 1275
         $this->_set_empty_category_object();
1276 1276
 
1277 1277
         // only set if we've got an id
1278
-        if (! isset($this->_req_data['VEN_CAT_ID'])) {
1278
+        if ( ! isset($this->_req_data['VEN_CAT_ID'])) {
1279 1279
             return;
1280 1280
         }
1281 1281
 
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
         $term = get_term($category_id, 'espresso_venue_categories');
1284 1284
 
1285 1285
 
1286
-        if (! empty($term)) {
1286
+        if ( ! empty($term)) {
1287 1287
             $this->_category->category_name = $term->name;
1288 1288
             $this->_category->category_identifier = $term->slug;
1289 1289
             $this->_category->category_desc = $term->description;
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
     protected function _category_list_table()
1305 1305
     {
1306 1306
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1307
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1307
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1308 1308
             'add_category',
1309 1309
             'add_category',
1310 1310
             array(),
@@ -1379,7 +1379,7 @@  discard block
 block discarded – undo
1379 1379
             'disable'                  => '',
1380 1380
             'disabled_message'         => false,
1381 1381
         );
1382
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1382
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
1383 1383
         return EEH_Template::display_template($template, $template_args, true);
1384 1384
     }
1385 1385
 
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
                 $term_args
1454 1454
             );
1455 1455
 
1456
-        if (! is_array($insert_ids)) {
1456
+        if ( ! is_array($insert_ids)) {
1457 1457
             $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1458 1458
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1459 1459
         } else {
@@ -1483,8 +1483,8 @@  discard block
 block discarded – undo
1483 1483
 
1484 1484
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
1485 1485
 
1486
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1487
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1486
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
1487
+            require_once(EE_CLASSES.'EE_Export.class.php');
1488 1488
             $EE_Export = EE_Export::instance($this->_req_data);
1489 1489
             $EE_Export->export();
1490 1490
         }
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
     protected function _import_categories()
1495 1495
     {
1496 1496
 
1497
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1497
+        require_once(EE_CLASSES.'EE_Import.class.php');
1498 1498
         EE_Import::instance()->import();
1499 1499
     }
1500 1500
 
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
         $limit = ($current_page - 1) * $per_page;
1509 1509
         $where = array('taxonomy' => 'espresso_venue_categories');
1510 1510
         if (isset($this->_req_data['s'])) {
1511
-            $sstr = '%' . $this->_req_data['s'] . '%';
1511
+            $sstr = '%'.$this->_req_data['s'].'%';
1512 1512
             $where['OR'] = array(
1513 1513
                 'Term.name'   => array('LIKE', $sstr),
1514 1514
                 'description' => array('LIKE', $sstr),
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
         $query_params = array(
1519 1519
             $where,
1520 1520
             'order_by'   => array($orderby => $order),
1521
-            'limit'      => $limit . ',' . $per_page,
1521
+            'limit'      => $limit.','.$per_page,
1522 1522
             'force_join' => array('Term'),
1523 1523
         );
1524 1524
 
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      *
343 343
      * @param $template
344 344
      * @param $template_args
345
-     * @return mixed
345
+     * @return string
346 346
      * @throws DomainException
347 347
      */
348 348
     public function add_additional_datetime_button($template, $template_args)
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      *
361 361
      * @param $template
362 362
      * @param $template_args
363
-     * @return mixed
363
+     * @return string
364 364
      * @throws DomainException
365 365
      */
366 366
     public function add_datetime_clone_button($template, $template_args)
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
      *
379 379
      * @param $template
380 380
      * @param $template_args
381
-     * @return mixed
381
+     * @return string
382 382
      * @throws DomainException
383 383
      */
384 384
     public function datetime_timezones_template($template, $template_args)
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function __construct($routing = true)
41 41
     {
42
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
43
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
44
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
45
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
42
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
43
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
44
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
45
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
46 46
         }
47 47
         parent::__construct($routing);
48 48
     }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     protected function _extend_page_config()
61 61
     {
62
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
62
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
63 63
         // is there a evt_id in the request?
64 64
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
65 65
             ? $this->_req_data['EVT_ID']
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     {
293 293
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
294 294
         // make sure this is only when editing
295
-        if (! empty($id)) {
295
+        if ( ! empty($id)) {
296 296
             $href = EE_Admin_Page::add_query_args_and_nonce(
297 297
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
298 298
                 $this->_admin_base_url
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
     {
345 345
         wp_register_script(
346 346
             'ee-event-editor-heartbeat',
347
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
347
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
348 348
             array('ee_admin_js', 'heartbeat'),
349 349
             EVENT_ESPRESSO_VERSION,
350 350
             true
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
     public function add_additional_datetime_button($template, $template_args)
369 369
     {
370 370
         return EEH_Template::display_template(
371
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
371
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
372 372
             $template_args,
373 373
             true
374 374
         );
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
     public function add_datetime_clone_button($template, $template_args)
387 387
     {
388 388
         return EEH_Template::display_template(
389
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
389
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
390 390
             $template_args,
391 391
             true
392 392
         );
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
     public function datetime_timezones_template($template, $template_args)
405 405
     {
406 406
         return EEH_Template::display_template(
407
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
407
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
408 408
             $template_args,
409 409
             true
410 410
         );
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
     {
534 534
         // first make sure the ID for the event is in the request.
535 535
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
536
-        if (! isset($this->_req_data['EVT_ID'])) {
536
+        if ( ! isset($this->_req_data['EVT_ID'])) {
537 537
             EE_Error::add_error(
538 538
                 esc_html__(
539 539
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
         }
549 549
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
550 550
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
551
-        if (! $orig_event instanceof EE_Event) {
551
+        if ( ! $orig_event instanceof EE_Event) {
552 552
             throw new EE_Error(
553 553
                 sprintf(
554 554
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
         $orig_ven = $orig_event->get_many_related('Venue');
565 565
         // reset the ID and modify other details to make it clear this is a dupe
566 566
         $new_event->set('EVT_ID', 0);
567
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
567
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
568 568
         $new_event->set('EVT_name', $new_name);
569 569
         $new_event->set(
570 570
             'EVT_slug',
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
             'Question_Group',
594 594
             [['Event_Question_Group.EQG_primary' => true]]
595 595
         );
596
-        if (! empty($orig_primary_qgs)) {
596
+        if ( ! empty($orig_primary_qgs)) {
597 597
             foreach ($orig_primary_qgs as $id => $obj) {
598 598
                 if ($obj instanceof EE_Question_Group) {
599 599
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
             'Question_Group',
606 606
             [['Event_Question_Group.EQG_additional' => true]]
607 607
         );
608
-        if (! empty($orig_additional_qgs)) {
608
+        if ( ! empty($orig_additional_qgs)) {
609 609
             foreach ($orig_additional_qgs as $id => $obj) {
610 610
                 if ($obj instanceof EE_Question_Group) {
611 611
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
619 619
         $cloned_tickets = array();
620 620
         foreach ($orig_datetimes as $orig_dtt) {
621
-            if (! $orig_dtt instanceof EE_Datetime) {
621
+            if ( ! $orig_dtt instanceof EE_Datetime) {
622 622
                 continue;
623 623
             }
624 624
             $new_dtt = clone $orig_dtt;
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
             // now let's get the ticket relations setup.
634 634
             foreach ((array) $orig_tkts as $orig_tkt) {
635 635
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
636
-                if (! $orig_tkt instanceof EE_Ticket) {
636
+                if ( ! $orig_tkt instanceof EE_Ticket) {
637 637
                     continue;
638 638
                 }
639 639
                 // is this ticket archived?  If it is then let's skip
@@ -642,8 +642,8 @@  discard block
 block discarded – undo
642 642
                 }
643 643
                 // does this original ticket already exist in the clone_tickets cache?
644 644
                 //  If so we'll just use the new ticket from it.
645
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
646
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
645
+                if (isset($cloned_tickets[$orig_tkt->ID()])) {
646
+                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
647 647
                 } else {
648 648
                     $new_tkt = clone $orig_tkt;
649 649
                     // get relations on the $orig_tkt that we need to setup.
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
                 // for use with later datetimes that have the same ticket.
677 677
                 $new_dtt->_add_relation_to($new_tkt, 'Ticket');
678 678
                 $new_dtt->save();
679
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
679
+                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
680 680
             }
681 681
         }
682 682
         // clone taxonomy information
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
             $this->_admin_base_url
764 764
         );
765 765
         $content = EEH_Template::display_template(
766
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
766
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
767 767
             $this->_template_args,
768 768
             true
769 769
         );
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
      */
785 785
     protected function _import_events()
786 786
     {
787
-        require_once(EE_CLASSES . 'EE_Import.class.php');
787
+        require_once(EE_CLASSES.'EE_Import.class.php');
788 788
         $success = EE_Import::instance()->import();
789 789
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
790 790
     }
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
             'EVT_ID' => $event_ids,
814 814
         );
815 815
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
816
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
817
-            require_once(EE_CLASSES . 'EE_Export.class.php');
816
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
817
+            require_once(EE_CLASSES.'EE_Export.class.php');
818 818
             $EE_Export = EE_Export::instance($this->_req_data);
819 819
             $EE_Export->export();
820 820
         }
@@ -835,8 +835,8 @@  discard block
 block discarded – undo
835 835
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
836 836
         );
837 837
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
838
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
839
-            require_once(EE_CLASSES . 'EE_Export.class.php');
838
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
839
+            require_once(EE_CLASSES.'EE_Export.class.php');
840 840
             $EE_Export = EE_Export::instance($this->_req_data);
841 841
             $EE_Export->export();
842 842
         }
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
         $this->_set_add_edit_form_tags('update_template_settings');
878 878
         $this->_set_publish_post_box_vars(null, false, false, null, false);
879 879
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
880
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
880
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
881 881
             $this->_template_args,
882 882
             true
883 883
         );
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
             $default_reg_status_values
1011 1011
         );
1012 1012
         EEH_Template::display_template(
1013
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1013
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
1014 1014
             $template_args
1015 1015
         );
1016 1016
     }
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
         $venues = $venue_model->get_all(array('order_by' => array('VNU_name' => 'ASC')));
1120 1120
 
1121 1121
         foreach ($venues as $venue) {
1122
-            $values[ $venue->ID() ] = $venue->name();
1122
+            $values[$venue->ID()] = $venue->name();
1123 1123
         }
1124 1124
 
1125 1125
         return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
@@ -1153,13 +1153,13 @@  discard block
 block discarded – undo
1153 1153
     {
1154 1154
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1155 1155
             'DTT_EVT_start',
1156
-            date('Y-m-d') . ' 00:00:00',
1156
+            date('Y-m-d').' 00:00:00',
1157 1157
             'Y-m-d H:i:s',
1158 1158
             'UTC'
1159 1159
         );
1160 1160
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1161 1161
             'DTT_EVT_start',
1162
-            date('Y-m-d') . ' 23:59:59',
1162
+            date('Y-m-d').' 23:59:59',
1163 1163
             'Y-m-d H:i:s',
1164 1164
             'UTC'
1165 1165
         );
@@ -1189,13 +1189,13 @@  discard block
 block discarded – undo
1189 1189
         $days_this_month = date('t');
1190 1190
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1191 1191
             'DTT_EVT_start',
1192
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1192
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1193 1193
             'Y-m-d H:i:s',
1194 1194
             'UTC'
1195 1195
         );
1196 1196
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1197 1197
             'DTT_EVT_start',
1198
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1198
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1199 1199
             'Y-m-d H:i:s',
1200 1200
             'UTC'
1201 1201
         );
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
         $offset = ($current_page - 1) * $per_page;
1273 1273
         $limit = array($offset, $per_page);
1274 1274
         if (isset($this->_req_data['s'])) {
1275
-            $sstr = '%' . $this->_req_data['s'] . '%';
1275
+            $sstr = '%'.$this->_req_data['s'].'%';
1276 1276
             $_where['OR'] = array(
1277 1277
                 'TKT_name'        => array('LIKE', $sstr),
1278 1278
                 'TKT_description' => array('LIKE', $sstr),
@@ -1304,16 +1304,16 @@  discard block
 block discarded – undo
1304 1304
         $success = 1;
1305 1305
         $TKT = EEM_Ticket::instance();
1306 1306
         // checkboxes?
1307
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1307
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1308 1308
             // if array has more than one element then success message should be plural
1309 1309
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1310 1310
             // cycle thru the boxes
1311 1311
             foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1312 1312
                 if ($trash) {
1313
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1313
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1314 1314
                         $success = 0;
1315 1315
                     }
1316
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1316
+                } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1317 1317
                     $success = 0;
1318 1318
                 }
1319 1319
             }
@@ -1321,10 +1321,10 @@  discard block
 block discarded – undo
1321 1321
             // grab single id and trash
1322 1322
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1323 1323
             if ($trash) {
1324
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1324
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1325 1325
                     $success = 0;
1326 1326
                 }
1327
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1327
+            } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1328 1328
                 $success = 0;
1329 1329
             }
1330 1330
         }
@@ -1350,20 +1350,20 @@  discard block
 block discarded – undo
1350 1350
     {
1351 1351
         $success = 1;
1352 1352
         // checkboxes?
1353
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1353
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1354 1354
             // if array has more than one element then success message should be plural
1355 1355
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1356 1356
             // cycle thru the boxes
1357 1357
             foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1358 1358
                 // delete
1359
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1359
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1360 1360
                     $success = 0;
1361 1361
                 }
1362 1362
             }
1363 1363
         } else {
1364 1364
             // grab single id and trash
1365 1365
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1366
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1366
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1367 1367
                 $success = 0;
1368 1368
             }
1369 1369
         }
Please login to merge, or discard this patch.
Indentation   +1413 added lines, -1413 removed lines patch added patch discarded remove patch
@@ -18,1417 +18,1417 @@
 block discarded – undo
18 18
 class Extend_Events_Admin_Page extends Events_Admin_Page
19 19
 {
20 20
 
21
-    /**
22
-     * @var AdvancedEditorAdminFormSection
23
-     */
24
-    protected $advanced_editor_admin_form;
25
-
26
-    /**
27
-     * @var EventEditor
28
-     */
29
-    protected $advanced_editor_data;
30
-
31
-
32
-    /**
33
-     * Extend_Events_Admin_Page constructor.
34
-     *
35
-     * @param bool $routing
36
-     * @throws EE_Error
37
-     * @throws InvalidArgumentException
38
-     * @throws InvalidDataTypeException
39
-     * @throws InvalidInterfaceException
40
-     * @throws ReflectionException
41
-     */
42
-    public function __construct($routing = true)
43
-    {
44
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
45
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
46
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
47
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
48
-        }
49
-        parent::__construct($routing);
50
-    }
51
-
52
-
53
-    /**
54
-     * Sets routes.
55
-     *
56
-     * @throws EE_Error
57
-     * @throws InvalidArgumentException
58
-     * @throws InvalidDataTypeException
59
-     * @throws InvalidInterfaceException
60
-     * @throws Exception
61
-     */
62
-    protected function _extend_page_config()
63
-    {
64
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
65
-        // is there a evt_id in the request?
66
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
67
-            ? $this->_req_data['EVT_ID']
68
-            : 0;
69
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
70
-        // tkt_id?
71
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
72
-            ? $this->_req_data['TKT_ID']
73
-            : 0;
74
-        $new_page_routes = array(
75
-            'duplicate_event'          => array(
76
-                'func'       => '_duplicate_event',
77
-                'capability' => 'ee_edit_event',
78
-                'obj_id'     => $evt_id,
79
-                'noheader'   => true,
80
-            ),
81
-            'ticket_list_table'        => array(
82
-                'func'       => '_tickets_overview_list_table',
83
-                'capability' => 'ee_read_default_tickets',
84
-            ),
85
-            'trash_ticket'             => array(
86
-                'func'       => '_trash_or_restore_ticket',
87
-                'capability' => 'ee_delete_default_ticket',
88
-                'obj_id'     => $tkt_id,
89
-                'noheader'   => true,
90
-                'args'       => array('trash' => true),
91
-            ),
92
-            'trash_tickets'            => array(
93
-                'func'       => '_trash_or_restore_ticket',
94
-                'capability' => 'ee_delete_default_tickets',
95
-                'noheader'   => true,
96
-                'args'       => array('trash' => true),
97
-            ),
98
-            'restore_ticket'           => array(
99
-                'func'       => '_trash_or_restore_ticket',
100
-                'capability' => 'ee_delete_default_ticket',
101
-                'obj_id'     => $tkt_id,
102
-                'noheader'   => true,
103
-            ),
104
-            'restore_tickets'          => array(
105
-                'func'       => '_trash_or_restore_ticket',
106
-                'capability' => 'ee_delete_default_tickets',
107
-                'noheader'   => true,
108
-            ),
109
-            'delete_ticket'            => array(
110
-                'func'       => '_delete_ticket',
111
-                'capability' => 'ee_delete_default_ticket',
112
-                'obj_id'     => $tkt_id,
113
-                'noheader'   => true,
114
-            ),
115
-            'delete_tickets'           => array(
116
-                'func'       => '_delete_ticket',
117
-                'capability' => 'ee_delete_default_tickets',
118
-                'noheader'   => true,
119
-            ),
120
-            'import_page'              => array(
121
-                'func'       => '_import_page',
122
-                'capability' => 'import',
123
-            ),
124
-            'import'                   => array(
125
-                'func'       => '_import_events',
126
-                'capability' => 'import',
127
-                'noheader'   => true,
128
-            ),
129
-            'import_events'            => array(
130
-                'func'       => '_import_events',
131
-                'capability' => 'import',
132
-                'noheader'   => true,
133
-            ),
134
-            'export_events'            => array(
135
-                'func'       => '_events_export',
136
-                'capability' => 'export',
137
-                'noheader'   => true,
138
-            ),
139
-            'export_categories'        => array(
140
-                'func'       => '_categories_export',
141
-                'capability' => 'export',
142
-                'noheader'   => true,
143
-            ),
144
-            'sample_export_file'       => array(
145
-                'func'       => '_sample_export_file',
146
-                'capability' => 'export',
147
-                'noheader'   => true,
148
-            ),
149
-            'update_template_settings' => array(
150
-                'func'       => '_update_template_settings',
151
-                'capability' => 'manage_options',
152
-                'noheader'   => true,
153
-            ),
154
-        );
155
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
156
-        // partial route/config override
157
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
158
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
159
-        $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
160
-        $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
161
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
162
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
163
-        // add tickets tab but only if there are more than one default ticket!
164
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
165
-            array(array('TKT_is_default' => 1)),
166
-            'TKT_ID',
167
-            true
168
-        );
169
-        if ($tkt_count > 1) {
170
-            $new_page_config = array(
171
-                'ticket_list_table' => array(
172
-                    'nav'           => array(
173
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
174
-                        'order' => 60,
175
-                    ),
176
-                    'list_table'    => 'Tickets_List_Table',
177
-                    'require_nonce' => false,
178
-                ),
179
-            );
180
-        }
181
-        // template settings
182
-        $new_page_config['template_settings'] = array(
183
-            'nav'           => array(
184
-                'label' => esc_html__('Templates', 'event_espresso'),
185
-                'order' => 30,
186
-            ),
187
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
188
-            'help_tabs'     => array(
189
-                'general_settings_templates_help_tab' => array(
190
-                    'title'    => esc_html__('Templates', 'event_espresso'),
191
-                    'filename' => 'general_settings_templates',
192
-                ),
193
-            ),
194
-            'help_tour'     => array('Templates_Help_Tour'),
195
-            'require_nonce' => false,
196
-        );
197
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
198
-        // add filters and actions
199
-        // modifying _views
200
-        add_filter(
201
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
202
-            array($this, 'add_additional_datetime_button'),
203
-            10,
204
-            2
205
-        );
206
-        add_filter(
207
-            'FHEE_event_datetime_metabox_clone_button_template',
208
-            array($this, 'add_datetime_clone_button'),
209
-            10,
210
-            2
211
-        );
212
-        add_filter(
213
-            'FHEE_event_datetime_metabox_timezones_template',
214
-            array($this, 'datetime_timezones_template'),
215
-            10,
216
-            2
217
-        );
218
-        // filters for event list table
219
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
220
-        add_filter(
221
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
222
-            array($this, 'extra_list_table_actions'),
223
-            10,
224
-            2
225
-        );
226
-        // legend item
227
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
228
-        add_action('admin_init', array($this, 'admin_init'));
229
-       // load additional handlers
230
-        $this->handleActionRequest();
231
-    }
232
-
233
-
234
-    private function getRequestAction()
235
-    {
236
-        return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null;
237
-    }
238
-
239
-
240
-    /**
241
-     * @throws Exception
242
-     */
243
-    private function handleActionRequest()
244
-    {
245
-        $action = $this->getRequestAction();
246
-        if ($action) {
247
-            // setup Advanced Editor ???
248
-            if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
249
-                $this->advanced_editor_admin_form = $this->loader->getShared(
250
-                    'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
251
-                );
252
-            }
253
-            $admin_config = $this->loader->getShared('EE_Admin_Config');
254
-            // load handler for GraphQL requests and EventEditor
255
-            if (($action === 'edit' || $action === 'create_new')
256
-                && $admin_config instanceof EE_Admin_Config
257
-                && class_exists('WPGraphQL')
258
-                && $admin_config->useAdvancedEditor()
259
-            ) {
260
-                try {
261
-                    /** @var EventEspresso\core\services\graphql\GraphQLManager $graphQL_manager */
262
-                    $graphQL_manager = $this->loader->getShared(
263
-                        'EventEspresso\core\services\graphql\GraphQLManager'
264
-                    );
265
-                    $graphQL_manager->init();
266
-                    $this->advanced_editor_data = $this->loader->getShared(
267
-                        'EventEspresso\core\domain\services\admin\events\editor\EventEditor',
268
-                        [$this->_cpt_model_obj]
269
-                    );
270
-                } catch (Exception $exception) {
271
-                    new ExceptionStackTraceDisplay($exception);
272
-                }
273
-            }
274
-        }
275
-    }
276
-
277
-
278
-    /**
279
-     * admin_init
280
-     */
281
-    public function admin_init()
282
-    {
283
-        EE_Registry::$i18n_js_strings = array_merge(
284
-            EE_Registry::$i18n_js_strings,
285
-            array(
286
-                'image_confirm'          => esc_html__(
287
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
288
-                    'event_espresso'
289
-                ),
290
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
291
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
292
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
293
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
294
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
295
-            )
296
-        );
297
-    }
298
-
299
-
300
-    /**
301
-     * Add per page screen options to the default ticket list table view.
302
-     *
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     */
307
-    protected function _add_screen_options_ticket_list_table()
308
-    {
309
-        $this->_per_page_screen_option();
310
-    }
311
-
312
-
313
-    /**
314
-     * @param string $return
315
-     * @param int    $id
316
-     * @param string $new_title
317
-     * @param string $new_slug
318
-     * @return string
319
-     */
320
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
321
-    {
322
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
323
-        // make sure this is only when editing
324
-        if (! empty($id)) {
325
-            $href = EE_Admin_Page::add_query_args_and_nonce(
326
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
327
-                $this->_admin_base_url
328
-            );
329
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
330
-            $return .= '<a href="'
331
-                       . $href
332
-                       . '" title="'
333
-                       . $title
334
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
335
-                       . $title
336
-                       . '</a>';
337
-        }
338
-        return $return;
339
-    }
340
-
341
-
342
-    /**
343
-     * Set the list table views for the default ticket list table view.
344
-     */
345
-    public function _set_list_table_views_ticket_list_table()
346
-    {
347
-        $this->_views = array(
348
-            'all'     => array(
349
-                'slug'        => 'all',
350
-                'label'       => esc_html__('All', 'event_espresso'),
351
-                'count'       => 0,
352
-                'bulk_action' => array(
353
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
354
-                ),
355
-            ),
356
-            'trashed' => array(
357
-                'slug'        => 'trashed',
358
-                'label'       => esc_html__('Trash', 'event_espresso'),
359
-                'count'       => 0,
360
-                'bulk_action' => array(
361
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
362
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
363
-                ),
364
-            ),
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * Enqueue scripts and styles for the event editor.
371
-     */
372
-    public function load_scripts_styles_edit()
373
-    {
374
-        wp_register_script(
375
-            'ee-event-editor-heartbeat',
376
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
377
-            array('ee_admin_js', 'heartbeat'),
378
-            EVENT_ESPRESSO_VERSION,
379
-            true
380
-        );
381
-        wp_enqueue_script('ee-accounting');
382
-        // styles
383
-        wp_enqueue_style('espresso-ui-theme');
384
-        wp_enqueue_script('event_editor_js');
385
-        wp_enqueue_script('ee-event-editor-heartbeat');
386
-    }
387
-
388
-
389
-    /**
390
-     * Returns template for the additional datetime.
391
-     *
392
-     * @param $template
393
-     * @param $template_args
394
-     * @return mixed
395
-     * @throws DomainException
396
-     */
397
-    public function add_additional_datetime_button($template, $template_args)
398
-    {
399
-        return EEH_Template::display_template(
400
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
401
-            $template_args,
402
-            true
403
-        );
404
-    }
405
-
406
-
407
-    /**
408
-     * Returns the template for cloning a datetime.
409
-     *
410
-     * @param $template
411
-     * @param $template_args
412
-     * @return mixed
413
-     * @throws DomainException
414
-     */
415
-    public function add_datetime_clone_button($template, $template_args)
416
-    {
417
-        return EEH_Template::display_template(
418
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
419
-            $template_args,
420
-            true
421
-        );
422
-    }
423
-
424
-
425
-    /**
426
-     * Returns the template for datetime timezones.
427
-     *
428
-     * @param $template
429
-     * @param $template_args
430
-     * @return mixed
431
-     * @throws DomainException
432
-     */
433
-    public function datetime_timezones_template($template, $template_args)
434
-    {
435
-        return EEH_Template::display_template(
436
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
437
-            $template_args,
438
-            true
439
-        );
440
-    }
441
-
442
-
443
-    /**
444
-     * Sets the views for the default list table view.
445
-     */
446
-    protected function _set_list_table_views_default()
447
-    {
448
-        parent::_set_list_table_views_default();
449
-        $new_views = array(
450
-            'today' => array(
451
-                'slug'        => 'today',
452
-                'label'       => esc_html__('Today', 'event_espresso'),
453
-                'count'       => $this->total_events_today(),
454
-                'bulk_action' => array(
455
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
456
-                ),
457
-            ),
458
-            'month' => array(
459
-                'slug'        => 'month',
460
-                'label'       => esc_html__('This Month', 'event_espresso'),
461
-                'count'       => $this->total_events_this_month(),
462
-                'bulk_action' => array(
463
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
464
-                ),
465
-            ),
466
-        );
467
-        $this->_views = array_merge($this->_views, $new_views);
468
-    }
469
-
470
-
471
-    /**
472
-     * Returns the extra action links for the default list table view.
473
-     *
474
-     * @param array    $action_links
475
-     * @param EE_Event $event
476
-     * @return array
477
-     * @throws EE_Error
478
-     * @throws InvalidArgumentException
479
-     * @throws InvalidDataTypeException
480
-     * @throws InvalidInterfaceException
481
-     * @throws ReflectionException
482
-     */
483
-    public function extra_list_table_actions(array $action_links, EE_Event $event)
484
-    {
485
-        if (EE_Registry::instance()->CAP->current_user_can(
486
-            'ee_read_registrations',
487
-            'espresso_registrations_reports',
488
-            $event->ID()
489
-        )
490
-        ) {
491
-            $reports_query_args = array(
492
-                'action' => 'reports',
493
-                'EVT_ID' => $event->ID(),
494
-            );
495
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
496
-            $action_links[] = '<a href="'
497
-                              . $reports_link
498
-                              . '" title="'
499
-                              . esc_attr__('View Report', 'event_espresso')
500
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
501
-                              . "\n\t";
502
-        }
503
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
504
-            EE_Registry::instance()->load_helper('MSG_Template');
505
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
506
-                'see_notifications_for',
507
-                null,
508
-                array('EVT_ID' => $event->ID())
509
-            );
510
-        }
511
-        return $action_links;
512
-    }
513
-
514
-
515
-    /**
516
-     * @param $items
517
-     * @return mixed
518
-     */
519
-    public function additional_legend_items($items)
520
-    {
521
-        if (EE_Registry::instance()->CAP->current_user_can(
522
-            'ee_read_registrations',
523
-            'espresso_registrations_reports'
524
-        )
525
-        ) {
526
-            $items['reports'] = array(
527
-                'class' => 'dashicons dashicons-chart-bar',
528
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
529
-            );
530
-        }
531
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
532
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
533
-            // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
534
-            // (can only use numeric offsets when treating strings as arrays)
535
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
536
-                $items['view_related_messages'] = array(
537
-                    'class' => $related_for_icon['css_class'],
538
-                    'desc'  => $related_for_icon['label'],
539
-                );
540
-            }
541
-        }
542
-        return $items;
543
-    }
544
-
545
-
546
-    /**
547
-     * This is the callback method for the duplicate event route
548
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
549
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
550
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
551
-     * After duplication the redirect is to the new event edit page.
552
-     *
553
-     * @return void
554
-     * @throws EE_Error If EE_Event is not available with given ID
555
-     * @throws InvalidArgumentException
556
-     * @throws InvalidDataTypeException
557
-     * @throws InvalidInterfaceException
558
-     * @throws ReflectionException
559
-     * @access protected
560
-     */
561
-    protected function _duplicate_event()
562
-    {
563
-        // first make sure the ID for the event is in the request.
564
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
565
-        if (! isset($this->_req_data['EVT_ID'])) {
566
-            EE_Error::add_error(
567
-                esc_html__(
568
-                    'In order to duplicate an event an Event ID is required.  None was given.',
569
-                    'event_espresso'
570
-                ),
571
-                __FILE__,
572
-                __FUNCTION__,
573
-                __LINE__
574
-            );
575
-            $this->_redirect_after_action(false, '', '', array(), true);
576
-            return;
577
-        }
578
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
579
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
580
-        if (! $orig_event instanceof EE_Event) {
581
-            throw new EE_Error(
582
-                sprintf(
583
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
584
-                    $this->_req_data['EVT_ID']
585
-                )
586
-            );
587
-        }
588
-        // k now let's clone the $orig_event before getting relations
589
-        $new_event = clone $orig_event;
590
-        // original datetimes
591
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
592
-        // other original relations
593
-        $orig_ven = $orig_event->get_many_related('Venue');
594
-        // reset the ID and modify other details to make it clear this is a dupe
595
-        $new_event->set('EVT_ID', 0);
596
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
597
-        $new_event->set('EVT_name', $new_name);
598
-        $new_event->set(
599
-            'EVT_slug',
600
-            wp_unique_post_slug(
601
-                sanitize_title($orig_event->name()),
602
-                0,
603
-                'publish',
604
-                'espresso_events',
605
-                0
606
-            )
607
-        );
608
-        $new_event->set('status', 'draft');
609
-        // duplicate discussion settings
610
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
611
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
612
-        // save the new event
613
-        $new_event->save();
614
-        // venues
615
-        foreach ($orig_ven as $ven) {
616
-            $new_event->_add_relation_to($ven, 'Venue');
617
-        }
618
-        $new_event->save();
619
-        // now we need to get the question group relations and handle that
620
-        // first primary question groups
621
-        $orig_primary_qgs = $orig_event->get_many_related(
622
-            'Question_Group',
623
-            [['Event_Question_Group.EQG_primary' => true]]
624
-        );
625
-        if (! empty($orig_primary_qgs)) {
626
-            foreach ($orig_primary_qgs as $id => $obj) {
627
-                if ($obj instanceof EE_Question_Group) {
628
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
629
-                }
630
-            }
631
-        }
632
-        // next additional attendee question groups
633
-        $orig_additional_qgs = $orig_event->get_many_related(
634
-            'Question_Group',
635
-            [['Event_Question_Group.EQG_additional' => true]]
636
-        );
637
-        if (! empty($orig_additional_qgs)) {
638
-            foreach ($orig_additional_qgs as $id => $obj) {
639
-                if ($obj instanceof EE_Question_Group) {
640
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
641
-                }
642
-            }
643
-        }
644
-
645
-        $new_event->save();
646
-
647
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
648
-        $cloned_tickets = array();
649
-        foreach ($orig_datetimes as $orig_dtt) {
650
-            if (! $orig_dtt instanceof EE_Datetime) {
651
-                continue;
652
-            }
653
-            $new_dtt = clone $orig_dtt;
654
-            $orig_tkts = $orig_dtt->tickets();
655
-            // save new dtt then add to event
656
-            $new_dtt->set('DTT_ID', 0);
657
-            $new_dtt->set('DTT_sold', 0);
658
-            $new_dtt->set_reserved(0);
659
-            $new_dtt->save();
660
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
661
-            $new_event->save();
662
-            // now let's get the ticket relations setup.
663
-            foreach ((array) $orig_tkts as $orig_tkt) {
664
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
665
-                if (! $orig_tkt instanceof EE_Ticket) {
666
-                    continue;
667
-                }
668
-                // is this ticket archived?  If it is then let's skip
669
-                if ($orig_tkt->get('TKT_deleted')) {
670
-                    continue;
671
-                }
672
-                // does this original ticket already exist in the clone_tickets cache?
673
-                //  If so we'll just use the new ticket from it.
674
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
675
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
676
-                } else {
677
-                    $new_tkt = clone $orig_tkt;
678
-                    // get relations on the $orig_tkt that we need to setup.
679
-                    $orig_prices = $orig_tkt->prices();
680
-                    $new_tkt->set('TKT_ID', 0);
681
-                    $new_tkt->set('TKT_sold', 0);
682
-                    $new_tkt->set('TKT_reserved', 0);
683
-                    $new_tkt->save(); // make sure new ticket has ID.
684
-                    // price relations on new ticket need to be setup.
685
-                    foreach ($orig_prices as $orig_price) {
686
-                        $new_price = clone $orig_price;
687
-                        $new_price->set('PRC_ID', 0);
688
-                        $new_price->save();
689
-                        $new_tkt->_add_relation_to($new_price, 'Price');
690
-                        $new_tkt->save();
691
-                    }
692
-
693
-                    do_action(
694
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
695
-                        $orig_tkt,
696
-                        $new_tkt,
697
-                        $orig_prices,
698
-                        $orig_event,
699
-                        $orig_dtt,
700
-                        $new_dtt
701
-                    );
702
-                }
703
-                // k now we can add the new ticket as a relation to the new datetime
704
-                // and make sure its added to our cached $cloned_tickets array
705
-                // for use with later datetimes that have the same ticket.
706
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
707
-                $new_dtt->save();
708
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
709
-            }
710
-        }
711
-        // clone taxonomy information
712
-        $taxonomies_to_clone_with = apply_filters(
713
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
714
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
715
-        );
716
-        // get terms for original event (notice)
717
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
718
-        // loop through terms and add them to new event.
719
-        foreach ($orig_terms as $term) {
720
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
721
-        }
722
-
723
-        // duplicate other core WP_Post items for this event.
724
-        // post thumbnail (feature image).
725
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
726
-        if ($feature_image_id) {
727
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
728
-        }
729
-
730
-        // duplicate page_template setting
731
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
732
-        if ($page_template) {
733
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
734
-        }
735
-
736
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
737
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
738
-        if ($new_event->ID()) {
739
-            $redirect_args = array(
740
-                'post'   => $new_event->ID(),
741
-                'action' => 'edit',
742
-            );
743
-            EE_Error::add_success(
744
-                esc_html__(
745
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
746
-                    'event_espresso'
747
-                )
748
-            );
749
-        } else {
750
-            $redirect_args = array(
751
-                'action' => 'default',
752
-            );
753
-            EE_Error::add_error(
754
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
755
-                __FILE__,
756
-                __FUNCTION__,
757
-                __LINE__
758
-            );
759
-        }
760
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
761
-    }
762
-
763
-
764
-    /**
765
-     * Generates output for the import page.
766
-     *
767
-     * @throws DomainException
768
-     * @throws EE_Error
769
-     * @throws InvalidArgumentException
770
-     * @throws InvalidDataTypeException
771
-     * @throws InvalidInterfaceException
772
-     */
773
-    protected function _import_page()
774
-    {
775
-        $title = esc_html__('Import', 'event_espresso');
776
-        $intro = esc_html__(
777
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
778
-            'event_espresso'
779
-        );
780
-        $form_url = EVENTS_ADMIN_URL;
781
-        $action = 'import_events';
782
-        $type = 'csv';
783
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
784
-            $title,
785
-            $intro,
786
-            $form_url,
787
-            $action,
788
-            $type
789
-        );
790
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
791
-            array('action' => 'sample_export_file'),
792
-            $this->_admin_base_url
793
-        );
794
-        $content = EEH_Template::display_template(
795
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
796
-            $this->_template_args,
797
-            true
798
-        );
799
-        $this->_template_args['admin_page_content'] = $content;
800
-        $this->display_admin_page_with_sidebar();
801
-    }
802
-
803
-
804
-    /**
805
-     * _import_events
806
-     * This handles displaying the screen and running imports for importing events.
807
-     *
808
-     * @return void
809
-     * @throws EE_Error
810
-     * @throws InvalidArgumentException
811
-     * @throws InvalidDataTypeException
812
-     * @throws InvalidInterfaceException
813
-     */
814
-    protected function _import_events()
815
-    {
816
-        require_once(EE_CLASSES . 'EE_Import.class.php');
817
-        $success = EE_Import::instance()->import();
818
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
819
-    }
820
-
821
-
822
-    /**
823
-     * _events_export
824
-     * Will export all (or just the given event) to a Excel compatible file.
825
-     *
826
-     * @access protected
827
-     * @return void
828
-     */
829
-    protected function _events_export()
830
-    {
831
-        if (isset($this->_req_data['EVT_ID'])) {
832
-            $event_ids = $this->_req_data['EVT_ID'];
833
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
834
-            $event_ids = $this->_req_data['EVT_IDs'];
835
-        } else {
836
-            $event_ids = null;
837
-        }
838
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
839
-        $new_request_args = array(
840
-            'export' => 'report',
841
-            'action' => 'all_event_data',
842
-            'EVT_ID' => $event_ids,
843
-        );
844
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
845
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
846
-            require_once(EE_CLASSES . 'EE_Export.class.php');
847
-            $EE_Export = EE_Export::instance($this->_req_data);
848
-            $EE_Export->export();
849
-        }
850
-    }
851
-
852
-
853
-    /**
854
-     * handle category exports()
855
-     *
856
-     * @return void
857
-     */
858
-    protected function _categories_export()
859
-    {
860
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
861
-        $new_request_args = array(
862
-            'export'       => 'report',
863
-            'action'       => 'categories',
864
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
865
-        );
866
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
867
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
868
-            require_once(EE_CLASSES . 'EE_Export.class.php');
869
-            $EE_Export = EE_Export::instance($this->_req_data);
870
-            $EE_Export->export();
871
-        }
872
-    }
873
-
874
-
875
-    /**
876
-     * Creates a sample CSV file for importing
877
-     */
878
-    protected function _sample_export_file()
879
-    {
880
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
881
-        EE_Export::instance()->export_sample();
882
-    }
883
-
884
-
885
-    /*************        Template Settings        *************/
886
-    /**
887
-     * Generates template settings page output
888
-     *
889
-     * @throws DomainException
890
-     * @throws EE_Error
891
-     * @throws InvalidArgumentException
892
-     * @throws InvalidDataTypeException
893
-     * @throws InvalidInterfaceException
894
-     */
895
-    protected function _template_settings()
896
-    {
897
-        $this->_template_args['values'] = $this->_yes_no_values;
898
-        /**
899
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
900
-         * from General_Settings_Admin_Page to here.
901
-         */
902
-        $this->_template_args = apply_filters(
903
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
904
-            $this->_template_args
905
-        );
906
-        $this->_set_add_edit_form_tags('update_template_settings');
907
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
908
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
909
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
910
-            $this->_template_args,
911
-            true
912
-        );
913
-        $this->display_admin_page_with_sidebar();
914
-    }
915
-
916
-
917
-    /**
918
-     * Handler for updating template settings.
919
-     *
920
-     * @throws EE_Error
921
-     * @throws InvalidArgumentException
922
-     * @throws InvalidDataTypeException
923
-     * @throws InvalidInterfaceException
924
-     */
925
-    protected function _update_template_settings()
926
-    {
927
-        /**
928
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
929
-         * from General_Settings_Admin_Page to here.
930
-         */
931
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
932
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
933
-            EE_Registry::instance()->CFG->template_settings,
934
-            $this->_req_data
935
-        );
936
-        // update custom post type slugs and detect if we need to flush rewrite rules
937
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
938
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
939
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
940
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
941
-        $what = 'Template Settings';
942
-        $success = $this->_update_espresso_configuration(
943
-            $what,
944
-            EE_Registry::instance()->CFG->template_settings,
945
-            __FILE__,
946
-            __FUNCTION__,
947
-            __LINE__
948
-        );
949
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
950
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
951
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
952
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
953
-            );
954
-            $rewrite_rules->flush();
955
-        }
956
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
957
-    }
958
-
959
-
960
-    /**
961
-     * _premium_event_editor_meta_boxes
962
-     * add all metaboxes related to the event_editor
963
-     *
964
-     * @access protected
965
-     * @return void
966
-     * @throws EE_Error
967
-     * @throws InvalidArgumentException
968
-     * @throws InvalidDataTypeException
969
-     * @throws InvalidInterfaceException
970
-     * @throws ReflectionException
971
-     */
972
-    protected function _premium_event_editor_meta_boxes()
973
-    {
974
-        $this->verify_cpt_object();
975
-        add_meta_box(
976
-            'espresso_event_editor_event_options',
977
-            esc_html__('Event Registration Options', 'event_espresso'),
978
-            array($this, 'registration_options_meta_box'),
979
-            $this->page_slug,
980
-            'side',
981
-            'core'
982
-        );
983
-    }
984
-
985
-
986
-    /**
987
-     * override caf metabox
988
-     *
989
-     * @return void
990
-     * @throws DomainException
991
-     * @throws EE_Error
992
-     */
993
-    public function registration_options_meta_box()
994
-    {
995
-        $yes_no_values = array(
996
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
997
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
998
-        );
999
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1000
-            array(
1001
-                EEM_Registration::status_id_cancelled,
1002
-                EEM_Registration::status_id_declined,
1003
-                EEM_Registration::status_id_incomplete,
1004
-                EEM_Registration::status_id_wait_list,
1005
-            ),
1006
-            true
1007
-        );
1008
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1009
-        $template_args['_event'] = $this->_cpt_model_obj;
1010
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1011
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1012
-            'default_reg_status',
1013
-            $default_reg_status_values,
1014
-            $this->_cpt_model_obj->default_registration_status()
1015
-        );
1016
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1017
-            'display_desc',
1018
-            $yes_no_values,
1019
-            $this->_cpt_model_obj->display_description()
1020
-        );
1021
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1022
-            'display_ticket_selector',
1023
-            $yes_no_values,
1024
-            $this->_cpt_model_obj->display_ticket_selector(),
1025
-            '',
1026
-            '',
1027
-            false
1028
-        );
1029
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1030
-            'EVT_default_registration_status',
1031
-            $default_reg_status_values,
1032
-            $this->_cpt_model_obj->default_registration_status()
1033
-        );
1034
-        $template_args['additional_registration_options'] = apply_filters(
1035
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1036
-            '',
1037
-            $template_args,
1038
-            $yes_no_values,
1039
-            $default_reg_status_values
1040
-        );
1041
-        EEH_Template::display_template(
1042
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1043
-            $template_args
1044
-        );
1045
-    }
1046
-
1047
-
1048
-
1049
-    /**
1050
-     * wp_list_table_mods for caf
1051
-     * ============================
1052
-     */
1053
-    /**
1054
-     * hook into list table filters and provide filters for caffeinated list table
1055
-     *
1056
-     * @param array $old_filters    any existing filters present
1057
-     * @param array $list_table_obj the list table object
1058
-     * @return array                  new filters
1059
-     * @throws EE_Error
1060
-     * @throws InvalidArgumentException
1061
-     * @throws InvalidDataTypeException
1062
-     * @throws InvalidInterfaceException
1063
-     * @throws ReflectionException
1064
-     */
1065
-    public function list_table_filters($old_filters, $list_table_obj)
1066
-    {
1067
-        $filters = array();
1068
-        // first month/year filters
1069
-        $filters[] = $this->espresso_event_months_dropdown();
1070
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1071
-        // active status dropdown
1072
-        if ($status !== 'draft') {
1073
-            $filters[] = $this->active_status_dropdown(
1074
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1075
-            );
1076
-            $filters[] = $this->venuesDropdown(
1077
-                isset($this->_req_data['venue']) ? $this->_req_data['venue'] : ''
1078
-            );
1079
-        }
1080
-        // category filter
1081
-        $filters[] = $this->category_dropdown();
1082
-        return array_merge($old_filters, $filters);
1083
-    }
1084
-
1085
-
1086
-    /**
1087
-     * espresso_event_months_dropdown
1088
-     *
1089
-     * @access public
1090
-     * @return string                dropdown listing month/year selections for events.
1091
-     */
1092
-    public function espresso_event_months_dropdown()
1093
-    {
1094
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1095
-        // Note we need to include any other filters that are set!
1096
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1097
-        // categories?
1098
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1099
-            ? $this->_req_data['EVT_CAT']
1100
-            : null;
1101
-        // active status?
1102
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1103
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1104
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * returns a list of "active" statuses on the event
1110
-     *
1111
-     * @param  string $current_value whatever the current active status is
1112
-     * @return string
1113
-     */
1114
-    public function active_status_dropdown($current_value = '')
1115
-    {
1116
-        $select_name = 'active_status';
1117
-        $values = array(
1118
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1119
-            'active'   => esc_html__('Active', 'event_espresso'),
1120
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1121
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1122
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1123
-        );
1124
-
1125
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     * returns a list of "venues"
1131
-     *
1132
-     * @param string $current_value whatever the current active status is
1133
-     * @return string
1134
-     * @throws EE_Error
1135
-     * @throws InvalidArgumentException
1136
-     * @throws InvalidDataTypeException
1137
-     * @throws InvalidInterfaceException
1138
-     * @throws ReflectionException
1139
-     */
1140
-    protected function venuesDropdown($current_value = '')
1141
-    {
1142
-        $select_name = 'venue';
1143
-        $values = array(
1144
-            '' => esc_html__('All Venues', 'event_espresso'),
1145
-        );
1146
-        // populate the list of venues.
1147
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1148
-        $venues = $venue_model->get_all(array('order_by' => array('VNU_name' => 'ASC')));
1149
-
1150
-        foreach ($venues as $venue) {
1151
-            $values[ $venue->ID() ] = $venue->name();
1152
-        }
1153
-
1154
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1155
-    }
1156
-
1157
-
1158
-    /**
1159
-     * output a dropdown of the categories for the category filter on the event admin list table
1160
-     *
1161
-     * @access  public
1162
-     * @return string html
1163
-     */
1164
-    public function category_dropdown()
1165
-    {
1166
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1167
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * get total number of events today
1173
-     *
1174
-     * @access public
1175
-     * @return int
1176
-     * @throws EE_Error
1177
-     * @throws InvalidArgumentException
1178
-     * @throws InvalidDataTypeException
1179
-     * @throws InvalidInterfaceException
1180
-     */
1181
-    public function total_events_today()
1182
-    {
1183
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1184
-            'DTT_EVT_start',
1185
-            date('Y-m-d') . ' 00:00:00',
1186
-            'Y-m-d H:i:s',
1187
-            'UTC'
1188
-        );
1189
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1190
-            'DTT_EVT_start',
1191
-            date('Y-m-d') . ' 23:59:59',
1192
-            'Y-m-d H:i:s',
1193
-            'UTC'
1194
-        );
1195
-        $where = array(
1196
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1197
-        );
1198
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1199
-        return $count;
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * get total number of events this month
1205
-     *
1206
-     * @access public
1207
-     * @return int
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws InvalidDataTypeException
1211
-     * @throws InvalidInterfaceException
1212
-     */
1213
-    public function total_events_this_month()
1214
-    {
1215
-        // Dates
1216
-        $this_year_r = date('Y');
1217
-        $this_month_r = date('m');
1218
-        $days_this_month = date('t');
1219
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1220
-            'DTT_EVT_start',
1221
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1222
-            'Y-m-d H:i:s',
1223
-            'UTC'
1224
-        );
1225
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1226
-            'DTT_EVT_start',
1227
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1228
-            'Y-m-d H:i:s',
1229
-            'UTC'
1230
-        );
1231
-        $where = array(
1232
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1233
-        );
1234
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1235
-        return $count;
1236
-    }
1237
-
1238
-
1239
-    /** DEFAULT TICKETS STUFF **/
1240
-
1241
-    /**
1242
-     * Output default tickets list table view.
1243
-     *
1244
-     * @throws DomainException
1245
-     * @throws EE_Error
1246
-     * @throws InvalidArgumentException
1247
-     * @throws InvalidDataTypeException
1248
-     * @throws InvalidInterfaceException
1249
-     */
1250
-    public function _tickets_overview_list_table()
1251
-    {
1252
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1253
-        $this->display_admin_list_table_page_with_no_sidebar();
1254
-    }
1255
-
1256
-
1257
-    /**
1258
-     * @param int  $per_page
1259
-     * @param bool $count
1260
-     * @param bool $trashed
1261
-     * @return EE_Soft_Delete_Base_Class[]|int
1262
-     * @throws EE_Error
1263
-     * @throws InvalidArgumentException
1264
-     * @throws InvalidDataTypeException
1265
-     * @throws InvalidInterfaceException
1266
-     */
1267
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1268
-    {
1269
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1270
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1271
-        switch ($orderby) {
1272
-            case 'TKT_name':
1273
-                $orderby = array('TKT_name' => $order);
1274
-                break;
1275
-            case 'TKT_price':
1276
-                $orderby = array('TKT_price' => $order);
1277
-                break;
1278
-            case 'TKT_uses':
1279
-                $orderby = array('TKT_uses' => $order);
1280
-                break;
1281
-            case 'TKT_min':
1282
-                $orderby = array('TKT_min' => $order);
1283
-                break;
1284
-            case 'TKT_max':
1285
-                $orderby = array('TKT_max' => $order);
1286
-                break;
1287
-            case 'TKT_qty':
1288
-                $orderby = array('TKT_qty' => $order);
1289
-                break;
1290
-        }
1291
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1292
-            ? $this->_req_data['paged']
1293
-            : 1;
1294
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1295
-            ? $this->_req_data['perpage']
1296
-            : $per_page;
1297
-        $_where = array(
1298
-            'TKT_is_default' => 1,
1299
-            'TKT_deleted'    => $trashed,
1300
-        );
1301
-        $offset = ($current_page - 1) * $per_page;
1302
-        $limit = array($offset, $per_page);
1303
-        if (isset($this->_req_data['s'])) {
1304
-            $sstr = '%' . $this->_req_data['s'] . '%';
1305
-            $_where['OR'] = array(
1306
-                'TKT_name'        => array('LIKE', $sstr),
1307
-                'TKT_description' => array('LIKE', $sstr),
1308
-            );
1309
-        }
1310
-        $query_params = array(
1311
-            $_where,
1312
-            'order_by' => $orderby,
1313
-            'limit'    => $limit,
1314
-            'group_by' => 'TKT_ID',
1315
-        );
1316
-        if ($count) {
1317
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1318
-        } else {
1319
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1320
-        }
1321
-    }
1322
-
1323
-
1324
-    /**
1325
-     * @param bool $trash
1326
-     * @throws EE_Error
1327
-     * @throws InvalidArgumentException
1328
-     * @throws InvalidDataTypeException
1329
-     * @throws InvalidInterfaceException
1330
-     */
1331
-    protected function _trash_or_restore_ticket($trash = false)
1332
-    {
1333
-        $success = 1;
1334
-        $TKT = EEM_Ticket::instance();
1335
-        // checkboxes?
1336
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1337
-            // if array has more than one element then success message should be plural
1338
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1339
-            // cycle thru the boxes
1340
-            foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1341
-                if ($trash) {
1342
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1343
-                        $success = 0;
1344
-                    }
1345
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1346
-                    $success = 0;
1347
-                }
1348
-            }
1349
-        } else {
1350
-            // grab single id and trash
1351
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1352
-            if ($trash) {
1353
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1354
-                    $success = 0;
1355
-                }
1356
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1357
-                $success = 0;
1358
-            }
1359
-        }
1360
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1361
-        $query_args = array(
1362
-            'action' => 'ticket_list_table',
1363
-            'status' => $trash ? '' : 'trashed',
1364
-        );
1365
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1366
-    }
1367
-
1368
-
1369
-    /**
1370
-     * Handles trashing default ticket.
1371
-     *
1372
-     * @throws EE_Error
1373
-     * @throws InvalidArgumentException
1374
-     * @throws InvalidDataTypeException
1375
-     * @throws InvalidInterfaceException
1376
-     * @throws ReflectionException
1377
-     */
1378
-    protected function _delete_ticket()
1379
-    {
1380
-        $success = 1;
1381
-        // checkboxes?
1382
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1383
-            // if array has more than one element then success message should be plural
1384
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1385
-            // cycle thru the boxes
1386
-            foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1387
-                // delete
1388
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1389
-                    $success = 0;
1390
-                }
1391
-            }
1392
-        } else {
1393
-            // grab single id and trash
1394
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1395
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1396
-                $success = 0;
1397
-            }
1398
-        }
1399
-        $action_desc = 'deleted';
1400
-        $query_args = array(
1401
-            'action' => 'ticket_list_table',
1402
-            'status' => 'trashed',
1403
-        );
1404
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1405
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1406
-            array(array('TKT_is_default' => 1)),
1407
-            'TKT_ID',
1408
-            true
1409
-        )
1410
-        ) {
1411
-            $query_args = array();
1412
-        }
1413
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * @param int $TKT_ID
1419
-     * @return bool|int
1420
-     * @throws EE_Error
1421
-     * @throws InvalidArgumentException
1422
-     * @throws InvalidDataTypeException
1423
-     * @throws InvalidInterfaceException
1424
-     * @throws ReflectionException
1425
-     */
1426
-    protected function _delete_the_ticket($TKT_ID)
1427
-    {
1428
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1429
-        $tkt->_remove_relations('Datetime');
1430
-        // delete all related prices first
1431
-        $tkt->delete_related_permanently('Price');
1432
-        return $tkt->delete_permanently();
1433
-    }
21
+	/**
22
+	 * @var AdvancedEditorAdminFormSection
23
+	 */
24
+	protected $advanced_editor_admin_form;
25
+
26
+	/**
27
+	 * @var EventEditor
28
+	 */
29
+	protected $advanced_editor_data;
30
+
31
+
32
+	/**
33
+	 * Extend_Events_Admin_Page constructor.
34
+	 *
35
+	 * @param bool $routing
36
+	 * @throws EE_Error
37
+	 * @throws InvalidArgumentException
38
+	 * @throws InvalidDataTypeException
39
+	 * @throws InvalidInterfaceException
40
+	 * @throws ReflectionException
41
+	 */
42
+	public function __construct($routing = true)
43
+	{
44
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
45
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
46
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
47
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
48
+		}
49
+		parent::__construct($routing);
50
+	}
51
+
52
+
53
+	/**
54
+	 * Sets routes.
55
+	 *
56
+	 * @throws EE_Error
57
+	 * @throws InvalidArgumentException
58
+	 * @throws InvalidDataTypeException
59
+	 * @throws InvalidInterfaceException
60
+	 * @throws Exception
61
+	 */
62
+	protected function _extend_page_config()
63
+	{
64
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
65
+		// is there a evt_id in the request?
66
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
67
+			? $this->_req_data['EVT_ID']
68
+			: 0;
69
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
70
+		// tkt_id?
71
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
72
+			? $this->_req_data['TKT_ID']
73
+			: 0;
74
+		$new_page_routes = array(
75
+			'duplicate_event'          => array(
76
+				'func'       => '_duplicate_event',
77
+				'capability' => 'ee_edit_event',
78
+				'obj_id'     => $evt_id,
79
+				'noheader'   => true,
80
+			),
81
+			'ticket_list_table'        => array(
82
+				'func'       => '_tickets_overview_list_table',
83
+				'capability' => 'ee_read_default_tickets',
84
+			),
85
+			'trash_ticket'             => array(
86
+				'func'       => '_trash_or_restore_ticket',
87
+				'capability' => 'ee_delete_default_ticket',
88
+				'obj_id'     => $tkt_id,
89
+				'noheader'   => true,
90
+				'args'       => array('trash' => true),
91
+			),
92
+			'trash_tickets'            => array(
93
+				'func'       => '_trash_or_restore_ticket',
94
+				'capability' => 'ee_delete_default_tickets',
95
+				'noheader'   => true,
96
+				'args'       => array('trash' => true),
97
+			),
98
+			'restore_ticket'           => array(
99
+				'func'       => '_trash_or_restore_ticket',
100
+				'capability' => 'ee_delete_default_ticket',
101
+				'obj_id'     => $tkt_id,
102
+				'noheader'   => true,
103
+			),
104
+			'restore_tickets'          => array(
105
+				'func'       => '_trash_or_restore_ticket',
106
+				'capability' => 'ee_delete_default_tickets',
107
+				'noheader'   => true,
108
+			),
109
+			'delete_ticket'            => array(
110
+				'func'       => '_delete_ticket',
111
+				'capability' => 'ee_delete_default_ticket',
112
+				'obj_id'     => $tkt_id,
113
+				'noheader'   => true,
114
+			),
115
+			'delete_tickets'           => array(
116
+				'func'       => '_delete_ticket',
117
+				'capability' => 'ee_delete_default_tickets',
118
+				'noheader'   => true,
119
+			),
120
+			'import_page'              => array(
121
+				'func'       => '_import_page',
122
+				'capability' => 'import',
123
+			),
124
+			'import'                   => array(
125
+				'func'       => '_import_events',
126
+				'capability' => 'import',
127
+				'noheader'   => true,
128
+			),
129
+			'import_events'            => array(
130
+				'func'       => '_import_events',
131
+				'capability' => 'import',
132
+				'noheader'   => true,
133
+			),
134
+			'export_events'            => array(
135
+				'func'       => '_events_export',
136
+				'capability' => 'export',
137
+				'noheader'   => true,
138
+			),
139
+			'export_categories'        => array(
140
+				'func'       => '_categories_export',
141
+				'capability' => 'export',
142
+				'noheader'   => true,
143
+			),
144
+			'sample_export_file'       => array(
145
+				'func'       => '_sample_export_file',
146
+				'capability' => 'export',
147
+				'noheader'   => true,
148
+			),
149
+			'update_template_settings' => array(
150
+				'func'       => '_update_template_settings',
151
+				'capability' => 'manage_options',
152
+				'noheader'   => true,
153
+			),
154
+		);
155
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
156
+		// partial route/config override
157
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
158
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
159
+		$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
160
+		$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
161
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
162
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
163
+		// add tickets tab but only if there are more than one default ticket!
164
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
165
+			array(array('TKT_is_default' => 1)),
166
+			'TKT_ID',
167
+			true
168
+		);
169
+		if ($tkt_count > 1) {
170
+			$new_page_config = array(
171
+				'ticket_list_table' => array(
172
+					'nav'           => array(
173
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
174
+						'order' => 60,
175
+					),
176
+					'list_table'    => 'Tickets_List_Table',
177
+					'require_nonce' => false,
178
+				),
179
+			);
180
+		}
181
+		// template settings
182
+		$new_page_config['template_settings'] = array(
183
+			'nav'           => array(
184
+				'label' => esc_html__('Templates', 'event_espresso'),
185
+				'order' => 30,
186
+			),
187
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
188
+			'help_tabs'     => array(
189
+				'general_settings_templates_help_tab' => array(
190
+					'title'    => esc_html__('Templates', 'event_espresso'),
191
+					'filename' => 'general_settings_templates',
192
+				),
193
+			),
194
+			'help_tour'     => array('Templates_Help_Tour'),
195
+			'require_nonce' => false,
196
+		);
197
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
198
+		// add filters and actions
199
+		// modifying _views
200
+		add_filter(
201
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
202
+			array($this, 'add_additional_datetime_button'),
203
+			10,
204
+			2
205
+		);
206
+		add_filter(
207
+			'FHEE_event_datetime_metabox_clone_button_template',
208
+			array($this, 'add_datetime_clone_button'),
209
+			10,
210
+			2
211
+		);
212
+		add_filter(
213
+			'FHEE_event_datetime_metabox_timezones_template',
214
+			array($this, 'datetime_timezones_template'),
215
+			10,
216
+			2
217
+		);
218
+		// filters for event list table
219
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
220
+		add_filter(
221
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
222
+			array($this, 'extra_list_table_actions'),
223
+			10,
224
+			2
225
+		);
226
+		// legend item
227
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
228
+		add_action('admin_init', array($this, 'admin_init'));
229
+	   // load additional handlers
230
+		$this->handleActionRequest();
231
+	}
232
+
233
+
234
+	private function getRequestAction()
235
+	{
236
+		return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @throws Exception
242
+	 */
243
+	private function handleActionRequest()
244
+	{
245
+		$action = $this->getRequestAction();
246
+		if ($action) {
247
+			// setup Advanced Editor ???
248
+			if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
249
+				$this->advanced_editor_admin_form = $this->loader->getShared(
250
+					'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
251
+				);
252
+			}
253
+			$admin_config = $this->loader->getShared('EE_Admin_Config');
254
+			// load handler for GraphQL requests and EventEditor
255
+			if (($action === 'edit' || $action === 'create_new')
256
+				&& $admin_config instanceof EE_Admin_Config
257
+				&& class_exists('WPGraphQL')
258
+				&& $admin_config->useAdvancedEditor()
259
+			) {
260
+				try {
261
+					/** @var EventEspresso\core\services\graphql\GraphQLManager $graphQL_manager */
262
+					$graphQL_manager = $this->loader->getShared(
263
+						'EventEspresso\core\services\graphql\GraphQLManager'
264
+					);
265
+					$graphQL_manager->init();
266
+					$this->advanced_editor_data = $this->loader->getShared(
267
+						'EventEspresso\core\domain\services\admin\events\editor\EventEditor',
268
+						[$this->_cpt_model_obj]
269
+					);
270
+				} catch (Exception $exception) {
271
+					new ExceptionStackTraceDisplay($exception);
272
+				}
273
+			}
274
+		}
275
+	}
276
+
277
+
278
+	/**
279
+	 * admin_init
280
+	 */
281
+	public function admin_init()
282
+	{
283
+		EE_Registry::$i18n_js_strings = array_merge(
284
+			EE_Registry::$i18n_js_strings,
285
+			array(
286
+				'image_confirm'          => esc_html__(
287
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
288
+					'event_espresso'
289
+				),
290
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
291
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
292
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
293
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
294
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
295
+			)
296
+		);
297
+	}
298
+
299
+
300
+	/**
301
+	 * Add per page screen options to the default ticket list table view.
302
+	 *
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 */
307
+	protected function _add_screen_options_ticket_list_table()
308
+	{
309
+		$this->_per_page_screen_option();
310
+	}
311
+
312
+
313
+	/**
314
+	 * @param string $return
315
+	 * @param int    $id
316
+	 * @param string $new_title
317
+	 * @param string $new_slug
318
+	 * @return string
319
+	 */
320
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
321
+	{
322
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
323
+		// make sure this is only when editing
324
+		if (! empty($id)) {
325
+			$href = EE_Admin_Page::add_query_args_and_nonce(
326
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
327
+				$this->_admin_base_url
328
+			);
329
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
330
+			$return .= '<a href="'
331
+					   . $href
332
+					   . '" title="'
333
+					   . $title
334
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
335
+					   . $title
336
+					   . '</a>';
337
+		}
338
+		return $return;
339
+	}
340
+
341
+
342
+	/**
343
+	 * Set the list table views for the default ticket list table view.
344
+	 */
345
+	public function _set_list_table_views_ticket_list_table()
346
+	{
347
+		$this->_views = array(
348
+			'all'     => array(
349
+				'slug'        => 'all',
350
+				'label'       => esc_html__('All', 'event_espresso'),
351
+				'count'       => 0,
352
+				'bulk_action' => array(
353
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
354
+				),
355
+			),
356
+			'trashed' => array(
357
+				'slug'        => 'trashed',
358
+				'label'       => esc_html__('Trash', 'event_espresso'),
359
+				'count'       => 0,
360
+				'bulk_action' => array(
361
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
362
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
363
+				),
364
+			),
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * Enqueue scripts and styles for the event editor.
371
+	 */
372
+	public function load_scripts_styles_edit()
373
+	{
374
+		wp_register_script(
375
+			'ee-event-editor-heartbeat',
376
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
377
+			array('ee_admin_js', 'heartbeat'),
378
+			EVENT_ESPRESSO_VERSION,
379
+			true
380
+		);
381
+		wp_enqueue_script('ee-accounting');
382
+		// styles
383
+		wp_enqueue_style('espresso-ui-theme');
384
+		wp_enqueue_script('event_editor_js');
385
+		wp_enqueue_script('ee-event-editor-heartbeat');
386
+	}
387
+
388
+
389
+	/**
390
+	 * Returns template for the additional datetime.
391
+	 *
392
+	 * @param $template
393
+	 * @param $template_args
394
+	 * @return mixed
395
+	 * @throws DomainException
396
+	 */
397
+	public function add_additional_datetime_button($template, $template_args)
398
+	{
399
+		return EEH_Template::display_template(
400
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
401
+			$template_args,
402
+			true
403
+		);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Returns the template for cloning a datetime.
409
+	 *
410
+	 * @param $template
411
+	 * @param $template_args
412
+	 * @return mixed
413
+	 * @throws DomainException
414
+	 */
415
+	public function add_datetime_clone_button($template, $template_args)
416
+	{
417
+		return EEH_Template::display_template(
418
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
419
+			$template_args,
420
+			true
421
+		);
422
+	}
423
+
424
+
425
+	/**
426
+	 * Returns the template for datetime timezones.
427
+	 *
428
+	 * @param $template
429
+	 * @param $template_args
430
+	 * @return mixed
431
+	 * @throws DomainException
432
+	 */
433
+	public function datetime_timezones_template($template, $template_args)
434
+	{
435
+		return EEH_Template::display_template(
436
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
437
+			$template_args,
438
+			true
439
+		);
440
+	}
441
+
442
+
443
+	/**
444
+	 * Sets the views for the default list table view.
445
+	 */
446
+	protected function _set_list_table_views_default()
447
+	{
448
+		parent::_set_list_table_views_default();
449
+		$new_views = array(
450
+			'today' => array(
451
+				'slug'        => 'today',
452
+				'label'       => esc_html__('Today', 'event_espresso'),
453
+				'count'       => $this->total_events_today(),
454
+				'bulk_action' => array(
455
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
456
+				),
457
+			),
458
+			'month' => array(
459
+				'slug'        => 'month',
460
+				'label'       => esc_html__('This Month', 'event_espresso'),
461
+				'count'       => $this->total_events_this_month(),
462
+				'bulk_action' => array(
463
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
464
+				),
465
+			),
466
+		);
467
+		$this->_views = array_merge($this->_views, $new_views);
468
+	}
469
+
470
+
471
+	/**
472
+	 * Returns the extra action links for the default list table view.
473
+	 *
474
+	 * @param array    $action_links
475
+	 * @param EE_Event $event
476
+	 * @return array
477
+	 * @throws EE_Error
478
+	 * @throws InvalidArgumentException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws InvalidInterfaceException
481
+	 * @throws ReflectionException
482
+	 */
483
+	public function extra_list_table_actions(array $action_links, EE_Event $event)
484
+	{
485
+		if (EE_Registry::instance()->CAP->current_user_can(
486
+			'ee_read_registrations',
487
+			'espresso_registrations_reports',
488
+			$event->ID()
489
+		)
490
+		) {
491
+			$reports_query_args = array(
492
+				'action' => 'reports',
493
+				'EVT_ID' => $event->ID(),
494
+			);
495
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
496
+			$action_links[] = '<a href="'
497
+							  . $reports_link
498
+							  . '" title="'
499
+							  . esc_attr__('View Report', 'event_espresso')
500
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
501
+							  . "\n\t";
502
+		}
503
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
504
+			EE_Registry::instance()->load_helper('MSG_Template');
505
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
506
+				'see_notifications_for',
507
+				null,
508
+				array('EVT_ID' => $event->ID())
509
+			);
510
+		}
511
+		return $action_links;
512
+	}
513
+
514
+
515
+	/**
516
+	 * @param $items
517
+	 * @return mixed
518
+	 */
519
+	public function additional_legend_items($items)
520
+	{
521
+		if (EE_Registry::instance()->CAP->current_user_can(
522
+			'ee_read_registrations',
523
+			'espresso_registrations_reports'
524
+		)
525
+		) {
526
+			$items['reports'] = array(
527
+				'class' => 'dashicons dashicons-chart-bar',
528
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
529
+			);
530
+		}
531
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
532
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
533
+			// $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
534
+			// (can only use numeric offsets when treating strings as arrays)
535
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
536
+				$items['view_related_messages'] = array(
537
+					'class' => $related_for_icon['css_class'],
538
+					'desc'  => $related_for_icon['label'],
539
+				);
540
+			}
541
+		}
542
+		return $items;
543
+	}
544
+
545
+
546
+	/**
547
+	 * This is the callback method for the duplicate event route
548
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
549
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
550
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
551
+	 * After duplication the redirect is to the new event edit page.
552
+	 *
553
+	 * @return void
554
+	 * @throws EE_Error If EE_Event is not available with given ID
555
+	 * @throws InvalidArgumentException
556
+	 * @throws InvalidDataTypeException
557
+	 * @throws InvalidInterfaceException
558
+	 * @throws ReflectionException
559
+	 * @access protected
560
+	 */
561
+	protected function _duplicate_event()
562
+	{
563
+		// first make sure the ID for the event is in the request.
564
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
565
+		if (! isset($this->_req_data['EVT_ID'])) {
566
+			EE_Error::add_error(
567
+				esc_html__(
568
+					'In order to duplicate an event an Event ID is required.  None was given.',
569
+					'event_espresso'
570
+				),
571
+				__FILE__,
572
+				__FUNCTION__,
573
+				__LINE__
574
+			);
575
+			$this->_redirect_after_action(false, '', '', array(), true);
576
+			return;
577
+		}
578
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
579
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
580
+		if (! $orig_event instanceof EE_Event) {
581
+			throw new EE_Error(
582
+				sprintf(
583
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
584
+					$this->_req_data['EVT_ID']
585
+				)
586
+			);
587
+		}
588
+		// k now let's clone the $orig_event before getting relations
589
+		$new_event = clone $orig_event;
590
+		// original datetimes
591
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
592
+		// other original relations
593
+		$orig_ven = $orig_event->get_many_related('Venue');
594
+		// reset the ID and modify other details to make it clear this is a dupe
595
+		$new_event->set('EVT_ID', 0);
596
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
597
+		$new_event->set('EVT_name', $new_name);
598
+		$new_event->set(
599
+			'EVT_slug',
600
+			wp_unique_post_slug(
601
+				sanitize_title($orig_event->name()),
602
+				0,
603
+				'publish',
604
+				'espresso_events',
605
+				0
606
+			)
607
+		);
608
+		$new_event->set('status', 'draft');
609
+		// duplicate discussion settings
610
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
611
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
612
+		// save the new event
613
+		$new_event->save();
614
+		// venues
615
+		foreach ($orig_ven as $ven) {
616
+			$new_event->_add_relation_to($ven, 'Venue');
617
+		}
618
+		$new_event->save();
619
+		// now we need to get the question group relations and handle that
620
+		// first primary question groups
621
+		$orig_primary_qgs = $orig_event->get_many_related(
622
+			'Question_Group',
623
+			[['Event_Question_Group.EQG_primary' => true]]
624
+		);
625
+		if (! empty($orig_primary_qgs)) {
626
+			foreach ($orig_primary_qgs as $id => $obj) {
627
+				if ($obj instanceof EE_Question_Group) {
628
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
629
+				}
630
+			}
631
+		}
632
+		// next additional attendee question groups
633
+		$orig_additional_qgs = $orig_event->get_many_related(
634
+			'Question_Group',
635
+			[['Event_Question_Group.EQG_additional' => true]]
636
+		);
637
+		if (! empty($orig_additional_qgs)) {
638
+			foreach ($orig_additional_qgs as $id => $obj) {
639
+				if ($obj instanceof EE_Question_Group) {
640
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
641
+				}
642
+			}
643
+		}
644
+
645
+		$new_event->save();
646
+
647
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
648
+		$cloned_tickets = array();
649
+		foreach ($orig_datetimes as $orig_dtt) {
650
+			if (! $orig_dtt instanceof EE_Datetime) {
651
+				continue;
652
+			}
653
+			$new_dtt = clone $orig_dtt;
654
+			$orig_tkts = $orig_dtt->tickets();
655
+			// save new dtt then add to event
656
+			$new_dtt->set('DTT_ID', 0);
657
+			$new_dtt->set('DTT_sold', 0);
658
+			$new_dtt->set_reserved(0);
659
+			$new_dtt->save();
660
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
661
+			$new_event->save();
662
+			// now let's get the ticket relations setup.
663
+			foreach ((array) $orig_tkts as $orig_tkt) {
664
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
665
+				if (! $orig_tkt instanceof EE_Ticket) {
666
+					continue;
667
+				}
668
+				// is this ticket archived?  If it is then let's skip
669
+				if ($orig_tkt->get('TKT_deleted')) {
670
+					continue;
671
+				}
672
+				// does this original ticket already exist in the clone_tickets cache?
673
+				//  If so we'll just use the new ticket from it.
674
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
675
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
676
+				} else {
677
+					$new_tkt = clone $orig_tkt;
678
+					// get relations on the $orig_tkt that we need to setup.
679
+					$orig_prices = $orig_tkt->prices();
680
+					$new_tkt->set('TKT_ID', 0);
681
+					$new_tkt->set('TKT_sold', 0);
682
+					$new_tkt->set('TKT_reserved', 0);
683
+					$new_tkt->save(); // make sure new ticket has ID.
684
+					// price relations on new ticket need to be setup.
685
+					foreach ($orig_prices as $orig_price) {
686
+						$new_price = clone $orig_price;
687
+						$new_price->set('PRC_ID', 0);
688
+						$new_price->save();
689
+						$new_tkt->_add_relation_to($new_price, 'Price');
690
+						$new_tkt->save();
691
+					}
692
+
693
+					do_action(
694
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
695
+						$orig_tkt,
696
+						$new_tkt,
697
+						$orig_prices,
698
+						$orig_event,
699
+						$orig_dtt,
700
+						$new_dtt
701
+					);
702
+				}
703
+				// k now we can add the new ticket as a relation to the new datetime
704
+				// and make sure its added to our cached $cloned_tickets array
705
+				// for use with later datetimes that have the same ticket.
706
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
707
+				$new_dtt->save();
708
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
709
+			}
710
+		}
711
+		// clone taxonomy information
712
+		$taxonomies_to_clone_with = apply_filters(
713
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
714
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
715
+		);
716
+		// get terms for original event (notice)
717
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
718
+		// loop through terms and add them to new event.
719
+		foreach ($orig_terms as $term) {
720
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
721
+		}
722
+
723
+		// duplicate other core WP_Post items for this event.
724
+		// post thumbnail (feature image).
725
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
726
+		if ($feature_image_id) {
727
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
728
+		}
729
+
730
+		// duplicate page_template setting
731
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
732
+		if ($page_template) {
733
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
734
+		}
735
+
736
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
737
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
738
+		if ($new_event->ID()) {
739
+			$redirect_args = array(
740
+				'post'   => $new_event->ID(),
741
+				'action' => 'edit',
742
+			);
743
+			EE_Error::add_success(
744
+				esc_html__(
745
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
746
+					'event_espresso'
747
+				)
748
+			);
749
+		} else {
750
+			$redirect_args = array(
751
+				'action' => 'default',
752
+			);
753
+			EE_Error::add_error(
754
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
755
+				__FILE__,
756
+				__FUNCTION__,
757
+				__LINE__
758
+			);
759
+		}
760
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
761
+	}
762
+
763
+
764
+	/**
765
+	 * Generates output for the import page.
766
+	 *
767
+	 * @throws DomainException
768
+	 * @throws EE_Error
769
+	 * @throws InvalidArgumentException
770
+	 * @throws InvalidDataTypeException
771
+	 * @throws InvalidInterfaceException
772
+	 */
773
+	protected function _import_page()
774
+	{
775
+		$title = esc_html__('Import', 'event_espresso');
776
+		$intro = esc_html__(
777
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
778
+			'event_espresso'
779
+		);
780
+		$form_url = EVENTS_ADMIN_URL;
781
+		$action = 'import_events';
782
+		$type = 'csv';
783
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
784
+			$title,
785
+			$intro,
786
+			$form_url,
787
+			$action,
788
+			$type
789
+		);
790
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
791
+			array('action' => 'sample_export_file'),
792
+			$this->_admin_base_url
793
+		);
794
+		$content = EEH_Template::display_template(
795
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
796
+			$this->_template_args,
797
+			true
798
+		);
799
+		$this->_template_args['admin_page_content'] = $content;
800
+		$this->display_admin_page_with_sidebar();
801
+	}
802
+
803
+
804
+	/**
805
+	 * _import_events
806
+	 * This handles displaying the screen and running imports for importing events.
807
+	 *
808
+	 * @return void
809
+	 * @throws EE_Error
810
+	 * @throws InvalidArgumentException
811
+	 * @throws InvalidDataTypeException
812
+	 * @throws InvalidInterfaceException
813
+	 */
814
+	protected function _import_events()
815
+	{
816
+		require_once(EE_CLASSES . 'EE_Import.class.php');
817
+		$success = EE_Import::instance()->import();
818
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
819
+	}
820
+
821
+
822
+	/**
823
+	 * _events_export
824
+	 * Will export all (or just the given event) to a Excel compatible file.
825
+	 *
826
+	 * @access protected
827
+	 * @return void
828
+	 */
829
+	protected function _events_export()
830
+	{
831
+		if (isset($this->_req_data['EVT_ID'])) {
832
+			$event_ids = $this->_req_data['EVT_ID'];
833
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
834
+			$event_ids = $this->_req_data['EVT_IDs'];
835
+		} else {
836
+			$event_ids = null;
837
+		}
838
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
839
+		$new_request_args = array(
840
+			'export' => 'report',
841
+			'action' => 'all_event_data',
842
+			'EVT_ID' => $event_ids,
843
+		);
844
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
845
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
846
+			require_once(EE_CLASSES . 'EE_Export.class.php');
847
+			$EE_Export = EE_Export::instance($this->_req_data);
848
+			$EE_Export->export();
849
+		}
850
+	}
851
+
852
+
853
+	/**
854
+	 * handle category exports()
855
+	 *
856
+	 * @return void
857
+	 */
858
+	protected function _categories_export()
859
+	{
860
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
861
+		$new_request_args = array(
862
+			'export'       => 'report',
863
+			'action'       => 'categories',
864
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
865
+		);
866
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
867
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
868
+			require_once(EE_CLASSES . 'EE_Export.class.php');
869
+			$EE_Export = EE_Export::instance($this->_req_data);
870
+			$EE_Export->export();
871
+		}
872
+	}
873
+
874
+
875
+	/**
876
+	 * Creates a sample CSV file for importing
877
+	 */
878
+	protected function _sample_export_file()
879
+	{
880
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
881
+		EE_Export::instance()->export_sample();
882
+	}
883
+
884
+
885
+	/*************        Template Settings        *************/
886
+	/**
887
+	 * Generates template settings page output
888
+	 *
889
+	 * @throws DomainException
890
+	 * @throws EE_Error
891
+	 * @throws InvalidArgumentException
892
+	 * @throws InvalidDataTypeException
893
+	 * @throws InvalidInterfaceException
894
+	 */
895
+	protected function _template_settings()
896
+	{
897
+		$this->_template_args['values'] = $this->_yes_no_values;
898
+		/**
899
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
900
+		 * from General_Settings_Admin_Page to here.
901
+		 */
902
+		$this->_template_args = apply_filters(
903
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
904
+			$this->_template_args
905
+		);
906
+		$this->_set_add_edit_form_tags('update_template_settings');
907
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
908
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
909
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
910
+			$this->_template_args,
911
+			true
912
+		);
913
+		$this->display_admin_page_with_sidebar();
914
+	}
915
+
916
+
917
+	/**
918
+	 * Handler for updating template settings.
919
+	 *
920
+	 * @throws EE_Error
921
+	 * @throws InvalidArgumentException
922
+	 * @throws InvalidDataTypeException
923
+	 * @throws InvalidInterfaceException
924
+	 */
925
+	protected function _update_template_settings()
926
+	{
927
+		/**
928
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
929
+		 * from General_Settings_Admin_Page to here.
930
+		 */
931
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
932
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
933
+			EE_Registry::instance()->CFG->template_settings,
934
+			$this->_req_data
935
+		);
936
+		// update custom post type slugs and detect if we need to flush rewrite rules
937
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
938
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
939
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
940
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
941
+		$what = 'Template Settings';
942
+		$success = $this->_update_espresso_configuration(
943
+			$what,
944
+			EE_Registry::instance()->CFG->template_settings,
945
+			__FILE__,
946
+			__FUNCTION__,
947
+			__LINE__
948
+		);
949
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
950
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
951
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
952
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
953
+			);
954
+			$rewrite_rules->flush();
955
+		}
956
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
957
+	}
958
+
959
+
960
+	/**
961
+	 * _premium_event_editor_meta_boxes
962
+	 * add all metaboxes related to the event_editor
963
+	 *
964
+	 * @access protected
965
+	 * @return void
966
+	 * @throws EE_Error
967
+	 * @throws InvalidArgumentException
968
+	 * @throws InvalidDataTypeException
969
+	 * @throws InvalidInterfaceException
970
+	 * @throws ReflectionException
971
+	 */
972
+	protected function _premium_event_editor_meta_boxes()
973
+	{
974
+		$this->verify_cpt_object();
975
+		add_meta_box(
976
+			'espresso_event_editor_event_options',
977
+			esc_html__('Event Registration Options', 'event_espresso'),
978
+			array($this, 'registration_options_meta_box'),
979
+			$this->page_slug,
980
+			'side',
981
+			'core'
982
+		);
983
+	}
984
+
985
+
986
+	/**
987
+	 * override caf metabox
988
+	 *
989
+	 * @return void
990
+	 * @throws DomainException
991
+	 * @throws EE_Error
992
+	 */
993
+	public function registration_options_meta_box()
994
+	{
995
+		$yes_no_values = array(
996
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
997
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
998
+		);
999
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1000
+			array(
1001
+				EEM_Registration::status_id_cancelled,
1002
+				EEM_Registration::status_id_declined,
1003
+				EEM_Registration::status_id_incomplete,
1004
+				EEM_Registration::status_id_wait_list,
1005
+			),
1006
+			true
1007
+		);
1008
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1009
+		$template_args['_event'] = $this->_cpt_model_obj;
1010
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1011
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1012
+			'default_reg_status',
1013
+			$default_reg_status_values,
1014
+			$this->_cpt_model_obj->default_registration_status()
1015
+		);
1016
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1017
+			'display_desc',
1018
+			$yes_no_values,
1019
+			$this->_cpt_model_obj->display_description()
1020
+		);
1021
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1022
+			'display_ticket_selector',
1023
+			$yes_no_values,
1024
+			$this->_cpt_model_obj->display_ticket_selector(),
1025
+			'',
1026
+			'',
1027
+			false
1028
+		);
1029
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1030
+			'EVT_default_registration_status',
1031
+			$default_reg_status_values,
1032
+			$this->_cpt_model_obj->default_registration_status()
1033
+		);
1034
+		$template_args['additional_registration_options'] = apply_filters(
1035
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1036
+			'',
1037
+			$template_args,
1038
+			$yes_no_values,
1039
+			$default_reg_status_values
1040
+		);
1041
+		EEH_Template::display_template(
1042
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1043
+			$template_args
1044
+		);
1045
+	}
1046
+
1047
+
1048
+
1049
+	/**
1050
+	 * wp_list_table_mods for caf
1051
+	 * ============================
1052
+	 */
1053
+	/**
1054
+	 * hook into list table filters and provide filters for caffeinated list table
1055
+	 *
1056
+	 * @param array $old_filters    any existing filters present
1057
+	 * @param array $list_table_obj the list table object
1058
+	 * @return array                  new filters
1059
+	 * @throws EE_Error
1060
+	 * @throws InvalidArgumentException
1061
+	 * @throws InvalidDataTypeException
1062
+	 * @throws InvalidInterfaceException
1063
+	 * @throws ReflectionException
1064
+	 */
1065
+	public function list_table_filters($old_filters, $list_table_obj)
1066
+	{
1067
+		$filters = array();
1068
+		// first month/year filters
1069
+		$filters[] = $this->espresso_event_months_dropdown();
1070
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1071
+		// active status dropdown
1072
+		if ($status !== 'draft') {
1073
+			$filters[] = $this->active_status_dropdown(
1074
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1075
+			);
1076
+			$filters[] = $this->venuesDropdown(
1077
+				isset($this->_req_data['venue']) ? $this->_req_data['venue'] : ''
1078
+			);
1079
+		}
1080
+		// category filter
1081
+		$filters[] = $this->category_dropdown();
1082
+		return array_merge($old_filters, $filters);
1083
+	}
1084
+
1085
+
1086
+	/**
1087
+	 * espresso_event_months_dropdown
1088
+	 *
1089
+	 * @access public
1090
+	 * @return string                dropdown listing month/year selections for events.
1091
+	 */
1092
+	public function espresso_event_months_dropdown()
1093
+	{
1094
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1095
+		// Note we need to include any other filters that are set!
1096
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1097
+		// categories?
1098
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1099
+			? $this->_req_data['EVT_CAT']
1100
+			: null;
1101
+		// active status?
1102
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1103
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1104
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * returns a list of "active" statuses on the event
1110
+	 *
1111
+	 * @param  string $current_value whatever the current active status is
1112
+	 * @return string
1113
+	 */
1114
+	public function active_status_dropdown($current_value = '')
1115
+	{
1116
+		$select_name = 'active_status';
1117
+		$values = array(
1118
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1119
+			'active'   => esc_html__('Active', 'event_espresso'),
1120
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1121
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1122
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1123
+		);
1124
+
1125
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 * returns a list of "venues"
1131
+	 *
1132
+	 * @param string $current_value whatever the current active status is
1133
+	 * @return string
1134
+	 * @throws EE_Error
1135
+	 * @throws InvalidArgumentException
1136
+	 * @throws InvalidDataTypeException
1137
+	 * @throws InvalidInterfaceException
1138
+	 * @throws ReflectionException
1139
+	 */
1140
+	protected function venuesDropdown($current_value = '')
1141
+	{
1142
+		$select_name = 'venue';
1143
+		$values = array(
1144
+			'' => esc_html__('All Venues', 'event_espresso'),
1145
+		);
1146
+		// populate the list of venues.
1147
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1148
+		$venues = $venue_model->get_all(array('order_by' => array('VNU_name' => 'ASC')));
1149
+
1150
+		foreach ($venues as $venue) {
1151
+			$values[ $venue->ID() ] = $venue->name();
1152
+		}
1153
+
1154
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1155
+	}
1156
+
1157
+
1158
+	/**
1159
+	 * output a dropdown of the categories for the category filter on the event admin list table
1160
+	 *
1161
+	 * @access  public
1162
+	 * @return string html
1163
+	 */
1164
+	public function category_dropdown()
1165
+	{
1166
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1167
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * get total number of events today
1173
+	 *
1174
+	 * @access public
1175
+	 * @return int
1176
+	 * @throws EE_Error
1177
+	 * @throws InvalidArgumentException
1178
+	 * @throws InvalidDataTypeException
1179
+	 * @throws InvalidInterfaceException
1180
+	 */
1181
+	public function total_events_today()
1182
+	{
1183
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1184
+			'DTT_EVT_start',
1185
+			date('Y-m-d') . ' 00:00:00',
1186
+			'Y-m-d H:i:s',
1187
+			'UTC'
1188
+		);
1189
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1190
+			'DTT_EVT_start',
1191
+			date('Y-m-d') . ' 23:59:59',
1192
+			'Y-m-d H:i:s',
1193
+			'UTC'
1194
+		);
1195
+		$where = array(
1196
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1197
+		);
1198
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1199
+		return $count;
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * get total number of events this month
1205
+	 *
1206
+	 * @access public
1207
+	 * @return int
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws InvalidDataTypeException
1211
+	 * @throws InvalidInterfaceException
1212
+	 */
1213
+	public function total_events_this_month()
1214
+	{
1215
+		// Dates
1216
+		$this_year_r = date('Y');
1217
+		$this_month_r = date('m');
1218
+		$days_this_month = date('t');
1219
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1220
+			'DTT_EVT_start',
1221
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1222
+			'Y-m-d H:i:s',
1223
+			'UTC'
1224
+		);
1225
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1226
+			'DTT_EVT_start',
1227
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1228
+			'Y-m-d H:i:s',
1229
+			'UTC'
1230
+		);
1231
+		$where = array(
1232
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1233
+		);
1234
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1235
+		return $count;
1236
+	}
1237
+
1238
+
1239
+	/** DEFAULT TICKETS STUFF **/
1240
+
1241
+	/**
1242
+	 * Output default tickets list table view.
1243
+	 *
1244
+	 * @throws DomainException
1245
+	 * @throws EE_Error
1246
+	 * @throws InvalidArgumentException
1247
+	 * @throws InvalidDataTypeException
1248
+	 * @throws InvalidInterfaceException
1249
+	 */
1250
+	public function _tickets_overview_list_table()
1251
+	{
1252
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1253
+		$this->display_admin_list_table_page_with_no_sidebar();
1254
+	}
1255
+
1256
+
1257
+	/**
1258
+	 * @param int  $per_page
1259
+	 * @param bool $count
1260
+	 * @param bool $trashed
1261
+	 * @return EE_Soft_Delete_Base_Class[]|int
1262
+	 * @throws EE_Error
1263
+	 * @throws InvalidArgumentException
1264
+	 * @throws InvalidDataTypeException
1265
+	 * @throws InvalidInterfaceException
1266
+	 */
1267
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1268
+	{
1269
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1270
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1271
+		switch ($orderby) {
1272
+			case 'TKT_name':
1273
+				$orderby = array('TKT_name' => $order);
1274
+				break;
1275
+			case 'TKT_price':
1276
+				$orderby = array('TKT_price' => $order);
1277
+				break;
1278
+			case 'TKT_uses':
1279
+				$orderby = array('TKT_uses' => $order);
1280
+				break;
1281
+			case 'TKT_min':
1282
+				$orderby = array('TKT_min' => $order);
1283
+				break;
1284
+			case 'TKT_max':
1285
+				$orderby = array('TKT_max' => $order);
1286
+				break;
1287
+			case 'TKT_qty':
1288
+				$orderby = array('TKT_qty' => $order);
1289
+				break;
1290
+		}
1291
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1292
+			? $this->_req_data['paged']
1293
+			: 1;
1294
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1295
+			? $this->_req_data['perpage']
1296
+			: $per_page;
1297
+		$_where = array(
1298
+			'TKT_is_default' => 1,
1299
+			'TKT_deleted'    => $trashed,
1300
+		);
1301
+		$offset = ($current_page - 1) * $per_page;
1302
+		$limit = array($offset, $per_page);
1303
+		if (isset($this->_req_data['s'])) {
1304
+			$sstr = '%' . $this->_req_data['s'] . '%';
1305
+			$_where['OR'] = array(
1306
+				'TKT_name'        => array('LIKE', $sstr),
1307
+				'TKT_description' => array('LIKE', $sstr),
1308
+			);
1309
+		}
1310
+		$query_params = array(
1311
+			$_where,
1312
+			'order_by' => $orderby,
1313
+			'limit'    => $limit,
1314
+			'group_by' => 'TKT_ID',
1315
+		);
1316
+		if ($count) {
1317
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1318
+		} else {
1319
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1320
+		}
1321
+	}
1322
+
1323
+
1324
+	/**
1325
+	 * @param bool $trash
1326
+	 * @throws EE_Error
1327
+	 * @throws InvalidArgumentException
1328
+	 * @throws InvalidDataTypeException
1329
+	 * @throws InvalidInterfaceException
1330
+	 */
1331
+	protected function _trash_or_restore_ticket($trash = false)
1332
+	{
1333
+		$success = 1;
1334
+		$TKT = EEM_Ticket::instance();
1335
+		// checkboxes?
1336
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1337
+			// if array has more than one element then success message should be plural
1338
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1339
+			// cycle thru the boxes
1340
+			foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1341
+				if ($trash) {
1342
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1343
+						$success = 0;
1344
+					}
1345
+				} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1346
+					$success = 0;
1347
+				}
1348
+			}
1349
+		} else {
1350
+			// grab single id and trash
1351
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1352
+			if ($trash) {
1353
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1354
+					$success = 0;
1355
+				}
1356
+			} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1357
+				$success = 0;
1358
+			}
1359
+		}
1360
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1361
+		$query_args = array(
1362
+			'action' => 'ticket_list_table',
1363
+			'status' => $trash ? '' : 'trashed',
1364
+		);
1365
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1366
+	}
1367
+
1368
+
1369
+	/**
1370
+	 * Handles trashing default ticket.
1371
+	 *
1372
+	 * @throws EE_Error
1373
+	 * @throws InvalidArgumentException
1374
+	 * @throws InvalidDataTypeException
1375
+	 * @throws InvalidInterfaceException
1376
+	 * @throws ReflectionException
1377
+	 */
1378
+	protected function _delete_ticket()
1379
+	{
1380
+		$success = 1;
1381
+		// checkboxes?
1382
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1383
+			// if array has more than one element then success message should be plural
1384
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1385
+			// cycle thru the boxes
1386
+			foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1387
+				// delete
1388
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1389
+					$success = 0;
1390
+				}
1391
+			}
1392
+		} else {
1393
+			// grab single id and trash
1394
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1395
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1396
+				$success = 0;
1397
+			}
1398
+		}
1399
+		$action_desc = 'deleted';
1400
+		$query_args = array(
1401
+			'action' => 'ticket_list_table',
1402
+			'status' => 'trashed',
1403
+		);
1404
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1405
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1406
+			array(array('TKT_is_default' => 1)),
1407
+			'TKT_ID',
1408
+			true
1409
+		)
1410
+		) {
1411
+			$query_args = array();
1412
+		}
1413
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * @param int $TKT_ID
1419
+	 * @return bool|int
1420
+	 * @throws EE_Error
1421
+	 * @throws InvalidArgumentException
1422
+	 * @throws InvalidDataTypeException
1423
+	 * @throws InvalidInterfaceException
1424
+	 * @throws ReflectionException
1425
+	 */
1426
+	protected function _delete_the_ticket($TKT_ID)
1427
+	{
1428
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1429
+		$tkt->_remove_relations('Datetime');
1430
+		// delete all related prices first
1431
+		$tkt->delete_related_permanently('Price');
1432
+		return $tkt->delete_permanently();
1433
+	}
1434 1434
 }
Please login to merge, or discard this patch.
core/admin/EE_Help_Tour.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
      *
97 97
      * @access public
98 98
      * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
-     * @return void
99
+     * @return EE_Help_Tour
100 100
      */
101 101
     public function __construct($caf = false)
102 102
     {
Please login to merge, or discard this patch.
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -15,268 +15,268 @@
 block discarded – undo
15 15
 abstract class EE_Help_Tour extends EE_Base
16 16
 {
17 17
 
18
-    /**
19
-     * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the
20
-     * constructor of the child class.
21
-     *
22
-     * @access protected
23
-     * @var string
24
-     */
25
-    protected $_label = '';
26
-
27
-
28
-    /**
29
-     * This is the slug for the tour.  It should be unique from all tours and is used for starting a tour and setting
30
-     * cookies for the tour. Set this in the constructor of the child class.
31
-     *
32
-     * @access protected
33
-     * @var string
34
-     */
35
-    protected $_slug = '';
36
-
37
-
38
-    /**
39
-     * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for
40
-     * setting up a tour on a given page. format for array is: array(
41
-     *        0 => array(
42
-     *            'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take
43
-     *            precendence even if you also set class.
44
-     *            'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use
45
-     *            this param. The first element for that class is the anchor. If the class or the id are empty then the
46
-     *            stop will be a modal on the page anchored to the main body.
47
-     *            'custom_class' => 'some_custom_class', //optional custom class to add for this stop.
48
-     *            'button_text' => 'custom text for button', //optional
49
-     *            'content' => 'The content for the stop', //required
50
-     *            'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get
51
-     *            added to the pauseAfter global option array setup for the joyride instance. This is only applicable
52
-     *            when this tour has been set to run on timer.
53
-     *            'options' => array(
54
-     *                //override any of the global options set via the help_tour "option_callback" for the joyride
55
-     *                instance on this specific stop.
56
-     *                )
57
-     *            )
58
-     *        );
59
-     *
60
-     * @access protected
61
-     * @var array
62
-     */
63
-    protected $_stops = array();
64
-
65
-
66
-    /**
67
-     * This contains any stop specific options for the tour.
68
-     * defaults are set but child classes can override.
69
-     *
70
-     * @access protected
71
-     * @var array
72
-     */
73
-    protected $_options = array();
74
-
75
-
76
-    /**
77
-     * holds anything found in the $_REQUEST object (however we override any _gets with _post data).
78
-     *
79
-     * @access protected
80
-     * @var array
81
-     */
82
-    protected $_req_data = array();
83
-
84
-
85
-    /**
86
-     * a flag that is set on init for whether this help_tour is happening on a caf install or not.
87
-     *
88
-     * @var boolean
89
-     */
90
-    protected $_is_caf = false;
91
-
92
-
93
-    /**
94
-     * _constructor
95
-     * initialized the tour object and sets up important properties required to setup the tour.
96
-     *
97
-     * @access public
98
-     * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
-     * @return void
100
-     */
101
-    public function __construct($caf = false)
102
-    {
103
-        $this->_is_caf = $caf;
104
-        $this->_req_data = array_merge($_GET, $_POST);
105
-        $this->_set_tour_properties();
106
-        $this->_set_tour_stops();
107
-        $this->_set_tour_options();
108
-
109
-        // make sure the last tour stop has "end tour" for its button
110
-        $end = array_pop($this->_stops);
111
-        $end['button_text'] = __('End Tour', 'event_espresso');
112
-        // add back to stops
113
-        $this->_stops[] = $end;
114
-    }
115
-
116
-
117
-    /**
118
-     * required method that has the sole purpose of setting up the tour $_label and $_slug properties
119
-     *
120
-     * @abstract
121
-     * @access protected
122
-     * @return void
123
-     */
124
-    abstract protected function _set_tour_properties();
125
-
126
-
127
-    /**
128
-     * required method that's sole purpose is to setup the $_stops property
129
-     *
130
-     * @abstract
131
-     * @access protected
132
-     * @return void
133
-     */
134
-    abstract protected function _set_tour_stops();
135
-
136
-
137
-    /**
138
-     * The method can optionally be overridden by child classes to set the _options array if there are any default
139
-     * options the child wishes to override for a this tour. See property definition for more info
140
-     *
141
-     * @access protected
142
-     * @return void
143
-     */
144
-    protected function _set_tour_options($options = array())
145
-    {
146
-        $defaults = array(
147
-            'tipLocation'           => 'bottom',
148
-            // 'top', 'bottom', 'right', 'left' in relation to parent
149
-            'nubPosition'           => 'auto',
150
-            // override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left"
151
-            'tipAdjustmentY'        => 0,
152
-            // allow for adjustment of tip
153
-            'tipAdjustmentX'        => 0,
154
-            // allow for adjustment of tip
155
-            'scroll'                => true,
156
-            // whether to scrollTo the next step or not
157
-            'scrollSpeed'           => 300,
158
-            // Page scrolling speed in ms
159
-            'timer'                 => 0,
160
-            // 0 = off, all other numbers = time(ms)
161
-            'autoStart'             => true,
162
-            // true or false - false tour starts when restart called
163
-            'startTimerOnClick'     => true,
164
-            // true/false to start timer on first click
165
-            'nextButton'            => true,
166
-            // true/false for next button visibility
167
-            'button_text'           => __('Next', 'event_espresso'),
168
-            'tipAnimation'          => 'fade',
169
-            // 'pop' or 'fade' in each tip
170
-            'pauseAfter'            => array(),
171
-            // array of indexes where to pause the tour after
172
-            'tipAnimationFadeSpeed' => 300,
173
-            // if 'fade'- speed in ms of transition
174
-            'cookieMonster'         => true,
175
-            // true/false for whether cookies are used
176
-            'cookieName'            => $this->get_slug(),
177
-            // choose your own cookie name (setup will add the prefix for the specific page joyride)
178
-            'cookieDomain'          => false,
179
-            // set to false or yoursite.com
180
-            // 'tipContainer' => 'body',            // Where the tip be attached if not inline
181
-            'modal'                 => false,
182
-            // Whether to cover page with modal during the tour
183
-            'expose'                => false,
184
-            // Whether to expose the elements at each step in the tour (requires modal:true),
185
-            'postExposeCallback'    => 'EEHelpTour.postExposeCallback',
186
-            // A method to call after an element has been exposed
187
-            'preRideCallback'       => 'EEHelpTour_preRideCallback',
188
-            // A method to call before the tour starts (passed index, tip, and cloned exposed element)
189
-            'postRideCallback'      => 'EEHelpTour_postRideCallback',
190
-            // a method to call once the tour closes.  This will correspond to the name of a js method that will have to be defined in loaded js.
191
-            'preStepCallback'       => 'EEHelpTour_preStepCallback',
192
-            // A method to call before each step
193
-            'postStepCallback'      => 'EEHelpTour_postStepCallback',
194
-            // A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/
195
-        );
196
-
197
-        $options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults;
198
-        $this->_options = $options;
199
-    }
200
-
201
-
202
-    /**
203
-     * getter functions to return all the properties for the tour.
204
-     */
205
-
206
-
207
-    /**
208
-     * get_slug
209
-     *
210
-     * @return string slug for the tour
211
-     */
212
-    public function get_slug()
213
-    {
214
-        if (empty($this->_slug)) {
215
-            throw new EE_Error(
216
-                sprintf(
217
-                    __(
218
-                        'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor',
219
-                        'event_espresso'
220
-                    ),
221
-                    get_class($this)
222
-                )
223
-            );
224
-        }
225
-        return $this->_slug;
226
-    }
227
-
228
-
229
-    /**
230
-     * get_label
231
-     *
232
-     * @return string
233
-     */
234
-    public function get_label()
235
-    {
236
-        if (empty($this->_label)) {
237
-            throw new EE_Error(
238
-                sprintf(
239
-                    __(
240
-                        'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor',
241
-                        'event_espresso'
242
-                    ),
243
-                    get_class($this)
244
-                )
245
-            );
246
-        }
247
-        return $this->_label;
248
-    }
249
-
250
-
251
-    /**
252
-     * get_stops
253
-     *
254
-     * @return array
255
-     */
256
-    public function get_stops()
257
-    {
258
-        foreach ($this->_stops as $ind => $stop) {
259
-            if (! isset($stop['button_text'])) {
260
-                $this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
261
-            }
262
-        }
263
-        return $this->_stops;
264
-    }
265
-
266
-
267
-    /**
268
-     * get options
269
-     *
270
-     * @return array
271
-     */
272
-    public function get_options()
273
-    {
274
-        // let's make sure there are not pauses set
275
-        foreach ($this->_stops as $ind => $stop) {
276
-            if (isset($stop['pause_after']) && $stop['pause_after']) {
277
-                $this->_options['pauseAfter'][] = $ind;
278
-            }
279
-        }
280
-        return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
281
-    }
18
+	/**
19
+	 * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the
20
+	 * constructor of the child class.
21
+	 *
22
+	 * @access protected
23
+	 * @var string
24
+	 */
25
+	protected $_label = '';
26
+
27
+
28
+	/**
29
+	 * This is the slug for the tour.  It should be unique from all tours and is used for starting a tour and setting
30
+	 * cookies for the tour. Set this in the constructor of the child class.
31
+	 *
32
+	 * @access protected
33
+	 * @var string
34
+	 */
35
+	protected $_slug = '';
36
+
37
+
38
+	/**
39
+	 * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for
40
+	 * setting up a tour on a given page. format for array is: array(
41
+	 *        0 => array(
42
+	 *            'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take
43
+	 *            precendence even if you also set class.
44
+	 *            'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use
45
+	 *            this param. The first element for that class is the anchor. If the class or the id are empty then the
46
+	 *            stop will be a modal on the page anchored to the main body.
47
+	 *            'custom_class' => 'some_custom_class', //optional custom class to add for this stop.
48
+	 *            'button_text' => 'custom text for button', //optional
49
+	 *            'content' => 'The content for the stop', //required
50
+	 *            'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get
51
+	 *            added to the pauseAfter global option array setup for the joyride instance. This is only applicable
52
+	 *            when this tour has been set to run on timer.
53
+	 *            'options' => array(
54
+	 *                //override any of the global options set via the help_tour "option_callback" for the joyride
55
+	 *                instance on this specific stop.
56
+	 *                )
57
+	 *            )
58
+	 *        );
59
+	 *
60
+	 * @access protected
61
+	 * @var array
62
+	 */
63
+	protected $_stops = array();
64
+
65
+
66
+	/**
67
+	 * This contains any stop specific options for the tour.
68
+	 * defaults are set but child classes can override.
69
+	 *
70
+	 * @access protected
71
+	 * @var array
72
+	 */
73
+	protected $_options = array();
74
+
75
+
76
+	/**
77
+	 * holds anything found in the $_REQUEST object (however we override any _gets with _post data).
78
+	 *
79
+	 * @access protected
80
+	 * @var array
81
+	 */
82
+	protected $_req_data = array();
83
+
84
+
85
+	/**
86
+	 * a flag that is set on init for whether this help_tour is happening on a caf install or not.
87
+	 *
88
+	 * @var boolean
89
+	 */
90
+	protected $_is_caf = false;
91
+
92
+
93
+	/**
94
+	 * _constructor
95
+	 * initialized the tour object and sets up important properties required to setup the tour.
96
+	 *
97
+	 * @access public
98
+	 * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
+	 * @return void
100
+	 */
101
+	public function __construct($caf = false)
102
+	{
103
+		$this->_is_caf = $caf;
104
+		$this->_req_data = array_merge($_GET, $_POST);
105
+		$this->_set_tour_properties();
106
+		$this->_set_tour_stops();
107
+		$this->_set_tour_options();
108
+
109
+		// make sure the last tour stop has "end tour" for its button
110
+		$end = array_pop($this->_stops);
111
+		$end['button_text'] = __('End Tour', 'event_espresso');
112
+		// add back to stops
113
+		$this->_stops[] = $end;
114
+	}
115
+
116
+
117
+	/**
118
+	 * required method that has the sole purpose of setting up the tour $_label and $_slug properties
119
+	 *
120
+	 * @abstract
121
+	 * @access protected
122
+	 * @return void
123
+	 */
124
+	abstract protected function _set_tour_properties();
125
+
126
+
127
+	/**
128
+	 * required method that's sole purpose is to setup the $_stops property
129
+	 *
130
+	 * @abstract
131
+	 * @access protected
132
+	 * @return void
133
+	 */
134
+	abstract protected function _set_tour_stops();
135
+
136
+
137
+	/**
138
+	 * The method can optionally be overridden by child classes to set the _options array if there are any default
139
+	 * options the child wishes to override for a this tour. See property definition for more info
140
+	 *
141
+	 * @access protected
142
+	 * @return void
143
+	 */
144
+	protected function _set_tour_options($options = array())
145
+	{
146
+		$defaults = array(
147
+			'tipLocation'           => 'bottom',
148
+			// 'top', 'bottom', 'right', 'left' in relation to parent
149
+			'nubPosition'           => 'auto',
150
+			// override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left"
151
+			'tipAdjustmentY'        => 0,
152
+			// allow for adjustment of tip
153
+			'tipAdjustmentX'        => 0,
154
+			// allow for adjustment of tip
155
+			'scroll'                => true,
156
+			// whether to scrollTo the next step or not
157
+			'scrollSpeed'           => 300,
158
+			// Page scrolling speed in ms
159
+			'timer'                 => 0,
160
+			// 0 = off, all other numbers = time(ms)
161
+			'autoStart'             => true,
162
+			// true or false - false tour starts when restart called
163
+			'startTimerOnClick'     => true,
164
+			// true/false to start timer on first click
165
+			'nextButton'            => true,
166
+			// true/false for next button visibility
167
+			'button_text'           => __('Next', 'event_espresso'),
168
+			'tipAnimation'          => 'fade',
169
+			// 'pop' or 'fade' in each tip
170
+			'pauseAfter'            => array(),
171
+			// array of indexes where to pause the tour after
172
+			'tipAnimationFadeSpeed' => 300,
173
+			// if 'fade'- speed in ms of transition
174
+			'cookieMonster'         => true,
175
+			// true/false for whether cookies are used
176
+			'cookieName'            => $this->get_slug(),
177
+			// choose your own cookie name (setup will add the prefix for the specific page joyride)
178
+			'cookieDomain'          => false,
179
+			// set to false or yoursite.com
180
+			// 'tipContainer' => 'body',            // Where the tip be attached if not inline
181
+			'modal'                 => false,
182
+			// Whether to cover page with modal during the tour
183
+			'expose'                => false,
184
+			// Whether to expose the elements at each step in the tour (requires modal:true),
185
+			'postExposeCallback'    => 'EEHelpTour.postExposeCallback',
186
+			// A method to call after an element has been exposed
187
+			'preRideCallback'       => 'EEHelpTour_preRideCallback',
188
+			// A method to call before the tour starts (passed index, tip, and cloned exposed element)
189
+			'postRideCallback'      => 'EEHelpTour_postRideCallback',
190
+			// a method to call once the tour closes.  This will correspond to the name of a js method that will have to be defined in loaded js.
191
+			'preStepCallback'       => 'EEHelpTour_preStepCallback',
192
+			// A method to call before each step
193
+			'postStepCallback'      => 'EEHelpTour_postStepCallback',
194
+			// A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/
195
+		);
196
+
197
+		$options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults;
198
+		$this->_options = $options;
199
+	}
200
+
201
+
202
+	/**
203
+	 * getter functions to return all the properties for the tour.
204
+	 */
205
+
206
+
207
+	/**
208
+	 * get_slug
209
+	 *
210
+	 * @return string slug for the tour
211
+	 */
212
+	public function get_slug()
213
+	{
214
+		if (empty($this->_slug)) {
215
+			throw new EE_Error(
216
+				sprintf(
217
+					__(
218
+						'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor',
219
+						'event_espresso'
220
+					),
221
+					get_class($this)
222
+				)
223
+			);
224
+		}
225
+		return $this->_slug;
226
+	}
227
+
228
+
229
+	/**
230
+	 * get_label
231
+	 *
232
+	 * @return string
233
+	 */
234
+	public function get_label()
235
+	{
236
+		if (empty($this->_label)) {
237
+			throw new EE_Error(
238
+				sprintf(
239
+					__(
240
+						'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor',
241
+						'event_espresso'
242
+					),
243
+					get_class($this)
244
+				)
245
+			);
246
+		}
247
+		return $this->_label;
248
+	}
249
+
250
+
251
+	/**
252
+	 * get_stops
253
+	 *
254
+	 * @return array
255
+	 */
256
+	public function get_stops()
257
+	{
258
+		foreach ($this->_stops as $ind => $stop) {
259
+			if (! isset($stop['button_text'])) {
260
+				$this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
261
+			}
262
+		}
263
+		return $this->_stops;
264
+	}
265
+
266
+
267
+	/**
268
+	 * get options
269
+	 *
270
+	 * @return array
271
+	 */
272
+	public function get_options()
273
+	{
274
+		// let's make sure there are not pauses set
275
+		foreach ($this->_stops as $ind => $stop) {
276
+			if (isset($stop['pause_after']) && $stop['pause_after']) {
277
+				$this->_options['pauseAfter'][] = $ind;
278
+			}
279
+		}
280
+		return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
     public function get_stops()
257 257
     {
258 258
         foreach ($this->_stops as $ind => $stop) {
259
-            if (! isset($stop['button_text'])) {
260
-                $this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
259
+            if ( ! isset($stop['button_text'])) {
260
+                $this->_stops[$ind]['button_text'] = $this->_options['button_text'];
261 261
             }
262 262
         }
263 263
         return $this->_stops;
@@ -277,6 +277,6 @@  discard block
 block discarded – undo
277 277
                 $this->_options['pauseAfter'][] = $ind;
278 278
             }
279 279
         }
280
-        return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
280
+        return apply_filters('FHEE__'.get_class($this).'__get_options', $this->_options, $this);
281 281
     }
282 282
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_answers.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,6 @@
 block discarded – undo
62 62
     /**
63 63
      * Creates a 4.1 price base type
64 64
      * @global type $wpdb
65
-     * @param array $old_price
66 65
      * @param int $new_reg_id
67 66
      * @return int
68 67
      */
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
         // join to attendee and then join to events table
43 43
         $this->select_expression = 'ans.*, e.event_status';
44 44
         $this->_extra_where_sql = ' AS ans 
45
-            INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id
46
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id 
45
+            INNER JOIN ' . $wpdb->prefix.'events_attendee AS att ON ans.attendee_id = att.id
46
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id = e.id 
47 47
             WHERE e.event_status !="D"';
48 48
         $this->_new_answer_table = $wpdb->prefix."esp_answer";
49 49
         $this->_new_question_table = $wpdb->prefix."esp_question";
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         $old_attendee_table = $wpdb->prefix."events_attendee";
57 57
         $new_reg_table = $wpdb->prefix."esp_registration";
58 58
         $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
-        if (! $regs) {
59
+        if ( ! $regs) {
60 60
             $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61 61
             return false;
62 62
         }
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
             'ANS_value'=>$ans_value
91 91
         );
92 92
         $datatypes = array(
93
-            '%d',// REG_ID
94
-            '%d',// QST_ID
95
-            '%s',// ANS_value
93
+            '%d', // REG_ID
94
+            '%d', // QST_ID
95
+            '%s', // ANS_value
96 96
         );
97 97
         $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
98
-        if (! $success) {
98
+        if ( ! $success) {
99 99
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
100 100
             return 0;
101 101
         }
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -32,102 +32,102 @@
 block discarded – undo
32 32
 
33 33
 class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table
34 34
 {
35
-    private $_new_answer_table;
36
-    private $_new_question_table;
37
-    public function __construct()
38
-    {
39
-        global $wpdb;
40
-        $this->_pretty_name = __("Answers", "event_espresso");
41
-        $this->_old_table = $wpdb->prefix."events_answer";
42
-        // join to attendee and then join to events table
43
-        $this->select_expression = 'ans.*, e.event_status';
44
-        $this->_extra_where_sql = ' AS ans 
35
+	private $_new_answer_table;
36
+	private $_new_question_table;
37
+	public function __construct()
38
+	{
39
+		global $wpdb;
40
+		$this->_pretty_name = __("Answers", "event_espresso");
41
+		$this->_old_table = $wpdb->prefix."events_answer";
42
+		// join to attendee and then join to events table
43
+		$this->select_expression = 'ans.*, e.event_status';
44
+		$this->_extra_where_sql = ' AS ans 
45 45
             INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id
46 46
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id 
47 47
             WHERE e.event_status !="D"';
48
-        $this->_new_answer_table = $wpdb->prefix."esp_answer";
49
-        $this->_new_question_table = $wpdb->prefix."esp_question";
50
-        parent::__construct();
51
-    }
52
-    protected function _migrate_old_row($old_row)
53
-    {
54
-        // get the new REGs for the old answer
55
-        global $wpdb;
56
-        $old_attendee_table = $wpdb->prefix."events_attendee";
57
-        $new_reg_table = $wpdb->prefix."esp_registration";
58
-        $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
-        if (! $regs) {
60
-            $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61
-            return false;
62
-        }
63
-        // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
64
-        foreach ($regs as $new_reg_id) {
65
-            $this->_insert_new_answer($old_row, $new_reg_id);
66
-        }
67
-    }
68
-    /**
69
-     * Creates a 4.1 price base type
70
-     * @global type $wpdb
71
-     * @param array $old_price
72
-     * @param int $new_reg_id
73
-     * @return int
74
-     */
75
-    private function _insert_new_answer($old_answer, $new_reg_id)
76
-    {
77
-        global $wpdb;
78
-        $old_question_table = $wpdb->prefix."events_question";
79
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
48
+		$this->_new_answer_table = $wpdb->prefix."esp_answer";
49
+		$this->_new_question_table = $wpdb->prefix."esp_question";
50
+		parent::__construct();
51
+	}
52
+	protected function _migrate_old_row($old_row)
53
+	{
54
+		// get the new REGs for the old answer
55
+		global $wpdb;
56
+		$old_attendee_table = $wpdb->prefix."events_attendee";
57
+		$new_reg_table = $wpdb->prefix."esp_registration";
58
+		$regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
+		if (! $regs) {
60
+			$this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61
+			return false;
62
+		}
63
+		// as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
64
+		foreach ($regs as $new_reg_id) {
65
+			$this->_insert_new_answer($old_row, $new_reg_id);
66
+		}
67
+	}
68
+	/**
69
+	 * Creates a 4.1 price base type
70
+	 * @global type $wpdb
71
+	 * @param array $old_price
72
+	 * @param int $new_reg_id
73
+	 * @return int
74
+	 */
75
+	private function _insert_new_answer($old_answer, $new_reg_id)
76
+	{
77
+		global $wpdb;
78
+		$old_question_table = $wpdb->prefix."events_question";
79
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
80 80
 
81
-        $question_row = $this->_get_question_type_and_system($new_question_id);
82
-        if ($question_row['QST_system']) {
83
-            // It's an answer to a system question? EE3 used to store that on both the attendee and the answers column,
84
-            // but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom
85
-            // questions.
86
-            return 0;
87
-        }
88
-        if (in_array($question_row['QST_type'], array('MULTIPLE'))) {
89
-            $ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
90
-        } else {
91
-            $ans_value = stripslashes($old_answer['answer']);
92
-        }
93
-        $cols_n_values = array(
94
-            'REG_ID'=>$new_reg_id,
95
-            'QST_ID'=>$new_question_id,
96
-            'ANS_value'=>$ans_value
97
-        );
98
-        $datatypes = array(
99
-            '%d',// REG_ID
100
-            '%d',// QST_ID
101
-            '%s',// ANS_value
102
-        );
103
-        $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
-        if (! $success) {
105
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
106
-            return 0;
107
-        }
108
-        $new_id = $wpdb->insert_id;
109
-        return $new_id;
110
-    }
81
+		$question_row = $this->_get_question_type_and_system($new_question_id);
82
+		if ($question_row['QST_system']) {
83
+			// It's an answer to a system question? EE3 used to store that on both the attendee and the answers column,
84
+			// but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom
85
+			// questions.
86
+			return 0;
87
+		}
88
+		if (in_array($question_row['QST_type'], array('MULTIPLE'))) {
89
+			$ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
90
+		} else {
91
+			$ans_value = stripslashes($old_answer['answer']);
92
+		}
93
+		$cols_n_values = array(
94
+			'REG_ID'=>$new_reg_id,
95
+			'QST_ID'=>$new_question_id,
96
+			'ANS_value'=>$ans_value
97
+		);
98
+		$datatypes = array(
99
+			'%d',// REG_ID
100
+			'%d',// QST_ID
101
+			'%s',// ANS_value
102
+		);
103
+		$success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
+		if (! $success) {
105
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
106
+			return 0;
107
+		}
108
+		$new_id = $wpdb->insert_id;
109
+		return $new_id;
110
+	}
111 111
 
112
-    /**
113
-     * Gets the question's type
114
-     * @global type $wpdb
115
-     * @param type $question_id
116
-     * @return array {
117
-     *  @type string $QST_type
118
-     *  @type string $QST_system
119
-     * }
120
-     */
121
-    private function _get_question_type_and_system($question_id)
122
-    {
123
-        global $wpdb;
124
-        $row = $wpdb->get_row(
125
-            $wpdb->prepare(
126
-                "SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1",
127
-                $question_id
128
-            ),
129
-            ARRAY_A
130
-        );
131
-        return $row;
132
-    }
112
+	/**
113
+	 * Gets the question's type
114
+	 * @global type $wpdb
115
+	 * @param type $question_id
116
+	 * @return array {
117
+	 *  @type string $QST_type
118
+	 *  @type string $QST_system
119
+	 * }
120
+	 */
121
+	private function _get_question_type_and_system($question_id)
122
+	{
123
+		global $wpdb;
124
+		$row = $wpdb->get_row(
125
+			$wpdb->prepare(
126
+				"SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1",
127
+				$question_id
128
+			),
129
+			ARRAY_A
130
+		);
131
+		return $row;
132
+	}
133 133
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_checkins.dmsstage.php 3 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * (because we know the attendee was for an event as a specific time, and we know
86 86
      * the event's OLD ID...)
87 87
      * @global type $wpdb
88
-     * @param array $old_attendee_row
88
+     * @param array $old_attendee
89 89
      * @return array row of datetime from DB
90 90
      */
91 91
     private function _try_to_find_datetime($old_attendee)
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
     /**
122 122
      * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
123 123
      * @param int $new_reg_id
124
-     * @param int $new_datetime_id
125
-     * @param string $timestamp mysql datetime
124
+     * @param int $new_datetime
126 125
      * @return int new Check-in id
127 126
      */
128 127
     private function _insert_checkin_record($new_reg_id, $new_datetime)
Please login to merge, or discard this patch.
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -26,160 +26,160 @@
 block discarded – undo
26 26
 
27 27
 class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table
28 28
 {
29
-    private $_new_table;
30
-    public function __construct()
31
-    {
32
-        global $wpdb;
33
-        $this->_pretty_name = esc_html__('Checkins', 'event_espresso');
34
-        $this->_old_table = $wpdb->prefix."events_attendee";
35
-        $this->select_expression = 'att.*, e.event_status';
36
-        $this->_extra_where_sql = 'AS att
29
+	private $_new_table;
30
+	public function __construct()
31
+	{
32
+		global $wpdb;
33
+		$this->_pretty_name = esc_html__('Checkins', 'event_espresso');
34
+		$this->_old_table = $wpdb->prefix."events_attendee";
35
+		$this->select_expression = 'att.*, e.event_status';
36
+		$this->_extra_where_sql = 'AS att
37 37
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
38 38
             WHERE e.event_status!="D"';
39
-        $this->_new_table = $wpdb->prefix."esp_checkin";
40
-        parent::__construct();
41
-    }
42
-    protected function _migrate_old_row($old_row)
43
-    {
44
-        global $wpdb;
45
-        $new_reg_table = $wpdb->prefix."esp_registration";
39
+		$this->_new_table = $wpdb->prefix."esp_checkin";
40
+		parent::__construct();
41
+	}
42
+	protected function _migrate_old_row($old_row)
43
+	{
44
+		global $wpdb;
45
+		$new_reg_table = $wpdb->prefix."esp_registration";
46 46
 
47
-        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
47
+		$num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
48 48
 
49
-        $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
50
-        if (! $new_registrations_for_attendee) {
51
-            $new_registrations_for_attendee = array();
52
-        }
53
-        $new_datetime = $this->_try_to_find_datetime($old_row);
49
+		$new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
50
+		if (! $new_registrations_for_attendee) {
51
+			$new_registrations_for_attendee = array();
52
+		}
53
+		$new_datetime = $this->_try_to_find_datetime($old_row);
54 54
 
55
-        // make sure registrations array is numerically indexed starting at 0 (it probably already is)
56
-        $new_registrations_for_attendee = array_values($new_registrations_for_attendee);
57
-        $new_checkin_ids = array();
58
-        for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
59
-            $new_reg_id = $new_registrations_for_attendee[ $i ];
60
-            if (! $new_reg_id) {
61
-                $this->add_error(sprintf(
62
-                    esc_html__(
63
-                        /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in
55
+		// make sure registrations array is numerically indexed starting at 0 (it probably already is)
56
+		$new_registrations_for_attendee = array_values($new_registrations_for_attendee);
57
+		$new_checkin_ids = array();
58
+		for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
59
+			$new_reg_id = $new_registrations_for_attendee[ $i ];
60
+			if (! $new_reg_id) {
61
+				$this->add_error(sprintf(
62
+					esc_html__(
63
+						/* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in
64 64
                         *  %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON
65 65
                         */
66
-                        // @codingStandardsIgnoreStart
67
-                        'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)',
68
-                        // @codingStandardsIgnoreEnd
69
-                        'event_espresso'
70
-                    ),
71
-                    $this->_json_encode($old_row),
72
-                    abs($num_to_checkin_at_this_time),
73
-                    count($new_registrations_for_attendee),
74
-                    $this->_json_encode($new_registrations_for_attendee)
75
-                ));
76
-                break;
77
-            }
78
-            $existing_checkin_record = $wpdb->get_var(
79
-                $wpdb->prepare(
80
-                    "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1",
81
-                    $new_reg_id
82
-                )
83
-            );
84
-            if (! $existing_checkin_record) {
85
-                $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
86
-                if ($new_id) {
87
-                    $new_checkin_ids[]= $new_id;
88
-                }
89
-            }
90
-        }
91
-        if ($new_checkin_ids) {
92
-            $this->get_migration_script()->set_mapping(
93
-                $this->_old_table,
94
-                $old_row['id'],
95
-                $this->_new_table,
96
-                $new_checkin_ids
97
-            );
98
-        }
99
-    }
66
+						// @codingStandardsIgnoreStart
67
+						'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)',
68
+						// @codingStandardsIgnoreEnd
69
+						'event_espresso'
70
+					),
71
+					$this->_json_encode($old_row),
72
+					abs($num_to_checkin_at_this_time),
73
+					count($new_registrations_for_attendee),
74
+					$this->_json_encode($new_registrations_for_attendee)
75
+				));
76
+				break;
77
+			}
78
+			$existing_checkin_record = $wpdb->get_var(
79
+				$wpdb->prepare(
80
+					"SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1",
81
+					$new_reg_id
82
+				)
83
+			);
84
+			if (! $existing_checkin_record) {
85
+				$new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
86
+				if ($new_id) {
87
+					$new_checkin_ids[]= $new_id;
88
+				}
89
+			}
90
+		}
91
+		if ($new_checkin_ids) {
92
+			$this->get_migration_script()->set_mapping(
93
+				$this->_old_table,
94
+				$old_row['id'],
95
+				$this->_new_table,
96
+				$new_checkin_ids
97
+			);
98
+		}
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * Tries to find the new datetime the Check-in was for, based on the attendee row
104
-     * (because we know the attendee was for an event as a specific time, and we know
105
-     * the event's OLD ID...)
106
-     * @global type $wpdb
107
-     * @param array $old_attendee_row
108
-     * @return array row of datetime from DB
109
-     */
110
-    private function _try_to_find_datetime($old_attendee)
111
-    {
112
-        global $wpdb;
102
+	/**
103
+	 * Tries to find the new datetime the Check-in was for, based on the attendee row
104
+	 * (because we know the attendee was for an event as a specific time, and we know
105
+	 * the event's OLD ID...)
106
+	 * @global type $wpdb
107
+	 * @param array $old_attendee_row
108
+	 * @return array row of datetime from DB
109
+	 */
110
+	private function _try_to_find_datetime($old_attendee)
111
+	{
112
+		global $wpdb;
113 113
 
114
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
115
-        if (! $new_event_id) {
116
-            $this->add_error(
117
-                sprintf(
118
-                    esc_html__(
119
-                        /* translators: 1: original event ID, 2: original attendee database row */
120
-                        // @codingStandardsIgnoreStart
121
-                        'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in',
122
-                        // @codingStandardsIgnoreEnd
123
-                        'event_espresso'
124
-                    ),
125
-                    $old_attendee['event_id'],
126
-                    $this->_json_encode($old_attendee)
127
-                )
128
-            );
129
-            return 0;
130
-        }
131
-        $old_att_start_date = $old_attendee['start_date'];
132
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
133
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
114
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
115
+		if (! $new_event_id) {
116
+			$this->add_error(
117
+				sprintf(
118
+					esc_html__(
119
+						/* translators: 1: original event ID, 2: original attendee database row */
120
+						// @codingStandardsIgnoreStart
121
+						'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in',
122
+						// @codingStandardsIgnoreEnd
123
+						'event_espresso'
124
+					),
125
+					$old_attendee['event_id'],
126
+					$this->_json_encode($old_attendee)
127
+				)
128
+			);
129
+			return 0;
130
+		}
131
+		$old_att_start_date = $old_attendee['start_date'];
132
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
133
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
134 134
 
135
-        $datetime_table = $wpdb->prefix."esp_datetime";
136
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
137
-        // the most important condition should be last, as it will be array_shift'ed off last
138
-        $conditions = array(
139
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
140
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
141
-        );
142
-        // start running queries, widening search each time by removing a condition
143
-        $datetime_found = null;
144
-        do {
145
-            $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
146
-            $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
147
-            array_shift($conditions);
148
-        } while (! $datetime_found && $conditions);
149
-        return $datetime_found;
150
-    }
135
+		$datetime_table = $wpdb->prefix."esp_datetime";
136
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
137
+		// the most important condition should be last, as it will be array_shift'ed off last
138
+		$conditions = array(
139
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
140
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
141
+		);
142
+		// start running queries, widening search each time by removing a condition
143
+		$datetime_found = null;
144
+		do {
145
+			$full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
146
+			$datetime_found = $wpdb->get_row($full_query, ARRAY_A);
147
+			array_shift($conditions);
148
+		} while (! $datetime_found && $conditions);
149
+		return $datetime_found;
150
+	}
151 151
 
152
-    /**
153
-     * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
154
-     * @param int $new_reg_id
155
-     * @param int $new_datetime_id
156
-     * @param string $timestamp mysql datetime
157
-     * @return int new Check-in id
158
-     */
159
-    private function _insert_checkin_record($new_reg_id, $new_datetime)
160
-    {
161
-        global $wpdb;
152
+	/**
153
+	 * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
154
+	 * @param int $new_reg_id
155
+	 * @param int $new_datetime_id
156
+	 * @param string $timestamp mysql datetime
157
+	 * @return int new Check-in id
158
+	 */
159
+	private function _insert_checkin_record($new_reg_id, $new_datetime)
160
+	{
161
+		global $wpdb;
162 162
 
163 163
 
164
-        // ok we can actually do what we set out to do: add a checkin/checkout record
165
-        $cols_n_values = array(
166
-            'REG_ID'=>$new_reg_id,
167
-            'DTT_ID'=>$new_datetime['DTT_ID'],
168
-            'CHK_in'=>true,
169
-            'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
170
-        );
171
-        $datatypes = array(
172
-            '%d',// REG_ID
173
-            '%d',// DTT_ID
174
-            '%d',// CHK_in
175
-            '%s',// CHK_timestamp
176
-        );
177
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
178
-        if (! $success) {
179
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
180
-            return 0;
181
-        }
182
-        $new_id = $wpdb->insert_id;
183
-        return $new_id;
184
-    }
164
+		// ok we can actually do what we set out to do: add a checkin/checkout record
165
+		$cols_n_values = array(
166
+			'REG_ID'=>$new_reg_id,
167
+			'DTT_ID'=>$new_datetime['DTT_ID'],
168
+			'CHK_in'=>true,
169
+			'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
170
+		);
171
+		$datatypes = array(
172
+			'%d',// REG_ID
173
+			'%d',// DTT_ID
174
+			'%d',// CHK_in
175
+			'%s',// CHK_timestamp
176
+		);
177
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
178
+		if (! $success) {
179
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
180
+			return 0;
181
+		}
182
+		$new_id = $wpdb->insert_id;
183
+		return $new_id;
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         $this->_old_table = $wpdb->prefix."events_attendee";
35 35
         $this->select_expression = 'att.*, e.event_status';
36 36
         $this->_extra_where_sql = 'AS att
37
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
37
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id
38 38
             WHERE e.event_status!="D"';
39 39
         $this->_new_table = $wpdb->prefix."esp_checkin";
40 40
         parent::__construct();
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
         global $wpdb;
45 45
         $new_reg_table = $wpdb->prefix."esp_registration";
46 46
 
47
-        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
47
+        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])));
48 48
 
49 49
         $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
50
-        if (! $new_registrations_for_attendee) {
50
+        if ( ! $new_registrations_for_attendee) {
51 51
             $new_registrations_for_attendee = array();
52 52
         }
53 53
         $new_datetime = $this->_try_to_find_datetime($old_row);
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
         // make sure registrations array is numerically indexed starting at 0 (it probably already is)
56 56
         $new_registrations_for_attendee = array_values($new_registrations_for_attendee);
57 57
         $new_checkin_ids = array();
58
-        for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
59
-            $new_reg_id = $new_registrations_for_attendee[ $i ];
60
-            if (! $new_reg_id) {
58
+        for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) {
59
+            $new_reg_id = $new_registrations_for_attendee[$i];
60
+            if ( ! $new_reg_id) {
61 61
                 $this->add_error(sprintf(
62 62
                     esc_html__(
63 63
                         /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
                     $new_reg_id
82 82
                 )
83 83
             );
84
-            if (! $existing_checkin_record) {
84
+            if ( ! $existing_checkin_record) {
85 85
                 $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
86 86
                 if ($new_id) {
87
-                    $new_checkin_ids[]= $new_id;
87
+                    $new_checkin_ids[] = $new_id;
88 88
                 }
89 89
             }
90 90
         }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         global $wpdb;
113 113
 
114 114
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
115
-        if (! $new_event_id) {
115
+        if ( ! $new_event_id) {
116 116
             $this->add_error(
117 117
                 sprintf(
118 118
                     esc_html__(
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
137 137
         // the most important condition should be last, as it will be array_shift'ed off last
138 138
         $conditions = array(
139
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
140
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
139
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
140
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
141 141
         );
142 142
         // start running queries, widening search each time by removing a condition
143 143
         $datetime_found = null;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
             $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
146 146
             $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
147 147
             array_shift($conditions);
148
-        } while (! $datetime_found && $conditions);
148
+        }while ( ! $datetime_found && $conditions);
149 149
         return $datetime_found;
150 150
     }
151 151
 
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
             'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
170 170
         );
171 171
         $datatypes = array(
172
-            '%d',// REG_ID
173
-            '%d',// DTT_ID
174
-            '%d',// CHK_in
175
-            '%s',// CHK_timestamp
172
+            '%d', // REG_ID
173
+            '%d', // DTT_ID
174
+            '%d', // CHK_in
175
+            '%s', // CHK_timestamp
176 176
         );
177 177
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
178
-        if (! $success) {
178
+        if ( ! $success) {
179 179
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
180 180
             return 0;
181 181
         }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_event_question_group.dmsstage.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -98,6 +98,9 @@
 block discarded – undo
98 98
         $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids);
99 99
     }
100 100
 
101
+    /**
102
+     * @param boolean $primary
103
+     */
101 104
     private function _insert_event_question_group($old_event, $old_question_group_id, $primary)
102 105
     {
103 106
         global $wpdb;
Please login to merge, or discard this patch.
Indentation   +104 added lines, -106 removed lines patch added patch discarded remove patch
@@ -16,15 +16,13 @@  discard block
 block discarded – undo
16 16
             'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees','event_espresso'), false, false)
17 17
         )
18 18
     );
19
-
20
-
21 19
  *
22 20
  */
23 21
 class EE_DMS_4_1_0_event_question_group extends EE_Data_Migration_Script_Stage_Table
24 22
 {
25
-    private $_new_table;
26
-    public function _migrate_old_row($old_row)
27
-    {
23
+	private $_new_table;
24
+	public function _migrate_old_row($old_row)
25
+	{
28 26
 //      $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table);
29 27
 //          if ( ! $txn_id ){
30 28
 //              $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"),$old_row['id'],$this->_json_encode($old_row)));
@@ -34,8 +32,8 @@  discard block
 block discarded – undo
34 32
 //          $new_line_items = $this->_insert_new_line_items($txn,$old_row);
35 33
 //          $this->get_migration_script()->set_mapping($this->_old_table,$old_row['id'],$this->_new_line_table,$new_line_items);
36 34
 
37
-            $this->_insert_new_event_question_groups($old_row);
38
-    }
35
+			$this->_insert_new_event_question_groups($old_row);
36
+	}
39 37
 //  function _migration_step($num_items=50){
40 38
 //      global $wpdb;
41 39
 //      $start_at_record = $this->count_records_migrated();
@@ -55,109 +53,109 @@  discard block
 block discarded – undo
55 53
 //      $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
56 54
 //      return $count;
57 55
 //  }
58
-    public function __construct()
59
-    {
60
-        global $wpdb;
61
-        $this->_old_table = $wpdb->prefix."events_detail";
62
-        $this->_extra_where_sql = 'WHERE event_status!="D"';
63
-        $this->_new_table = $wpdb->prefix."esp_event_question_group";
64
-        $this->_pretty_name = __("Question Groups in each Event", "event_espresso");
65
-        parent::__construct();
66
-    }
56
+	public function __construct()
57
+	{
58
+		global $wpdb;
59
+		$this->_old_table = $wpdb->prefix."events_detail";
60
+		$this->_extra_where_sql = 'WHERE event_status!="D"';
61
+		$this->_new_table = $wpdb->prefix."esp_event_question_group";
62
+		$this->_pretty_name = __("Question Groups in each Event", "event_espresso");
63
+		parent::__construct();
64
+	}
67 65
 
68
-    /**
69
-     * Attempts to insert a new question group inthe new format given an old one
70
-     * @global type $wpdb
71
-     * @param array $old_event
72
-     * @return void
73
-     */
74
-    private function _insert_new_event_question_groups($old_event)
75
-    {
76
-        $new_event_question_group_ids = array();
77
-        $question_groups_for_primary = maybe_unserialize($old_event['question_groups']);
78
-        if (is_array($question_groups_for_primary)) {
79
-            foreach ($question_groups_for_primary as $old_question_group_id) {
80
-                $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true);
81
-                if ($new_id) {
82
-                    $new_event_question_group_ids[] = $new_id;
83
-                }
84
-            }
85
-        }
86
-        $event_meta = maybe_unserialize($old_event['event_meta']);
87
-        if (isset($event_meta['add_attendee_question_groups'])) {
88
-            if (is_array($event_meta['add_attendee_question_groups'])) {
89
-                foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) {
90
-                    $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false);
91
-                    if ($new_id) {
92
-                        $new_event_question_group_ids[] = $new_id;
93
-                    }
94
-                }
95
-            }
96
-        }
66
+	/**
67
+	 * Attempts to insert a new question group inthe new format given an old one
68
+	 * @global type $wpdb
69
+	 * @param array $old_event
70
+	 * @return void
71
+	 */
72
+	private function _insert_new_event_question_groups($old_event)
73
+	{
74
+		$new_event_question_group_ids = array();
75
+		$question_groups_for_primary = maybe_unserialize($old_event['question_groups']);
76
+		if (is_array($question_groups_for_primary)) {
77
+			foreach ($question_groups_for_primary as $old_question_group_id) {
78
+				$new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true);
79
+				if ($new_id) {
80
+					$new_event_question_group_ids[] = $new_id;
81
+				}
82
+			}
83
+		}
84
+		$event_meta = maybe_unserialize($old_event['event_meta']);
85
+		if (isset($event_meta['add_attendee_question_groups'])) {
86
+			if (is_array($event_meta['add_attendee_question_groups'])) {
87
+				foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) {
88
+					$new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false);
89
+					if ($new_id) {
90
+						$new_event_question_group_ids[] = $new_id;
91
+					}
92
+				}
93
+			}
94
+		}
97 95
 
98 96
 
99
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids);
100
-    }
97
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids);
98
+	}
101 99
 
102
-    private function _insert_event_question_group($old_event, $old_question_group_id, $primary)
103
-    {
104
-        global $wpdb;
105
-        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk(
106
-            $wpdb->prefix . "events_qst_group",
107
-            intval($old_question_group_id),
108
-            $wpdb->prefix . "esp_question_group"
109
-        );
100
+	private function _insert_event_question_group($old_event, $old_question_group_id, $primary)
101
+	{
102
+		global $wpdb;
103
+		$new_question_group_id = $this->get_migration_script()->get_mapping_new_pk(
104
+			$wpdb->prefix . "events_qst_group",
105
+			intval($old_question_group_id),
106
+			$wpdb->prefix . "esp_question_group"
107
+		);
110 108
 
111
-        if (! $new_question_group_id) {
112
-            $this->add_error(
113
-                sprintf(
114
-                    // translators: %s question ID, %s event ID
115
-                    __("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"),
116
-                    $old_question_group_id,
117
-                    $old_event['id']
118
-                )
119
-            );
120
-            return 0;
121
-        }
122
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk(
123
-            $wpdb->prefix . "events_detail",
124
-            intval($old_event['id']),
125
-            $wpdb->posts
126
-        );
127
-        if (! $new_question_group_id) {
128
-            $this->add_error(
129
-                sprintf(
130
-                    // translators: %s event ID
131
-                    __("Could not find 4.1 event 3.1 event id #%s", "event_espresso"),
132
-                    $old_event['id']
133
-                )
134
-            );
135
-            return 0;
136
-        }
137
-        $cols_n_values = array(
138
-            'EVT_ID'=>$new_event_id,
139
-            'QSG_ID'=>$new_question_group_id,
140
-            'EQG_primary' => $primary
141
-        );
109
+		if (! $new_question_group_id) {
110
+			$this->add_error(
111
+				sprintf(
112
+					// translators: %s question ID, %s event ID
113
+					__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"),
114
+					$old_question_group_id,
115
+					$old_event['id']
116
+				)
117
+			);
118
+			return 0;
119
+		}
120
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk(
121
+			$wpdb->prefix . "events_detail",
122
+			intval($old_event['id']),
123
+			$wpdb->posts
124
+		);
125
+		if (! $new_question_group_id) {
126
+			$this->add_error(
127
+				sprintf(
128
+					// translators: %s event ID
129
+					__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"),
130
+					$old_event['id']
131
+				)
132
+			);
133
+			return 0;
134
+		}
135
+		$cols_n_values = array(
136
+			'EVT_ID'=>$new_event_id,
137
+			'QSG_ID'=>$new_question_group_id,
138
+			'EQG_primary' => $primary
139
+		);
142 140
 
143
-        $datatypes = array(
144
-            '%d',// EVT_ID
145
-            '%d',// QSG_ID
146
-            '%d',// EQG_primary
147
-        );
148
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
149
-        if (! $success) {
150
-            $this->add_error(
151
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
152
-                    $this->_old_table,
153
-                    $old_event,
154
-                    $this->_new_table,
155
-                    $cols_n_values,
156
-                    $datatypes
157
-                )
158
-            );
159
-            return 0;
160
-        }
161
-        return $wpdb->insert_id;
162
-    }
141
+		$datatypes = array(
142
+			'%d',// EVT_ID
143
+			'%d',// QSG_ID
144
+			'%d',// EQG_primary
145
+		);
146
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
147
+		if (! $success) {
148
+			$this->add_error(
149
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
150
+					$this->_old_table,
151
+					$old_event,
152
+					$this->_new_table,
153
+					$cols_n_values,
154
+					$datatypes
155
+				)
156
+			);
157
+			return 0;
158
+		}
159
+		return $wpdb->insert_id;
160
+	}
163 161
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
     {
104 104
         global $wpdb;
105 105
         $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk(
106
-            $wpdb->prefix . "events_qst_group",
106
+            $wpdb->prefix."events_qst_group",
107 107
             intval($old_question_group_id),
108
-            $wpdb->prefix . "esp_question_group"
108
+            $wpdb->prefix."esp_question_group"
109 109
         );
110 110
 
111
-        if (! $new_question_group_id) {
111
+        if ( ! $new_question_group_id) {
112 112
             $this->add_error(
113 113
                 sprintf(
114 114
                     // translators: %s question ID, %s event ID
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
             return 0;
121 121
         }
122 122
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk(
123
-            $wpdb->prefix . "events_detail",
123
+            $wpdb->prefix."events_detail",
124 124
             intval($old_event['id']),
125 125
             $wpdb->posts
126 126
         );
127
-        if (! $new_question_group_id) {
127
+        if ( ! $new_question_group_id) {
128 128
             $this->add_error(
129 129
                 sprintf(
130 130
                     // translators: %s event ID
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
         );
142 142
 
143 143
         $datatypes = array(
144
-            '%d',// EVT_ID
145
-            '%d',// QSG_ID
146
-            '%d',// EQG_primary
144
+            '%d', // EVT_ID
145
+            '%d', // QSG_ID
146
+            '%d', // EQG_primary
147 147
         );
148 148
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
149
-        if (! $success) {
149
+        if ( ! $success) {
150 150
             $this->add_error(
151 151
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
152 152
                     $this->_old_table,
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_events.dmsstage.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
     /**
428 428
      * @param $old_event
429
-     * @param $new_cpt_id
429
+     * @param integer $new_cpt_id
430 430
      * @return int
431 431
      */
432 432
     private function _insert_event_meta($old_event, $new_cpt_id)
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 
694 694
 
695 695
     /**
696
-     * @param $new_event_id
697
-     * @param $new_venue_id
696
+     * @param integer $new_event_id
697
+     * @param integer $new_venue_id
698 698
      * @return int
699 699
      */
700 700
     private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
Please login to merge, or discard this patch.
Indentation   +634 added lines, -639 removed lines patch added patch discarded remove patch
@@ -84,8 +84,6 @@  discard block
 block discarded – undo
84 84
   KEY `submitted` (`submitted`),
85 85
   KEY `likes` (`likes`)
86 86
 ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$
87
-
88
-
89 87
  *
90 88
  * 4.1 Event model:
91 89
  * $this->_tables = array(
@@ -124,7 +122,6 @@  discard block
 block discarded – undo
124 122
                 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', __("Accept Donations?", "event_espresso"), false, false)
125 123
 
126 124
             ));
127
-
128 125
  *
129 126
  * 3.1's start end table
130 127
  *
@@ -137,8 +134,6 @@  discard block
 block discarded – undo
137 134
   PRIMARY KEY (`id`),
138 135
   KEY `event_id` (`event_id`)
139 136
 ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$
140
-
141
-
142 137
  *
143 138
  * and 4.1 Datetime model's tables and fields:
144 139
  * $this->_tables = array(
@@ -160,172 +155,172 @@  discard block
 block discarded – undo
160 155
  */
161 156
 class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage
162 157
 {
163
-    private $_old_table;
164
-    private $_old_start_end_table;
165
-    private $_new_table;
166
-    private $_new_meta_table;
167
-    private $_new_datetime_table;
168
-
169
-
170
-
171
-    /**
172
-     * Just initializes the status of the migration
173
-     * @throws EE_Error
174
-     */
175
-    public function __construct()
176
-    {
177
-        global $wpdb;
178
-        $this->_old_table = $wpdb->prefix."events_detail";
179
-        $this->_old_start_end_table = $wpdb->prefix."events_start_end";
180
-        $this->_new_table = $wpdb->prefix."posts";
181
-        $this->_new_meta_table = $wpdb->prefix."esp_event_meta";
182
-        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
183
-        $this->_pretty_name = __("Events", "event_espresso");
184
-        parent::__construct();
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * Counts the records to migrate; the public version may cache it
191
-     * @return int
192
-     */
193
-    public function _count_records_to_migrate()
194
-    {
195
-        global $wpdb;
196
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"');
197
-        return intval($count);
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
204
-     * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
205
-     * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
206
-     * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50,
207
-     * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
208
-     * @param int $num_items_to_migrate
209
-     * @return int number of items ACTUALLY migrated
210
-     */
211
-    protected function _migration_step($num_items_to_migrate = 50)
212
-    {
213
-        global $wpdb;
214
-        // because the migration of each event can be a LOT more work, make each step smaller
215
-        $num_items_to_migrate = max(1, $num_items_to_migrate/5);
216
-        $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
217
-        $items_migrated_this_step = 0;
218
-
219
-        foreach ($events as $event_row) {
220
-            $guid = null;
221
-            // insert new 4.1 Attendee object using $wpdb
222
-            $post_id = $this->_insert_cpt($event_row);
223
-            if ($post_id) {
224
-                $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
225
-                $meta_id = $this->_insert_event_meta($event_row, $post_id);
226
-                if ($meta_id) {
227
-                    $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
228
-                }
229
-                $this->_convert_start_end_times($event_row, $post_id);
230
-                $event_meta = maybe_unserialize($event_row['event_meta']);
231
-                $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
232
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
233
-
234
-                // maybe create a venue from info on the event?
235
-                $new_venue_id = $this->_maybe_create_venue($event_row);
236
-                if ($new_venue_id) {
237
-                    $this->_insert_new_venue_to_event($post_id, $new_venue_id);
238
-                }
239
-                $this->_add_post_metas($event_row, $post_id);
240
-            }
241
-            $items_migrated_this_step++;
242
-            if ($guid) {
243
-                // if we had to check for an image attachment
244
-                // then let's call it a day (avoid timing out, because this took a long time)
245
-                break;
246
-            }
247
-        }
248
-        if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
249
-            $this->set_status(EE_Data_Migration_Manager::status_completed);
250
-        }
251
-        return $items_migrated_this_step;
252
-    }
253
-
254
-    /**
255
-     * Stores any extra 3.1 "event_meta" column things as post meta
256
-     * @param array $old_event
257
-     * @param int $post_id
258
-     * @return void
259
-     */
260
-    private function _add_post_metas($old_event, $post_id)
261
-    {
262
-        $event_meta = maybe_unserialize($old_event['event_meta']);
263
-        if (! $event_meta || ! is_array($event_meta)) {
264
-            return;
265
-        }
266
-        unset($event_meta['date_submitted']);// factored into CPT
267
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
268
-        unset($event_meta['default_payment_status']);// dido
269
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
270
-        foreach ($event_meta as $meta_key => $meta_value) {
271
-            if ($meta_key) {// if the meta key is just an empty string, ignore it
272
-                $success = add_post_meta($post_id, $meta_key, $meta_value, true);
273
-                if (! $success) {
274
-                    $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
275
-                }
276
-            }
277
-        }
278
-        if ($old_event['alt_email']) {
279
-            add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
280
-        }
281
-        if ($old_event['recurrence_id']) {
282
-            add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
283
-        }
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * Finds a unique slug for this event, given its name (we could have simply used
290
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
291
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
292
-     * @param string $event_name (the name of the event for reading by humans)
293
-     * @param string $old_identifier the old EE3 identifier (a long unique string)
294
-     * @param string $new_post_status a post status
295
-     * @return string
296
-     */
297
-    private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
298
-    {
299
-        $count = 0;
300
-        $original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
301
-        return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
302
-    }
303
-
304
-    /**
305
-     * returns whether or not there is a post that has this same slug (post_title)
306
-     * @global wpdb $wpdb
307
-     * @param string $slug
308
-     * @return boolean
309
-     */
310
-    private function _other_post_exists_with_that_slug($slug)
311
-    {
312
-        global $wpdb;
313
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
314
-        $count = $wpdb->get_var($query);
315
-        return (boolean) intval($count);
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * @param $old_event
322
-     * @return int
323
-     */
324
-    private function _insert_cpt($old_event)
325
-    {
326
-        global $wpdb;
327
-        // convert 3.1 event status to 4.1 CPT status
328
-        // for reference, 3.1 event stati available for setting are:
158
+	private $_old_table;
159
+	private $_old_start_end_table;
160
+	private $_new_table;
161
+	private $_new_meta_table;
162
+	private $_new_datetime_table;
163
+
164
+
165
+
166
+	/**
167
+	 * Just initializes the status of the migration
168
+	 * @throws EE_Error
169
+	 */
170
+	public function __construct()
171
+	{
172
+		global $wpdb;
173
+		$this->_old_table = $wpdb->prefix."events_detail";
174
+		$this->_old_start_end_table = $wpdb->prefix."events_start_end";
175
+		$this->_new_table = $wpdb->prefix."posts";
176
+		$this->_new_meta_table = $wpdb->prefix."esp_event_meta";
177
+		$this->_new_datetime_table = $wpdb->prefix."esp_datetime";
178
+		$this->_pretty_name = __("Events", "event_espresso");
179
+		parent::__construct();
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * Counts the records to migrate; the public version may cache it
186
+	 * @return int
187
+	 */
188
+	public function _count_records_to_migrate()
189
+	{
190
+		global $wpdb;
191
+		$count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"');
192
+		return intval($count);
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
199
+	 * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
200
+	 * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
201
+	 * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50,
202
+	 * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
203
+	 * @param int $num_items_to_migrate
204
+	 * @return int number of items ACTUALLY migrated
205
+	 */
206
+	protected function _migration_step($num_items_to_migrate = 50)
207
+	{
208
+		global $wpdb;
209
+		// because the migration of each event can be a LOT more work, make each step smaller
210
+		$num_items_to_migrate = max(1, $num_items_to_migrate/5);
211
+		$events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
212
+		$items_migrated_this_step = 0;
213
+
214
+		foreach ($events as $event_row) {
215
+			$guid = null;
216
+			// insert new 4.1 Attendee object using $wpdb
217
+			$post_id = $this->_insert_cpt($event_row);
218
+			if ($post_id) {
219
+				$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
220
+				$meta_id = $this->_insert_event_meta($event_row, $post_id);
221
+				if ($meta_id) {
222
+					$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
223
+				}
224
+				$this->_convert_start_end_times($event_row, $post_id);
225
+				$event_meta = maybe_unserialize($event_row['event_meta']);
226
+				$guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
227
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
228
+
229
+				// maybe create a venue from info on the event?
230
+				$new_venue_id = $this->_maybe_create_venue($event_row);
231
+				if ($new_venue_id) {
232
+					$this->_insert_new_venue_to_event($post_id, $new_venue_id);
233
+				}
234
+				$this->_add_post_metas($event_row, $post_id);
235
+			}
236
+			$items_migrated_this_step++;
237
+			if ($guid) {
238
+				// if we had to check for an image attachment
239
+				// then let's call it a day (avoid timing out, because this took a long time)
240
+				break;
241
+			}
242
+		}
243
+		if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
244
+			$this->set_status(EE_Data_Migration_Manager::status_completed);
245
+		}
246
+		return $items_migrated_this_step;
247
+	}
248
+
249
+	/**
250
+	 * Stores any extra 3.1 "event_meta" column things as post meta
251
+	 * @param array $old_event
252
+	 * @param int $post_id
253
+	 * @return void
254
+	 */
255
+	private function _add_post_metas($old_event, $post_id)
256
+	{
257
+		$event_meta = maybe_unserialize($old_event['event_meta']);
258
+		if (! $event_meta || ! is_array($event_meta)) {
259
+			return;
260
+		}
261
+		unset($event_meta['date_submitted']);// factored into CPT
262
+		unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
263
+		unset($event_meta['default_payment_status']);// dido
264
+		unset($event_meta['event_thumbnail_url']);// used to find post featured image
265
+		foreach ($event_meta as $meta_key => $meta_value) {
266
+			if ($meta_key) {// if the meta key is just an empty string, ignore it
267
+				$success = add_post_meta($post_id, $meta_key, $meta_value, true);
268
+				if (! $success) {
269
+					$this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
270
+				}
271
+			}
272
+		}
273
+		if ($old_event['alt_email']) {
274
+			add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
275
+		}
276
+		if ($old_event['recurrence_id']) {
277
+			add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
278
+		}
279
+	}
280
+
281
+
282
+
283
+	/**
284
+	 * Finds a unique slug for this event, given its name (we could have simply used
285
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
286
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
287
+	 * @param string $event_name (the name of the event for reading by humans)
288
+	 * @param string $old_identifier the old EE3 identifier (a long unique string)
289
+	 * @param string $new_post_status a post status
290
+	 * @return string
291
+	 */
292
+	private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
293
+	{
294
+		$count = 0;
295
+		$original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
296
+		return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
297
+	}
298
+
299
+	/**
300
+	 * returns whether or not there is a post that has this same slug (post_title)
301
+	 * @global wpdb $wpdb
302
+	 * @param string $slug
303
+	 * @return boolean
304
+	 */
305
+	private function _other_post_exists_with_that_slug($slug)
306
+	{
307
+		global $wpdb;
308
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
309
+		$count = $wpdb->get_var($query);
310
+		return (boolean) intval($count);
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * @param $old_event
317
+	 * @return int
318
+	 */
319
+	private function _insert_cpt($old_event)
320
+	{
321
+		global $wpdb;
322
+		// convert 3.1 event status to 4.1 CPT status
323
+		// for reference, 3.1 event stati available for setting are:
329 324
 //      $status = array(array('id' => 'A', 'text' => __('Public', 'event_espresso')), array('id' => 'S', 'text' => __('Waitlist', 'event_espresso')), array('id' => 'O', 'text' => __('Ongoing', 'event_espresso')), array('id' => 'R', 'text' => __('Draft', 'event_espresso')), array('id' => 'D', 'text' => __('Deleted', 'event_espresso')));
330 325
 //      and the json api uses the following to convert from 3.1 to 4.0
331 326
 //      'S'=>'secondary/waitlist',
@@ -339,486 +334,486 @@  discard block
 block discarded – undo
339 334
 //      4.1 Event Post stati are the normal post statis
340 335
 //      (publish,future,draft,pending,private,trash,auto-draft,inherit)
341 336
 //      and 3 custom ones: cancelled,postponed,sold_out
342
-        $status_conversions = array(
343
-            'R'=>'draft',
344
-            'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
345
-            'P'=>'pending',
346
-            'IA'=>'draft',// draft and in the past
337
+		$status_conversions = array(
338
+			'R'=>'draft',
339
+			'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
340
+			'P'=>'pending',
341
+			'IA'=>'draft',// draft and in the past
347 342
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
348
-            'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
349
-            'A'=>'publish',
350
-            'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
351
-            'D'=>'trash',
352
-        );
353
-        $post_status = $status_conversions[ $old_event['event_status'] ];
354
-        // check if we've sold out
355
-        if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
356
-            $post_status = 'sold_out';
357
-        }
343
+			'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
344
+			'A'=>'publish',
345
+			'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
346
+			'D'=>'trash',
347
+		);
348
+		$post_status = $status_conversions[ $old_event['event_status'] ];
349
+		// check if we've sold out
350
+		if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
351
+			$post_status = 'sold_out';
352
+		}
358 353
 //      FYI postponed and cancelled don't exist in 3.1
359
-        $cols_n_values = array(
360
-            'post_title'=>stripslashes($old_event['event_name']),// EVT_name
361
-            'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc
362
-            'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
363
-            'post_date'=>$old_event['submitted'],// EVT_created NOT
364
-            'post_date_gmt'=>get_gmt_from_date($old_event['submitted']),
365
-            'post_excerpt'=>'',// EVT_short_desc
366
-            'post_modified'=>$old_event['submitted'],// EVT_modified
367
-            'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']),
368
-            'post_author'=>$old_event['wp_user'],// EVT_wp_user
369
-            'post_parent'=>0,// parent maybe get this from some REM field?
370
-            'menu_order'=>0,// EVT_order
371
-            'post_type'=>'espresso_events',// post_type
372
-            'post_status'=>$post_status,// status
373
-        );
374
-        $cols_n_values_with_no_invalid_text = array();
375
-        foreach ($cols_n_values as $col => $value) {
376
-            $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
377
-            if (! is_wp_error($value_sans_invalid_chars)) {
378
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
379
-            } else {
380
-                // otherwise leave it as-is. It will blow everything up and stop the migration
381
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
382
-            }
383
-        }
384
-        $cols_n_values = $cols_n_values_with_no_invalid_text;
385
-        $datatypes = array(
386
-            '%s',// EVT_name
387
-            '%s',// EVT_desc
388
-            '%s',// EVT_slug
389
-            '%s',// EVT_created
390
-            '%s',
391
-            '%s',// EVT_short_desc
392
-            '%s',// EVT_modified
393
-            '%s',
394
-            '%s',// EVT_wp_user
395
-            '%d',// post_parent
396
-            '%d',// EVT_order
397
-            '%s',// post_type
398
-            '%s',// status
399
-        );
400
-        $success = $wpdb->insert(
401
-            $this->_new_table,
402
-            $cols_n_values,
403
-            $datatypes
404
-        );
405
-        if (! $success) {
406
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
407
-            return 0;
408
-        }
409
-        return $wpdb->insert_id;
410
-    }
411
-
412
-    /**
413
-     * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
414
-     * @global wpdb $wpdb
415
-     * @param int $event_id
416
-     * @return int
417
-     */
418
-    public static function count_registrations($event_id)
419
-    {
420
-        global $wpdb;
421
-        $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
422
-        return intval($count);
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * @param $old_event
429
-     * @param $new_cpt_id
430
-     * @return int
431
-     */
432
-    private function _insert_event_meta($old_event, $new_cpt_id)
433
-    {
434
-        global $wpdb;
435
-        $event_meta = maybe_unserialize($old_event['event_meta']);
354
+		$cols_n_values = array(
355
+			'post_title'=>stripslashes($old_event['event_name']),// EVT_name
356
+			'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc
357
+			'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
358
+			'post_date'=>$old_event['submitted'],// EVT_created NOT
359
+			'post_date_gmt'=>get_gmt_from_date($old_event['submitted']),
360
+			'post_excerpt'=>'',// EVT_short_desc
361
+			'post_modified'=>$old_event['submitted'],// EVT_modified
362
+			'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']),
363
+			'post_author'=>$old_event['wp_user'],// EVT_wp_user
364
+			'post_parent'=>0,// parent maybe get this from some REM field?
365
+			'menu_order'=>0,// EVT_order
366
+			'post_type'=>'espresso_events',// post_type
367
+			'post_status'=>$post_status,// status
368
+		);
369
+		$cols_n_values_with_no_invalid_text = array();
370
+		foreach ($cols_n_values as $col => $value) {
371
+			$value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
372
+			if (! is_wp_error($value_sans_invalid_chars)) {
373
+				$cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
374
+			} else {
375
+				// otherwise leave it as-is. It will blow everything up and stop the migration
376
+				$cols_n_values_with_no_invalid_text[ $col ] = $value;
377
+			}
378
+		}
379
+		$cols_n_values = $cols_n_values_with_no_invalid_text;
380
+		$datatypes = array(
381
+			'%s',// EVT_name
382
+			'%s',// EVT_desc
383
+			'%s',// EVT_slug
384
+			'%s',// EVT_created
385
+			'%s',
386
+			'%s',// EVT_short_desc
387
+			'%s',// EVT_modified
388
+			'%s',
389
+			'%s',// EVT_wp_user
390
+			'%d',// post_parent
391
+			'%d',// EVT_order
392
+			'%s',// post_type
393
+			'%s',// status
394
+		);
395
+		$success = $wpdb->insert(
396
+			$this->_new_table,
397
+			$cols_n_values,
398
+			$datatypes
399
+		);
400
+		if (! $success) {
401
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
402
+			return 0;
403
+		}
404
+		return $wpdb->insert_id;
405
+	}
406
+
407
+	/**
408
+	 * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
409
+	 * @global wpdb $wpdb
410
+	 * @param int $event_id
411
+	 * @return int
412
+	 */
413
+	public static function count_registrations($event_id)
414
+	{
415
+		global $wpdb;
416
+		$count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
417
+		return intval($count);
418
+	}
419
+
420
+
421
+
422
+	/**
423
+	 * @param $old_event
424
+	 * @param $new_cpt_id
425
+	 * @return int
426
+	 */
427
+	private function _insert_event_meta($old_event, $new_cpt_id)
428
+	{
429
+		global $wpdb;
430
+		$event_meta = maybe_unserialize($old_event['event_meta']);
436 431
 //      for reference, 3.1 'default_payment_status' are: $default_payment_status = array(
437 432
 //  array('id' => "", 'text' => 'No Change'),
438 433
 //  array('id' => 'Incomplete', 'text' => 'Incomplete'),
439 434
 //  array('id' => 'Pending', 'text' => 'Pending'),
440 435
 //  //array('id' => 'Completed', 'text' => 'Completed')
441 436
 // );
442
-        $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
443
-        $cols_n_values = array(
444
-            'EVT_ID'=>$new_cpt_id,// EVT_ID_fk
445
-            'EVT_display_desc'=> 'Y' == $old_event['display_desc'],
446
-            'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'],
447
-            'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
448
-            'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
449
-            'EVT_default_registration_status' => $default_reg_status,
450
-            'EVT_member_only'=>$old_event['member_only'],
451
-            'EVT_phone'=> $old_event['phone'],
452
-            'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
453
-            'EVT_timezone_string'=> $old_event['timezone_string'],
454
-            'EVT_external_URL'=>$old_event['externalURL'],
455
-            'EVT_donations'=>false// doesnt exist in 3.1
456
-
457
-        );
458
-        $datatypes = array(
459
-            '%s',// EVT_ID
460
-            '%d',// EVT_display_desc
461
-            '%d',// EVT_display_ticket_selector
462
-            '%s',// EVT_visible_on
463
-            '%d',// EVT_additional_limit
464
-            '%s',// EVT_default_registration_status
465
-            '%d',// EVT_member_only
466
-            '%s',// EVT_phone
467
-            '%d',// EVT_allow_overflow
468
-            '%s',// EVT_timezone_string
469
-            '%s',// EVT_external_URL
470
-            '%d',// EVT_donations
471
-        );
472
-        $success = $wpdb->insert(
473
-            $this->_new_meta_table,
474
-            $cols_n_values,
475
-            $datatypes
476
-        );
477
-        if (! $success) {
478
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
479
-            return 0;
480
-        }
481
-        return $wpdb->insert_id;
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * @param $old_event
488
-     * @return int
489
-     */
490
-    private function _maybe_create_venue($old_event)
491
-    {
492
-        if ($old_event['address'] ||
493
-                $old_event['address2'] ||
494
-                $old_event['city'] ||
495
-                $old_event['state'] ||
496
-                $old_event['zip'] ||
497
-                $old_event['venue_title'] ||
498
-                $old_event['venue_url'] ||
499
-                $old_event['venue_image'] ||
500
-                $old_event['venue_phone'] ||
501
-                $old_event['virtual_url'] ||
502
-                $old_event['virtual_phone']
503
-                ) {
504
-            $old_id = $this->_duplicate_venue_exists($old_event);
505
-            if ($old_id) {
506
-                return $old_id;
507
-            }
508
-            $new_id = $this->_insert_venue_into_posts($old_event);
509
-            if ($new_id) {
510
-                $this->_insert_venue_into_meta_table($new_id, $old_event);
511
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
512
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
513
-            }
514
-            // we don't bother recording the conversion from old events to venues as that
515
-            // will complicate finding the conversion from old venues to new events
516
-            return $new_id;
517
-        } else {
518
-            return 0;
519
-        }
520
-    }
521
-
522
-    /**
523
-     * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
524
-     * If so, return it. Otherwise return NULL.
525
-     * @param array $old_event
526
-     * @return int duplicate venue id
527
-     */
528
-    private function _duplicate_venue_exists($old_event)
529
-    {
530
-        global $wpdb;
531
-        $conditions = array(
532
-            'VNU_address' => $old_event ['address'],
533
-            'VNU_address2' => $old_event['address2'],
534
-            'VNU_city' => $old_event['city'],
535
-            'VNU_zip' => $old_event['zip'],
536
-            'post_title'=> $this->_get_venue_title_for_event($old_event),
537
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
538
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
539
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
540
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
541
-        );
542
-        $sql_conditions = array();
543
-        foreach ($conditions as $column => $value) {
544
-            $sql_conditions [] = $wpdb->prepare("$column = %s", $value);
545
-        }
546
-        $query = "SELECT VNU_ID
437
+		$default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
438
+		$cols_n_values = array(
439
+			'EVT_ID'=>$new_cpt_id,// EVT_ID_fk
440
+			'EVT_display_desc'=> 'Y' == $old_event['display_desc'],
441
+			'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'],
442
+			'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
443
+			'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
444
+			'EVT_default_registration_status' => $default_reg_status,
445
+			'EVT_member_only'=>$old_event['member_only'],
446
+			'EVT_phone'=> $old_event['phone'],
447
+			'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
448
+			'EVT_timezone_string'=> $old_event['timezone_string'],
449
+			'EVT_external_URL'=>$old_event['externalURL'],
450
+			'EVT_donations'=>false// doesnt exist in 3.1
451
+
452
+		);
453
+		$datatypes = array(
454
+			'%s',// EVT_ID
455
+			'%d',// EVT_display_desc
456
+			'%d',// EVT_display_ticket_selector
457
+			'%s',// EVT_visible_on
458
+			'%d',// EVT_additional_limit
459
+			'%s',// EVT_default_registration_status
460
+			'%d',// EVT_member_only
461
+			'%s',// EVT_phone
462
+			'%d',// EVT_allow_overflow
463
+			'%s',// EVT_timezone_string
464
+			'%s',// EVT_external_URL
465
+			'%d',// EVT_donations
466
+		);
467
+		$success = $wpdb->insert(
468
+			$this->_new_meta_table,
469
+			$cols_n_values,
470
+			$datatypes
471
+		);
472
+		if (! $success) {
473
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
474
+			return 0;
475
+		}
476
+		return $wpdb->insert_id;
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * @param $old_event
483
+	 * @return int
484
+	 */
485
+	private function _maybe_create_venue($old_event)
486
+	{
487
+		if ($old_event['address'] ||
488
+				$old_event['address2'] ||
489
+				$old_event['city'] ||
490
+				$old_event['state'] ||
491
+				$old_event['zip'] ||
492
+				$old_event['venue_title'] ||
493
+				$old_event['venue_url'] ||
494
+				$old_event['venue_image'] ||
495
+				$old_event['venue_phone'] ||
496
+				$old_event['virtual_url'] ||
497
+				$old_event['virtual_phone']
498
+				) {
499
+			$old_id = $this->_duplicate_venue_exists($old_event);
500
+			if ($old_id) {
501
+				return $old_id;
502
+			}
503
+			$new_id = $this->_insert_venue_into_posts($old_event);
504
+			if ($new_id) {
505
+				$this->_insert_venue_into_meta_table($new_id, $old_event);
506
+				$guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
507
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
508
+			}
509
+			// we don't bother recording the conversion from old events to venues as that
510
+			// will complicate finding the conversion from old venues to new events
511
+			return $new_id;
512
+		} else {
513
+			return 0;
514
+		}
515
+	}
516
+
517
+	/**
518
+	 * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
519
+	 * If so, return it. Otherwise return NULL.
520
+	 * @param array $old_event
521
+	 * @return int duplicate venue id
522
+	 */
523
+	private function _duplicate_venue_exists($old_event)
524
+	{
525
+		global $wpdb;
526
+		$conditions = array(
527
+			'VNU_address' => $old_event ['address'],
528
+			'VNU_address2' => $old_event['address2'],
529
+			'VNU_city' => $old_event['city'],
530
+			'VNU_zip' => $old_event['zip'],
531
+			'post_title'=> $this->_get_venue_title_for_event($old_event),
532
+			'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
533
+			'VNU_url'=>$old_event['venue_url'],// VNU_url
534
+			'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
535
+			'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
536
+		);
537
+		$sql_conditions = array();
538
+		foreach ($conditions as $column => $value) {
539
+			$sql_conditions [] = $wpdb->prepare("$column = %s", $value);
540
+		}
541
+		$query = "SELECT VNU_ID
547 542
 					FROM
548 543
 		{$wpdb->posts} as p INNER JOIN
549 544
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
550 545
 			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
551
-        $id = $wpdb->get_var($query);
552
-        return $id;
553
-    }
554
-
555
-    /**
556
-     * Gets teh venue's title or makes one up if there is none
557
-     * @param array $event_data_array keys are events_details columns and values are their values
558
-     * @return string
559
-     */
560
-    protected function _get_venue_title_for_event($event_data_array)
561
-    {
562
-        return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
563
-    }
564
-
565
-    /**
566
-     * Inserts the CPT
567
-     *
568
-     * @param array $old_event keys are cols, values are col values
569
-     * @return int
570
-     */
571
-    private function _insert_venue_into_posts($old_event)
572
-    {
573
-        global $wpdb;
574
-        $insertion_array = array(
575
-                    'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name
576
-                    'post_content'=>'',// VNU_desc
577
-                    'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
578
-                    'post_date'=>current_time('mysql'),// VNU_created
579
-                    'post_date_gmt'=>get_gmt_from_date(current_time('mysql')),
580
-                    'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters
581
-                    'post_modified'=>current_time('mysql'),// VNU_modified
582
-                    'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')),
583
-                    'post_author'=>$old_event['wp_user'],// VNU_wp_user
584
-                    'post_parent'=>0,// parent
585
-                    'menu_order'=>0,// VNU_order
586
-                    'post_type'=>'espresso_venues'// post_type
587
-                );
588
-        $datatypes_array = array(
589
-                    '%s',// VNU_name
590
-                    '%s',// VNU_desc
591
-                    '%s',// VNU_identifier
592
-                    '%s',// VNU_created
593
-                    '%s',
594
-                    '%s',// VNU_short_desc
595
-                    '%s',// VNU_modified
596
-                    '%s',
597
-                    '%d',// VNU_wp_user
598
-                    '%d',// parent
599
-                    '%d',// VNU_order
600
-                    '%s',// post_type
601
-                );
602
-        $success = $wpdb->insert(
603
-            $wpdb->posts,
604
-            $insertion_array,
605
-            $datatypes_array
606
-        );
607
-        if (! $success) {
608
-            $this->add_error(
609
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
610
-                    $this->_old_table,
611
-                    $old_event,
612
-                    $this->_new_table,
613
-                    $insertion_array,
614
-                    $datatypes_array
615
-                )
616
-            );
617
-            return 0;
618
-        }
619
-        return $wpdb->insert_id;
620
-    }
621
-
622
-    /**
623
-     * Inserts into the venue_meta table
624
-     * @param int $cpt_id
625
-     * @param array $old_event
626
-     * @return int
627
-     */
628
-    private function _insert_venue_into_meta_table($cpt_id, $old_event)
629
-    {
630
-        global $wpdb;
631
-
632
-        // assume the country is the same as the organization's old settings
633
-        $country_iso = $this->get_migration_script()->get_default_country_iso();
634
-        // find the state from the venue, or the organization, or just guess california
635
-        if (! $old_event['state']) {
636
-            $old_org_options = get_option('events_organization_settings');
637
-            $state_name = stripslashes($old_org_options['organization_state']);
638
-        } else {
639
-            $state_name = $old_event['state'];
640
-        }
641
-        if (! $state_name) {
642
-            $state_name = 'CA';
643
-        }
644
-        // get a state ID with the same name, if possible
645
-        try {
646
-            $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
647
-            $state_id = $state['STA_ID'];
648
-        } catch (EE_Error $e) {
649
-            $this->add_error($e->getMessage());
650
-            $state_id = 0;
651
-        }
652
-        // now insert into meta table
653
-        $insertion_array = array(
654
-            'VNU_ID'=>$cpt_id,// VNU_ID_fk
655
-            'VNU_address'=>stripslashes($old_event['address']),// VNU_address
656
-            'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2
657
-            'VNU_city'=>stripslashes($old_event['city']),// VNU_city
658
-            'STA_ID'=>$state_id,// STA_ID
659
-            'CNT_ISO'=>$country_iso,// CNT_ISO
660
-            'VNU_zip'=>$old_event['zip'],// VNU_zip
661
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
662
-            'VNU_capacity'=>-1,// VNU_capacity
663
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
664
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
665
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
666
-            'VNU_google_map_link'=>'',// VNU_google_map_link
667
-            'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
668
-        );
669
-        $datatypes = array(
670
-            '%d',// VNU_ID_fk
671
-            '%s',// VNU_address
672
-            '%s',// VNU_address2
673
-            '%s',// VNU_city
674
-            '%d',// STA_ID
675
-            '%s',// CNT_ISO
676
-            '%s',// VNU_zip
677
-            '%s',// VNU_phone
678
-            '%d',// VNU_capacity
679
-            '%s',// VNU_url
680
-            '%s',// VNU_virtual_phone
681
-            '%s',// VNU_virtual_url
682
-            '%s',// VNU_google_map_link
683
-            '%d',// VNU_enable_for_gmap
684
-        );
685
-        $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
686
-        if (! $success) {
687
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
688
-            return 0;
689
-        }
690
-        return $wpdb->insert_id;
691
-    }
692
-
693
-
694
-
695
-    /**
696
-     * @param $new_event_id
697
-     * @param $new_venue_id
698
-     * @return int
699
-     */
700
-    private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
701
-    {
702
-        global $wpdb;
703
-        if (! $new_event_id) {
704
-            $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
705
-            return 0;
706
-        }
707
-        if (! $new_venue_id) {
708
-            $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
709
-            return 0;
710
-        }
711
-        $cols_n_values = array(
712
-            'EVT_ID'=>$new_event_id,
713
-            'VNU_ID'=>$new_venue_id,
714
-            'EVV_primary'=>true
715
-        );
716
-        $datatypes = array(
717
-            '%d',// EVT_ID
718
-            '%d',// VNU_ID
719
-            '%d',// EVT_primary
720
-        );
721
-        $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
722
-        if (! $success) {
723
-            $this->add_error(
724
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
725
-                    $this->_old_table,
726
-                    array(),
727
-                    $this->_new_table,
728
-                    $cols_n_values,
729
-                    $datatypes
730
-                )
731
-            );
732
-            return 0;
733
-        }
734
-        return $wpdb->insert_id;
735
-    }
736
-    /**
737
-     * Converts all the 3.1 start-end times for the event to 4.1 datetimes
738
-     * @global wpdb $wpdb
739
-     * @param array $old_event results of get_results(...,ARRAY_A)
740
-     * @param int $new_cpt_id new post ID
741
-     * @return void (if there are errors though, adds them to the stage's error list
742
-     */
743
-    private function _convert_start_end_times($old_event, $new_cpt_id)
744
-    {
745
-        $start_end_times = $this->_get_old_start_end_times($old_event['id']);
746
-        foreach ($start_end_times as $start_end_time) {
747
-            $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
748
-            if ($datetime_id) {
749
-                $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
750
-            }
751
-        }
752
-    }
753
-    /**
754
-     * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
755
-     * @global wpdb $wpdb
756
-     * @param int $old_event_id
757
-     * @return array
758
-     */
759
-    private function _get_old_start_end_times($old_event_id)
760
-    {
761
-        global $wpdb;
762
-        return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
763
-    }
764
-    /**
765
-     * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
766
-     * @param array $start_end_time_row
767
-     * @param array $old_event_row
768
-     * @param int $new_cpt_id
769
-     * @return int ID of new datetime
770
-     */
771
-    private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
772
-    {
773
-        global $wpdb;
774
-        $start_date = $old_event_row['start_date'];
775
-        $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
776
-        $end_date = $old_event_row['end_date'];
777
-        $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
778
-        $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
779
-        $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
780
-        $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
781
-        $cols_n_values = array(
782
-            'EVT_ID'=>$new_cpt_id,// EVT_ID
783
-            'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start
784
-            'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end
785
-            'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
786
-            'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration
546
+		$id = $wpdb->get_var($query);
547
+		return $id;
548
+	}
549
+
550
+	/**
551
+	 * Gets teh venue's title or makes one up if there is none
552
+	 * @param array $event_data_array keys are events_details columns and values are their values
553
+	 * @return string
554
+	 */
555
+	protected function _get_venue_title_for_event($event_data_array)
556
+	{
557
+		return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
558
+	}
559
+
560
+	/**
561
+	 * Inserts the CPT
562
+	 *
563
+	 * @param array $old_event keys are cols, values are col values
564
+	 * @return int
565
+	 */
566
+	private function _insert_venue_into_posts($old_event)
567
+	{
568
+		global $wpdb;
569
+		$insertion_array = array(
570
+					'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name
571
+					'post_content'=>'',// VNU_desc
572
+					'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
573
+					'post_date'=>current_time('mysql'),// VNU_created
574
+					'post_date_gmt'=>get_gmt_from_date(current_time('mysql')),
575
+					'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters
576
+					'post_modified'=>current_time('mysql'),// VNU_modified
577
+					'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')),
578
+					'post_author'=>$old_event['wp_user'],// VNU_wp_user
579
+					'post_parent'=>0,// parent
580
+					'menu_order'=>0,// VNU_order
581
+					'post_type'=>'espresso_venues'// post_type
582
+				);
583
+		$datatypes_array = array(
584
+					'%s',// VNU_name
585
+					'%s',// VNU_desc
586
+					'%s',// VNU_identifier
587
+					'%s',// VNU_created
588
+					'%s',
589
+					'%s',// VNU_short_desc
590
+					'%s',// VNU_modified
591
+					'%s',
592
+					'%d',// VNU_wp_user
593
+					'%d',// parent
594
+					'%d',// VNU_order
595
+					'%s',// post_type
596
+				);
597
+		$success = $wpdb->insert(
598
+			$wpdb->posts,
599
+			$insertion_array,
600
+			$datatypes_array
601
+		);
602
+		if (! $success) {
603
+			$this->add_error(
604
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
605
+					$this->_old_table,
606
+					$old_event,
607
+					$this->_new_table,
608
+					$insertion_array,
609
+					$datatypes_array
610
+				)
611
+			);
612
+			return 0;
613
+		}
614
+		return $wpdb->insert_id;
615
+	}
616
+
617
+	/**
618
+	 * Inserts into the venue_meta table
619
+	 * @param int $cpt_id
620
+	 * @param array $old_event
621
+	 * @return int
622
+	 */
623
+	private function _insert_venue_into_meta_table($cpt_id, $old_event)
624
+	{
625
+		global $wpdb;
626
+
627
+		// assume the country is the same as the organization's old settings
628
+		$country_iso = $this->get_migration_script()->get_default_country_iso();
629
+		// find the state from the venue, or the organization, or just guess california
630
+		if (! $old_event['state']) {
631
+			$old_org_options = get_option('events_organization_settings');
632
+			$state_name = stripslashes($old_org_options['organization_state']);
633
+		} else {
634
+			$state_name = $old_event['state'];
635
+		}
636
+		if (! $state_name) {
637
+			$state_name = 'CA';
638
+		}
639
+		// get a state ID with the same name, if possible
640
+		try {
641
+			$state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
642
+			$state_id = $state['STA_ID'];
643
+		} catch (EE_Error $e) {
644
+			$this->add_error($e->getMessage());
645
+			$state_id = 0;
646
+		}
647
+		// now insert into meta table
648
+		$insertion_array = array(
649
+			'VNU_ID'=>$cpt_id,// VNU_ID_fk
650
+			'VNU_address'=>stripslashes($old_event['address']),// VNU_address
651
+			'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2
652
+			'VNU_city'=>stripslashes($old_event['city']),// VNU_city
653
+			'STA_ID'=>$state_id,// STA_ID
654
+			'CNT_ISO'=>$country_iso,// CNT_ISO
655
+			'VNU_zip'=>$old_event['zip'],// VNU_zip
656
+			'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
657
+			'VNU_capacity'=>-1,// VNU_capacity
658
+			'VNU_url'=>$old_event['venue_url'],// VNU_url
659
+			'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
660
+			'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
661
+			'VNU_google_map_link'=>'',// VNU_google_map_link
662
+			'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
663
+		);
664
+		$datatypes = array(
665
+			'%d',// VNU_ID_fk
666
+			'%s',// VNU_address
667
+			'%s',// VNU_address2
668
+			'%s',// VNU_city
669
+			'%d',// STA_ID
670
+			'%s',// CNT_ISO
671
+			'%s',// VNU_zip
672
+			'%s',// VNU_phone
673
+			'%d',// VNU_capacity
674
+			'%s',// VNU_url
675
+			'%s',// VNU_virtual_phone
676
+			'%s',// VNU_virtual_url
677
+			'%s',// VNU_google_map_link
678
+			'%d',// VNU_enable_for_gmap
679
+		);
680
+		$success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
681
+		if (! $success) {
682
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
683
+			return 0;
684
+		}
685
+		return $wpdb->insert_id;
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * @param $new_event_id
692
+	 * @param $new_venue_id
693
+	 * @return int
694
+	 */
695
+	private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
696
+	{
697
+		global $wpdb;
698
+		if (! $new_event_id) {
699
+			$this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
700
+			return 0;
701
+		}
702
+		if (! $new_venue_id) {
703
+			$this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
704
+			return 0;
705
+		}
706
+		$cols_n_values = array(
707
+			'EVT_ID'=>$new_event_id,
708
+			'VNU_ID'=>$new_venue_id,
709
+			'EVV_primary'=>true
710
+		);
711
+		$datatypes = array(
712
+			'%d',// EVT_ID
713
+			'%d',// VNU_ID
714
+			'%d',// EVT_primary
715
+		);
716
+		$success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
717
+		if (! $success) {
718
+			$this->add_error(
719
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
720
+					$this->_old_table,
721
+					array(),
722
+					$this->_new_table,
723
+					$cols_n_values,
724
+					$datatypes
725
+				)
726
+			);
727
+			return 0;
728
+		}
729
+		return $wpdb->insert_id;
730
+	}
731
+	/**
732
+	 * Converts all the 3.1 start-end times for the event to 4.1 datetimes
733
+	 * @global wpdb $wpdb
734
+	 * @param array $old_event results of get_results(...,ARRAY_A)
735
+	 * @param int $new_cpt_id new post ID
736
+	 * @return void (if there are errors though, adds them to the stage's error list
737
+	 */
738
+	private function _convert_start_end_times($old_event, $new_cpt_id)
739
+	{
740
+		$start_end_times = $this->_get_old_start_end_times($old_event['id']);
741
+		foreach ($start_end_times as $start_end_time) {
742
+			$datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
743
+			if ($datetime_id) {
744
+				$this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
745
+			}
746
+		}
747
+	}
748
+	/**
749
+	 * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
750
+	 * @global wpdb $wpdb
751
+	 * @param int $old_event_id
752
+	 * @return array
753
+	 */
754
+	private function _get_old_start_end_times($old_event_id)
755
+	{
756
+		global $wpdb;
757
+		return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
758
+	}
759
+	/**
760
+	 * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
761
+	 * @param array $start_end_time_row
762
+	 * @param array $old_event_row
763
+	 * @param int $new_cpt_id
764
+	 * @return int ID of new datetime
765
+	 */
766
+	private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
767
+	{
768
+		global $wpdb;
769
+		$start_date = $old_event_row['start_date'];
770
+		$start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
771
+		$end_date = $old_event_row['end_date'];
772
+		$end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
773
+		$existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
774
+		$start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
775
+		$end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
776
+		$cols_n_values = array(
777
+			'EVT_ID'=>$new_cpt_id,// EVT_ID
778
+			'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start
779
+			'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end
780
+			'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
781
+			'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration
787 782
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
788
-            'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
789
-            'DTT_parent'=>0,
790
-            'DTT_deleted'=>false
791
-        );
792
-        $datatypes = array(
793
-            '%d',// EVT_Id
794
-            '%s',// DTT_EVT_start
795
-            '%s',// DTT_EVT_end
796
-            '%d',// DTT_reg_limit
797
-            '%d',// DTT_sold
783
+			'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
784
+			'DTT_parent'=>0,
785
+			'DTT_deleted'=>false
786
+		);
787
+		$datatypes = array(
788
+			'%d',// EVT_Id
789
+			'%s',// DTT_EVT_start
790
+			'%s',// DTT_EVT_end
791
+			'%d',// DTT_reg_limit
792
+			'%d',// DTT_sold
798 793
 //          '%d',//DTT_is_primary
799
-            '%d',// DTT_order
800
-            '%d',// DTT_parent
801
-            '%d',// DTT_deleted
802
-        );
803
-        $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
804
-        if (! $success) {
805
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
806
-            return 0;
807
-        }
808
-        return $wpdb->insert_id;
809
-    }
810
-
811
-    /**
812
-     * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
813
-     * when deciding whether a datetime we're about ot insert should be the 'primary' or not
814
-     * @global wpdb $wpdb
815
-     * @param int $cpt_event_id
816
-     * @return int
817
-     */
818
-    private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
819
-    {
820
-        global $wpdb;
821
-        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
822
-        return intval($count);
823
-    }
794
+			'%d',// DTT_order
795
+			'%d',// DTT_parent
796
+			'%d',// DTT_deleted
797
+		);
798
+		$success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
799
+		if (! $success) {
800
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
801
+			return 0;
802
+		}
803
+		return $wpdb->insert_id;
804
+	}
805
+
806
+	/**
807
+	 * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
808
+	 * when deciding whether a datetime we're about ot insert should be the 'primary' or not
809
+	 * @global wpdb $wpdb
810
+	 * @param int $cpt_event_id
811
+	 * @return int
812
+	 */
813
+	private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
814
+	{
815
+		global $wpdb;
816
+		$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
817
+		return intval($count);
818
+	}
824 819
 }
Please login to merge, or discard this patch.
Spacing   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     public function _count_records_to_migrate()
194 194
     {
195 195
         global $wpdb;
196
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"');
196
+        $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table.' WHERE event_status !="D"');
197 197
         return intval($count);
198 198
     }
199 199
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     {
213 213
         global $wpdb;
214 214
         // because the migration of each event can be a LOT more work, make each step smaller
215
-        $num_items_to_migrate = max(1, $num_items_to_migrate/5);
215
+        $num_items_to_migrate = max(1, $num_items_to_migrate / 5);
216 216
         $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
217 217
         $items_migrated_this_step = 0;
218 218
 
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
     private function _add_post_metas($old_event, $post_id)
261 261
     {
262 262
         $event_meta = maybe_unserialize($old_event['event_meta']);
263
-        if (! $event_meta || ! is_array($event_meta)) {
263
+        if ( ! $event_meta || ! is_array($event_meta)) {
264 264
             return;
265 265
         }
266
-        unset($event_meta['date_submitted']);// factored into CPT
267
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
268
-        unset($event_meta['default_payment_status']);// dido
269
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
266
+        unset($event_meta['date_submitted']); // factored into CPT
267
+        unset($event_meta['additional_attendee_reg_info']); // factored into event meta table
268
+        unset($event_meta['default_payment_status']); // dido
269
+        unset($event_meta['event_thumbnail_url']); // used to find post featured image
270 270
         foreach ($event_meta as $meta_key => $meta_value) {
271 271
             if ($meta_key) {// if the meta key is just an empty string, ignore it
272 272
                 $success = add_post_meta($post_id, $meta_key, $meta_value, true);
273
-                if (! $success) {
273
+                if ( ! $success) {
274 274
                     $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
275 275
                 }
276 276
             }
@@ -341,68 +341,68 @@  discard block
 block discarded – undo
341 341
 //      and 3 custom ones: cancelled,postponed,sold_out
342 342
         $status_conversions = array(
343 343
             'R'=>'draft',
344
-            'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
344
+            'X'=>'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
345 345
             'P'=>'pending',
346
-            'IA'=>'draft',// draft and in the past
346
+            'IA'=>'draft', // draft and in the past
347 347
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
348
-            'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
348
+            'O'=>'publish', // @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
349 349
             'A'=>'publish',
350
-            'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
350
+            'S'=>'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
351 351
             'D'=>'trash',
352 352
         );
353
-        $post_status = $status_conversions[ $old_event['event_status'] ];
353
+        $post_status = $status_conversions[$old_event['event_status']];
354 354
         // check if we've sold out
355 355
         if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
356 356
             $post_status = 'sold_out';
357 357
         }
358 358
 //      FYI postponed and cancelled don't exist in 3.1
359 359
         $cols_n_values = array(
360
-            'post_title'=>stripslashes($old_event['event_name']),// EVT_name
361
-            'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc
362
-            'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
363
-            'post_date'=>$old_event['submitted'],// EVT_created NOT
360
+            'post_title'=>stripslashes($old_event['event_name']), // EVT_name
361
+            'post_content'=>stripslashes($old_event['event_desc']), // EVT_desc
362
+            'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug
363
+            'post_date'=>$old_event['submitted'], // EVT_created NOT
364 364
             'post_date_gmt'=>get_gmt_from_date($old_event['submitted']),
365
-            'post_excerpt'=>'',// EVT_short_desc
366
-            'post_modified'=>$old_event['submitted'],// EVT_modified
365
+            'post_excerpt'=>'', // EVT_short_desc
366
+            'post_modified'=>$old_event['submitted'], // EVT_modified
367 367
             'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']),
368
-            'post_author'=>$old_event['wp_user'],// EVT_wp_user
369
-            'post_parent'=>0,// parent maybe get this from some REM field?
370
-            'menu_order'=>0,// EVT_order
371
-            'post_type'=>'espresso_events',// post_type
372
-            'post_status'=>$post_status,// status
368
+            'post_author'=>$old_event['wp_user'], // EVT_wp_user
369
+            'post_parent'=>0, // parent maybe get this from some REM field?
370
+            'menu_order'=>0, // EVT_order
371
+            'post_type'=>'espresso_events', // post_type
372
+            'post_status'=>$post_status, // status
373 373
         );
374 374
         $cols_n_values_with_no_invalid_text = array();
375 375
         foreach ($cols_n_values as $col => $value) {
376 376
             $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
377
-            if (! is_wp_error($value_sans_invalid_chars)) {
378
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
377
+            if ( ! is_wp_error($value_sans_invalid_chars)) {
378
+                $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars;
379 379
             } else {
380 380
                 // otherwise leave it as-is. It will blow everything up and stop the migration
381
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
381
+                $cols_n_values_with_no_invalid_text[$col] = $value;
382 382
             }
383 383
         }
384 384
         $cols_n_values = $cols_n_values_with_no_invalid_text;
385 385
         $datatypes = array(
386
-            '%s',// EVT_name
387
-            '%s',// EVT_desc
388
-            '%s',// EVT_slug
389
-            '%s',// EVT_created
386
+            '%s', // EVT_name
387
+            '%s', // EVT_desc
388
+            '%s', // EVT_slug
389
+            '%s', // EVT_created
390 390
             '%s',
391
-            '%s',// EVT_short_desc
392
-            '%s',// EVT_modified
391
+            '%s', // EVT_short_desc
392
+            '%s', // EVT_modified
393 393
             '%s',
394
-            '%s',// EVT_wp_user
395
-            '%d',// post_parent
396
-            '%d',// EVT_order
397
-            '%s',// post_type
398
-            '%s',// status
394
+            '%s', // EVT_wp_user
395
+            '%d', // post_parent
396
+            '%d', // EVT_order
397
+            '%s', // post_type
398
+            '%s', // status
399 399
         );
400 400
         $success = $wpdb->insert(
401 401
             $this->_new_table,
402 402
             $cols_n_values,
403 403
             $datatypes
404 404
         );
405
-        if (! $success) {
405
+        if ( ! $success) {
406 406
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
407 407
             return 0;
408 408
         }
@@ -441,10 +441,10 @@  discard block
 block discarded – undo
441 441
 // );
442 442
         $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
443 443
         $cols_n_values = array(
444
-            'EVT_ID'=>$new_cpt_id,// EVT_ID_fk
444
+            'EVT_ID'=>$new_cpt_id, // EVT_ID_fk
445 445
             'EVT_display_desc'=> 'Y' == $old_event['display_desc'],
446
-            'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'],
447
-            'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
446
+            'EVT_display_ticket_selector'=> 'Y' == $old_event['display_reg_form'],
447
+            'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']), // don't use the old 'visible_on', as it wasn't ever used
448 448
             'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
449 449
             'EVT_default_registration_status' => $default_reg_status,
450 450
             'EVT_member_only'=>$old_event['member_only'],
@@ -456,25 +456,25 @@  discard block
 block discarded – undo
456 456
 
457 457
         );
458 458
         $datatypes = array(
459
-            '%s',// EVT_ID
460
-            '%d',// EVT_display_desc
461
-            '%d',// EVT_display_ticket_selector
462
-            '%s',// EVT_visible_on
463
-            '%d',// EVT_additional_limit
464
-            '%s',// EVT_default_registration_status
465
-            '%d',// EVT_member_only
466
-            '%s',// EVT_phone
467
-            '%d',// EVT_allow_overflow
468
-            '%s',// EVT_timezone_string
469
-            '%s',// EVT_external_URL
470
-            '%d',// EVT_donations
459
+            '%s', // EVT_ID
460
+            '%d', // EVT_display_desc
461
+            '%d', // EVT_display_ticket_selector
462
+            '%s', // EVT_visible_on
463
+            '%d', // EVT_additional_limit
464
+            '%s', // EVT_default_registration_status
465
+            '%d', // EVT_member_only
466
+            '%s', // EVT_phone
467
+            '%d', // EVT_allow_overflow
468
+            '%s', // EVT_timezone_string
469
+            '%s', // EVT_external_URL
470
+            '%d', // EVT_donations
471 471
         );
472 472
         $success = $wpdb->insert(
473 473
             $this->_new_meta_table,
474 474
             $cols_n_values,
475 475
             $datatypes
476 476
         );
477
-        if (! $success) {
477
+        if ( ! $success) {
478 478
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
479 479
             return 0;
480 480
         }
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
             $new_id = $this->_insert_venue_into_posts($old_event);
509 509
             if ($new_id) {
510 510
                 $this->_insert_venue_into_meta_table($new_id, $old_event);
511
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
511
+                $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null;
512 512
                 $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
513 513
             }
514 514
             // we don't bother recording the conversion from old events to venues as that
@@ -534,10 +534,10 @@  discard block
 block discarded – undo
534 534
             'VNU_city' => $old_event['city'],
535 535
             'VNU_zip' => $old_event['zip'],
536 536
             'post_title'=> $this->_get_venue_title_for_event($old_event),
537
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
538
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
539
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
540
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
537
+            'VNU_phone'=>$old_event['venue_phone'], // VNU_phone
538
+            'VNU_url'=>$old_event['venue_url'], // VNU_url
539
+            'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone
540
+            'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url
541 541
         );
542 542
         $sql_conditions = array();
543 543
         foreach ($conditions as $column => $value) {
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 					FROM
548 548
 		{$wpdb->posts} as p INNER JOIN
549 549
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
550
-			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
550
+			WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1";
551 551
         $id = $wpdb->get_var($query);
552 552
         return $id;
553 553
     }
@@ -572,39 +572,39 @@  discard block
 block discarded – undo
572 572
     {
573 573
         global $wpdb;
574 574
         $insertion_array = array(
575
-                    'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name
576
-                    'post_content'=>'',// VNU_desc
577
-                    'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
578
-                    'post_date'=>current_time('mysql'),// VNU_created
575
+                    'post_title'=> $this->_get_venue_title_for_event($old_event), // VNU_name
576
+                    'post_content'=>'', // VNU_desc
577
+                    'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier
578
+                    'post_date'=>current_time('mysql'), // VNU_created
579 579
                     'post_date_gmt'=>get_gmt_from_date(current_time('mysql')),
580
-                    'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters
581
-                    'post_modified'=>current_time('mysql'),// VNU_modified
580
+                    'post_excerpt'=>'', // VNU_short_desc arbitrary only 50 characters
581
+                    'post_modified'=>current_time('mysql'), // VNU_modified
582 582
                     'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')),
583
-                    'post_author'=>$old_event['wp_user'],// VNU_wp_user
584
-                    'post_parent'=>0,// parent
585
-                    'menu_order'=>0,// VNU_order
583
+                    'post_author'=>$old_event['wp_user'], // VNU_wp_user
584
+                    'post_parent'=>0, // parent
585
+                    'menu_order'=>0, // VNU_order
586 586
                     'post_type'=>'espresso_venues'// post_type
587 587
                 );
588 588
         $datatypes_array = array(
589
-                    '%s',// VNU_name
590
-                    '%s',// VNU_desc
591
-                    '%s',// VNU_identifier
592
-                    '%s',// VNU_created
589
+                    '%s', // VNU_name
590
+                    '%s', // VNU_desc
591
+                    '%s', // VNU_identifier
592
+                    '%s', // VNU_created
593 593
                     '%s',
594
-                    '%s',// VNU_short_desc
595
-                    '%s',// VNU_modified
594
+                    '%s', // VNU_short_desc
595
+                    '%s', // VNU_modified
596 596
                     '%s',
597
-                    '%d',// VNU_wp_user
598
-                    '%d',// parent
599
-                    '%d',// VNU_order
600
-                    '%s',// post_type
597
+                    '%d', // VNU_wp_user
598
+                    '%d', // parent
599
+                    '%d', // VNU_order
600
+                    '%s', // post_type
601 601
                 );
602 602
         $success = $wpdb->insert(
603 603
             $wpdb->posts,
604 604
             $insertion_array,
605 605
             $datatypes_array
606 606
         );
607
-        if (! $success) {
607
+        if ( ! $success) {
608 608
             $this->add_error(
609 609
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
610 610
                     $this->_old_table,
@@ -632,13 +632,13 @@  discard block
 block discarded – undo
632 632
         // assume the country is the same as the organization's old settings
633 633
         $country_iso = $this->get_migration_script()->get_default_country_iso();
634 634
         // find the state from the venue, or the organization, or just guess california
635
-        if (! $old_event['state']) {
635
+        if ( ! $old_event['state']) {
636 636
             $old_org_options = get_option('events_organization_settings');
637 637
             $state_name = stripslashes($old_org_options['organization_state']);
638 638
         } else {
639 639
             $state_name = $old_event['state'];
640 640
         }
641
-        if (! $state_name) {
641
+        if ( ! $state_name) {
642 642
             $state_name = 'CA';
643 643
         }
644 644
         // get a state ID with the same name, if possible
@@ -651,39 +651,39 @@  discard block
 block discarded – undo
651 651
         }
652 652
         // now insert into meta table
653 653
         $insertion_array = array(
654
-            'VNU_ID'=>$cpt_id,// VNU_ID_fk
655
-            'VNU_address'=>stripslashes($old_event['address']),// VNU_address
656
-            'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2
657
-            'VNU_city'=>stripslashes($old_event['city']),// VNU_city
658
-            'STA_ID'=>$state_id,// STA_ID
659
-            'CNT_ISO'=>$country_iso,// CNT_ISO
660
-            'VNU_zip'=>$old_event['zip'],// VNU_zip
661
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
662
-            'VNU_capacity'=>-1,// VNU_capacity
663
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
664
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
665
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
666
-            'VNU_google_map_link'=>'',// VNU_google_map_link
654
+            'VNU_ID'=>$cpt_id, // VNU_ID_fk
655
+            'VNU_address'=>stripslashes($old_event['address']), // VNU_address
656
+            'VNU_address2'=>stripslashes($old_event['address2']), // VNU_address2
657
+            'VNU_city'=>stripslashes($old_event['city']), // VNU_city
658
+            'STA_ID'=>$state_id, // STA_ID
659
+            'CNT_ISO'=>$country_iso, // CNT_ISO
660
+            'VNU_zip'=>$old_event['zip'], // VNU_zip
661
+            'VNU_phone'=>$old_event['venue_phone'], // VNU_phone
662
+            'VNU_capacity'=>-1, // VNU_capacity
663
+            'VNU_url'=>$old_event['venue_url'], // VNU_url
664
+            'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone
665
+            'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url
666
+            'VNU_google_map_link'=>'', // VNU_google_map_link
667 667
             'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
668 668
         );
669 669
         $datatypes = array(
670
-            '%d',// VNU_ID_fk
671
-            '%s',// VNU_address
672
-            '%s',// VNU_address2
673
-            '%s',// VNU_city
674
-            '%d',// STA_ID
675
-            '%s',// CNT_ISO
676
-            '%s',// VNU_zip
677
-            '%s',// VNU_phone
678
-            '%d',// VNU_capacity
679
-            '%s',// VNU_url
680
-            '%s',// VNU_virtual_phone
681
-            '%s',// VNU_virtual_url
682
-            '%s',// VNU_google_map_link
683
-            '%d',// VNU_enable_for_gmap
670
+            '%d', // VNU_ID_fk
671
+            '%s', // VNU_address
672
+            '%s', // VNU_address2
673
+            '%s', // VNU_city
674
+            '%d', // STA_ID
675
+            '%s', // CNT_ISO
676
+            '%s', // VNU_zip
677
+            '%s', // VNU_phone
678
+            '%d', // VNU_capacity
679
+            '%s', // VNU_url
680
+            '%s', // VNU_virtual_phone
681
+            '%s', // VNU_virtual_url
682
+            '%s', // VNU_google_map_link
683
+            '%d', // VNU_enable_for_gmap
684 684
         );
685 685
         $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
686
-        if (! $success) {
686
+        if ( ! $success) {
687 687
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
688 688
             return 0;
689 689
         }
@@ -700,11 +700,11 @@  discard block
 block discarded – undo
700 700
     private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
701 701
     {
702 702
         global $wpdb;
703
-        if (! $new_event_id) {
703
+        if ( ! $new_event_id) {
704 704
             $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
705 705
             return 0;
706 706
         }
707
-        if (! $new_venue_id) {
707
+        if ( ! $new_venue_id) {
708 708
             $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
709 709
             return 0;
710 710
         }
@@ -714,12 +714,12 @@  discard block
 block discarded – undo
714 714
             'EVV_primary'=>true
715 715
         );
716 716
         $datatypes = array(
717
-            '%d',// EVT_ID
718
-            '%d',// VNU_ID
719
-            '%d',// EVT_primary
717
+            '%d', // EVT_ID
718
+            '%d', // VNU_ID
719
+            '%d', // EVT_primary
720 720
         );
721 721
         $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
722
-        if (! $success) {
722
+        if ( ! $success) {
723 723
             $this->add_error(
724 724
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
725 725
                     $this->_old_table,
@@ -779,29 +779,29 @@  discard block
 block discarded – undo
779 779
         $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
780 780
         $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
781 781
         $cols_n_values = array(
782
-            'EVT_ID'=>$new_cpt_id,// EVT_ID
783
-            'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start
784
-            'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end
785
-            'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
786
-            'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration
782
+            'EVT_ID'=>$new_cpt_id, // EVT_ID
783
+            'DTT_EVT_start'=>$start_datetime_utc, // DTT_EVT_start
784
+            'DTT_EVT_end'=> $end_datetime_utc, // DTT_EVT_end
785
+            'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit
786
+            'DTT_sold'=>0, // note: we will increment this as registrations are added during the migration
787 787
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
788
-            'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
788
+            'DTT_order'=> $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist
789 789
             'DTT_parent'=>0,
790 790
             'DTT_deleted'=>false
791 791
         );
792 792
         $datatypes = array(
793
-            '%d',// EVT_Id
794
-            '%s',// DTT_EVT_start
795
-            '%s',// DTT_EVT_end
796
-            '%d',// DTT_reg_limit
797
-            '%d',// DTT_sold
793
+            '%d', // EVT_Id
794
+            '%s', // DTT_EVT_start
795
+            '%s', // DTT_EVT_end
796
+            '%d', // DTT_reg_limit
797
+            '%d', // DTT_sold
798 798
 //          '%d',//DTT_is_primary
799
-            '%d',// DTT_order
800
-            '%d',// DTT_parent
801
-            '%d',// DTT_deleted
799
+            '%d', // DTT_order
800
+            '%d', // DTT_parent
801
+            '%d', // DTT_deleted
802 802
         );
803 803
         $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
804
-        if (! $success) {
804
+        if ( ! $success) {
805 805
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
806 806
             return 0;
807 807
         }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_org_options.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -273,7 +273,6 @@
 block discarded – undo
273 273
     /**
274 274
      * Creates a 4.1 member price discount
275 275
      * @global type $wpdb
276
-     * @param type $old_price
277 276
      * @return int
278 277
      */
279 278
     private function _insert_new_global_surcharge_price($org_options)
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
         $old_org_options = get_option('events_organization_settings');
111 111
         foreach ($this->_org_options_we_know_how_to_migrate as $option_name) {
112 112
             // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default
113
-            if (isset($old_org_options[ $option_name ])) {
114
-                $this->_handle_org_option($option_name, $old_org_options[ $option_name ]);
113
+            if (isset($old_org_options[$option_name])) {
114
+                $this->_handle_org_option($option_name, $old_org_options[$option_name]);
115 115
             }
116
-            if ($option_name=='surcharge') {
116
+            if ($option_name == 'surcharge') {
117 117
                 $this->_insert_new_global_surcharge_price($old_org_options);
118 118
             }
119 119
             $items_actually_migrated++;
120 120
         }
121 121
 
122 122
         $success = EE_Config::instance()->update_espresso_config(false, true);
123
-        if (! $success) {
123
+        if ( ! $success) {
124 124
             $this->add_error(sprintf(__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false)));
125 125
             EE_Error::overwrite_errors();
126 126
         }
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
                 $c->organization->email = $value;
177 177
                 break;
178 178
             case 'default_payment_status':
179
-                $c->registration->default_STS_ID =  $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
179
+                $c->registration->default_STS_ID = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
180 180
                 break;
181 181
             case 'organization_country':
182
-                $iso =$this->get_migration_script()->get_iso_from_3_1_country_id($value);
182
+                $iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value);
183 183
                 $c->organization->CNT_ISO = $iso;
184 184
                 $country_row = $this->get_migration_script()->get_or_create_country($iso);
185
-                if (! $country_row) {
185
+                if ( ! $country_row) {
186 186
                     $this->add_error(sprintf(__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso));
187 187
                 }
188 188
                 // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them)
189
-                $c->currency->code = $country_row['CNT_cur_code'];          // currency code: USD, CAD, EUR
190
-                $c->currency->name = $country_row['CNT_cur_single'];    // Dollar
191
-                $c->currency->plural = $country_row['CNT_cur_plural'];  // Dollars
192
-                $c->currency->sign =  $country_row['CNT_cur_sign'];             // currency sign: $
193
-                $c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN);        // currency sign before or after: $TRUE  or  FALSE$
194
-                $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc'];    // decimal places: 2 = 0.00  3 = 0.000
195
-                $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk'];    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
196
-                $c->currency->thsnds = $country_row['CNT_cur_thsnds'];  // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
189
+                $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR
190
+                $c->currency->name = $country_row['CNT_cur_single']; // Dollar
191
+                $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars
192
+                $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $
193
+                $c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN); // currency sign before or after: $TRUE  or  FALSE$
194
+                $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc']; // decimal places: 2 = 0.00  3 = 0.000
195
+                $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
196
+                $c->currency->thsnds = $country_row['CNT_cur_thsnds']; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
197 197
   //            $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break;
198 198
   //        case 'currency_symbol': ignore the currency symbol. we'll just go by their country.
199 199
   //            $c->currency->sign = $value;break;
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     {
281 281
         $amount = floatval($org_options['surcharge']);
282 282
         // dont createa a price if the surcharge is 0
283
-        if ($amount <=.01) {
283
+        if ($amount <= .01) {
284 284
             return 0;
285 285
         }
286 286
         if ($org_options['surcharge_type'] == 'flat_rate') {
@@ -301,18 +301,18 @@  discard block
 block discarded – undo
301 301
 
302 302
         );
303 303
         $datatypes = array(
304
-            '%d',// PRT_ID
305
-            '%f',// PRT_amount
306
-            '%s',// PRC_name
307
-            '%d',// PRC_is_default
308
-            '%d',// PRC_overrides
309
-            '%d',// PRC_order
310
-            '%d',// PRC_deleted
311
-            '%d',// PRC_parent
304
+            '%d', // PRT_ID
305
+            '%f', // PRT_amount
306
+            '%s', // PRC_name
307
+            '%d', // PRC_is_default
308
+            '%d', // PRC_overrides
309
+            '%d', // PRC_order
310
+            '%d', // PRC_deleted
311
+            '%d', // PRC_parent
312 312
         );
313 313
         $price_table = $wpdb->prefix."esp_price";
314 314
         $success = $wpdb->insert($price_table, $cols_n_values, $datatypes);
315
-        if (! $success) {
315
+        if ( ! $success) {
316 316
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion(
317 317
                 'org_options',
318 318
                 array(
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
       'payment_message',
343 343
       'message',
344 344
       'default_payment_status',
345
-      'surcharge',// unused?
346
-      'country_id',// unused?
345
+      'surcharge', // unused?
346
+      'country_id', // unused?
347 347
       'organization_country',
348 348
 //    'currency_symbol',
349 349
       'expire_on_registration_end',
@@ -355,13 +355,13 @@  discard block
 block discarded – undo
355 355
       'show_pending_payment_options',
356 356
       'show_reg_footer',
357 357
       'skip_confirmation_page',
358
-      'allow_mer_discounts',// no equiv
359
-      'allow_mer_vouchers',// no equiv
358
+      'allow_mer_discounts', // no equiv
359
+      'allow_mer_vouchers', // no equiv
360 360
       'display_short_description_in_event_list',
361 361
       'display_description_on_multi_reg_page',
362 362
       'display_address_in_event_list',
363 363
       'display_address_in_regform',
364
-      'use_custom_post_types',// no equiv
364
+      'use_custom_post_types', // no equiv
365 365
       'display_ical_download',
366 366
       'display_featured_image',
367 367
       'themeroller',
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
       'espresso_dashboard_widget',
381 381
       'time_reg_limit',
382 382
 //    'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status
383
-      'use_personnel_manager',// no equiv
383
+      'use_personnel_manager', // no equiv
384 384
       'use_event_timezones',
385 385
       'full_logging',
386
-      'surcharge_type',// unused
387
-      'surcharge_text',// unused
386
+      'surcharge_type', // unused
387
+      'surcharge_text', // unused
388 388
       'affiliate_id',
389 389
       'site_license_key',
390 390
     );
Please login to merge, or discard this patch.
Indentation   +270 added lines, -270 removed lines patch added patch discarded remove patch
@@ -103,286 +103,286 @@
 block discarded – undo
103 103
 class EE_DMS_4_1_0_org_options extends EE_Data_Migration_Script_Stage
104 104
 {
105 105
 
106
-    public function _migration_step($num_items = 50)
107
-    {
106
+	public function _migration_step($num_items = 50)
107
+	{
108 108
 
109
-        $items_actually_migrated = 0;
110
-        $old_org_options = get_option('events_organization_settings');
111
-        foreach ($this->_org_options_we_know_how_to_migrate as $option_name) {
112
-            // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default
113
-            if (isset($old_org_options[ $option_name ])) {
114
-                $this->_handle_org_option($option_name, $old_org_options[ $option_name ]);
115
-            }
116
-            if ($option_name=='surcharge') {
117
-                $this->_insert_new_global_surcharge_price($old_org_options);
118
-            }
119
-            $items_actually_migrated++;
120
-        }
109
+		$items_actually_migrated = 0;
110
+		$old_org_options = get_option('events_organization_settings');
111
+		foreach ($this->_org_options_we_know_how_to_migrate as $option_name) {
112
+			// only bother migrating if there's a setting to migrate. Otherwise we'll just use the default
113
+			if (isset($old_org_options[ $option_name ])) {
114
+				$this->_handle_org_option($option_name, $old_org_options[ $option_name ]);
115
+			}
116
+			if ($option_name=='surcharge') {
117
+				$this->_insert_new_global_surcharge_price($old_org_options);
118
+			}
119
+			$items_actually_migrated++;
120
+		}
121 121
 
122
-        $success = EE_Config::instance()->update_espresso_config(false, true);
123
-        if (! $success) {
124
-            $this->add_error(sprintf(__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false)));
125
-            EE_Error::overwrite_errors();
126
-        }
127
-        EE_Network_Config::instance()->update_config(false, false);
128
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
129
-            // we may have added new pages and this might be necessary
130
-            flush_rewrite_rules();
131
-            $this->set_completed();
132
-        }
133
-        return $items_actually_migrated;
134
-    }
135
-    public function _count_records_to_migrate()
136
-    {
137
-        $count_of_options_to_migrate = count($this->_org_options_we_know_how_to_migrate);
138
-        return $count_of_options_to_migrate;
139
-    }
140
-    public function __construct()
141
-    {
142
-        $this->_pretty_name = __("Organization Options/Config", "event_espresso");
143
-        $this->_org_options_we_know_how_to_migrate = apply_filters('FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', $this->_org_options_we_know_how_to_migrate);
144
-        parent::__construct();
145
-    }
122
+		$success = EE_Config::instance()->update_espresso_config(false, true);
123
+		if (! $success) {
124
+			$this->add_error(sprintf(__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false)));
125
+			EE_Error::overwrite_errors();
126
+		}
127
+		EE_Network_Config::instance()->update_config(false, false);
128
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
129
+			// we may have added new pages and this might be necessary
130
+			flush_rewrite_rules();
131
+			$this->set_completed();
132
+		}
133
+		return $items_actually_migrated;
134
+	}
135
+	public function _count_records_to_migrate()
136
+	{
137
+		$count_of_options_to_migrate = count($this->_org_options_we_know_how_to_migrate);
138
+		return $count_of_options_to_migrate;
139
+	}
140
+	public function __construct()
141
+	{
142
+		$this->_pretty_name = __("Organization Options/Config", "event_espresso");
143
+		$this->_org_options_we_know_how_to_migrate = apply_filters('FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', $this->_org_options_we_know_how_to_migrate);
144
+		parent::__construct();
145
+	}
146 146
 
147
-    private function _handle_org_option($option_name, $value)
148
-    {
149
-        $c = EE_Config::instance();
150
-        $cn = EE_Network_Config::instance();
151
-        switch ($option_name) {
152
-            case 'organization':
153
-                $c->organization->name = $value;
154
-                break;
155
-            case 'organization_street1':
156
-                $c->organization->address_1 = $value;
157
-                break;
158
-            case 'organization_street2':
159
-                $c->organization->address_2 = $value;
160
-                break;
161
-            case 'organization_city':
162
-                $c->organization->city = $value;
163
-                break;
164
-            case 'organization_state':
165
-                try {
166
-                    $state = $this->get_migration_script()->get_or_create_state($value);
167
-                    $state_id = $state['STA_ID'];
168
-                    $c->organization->STA_ID = $state_id;
169
-                } catch (EE_Error $e) {
170
-                }
171
-                break;
172
-            case 'organization_zip':
173
-                $c->organization->zip = $value;
174
-                break;
175
-            case 'contact_email':
176
-                $c->organization->email = $value;
177
-                break;
178
-            case 'default_payment_status':
179
-                $c->registration->default_STS_ID =  $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
180
-                break;
181
-            case 'organization_country':
182
-                $iso =$this->get_migration_script()->get_iso_from_3_1_country_id($value);
183
-                $c->organization->CNT_ISO = $iso;
184
-                $country_row = $this->get_migration_script()->get_or_create_country($iso);
185
-                if (! $country_row) {
186
-                    $this->add_error(sprintf(__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso));
187
-                }
188
-                // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them)
189
-                $c->currency->code = $country_row['CNT_cur_code'];          // currency code: USD, CAD, EUR
190
-                $c->currency->name = $country_row['CNT_cur_single'];    // Dollar
191
-                $c->currency->plural = $country_row['CNT_cur_plural'];  // Dollars
192
-                $c->currency->sign =  $country_row['CNT_cur_sign'];             // currency sign: $
193
-                $c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN);        // currency sign before or after: $TRUE  or  FALSE$
194
-                $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc'];    // decimal places: 2 = 0.00  3 = 0.000
195
-                $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk'];    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
196
-                $c->currency->thsnds = $country_row['CNT_cur_thsnds'];  // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
147
+	private function _handle_org_option($option_name, $value)
148
+	{
149
+		$c = EE_Config::instance();
150
+		$cn = EE_Network_Config::instance();
151
+		switch ($option_name) {
152
+			case 'organization':
153
+				$c->organization->name = $value;
154
+				break;
155
+			case 'organization_street1':
156
+				$c->organization->address_1 = $value;
157
+				break;
158
+			case 'organization_street2':
159
+				$c->organization->address_2 = $value;
160
+				break;
161
+			case 'organization_city':
162
+				$c->organization->city = $value;
163
+				break;
164
+			case 'organization_state':
165
+				try {
166
+					$state = $this->get_migration_script()->get_or_create_state($value);
167
+					$state_id = $state['STA_ID'];
168
+					$c->organization->STA_ID = $state_id;
169
+				} catch (EE_Error $e) {
170
+				}
171
+				break;
172
+			case 'organization_zip':
173
+				$c->organization->zip = $value;
174
+				break;
175
+			case 'contact_email':
176
+				$c->organization->email = $value;
177
+				break;
178
+			case 'default_payment_status':
179
+				$c->registration->default_STS_ID =  $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
180
+				break;
181
+			case 'organization_country':
182
+				$iso =$this->get_migration_script()->get_iso_from_3_1_country_id($value);
183
+				$c->organization->CNT_ISO = $iso;
184
+				$country_row = $this->get_migration_script()->get_or_create_country($iso);
185
+				if (! $country_row) {
186
+					$this->add_error(sprintf(__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso));
187
+				}
188
+				// can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them)
189
+				$c->currency->code = $country_row['CNT_cur_code'];          // currency code: USD, CAD, EUR
190
+				$c->currency->name = $country_row['CNT_cur_single'];    // Dollar
191
+				$c->currency->plural = $country_row['CNT_cur_plural'];  // Dollars
192
+				$c->currency->sign =  $country_row['CNT_cur_sign'];             // currency sign: $
193
+				$c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN);        // currency sign before or after: $TRUE  or  FALSE$
194
+				$c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc'];    // decimal places: 2 = 0.00  3 = 0.000
195
+				$c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk'];    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
196
+				$c->currency->thsnds = $country_row['CNT_cur_thsnds'];  // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
197 197
   //            $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break;
198 198
   //        case 'currency_symbol': ignore the currency symbol. we'll just go by their country.
199 199
   //            $c->currency->sign = $value;break;
200
-            case 'show_pending_payment_options':
201
-                $c->registration->show_pending_payment_options = ($value == 'Y');
202
-                break;
203
-            case 'display_address_in_regform':
204
-                $c->template_settings->display_address_in_regform = ($value == 'Y');
205
-                break;
206
-            case 'default_logo_url':
207
-                $c->organization->logo_url = $value;
208
-                break;
209
-            case 'event_page_id':
210
-                // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
211
-                // to ESPRESSO_THANK_YOU
212
-                $reg_page_post = get_post($value);
213
-                $reg_page_post->post_content = str_replace("[ESPRESSO_EVENTS]", "[ESPRESSO_CHECKOUT]", $reg_page_post->post_content);
214
-                wp_update_post($reg_page_post);
215
-                $c->core->reg_page_id = $value;
216
-                break;
217
-            case 'return_url':
218
-                // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
219
-                // to ESPRESSO_THANK_YOU
220
-                $thank_you_page_post = get_post($value);
221
-                $thank_you_page_post->post_content = str_replace("[ESPRESSO_PAYMENTS]", "[ESPRESSO_THANK_YOU]", $thank_you_page_post->post_content);
222
-                wp_update_post($thank_you_page_post);
223
-                $c->core->thank_you_page_id = $value;
224
-                break;
225
-            case 'cancel_return':
226
-                $c->core->cancel_page_id = $value;
200
+			case 'show_pending_payment_options':
201
+				$c->registration->show_pending_payment_options = ($value == 'Y');
202
+				break;
203
+			case 'display_address_in_regform':
204
+				$c->template_settings->display_address_in_regform = ($value == 'Y');
205
+				break;
206
+			case 'default_logo_url':
207
+				$c->organization->logo_url = $value;
208
+				break;
209
+			case 'event_page_id':
210
+				// also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
211
+				// to ESPRESSO_THANK_YOU
212
+				$reg_page_post = get_post($value);
213
+				$reg_page_post->post_content = str_replace("[ESPRESSO_EVENTS]", "[ESPRESSO_CHECKOUT]", $reg_page_post->post_content);
214
+				wp_update_post($reg_page_post);
215
+				$c->core->reg_page_id = $value;
216
+				break;
217
+			case 'return_url':
218
+				// also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
219
+				// to ESPRESSO_THANK_YOU
220
+				$thank_you_page_post = get_post($value);
221
+				$thank_you_page_post->post_content = str_replace("[ESPRESSO_PAYMENTS]", "[ESPRESSO_THANK_YOU]", $thank_you_page_post->post_content);
222
+				wp_update_post($thank_you_page_post);
223
+				$c->core->thank_you_page_id = $value;
224
+				break;
225
+			case 'cancel_return':
226
+				$c->core->cancel_page_id = $value;
227 227
 
228
-                break;
229
-            case 'notify_url':
230
-                $c->core->txn_page_id = $value;
231
-                break;
232
-            case 'use_captcha':
233
-                $c->registration->use_captcha = ($value == 'Y');
234
-                break;
235
-            case 'recaptcha_publickey':
236
-                $c->registration->recaptcha_publickey = $value;
237
-                break;
238
-            case 'recaptcha_privatekey':
239
-                $c->registration->recaptcha_privatekey = $value;
240
-                break;
241
-            case 'recaptcha_theme':
242
-                $c->registration->recaptcha_theme = $value;
243
-                break;
244
-            case 'recaptcha_width':
245
-                $c->registration->recaptcha_width = $value;
246
-                break;
247
-            case 'recaptcha_language':
248
-                $c->registration->recaptcha_language = $value;
249
-                break;
250
-            case 'espresso_dashboard_widget':
251
-                $c->admin->use_dashboard_widget = ($value == 'Y');
252
-                break;
253
-            case 'use_personnel_manager':
254
-                $c->admin->use_personnel_manager = ($value == 'Y');
255
-                break;
256
-            case 'use_event_timezones':
257
-                $c->admin->use_event_timezones = ($value == 'Y');
258
-                break;
259
-            case 'affiliate_id':
260
-                $c->admin->affiliate_id = $value;
261
-                break;
262
-            case 'site_license_key':
263
-                $cn->core->site_license_key = $value;
264
-                break;
265
-            default:
266
-                do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value);
267
-        }
268
-    }
228
+				break;
229
+			case 'notify_url':
230
+				$c->core->txn_page_id = $value;
231
+				break;
232
+			case 'use_captcha':
233
+				$c->registration->use_captcha = ($value == 'Y');
234
+				break;
235
+			case 'recaptcha_publickey':
236
+				$c->registration->recaptcha_publickey = $value;
237
+				break;
238
+			case 'recaptcha_privatekey':
239
+				$c->registration->recaptcha_privatekey = $value;
240
+				break;
241
+			case 'recaptcha_theme':
242
+				$c->registration->recaptcha_theme = $value;
243
+				break;
244
+			case 'recaptcha_width':
245
+				$c->registration->recaptcha_width = $value;
246
+				break;
247
+			case 'recaptcha_language':
248
+				$c->registration->recaptcha_language = $value;
249
+				break;
250
+			case 'espresso_dashboard_widget':
251
+				$c->admin->use_dashboard_widget = ($value == 'Y');
252
+				break;
253
+			case 'use_personnel_manager':
254
+				$c->admin->use_personnel_manager = ($value == 'Y');
255
+				break;
256
+			case 'use_event_timezones':
257
+				$c->admin->use_event_timezones = ($value == 'Y');
258
+				break;
259
+			case 'affiliate_id':
260
+				$c->admin->affiliate_id = $value;
261
+				break;
262
+			case 'site_license_key':
263
+				$cn->core->site_license_key = $value;
264
+				break;
265
+			default:
266
+				do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value);
267
+		}
268
+	}
269 269
 
270
-    /**
271
-     * Creates a 4.1 member price discount
272
-     * @global type $wpdb
273
-     * @param type $old_price
274
-     * @return int
275
-     */
276
-    private function _insert_new_global_surcharge_price($org_options)
277
-    {
278
-        $amount = floatval($org_options['surcharge']);
279
-        // dont createa a price if the surcharge is 0
280
-        if ($amount <=.01) {
281
-            return 0;
282
-        }
283
-        if ($org_options['surcharge_type'] == 'flat_rate') {
284
-            $price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge;
285
-        } else {
286
-            $price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge;
287
-        }
288
-        global $wpdb;
289
-        $cols_n_values = array(
290
-            'PRT_ID'=>$price_type,
291
-            'PRC_amount'=>$amount,
292
-            'PRC_name'=>  $org_options['surcharge_text'],
293
-            'PRC_is_default'=>true,
294
-            'PRC_overrides'=>false,
295
-            'PRC_order'=>100,
296
-            'PRC_deleted'=>false,
297
-            'PRC_parent'=>null
270
+	/**
271
+	 * Creates a 4.1 member price discount
272
+	 * @global type $wpdb
273
+	 * @param type $old_price
274
+	 * @return int
275
+	 */
276
+	private function _insert_new_global_surcharge_price($org_options)
277
+	{
278
+		$amount = floatval($org_options['surcharge']);
279
+		// dont createa a price if the surcharge is 0
280
+		if ($amount <=.01) {
281
+			return 0;
282
+		}
283
+		if ($org_options['surcharge_type'] == 'flat_rate') {
284
+			$price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge;
285
+		} else {
286
+			$price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge;
287
+		}
288
+		global $wpdb;
289
+		$cols_n_values = array(
290
+			'PRT_ID'=>$price_type,
291
+			'PRC_amount'=>$amount,
292
+			'PRC_name'=>  $org_options['surcharge_text'],
293
+			'PRC_is_default'=>true,
294
+			'PRC_overrides'=>false,
295
+			'PRC_order'=>100,
296
+			'PRC_deleted'=>false,
297
+			'PRC_parent'=>null
298 298
 
299
-        );
300
-        $datatypes = array(
301
-            '%d',// PRT_ID
302
-            '%f',// PRT_amount
303
-            '%s',// PRC_name
304
-            '%d',// PRC_is_default
305
-            '%d',// PRC_overrides
306
-            '%d',// PRC_order
307
-            '%d',// PRC_deleted
308
-            '%d',// PRC_parent
309
-        );
310
-        $price_table = $wpdb->prefix."esp_price";
311
-        $success = $wpdb->insert($price_table, $cols_n_values, $datatypes);
312
-        if (! $success) {
313
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion(
314
-                'org_options',
315
-                array(
316
-                        'surcharge'=>$org_options['surcharge'],
317
-                        'surcharge_type'=>$org_options['surcharge_type'],
318
-                        'surcharge_text'=>$org_options['surcharge_text']),
319
-                $price_table,
320
-                $cols_n_values,
321
-                $datatypes
322
-            ));
323
-            return 0;
324
-        }
325
-        $new_id = $wpdb->insert_id;
326
-        return $new_id;
327
-    }
299
+		);
300
+		$datatypes = array(
301
+			'%d',// PRT_ID
302
+			'%f',// PRT_amount
303
+			'%s',// PRC_name
304
+			'%d',// PRC_is_default
305
+			'%d',// PRC_overrides
306
+			'%d',// PRC_order
307
+			'%d',// PRC_deleted
308
+			'%d',// PRC_parent
309
+		);
310
+		$price_table = $wpdb->prefix."esp_price";
311
+		$success = $wpdb->insert($price_table, $cols_n_values, $datatypes);
312
+		if (! $success) {
313
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion(
314
+				'org_options',
315
+				array(
316
+						'surcharge'=>$org_options['surcharge'],
317
+						'surcharge_type'=>$org_options['surcharge_type'],
318
+						'surcharge_text'=>$org_options['surcharge_text']),
319
+				$price_table,
320
+				$cols_n_values,
321
+				$datatypes
322
+			));
323
+			return 0;
324
+		}
325
+		$new_id = $wpdb->insert_id;
326
+		return $new_id;
327
+	}
328 328
 
329
-    protected $_org_options_we_know_how_to_migrate = array(
330
-      'organization',
331
-      'organization_street1',
332
-      'organization_street2',
333
-      'organization_city',
334
-      'organization_state',
335
-      'organization_zip',
336
-      'contact_email',
337
-      'default_mail',
338
-      'payment_subject',
339
-      'payment_message',
340
-      'message',
341
-      'default_payment_status',
342
-      'surcharge',// unused?
343
-      'country_id',// unused?
344
-      'organization_country',
329
+	protected $_org_options_we_know_how_to_migrate = array(
330
+	  'organization',
331
+	  'organization_street1',
332
+	  'organization_street2',
333
+	  'organization_city',
334
+	  'organization_state',
335
+	  'organization_zip',
336
+	  'contact_email',
337
+	  'default_mail',
338
+	  'payment_subject',
339
+	  'payment_message',
340
+	  'message',
341
+	  'default_payment_status',
342
+	  'surcharge',// unused?
343
+	  'country_id',// unused?
344
+	  'organization_country',
345 345
 //    'currency_symbol',
346
-      'expire_on_registration_end',
347
-      'email_before_payment',
348
-      'email_fancy_headers',
349
-      'enable_default_style',
350
-      'event_ssl_active',
351
-      'selected_style',
352
-      'show_pending_payment_options',
353
-      'show_reg_footer',
354
-      'skip_confirmation_page',
355
-      'allow_mer_discounts',// no equiv
356
-      'allow_mer_vouchers',// no equiv
357
-      'display_short_description_in_event_list',
358
-      'display_description_on_multi_reg_page',
359
-      'display_address_in_event_list',
360
-      'display_address_in_regform',
361
-      'use_custom_post_types',// no equiv
362
-      'display_ical_download',
363
-      'display_featured_image',
364
-      'themeroller',
365
-      'default_logo_url',
366
-      'event_page_id',
367
-      'return_url',
368
-      'cancel_return',
369
-      'notify_url',
370
-      'events_in_dashboard',
371
-      'use_captcha',
372
-      'recaptcha_publickey',
373
-      'recaptcha_privatekey',
374
-      'recaptcha_theme',
375
-      'recaptcha_width',
376
-      'recaptcha_language',
377
-      'espresso_dashboard_widget',
378
-      'time_reg_limit',
346
+	  'expire_on_registration_end',
347
+	  'email_before_payment',
348
+	  'email_fancy_headers',
349
+	  'enable_default_style',
350
+	  'event_ssl_active',
351
+	  'selected_style',
352
+	  'show_pending_payment_options',
353
+	  'show_reg_footer',
354
+	  'skip_confirmation_page',
355
+	  'allow_mer_discounts',// no equiv
356
+	  'allow_mer_vouchers',// no equiv
357
+	  'display_short_description_in_event_list',
358
+	  'display_description_on_multi_reg_page',
359
+	  'display_address_in_event_list',
360
+	  'display_address_in_regform',
361
+	  'use_custom_post_types',// no equiv
362
+	  'display_ical_download',
363
+	  'display_featured_image',
364
+	  'themeroller',
365
+	  'default_logo_url',
366
+	  'event_page_id',
367
+	  'return_url',
368
+	  'cancel_return',
369
+	  'notify_url',
370
+	  'events_in_dashboard',
371
+	  'use_captcha',
372
+	  'recaptcha_publickey',
373
+	  'recaptcha_privatekey',
374
+	  'recaptcha_theme',
375
+	  'recaptcha_width',
376
+	  'recaptcha_language',
377
+	  'espresso_dashboard_widget',
378
+	  'time_reg_limit',
379 379
 //    'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status
380
-      'use_personnel_manager',// no equiv
381
-      'use_event_timezones',
382
-      'full_logging',
383
-      'surcharge_type',// unused
384
-      'surcharge_text',// unused
385
-      'affiliate_id',
386
-      'site_license_key',
387
-    );
380
+	  'use_personnel_manager',// no equiv
381
+	  'use_event_timezones',
382
+	  'full_logging',
383
+	  'surcharge_type',// unused
384
+	  'surcharge_text',// unused
385
+	  'affiliate_id',
386
+	  'site_license_key',
387
+	);
388 388
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_prices.dmsstage.php 3 patches
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
     /**
350 350
      * Adds a join between a ticket and a price
351 351
      * @global type $wpdb
352
-     * @param type $new_ticket_id
353
-     * @param type $new_price_id
352
+     * @param integer $new_ticket_id
353
+     * @param integer $new_price_id
354 354
      * @return int
355 355
      */
356 356
     private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
@@ -376,8 +376,7 @@  discard block
 block discarded – undo
376 376
     /**
377 377
      * Adds a join between a ticket and a datetime
378 378
      * @global type $wpdb
379
-     * @param type $new_ticket_id
380
-     * @param type $new_price_id
379
+     * @param integer $new_ticket_id
381 380
      * @return int
382 381
      */
383 382
     private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
Please login to merge, or discard this patch.
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -87,57 +87,57 @@  discard block
 block discarded – undo
87 87
  */
88 88
 class EE_DMS_4_1_0_prices extends EE_Data_Migration_Script_Stage_Table
89 89
 {
90
-    private $_new_price_table;
91
-    private $_new_ticket_table;
92
-    private $_new_ticket_price_table;
93
-    private $_new_datetime_ticket_table;
94
-    /**
95
-     * A count of all the different tickets created, used for setting the new ones' TKT_Order
96
-     * @var int
97
-     */
98
-    private $_ticket_count = 0;
99
-    const price_type_base = 1;
100
-    const price_type_member_discount = 3;
101
-    const price_type_percent_surcharge = 4;
102
-    const price_type_flat_surcharge = 5;
90
+	private $_new_price_table;
91
+	private $_new_ticket_table;
92
+	private $_new_ticket_price_table;
93
+	private $_new_datetime_ticket_table;
94
+	/**
95
+	 * A count of all the different tickets created, used for setting the new ones' TKT_Order
96
+	 * @var int
97
+	 */
98
+	private $_ticket_count = 0;
99
+	const price_type_base = 1;
100
+	const price_type_member_discount = 3;
101
+	const price_type_percent_surcharge = 4;
102
+	const price_type_flat_surcharge = 5;
103 103
 
104
-    public function __construct()
105
-    {
106
-        global $wpdb;
107
-        $this->_pretty_name = __("Prices", "event_espresso");
108
-        $this->_old_table = $wpdb->prefix."events_prices";
109
-        $this->select_expression = 'p.*, e.event_status';
110
-        $this->_extra_where_sql = ' AS p 
104
+	public function __construct()
105
+	{
106
+		global $wpdb;
107
+		$this->_pretty_name = __("Prices", "event_espresso");
108
+		$this->_old_table = $wpdb->prefix."events_prices";
109
+		$this->select_expression = 'p.*, e.event_status';
110
+		$this->_extra_where_sql = ' AS p 
111 111
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id
112 112
             WHERE e.event_status!="D"';
113
-        $this->_new_price_table = $wpdb->prefix."esp_price";
114
-        $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
115
-        $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
116
-        $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
117
-        parent::__construct();
118
-    }
119
-    protected function _migrate_old_row($old_row)
120
-    {
121
-        // create the base price
122
-        $new_price_id = $this->_insert_new_price($old_row);
123
-        // create the member discount if there is any
124
-        // commented-out because we may actually NOT be supporting this in 4.1
113
+		$this->_new_price_table = $wpdb->prefix."esp_price";
114
+		$this->_new_ticket_table = $wpdb->prefix."esp_ticket";
115
+		$this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
116
+		$this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
117
+		parent::__construct();
118
+	}
119
+	protected function _migrate_old_row($old_row)
120
+	{
121
+		// create the base price
122
+		$new_price_id = $this->_insert_new_price($old_row);
123
+		// create the member discount if there is any
124
+		// commented-out because we may actually NOT be supporting this in 4.1
125 125
 //      if($old_row['event_cost'] != $old_row['member_price']){
126 126
 //          $member_price_discount_id = $this->_insert_new_member_price($old_row);
127 127
 //      }else{
128 128
 //          $member_price_discount_id = 0;
129 129
 //      }
130
-        // create the surcharge if there is any
131
-        if (floatval($old_row['surcharge']) >= 0.01) {
132
-            $surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
134
-        } else {
135
-            $surcharge_price_id = 0;
136
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
137
-        }
138
-        // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice.
139
-        // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one)
140
-        // create ticket
130
+		// create the surcharge if there is any
131
+		if (floatval($old_row['surcharge']) >= 0.01) {
132
+			$surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
134
+		} else {
135
+			$surcharge_price_id = 0;
136
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
137
+		}
138
+		// associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice.
139
+		// if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one)
140
+		// create ticket
141 141
 //      $ticket_id = $this->_insert_new_ticket($old_row);
142 142
 //      if($ticket_id){
143 143
 //          $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $ticket_id);
@@ -149,62 +149,62 @@  discard block
 block discarded – undo
149 149
 //              $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
150 150
 //          }
151 151
 //      }
152
-        // create a ticket for each old price -old datetime combo
153
-        $tickets_for_old_price = array();
154
-        foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) {
155
-            $ticket_id = $this->_insert_new_ticket($old_row);
156
-            $tickets_for_old_price[] = $ticket_id;
157
-            // associate to old prices
158
-            $this->_insert_ticket_price_relation($ticket_id, $new_price_id);
159
-            $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id);
160
-            $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
161
-        }
162
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price);
163
-    }
164
-    /**
165
-     * Creates a 4.1 price base type
166
-     * @global type $wpdb
167
-     * @param type $old_price
168
-     * @return int
169
-     */
170
-    private function _insert_new_price($old_price)
171
-    {
172
-        global $wpdb;
173
-        $cols_n_values = array(
174
-            'PRT_ID'=>self::price_type_base,
175
-            'PRC_amount'=>floatval($old_price['event_cost']),
176
-            'PRC_name'=>$old_price['price_type'],
177
-            'PRC_is_default'=>false,
178
-            'PRC_overrides'=>false,
179
-            'PRC_order'=>0,
180
-            'PRC_deleted'=>false,
181
-            'PRC_parent'=>null
152
+		// create a ticket for each old price -old datetime combo
153
+		$tickets_for_old_price = array();
154
+		foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) {
155
+			$ticket_id = $this->_insert_new_ticket($old_row);
156
+			$tickets_for_old_price[] = $ticket_id;
157
+			// associate to old prices
158
+			$this->_insert_ticket_price_relation($ticket_id, $new_price_id);
159
+			$this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id);
160
+			$this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
161
+		}
162
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price);
163
+	}
164
+	/**
165
+	 * Creates a 4.1 price base type
166
+	 * @global type $wpdb
167
+	 * @param type $old_price
168
+	 * @return int
169
+	 */
170
+	private function _insert_new_price($old_price)
171
+	{
172
+		global $wpdb;
173
+		$cols_n_values = array(
174
+			'PRT_ID'=>self::price_type_base,
175
+			'PRC_amount'=>floatval($old_price['event_cost']),
176
+			'PRC_name'=>$old_price['price_type'],
177
+			'PRC_is_default'=>false,
178
+			'PRC_overrides'=>false,
179
+			'PRC_order'=>0,
180
+			'PRC_deleted'=>false,
181
+			'PRC_parent'=>null
182 182
 
183
-        );
184
-        $datatypes = array(
185
-            '%d',// PRT_ID
186
-            '%f',// PRT_amount
187
-            '%s',// PRC_name
188
-            '%d',// PRC_is_default
189
-            '%d',// PRC_overrides
190
-            '%d',// PRC_order
191
-            '%d',// PRC_deleted
192
-            '%d',// PRC_parent
193
-        );
194
-        $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
-        if (! $success) {
196
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197
-            return 0;
198
-        }
199
-        $new_id = $wpdb->insert_id;
200
-        return $new_id;
201
-    }
202
-    /**
203
-     * Creates a 4.1 member price discount
204
-     * @global type $wpdb
205
-     * @param type $old_price
206
-     * @return int
207
-     */
183
+		);
184
+		$datatypes = array(
185
+			'%d',// PRT_ID
186
+			'%f',// PRT_amount
187
+			'%s',// PRC_name
188
+			'%d',// PRC_is_default
189
+			'%d',// PRC_overrides
190
+			'%d',// PRC_order
191
+			'%d',// PRC_deleted
192
+			'%d',// PRC_parent
193
+		);
194
+		$success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
+		if (! $success) {
196
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197
+			return 0;
198
+		}
199
+		$new_id = $wpdb->insert_id;
200
+		return $new_id;
201
+	}
202
+	/**
203
+	 * Creates a 4.1 member price discount
204
+	 * @global type $wpdb
205
+	 * @param type $old_price
206
+	 * @return int
207
+	 */
208 208
 //  private function _insert_new_member_price($old_price){
209 209
 //      $discount_amount = floatval($old_price['event_cost']) - floatval($old_price['member_price']);
210 210
 //      global $wpdb;
@@ -237,207 +237,207 @@  discard block
 block discarded – undo
237 237
 //      $new_id = $wpdb->insert_id;
238 238
 //      return $new_id;
239 239
 //  }
240
-    /**
241
-     * Creates a 4.1 member price discount
242
-     * @global type $wpdb
243
-     * @param type $old_price
244
-     * @return int
245
-     */
246
-    private function _insert_new_surcharge_price($old_price)
247
-    {
240
+	/**
241
+	 * Creates a 4.1 member price discount
242
+	 * @global type $wpdb
243
+	 * @param type $old_price
244
+	 * @return int
245
+	 */
246
+	private function _insert_new_surcharge_price($old_price)
247
+	{
248 248
 
249
-        if ($old_price['surcharge_type'] == 'flat_rate') {
250
-            $price_type = self::price_type_flat_surcharge;
251
-        } else {
252
-            $price_type = self::price_type_percent_surcharge;
253
-        }
254
-        global $wpdb;
255
-        $cols_n_values = array(
256
-            'PRT_ID'=>$price_type,
257
-            'PRC_amount'=>floatval($old_price['surcharge']),
258
-            'PRC_name'=>  __("Surcharge", "event_espresso"),
259
-            'PRC_is_default'=>false,
260
-            'PRC_overrides'=>false,
261
-            'PRC_order'=>20,
262
-            'PRC_deleted'=>false,
263
-            'PRC_parent'=>null
249
+		if ($old_price['surcharge_type'] == 'flat_rate') {
250
+			$price_type = self::price_type_flat_surcharge;
251
+		} else {
252
+			$price_type = self::price_type_percent_surcharge;
253
+		}
254
+		global $wpdb;
255
+		$cols_n_values = array(
256
+			'PRT_ID'=>$price_type,
257
+			'PRC_amount'=>floatval($old_price['surcharge']),
258
+			'PRC_name'=>  __("Surcharge", "event_espresso"),
259
+			'PRC_is_default'=>false,
260
+			'PRC_overrides'=>false,
261
+			'PRC_order'=>20,
262
+			'PRC_deleted'=>false,
263
+			'PRC_parent'=>null
264 264
 
265
-        );
266
-        $datatypes = array(
267
-            '%d',// PRT_ID
268
-            '%f',// PRT_amount
269
-            '%s',// PRC_name
270
-            '%d',// PRC_is_default
271
-            '%d',// PRC_overrides
272
-            '%d',// PRC_order
273
-            '%d',// PRC_deleted
274
-            '%d',// PRC_parent
275
-        );
276
-        $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
-        if (! $success) {
278
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279
-            return 0;
280
-        }
281
-        $new_id = $wpdb->insert_id;
282
-        return $new_id;
283
-    }
284
-    /**
285
-     * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price
286
-     * @param $old_price_row array where keys are columns
287
-     * @param $new_base_price_id int
288
-     * @param $new_member_discount_id int
289
-     * @param $new_surcharge_id int
290
-     * @return int new ticket id
291
-     */
292
-    private function _insert_new_ticket($old_price_row)
293
-    {
294
-        global $wpdb;
295
-        $event_row = $this->_get_event_row($old_price_row['event_id']);
296
-        if ($old_price_row['surcharge_type'] == 'flat_rate') {
297
-            $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298
-        } else {// percent surcharge
299
-            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
300
-        }
301
-        $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302
-        $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
303
-        $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304
-        $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305
-        $cols_n_values = array(
306
-            'TTM_ID'=>0,
307
-            'TKT_name'=>$old_price_row['price_type'],
308
-            'TKT_description'=>'',
309
-            'TKT_start_date'=>$start_date_utc,
310
-            'TKT_end_date'=>$end_date_utc,
311
-            'TKT_min'=>0,
312
-            'TKT_max'=>-1,
313
-            'TKT_price'=>$final_ticket_price,
314
-            'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
315
-            'TKT_qty'=> -1,
316
-            'TKT_uses'=> 1,
317
-            'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318
-            'TKT_is_default'=>false,
319
-            'TKT_order'=>$this->_get_ticket_count(),
320
-            'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
321
-            'TKT_deleted'=>false,
322
-            'TKT_parent'=>0
265
+		);
266
+		$datatypes = array(
267
+			'%d',// PRT_ID
268
+			'%f',// PRT_amount
269
+			'%s',// PRC_name
270
+			'%d',// PRC_is_default
271
+			'%d',// PRC_overrides
272
+			'%d',// PRC_order
273
+			'%d',// PRC_deleted
274
+			'%d',// PRC_parent
275
+		);
276
+		$success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
+		if (! $success) {
278
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279
+			return 0;
280
+		}
281
+		$new_id = $wpdb->insert_id;
282
+		return $new_id;
283
+	}
284
+	/**
285
+	 * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price
286
+	 * @param $old_price_row array where keys are columns
287
+	 * @param $new_base_price_id int
288
+	 * @param $new_member_discount_id int
289
+	 * @param $new_surcharge_id int
290
+	 * @return int new ticket id
291
+	 */
292
+	private function _insert_new_ticket($old_price_row)
293
+	{
294
+		global $wpdb;
295
+		$event_row = $this->_get_event_row($old_price_row['event_id']);
296
+		if ($old_price_row['surcharge_type'] == 'flat_rate') {
297
+			$final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298
+		} else {// percent surcharge
299
+			$final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
300
+		}
301
+		$start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302
+		$start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
303
+		$end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304
+		$end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305
+		$cols_n_values = array(
306
+			'TTM_ID'=>0,
307
+			'TKT_name'=>$old_price_row['price_type'],
308
+			'TKT_description'=>'',
309
+			'TKT_start_date'=>$start_date_utc,
310
+			'TKT_end_date'=>$end_date_utc,
311
+			'TKT_min'=>0,
312
+			'TKT_max'=>-1,
313
+			'TKT_price'=>$final_ticket_price,
314
+			'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
315
+			'TKT_qty'=> -1,
316
+			'TKT_uses'=> 1,
317
+			'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318
+			'TKT_is_default'=>false,
319
+			'TKT_order'=>$this->_get_ticket_count(),
320
+			'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
321
+			'TKT_deleted'=>false,
322
+			'TKT_parent'=>0
323 323
 
324
-        );
325
-        $datatypes = array(
326
-            '%d',// TTM_ID
327
-            '%s',// TKT_name
328
-            '%s',// TKT_description
329
-            '%s',// TKT_start_date
330
-            '%s',// TKT_end_date
331
-            '%d',// TKT_min
332
-            '%d',// TKT_max
333
-            '%f',// TKT_price
334
-            '%d',// TKT_sold
335
-            '%d',// TKT_qty
336
-            '%d',// TKT_uses
337
-            '%d',// TKT_taxable
338
-            '%d',// TKT_is_default
339
-            '%d',// TKT_order
340
-            '%d',// TKT_row
341
-            '%d',// TKT_deleted
342
-            '%d',// TKT_parent
343
-        );
344
-        $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
-        if (! $success) {
346
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347
-            return 0;
348
-        }
349
-        $new_id = $wpdb->insert_id;
350
-        return $new_id;
351
-    }
324
+		);
325
+		$datatypes = array(
326
+			'%d',// TTM_ID
327
+			'%s',// TKT_name
328
+			'%s',// TKT_description
329
+			'%s',// TKT_start_date
330
+			'%s',// TKT_end_date
331
+			'%d',// TKT_min
332
+			'%d',// TKT_max
333
+			'%f',// TKT_price
334
+			'%d',// TKT_sold
335
+			'%d',// TKT_qty
336
+			'%d',// TKT_uses
337
+			'%d',// TKT_taxable
338
+			'%d',// TKT_is_default
339
+			'%d',// TKT_order
340
+			'%d',// TKT_row
341
+			'%d',// TKT_deleted
342
+			'%d',// TKT_parent
343
+		);
344
+		$success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
+		if (! $success) {
346
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347
+			return 0;
348
+		}
349
+		$new_id = $wpdb->insert_id;
350
+		return $new_id;
351
+	}
352 352
 
353
-    /**
354
-     * Adds a join between a ticket and a price
355
-     * @global type $wpdb
356
-     * @param type $new_ticket_id
357
-     * @param type $new_price_id
358
-     * @return int
359
-     */
360
-    private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
361
-    {
362
-        global $wpdb;
363
-        $cols_n_values = array(
364
-            'TKT_ID'=>$new_ticket_id,
365
-            'PRC_ID'=>$new_price_id,
366
-        );
367
-        $datatypes = array(
368
-            '%d',// TKT_ID
369
-            '%d',// PRC_ID
370
-        );
371
-        $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
-        if (! $success) {
373
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374
-            return 0;
375
-        }
376
-        $new_id = $wpdb->insert_id;
377
-        return $new_id;
378
-    }
353
+	/**
354
+	 * Adds a join between a ticket and a price
355
+	 * @global type $wpdb
356
+	 * @param type $new_ticket_id
357
+	 * @param type $new_price_id
358
+	 * @return int
359
+	 */
360
+	private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
361
+	{
362
+		global $wpdb;
363
+		$cols_n_values = array(
364
+			'TKT_ID'=>$new_ticket_id,
365
+			'PRC_ID'=>$new_price_id,
366
+		);
367
+		$datatypes = array(
368
+			'%d',// TKT_ID
369
+			'%d',// PRC_ID
370
+		);
371
+		$success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
+		if (! $success) {
373
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374
+			return 0;
375
+		}
376
+		$new_id = $wpdb->insert_id;
377
+		return $new_id;
378
+	}
379 379
 
380
-    /**
381
-     * Adds a join between a ticket and a datetime
382
-     * @global type $wpdb
383
-     * @param type $new_ticket_id
384
-     * @param type $new_price_id
385
-     * @return int
386
-     */
387
-    private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
388
-    {
389
-        global $wpdb;
390
-        $cols_n_values = array(
391
-            'TKT_ID'=>$new_ticket_id,
392
-            'DTT_ID'=>$new_datetime_id,
393
-        );
394
-        $datatypes = array(
395
-            '%d',// TKT_ID
396
-            '%d',// DTT_ID
397
-        );
398
-        $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
-        if (! $success) {
400
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401
-            return 0;
402
-        }
403
-        $new_id = $wpdb->insert_id;
404
-        return $new_id;
405
-    }
380
+	/**
381
+	 * Adds a join between a ticket and a datetime
382
+	 * @global type $wpdb
383
+	 * @param type $new_ticket_id
384
+	 * @param type $new_price_id
385
+	 * @return int
386
+	 */
387
+	private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
388
+	{
389
+		global $wpdb;
390
+		$cols_n_values = array(
391
+			'TKT_ID'=>$new_ticket_id,
392
+			'DTT_ID'=>$new_datetime_id,
393
+		);
394
+		$datatypes = array(
395
+			'%d',// TKT_ID
396
+			'%d',// DTT_ID
397
+		);
398
+		$success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
+		if (! $success) {
400
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401
+			return 0;
402
+		}
403
+		$new_id = $wpdb->insert_id;
404
+		return $new_id;
405
+	}
406 406
 
407
-    /**
408
-     * Simply gets the 3.1 event row data
409
-     * @global type $wpdb
410
-     * @param type $event_id
411
-     * @return array
412
-     */
413
-    private function _get_event_row($event_id)
414
-    {
415
-        global $wpdb;
416
-        $old_event_table = $wpdb->prefix."events_detail";
417
-        return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418
-    }
419
-    /**
420
-     * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests).
421
-     * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too
422
-     * @return int
423
-     */
424
-    private function _get_ticket_count()
425
-    {
426
-        return $this->_ticket_count++;
427
-    }
407
+	/**
408
+	 * Simply gets the 3.1 event row data
409
+	 * @global type $wpdb
410
+	 * @param type $event_id
411
+	 * @return array
412
+	 */
413
+	private function _get_event_row($event_id)
414
+	{
415
+		global $wpdb;
416
+		$old_event_table = $wpdb->prefix."events_detail";
417
+		return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418
+	}
419
+	/**
420
+	 * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests).
421
+	 * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too
422
+	 * @return int
423
+	 */
424
+	private function _get_ticket_count()
425
+	{
426
+		return $this->_ticket_count++;
427
+	}
428 428
 
429
-    /**
430
-     * Using the 3.1 event id, gets the 4.1 datetimes for it
431
-     * @param int $old_event_id
432
-     * @return array where values are datetime ids
433
-     */
434
-    private function _get_datetime_ids_for_old_event_id($old_event_id)
435
-    {
436
-        global $wpdb;
437
-        $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438
-        $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439
-        return $datetime_ids;
440
-    }
429
+	/**
430
+	 * Using the 3.1 event id, gets the 4.1 datetimes for it
431
+	 * @param int $old_event_id
432
+	 * @return array where values are datetime ids
433
+	 */
434
+	private function _get_datetime_ids_for_old_event_id($old_event_id)
435
+	{
436
+		global $wpdb;
437
+		$new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438
+		$datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439
+		return $datetime_ids;
440
+	}
441 441
 }
442 442
 // @todo: tell users that in 3.1 the limit was on registration PER event,in 4.1 it's limit PER TICKET... SO, if they sell 2 different types of tickets
443 443
 //
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         $this->_old_table = $wpdb->prefix."events_prices";
109 109
         $this->select_expression = 'p.*, e.event_status';
110 110
         $this->_extra_where_sql = ' AS p 
111
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id
111
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON p.event_id=e.id
112 112
             WHERE e.event_status!="D"';
113 113
         $this->_new_price_table = $wpdb->prefix."esp_price";
114 114
         $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         // create the surcharge if there is any
131 131
         if (floatval($old_row['surcharge']) >= 0.01) {
132 132
             $surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
133
+            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id, $surcharge_price_id));
134 134
         } else {
135 135
             $surcharge_price_id = 0;
136 136
             $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
 
183 183
         );
184 184
         $datatypes = array(
185
-            '%d',// PRT_ID
186
-            '%f',// PRT_amount
187
-            '%s',// PRC_name
188
-            '%d',// PRC_is_default
189
-            '%d',// PRC_overrides
190
-            '%d',// PRC_order
191
-            '%d',// PRC_deleted
192
-            '%d',// PRC_parent
185
+            '%d', // PRT_ID
186
+            '%f', // PRT_amount
187
+            '%s', // PRC_name
188
+            '%d', // PRC_is_default
189
+            '%d', // PRC_overrides
190
+            '%d', // PRC_order
191
+            '%d', // PRC_deleted
192
+            '%d', // PRC_parent
193 193
         );
194 194
         $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
-        if (! $success) {
195
+        if ( ! $success) {
196 196
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197 197
             return 0;
198 198
         }
@@ -264,17 +264,17 @@  discard block
 block discarded – undo
264 264
 
265 265
         );
266 266
         $datatypes = array(
267
-            '%d',// PRT_ID
268
-            '%f',// PRT_amount
269
-            '%s',// PRC_name
270
-            '%d',// PRC_is_default
271
-            '%d',// PRC_overrides
272
-            '%d',// PRC_order
273
-            '%d',// PRC_deleted
274
-            '%d',// PRC_parent
267
+            '%d', // PRT_ID
268
+            '%f', // PRT_amount
269
+            '%s', // PRC_name
270
+            '%d', // PRC_is_default
271
+            '%d', // PRC_overrides
272
+            '%d', // PRC_order
273
+            '%d', // PRC_deleted
274
+            '%d', // PRC_parent
275 275
         );
276 276
         $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
-        if (! $success) {
277
+        if ( ! $success) {
278 278
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279 279
             return 0;
280 280
         }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
         if ($old_price_row['surcharge_type'] == 'flat_rate') {
297 297
             $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298 298
         } else {// percent surcharge
299
-            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
299
+            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100);
300 300
         }
301 301
         $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302 302
         $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
@@ -311,38 +311,38 @@  discard block
 block discarded – undo
311 311
             'TKT_min'=>0,
312 312
             'TKT_max'=>-1,
313 313
             'TKT_price'=>$final_ticket_price,
314
-            'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
314
+            'TKT_sold'=> 0, // note: this will get calculated as we actually add registrations during the migration
315 315
             'TKT_qty'=> -1,
316 316
             'TKT_uses'=> 1,
317
-            'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
317
+            'TKT_taxable'=>false, // so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318 318
             'TKT_is_default'=>false,
319 319
             'TKT_order'=>$this->_get_ticket_count(),
320
-            'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
320
+            'TKT_row'=>0, // doesn't matter because UI reset this on first save anyways
321 321
             'TKT_deleted'=>false,
322 322
             'TKT_parent'=>0
323 323
 
324 324
         );
325 325
         $datatypes = array(
326
-            '%d',// TTM_ID
327
-            '%s',// TKT_name
328
-            '%s',// TKT_description
329
-            '%s',// TKT_start_date
330
-            '%s',// TKT_end_date
331
-            '%d',// TKT_min
332
-            '%d',// TKT_max
333
-            '%f',// TKT_price
334
-            '%d',// TKT_sold
335
-            '%d',// TKT_qty
336
-            '%d',// TKT_uses
337
-            '%d',// TKT_taxable
338
-            '%d',// TKT_is_default
339
-            '%d',// TKT_order
340
-            '%d',// TKT_row
341
-            '%d',// TKT_deleted
342
-            '%d',// TKT_parent
326
+            '%d', // TTM_ID
327
+            '%s', // TKT_name
328
+            '%s', // TKT_description
329
+            '%s', // TKT_start_date
330
+            '%s', // TKT_end_date
331
+            '%d', // TKT_min
332
+            '%d', // TKT_max
333
+            '%f', // TKT_price
334
+            '%d', // TKT_sold
335
+            '%d', // TKT_qty
336
+            '%d', // TKT_uses
337
+            '%d', // TKT_taxable
338
+            '%d', // TKT_is_default
339
+            '%d', // TKT_order
340
+            '%d', // TKT_row
341
+            '%d', // TKT_deleted
342
+            '%d', // TKT_parent
343 343
         );
344 344
         $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
-        if (! $success) {
345
+        if ( ! $success) {
346 346
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347 347
             return 0;
348 348
         }
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
             'PRC_ID'=>$new_price_id,
366 366
         );
367 367
         $datatypes = array(
368
-            '%d',// TKT_ID
369
-            '%d',// PRC_ID
368
+            '%d', // TKT_ID
369
+            '%d', // PRC_ID
370 370
         );
371 371
         $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
-        if (! $success) {
373
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
372
+        if ( ! $success) {
373
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374 374
             return 0;
375 375
         }
376 376
         $new_id = $wpdb->insert_id;
@@ -392,12 +392,12 @@  discard block
 block discarded – undo
392 392
             'DTT_ID'=>$new_datetime_id,
393 393
         );
394 394
         $datatypes = array(
395
-            '%d',// TKT_ID
396
-            '%d',// DTT_ID
395
+            '%d', // TKT_ID
396
+            '%d', // DTT_ID
397 397
         );
398 398
         $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
-        if (! $success) {
400
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
399
+        if ( ! $success) {
400
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401 401
             return 0;
402 402
         }
403 403
         $new_id = $wpdb->insert_id;
Please login to merge, or discard this patch.