Completed
Branch FET/reg-form-builder/main (d0d867)
by
unknown
09:57 queued 24s
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.
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.
Indentation   +1517 added lines, -1517 removed lines patch added patch discarded remove patch
@@ -17,1523 +17,1523 @@
 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
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
245
-                // 'help_tour'     => array('Venues_Overview_Help_Tour'),
246
-                'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
247
-                'require_nonce' => false,
248
-            ),
249
-            'create_new'          => array(
250
-                'nav'           => array(
251
-                    'label'      => __('Add Venue', 'event_espresso'),
252
-                    'order'      => 5,
253
-                    'persistent' => false,
254
-                ),
255
-                'help_tabs'     => array(
256
-                    'venues_editor_help_tab'                                               => array(
257
-                        'title'    => __('Venue Editor', 'event_espresso'),
258
-                        'filename' => 'venues_editor',
259
-                    ),
260
-                    'venues_editor_title_richtexteditor_help_tab'                          => array(
261
-                        'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
262
-                        'filename' => 'venues_editor_title_richtexteditor',
263
-                    ),
264
-                    'venues_editor_tags_categories_help_tab'                               => array(
265
-                        'title'    => __('Venue Tags & Categories', 'event_espresso'),
266
-                        'filename' => 'venues_editor_tags_categories',
267
-                    ),
268
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
269
-                        'title'    => __(
270
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
271
-                            'event_espresso'
272
-                        ),
273
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
274
-                    ),
275
-                    'venues_editor_save_new_venue_help_tab'                                => array(
276
-                        'title'    => __('Save New Venue', 'event_espresso'),
277
-                        'filename' => 'venues_editor_save_new_venue',
278
-                    ),
279
-                    'venues_editor_other_help_tab'                                         => array(
280
-                        'title'    => __('Venue Editor Other', 'event_espresso'),
281
-                        'filename' => 'venues_editor_other',
282
-                    ),
283
-                ),
284
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
285
-                // 'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
286
-                'metaboxes'     => array('_venue_editor_metaboxes'),
287
-                'require_nonce' => false,
288
-            ),
289
-            'edit'                => array(
290
-                'nav'           => array(
291
-                    'label'      => __('Edit Venue', 'event_espresso'),
292
-                    'order'      => 5,
293
-                    'persistent' => false,
294
-                    'url'        => isset($this->_req_data['post']) ? add_query_arg(
295
-                        array('post' => $this->_req_data['post']),
296
-                        $this->_current_page_view_url
297
-                    ) : $this->_admin_base_url,
298
-                ),
299
-                'help_tabs'     => array(
300
-                    'venues_editor_help_tab'                                               => array(
301
-                        'title'    => __('Venue Editor', 'event_espresso'),
302
-                        'filename' => 'venues_editor',
303
-                    ),
304
-                    'venues_editor_title_richtexteditor_help_tab'                          => array(
305
-                        'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
306
-                        'filename' => 'venues_editor_title_richtexteditor',
307
-                    ),
308
-                    'venues_editor_tags_categories_help_tab'                               => array(
309
-                        'title'    => __('Venue Tags & Categories', 'event_espresso'),
310
-                        'filename' => 'venues_editor_tags_categories',
311
-                    ),
312
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
313
-                        'title'    => __(
314
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
315
-                            'event_espresso'
316
-                        ),
317
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
318
-                    ),
319
-                    'venues_editor_save_new_venue_help_tab'                                => array(
320
-                        'title'    => __('Save New Venue', 'event_espresso'),
321
-                        'filename' => 'venues_editor_save_new_venue',
322
-                    ),
323
-                    'venues_editor_other_help_tab'                                         => array(
324
-                        'title'    => __('Venue Editor Other', 'event_espresso'),
325
-                        'filename' => 'venues_editor_other',
326
-                    ),
327
-                ),
328
-                /*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
329
-                'metaboxes'     => array('_venue_editor_metaboxes'),
330
-                'require_nonce' => false,
331
-            ),
332
-            'google_map_settings' => array(
333
-                'nav'           => array(
334
-                    'label' => esc_html__('Google Maps', 'event_espresso'),
335
-                    'order' => 40,
336
-                ),
337
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
338
-                'help_tabs'     => array(
339
-                    'general_settings_google_maps_help_tab' => array(
340
-                        'title'    => __('Google Maps', 'event_espresso'),
341
-                        'filename' => 'general_settings_google_maps',
342
-                    ),
343
-                ),
344
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
345
-                // 'help_tour'     => array('Google_Maps_Help_Tour'),
346
-                'require_nonce' => false,
347
-            ),
348
-            // venue category stuff
349
-            'add_category'        => array(
350
-                'nav'           => array(
351
-                    'label'      => __('Add Category', 'event_espresso'),
352
-                    'order'      => 15,
353
-                    'persistent' => false,
354
-                ),
355
-                'metaboxes'     => array('_publish_post_box'),
356
-                'help_tabs'     => array(
357
-                    'venues_add_category_help_tab' => array(
358
-                        'title'    => __('Add New Venue Category', 'event_espresso'),
359
-                        'filename' => 'venues_add_category',
360
-                    ),
361
-                ),
362
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
363
-                // 'help_tour'     => array('Venues_Add_Category_Help_Tour'),
364
-                'require_nonce' => false,
365
-            ),
366
-            'edit_category'       => array(
367
-                'nav'           => array(
368
-                    'label'      => __('Edit Category', 'event_espresso'),
369
-                    'order'      => 15,
370
-                    'persistent' => false,
371
-                    'url'        => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(
372
-                        array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
373
-                        $this->_current_page_view_url
374
-                    ) : $this->_admin_base_url,
375
-                ),
376
-                'metaboxes'     => array('_publish_post_box'),
377
-                'help_tabs'     => array(
378
-                    'venues_edit_category_help_tab' => array(
379
-                        'title'    => __('Edit Venue Category', 'event_espresso'),
380
-                        'filename' => 'venues_edit_category',
381
-                    ),
382
-                ),
383
-                /*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
384
-                'require_nonce' => false,
385
-            ),
386
-            'category_list'       => array(
387
-                'nav'           => array(
388
-                    'label' => __('Categories', 'event_espresso'),
389
-                    'order' => 20,
390
-                ),
391
-                'list_table'    => 'Venue_Categories_Admin_List_Table',
392
-                'help_tabs'     => array(
393
-                    'venues_categories_help_tab'                       => array(
394
-                        'title'    => __('Venue Categories', 'event_espresso'),
395
-                        'filename' => 'venues_categories',
396
-                    ),
397
-                    'venues_categories_table_column_headings_help_tab' => array(
398
-                        'title'    => __('Venue Categories Table Column Headings', 'event_espresso'),
399
-                        'filename' => 'venues_categories_table_column_headings',
400
-                    ),
401
-                    'venues_categories_views_help_tab'                 => array(
402
-                        'title'    => __('Venue Categories Views', 'event_espresso'),
403
-                        'filename' => 'venues_categories_views',
404
-                    ),
405
-                    'venues_categories_other_help_tab'                 => array(
406
-                        'title'    => __('Venue Categories Other', 'event_espresso'),
407
-                        'filename' => 'venues_categories_other',
408
-                    ),
409
-                ),
410
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
411
-                // 'help_tour'     => array('Venues_Categories_Help_Tour'),
412
-                'metaboxes'     => $this->_default_espresso_metaboxes,
413
-                'require_nonce' => false,
414
-            ),
415
-        );
416
-    }
417
-
418
-
419
-    protected function _add_screen_options()
420
-    {
421
-        // todo
422
-    }
423
-
424
-
425
-    protected function _add_screen_options_default()
426
-    {
427
-        $this->_per_page_screen_option();
428
-    }
429
-
430
-
431
-    protected function _add_screen_options_category_list()
432
-    {
433
-        $page_title = $this->_admin_page_title;
434
-        $this->_admin_page_title = __('Venue Categories', 'event_espresso');
435
-        $this->_per_page_screen_option();
436
-        $this->_admin_page_title = $page_title;
437
-    }
438
-
439
-
440
-    // none of the below group are currently used for Event Venues
441
-    protected function _add_feature_pointers()
442
-    {
443
-    }
444
-
445
-    public function admin_init()
446
-    {
447
-    }
448
-
449
-    public function admin_notices()
450
-    {
451
-    }
452
-
453
-    public function admin_footer_scripts()
454
-    {
455
-    }
456
-
457
-
458
-    public function load_scripts_styles_create_new()
459
-    {
460
-        $this->load_scripts_styles_edit();
461
-    }
462
-
463
-
464
-    public function load_scripts_styles()
465
-    {
466
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
467
-        wp_enqueue_style('ee-cat-admin');
468
-    }
469
-
470
-
471
-    public function load_scripts_styles_add_category()
472
-    {
473
-        $this->load_scripts_styles_edit_category();
474
-    }
475
-
476
-
477
-    public function load_scripts_styles_edit_category()
478
-    {
479
-    }
480
-
481
-
482
-    public function load_scripts_styles_edit()
483
-    {
484
-        // styles
485
-        wp_enqueue_style('espresso-ui-theme');
486
-        wp_register_style(
487
-            'espresso_venues',
488
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
489
-            array(),
490
-            EVENT_ESPRESSO_VERSION
491
-        );
492
-        wp_enqueue_style('espresso_venues');
493
-    }
494
-
495
-
496
-    protected function _set_list_table_views_default()
497
-    {
498
-        $this->_views = array(
499
-            'all' => array(
500
-                'slug'        => 'all',
501
-                'label'       => __('View All Venues', 'event_espresso'),
502
-                'count'       => 0,
503
-                'bulk_action' => array(),
504
-            ),
505
-        );
506
-
507
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
508
-            $this->_views['all']['bulk_action'] = array(
509
-                'trash_venues' => __('Move to Trash', 'event_espresso'),
510
-            );
511
-            $this->_views['trash'] = array(
512
-                'slug'        => 'trash',
513
-                'label'       => __('Trash', 'event_espresso'),
514
-                'count'       => 0,
515
-                'bulk_action' => array(
516
-                    'restore_venues' => __('Restore from Trash', 'event_espresso'),
517
-                    'delete_venues'  => __('Delete', 'event_espresso'),
518
-                ),
519
-            );
520
-        }
521
-    }
522
-
523
-
524
-    protected function _set_list_table_views_category_list()
525
-    {
526
-        $this->_views = array(
527
-            'all' => array(
528
-                'slug'        => 'all',
529
-                'label'       => __('All', 'event_espresso'),
530
-                'count'       => 0,
531
-                'bulk_action' => array(
532
-                    'delete_categories' => __('Delete Permanently', 'event_espresso'),
533
-                ),
534
-            ),
535
-        );
536
-    }
537
-
538
-
539
-    protected function _overview_list_table()
540
-    {
541
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
542
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
543
-            get_post_type_archive_link('espresso_venues'),
544
-            __("View Venue Archive Page", "event_espresso"),
545
-            'button'
546
-        );
547
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
548
-        $this->_search_btn_label = __('Venues', 'event_espresso');
549
-        $this->display_admin_list_table_page_with_sidebar();
550
-    }
551
-
552
-
553
-    public function extra_misc_actions_publish_box()
554
-    {
555
-        $extra_rows = array(
556
-            'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
557
-            'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
558
-            'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
559
-        );
560
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
561
-        EEH_Template::display_template($template, $extra_rows);
562
-    }
563
-
564
-
565
-    /*************        Google Maps        *************/
566
-
567
-
568
-    protected function _google_map_settings()
569
-    {
570
-
571
-
572
-        $this->_template_args['values'] = $this->_yes_no_values;
573
-        $default_map_settings = new stdClass();
574
-        $default_map_settings->use_google_maps = true;
575
-        $default_map_settings->google_map_api_key = '';
576
-        // for event details pages (reg page)
577
-        $default_map_settings->event_details_map_width = 585;            // ee_map_width_single
578
-        $default_map_settings->event_details_map_height = 362;            // ee_map_height_single
579
-        $default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
580
-        $default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
581
-        $default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
582
-        $default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
583
-        $default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
584
-        // for event list pages
585
-        $default_map_settings->event_list_map_width = 300;            // ee_map_width
586
-        $default_map_settings->event_list_map_height = 185;        // ee_map_height
587
-        $default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
588
-        $default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
589
-        $default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
590
-        $default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
591
-        $default_map_settings->event_list_map_align = 'center';            // ee_map_align
592
-
593
-        $this->_template_args['map_settings'] =
594
-            isset(EE_Registry::instance()->CFG->map_settings)
595
-            && ! empty(EE_Registry::instance()->CFG->map_settings)
596
-                ? (object) array_merge(
597
-                    (array) $default_map_settings,
598
-                    (array) EE_Registry::instance()->CFG->map_settings
599
-                )
600
-                : $default_map_settings;
601
-
602
-        $this->_set_add_edit_form_tags('update_google_map_settings');
603
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
604
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
605
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
606
-            $this->_template_args,
607
-            true
608
-        );
609
-        $this->display_admin_page_with_sidebar();
610
-    }
611
-
612
-    protected function _update_google_map_settings()
613
-    {
614
-
615
-        EE_Registry::instance()->CFG->map_settings->use_google_maps =
616
-            isset($this->_req_data['use_google_maps'])
617
-                ? absint($this->_req_data['use_google_maps'])
618
-                : EE_Registry::instance()->CFG->map_settings->use_google_maps;
619
-
620
-        EE_Registry::instance()->CFG->map_settings->google_map_api_key =
621
-            isset($this->_req_data['google_map_api_key'])
622
-                ? sanitize_text_field($this->_req_data['google_map_api_key'])
623
-                : EE_Registry::instance()->CFG->map_settings->google_map_api_key;
624
-
625
-        EE_Registry::instance()->CFG->map_settings->event_details_map_width =
626
-            isset($this->_req_data['event_details_map_width'])
627
-                ? absint($this->_req_data['event_details_map_width'])
628
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_width;
629
-
630
-        EE_Registry::instance()->CFG->map_settings->event_details_map_height =
631
-            isset($this->_req_data['event_details_map_height'])
632
-                ? absint($this->_req_data['event_details_map_height'])
633
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_height;
634
-
635
-        EE_Registry::instance()->CFG->map_settings->event_details_map_zoom =
636
-            isset($this->_req_data['event_details_map_zoom'])
637
-                ? absint($this->_req_data['event_details_map_zoom'])
638
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_zoom;
639
-
640
-        EE_Registry::instance()->CFG->map_settings->event_details_display_nav =
641
-            isset($this->_req_data['event_details_display_nav'])
642
-                ? absint($this->_req_data['event_details_display_nav'])
643
-                : EE_Registry::instance()->CFG->map_settings->event_details_display_nav;
644
-
645
-        EE_Registry::instance()->CFG->map_settings->event_details_nav_size =
646
-            isset($this->_req_data['event_details_nav_size'])
647
-                ? absint($this->_req_data['event_details_nav_size'])
648
-                : EE_Registry::instance()->CFG->map_settings->event_details_nav_size;
649
-
650
-        EE_Registry::instance()->CFG->map_settings->event_details_control_type =
651
-            isset($this->_req_data['event_details_control_type'])
652
-                ? sanitize_text_field($this->_req_data['event_details_control_type'])
653
-                : EE_Registry::instance()->CFG->map_settings->event_details_control_type;
654
-
655
-        EE_Registry::instance()->CFG->map_settings->event_details_map_align =
656
-            isset($this->_req_data['event_details_map_align'])
657
-                ? sanitize_text_field($this->_req_data['event_details_map_align'])
658
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_align;
659
-
660
-        EE_Registry::instance()->CFG->map_settings->event_list_map_width =
661
-            isset($this->_req_data['event_list_map_width'])
662
-                ? absint($this->_req_data['event_list_map_width'])
663
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_width;
664
-
665
-        EE_Registry::instance()->CFG->map_settings->event_list_map_height =
666
-            isset($this->_req_data['event_list_map_height'])
667
-                ? absint($this->_req_data['event_list_map_height'])
668
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_height;
669
-
670
-        EE_Registry::instance()->CFG->map_settings->event_list_map_zoom =
671
-            isset($this->_req_data['event_list_map_zoom'])
672
-                ? absint($this->_req_data['event_list_map_zoom'])
673
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_zoom;
674
-
675
-        EE_Registry::instance()->CFG->map_settings->event_list_display_nav =
676
-            isset($this->_req_data['event_list_display_nav'])
677
-                ? absint($this->_req_data['event_list_display_nav'])
678
-                : EE_Registry::instance()->CFG->map_settings->event_list_display_nav;
679
-
680
-        EE_Registry::instance()->CFG->map_settings->event_list_nav_size =
681
-            isset($this->_req_data['event_list_nav_size'])
682
-                ? absint($this->_req_data['event_list_nav_size'])
683
-                : EE_Registry::instance()->CFG->map_settings->event_list_nav_size;
684
-
685
-        EE_Registry::instance()->CFG->map_settings->event_list_control_type =
686
-            isset($this->_req_data['event_list_control_type'])
687
-                ? sanitize_text_field($this->_req_data['event_list_control_type'])
688
-                : EE_Registry::instance()->CFG->map_settings->event_list_control_type;
689
-
690
-        EE_Registry::instance()->CFG->map_settings->event_list_map_align =
691
-            isset($this->_req_data['event_list_map_align'])
692
-                ? sanitize_text_field($this->_req_data['event_list_map_align'])
693
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_align;
694
-
695
-        EE_Registry::instance()->CFG->map_settings = apply_filters(
696
-            'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
697
-            EE_Registry::instance()->CFG->map_settings
698
-        );
699
-
700
-        $what = 'Google Map Settings';
701
-        $success = $this->_update_espresso_configuration(
702
-            $what,
703
-            EE_Registry::instance()->CFG->map_settings,
704
-            __FILE__,
705
-            __FUNCTION__,
706
-            __LINE__
707
-        );
708
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings'));
709
-    }
710
-
711
-
712
-    protected function _venue_editor_metaboxes()
713
-    {
714
-        $this->verify_cpt_object();
715
-
716
-        add_meta_box(
717
-            'espresso_venue_address_options',
718
-            __('Physical Location', 'event_espresso'),
719
-            array($this, 'venue_address_metabox'),
720
-            $this->page_slug,
721
-            'side',
722
-            'default'
723
-        );
724
-        add_meta_box(
725
-            'espresso_venue_gmap_options',
726
-            __('Google Map', 'event_espresso'),
727
-            array($this, 'venue_gmap_metabox'),
728
-            $this->page_slug,
729
-            'side',
730
-            'default'
731
-        );
732
-        add_meta_box(
733
-            'espresso_venue_virtual_loc_options',
734
-            __('Virtual Location', 'event_espresso'),
735
-            array($this, 'venue_virtual_loc_metabox'),
736
-            $this->page_slug,
737
-            'side',
738
-            'default'
739
-        );
740
-    }
741
-
742
-
743
-    public function venue_gmap_metabox()
744
-    {
745
-        $template_args = array(
746
-            'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
747
-                'vnu_enable_for_gmap',
748
-                $this->get_yes_no_values(),
749
-                $this->_cpt_model_obj->enable_for_gmap()
750
-            ),
751
-            'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
752
-        );
753
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
754
-        EEH_Template::display_template($template, $template_args);
755
-    }
756
-
757
-
758
-    public function venue_address_metabox()
759
-    {
760
-
761
-        $template_args['_venue'] = $this->_cpt_model_obj;
762
-
763
-        $template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input(
764
-            $QFI = new EE_Question_Form_Input(
765
-                EE_Question::new_instance(
766
-                    array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')
767
-                ),
768
-                EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->state_ID())),
769
-                array(
770
-                    'input_name'     => 'sta_id',
771
-                    'input_id'       => 'sta_id',
772
-                    'input_class'    => '',
773
-                    'input_prefix'   => '',
774
-                    'append_qstn_id' => false,
775
-                )
776
-            )
777
-        );
778
-        $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
779
-            $QFI = new EE_Question_Form_Input(
780
-                EE_Question::new_instance(
781
-                    array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')
782
-                ),
783
-                EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->country_ID())),
784
-                array(
785
-                    'input_name'     => 'cnt_iso',
786
-                    'input_id'       => 'cnt_iso',
787
-                    'input_class'    => '',
788
-                    'input_prefix'   => '',
789
-                    'append_qstn_id' => false,
790
-                )
791
-            )
792
-        );
793
-
794
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
795
-        EEH_Template::display_template($template, $template_args);
796
-    }
797
-
798
-
799
-    public function venue_virtual_loc_metabox()
800
-    {
801
-        $template_args = array(
802
-            '_venue' => $this->_cpt_model_obj,
803
-        );
804
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
805
-        EEH_Template::display_template($template, $template_args);
806
-    }
807
-
808
-
809
-    protected function _restore_cpt_item($post_id, $revision_id)
810
-    {
811
-        $venue_obj = $this->_venue_model->get_one_by_ID($post_id);
812
-
813
-        // meta revision restore
814
-        $venue_obj->restore_revision($revision_id);
815
-    }
816
-
817
-
818
-    /**
819
-     * Handles updates for venue cpts
820
-     *
821
-     * @param  int    $post_id ID of Venue CPT
822
-     * @param  object $post    Post object (with "blessed" WP properties)
823
-     * @return void
824
-     */
825
-    protected function _insert_update_cpt_item($post_id, $post)
826
-    {
827
-
828
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
829
-            return;// get out we're not processing the saving of venues.
830
-        }
831
-
832
-        $wheres = array($this->_venue_model->primary_key_name() => $post_id);
833
-
834
-        $venue_values = array(
835
-            'VNU_address'         => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : null,
836
-            'VNU_address2'        => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2']
837
-                : null,
838
-            'VNU_city'            => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : null,
839
-            'STA_ID'              => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : null,
840
-            'CNT_ISO'             => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : null,
841
-            'VNU_zip'             => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : null,
842
-            'VNU_phone'           => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : null,
843
-            'VNU_capacity'        => ! empty($this->_req_data['vnu_capacity']) ? str_replace(
844
-                ',',
845
-                '',
846
-                $this->_req_data['vnu_capacity']
847
-            ) : EE_INF,
848
-            'VNU_url'             => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : null,
849
-            'VNU_virtual_phone'   => ! empty($this->_req_data['vnu_virtual_phone'])
850
-                ? $this->_req_data['vnu_virtual_phone'] : null,
851
-            'VNU_virtual_url'     => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url']
852
-                : null,
853
-            'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? true : false,
854
-            'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link'])
855
-                ? $this->_req_data['vnu_google_map_link'] : null,
856
-        );
857
-
858
-        // update venue
859
-        $success = $this->_venue_model->update($venue_values, array($wheres));
860
-
861
-        // 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!
862
-        $get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status);
863
-        $venue = $this->_venue_model->get_one(array($get_one_where));
864
-
865
-        // 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.
866
-        $venue_update_callbacks = apply_filters(
867
-            'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
868
-            array()
869
-        );
870
-
871
-        $att_success = true;
872
-
873
-        foreach ($venue_update_callbacks as $v_callback) {
874
-            $_succ = call_user_func_array($v_callback, array($venue, $this->_req_data));
875
-            $att_success = ! $att_success ? $att_success
876
-                : $_succ; // if ANY of these updates fail then we want the appropriate global error message
877
-        }
878
-
879
-        // any errors?
880
-        if ($success && ! $att_success) {
881
-            EE_Error::add_error(
882
-                __(
883
-                    'Venue Details saved successfully but something went wrong with saving attachments.',
884
-                    'event_espresso'
885
-                ),
886
-                __FILE__,
887
-                __FUNCTION__,
888
-                __LINE__
889
-            );
890
-        } elseif ($success === false) {
891
-            EE_Error::add_error(
892
-                __('Venue Details did not save successfully.', 'event_espresso'),
893
-                __FILE__,
894
-                __FUNCTION__,
895
-                __LINE__
896
-            );
897
-        }
898
-    }
899
-
900
-
901
-    public function trash_cpt_item($post_id)
902
-    {
903
-        $this->_req_data['VNU_ID'] = $post_id;
904
-        $this->_trash_or_restore_venue('trash', false);
905
-    }
906
-
907
-
908
-    public function restore_cpt_item($post_id)
909
-    {
910
-        $this->_req_data['VNU_ID'] = $post_id;
911
-        $this->_trash_or_restore_venue('draft', false);
912
-    }
913
-
914
-
915
-    public function delete_cpt_item($post_id)
916
-    {
917
-        $this->_req_data['VNU_ID'] = $post_id;
918
-        $this->_delete_venue(false);
919
-    }
920
-
921
-
922
-    public function get_venue_object()
923
-    {
924
-        return $this->_cpt_model_obj;
925
-    }
926
-
927
-
928
-    protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
929
-    {
930
-        $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : false;
931
-
932
-        // loop thru venues
933
-        if ($VNU_ID) {
934
-            // clean status
935
-            $venue_status = sanitize_key($venue_status);
936
-            // grab status
937
-            if (! empty($venue_status)) {
938
-                $success = $this->_change_venue_status($VNU_ID, $venue_status);
939
-            } else {
940
-                $success = false;
941
-                $msg = __(
942
-                    'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
943
-                    'event_espresso'
944
-                );
945
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
946
-            }
947
-        } else {
948
-            $success = false;
949
-            $msg = __(
950
-                'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
951
-                'event_espresso'
952
-            );
953
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
954
-        }
955
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
956
-
957
-        if ($redirect_after) {
958
-            $this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default'));
959
-        }
960
-    }
961
-
962
-
963
-    protected function _trash_or_restore_venues($venue_status = 'trash')
964
-    {
965
-        // clean status
966
-        $venue_status = sanitize_key($venue_status);
967
-        // grab status
968
-        if (! empty($venue_status)) {
969
-            $success = true;
970
-            // determine the event id and set to array.
971
-            $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
972
-            // loop thru events
973
-            foreach ($VNU_IDs as $VNU_ID) {
974
-                if ($VNU_ID = absint($VNU_ID)) {
975
-                    $results = $this->_change_venue_status($VNU_ID, $venue_status);
976
-                    $success = $results !== false ? $success : false;
977
-                } else {
978
-                    $msg = sprintf(
979
-                        __(
980
-                            'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
981
-                            'event_espresso'
982
-                        ),
983
-                        $VNU_ID
984
-                    );
985
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
986
-                    $success = false;
987
-                }
988
-            }
989
-        } else {
990
-            $success = false;
991
-            $msg = __(
992
-                'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
993
-                'event_espresso'
994
-            );
995
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
996
-        }
997
-        // in order to force a pluralized result message we need to send back a success status greater than 1
998
-        $success = $success ? 2 : false;
999
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1000
-        $this->_redirect_after_action($success, 'Venues', $action, array('action' => 'default'));
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * _trash_or_restore_venues
1006
-     *
1007
-     * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1008
-     * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1009
-     * accepting a certain number of params.
1010
-     *
1011
-     * @access  private
1012
-     * @param  int    $VNU_ID
1013
-     * @param  string $venue_status
1014
-     * @return void
1015
-     */
1016
-    private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1017
-    {
1018
-        // grab venue id
1019
-        if (! $VNU_ID) {
1020
-            $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1021
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1022
-            return false;
1023
-        }
1024
-
1025
-        $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1026
-
1027
-        // clean status
1028
-        $venue_status = sanitize_key($venue_status);
1029
-        // grab status
1030
-        if (! $venue_status) {
1031
-            $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1032
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1033
-            return false;
1034
-        }
1035
-
1036
-        // was event trashed or restored ?
1037
-        switch ($venue_status) {
1038
-            case 'draft':
1039
-                $action = 'restored from the trash';
1040
-                $hook = 'AHEE_venue_restored_from_trash';
1041
-                break;
1042
-            case 'trash':
1043
-                $action = 'moved to the trash';
1044
-                $hook = 'AHEE_venue_moved_to_trash';
1045
-                break;
1046
-            default:
1047
-                $action = 'updated';
1048
-                $hook = false;
1049
-        }
1050
-        // use class to change status
1051
-        $this->_cpt_model_obj->set_status($venue_status);
1052
-        $success = $this->_cpt_model_obj->save();
1053
-
1054
-        if ($success === false) {
1055
-            $msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1056
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1057
-            return false;
1058
-        }
1059
-        if ($hook) {
1060
-            do_action($hook);
1061
-        }
1062
-        return true;
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * @param  bool $redirect_after
1068
-     * @return void
1069
-     */
1070
-    protected function _delete_venue($redirect_after = true)
1071
-    {
1072
-        // determine the venue id and set to array.
1073
-        $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : null;
1074
-        $VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID;
1075
-
1076
-
1077
-        // loop thru venues
1078
-        if ($VNU_ID) {
1079
-            $success = $this->_delete_or_trash_venue($VNU_ID);
1080
-        } else {
1081
-            $success = false;
1082
-            $msg = __(
1083
-                'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1084
-                'event_espresso'
1085
-            );
1086
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1087
-        }
1088
-        if ($redirect_after) {
1089
-            $this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default'));
1090
-        }
1091
-    }
1092
-
1093
-
1094
-    protected function _delete_venues()
1095
-    {
1096
-        $success = true;
1097
-        // determine the event id and set to array.
1098
-        $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
1099
-        // loop thru events
1100
-        foreach ($VNU_IDs as $VNU_ID) {
1101
-            if ($VNU_ID = absint($VNU_ID)) {
1102
-                $results = $this->_delete_or_trash_venue($VNU_ID);
1103
-                $success = $results !== false ? $success : false;
1104
-            } else {
1105
-                $success = false;
1106
-                $msg = __(
1107
-                    'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1108
-                    'event_espresso'
1109
-                );
1110
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1111
-            }
1112
-        }
1113
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1114
-        $success = $success ? 2 : false;
1115
-        $this->_redirect_after_action(
1116
-            $success,
1117
-            __('Venues', 'event_espresso'),
1118
-            __('deleted', 'event_espresso'),
1119
-            array('action' => 'default')
1120
-        );
1121
-    }
1122
-
1123
-
1124
-    // todo: put in parent
1125
-    private function _delete_or_trash_venue($VNU_ID = false)
1126
-    {
1127
-        // grab event id
1128
-        if (! $VNU_ID = absint($VNU_ID)) {
1129
-            $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1130
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1131
-            return false;
1132
-        }
1133
-
1134
-
1135
-        $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1136
-        // first need to remove all term relationships
1137
-        $venue->_remove_relations('Term_Taxonomy');
1138
-        $success = $venue->delete_permanently();
1139
-        // did it all go as planned ?
1140
-        if ($success) {
1141
-            $msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1142
-            EE_Error::add_success($msg);
1143
-        } else {
1144
-            $msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID);
1145
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1146
-            return false;
1147
-        }
1148
-        do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1149
-        return true;
1150
-    }
1151
-
1152
-
1153
-
1154
-
1155
-    /***********/
1156
-    /* QUERIES */
1157
-
1158
-
1159
-    public function get_venues($per_page = 10, $count = false)
1160
-    {
1161
-
1162
-        $_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1163
-
1164
-        switch ($_orderby) {
1165
-            case 'id':
1166
-                $orderby = 'VNU_ID';
1167
-                break;
1168
-
1169
-            case 'capacity':
1170
-                $orderby = 'VNU_capacity';
1171
-                break;
1172
-
1173
-            case 'city':
1174
-                $orderby = 'VNU_city';
1175
-                break;
1176
-
1177
-            default:
1178
-                $orderby = 'VNU_name';
1179
-        }
1180
-
1181
-
1182
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1183
-            : 'ASC';
1184
-
1185
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1186
-            ? $this->_req_data['paged'] : 1;
1187
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
1188
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1189
-            ? $this->_req_data['perpage'] : $per_page;
1190
-
1191
-
1192
-        $offset = ($current_page - 1) * $per_page;
1193
-        $limit = array($offset, $per_page);
1194
-
1195
-        $category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0
1196
-            ? $this->_req_data['category'] : null;
1197
-        $where = array();
1198
-
1199
-        // only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1200
-        if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') {
1201
-            $where['status'] = $this->_req_data['status'];
1202
-        }
1203
-
1204
-        if (isset($this->_req_data['venue_status'])) {
1205
-            $where['status'] = $this->_req_data['venue_status'];
1206
-        }
1207
-
1208
-
1209
-        if ($category) {
1210
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1211
-            $where['Term_Taxonomy.term_id'] = $category;
1212
-        }
1213
-
1214
-
1215
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1216
-            $where['VNU_wp_user'] = get_current_user_id();
1217
-        } else {
1218
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1219
-                $where['OR'] = array(
1220
-                    'status*restrict_private' => array('!=', 'private'),
1221
-                    'AND'                     => array(
1222
-                        'status*inclusive' => array('=', 'private'),
1223
-                        'VNU_wp_user'      => get_current_user_id(),
1224
-                    ),
1225
-                );
1226
-            }
1227
-        }
1228
-
1229
-
1230
-        if (isset($this->_req_data['s'])) {
1231
-            $sstr = '%' . $this->_req_data['s'] . '%';
1232
-            $where['OR'] = array(
1233
-                'VNU_name'               => array('LIKE', $sstr),
1234
-                'VNU_desc'               => array('LIKE', $sstr),
1235
-                'VNU_short_desc'         => array('LIKE', $sstr),
1236
-                'VNU_address'            => array('LIKE', $sstr),
1237
-                'VNU_address2'           => array('LIKE', $sstr),
1238
-                'VNU_city'               => array('LIKE', $sstr),
1239
-                'VNU_zip'                => array('LIKE', $sstr),
1240
-                'VNU_phone'              => array('LIKE', $sstr),
1241
-                'VNU_url'                => array('LIKE', $sstr),
1242
-                'VNU_virtual_phone'      => array('LIKE', $sstr),
1243
-                'VNU_virtual_url'        => array('LIKE', $sstr),
1244
-                'VNU_google_map_link'    => array('LIKE', $sstr),
1245
-                'Event.EVT_name'         => array('LIKE', $sstr),
1246
-                'Event.EVT_desc'         => array('LIKE', $sstr),
1247
-                'Event.EVT_phone'        => array('LIKE', $sstr),
1248
-                'Event.EVT_external_URL' => array('LIKE', $sstr),
1249
-            );
1250
-        }
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
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
245
+				// 'help_tour'     => array('Venues_Overview_Help_Tour'),
246
+				'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
247
+				'require_nonce' => false,
248
+			),
249
+			'create_new'          => array(
250
+				'nav'           => array(
251
+					'label'      => __('Add Venue', 'event_espresso'),
252
+					'order'      => 5,
253
+					'persistent' => false,
254
+				),
255
+				'help_tabs'     => array(
256
+					'venues_editor_help_tab'                                               => array(
257
+						'title'    => __('Venue Editor', 'event_espresso'),
258
+						'filename' => 'venues_editor',
259
+					),
260
+					'venues_editor_title_richtexteditor_help_tab'                          => array(
261
+						'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
262
+						'filename' => 'venues_editor_title_richtexteditor',
263
+					),
264
+					'venues_editor_tags_categories_help_tab'                               => array(
265
+						'title'    => __('Venue Tags & Categories', 'event_espresso'),
266
+						'filename' => 'venues_editor_tags_categories',
267
+					),
268
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
269
+						'title'    => __(
270
+							'Venue Editor Physical Location & Google Map & Virtual Location',
271
+							'event_espresso'
272
+						),
273
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
274
+					),
275
+					'venues_editor_save_new_venue_help_tab'                                => array(
276
+						'title'    => __('Save New Venue', 'event_espresso'),
277
+						'filename' => 'venues_editor_save_new_venue',
278
+					),
279
+					'venues_editor_other_help_tab'                                         => array(
280
+						'title'    => __('Venue Editor Other', 'event_espresso'),
281
+						'filename' => 'venues_editor_other',
282
+					),
283
+				),
284
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
285
+				// 'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
286
+				'metaboxes'     => array('_venue_editor_metaboxes'),
287
+				'require_nonce' => false,
288
+			),
289
+			'edit'                => array(
290
+				'nav'           => array(
291
+					'label'      => __('Edit Venue', 'event_espresso'),
292
+					'order'      => 5,
293
+					'persistent' => false,
294
+					'url'        => isset($this->_req_data['post']) ? add_query_arg(
295
+						array('post' => $this->_req_data['post']),
296
+						$this->_current_page_view_url
297
+					) : $this->_admin_base_url,
298
+				),
299
+				'help_tabs'     => array(
300
+					'venues_editor_help_tab'                                               => array(
301
+						'title'    => __('Venue Editor', 'event_espresso'),
302
+						'filename' => 'venues_editor',
303
+					),
304
+					'venues_editor_title_richtexteditor_help_tab'                          => array(
305
+						'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
306
+						'filename' => 'venues_editor_title_richtexteditor',
307
+					),
308
+					'venues_editor_tags_categories_help_tab'                               => array(
309
+						'title'    => __('Venue Tags & Categories', 'event_espresso'),
310
+						'filename' => 'venues_editor_tags_categories',
311
+					),
312
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
313
+						'title'    => __(
314
+							'Venue Editor Physical Location & Google Map & Virtual Location',
315
+							'event_espresso'
316
+						),
317
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
318
+					),
319
+					'venues_editor_save_new_venue_help_tab'                                => array(
320
+						'title'    => __('Save New Venue', 'event_espresso'),
321
+						'filename' => 'venues_editor_save_new_venue',
322
+					),
323
+					'venues_editor_other_help_tab'                                         => array(
324
+						'title'    => __('Venue Editor Other', 'event_espresso'),
325
+						'filename' => 'venues_editor_other',
326
+					),
327
+				),
328
+				/*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
329
+				'metaboxes'     => array('_venue_editor_metaboxes'),
330
+				'require_nonce' => false,
331
+			),
332
+			'google_map_settings' => array(
333
+				'nav'           => array(
334
+					'label' => esc_html__('Google Maps', 'event_espresso'),
335
+					'order' => 40,
336
+				),
337
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
338
+				'help_tabs'     => array(
339
+					'general_settings_google_maps_help_tab' => array(
340
+						'title'    => __('Google Maps', 'event_espresso'),
341
+						'filename' => 'general_settings_google_maps',
342
+					),
343
+				),
344
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
345
+				// 'help_tour'     => array('Google_Maps_Help_Tour'),
346
+				'require_nonce' => false,
347
+			),
348
+			// venue category stuff
349
+			'add_category'        => array(
350
+				'nav'           => array(
351
+					'label'      => __('Add Category', 'event_espresso'),
352
+					'order'      => 15,
353
+					'persistent' => false,
354
+				),
355
+				'metaboxes'     => array('_publish_post_box'),
356
+				'help_tabs'     => array(
357
+					'venues_add_category_help_tab' => array(
358
+						'title'    => __('Add New Venue Category', 'event_espresso'),
359
+						'filename' => 'venues_add_category',
360
+					),
361
+				),
362
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
363
+				// 'help_tour'     => array('Venues_Add_Category_Help_Tour'),
364
+				'require_nonce' => false,
365
+			),
366
+			'edit_category'       => array(
367
+				'nav'           => array(
368
+					'label'      => __('Edit Category', 'event_espresso'),
369
+					'order'      => 15,
370
+					'persistent' => false,
371
+					'url'        => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(
372
+						array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
373
+						$this->_current_page_view_url
374
+					) : $this->_admin_base_url,
375
+				),
376
+				'metaboxes'     => array('_publish_post_box'),
377
+				'help_tabs'     => array(
378
+					'venues_edit_category_help_tab' => array(
379
+						'title'    => __('Edit Venue Category', 'event_espresso'),
380
+						'filename' => 'venues_edit_category',
381
+					),
382
+				),
383
+				/*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
384
+				'require_nonce' => false,
385
+			),
386
+			'category_list'       => array(
387
+				'nav'           => array(
388
+					'label' => __('Categories', 'event_espresso'),
389
+					'order' => 20,
390
+				),
391
+				'list_table'    => 'Venue_Categories_Admin_List_Table',
392
+				'help_tabs'     => array(
393
+					'venues_categories_help_tab'                       => array(
394
+						'title'    => __('Venue Categories', 'event_espresso'),
395
+						'filename' => 'venues_categories',
396
+					),
397
+					'venues_categories_table_column_headings_help_tab' => array(
398
+						'title'    => __('Venue Categories Table Column Headings', 'event_espresso'),
399
+						'filename' => 'venues_categories_table_column_headings',
400
+					),
401
+					'venues_categories_views_help_tab'                 => array(
402
+						'title'    => __('Venue Categories Views', 'event_espresso'),
403
+						'filename' => 'venues_categories_views',
404
+					),
405
+					'venues_categories_other_help_tab'                 => array(
406
+						'title'    => __('Venue Categories Other', 'event_espresso'),
407
+						'filename' => 'venues_categories_other',
408
+					),
409
+				),
410
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
411
+				// 'help_tour'     => array('Venues_Categories_Help_Tour'),
412
+				'metaboxes'     => $this->_default_espresso_metaboxes,
413
+				'require_nonce' => false,
414
+			),
415
+		);
416
+	}
417
+
418
+
419
+	protected function _add_screen_options()
420
+	{
421
+		// todo
422
+	}
423
+
424
+
425
+	protected function _add_screen_options_default()
426
+	{
427
+		$this->_per_page_screen_option();
428
+	}
429
+
430
+
431
+	protected function _add_screen_options_category_list()
432
+	{
433
+		$page_title = $this->_admin_page_title;
434
+		$this->_admin_page_title = __('Venue Categories', 'event_espresso');
435
+		$this->_per_page_screen_option();
436
+		$this->_admin_page_title = $page_title;
437
+	}
438
+
439
+
440
+	// none of the below group are currently used for Event Venues
441
+	protected function _add_feature_pointers()
442
+	{
443
+	}
444
+
445
+	public function admin_init()
446
+	{
447
+	}
448
+
449
+	public function admin_notices()
450
+	{
451
+	}
452
+
453
+	public function admin_footer_scripts()
454
+	{
455
+	}
456
+
457
+
458
+	public function load_scripts_styles_create_new()
459
+	{
460
+		$this->load_scripts_styles_edit();
461
+	}
462
+
463
+
464
+	public function load_scripts_styles()
465
+	{
466
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
467
+		wp_enqueue_style('ee-cat-admin');
468
+	}
469
+
470
+
471
+	public function load_scripts_styles_add_category()
472
+	{
473
+		$this->load_scripts_styles_edit_category();
474
+	}
475
+
476
+
477
+	public function load_scripts_styles_edit_category()
478
+	{
479
+	}
480
+
481
+
482
+	public function load_scripts_styles_edit()
483
+	{
484
+		// styles
485
+		wp_enqueue_style('espresso-ui-theme');
486
+		wp_register_style(
487
+			'espresso_venues',
488
+			EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
489
+			array(),
490
+			EVENT_ESPRESSO_VERSION
491
+		);
492
+		wp_enqueue_style('espresso_venues');
493
+	}
494
+
495
+
496
+	protected function _set_list_table_views_default()
497
+	{
498
+		$this->_views = array(
499
+			'all' => array(
500
+				'slug'        => 'all',
501
+				'label'       => __('View All Venues', 'event_espresso'),
502
+				'count'       => 0,
503
+				'bulk_action' => array(),
504
+			),
505
+		);
506
+
507
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
508
+			$this->_views['all']['bulk_action'] = array(
509
+				'trash_venues' => __('Move to Trash', 'event_espresso'),
510
+			);
511
+			$this->_views['trash'] = array(
512
+				'slug'        => 'trash',
513
+				'label'       => __('Trash', 'event_espresso'),
514
+				'count'       => 0,
515
+				'bulk_action' => array(
516
+					'restore_venues' => __('Restore from Trash', 'event_espresso'),
517
+					'delete_venues'  => __('Delete', 'event_espresso'),
518
+				),
519
+			);
520
+		}
521
+	}
522
+
523
+
524
+	protected function _set_list_table_views_category_list()
525
+	{
526
+		$this->_views = array(
527
+			'all' => array(
528
+				'slug'        => 'all',
529
+				'label'       => __('All', 'event_espresso'),
530
+				'count'       => 0,
531
+				'bulk_action' => array(
532
+					'delete_categories' => __('Delete Permanently', 'event_espresso'),
533
+				),
534
+			),
535
+		);
536
+	}
537
+
538
+
539
+	protected function _overview_list_table()
540
+	{
541
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
542
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
543
+			get_post_type_archive_link('espresso_venues'),
544
+			__("View Venue Archive Page", "event_espresso"),
545
+			'button'
546
+		);
547
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
548
+		$this->_search_btn_label = __('Venues', 'event_espresso');
549
+		$this->display_admin_list_table_page_with_sidebar();
550
+	}
551
+
552
+
553
+	public function extra_misc_actions_publish_box()
554
+	{
555
+		$extra_rows = array(
556
+			'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
557
+			'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
558
+			'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
559
+		);
560
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
561
+		EEH_Template::display_template($template, $extra_rows);
562
+	}
563
+
564
+
565
+	/*************        Google Maps        *************/
566
+
567
+
568
+	protected function _google_map_settings()
569
+	{
570
+
571
+
572
+		$this->_template_args['values'] = $this->_yes_no_values;
573
+		$default_map_settings = new stdClass();
574
+		$default_map_settings->use_google_maps = true;
575
+		$default_map_settings->google_map_api_key = '';
576
+		// for event details pages (reg page)
577
+		$default_map_settings->event_details_map_width = 585;            // ee_map_width_single
578
+		$default_map_settings->event_details_map_height = 362;            // ee_map_height_single
579
+		$default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
580
+		$default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
581
+		$default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
582
+		$default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
583
+		$default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
584
+		// for event list pages
585
+		$default_map_settings->event_list_map_width = 300;            // ee_map_width
586
+		$default_map_settings->event_list_map_height = 185;        // ee_map_height
587
+		$default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
588
+		$default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
589
+		$default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
590
+		$default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
591
+		$default_map_settings->event_list_map_align = 'center';            // ee_map_align
592
+
593
+		$this->_template_args['map_settings'] =
594
+			isset(EE_Registry::instance()->CFG->map_settings)
595
+			&& ! empty(EE_Registry::instance()->CFG->map_settings)
596
+				? (object) array_merge(
597
+					(array) $default_map_settings,
598
+					(array) EE_Registry::instance()->CFG->map_settings
599
+				)
600
+				: $default_map_settings;
601
+
602
+		$this->_set_add_edit_form_tags('update_google_map_settings');
603
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
604
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
605
+			EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
606
+			$this->_template_args,
607
+			true
608
+		);
609
+		$this->display_admin_page_with_sidebar();
610
+	}
611
+
612
+	protected function _update_google_map_settings()
613
+	{
614
+
615
+		EE_Registry::instance()->CFG->map_settings->use_google_maps =
616
+			isset($this->_req_data['use_google_maps'])
617
+				? absint($this->_req_data['use_google_maps'])
618
+				: EE_Registry::instance()->CFG->map_settings->use_google_maps;
619
+
620
+		EE_Registry::instance()->CFG->map_settings->google_map_api_key =
621
+			isset($this->_req_data['google_map_api_key'])
622
+				? sanitize_text_field($this->_req_data['google_map_api_key'])
623
+				: EE_Registry::instance()->CFG->map_settings->google_map_api_key;
624
+
625
+		EE_Registry::instance()->CFG->map_settings->event_details_map_width =
626
+			isset($this->_req_data['event_details_map_width'])
627
+				? absint($this->_req_data['event_details_map_width'])
628
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_width;
629
+
630
+		EE_Registry::instance()->CFG->map_settings->event_details_map_height =
631
+			isset($this->_req_data['event_details_map_height'])
632
+				? absint($this->_req_data['event_details_map_height'])
633
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_height;
634
+
635
+		EE_Registry::instance()->CFG->map_settings->event_details_map_zoom =
636
+			isset($this->_req_data['event_details_map_zoom'])
637
+				? absint($this->_req_data['event_details_map_zoom'])
638
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_zoom;
639
+
640
+		EE_Registry::instance()->CFG->map_settings->event_details_display_nav =
641
+			isset($this->_req_data['event_details_display_nav'])
642
+				? absint($this->_req_data['event_details_display_nav'])
643
+				: EE_Registry::instance()->CFG->map_settings->event_details_display_nav;
644
+
645
+		EE_Registry::instance()->CFG->map_settings->event_details_nav_size =
646
+			isset($this->_req_data['event_details_nav_size'])
647
+				? absint($this->_req_data['event_details_nav_size'])
648
+				: EE_Registry::instance()->CFG->map_settings->event_details_nav_size;
649
+
650
+		EE_Registry::instance()->CFG->map_settings->event_details_control_type =
651
+			isset($this->_req_data['event_details_control_type'])
652
+				? sanitize_text_field($this->_req_data['event_details_control_type'])
653
+				: EE_Registry::instance()->CFG->map_settings->event_details_control_type;
654
+
655
+		EE_Registry::instance()->CFG->map_settings->event_details_map_align =
656
+			isset($this->_req_data['event_details_map_align'])
657
+				? sanitize_text_field($this->_req_data['event_details_map_align'])
658
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_align;
659
+
660
+		EE_Registry::instance()->CFG->map_settings->event_list_map_width =
661
+			isset($this->_req_data['event_list_map_width'])
662
+				? absint($this->_req_data['event_list_map_width'])
663
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_width;
664
+
665
+		EE_Registry::instance()->CFG->map_settings->event_list_map_height =
666
+			isset($this->_req_data['event_list_map_height'])
667
+				? absint($this->_req_data['event_list_map_height'])
668
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_height;
669
+
670
+		EE_Registry::instance()->CFG->map_settings->event_list_map_zoom =
671
+			isset($this->_req_data['event_list_map_zoom'])
672
+				? absint($this->_req_data['event_list_map_zoom'])
673
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_zoom;
674
+
675
+		EE_Registry::instance()->CFG->map_settings->event_list_display_nav =
676
+			isset($this->_req_data['event_list_display_nav'])
677
+				? absint($this->_req_data['event_list_display_nav'])
678
+				: EE_Registry::instance()->CFG->map_settings->event_list_display_nav;
679
+
680
+		EE_Registry::instance()->CFG->map_settings->event_list_nav_size =
681
+			isset($this->_req_data['event_list_nav_size'])
682
+				? absint($this->_req_data['event_list_nav_size'])
683
+				: EE_Registry::instance()->CFG->map_settings->event_list_nav_size;
684
+
685
+		EE_Registry::instance()->CFG->map_settings->event_list_control_type =
686
+			isset($this->_req_data['event_list_control_type'])
687
+				? sanitize_text_field($this->_req_data['event_list_control_type'])
688
+				: EE_Registry::instance()->CFG->map_settings->event_list_control_type;
689
+
690
+		EE_Registry::instance()->CFG->map_settings->event_list_map_align =
691
+			isset($this->_req_data['event_list_map_align'])
692
+				? sanitize_text_field($this->_req_data['event_list_map_align'])
693
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_align;
694
+
695
+		EE_Registry::instance()->CFG->map_settings = apply_filters(
696
+			'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
697
+			EE_Registry::instance()->CFG->map_settings
698
+		);
699
+
700
+		$what = 'Google Map Settings';
701
+		$success = $this->_update_espresso_configuration(
702
+			$what,
703
+			EE_Registry::instance()->CFG->map_settings,
704
+			__FILE__,
705
+			__FUNCTION__,
706
+			__LINE__
707
+		);
708
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings'));
709
+	}
710
+
711
+
712
+	protected function _venue_editor_metaboxes()
713
+	{
714
+		$this->verify_cpt_object();
715
+
716
+		add_meta_box(
717
+			'espresso_venue_address_options',
718
+			__('Physical Location', 'event_espresso'),
719
+			array($this, 'venue_address_metabox'),
720
+			$this->page_slug,
721
+			'side',
722
+			'default'
723
+		);
724
+		add_meta_box(
725
+			'espresso_venue_gmap_options',
726
+			__('Google Map', 'event_espresso'),
727
+			array($this, 'venue_gmap_metabox'),
728
+			$this->page_slug,
729
+			'side',
730
+			'default'
731
+		);
732
+		add_meta_box(
733
+			'espresso_venue_virtual_loc_options',
734
+			__('Virtual Location', 'event_espresso'),
735
+			array($this, 'venue_virtual_loc_metabox'),
736
+			$this->page_slug,
737
+			'side',
738
+			'default'
739
+		);
740
+	}
741
+
742
+
743
+	public function venue_gmap_metabox()
744
+	{
745
+		$template_args = array(
746
+			'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
747
+				'vnu_enable_for_gmap',
748
+				$this->get_yes_no_values(),
749
+				$this->_cpt_model_obj->enable_for_gmap()
750
+			),
751
+			'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
752
+		);
753
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
754
+		EEH_Template::display_template($template, $template_args);
755
+	}
756
+
757
+
758
+	public function venue_address_metabox()
759
+	{
760
+
761
+		$template_args['_venue'] = $this->_cpt_model_obj;
762
+
763
+		$template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input(
764
+			$QFI = new EE_Question_Form_Input(
765
+				EE_Question::new_instance(
766
+					array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')
767
+				),
768
+				EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->state_ID())),
769
+				array(
770
+					'input_name'     => 'sta_id',
771
+					'input_id'       => 'sta_id',
772
+					'input_class'    => '',
773
+					'input_prefix'   => '',
774
+					'append_qstn_id' => false,
775
+				)
776
+			)
777
+		);
778
+		$template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
779
+			$QFI = new EE_Question_Form_Input(
780
+				EE_Question::new_instance(
781
+					array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')
782
+				),
783
+				EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->country_ID())),
784
+				array(
785
+					'input_name'     => 'cnt_iso',
786
+					'input_id'       => 'cnt_iso',
787
+					'input_class'    => '',
788
+					'input_prefix'   => '',
789
+					'append_qstn_id' => false,
790
+				)
791
+			)
792
+		);
793
+
794
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
795
+		EEH_Template::display_template($template, $template_args);
796
+	}
797
+
798
+
799
+	public function venue_virtual_loc_metabox()
800
+	{
801
+		$template_args = array(
802
+			'_venue' => $this->_cpt_model_obj,
803
+		);
804
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
805
+		EEH_Template::display_template($template, $template_args);
806
+	}
807
+
808
+
809
+	protected function _restore_cpt_item($post_id, $revision_id)
810
+	{
811
+		$venue_obj = $this->_venue_model->get_one_by_ID($post_id);
812
+
813
+		// meta revision restore
814
+		$venue_obj->restore_revision($revision_id);
815
+	}
816
+
817
+
818
+	/**
819
+	 * Handles updates for venue cpts
820
+	 *
821
+	 * @param  int    $post_id ID of Venue CPT
822
+	 * @param  object $post    Post object (with "blessed" WP properties)
823
+	 * @return void
824
+	 */
825
+	protected function _insert_update_cpt_item($post_id, $post)
826
+	{
827
+
828
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
829
+			return;// get out we're not processing the saving of venues.
830
+		}
831
+
832
+		$wheres = array($this->_venue_model->primary_key_name() => $post_id);
833
+
834
+		$venue_values = array(
835
+			'VNU_address'         => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : null,
836
+			'VNU_address2'        => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2']
837
+				: null,
838
+			'VNU_city'            => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : null,
839
+			'STA_ID'              => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : null,
840
+			'CNT_ISO'             => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : null,
841
+			'VNU_zip'             => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : null,
842
+			'VNU_phone'           => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : null,
843
+			'VNU_capacity'        => ! empty($this->_req_data['vnu_capacity']) ? str_replace(
844
+				',',
845
+				'',
846
+				$this->_req_data['vnu_capacity']
847
+			) : EE_INF,
848
+			'VNU_url'             => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : null,
849
+			'VNU_virtual_phone'   => ! empty($this->_req_data['vnu_virtual_phone'])
850
+				? $this->_req_data['vnu_virtual_phone'] : null,
851
+			'VNU_virtual_url'     => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url']
852
+				: null,
853
+			'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? true : false,
854
+			'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link'])
855
+				? $this->_req_data['vnu_google_map_link'] : null,
856
+		);
857
+
858
+		// update venue
859
+		$success = $this->_venue_model->update($venue_values, array($wheres));
860
+
861
+		// 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!
862
+		$get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status);
863
+		$venue = $this->_venue_model->get_one(array($get_one_where));
864
+
865
+		// 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.
866
+		$venue_update_callbacks = apply_filters(
867
+			'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
868
+			array()
869
+		);
870
+
871
+		$att_success = true;
872
+
873
+		foreach ($venue_update_callbacks as $v_callback) {
874
+			$_succ = call_user_func_array($v_callback, array($venue, $this->_req_data));
875
+			$att_success = ! $att_success ? $att_success
876
+				: $_succ; // if ANY of these updates fail then we want the appropriate global error message
877
+		}
878
+
879
+		// any errors?
880
+		if ($success && ! $att_success) {
881
+			EE_Error::add_error(
882
+				__(
883
+					'Venue Details saved successfully but something went wrong with saving attachments.',
884
+					'event_espresso'
885
+				),
886
+				__FILE__,
887
+				__FUNCTION__,
888
+				__LINE__
889
+			);
890
+		} elseif ($success === false) {
891
+			EE_Error::add_error(
892
+				__('Venue Details did not save successfully.', 'event_espresso'),
893
+				__FILE__,
894
+				__FUNCTION__,
895
+				__LINE__
896
+			);
897
+		}
898
+	}
899
+
900
+
901
+	public function trash_cpt_item($post_id)
902
+	{
903
+		$this->_req_data['VNU_ID'] = $post_id;
904
+		$this->_trash_or_restore_venue('trash', false);
905
+	}
906
+
907
+
908
+	public function restore_cpt_item($post_id)
909
+	{
910
+		$this->_req_data['VNU_ID'] = $post_id;
911
+		$this->_trash_or_restore_venue('draft', false);
912
+	}
913
+
914
+
915
+	public function delete_cpt_item($post_id)
916
+	{
917
+		$this->_req_data['VNU_ID'] = $post_id;
918
+		$this->_delete_venue(false);
919
+	}
920
+
921
+
922
+	public function get_venue_object()
923
+	{
924
+		return $this->_cpt_model_obj;
925
+	}
926
+
927
+
928
+	protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
929
+	{
930
+		$VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : false;
931
+
932
+		// loop thru venues
933
+		if ($VNU_ID) {
934
+			// clean status
935
+			$venue_status = sanitize_key($venue_status);
936
+			// grab status
937
+			if (! empty($venue_status)) {
938
+				$success = $this->_change_venue_status($VNU_ID, $venue_status);
939
+			} else {
940
+				$success = false;
941
+				$msg = __(
942
+					'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
943
+					'event_espresso'
944
+				);
945
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
946
+			}
947
+		} else {
948
+			$success = false;
949
+			$msg = __(
950
+				'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
951
+				'event_espresso'
952
+			);
953
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
954
+		}
955
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
956
+
957
+		if ($redirect_after) {
958
+			$this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default'));
959
+		}
960
+	}
961
+
962
+
963
+	protected function _trash_or_restore_venues($venue_status = 'trash')
964
+	{
965
+		// clean status
966
+		$venue_status = sanitize_key($venue_status);
967
+		// grab status
968
+		if (! empty($venue_status)) {
969
+			$success = true;
970
+			// determine the event id and set to array.
971
+			$VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
972
+			// loop thru events
973
+			foreach ($VNU_IDs as $VNU_ID) {
974
+				if ($VNU_ID = absint($VNU_ID)) {
975
+					$results = $this->_change_venue_status($VNU_ID, $venue_status);
976
+					$success = $results !== false ? $success : false;
977
+				} else {
978
+					$msg = sprintf(
979
+						__(
980
+							'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
981
+							'event_espresso'
982
+						),
983
+						$VNU_ID
984
+					);
985
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
986
+					$success = false;
987
+				}
988
+			}
989
+		} else {
990
+			$success = false;
991
+			$msg = __(
992
+				'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
993
+				'event_espresso'
994
+			);
995
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
996
+		}
997
+		// in order to force a pluralized result message we need to send back a success status greater than 1
998
+		$success = $success ? 2 : false;
999
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1000
+		$this->_redirect_after_action($success, 'Venues', $action, array('action' => 'default'));
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * _trash_or_restore_venues
1006
+	 *
1007
+	 * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1008
+	 * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1009
+	 * accepting a certain number of params.
1010
+	 *
1011
+	 * @access  private
1012
+	 * @param  int    $VNU_ID
1013
+	 * @param  string $venue_status
1014
+	 * @return void
1015
+	 */
1016
+	private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1017
+	{
1018
+		// grab venue id
1019
+		if (! $VNU_ID) {
1020
+			$msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1021
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1022
+			return false;
1023
+		}
1024
+
1025
+		$this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1026
+
1027
+		// clean status
1028
+		$venue_status = sanitize_key($venue_status);
1029
+		// grab status
1030
+		if (! $venue_status) {
1031
+			$msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1032
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1033
+			return false;
1034
+		}
1035
+
1036
+		// was event trashed or restored ?
1037
+		switch ($venue_status) {
1038
+			case 'draft':
1039
+				$action = 'restored from the trash';
1040
+				$hook = 'AHEE_venue_restored_from_trash';
1041
+				break;
1042
+			case 'trash':
1043
+				$action = 'moved to the trash';
1044
+				$hook = 'AHEE_venue_moved_to_trash';
1045
+				break;
1046
+			default:
1047
+				$action = 'updated';
1048
+				$hook = false;
1049
+		}
1050
+		// use class to change status
1051
+		$this->_cpt_model_obj->set_status($venue_status);
1052
+		$success = $this->_cpt_model_obj->save();
1053
+
1054
+		if ($success === false) {
1055
+			$msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1056
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1057
+			return false;
1058
+		}
1059
+		if ($hook) {
1060
+			do_action($hook);
1061
+		}
1062
+		return true;
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * @param  bool $redirect_after
1068
+	 * @return void
1069
+	 */
1070
+	protected function _delete_venue($redirect_after = true)
1071
+	{
1072
+		// determine the venue id and set to array.
1073
+		$VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : null;
1074
+		$VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID;
1075
+
1076
+
1077
+		// loop thru venues
1078
+		if ($VNU_ID) {
1079
+			$success = $this->_delete_or_trash_venue($VNU_ID);
1080
+		} else {
1081
+			$success = false;
1082
+			$msg = __(
1083
+				'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1084
+				'event_espresso'
1085
+			);
1086
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1087
+		}
1088
+		if ($redirect_after) {
1089
+			$this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default'));
1090
+		}
1091
+	}
1092
+
1093
+
1094
+	protected function _delete_venues()
1095
+	{
1096
+		$success = true;
1097
+		// determine the event id and set to array.
1098
+		$VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
1099
+		// loop thru events
1100
+		foreach ($VNU_IDs as $VNU_ID) {
1101
+			if ($VNU_ID = absint($VNU_ID)) {
1102
+				$results = $this->_delete_or_trash_venue($VNU_ID);
1103
+				$success = $results !== false ? $success : false;
1104
+			} else {
1105
+				$success = false;
1106
+				$msg = __(
1107
+					'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1108
+					'event_espresso'
1109
+				);
1110
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1111
+			}
1112
+		}
1113
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1114
+		$success = $success ? 2 : false;
1115
+		$this->_redirect_after_action(
1116
+			$success,
1117
+			__('Venues', 'event_espresso'),
1118
+			__('deleted', 'event_espresso'),
1119
+			array('action' => 'default')
1120
+		);
1121
+	}
1122
+
1123
+
1124
+	// todo: put in parent
1125
+	private function _delete_or_trash_venue($VNU_ID = false)
1126
+	{
1127
+		// grab event id
1128
+		if (! $VNU_ID = absint($VNU_ID)) {
1129
+			$msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1130
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1131
+			return false;
1132
+		}
1133
+
1134
+
1135
+		$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1136
+		// first need to remove all term relationships
1137
+		$venue->_remove_relations('Term_Taxonomy');
1138
+		$success = $venue->delete_permanently();
1139
+		// did it all go as planned ?
1140
+		if ($success) {
1141
+			$msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1142
+			EE_Error::add_success($msg);
1143
+		} else {
1144
+			$msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID);
1145
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1146
+			return false;
1147
+		}
1148
+		do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1149
+		return true;
1150
+	}
1151
+
1152
+
1153
+
1154
+
1155
+	/***********/
1156
+	/* QUERIES */
1157
+
1158
+
1159
+	public function get_venues($per_page = 10, $count = false)
1160
+	{
1161
+
1162
+		$_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1163
+
1164
+		switch ($_orderby) {
1165
+			case 'id':
1166
+				$orderby = 'VNU_ID';
1167
+				break;
1168
+
1169
+			case 'capacity':
1170
+				$orderby = 'VNU_capacity';
1171
+				break;
1172
+
1173
+			case 'city':
1174
+				$orderby = 'VNU_city';
1175
+				break;
1176
+
1177
+			default:
1178
+				$orderby = 'VNU_name';
1179
+		}
1180
+
1181
+
1182
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1183
+			: 'ASC';
1184
+
1185
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1186
+			? $this->_req_data['paged'] : 1;
1187
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
1188
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1189
+			? $this->_req_data['perpage'] : $per_page;
1190
+
1191
+
1192
+		$offset = ($current_page - 1) * $per_page;
1193
+		$limit = array($offset, $per_page);
1194
+
1195
+		$category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0
1196
+			? $this->_req_data['category'] : null;
1197
+		$where = array();
1198
+
1199
+		// only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1200
+		if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') {
1201
+			$where['status'] = $this->_req_data['status'];
1202
+		}
1203
+
1204
+		if (isset($this->_req_data['venue_status'])) {
1205
+			$where['status'] = $this->_req_data['venue_status'];
1206
+		}
1207
+
1208
+
1209
+		if ($category) {
1210
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1211
+			$where['Term_Taxonomy.term_id'] = $category;
1212
+		}
1213
+
1214
+
1215
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1216
+			$where['VNU_wp_user'] = get_current_user_id();
1217
+		} else {
1218
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1219
+				$where['OR'] = array(
1220
+					'status*restrict_private' => array('!=', 'private'),
1221
+					'AND'                     => array(
1222
+						'status*inclusive' => array('=', 'private'),
1223
+						'VNU_wp_user'      => get_current_user_id(),
1224
+					),
1225
+				);
1226
+			}
1227
+		}
1228
+
1229
+
1230
+		if (isset($this->_req_data['s'])) {
1231
+			$sstr = '%' . $this->_req_data['s'] . '%';
1232
+			$where['OR'] = array(
1233
+				'VNU_name'               => array('LIKE', $sstr),
1234
+				'VNU_desc'               => array('LIKE', $sstr),
1235
+				'VNU_short_desc'         => array('LIKE', $sstr),
1236
+				'VNU_address'            => array('LIKE', $sstr),
1237
+				'VNU_address2'           => array('LIKE', $sstr),
1238
+				'VNU_city'               => array('LIKE', $sstr),
1239
+				'VNU_zip'                => array('LIKE', $sstr),
1240
+				'VNU_phone'              => array('LIKE', $sstr),
1241
+				'VNU_url'                => array('LIKE', $sstr),
1242
+				'VNU_virtual_phone'      => array('LIKE', $sstr),
1243
+				'VNU_virtual_url'        => array('LIKE', $sstr),
1244
+				'VNU_google_map_link'    => array('LIKE', $sstr),
1245
+				'Event.EVT_name'         => array('LIKE', $sstr),
1246
+				'Event.EVT_desc'         => array('LIKE', $sstr),
1247
+				'Event.EVT_phone'        => array('LIKE', $sstr),
1248
+				'Event.EVT_external_URL' => array('LIKE', $sstr),
1249
+			);
1250
+		}
1251 1251
 
1252 1252
 
1253
-        $venues = $count
1254
-            ? $this->_venue_model->count(array($where), 'VNU_ID')
1255
-            : $this->_venue_model->get_all(
1256
-                array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)
1257
-            );
1258
-
1259
-        return $venues;
1260
-    }
1261
-
1262
-
1263
-
1264
-
1265
-    /** Venue Category Stuff **/
1266
-
1267
-    /**
1268
-     * set the _category property with the category object for the loaded page.
1269
-     *
1270
-     * @access private
1271
-     * @return void
1272
-     */
1273
-    private function _set_category_object()
1274
-    {
1275
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
1276
-            return;
1277
-        } // already have the category object so get out.
1278
-
1279
-        // set default category object
1280
-        $this->_set_empty_category_object();
1281
-
1282
-        // only set if we've got an id
1283
-        if (! isset($this->_req_data['VEN_CAT_ID'])) {
1284
-            return;
1285
-        }
1286
-
1287
-        $category_id = absint($this->_req_data['VEN_CAT_ID']);
1288
-        $term = get_term($category_id, 'espresso_venue_categories');
1289
-
1290
-
1291
-        if (! empty($term)) {
1292
-            $this->_category->category_name = $term->name;
1293
-            $this->_category->category_identifier = $term->slug;
1294
-            $this->_category->category_desc = $term->description;
1295
-            $this->_category->id = $term->term_id;
1296
-            $this->_category->parent = $term->parent;
1297
-        }
1298
-    }
1299
-
1300
-
1301
-    private function _set_empty_category_object()
1302
-    {
1303
-        $this->_category = new stdClass();
1304
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1305
-        $this->_category->id = $this->_category->parent = 0;
1306
-    }
1307
-
1308
-
1309
-    protected function _category_list_table()
1310
-    {
1311
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1312
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1313
-            'add_category',
1314
-            'add_category',
1315
-            array(),
1316
-            'add-new-h2'
1317
-        );
1318
-        $this->_search_btn_label = __('Venue Categories', 'event_espresso');
1319
-        $this->display_admin_list_table_page_with_sidebar();
1320
-    }
1321
-
1322
-
1323
-    protected function _category_details($view)
1324
-    {
1325
-
1326
-        // load formatter helper
1327
-        // load field generator helper
1328
-
1329
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
1330
-        $this->_set_add_edit_form_tags($route);
1331
-
1332
-        $this->_set_category_object();
1333
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
1334
-
1335
-        $delete_action = 'delete_category';
1336
-
1337
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url);
1338
-
1339
-        $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1340
-
1341
-        // take care of contents
1342
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
1343
-        $this->display_admin_page_with_sidebar();
1344
-    }
1345
-
1346
-
1347
-    protected function _category_details_content()
1348
-    {
1349
-        $editor_args['category_desc'] = array(
1350
-            'type'          => 'wp_editor',
1351
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1352
-            'class'         => 'my_editor_custom',
1353
-            'wpeditor_args' => array('media_buttons' => false),
1354
-        );
1355
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
1356
-
1357
-        $all_terms = get_terms(
1358
-            array('espresso_venue_categories'),
1359
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
1360
-        );
1361
-
1362
-        // setup category select for term parents.
1363
-        $category_select_values[] = array(
1364
-            'text' => __('No Parent', 'event_espresso'),
1365
-            'id'   => 0,
1366
-        );
1367
-        foreach ($all_terms as $term) {
1368
-            $category_select_values[] = array(
1369
-                'text' => $term->name,
1370
-                'id'   => $term->term_id,
1371
-            );
1372
-        }
1373
-
1374
-        $category_select = EEH_Form_Fields::select_input(
1375
-            'category_parent',
1376
-            $category_select_values,
1377
-            $this->_category->parent
1378
-        );
1379
-        $template_args = array(
1380
-            'category'                 => $this->_category,
1381
-            'category_select'          => $category_select,
1382
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1383
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1384
-            'disable'                  => '',
1385
-            'disabled_message'         => false,
1386
-        );
1387
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1388
-        return EEH_Template::display_template($template, $template_args, true);
1389
-    }
1390
-
1391
-
1392
-    protected function _delete_categories()
1393
-    {
1394
-        $cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID']
1395
-            : (array) $this->_req_data['category_id'];
1396
-
1397
-        foreach ($cat_ids as $cat_id) {
1398
-            $this->_delete_category($cat_id);
1399
-        }
1400
-
1401
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
1402
-        $query_args = array(
1403
-            'action' => 'category_list',
1404
-        );
1405
-        $this->_redirect_after_action(0, '', '', $query_args);
1406
-    }
1407
-
1408
-
1409
-    protected function _delete_category($cat_id)
1410
-    {
1411
-        $cat_id = absint($cat_id);
1412
-        wp_delete_term($cat_id, 'espresso_venue_categories');
1413
-    }
1414
-
1415
-
1416
-    protected function _insert_or_update_category($new_category)
1417
-    {
1418
-
1419
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1420
-        $success = 0; // we already have a success message so lets not send another.
1421
-        if ($cat_id) {
1422
-            $query_args = array(
1423
-                'action'     => 'edit_category',
1424
-                'VEN_CAT_ID' => $cat_id,
1425
-            );
1426
-        } else {
1427
-            $query_args = array('action' => 'add_category');
1428
-        }
1429
-        $this->_redirect_after_action($success, '', '', $query_args, true);
1430
-    }
1431
-
1432
-
1433
-    private function _insert_category($update = false)
1434
-    {
1435
-        $cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : '';
1436
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
1437
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
1438
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
1439
-
1440
-        if (empty($category_name)) {
1441
-            $msg = __('You must add a name for the category.', 'event_espresso');
1442
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1443
-            return false;
1444
-        }
1445
-
1446
-
1447
-        $term_args = array(
1448
-            'name'        => $category_name,
1449
-            'description' => $category_desc,
1450
-            'parent'      => $category_parent,
1451
-        );
1452
-
1453
-        $insert_ids = $update
1454
-            ? wp_update_term($cat_id, 'espresso_venue_categories', $term_args)
1455
-            : wp_insert_term(
1456
-                $category_name,
1457
-                'espresso_venue_categories',
1458
-                $term_args
1459
-            );
1460
-
1461
-        if (! is_array($insert_ids)) {
1462
-            $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1463
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1464
-        } else {
1465
-            $cat_id = $insert_ids['term_id'];
1466
-            $msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name);
1467
-            EE_Error::add_success($msg);
1468
-        }
1469
-
1470
-        return $cat_id;
1471
-    }
1472
-
1473
-
1474
-    /**
1475
-     * TODO handle category exports()
1476
-     *
1477
-     * @return file export
1478
-     */
1479
-    protected function _categories_export()
1480
-    {
1481
-
1482
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
1483
-        $new_request_args = array(
1484
-            'export'       => 'report',
1485
-            'action'       => 'categories',
1486
-            'category_ids' => $this->_req_data['VEN_CAT_ID'],
1487
-        );
1488
-
1489
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
1490
-
1491
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1492
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1493
-            $EE_Export = EE_Export::instance($this->_req_data);
1494
-            $EE_Export->export();
1495
-        }
1496
-    }
1497
-
1498
-
1499
-    protected function _import_categories()
1500
-    {
1501
-
1502
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1503
-        EE_Import::instance()->import();
1504
-    }
1505
-
1506
-
1507
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
1508
-    {
1509
-
1510
-        // testing term stuff
1511
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
1512
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1513
-        $limit = ($current_page - 1) * $per_page;
1514
-        $where = array('taxonomy' => 'espresso_venue_categories');
1515
-        if (isset($this->_req_data['s'])) {
1516
-            $sstr = '%' . $this->_req_data['s'] . '%';
1517
-            $where['OR'] = array(
1518
-                'Term.name'   => array('LIKE', $sstr),
1519
-                'description' => array('LIKE', $sstr),
1520
-            );
1521
-        }
1522
-
1523
-        $query_params = array(
1524
-            $where,
1525
-            'order_by'   => array($orderby => $order),
1526
-            'limit'      => $limit . ',' . $per_page,
1527
-            'force_join' => array('Term'),
1528
-        );
1529
-
1530
-        $categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1531
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
1532
-
1533
-        return $categories;
1534
-    }
1535
-
1536
-
1537
-    /* end category stuff */
1538
-    /**************/
1253
+		$venues = $count
1254
+			? $this->_venue_model->count(array($where), 'VNU_ID')
1255
+			: $this->_venue_model->get_all(
1256
+				array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)
1257
+			);
1258
+
1259
+		return $venues;
1260
+	}
1261
+
1262
+
1263
+
1264
+
1265
+	/** Venue Category Stuff **/
1266
+
1267
+	/**
1268
+	 * set the _category property with the category object for the loaded page.
1269
+	 *
1270
+	 * @access private
1271
+	 * @return void
1272
+	 */
1273
+	private function _set_category_object()
1274
+	{
1275
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
1276
+			return;
1277
+		} // already have the category object so get out.
1278
+
1279
+		// set default category object
1280
+		$this->_set_empty_category_object();
1281
+
1282
+		// only set if we've got an id
1283
+		if (! isset($this->_req_data['VEN_CAT_ID'])) {
1284
+			return;
1285
+		}
1286
+
1287
+		$category_id = absint($this->_req_data['VEN_CAT_ID']);
1288
+		$term = get_term($category_id, 'espresso_venue_categories');
1289
+
1290
+
1291
+		if (! empty($term)) {
1292
+			$this->_category->category_name = $term->name;
1293
+			$this->_category->category_identifier = $term->slug;
1294
+			$this->_category->category_desc = $term->description;
1295
+			$this->_category->id = $term->term_id;
1296
+			$this->_category->parent = $term->parent;
1297
+		}
1298
+	}
1299
+
1300
+
1301
+	private function _set_empty_category_object()
1302
+	{
1303
+		$this->_category = new stdClass();
1304
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1305
+		$this->_category->id = $this->_category->parent = 0;
1306
+	}
1307
+
1308
+
1309
+	protected function _category_list_table()
1310
+	{
1311
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1312
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1313
+			'add_category',
1314
+			'add_category',
1315
+			array(),
1316
+			'add-new-h2'
1317
+		);
1318
+		$this->_search_btn_label = __('Venue Categories', 'event_espresso');
1319
+		$this->display_admin_list_table_page_with_sidebar();
1320
+	}
1321
+
1322
+
1323
+	protected function _category_details($view)
1324
+	{
1325
+
1326
+		// load formatter helper
1327
+		// load field generator helper
1328
+
1329
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
1330
+		$this->_set_add_edit_form_tags($route);
1331
+
1332
+		$this->_set_category_object();
1333
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
1334
+
1335
+		$delete_action = 'delete_category';
1336
+
1337
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url);
1338
+
1339
+		$this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1340
+
1341
+		// take care of contents
1342
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
1343
+		$this->display_admin_page_with_sidebar();
1344
+	}
1345
+
1346
+
1347
+	protected function _category_details_content()
1348
+	{
1349
+		$editor_args['category_desc'] = array(
1350
+			'type'          => 'wp_editor',
1351
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1352
+			'class'         => 'my_editor_custom',
1353
+			'wpeditor_args' => array('media_buttons' => false),
1354
+		);
1355
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
1356
+
1357
+		$all_terms = get_terms(
1358
+			array('espresso_venue_categories'),
1359
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
1360
+		);
1361
+
1362
+		// setup category select for term parents.
1363
+		$category_select_values[] = array(
1364
+			'text' => __('No Parent', 'event_espresso'),
1365
+			'id'   => 0,
1366
+		);
1367
+		foreach ($all_terms as $term) {
1368
+			$category_select_values[] = array(
1369
+				'text' => $term->name,
1370
+				'id'   => $term->term_id,
1371
+			);
1372
+		}
1373
+
1374
+		$category_select = EEH_Form_Fields::select_input(
1375
+			'category_parent',
1376
+			$category_select_values,
1377
+			$this->_category->parent
1378
+		);
1379
+		$template_args = array(
1380
+			'category'                 => $this->_category,
1381
+			'category_select'          => $category_select,
1382
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1383
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1384
+			'disable'                  => '',
1385
+			'disabled_message'         => false,
1386
+		);
1387
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1388
+		return EEH_Template::display_template($template, $template_args, true);
1389
+	}
1390
+
1391
+
1392
+	protected function _delete_categories()
1393
+	{
1394
+		$cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID']
1395
+			: (array) $this->_req_data['category_id'];
1396
+
1397
+		foreach ($cat_ids as $cat_id) {
1398
+			$this->_delete_category($cat_id);
1399
+		}
1400
+
1401
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
1402
+		$query_args = array(
1403
+			'action' => 'category_list',
1404
+		);
1405
+		$this->_redirect_after_action(0, '', '', $query_args);
1406
+	}
1407
+
1408
+
1409
+	protected function _delete_category($cat_id)
1410
+	{
1411
+		$cat_id = absint($cat_id);
1412
+		wp_delete_term($cat_id, 'espresso_venue_categories');
1413
+	}
1414
+
1415
+
1416
+	protected function _insert_or_update_category($new_category)
1417
+	{
1418
+
1419
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1420
+		$success = 0; // we already have a success message so lets not send another.
1421
+		if ($cat_id) {
1422
+			$query_args = array(
1423
+				'action'     => 'edit_category',
1424
+				'VEN_CAT_ID' => $cat_id,
1425
+			);
1426
+		} else {
1427
+			$query_args = array('action' => 'add_category');
1428
+		}
1429
+		$this->_redirect_after_action($success, '', '', $query_args, true);
1430
+	}
1431
+
1432
+
1433
+	private function _insert_category($update = false)
1434
+	{
1435
+		$cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : '';
1436
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
1437
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
1438
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
1439
+
1440
+		if (empty($category_name)) {
1441
+			$msg = __('You must add a name for the category.', 'event_espresso');
1442
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1443
+			return false;
1444
+		}
1445
+
1446
+
1447
+		$term_args = array(
1448
+			'name'        => $category_name,
1449
+			'description' => $category_desc,
1450
+			'parent'      => $category_parent,
1451
+		);
1452
+
1453
+		$insert_ids = $update
1454
+			? wp_update_term($cat_id, 'espresso_venue_categories', $term_args)
1455
+			: wp_insert_term(
1456
+				$category_name,
1457
+				'espresso_venue_categories',
1458
+				$term_args
1459
+			);
1460
+
1461
+		if (! is_array($insert_ids)) {
1462
+			$msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1463
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1464
+		} else {
1465
+			$cat_id = $insert_ids['term_id'];
1466
+			$msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name);
1467
+			EE_Error::add_success($msg);
1468
+		}
1469
+
1470
+		return $cat_id;
1471
+	}
1472
+
1473
+
1474
+	/**
1475
+	 * TODO handle category exports()
1476
+	 *
1477
+	 * @return file export
1478
+	 */
1479
+	protected function _categories_export()
1480
+	{
1481
+
1482
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
1483
+		$new_request_args = array(
1484
+			'export'       => 'report',
1485
+			'action'       => 'categories',
1486
+			'category_ids' => $this->_req_data['VEN_CAT_ID'],
1487
+		);
1488
+
1489
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
1490
+
1491
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1492
+			require_once(EE_CLASSES . 'EE_Export.class.php');
1493
+			$EE_Export = EE_Export::instance($this->_req_data);
1494
+			$EE_Export->export();
1495
+		}
1496
+	}
1497
+
1498
+
1499
+	protected function _import_categories()
1500
+	{
1501
+
1502
+		require_once(EE_CLASSES . 'EE_Import.class.php');
1503
+		EE_Import::instance()->import();
1504
+	}
1505
+
1506
+
1507
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
1508
+	{
1509
+
1510
+		// testing term stuff
1511
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
1512
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1513
+		$limit = ($current_page - 1) * $per_page;
1514
+		$where = array('taxonomy' => 'espresso_venue_categories');
1515
+		if (isset($this->_req_data['s'])) {
1516
+			$sstr = '%' . $this->_req_data['s'] . '%';
1517
+			$where['OR'] = array(
1518
+				'Term.name'   => array('LIKE', $sstr),
1519
+				'description' => array('LIKE', $sstr),
1520
+			);
1521
+		}
1522
+
1523
+		$query_params = array(
1524
+			$where,
1525
+			'order_by'   => array($orderby => $order),
1526
+			'limit'      => $limit . ',' . $per_page,
1527
+			'force_join' => array('Term'),
1528
+		);
1529
+
1530
+		$categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1531
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
1532
+
1533
+		return $categories;
1534
+	}
1535
+
1536
+
1537
+	/* end category stuff */
1538
+	/**************/
1539 1539
 }
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   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __construct($routing = true)
38 38
     {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
39
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
41
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
42
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
43 43
         }
44 44
         parent::__construct($routing);
45 45
         $this->admin_config = $this->loader->getShared('EE_Admin_Config');
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     protected function _extend_page_config()
59 59
     {
60
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
60
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
61 61
         // is there a evt_id in the request?
62 62
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
63 63
             ? $this->_req_data['EVT_ID']
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
                 'capability' => 'manage_options',
109 109
                 'noheader'   => true,
110 110
             ],
111
-        ];        // don't load these meta boxes if using the advanced editor
111
+        ]; // don't load these meta boxes if using the advanced editor
112 112
         $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
113 113
         $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
114
-        if (! $this->admin_config->useAdvancedEditor()) {
114
+        if ( ! $this->admin_config->useAdvancedEditor()) {
115 115
             $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
116 116
             $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
117 117
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     {
304 304
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
305 305
         // make sure this is only when editing
306
-        if (! empty($id)) {
306
+        if ( ! empty($id)) {
307 307
             $href = EE_Admin_Page::add_query_args_and_nonce(
308 308
                 ['action' => 'duplicate_event', 'EVT_ID' => $id],
309 309
                 $this->_admin_base_url
@@ -353,10 +353,10 @@  discard block
 block discarded – undo
353 353
      */
354 354
     public function load_scripts_styles_edit()
355 355
     {
356
-        if (! $this->admin_config->useAdvancedEditor()) {
356
+        if ( ! $this->admin_config->useAdvancedEditor()) {
357 357
             wp_register_script(
358 358
                 'ee-event-editor-heartbeat',
359
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
359
+                EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
360 360
                 ['ee_admin_js', 'heartbeat'],
361 361
                 EVENT_ESPRESSO_VERSION,
362 362
                 true
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
     public function add_additional_datetime_button($template, $template_args)
382 382
     {
383 383
         return EEH_Template::display_template(
384
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
384
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
385 385
             $template_args,
386 386
             true
387 387
         );
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     public function add_datetime_clone_button($template, $template_args)
400 400
     {
401 401
         return EEH_Template::display_template(
402
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
402
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
403 403
             $template_args,
404 404
             true
405 405
         );
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
     public function datetime_timezones_template($template, $template_args)
418 418
     {
419 419
         return EEH_Template::display_template(
420
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
420
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
421 421
             $template_args,
422 422
             true
423 423
         );
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
     {
549 549
         // first make sure the ID for the event is in the request.
550 550
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
551
-        if (! isset($this->_req_data['EVT_ID'])) {
551
+        if ( ! isset($this->_req_data['EVT_ID'])) {
552 552
             EE_Error::add_error(
553 553
                 esc_html__(
554 554
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
         }
564 564
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
565 565
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
566
-        if (! $orig_event instanceof EE_Event) {
566
+        if ( ! $orig_event instanceof EE_Event) {
567 567
             throw new EE_Error(
568 568
                 sprintf(
569 569
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
         $orig_ven = $orig_event->get_many_related('Venue');
580 580
         // reset the ID and modify other details to make it clear this is a dupe
581 581
         $new_event->set('EVT_ID', 0);
582
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
582
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
583 583
         $new_event->set('EVT_name', $new_name);
584 584
         $new_event->set(
585 585
             'EVT_slug',
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
             'Question_Group',
609 609
             [['Event_Question_Group.EQG_primary' => true]]
610 610
         );
611
-        if (! empty($orig_primary_qgs)) {
611
+        if ( ! empty($orig_primary_qgs)) {
612 612
             foreach ($orig_primary_qgs as $id => $obj) {
613 613
                 if ($obj instanceof EE_Question_Group) {
614 614
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
             'Question_Group',
621 621
             [['Event_Question_Group.EQG_additional' => true]]
622 622
         );
623
-        if (! empty($orig_additional_qgs)) {
623
+        if ( ! empty($orig_additional_qgs)) {
624 624
             foreach ($orig_additional_qgs as $id => $obj) {
625 625
                 if ($obj instanceof EE_Question_Group) {
626 626
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
634 634
         $cloned_tickets = [];
635 635
         foreach ($orig_datetimes as $orig_dtt) {
636
-            if (! $orig_dtt instanceof EE_Datetime) {
636
+            if ( ! $orig_dtt instanceof EE_Datetime) {
637 637
                 continue;
638 638
             }
639 639
             $new_dtt = clone $orig_dtt;
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
             // now let's get the ticket relations setup.
649 649
             foreach ((array) $orig_tkts as $orig_tkt) {
650 650
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
651
-                if (! $orig_tkt instanceof EE_Ticket) {
651
+                if ( ! $orig_tkt instanceof EE_Ticket) {
652 652
                     continue;
653 653
                 }
654 654
                 // is this ticket archived?  If it is then let's skip
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
                 }
658 658
                 // does this original ticket already exist in the clone_tickets cache?
659 659
                 //  If so we'll just use the new ticket from it.
660
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
661
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
660
+                if (isset($cloned_tickets[$orig_tkt->ID()])) {
661
+                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
662 662
                 } else {
663 663
                     $new_tkt = clone $orig_tkt;
664 664
                     // get relations on the $orig_tkt that we need to setup.
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
                 // for use with later datetimes that have the same ticket.
692 692
                 $new_dtt->_add_relation_to($new_tkt, 'Ticket');
693 693
                 $new_dtt->save();
694
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
694
+                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
695 695
             }
696 696
         }
697 697
         // clone taxonomy information
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
             $this->_admin_base_url
779 779
         );
780 780
         $content = EEH_Template::display_template(
781
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
781
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
782 782
             $this->_template_args,
783 783
             true
784 784
         );
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
      */
800 800
     protected function _import_events()
801 801
     {
802
-        require_once(EE_CLASSES . 'EE_Import.class.php');
802
+        require_once(EE_CLASSES.'EE_Import.class.php');
803 803
         $success = EE_Import::instance()->import();
804 804
         $this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true);
805 805
     }
@@ -828,8 +828,8 @@  discard block
 block discarded – undo
828 828
             'EVT_ID' => $event_ids,
829 829
         ];
830 830
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
831
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
832
-            require_once(EE_CLASSES . 'EE_Export.class.php');
831
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
832
+            require_once(EE_CLASSES.'EE_Export.class.php');
833 833
             $EE_Export = EE_Export::instance($this->_req_data);
834 834
             if ($EE_Export instanceof EE_Export) {
835 835
                 $EE_Export->export();
@@ -852,8 +852,8 @@  discard block
 block discarded – undo
852 852
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
853 853
         ];
854 854
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
855
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
856
-            require_once(EE_CLASSES . 'EE_Export.class.php');
855
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
856
+            require_once(EE_CLASSES.'EE_Export.class.php');
857 857
             $EE_Export = EE_Export::instance($this->_req_data);
858 858
             if ($EE_Export instanceof EE_Export) {
859 859
                 $EE_Export->export();
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
         $this->_set_add_edit_form_tags('update_template_settings');
899 899
         $this->_set_publish_post_box_vars(null, false, false, null, false);
900 900
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
901
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
901
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
902 902
             $this->_template_args,
903 903
             true
904 904
         );
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
         /** @var FeatureFlags $flags */
968 968
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
969 969
         // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
970
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
970
+        if ( ! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
971 971
             add_meta_box(
972 972
                 'espresso_event_editor_event_options',
973 973
                 esc_html__('Event Registration Options', 'event_espresso'),
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
             $default_reg_status_values
1037 1037
         );
1038 1038
         EEH_Template::display_template(
1039
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1039
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
1040 1040
             $template_args
1041 1041
         );
1042 1042
     }
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
         $venues = $venue_model->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1146 1146
 
1147 1147
         foreach ($venues as $venue) {
1148
-            $values[ $venue->ID() ] = $venue->name();
1148
+            $values[$venue->ID()] = $venue->name();
1149 1149
         }
1150 1150
 
1151 1151
         return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
@@ -1179,13 +1179,13 @@  discard block
 block discarded – undo
1179 1179
     {
1180 1180
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1181 1181
             'DTT_EVT_start',
1182
-            date('Y-m-d') . ' 00:00:00',
1182
+            date('Y-m-d').' 00:00:00',
1183 1183
             'Y-m-d H:i:s',
1184 1184
             'UTC'
1185 1185
         );
1186 1186
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1187 1187
             'DTT_EVT_start',
1188
-            date('Y-m-d') . ' 23:59:59',
1188
+            date('Y-m-d').' 23:59:59',
1189 1189
             'Y-m-d H:i:s',
1190 1190
             'UTC'
1191 1191
         );
@@ -1214,13 +1214,13 @@  discard block
 block discarded – undo
1214 1214
         $days_this_month = date('t');
1215 1215
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1216 1216
             'DTT_EVT_start',
1217
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1217
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1218 1218
             'Y-m-d H:i:s',
1219 1219
             'UTC'
1220 1220
         );
1221 1221
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1222 1222
             'DTT_EVT_start',
1223
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1223
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1224 1224
             'Y-m-d H:i:s',
1225 1225
             'UTC'
1226 1226
         );
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
         $offset = ($current_page - 1) * $per_page;
1297 1297
         $limit = [$offset, $per_page];
1298 1298
         if (isset($this->_req_data['s'])) {
1299
-            $sstr = '%' . $this->_req_data['s'] . '%';
1299
+            $sstr = '%'.$this->_req_data['s'].'%';
1300 1300
             $_where['OR'] = [
1301 1301
                 'TKT_name'        => ['LIKE', $sstr],
1302 1302
                 'TKT_description' => ['LIKE', $sstr],
@@ -1327,16 +1327,16 @@  discard block
 block discarded – undo
1327 1327
         $success = 1;
1328 1328
         $TKT = EEM_Ticket::instance();
1329 1329
         // checkboxes?
1330
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1330
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1331 1331
             // if array has more than one element then success message should be plural
1332 1332
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1333 1333
             // cycle thru the boxes
1334 1334
             foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1335 1335
                 if ($trash) {
1336
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1336
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1337 1337
                         $success = 0;
1338 1338
                     }
1339
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1339
+                } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1340 1340
                     $success = 0;
1341 1341
                 }
1342 1342
             }
@@ -1344,10 +1344,10 @@  discard block
 block discarded – undo
1344 1344
             // grab single id and trash
1345 1345
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1346 1346
             if ($trash) {
1347
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1347
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1348 1348
                     $success = 0;
1349 1349
                 }
1350
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1350
+            } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1351 1351
                 $success = 0;
1352 1352
             }
1353 1353
         }
@@ -1373,20 +1373,20 @@  discard block
 block discarded – undo
1373 1373
     {
1374 1374
         $success = 1;
1375 1375
         // checkboxes?
1376
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1376
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1377 1377
             // if array has more than one element then success message should be plural
1378 1378
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1379 1379
             // cycle thru the boxes
1380 1380
             foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1381 1381
                 // delete
1382
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1382
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1383 1383
                     $success = 0;
1384 1384
                 }
1385 1385
             }
1386 1386
         } else {
1387 1387
             // grab single id and trash
1388 1388
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1389
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1389
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1390 1390
                 $success = 0;
1391 1391
             }
1392 1392
         }
@@ -1419,7 +1419,7 @@  discard block
 block discarded – undo
1419 1419
     protected function _delete_the_ticket($TKT_ID)
1420 1420
     {
1421 1421
         $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1422
-        if (! $ticket instanceof EE_Ticket) {
1422
+        if ( ! $ticket instanceof EE_Ticket) {
1423 1423
             return false;
1424 1424
         }
1425 1425
         $ticket->_remove_relations('Datetime');
Please login to merge, or discard this patch.
Indentation   +1413 added lines, -1413 removed lines patch added patch discarded remove patch
@@ -17,1417 +17,1417 @@
 block discarded – undo
17 17
 class Extend_Events_Admin_Page extends Events_Admin_Page
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Admin_Config
22
-     */
23
-    protected $admin_config;
24
-
25
-    /**
26
-     * @var AdvancedEditorAdminFormSection
27
-     */
28
-    protected $advanced_editor_admin_form;
29
-
30
-
31
-    /**
32
-     * Extend_Events_Admin_Page constructor.
33
-     *
34
-     * @param bool $routing
35
-     * @throws ReflectionException
36
-     */
37
-    public function __construct($routing = true)
38
-    {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
-        }
44
-        parent::__construct($routing);
45
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
-    }
47
-
48
-
49
-    /**
50
-     * Sets routes.
51
-     *
52
-     * @throws EE_Error
53
-     * @throws InvalidArgumentException
54
-     * @throws InvalidDataTypeException
55
-     * @throws InvalidInterfaceException
56
-     * @throws Exception
57
-     */
58
-    protected function _extend_page_config()
59
-    {
60
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
61
-        // is there a evt_id in the request?
62
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
63
-            ? $this->_req_data['EVT_ID']
64
-            : 0;
65
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
66
-        // tkt_id?
67
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
68
-            ? $this->_req_data['TKT_ID']
69
-            : 0;
70
-        $new_page_routes = [
71
-            'duplicate_event'          => [
72
-                'func'       => '_duplicate_event',
73
-                'capability' => 'ee_edit_event',
74
-                'obj_id'     => $evt_id,
75
-                'noheader'   => true,
76
-            ],
77
-            'import_page'              => [
78
-                'func'       => '_import_page',
79
-                'capability' => 'import',
80
-            ],
81
-            'import'                   => [
82
-                'func'       => '_import_events',
83
-                'capability' => 'import',
84
-                'noheader'   => true,
85
-            ],
86
-            'import_events'            => [
87
-                'func'       => '_import_events',
88
-                'capability' => 'import',
89
-                'noheader'   => true,
90
-            ],
91
-            'export_events'            => [
92
-                'func'       => '_events_export',
93
-                'capability' => 'export',
94
-                'noheader'   => true,
95
-            ],
96
-            'export_categories'        => [
97
-                'func'       => '_categories_export',
98
-                'capability' => 'export',
99
-                'noheader'   => true,
100
-            ],
101
-            'sample_export_file'       => [
102
-                'func'       => '_sample_export_file',
103
-                'capability' => 'export',
104
-                'noheader'   => true,
105
-            ],
106
-            'update_template_settings' => [
107
-                'func'       => '_update_template_settings',
108
-                'capability' => 'manage_options',
109
-                'noheader'   => true,
110
-            ],
111
-        ];        // don't load these meta boxes if using the advanced editor
112
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
113
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
114
-        if (! $this->admin_config->useAdvancedEditor()) {
115
-            $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
116
-            $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
117
-
118
-            $legacy_editor_page_routes = [
119
-                'ticket_list_table' => [
120
-                    'func'       => '_tickets_overview_list_table',
121
-                    'capability' => 'ee_read_default_tickets',
122
-                ],
123
-                'trash_ticket'      => [
124
-                    'func'       => '_trash_or_restore_ticket',
125
-                    'capability' => 'ee_delete_default_ticket',
126
-                    'obj_id'     => $tkt_id,
127
-                    'noheader'   => true,
128
-                    'args'       => ['trash' => true],
129
-                ],
130
-                'trash_tickets'     => [
131
-                    'func'       => '_trash_or_restore_ticket',
132
-                    'capability' => 'ee_delete_default_tickets',
133
-                    'noheader'   => true,
134
-                    'args'       => ['trash' => true],
135
-                ],
136
-                'restore_ticket'    => [
137
-                    'func'       => '_trash_or_restore_ticket',
138
-                    'capability' => 'ee_delete_default_ticket',
139
-                    'obj_id'     => $tkt_id,
140
-                    'noheader'   => true,
141
-                ],
142
-                'restore_tickets'   => [
143
-                    'func'       => '_trash_or_restore_ticket',
144
-                    'capability' => 'ee_delete_default_tickets',
145
-                    'noheader'   => true,
146
-                ],
147
-                'delete_ticket'     => [
148
-                    'func'       => '_delete_ticket',
149
-                    'capability' => 'ee_delete_default_ticket',
150
-                    'obj_id'     => $tkt_id,
151
-                    'noheader'   => true,
152
-                ],
153
-                'delete_tickets'    => [
154
-                    'func'       => '_delete_ticket',
155
-                    'capability' => 'ee_delete_default_tickets',
156
-                    'noheader'   => true,
157
-                ],
158
-            ];
159
-            $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes);
160
-        }
161
-
162
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
163
-        // partial route/config override
164
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
165
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
166
-        // add tickets tab but only if there are more than one default ticket!
167
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
168
-            [['TKT_is_default' => 1]],
169
-            'TKT_ID',
170
-            true
171
-        );
172
-        if ($tkt_count > 1) {
173
-            $new_page_config = [
174
-                'ticket_list_table' => [
175
-                    'nav'           => [
176
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
177
-                        'order' => 60,
178
-                    ],
179
-                    'list_table'    => 'Tickets_List_Table',
180
-                    'require_nonce' => false,
181
-                ],
182
-            ];
183
-        }
184
-        // template settings
185
-        $new_page_config['template_settings'] = [
186
-            'nav'           => [
187
-                'label' => esc_html__('Templates', 'event_espresso'),
188
-                'order' => 30,
189
-            ],
190
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
191
-            'help_tabs'     => [
192
-                'general_settings_templates_help_tab' => [
193
-                    'title'    => esc_html__('Templates', 'event_espresso'),
194
-                    'filename' => 'general_settings_templates',
195
-                ],
196
-            ],
197
-           // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
198
-            // 'help_tour'     => ['Templates_Help_Tour'],
199
-            'require_nonce' => false,
200
-        ];
201
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
202
-        // add filters and actions
203
-        // modifying _views
204
-        add_filter(
205
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
206
-            [$this, 'add_additional_datetime_button'],
207
-            10,
208
-            2
209
-        );
210
-        add_filter(
211
-            'FHEE_event_datetime_metabox_clone_button_template',
212
-            [$this, 'add_datetime_clone_button'],
213
-            10,
214
-            2
215
-        );
216
-        add_filter(
217
-            'FHEE_event_datetime_metabox_timezones_template',
218
-            [$this, 'datetime_timezones_template'],
219
-            10,
220
-            2
221
-        );
222
-        // filters for event list table
223
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
224
-        add_filter(
225
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
226
-            [$this, 'extra_list_table_actions'],
227
-            10,
228
-            2
229
-        );
230
-        // legend item
231
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
232
-        add_action('admin_init', [$this, 'admin_init']);
233
-        // load additional handlers
234
-        $this->handleActionRequest();
235
-    }
236
-
237
-
238
-    private function getRequestAction()
239
-    {
240
-        return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null;
241
-    }
242
-
243
-
244
-    /**
245
-     * @throws Exception
246
-     */
247
-    private function handleActionRequest()
248
-    {
249
-        $action = $this->getRequestAction();
250
-        if ($action) {
251
-            // setup Advanced Editor ???
252
-            if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
253
-                $this->advanced_editor_admin_form = $this->loader->getShared(
254
-                    'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
255
-                );
256
-            }
257
-        }
258
-    }
259
-
260
-
261
-    /**
262
-     * admin_init
263
-     */
264
-    public function admin_init()
265
-    {
266
-        EE_Registry::$i18n_js_strings = array_merge(
267
-            EE_Registry::$i18n_js_strings,
268
-            [
269
-                'image_confirm'          => esc_html__(
270
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
271
-                    'event_espresso'
272
-                ),
273
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
274
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
275
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
276
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
277
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
278
-            ]
279
-        );
280
-    }
281
-
282
-
283
-    /**
284
-     * Add per page screen options to the default ticket list table view.
285
-     *
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidDataTypeException
288
-     * @throws InvalidInterfaceException
289
-     */
290
-    protected function _add_screen_options_ticket_list_table()
291
-    {
292
-        $this->_per_page_screen_option();
293
-    }
294
-
295
-
296
-    /**
297
-     * @param string $return
298
-     * @param int    $id
299
-     * @param string $new_title
300
-     * @param string $new_slug
301
-     * @return string
302
-     */
303
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
304
-    {
305
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
306
-        // make sure this is only when editing
307
-        if (! empty($id)) {
308
-            $href = EE_Admin_Page::add_query_args_and_nonce(
309
-                ['action' => 'duplicate_event', 'EVT_ID' => $id],
310
-                $this->_admin_base_url
311
-            );
312
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
313
-            $return .= '<a href="'
314
-                       . $href
315
-                       . '" title="'
316
-                       . $title
317
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
318
-                       . $title
319
-                       . '</a>';
320
-        }
321
-        return $return;
322
-    }
323
-
324
-
325
-    /**
326
-     * Set the list table views for the default ticket list table view.
327
-     */
328
-    public function _set_list_table_views_ticket_list_table()
329
-    {
330
-        $this->_views = [
331
-            'all'     => [
332
-                'slug'        => 'all',
333
-                'label'       => esc_html__('All', 'event_espresso'),
334
-                'count'       => 0,
335
-                'bulk_action' => [
336
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
337
-                ],
338
-            ],
339
-            'trashed' => [
340
-                'slug'        => 'trashed',
341
-                'label'       => esc_html__('Trash', 'event_espresso'),
342
-                'count'       => 0,
343
-                'bulk_action' => [
344
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
345
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
346
-                ],
347
-            ],
348
-        ];
349
-    }
350
-
351
-
352
-    /**
353
-     * Enqueue scripts and styles for the event editor.
354
-     */
355
-    public function load_scripts_styles_edit()
356
-    {
357
-        if (! $this->admin_config->useAdvancedEditor()) {
358
-            wp_register_script(
359
-                'ee-event-editor-heartbeat',
360
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
361
-                ['ee_admin_js', 'heartbeat'],
362
-                EVENT_ESPRESSO_VERSION,
363
-                true
364
-            );
365
-            wp_enqueue_script('ee-accounting');
366
-            wp_enqueue_script('ee-event-editor-heartbeat');
367
-        }
368
-        wp_enqueue_script('event_editor_js');
369
-        // styles
370
-        wp_enqueue_style('espresso-ui-theme');
371
-    }
372
-
373
-
374
-    /**
375
-     * Returns template for the additional datetime.
376
-     *
377
-     * @param $template
378
-     * @param $template_args
379
-     * @return mixed
380
-     * @throws DomainException
381
-     */
382
-    public function add_additional_datetime_button($template, $template_args)
383
-    {
384
-        return EEH_Template::display_template(
385
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
386
-            $template_args,
387
-            true
388
-        );
389
-    }
390
-
391
-
392
-    /**
393
-     * Returns the template for cloning a datetime.
394
-     *
395
-     * @param $template
396
-     * @param $template_args
397
-     * @return mixed
398
-     * @throws DomainException
399
-     */
400
-    public function add_datetime_clone_button($template, $template_args)
401
-    {
402
-        return EEH_Template::display_template(
403
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
404
-            $template_args,
405
-            true
406
-        );
407
-    }
408
-
409
-
410
-    /**
411
-     * Returns the template for datetime timezones.
412
-     *
413
-     * @param $template
414
-     * @param $template_args
415
-     * @return mixed
416
-     * @throws DomainException
417
-     */
418
-    public function datetime_timezones_template($template, $template_args)
419
-    {
420
-        return EEH_Template::display_template(
421
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
422
-            $template_args,
423
-            true
424
-        );
425
-    }
426
-
427
-
428
-    /**
429
-     * Sets the views for the default list table view.
430
-     *
431
-     * @throws EE_Error
432
-     */
433
-    protected function _set_list_table_views_default()
434
-    {
435
-        parent::_set_list_table_views_default();
436
-        $new_views = [
437
-            'today' => [
438
-                'slug'        => 'today',
439
-                'label'       => esc_html__('Today', 'event_espresso'),
440
-                'count'       => $this->total_events_today(),
441
-                'bulk_action' => [
442
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
443
-                ],
444
-            ],
445
-            'month' => [
446
-                'slug'        => 'month',
447
-                'label'       => esc_html__('This Month', 'event_espresso'),
448
-                'count'       => $this->total_events_this_month(),
449
-                'bulk_action' => [
450
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
451
-                ],
452
-            ],
453
-        ];
454
-        $this->_views = array_merge($this->_views, $new_views);
455
-    }
456
-
457
-
458
-    /**
459
-     * Returns the extra action links for the default list table view.
460
-     *
461
-     * @param array    $action_links
462
-     * @param EE_Event $event
463
-     * @return array
464
-     * @throws EE_Error
465
-     * @throws InvalidArgumentException
466
-     * @throws InvalidDataTypeException
467
-     * @throws InvalidInterfaceException
468
-     * @throws ReflectionException
469
-     */
470
-    public function extra_list_table_actions(array $action_links, EE_Event $event)
471
-    {
472
-        if (
473
-            EE_Registry::instance()->CAP->current_user_can(
474
-                'ee_read_registrations',
475
-                'espresso_registrations_reports',
476
-                $event->ID()
477
-            )
478
-        ) {
479
-            $reports_query_args = [
480
-                'action' => 'reports',
481
-                'EVT_ID' => $event->ID(),
482
-            ];
483
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
484
-            $action_links[] = '<a href="'
485
-                              . $reports_link
486
-                              . '" title="'
487
-                              . esc_attr__('View Report', 'event_espresso')
488
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
489
-                              . "\n\t";
490
-        }
491
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
492
-            EE_Registry::instance()->load_helper('MSG_Template');
493
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
494
-                'see_notifications_for',
495
-                null,
496
-                ['EVT_ID' => $event->ID()]
497
-            );
498
-        }
499
-        return $action_links;
500
-    }
501
-
502
-
503
-    /**
504
-     * @param $items
505
-     * @return mixed
506
-     */
507
-    public function additional_legend_items($items)
508
-    {
509
-        if (
510
-            EE_Registry::instance()->CAP->current_user_can(
511
-                'ee_read_registrations',
512
-                'espresso_registrations_reports'
513
-            )
514
-        ) {
515
-            $items['reports'] = [
516
-                'class' => 'dashicons dashicons-chart-bar',
517
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
518
-            ];
519
-        }
520
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
521
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
522
-            // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
523
-            // (can only use numeric offsets when treating strings as arrays)
524
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
525
-                $items['view_related_messages'] = [
526
-                    'class' => $related_for_icon['css_class'],
527
-                    'desc'  => $related_for_icon['label'],
528
-                ];
529
-            }
530
-        }
531
-        return $items;
532
-    }
533
-
534
-
535
-    /**
536
-     * This is the callback method for the duplicate event route
537
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
538
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
539
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
540
-     * After duplication the redirect is to the new event edit page.
541
-     *
542
-     * @return void
543
-     * @throws EE_Error If EE_Event is not available with given ID
544
-     * @throws InvalidArgumentException
545
-     * @throws InvalidDataTypeException
546
-     * @throws InvalidInterfaceException
547
-     * @throws ReflectionException
548
-     * @access protected
549
-     */
550
-    protected function _duplicate_event()
551
-    {
552
-        // first make sure the ID for the event is in the request.
553
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
554
-        if (! isset($this->_req_data['EVT_ID'])) {
555
-            EE_Error::add_error(
556
-                esc_html__(
557
-                    'In order to duplicate an event an Event ID is required.  None was given.',
558
-                    'event_espresso'
559
-                ),
560
-                __FILE__,
561
-                __FUNCTION__,
562
-                __LINE__
563
-            );
564
-            $this->_redirect_after_action(false, '', '', [], true);
565
-            return;
566
-        }
567
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
568
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
569
-        if (! $orig_event instanceof EE_Event) {
570
-            throw new EE_Error(
571
-                sprintf(
572
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
573
-                    $this->_req_data['EVT_ID']
574
-                )
575
-            );
576
-        }
577
-        // k now let's clone the $orig_event before getting relations
578
-        $new_event = clone $orig_event;
579
-        // original datetimes
580
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
581
-        // other original relations
582
-        $orig_ven = $orig_event->get_many_related('Venue');
583
-        // reset the ID and modify other details to make it clear this is a dupe
584
-        $new_event->set('EVT_ID', 0);
585
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
586
-        $new_event->set('EVT_name', $new_name);
587
-        $new_event->set(
588
-            'EVT_slug',
589
-            wp_unique_post_slug(
590
-                sanitize_title($orig_event->name()),
591
-                0,
592
-                'publish',
593
-                'espresso_events',
594
-                0
595
-            )
596
-        );
597
-        $new_event->set('status', 'draft');
598
-        // duplicate discussion settings
599
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
600
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
601
-        // save the new event
602
-        $new_event->save();
603
-        // venues
604
-        foreach ($orig_ven as $ven) {
605
-            $new_event->_add_relation_to($ven, 'Venue');
606
-        }
607
-        $new_event->save();
608
-        // now we need to get the question group relations and handle that
609
-        // first primary question groups
610
-        $orig_primary_qgs = $orig_event->get_many_related(
611
-            'Question_Group',
612
-            [['Event_Question_Group.EQG_primary' => true]]
613
-        );
614
-        if (! empty($orig_primary_qgs)) {
615
-            foreach ($orig_primary_qgs as $id => $obj) {
616
-                if ($obj instanceof EE_Question_Group) {
617
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
618
-                }
619
-            }
620
-        }
621
-        // next additional attendee question groups
622
-        $orig_additional_qgs = $orig_event->get_many_related(
623
-            'Question_Group',
624
-            [['Event_Question_Group.EQG_additional' => true]]
625
-        );
626
-        if (! empty($orig_additional_qgs)) {
627
-            foreach ($orig_additional_qgs as $id => $obj) {
628
-                if ($obj instanceof EE_Question_Group) {
629
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
630
-                }
631
-            }
632
-        }
633
-
634
-        $new_event->save();
635
-
636
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
637
-        $cloned_tickets = [];
638
-        foreach ($orig_datetimes as $orig_dtt) {
639
-            if (! $orig_dtt instanceof EE_Datetime) {
640
-                continue;
641
-            }
642
-            $new_dtt = clone $orig_dtt;
643
-            $orig_tkts = $orig_dtt->tickets();
644
-            // save new dtt then add to event
645
-            $new_dtt->set('DTT_ID', 0);
646
-            $new_dtt->set('DTT_sold', 0);
647
-            $new_dtt->set_reserved(0);
648
-            $new_dtt->save();
649
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
650
-            $new_event->save();
651
-            // now let's get the ticket relations setup.
652
-            foreach ((array) $orig_tkts as $orig_tkt) {
653
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
654
-                if (! $orig_tkt instanceof EE_Ticket) {
655
-                    continue;
656
-                }
657
-                // is this ticket archived?  If it is then let's skip
658
-                if ($orig_tkt->get('TKT_deleted')) {
659
-                    continue;
660
-                }
661
-                // does this original ticket already exist in the clone_tickets cache?
662
-                //  If so we'll just use the new ticket from it.
663
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
664
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
665
-                } else {
666
-                    $new_tkt = clone $orig_tkt;
667
-                    // get relations on the $orig_tkt that we need to setup.
668
-                    $orig_prices = $orig_tkt->prices();
669
-                    $new_tkt->set('TKT_ID', 0);
670
-                    $new_tkt->set('TKT_sold', 0);
671
-                    $new_tkt->set('TKT_reserved', 0);
672
-                    $new_tkt->save(); // make sure new ticket has ID.
673
-                    // price relations on new ticket need to be setup.
674
-                    foreach ($orig_prices as $orig_price) {
675
-                        $new_price = clone $orig_price;
676
-                        $new_price->set('PRC_ID', 0);
677
-                        $new_price->save();
678
-                        $new_tkt->_add_relation_to($new_price, 'Price');
679
-                        $new_tkt->save();
680
-                    }
681
-
682
-                    do_action(
683
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
684
-                        $orig_tkt,
685
-                        $new_tkt,
686
-                        $orig_prices,
687
-                        $orig_event,
688
-                        $orig_dtt,
689
-                        $new_dtt
690
-                    );
691
-                }
692
-                // k now we can add the new ticket as a relation to the new datetime
693
-                // and make sure its added to our cached $cloned_tickets array
694
-                // for use with later datetimes that have the same ticket.
695
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
696
-                $new_dtt->save();
697
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
698
-            }
699
-        }
700
-        // clone taxonomy information
701
-        $taxonomies_to_clone_with = apply_filters(
702
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
703
-            ['espresso_event_categories', 'espresso_event_type', 'post_tag']
704
-        );
705
-        // get terms for original event (notice)
706
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
707
-        // loop through terms and add them to new event.
708
-        foreach ($orig_terms as $term) {
709
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
710
-        }
711
-
712
-        // duplicate other core WP_Post items for this event.
713
-        // post thumbnail (feature image).
714
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
715
-        if ($feature_image_id) {
716
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
717
-        }
718
-
719
-        // duplicate page_template setting
720
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
721
-        if ($page_template) {
722
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
723
-        }
724
-
725
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
726
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
727
-        if ($new_event->ID()) {
728
-            $redirect_args = [
729
-                'post'   => $new_event->ID(),
730
-                'action' => 'edit',
731
-            ];
732
-            EE_Error::add_success(
733
-                esc_html__(
734
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
735
-                    'event_espresso'
736
-                )
737
-            );
738
-        } else {
739
-            $redirect_args = [
740
-                'action' => 'default',
741
-            ];
742
-            EE_Error::add_error(
743
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
744
-                __FILE__,
745
-                __FUNCTION__,
746
-                __LINE__
747
-            );
748
-        }
749
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
750
-    }
751
-
752
-
753
-    /**
754
-     * Generates output for the import page.
755
-     *
756
-     * @throws DomainException
757
-     * @throws EE_Error
758
-     * @throws InvalidArgumentException
759
-     * @throws InvalidDataTypeException
760
-     * @throws InvalidInterfaceException
761
-     */
762
-    protected function _import_page()
763
-    {
764
-        $title = esc_html__('Import', 'event_espresso');
765
-        $intro = esc_html__(
766
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
767
-            'event_espresso'
768
-        );
769
-        $form_url = EVENTS_ADMIN_URL;
770
-        $action = 'import_events';
771
-        $type = 'csv';
772
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
773
-            $title,
774
-            $intro,
775
-            $form_url,
776
-            $action,
777
-            $type
778
-        );
779
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
780
-            ['action' => 'sample_export_file'],
781
-            $this->_admin_base_url
782
-        );
783
-        $content = EEH_Template::display_template(
784
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
785
-            $this->_template_args,
786
-            true
787
-        );
788
-        $this->_template_args['admin_page_content'] = $content;
789
-        $this->display_admin_page_with_sidebar();
790
-    }
791
-
792
-
793
-    /**
794
-     * _import_events
795
-     * This handles displaying the screen and running imports for importing events.
796
-     *
797
-     * @return void
798
-     * @throws EE_Error
799
-     * @throws InvalidArgumentException
800
-     * @throws InvalidDataTypeException
801
-     * @throws InvalidInterfaceException
802
-     */
803
-    protected function _import_events()
804
-    {
805
-        require_once(EE_CLASSES . 'EE_Import.class.php');
806
-        $success = EE_Import::instance()->import();
807
-        $this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true);
808
-    }
809
-
810
-
811
-    /**
812
-     * _events_export
813
-     * Will export all (or just the given event) to a Excel compatible file.
814
-     *
815
-     * @access protected
816
-     * @return void
817
-     */
818
-    protected function _events_export()
819
-    {
820
-        if (isset($this->_req_data['EVT_ID'])) {
821
-            $event_ids = $this->_req_data['EVT_ID'];
822
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
823
-            $event_ids = $this->_req_data['EVT_IDs'];
824
-        } else {
825
-            $event_ids = null;
826
-        }
827
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
828
-        $new_request_args = [
829
-            'export' => 'report',
830
-            'action' => 'all_event_data',
831
-            'EVT_ID' => $event_ids,
832
-        ];
833
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
834
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
835
-            require_once(EE_CLASSES . 'EE_Export.class.php');
836
-            $EE_Export = EE_Export::instance($this->_req_data);
837
-            if ($EE_Export instanceof EE_Export) {
838
-                $EE_Export->export();
839
-            }
840
-        }
841
-    }
842
-
843
-
844
-    /**
845
-     * handle category exports()
846
-     *
847
-     * @return void
848
-     */
849
-    protected function _categories_export()
850
-    {
851
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
852
-        $new_request_args = [
853
-            'export'       => 'report',
854
-            'action'       => 'categories',
855
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
856
-        ];
857
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
858
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
859
-            require_once(EE_CLASSES . 'EE_Export.class.php');
860
-            $EE_Export = EE_Export::instance($this->_req_data);
861
-            if ($EE_Export instanceof EE_Export) {
862
-                $EE_Export->export();
863
-            }
864
-        }
865
-    }
866
-
867
-
868
-    /**
869
-     * Creates a sample CSV file for importing
870
-     */
871
-    protected function _sample_export_file()
872
-    {
873
-        $EE_Export = EE_Export::instance();
874
-        if ($EE_Export instanceof EE_Export) {
875
-            $EE_Export->export();
876
-        }
877
-    }
878
-
879
-
880
-    /*************        Template Settings        *************/
881
-    /**
882
-     * Generates template settings page output
883
-     *
884
-     * @throws DomainException
885
-     * @throws EE_Error
886
-     * @throws InvalidArgumentException
887
-     * @throws InvalidDataTypeException
888
-     * @throws InvalidInterfaceException
889
-     */
890
-    protected function _template_settings()
891
-    {
892
-        $this->_template_args['values'] = $this->_yes_no_values;
893
-        /**
894
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
895
-         * from General_Settings_Admin_Page to here.
896
-         */
897
-        $this->_template_args = apply_filters(
898
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
899
-            $this->_template_args
900
-        );
901
-        $this->_set_add_edit_form_tags('update_template_settings');
902
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
903
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
904
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
905
-            $this->_template_args,
906
-            true
907
-        );
908
-        $this->display_admin_page_with_sidebar();
909
-    }
910
-
911
-
912
-    /**
913
-     * Handler for updating template settings.
914
-     *
915
-     * @throws EE_Error
916
-     * @throws InvalidArgumentException
917
-     * @throws InvalidDataTypeException
918
-     * @throws InvalidInterfaceException
919
-     */
920
-    protected function _update_template_settings()
921
-    {
922
-        /**
923
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
924
-         * from General_Settings_Admin_Page to here.
925
-         */
926
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
927
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
928
-            EE_Registry::instance()->CFG->template_settings,
929
-            $this->_req_data
930
-        );
931
-        // update custom post type slugs and detect if we need to flush rewrite rules
932
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
933
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
934
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
935
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
936
-        $what = 'Template Settings';
937
-        $success = $this->_update_espresso_configuration(
938
-            $what,
939
-            EE_Registry::instance()->CFG->template_settings,
940
-            __FILE__,
941
-            __FUNCTION__,
942
-            __LINE__
943
-        );
944
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
945
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
946
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
947
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
948
-            );
949
-            $rewrite_rules->flush();
950
-        }
951
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
952
-    }
953
-
954
-
955
-    /**
956
-     * _premium_event_editor_meta_boxes
957
-     * add all metaboxes related to the event_editor
958
-     *
959
-     * @access protected
960
-     * @return void
961
-     * @throws EE_Error
962
-     * @throws InvalidArgumentException
963
-     * @throws InvalidDataTypeException
964
-     * @throws InvalidInterfaceException
965
-     * @throws ReflectionException
966
-     */
967
-    protected function _premium_event_editor_meta_boxes()
968
-    {
969
-        $this->verify_cpt_object();
970
-        /** @var FeatureFlags $flags */
971
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
972
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
973
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
974
-            add_meta_box(
975
-                'espresso_event_editor_event_options',
976
-                esc_html__('Event Registration Options', 'event_espresso'),
977
-                [$this, 'registration_options_meta_box'],
978
-                $this->page_slug,
979
-                'side',
980
-                'core'
981
-            );
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 = [
996
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
997
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
998
-        ];
999
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1000
-            [
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 = [];
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 = [
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 = [
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(['order_by' => ['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 = [
1196
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1197
-        ];
1198
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * get total number of events this month
1204
-     *
1205
-     * @access public
1206
-     * @return int
1207
-     * @throws EE_Error
1208
-     * @throws InvalidArgumentException
1209
-     * @throws InvalidDataTypeException
1210
-     * @throws InvalidInterfaceException
1211
-     */
1212
-    public function total_events_this_month()
1213
-    {
1214
-        // Dates
1215
-        $this_year_r = date('Y');
1216
-        $this_month_r = date('m');
1217
-        $days_this_month = date('t');
1218
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1219
-            'DTT_EVT_start',
1220
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1221
-            'Y-m-d H:i:s',
1222
-            'UTC'
1223
-        );
1224
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1225
-            'DTT_EVT_start',
1226
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1227
-            'Y-m-d H:i:s',
1228
-            'UTC'
1229
-        );
1230
-        $where = [
1231
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1232
-        ];
1233
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1234
-    }
1235
-
1236
-
1237
-    /** DEFAULT TICKETS STUFF **/
1238
-
1239
-    /**
1240
-     * Output default tickets list table view.
1241
-     *
1242
-     * @throws DomainException
1243
-     * @throws EE_Error
1244
-     * @throws InvalidArgumentException
1245
-     * @throws InvalidDataTypeException
1246
-     * @throws InvalidInterfaceException
1247
-     */
1248
-    public function _tickets_overview_list_table()
1249
-    {
1250
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1251
-        $this->display_admin_list_table_page_with_no_sidebar();
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     * @param int  $per_page
1257
-     * @param bool $count
1258
-     * @param bool $trashed
1259
-     * @return EE_Soft_Delete_Base_Class[]|int
1260
-     * @throws EE_Error
1261
-     * @throws InvalidArgumentException
1262
-     * @throws InvalidDataTypeException
1263
-     * @throws InvalidInterfaceException
1264
-     */
1265
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1266
-    {
1267
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1268
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1269
-        switch ($orderby) {
1270
-            case 'TKT_name':
1271
-                $orderby = ['TKT_name' => $order];
1272
-                break;
1273
-            case 'TKT_price':
1274
-                $orderby = ['TKT_price' => $order];
1275
-                break;
1276
-            case 'TKT_uses':
1277
-                $orderby = ['TKT_uses' => $order];
1278
-                break;
1279
-            case 'TKT_min':
1280
-                $orderby = ['TKT_min' => $order];
1281
-                break;
1282
-            case 'TKT_max':
1283
-                $orderby = ['TKT_max' => $order];
1284
-                break;
1285
-            case 'TKT_qty':
1286
-                $orderby = ['TKT_qty' => $order];
1287
-                break;
1288
-        }
1289
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1290
-            ? $this->_req_data['paged']
1291
-            : 1;
1292
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1293
-            ? $this->_req_data['perpage']
1294
-            : $per_page;
1295
-        $_where = [
1296
-            'TKT_is_default' => 1,
1297
-            'TKT_deleted'    => $trashed,
1298
-        ];
1299
-        $offset = ($current_page - 1) * $per_page;
1300
-        $limit = [$offset, $per_page];
1301
-        if (isset($this->_req_data['s'])) {
1302
-            $sstr = '%' . $this->_req_data['s'] . '%';
1303
-            $_where['OR'] = [
1304
-                'TKT_name'        => ['LIKE', $sstr],
1305
-                'TKT_description' => ['LIKE', $sstr],
1306
-            ];
1307
-        }
1308
-        $query_params = [
1309
-            $_where,
1310
-            'order_by' => $orderby,
1311
-            'limit'    => $limit,
1312
-            'group_by' => 'TKT_ID',
1313
-        ];
1314
-        if ($count) {
1315
-            return EEM_Ticket::instance()->count_deleted_and_undeleted([$_where]);
1316
-        }
1317
-        return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1318
-    }
1319
-
1320
-
1321
-    /**
1322
-     * @param bool $trash
1323
-     * @throws EE_Error
1324
-     * @throws InvalidArgumentException
1325
-     * @throws InvalidDataTypeException
1326
-     * @throws InvalidInterfaceException
1327
-     */
1328
-    protected function _trash_or_restore_ticket($trash = false)
1329
-    {
1330
-        $success = 1;
1331
-        $TKT = EEM_Ticket::instance();
1332
-        // checkboxes?
1333
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1334
-            // if array has more than one element then success message should be plural
1335
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1336
-            // cycle thru the boxes
1337
-            foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1338
-                if ($trash) {
1339
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1340
-                        $success = 0;
1341
-                    }
1342
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1343
-                    $success = 0;
1344
-                }
1345
-            }
1346
-        } else {
1347
-            // grab single id and trash
1348
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1349
-            if ($trash) {
1350
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1351
-                    $success = 0;
1352
-                }
1353
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1354
-                $success = 0;
1355
-            }
1356
-        }
1357
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1358
-        $query_args = [
1359
-            'action' => 'ticket_list_table',
1360
-            'status' => $trash ? '' : 'trashed',
1361
-        ];
1362
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1363
-    }
1364
-
1365
-
1366
-    /**
1367
-     * Handles trashing default ticket.
1368
-     *
1369
-     * @throws EE_Error
1370
-     * @throws InvalidArgumentException
1371
-     * @throws InvalidDataTypeException
1372
-     * @throws InvalidInterfaceException
1373
-     * @throws ReflectionException
1374
-     */
1375
-    protected function _delete_ticket()
1376
-    {
1377
-        $success = 1;
1378
-        // checkboxes?
1379
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1380
-            // if array has more than one element then success message should be plural
1381
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1382
-            // cycle thru the boxes
1383
-            foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1384
-                // delete
1385
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1386
-                    $success = 0;
1387
-                }
1388
-            }
1389
-        } else {
1390
-            // grab single id and trash
1391
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1392
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1393
-                $success = 0;
1394
-            }
1395
-        }
1396
-        $action_desc = 'deleted';
1397
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1398
-        $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
1399
-            [['TKT_is_default' => 1]],
1400
-            'TKT_ID',
1401
-            true
1402
-        );
1403
-        $query_args = $ticket_count
1404
-            ? []
1405
-            : [
1406
-                'action' => 'ticket_list_table',
1407
-                'status' => 'trashed',
1408
-            ];
1409
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1410
-    }
1411
-
1412
-
1413
-    /**
1414
-     * @param int $TKT_ID
1415
-     * @return bool|int
1416
-     * @throws EE_Error
1417
-     * @throws InvalidArgumentException
1418
-     * @throws InvalidDataTypeException
1419
-     * @throws InvalidInterfaceException
1420
-     * @throws ReflectionException
1421
-     */
1422
-    protected function _delete_the_ticket($TKT_ID)
1423
-    {
1424
-        $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1425
-        if (! $ticket instanceof EE_Ticket) {
1426
-            return false;
1427
-        }
1428
-        $ticket->_remove_relations('Datetime');
1429
-        // delete all related prices first
1430
-        $ticket->delete_related_permanently('Price');
1431
-        return $ticket->delete_permanently();
1432
-    }
20
+	/**
21
+	 * @var EE_Admin_Config
22
+	 */
23
+	protected $admin_config;
24
+
25
+	/**
26
+	 * @var AdvancedEditorAdminFormSection
27
+	 */
28
+	protected $advanced_editor_admin_form;
29
+
30
+
31
+	/**
32
+	 * Extend_Events_Admin_Page constructor.
33
+	 *
34
+	 * @param bool $routing
35
+	 * @throws ReflectionException
36
+	 */
37
+	public function __construct($routing = true)
38
+	{
39
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
+		}
44
+		parent::__construct($routing);
45
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
+	}
47
+
48
+
49
+	/**
50
+	 * Sets routes.
51
+	 *
52
+	 * @throws EE_Error
53
+	 * @throws InvalidArgumentException
54
+	 * @throws InvalidDataTypeException
55
+	 * @throws InvalidInterfaceException
56
+	 * @throws Exception
57
+	 */
58
+	protected function _extend_page_config()
59
+	{
60
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
61
+		// is there a evt_id in the request?
62
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
63
+			? $this->_req_data['EVT_ID']
64
+			: 0;
65
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
66
+		// tkt_id?
67
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
68
+			? $this->_req_data['TKT_ID']
69
+			: 0;
70
+		$new_page_routes = [
71
+			'duplicate_event'          => [
72
+				'func'       => '_duplicate_event',
73
+				'capability' => 'ee_edit_event',
74
+				'obj_id'     => $evt_id,
75
+				'noheader'   => true,
76
+			],
77
+			'import_page'              => [
78
+				'func'       => '_import_page',
79
+				'capability' => 'import',
80
+			],
81
+			'import'                   => [
82
+				'func'       => '_import_events',
83
+				'capability' => 'import',
84
+				'noheader'   => true,
85
+			],
86
+			'import_events'            => [
87
+				'func'       => '_import_events',
88
+				'capability' => 'import',
89
+				'noheader'   => true,
90
+			],
91
+			'export_events'            => [
92
+				'func'       => '_events_export',
93
+				'capability' => 'export',
94
+				'noheader'   => true,
95
+			],
96
+			'export_categories'        => [
97
+				'func'       => '_categories_export',
98
+				'capability' => 'export',
99
+				'noheader'   => true,
100
+			],
101
+			'sample_export_file'       => [
102
+				'func'       => '_sample_export_file',
103
+				'capability' => 'export',
104
+				'noheader'   => true,
105
+			],
106
+			'update_template_settings' => [
107
+				'func'       => '_update_template_settings',
108
+				'capability' => 'manage_options',
109
+				'noheader'   => true,
110
+			],
111
+		];        // don't load these meta boxes if using the advanced editor
112
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
113
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
114
+		if (! $this->admin_config->useAdvancedEditor()) {
115
+			$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
116
+			$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
117
+
118
+			$legacy_editor_page_routes = [
119
+				'ticket_list_table' => [
120
+					'func'       => '_tickets_overview_list_table',
121
+					'capability' => 'ee_read_default_tickets',
122
+				],
123
+				'trash_ticket'      => [
124
+					'func'       => '_trash_or_restore_ticket',
125
+					'capability' => 'ee_delete_default_ticket',
126
+					'obj_id'     => $tkt_id,
127
+					'noheader'   => true,
128
+					'args'       => ['trash' => true],
129
+				],
130
+				'trash_tickets'     => [
131
+					'func'       => '_trash_or_restore_ticket',
132
+					'capability' => 'ee_delete_default_tickets',
133
+					'noheader'   => true,
134
+					'args'       => ['trash' => true],
135
+				],
136
+				'restore_ticket'    => [
137
+					'func'       => '_trash_or_restore_ticket',
138
+					'capability' => 'ee_delete_default_ticket',
139
+					'obj_id'     => $tkt_id,
140
+					'noheader'   => true,
141
+				],
142
+				'restore_tickets'   => [
143
+					'func'       => '_trash_or_restore_ticket',
144
+					'capability' => 'ee_delete_default_tickets',
145
+					'noheader'   => true,
146
+				],
147
+				'delete_ticket'     => [
148
+					'func'       => '_delete_ticket',
149
+					'capability' => 'ee_delete_default_ticket',
150
+					'obj_id'     => $tkt_id,
151
+					'noheader'   => true,
152
+				],
153
+				'delete_tickets'    => [
154
+					'func'       => '_delete_ticket',
155
+					'capability' => 'ee_delete_default_tickets',
156
+					'noheader'   => true,
157
+				],
158
+			];
159
+			$new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes);
160
+		}
161
+
162
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
163
+		// partial route/config override
164
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
165
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
166
+		// add tickets tab but only if there are more than one default ticket!
167
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
168
+			[['TKT_is_default' => 1]],
169
+			'TKT_ID',
170
+			true
171
+		);
172
+		if ($tkt_count > 1) {
173
+			$new_page_config = [
174
+				'ticket_list_table' => [
175
+					'nav'           => [
176
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
177
+						'order' => 60,
178
+					],
179
+					'list_table'    => 'Tickets_List_Table',
180
+					'require_nonce' => false,
181
+				],
182
+			];
183
+		}
184
+		// template settings
185
+		$new_page_config['template_settings'] = [
186
+			'nav'           => [
187
+				'label' => esc_html__('Templates', 'event_espresso'),
188
+				'order' => 30,
189
+			],
190
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
191
+			'help_tabs'     => [
192
+				'general_settings_templates_help_tab' => [
193
+					'title'    => esc_html__('Templates', 'event_espresso'),
194
+					'filename' => 'general_settings_templates',
195
+				],
196
+			],
197
+		   // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
198
+			// 'help_tour'     => ['Templates_Help_Tour'],
199
+			'require_nonce' => false,
200
+		];
201
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
202
+		// add filters and actions
203
+		// modifying _views
204
+		add_filter(
205
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
206
+			[$this, 'add_additional_datetime_button'],
207
+			10,
208
+			2
209
+		);
210
+		add_filter(
211
+			'FHEE_event_datetime_metabox_clone_button_template',
212
+			[$this, 'add_datetime_clone_button'],
213
+			10,
214
+			2
215
+		);
216
+		add_filter(
217
+			'FHEE_event_datetime_metabox_timezones_template',
218
+			[$this, 'datetime_timezones_template'],
219
+			10,
220
+			2
221
+		);
222
+		// filters for event list table
223
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
224
+		add_filter(
225
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
226
+			[$this, 'extra_list_table_actions'],
227
+			10,
228
+			2
229
+		);
230
+		// legend item
231
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
232
+		add_action('admin_init', [$this, 'admin_init']);
233
+		// load additional handlers
234
+		$this->handleActionRequest();
235
+	}
236
+
237
+
238
+	private function getRequestAction()
239
+	{
240
+		return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null;
241
+	}
242
+
243
+
244
+	/**
245
+	 * @throws Exception
246
+	 */
247
+	private function handleActionRequest()
248
+	{
249
+		$action = $this->getRequestAction();
250
+		if ($action) {
251
+			// setup Advanced Editor ???
252
+			if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
253
+				$this->advanced_editor_admin_form = $this->loader->getShared(
254
+					'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
255
+				);
256
+			}
257
+		}
258
+	}
259
+
260
+
261
+	/**
262
+	 * admin_init
263
+	 */
264
+	public function admin_init()
265
+	{
266
+		EE_Registry::$i18n_js_strings = array_merge(
267
+			EE_Registry::$i18n_js_strings,
268
+			[
269
+				'image_confirm'          => esc_html__(
270
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
271
+					'event_espresso'
272
+				),
273
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
274
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
275
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
276
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
277
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
278
+			]
279
+		);
280
+	}
281
+
282
+
283
+	/**
284
+	 * Add per page screen options to the default ticket list table view.
285
+	 *
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidDataTypeException
288
+	 * @throws InvalidInterfaceException
289
+	 */
290
+	protected function _add_screen_options_ticket_list_table()
291
+	{
292
+		$this->_per_page_screen_option();
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param string $return
298
+	 * @param int    $id
299
+	 * @param string $new_title
300
+	 * @param string $new_slug
301
+	 * @return string
302
+	 */
303
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
304
+	{
305
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
306
+		// make sure this is only when editing
307
+		if (! empty($id)) {
308
+			$href = EE_Admin_Page::add_query_args_and_nonce(
309
+				['action' => 'duplicate_event', 'EVT_ID' => $id],
310
+				$this->_admin_base_url
311
+			);
312
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
313
+			$return .= '<a href="'
314
+					   . $href
315
+					   . '" title="'
316
+					   . $title
317
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
318
+					   . $title
319
+					   . '</a>';
320
+		}
321
+		return $return;
322
+	}
323
+
324
+
325
+	/**
326
+	 * Set the list table views for the default ticket list table view.
327
+	 */
328
+	public function _set_list_table_views_ticket_list_table()
329
+	{
330
+		$this->_views = [
331
+			'all'     => [
332
+				'slug'        => 'all',
333
+				'label'       => esc_html__('All', 'event_espresso'),
334
+				'count'       => 0,
335
+				'bulk_action' => [
336
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
337
+				],
338
+			],
339
+			'trashed' => [
340
+				'slug'        => 'trashed',
341
+				'label'       => esc_html__('Trash', 'event_espresso'),
342
+				'count'       => 0,
343
+				'bulk_action' => [
344
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
345
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
346
+				],
347
+			],
348
+		];
349
+	}
350
+
351
+
352
+	/**
353
+	 * Enqueue scripts and styles for the event editor.
354
+	 */
355
+	public function load_scripts_styles_edit()
356
+	{
357
+		if (! $this->admin_config->useAdvancedEditor()) {
358
+			wp_register_script(
359
+				'ee-event-editor-heartbeat',
360
+				EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
361
+				['ee_admin_js', 'heartbeat'],
362
+				EVENT_ESPRESSO_VERSION,
363
+				true
364
+			);
365
+			wp_enqueue_script('ee-accounting');
366
+			wp_enqueue_script('ee-event-editor-heartbeat');
367
+		}
368
+		wp_enqueue_script('event_editor_js');
369
+		// styles
370
+		wp_enqueue_style('espresso-ui-theme');
371
+	}
372
+
373
+
374
+	/**
375
+	 * Returns template for the additional datetime.
376
+	 *
377
+	 * @param $template
378
+	 * @param $template_args
379
+	 * @return mixed
380
+	 * @throws DomainException
381
+	 */
382
+	public function add_additional_datetime_button($template, $template_args)
383
+	{
384
+		return EEH_Template::display_template(
385
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
386
+			$template_args,
387
+			true
388
+		);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Returns the template for cloning a datetime.
394
+	 *
395
+	 * @param $template
396
+	 * @param $template_args
397
+	 * @return mixed
398
+	 * @throws DomainException
399
+	 */
400
+	public function add_datetime_clone_button($template, $template_args)
401
+	{
402
+		return EEH_Template::display_template(
403
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
404
+			$template_args,
405
+			true
406
+		);
407
+	}
408
+
409
+
410
+	/**
411
+	 * Returns the template for datetime timezones.
412
+	 *
413
+	 * @param $template
414
+	 * @param $template_args
415
+	 * @return mixed
416
+	 * @throws DomainException
417
+	 */
418
+	public function datetime_timezones_template($template, $template_args)
419
+	{
420
+		return EEH_Template::display_template(
421
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
422
+			$template_args,
423
+			true
424
+		);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Sets the views for the default list table view.
430
+	 *
431
+	 * @throws EE_Error
432
+	 */
433
+	protected function _set_list_table_views_default()
434
+	{
435
+		parent::_set_list_table_views_default();
436
+		$new_views = [
437
+			'today' => [
438
+				'slug'        => 'today',
439
+				'label'       => esc_html__('Today', 'event_espresso'),
440
+				'count'       => $this->total_events_today(),
441
+				'bulk_action' => [
442
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
443
+				],
444
+			],
445
+			'month' => [
446
+				'slug'        => 'month',
447
+				'label'       => esc_html__('This Month', 'event_espresso'),
448
+				'count'       => $this->total_events_this_month(),
449
+				'bulk_action' => [
450
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
451
+				],
452
+			],
453
+		];
454
+		$this->_views = array_merge($this->_views, $new_views);
455
+	}
456
+
457
+
458
+	/**
459
+	 * Returns the extra action links for the default list table view.
460
+	 *
461
+	 * @param array    $action_links
462
+	 * @param EE_Event $event
463
+	 * @return array
464
+	 * @throws EE_Error
465
+	 * @throws InvalidArgumentException
466
+	 * @throws InvalidDataTypeException
467
+	 * @throws InvalidInterfaceException
468
+	 * @throws ReflectionException
469
+	 */
470
+	public function extra_list_table_actions(array $action_links, EE_Event $event)
471
+	{
472
+		if (
473
+			EE_Registry::instance()->CAP->current_user_can(
474
+				'ee_read_registrations',
475
+				'espresso_registrations_reports',
476
+				$event->ID()
477
+			)
478
+		) {
479
+			$reports_query_args = [
480
+				'action' => 'reports',
481
+				'EVT_ID' => $event->ID(),
482
+			];
483
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
484
+			$action_links[] = '<a href="'
485
+							  . $reports_link
486
+							  . '" title="'
487
+							  . esc_attr__('View Report', 'event_espresso')
488
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
489
+							  . "\n\t";
490
+		}
491
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
492
+			EE_Registry::instance()->load_helper('MSG_Template');
493
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
494
+				'see_notifications_for',
495
+				null,
496
+				['EVT_ID' => $event->ID()]
497
+			);
498
+		}
499
+		return $action_links;
500
+	}
501
+
502
+
503
+	/**
504
+	 * @param $items
505
+	 * @return mixed
506
+	 */
507
+	public function additional_legend_items($items)
508
+	{
509
+		if (
510
+			EE_Registry::instance()->CAP->current_user_can(
511
+				'ee_read_registrations',
512
+				'espresso_registrations_reports'
513
+			)
514
+		) {
515
+			$items['reports'] = [
516
+				'class' => 'dashicons dashicons-chart-bar',
517
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
518
+			];
519
+		}
520
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
521
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
522
+			// $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
523
+			// (can only use numeric offsets when treating strings as arrays)
524
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
525
+				$items['view_related_messages'] = [
526
+					'class' => $related_for_icon['css_class'],
527
+					'desc'  => $related_for_icon['label'],
528
+				];
529
+			}
530
+		}
531
+		return $items;
532
+	}
533
+
534
+
535
+	/**
536
+	 * This is the callback method for the duplicate event route
537
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
538
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
539
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
540
+	 * After duplication the redirect is to the new event edit page.
541
+	 *
542
+	 * @return void
543
+	 * @throws EE_Error If EE_Event is not available with given ID
544
+	 * @throws InvalidArgumentException
545
+	 * @throws InvalidDataTypeException
546
+	 * @throws InvalidInterfaceException
547
+	 * @throws ReflectionException
548
+	 * @access protected
549
+	 */
550
+	protected function _duplicate_event()
551
+	{
552
+		// first make sure the ID for the event is in the request.
553
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
554
+		if (! isset($this->_req_data['EVT_ID'])) {
555
+			EE_Error::add_error(
556
+				esc_html__(
557
+					'In order to duplicate an event an Event ID is required.  None was given.',
558
+					'event_espresso'
559
+				),
560
+				__FILE__,
561
+				__FUNCTION__,
562
+				__LINE__
563
+			);
564
+			$this->_redirect_after_action(false, '', '', [], true);
565
+			return;
566
+		}
567
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
568
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
569
+		if (! $orig_event instanceof EE_Event) {
570
+			throw new EE_Error(
571
+				sprintf(
572
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
573
+					$this->_req_data['EVT_ID']
574
+				)
575
+			);
576
+		}
577
+		// k now let's clone the $orig_event before getting relations
578
+		$new_event = clone $orig_event;
579
+		// original datetimes
580
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
581
+		// other original relations
582
+		$orig_ven = $orig_event->get_many_related('Venue');
583
+		// reset the ID and modify other details to make it clear this is a dupe
584
+		$new_event->set('EVT_ID', 0);
585
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
586
+		$new_event->set('EVT_name', $new_name);
587
+		$new_event->set(
588
+			'EVT_slug',
589
+			wp_unique_post_slug(
590
+				sanitize_title($orig_event->name()),
591
+				0,
592
+				'publish',
593
+				'espresso_events',
594
+				0
595
+			)
596
+		);
597
+		$new_event->set('status', 'draft');
598
+		// duplicate discussion settings
599
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
600
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
601
+		// save the new event
602
+		$new_event->save();
603
+		// venues
604
+		foreach ($orig_ven as $ven) {
605
+			$new_event->_add_relation_to($ven, 'Venue');
606
+		}
607
+		$new_event->save();
608
+		// now we need to get the question group relations and handle that
609
+		// first primary question groups
610
+		$orig_primary_qgs = $orig_event->get_many_related(
611
+			'Question_Group',
612
+			[['Event_Question_Group.EQG_primary' => true]]
613
+		);
614
+		if (! empty($orig_primary_qgs)) {
615
+			foreach ($orig_primary_qgs as $id => $obj) {
616
+				if ($obj instanceof EE_Question_Group) {
617
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
618
+				}
619
+			}
620
+		}
621
+		// next additional attendee question groups
622
+		$orig_additional_qgs = $orig_event->get_many_related(
623
+			'Question_Group',
624
+			[['Event_Question_Group.EQG_additional' => true]]
625
+		);
626
+		if (! empty($orig_additional_qgs)) {
627
+			foreach ($orig_additional_qgs as $id => $obj) {
628
+				if ($obj instanceof EE_Question_Group) {
629
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
630
+				}
631
+			}
632
+		}
633
+
634
+		$new_event->save();
635
+
636
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
637
+		$cloned_tickets = [];
638
+		foreach ($orig_datetimes as $orig_dtt) {
639
+			if (! $orig_dtt instanceof EE_Datetime) {
640
+				continue;
641
+			}
642
+			$new_dtt = clone $orig_dtt;
643
+			$orig_tkts = $orig_dtt->tickets();
644
+			// save new dtt then add to event
645
+			$new_dtt->set('DTT_ID', 0);
646
+			$new_dtt->set('DTT_sold', 0);
647
+			$new_dtt->set_reserved(0);
648
+			$new_dtt->save();
649
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
650
+			$new_event->save();
651
+			// now let's get the ticket relations setup.
652
+			foreach ((array) $orig_tkts as $orig_tkt) {
653
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
654
+				if (! $orig_tkt instanceof EE_Ticket) {
655
+					continue;
656
+				}
657
+				// is this ticket archived?  If it is then let's skip
658
+				if ($orig_tkt->get('TKT_deleted')) {
659
+					continue;
660
+				}
661
+				// does this original ticket already exist in the clone_tickets cache?
662
+				//  If so we'll just use the new ticket from it.
663
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
664
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
665
+				} else {
666
+					$new_tkt = clone $orig_tkt;
667
+					// get relations on the $orig_tkt that we need to setup.
668
+					$orig_prices = $orig_tkt->prices();
669
+					$new_tkt->set('TKT_ID', 0);
670
+					$new_tkt->set('TKT_sold', 0);
671
+					$new_tkt->set('TKT_reserved', 0);
672
+					$new_tkt->save(); // make sure new ticket has ID.
673
+					// price relations on new ticket need to be setup.
674
+					foreach ($orig_prices as $orig_price) {
675
+						$new_price = clone $orig_price;
676
+						$new_price->set('PRC_ID', 0);
677
+						$new_price->save();
678
+						$new_tkt->_add_relation_to($new_price, 'Price');
679
+						$new_tkt->save();
680
+					}
681
+
682
+					do_action(
683
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
684
+						$orig_tkt,
685
+						$new_tkt,
686
+						$orig_prices,
687
+						$orig_event,
688
+						$orig_dtt,
689
+						$new_dtt
690
+					);
691
+				}
692
+				// k now we can add the new ticket as a relation to the new datetime
693
+				// and make sure its added to our cached $cloned_tickets array
694
+				// for use with later datetimes that have the same ticket.
695
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
696
+				$new_dtt->save();
697
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
698
+			}
699
+		}
700
+		// clone taxonomy information
701
+		$taxonomies_to_clone_with = apply_filters(
702
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
703
+			['espresso_event_categories', 'espresso_event_type', 'post_tag']
704
+		);
705
+		// get terms for original event (notice)
706
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
707
+		// loop through terms and add them to new event.
708
+		foreach ($orig_terms as $term) {
709
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
710
+		}
711
+
712
+		// duplicate other core WP_Post items for this event.
713
+		// post thumbnail (feature image).
714
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
715
+		if ($feature_image_id) {
716
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
717
+		}
718
+
719
+		// duplicate page_template setting
720
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
721
+		if ($page_template) {
722
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
723
+		}
724
+
725
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
726
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
727
+		if ($new_event->ID()) {
728
+			$redirect_args = [
729
+				'post'   => $new_event->ID(),
730
+				'action' => 'edit',
731
+			];
732
+			EE_Error::add_success(
733
+				esc_html__(
734
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
735
+					'event_espresso'
736
+				)
737
+			);
738
+		} else {
739
+			$redirect_args = [
740
+				'action' => 'default',
741
+			];
742
+			EE_Error::add_error(
743
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
744
+				__FILE__,
745
+				__FUNCTION__,
746
+				__LINE__
747
+			);
748
+		}
749
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
750
+	}
751
+
752
+
753
+	/**
754
+	 * Generates output for the import page.
755
+	 *
756
+	 * @throws DomainException
757
+	 * @throws EE_Error
758
+	 * @throws InvalidArgumentException
759
+	 * @throws InvalidDataTypeException
760
+	 * @throws InvalidInterfaceException
761
+	 */
762
+	protected function _import_page()
763
+	{
764
+		$title = esc_html__('Import', 'event_espresso');
765
+		$intro = esc_html__(
766
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
767
+			'event_espresso'
768
+		);
769
+		$form_url = EVENTS_ADMIN_URL;
770
+		$action = 'import_events';
771
+		$type = 'csv';
772
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
773
+			$title,
774
+			$intro,
775
+			$form_url,
776
+			$action,
777
+			$type
778
+		);
779
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
780
+			['action' => 'sample_export_file'],
781
+			$this->_admin_base_url
782
+		);
783
+		$content = EEH_Template::display_template(
784
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
785
+			$this->_template_args,
786
+			true
787
+		);
788
+		$this->_template_args['admin_page_content'] = $content;
789
+		$this->display_admin_page_with_sidebar();
790
+	}
791
+
792
+
793
+	/**
794
+	 * _import_events
795
+	 * This handles displaying the screen and running imports for importing events.
796
+	 *
797
+	 * @return void
798
+	 * @throws EE_Error
799
+	 * @throws InvalidArgumentException
800
+	 * @throws InvalidDataTypeException
801
+	 * @throws InvalidInterfaceException
802
+	 */
803
+	protected function _import_events()
804
+	{
805
+		require_once(EE_CLASSES . 'EE_Import.class.php');
806
+		$success = EE_Import::instance()->import();
807
+		$this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true);
808
+	}
809
+
810
+
811
+	/**
812
+	 * _events_export
813
+	 * Will export all (or just the given event) to a Excel compatible file.
814
+	 *
815
+	 * @access protected
816
+	 * @return void
817
+	 */
818
+	protected function _events_export()
819
+	{
820
+		if (isset($this->_req_data['EVT_ID'])) {
821
+			$event_ids = $this->_req_data['EVT_ID'];
822
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
823
+			$event_ids = $this->_req_data['EVT_IDs'];
824
+		} else {
825
+			$event_ids = null;
826
+		}
827
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
828
+		$new_request_args = [
829
+			'export' => 'report',
830
+			'action' => 'all_event_data',
831
+			'EVT_ID' => $event_ids,
832
+		];
833
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
834
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
835
+			require_once(EE_CLASSES . 'EE_Export.class.php');
836
+			$EE_Export = EE_Export::instance($this->_req_data);
837
+			if ($EE_Export instanceof EE_Export) {
838
+				$EE_Export->export();
839
+			}
840
+		}
841
+	}
842
+
843
+
844
+	/**
845
+	 * handle category exports()
846
+	 *
847
+	 * @return void
848
+	 */
849
+	protected function _categories_export()
850
+	{
851
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
852
+		$new_request_args = [
853
+			'export'       => 'report',
854
+			'action'       => 'categories',
855
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
856
+		];
857
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
858
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
859
+			require_once(EE_CLASSES . 'EE_Export.class.php');
860
+			$EE_Export = EE_Export::instance($this->_req_data);
861
+			if ($EE_Export instanceof EE_Export) {
862
+				$EE_Export->export();
863
+			}
864
+		}
865
+	}
866
+
867
+
868
+	/**
869
+	 * Creates a sample CSV file for importing
870
+	 */
871
+	protected function _sample_export_file()
872
+	{
873
+		$EE_Export = EE_Export::instance();
874
+		if ($EE_Export instanceof EE_Export) {
875
+			$EE_Export->export();
876
+		}
877
+	}
878
+
879
+
880
+	/*************        Template Settings        *************/
881
+	/**
882
+	 * Generates template settings page output
883
+	 *
884
+	 * @throws DomainException
885
+	 * @throws EE_Error
886
+	 * @throws InvalidArgumentException
887
+	 * @throws InvalidDataTypeException
888
+	 * @throws InvalidInterfaceException
889
+	 */
890
+	protected function _template_settings()
891
+	{
892
+		$this->_template_args['values'] = $this->_yes_no_values;
893
+		/**
894
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
895
+		 * from General_Settings_Admin_Page to here.
896
+		 */
897
+		$this->_template_args = apply_filters(
898
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
899
+			$this->_template_args
900
+		);
901
+		$this->_set_add_edit_form_tags('update_template_settings');
902
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
903
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
904
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
905
+			$this->_template_args,
906
+			true
907
+		);
908
+		$this->display_admin_page_with_sidebar();
909
+	}
910
+
911
+
912
+	/**
913
+	 * Handler for updating template settings.
914
+	 *
915
+	 * @throws EE_Error
916
+	 * @throws InvalidArgumentException
917
+	 * @throws InvalidDataTypeException
918
+	 * @throws InvalidInterfaceException
919
+	 */
920
+	protected function _update_template_settings()
921
+	{
922
+		/**
923
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
924
+		 * from General_Settings_Admin_Page to here.
925
+		 */
926
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
927
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
928
+			EE_Registry::instance()->CFG->template_settings,
929
+			$this->_req_data
930
+		);
931
+		// update custom post type slugs and detect if we need to flush rewrite rules
932
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
933
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
934
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
935
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
936
+		$what = 'Template Settings';
937
+		$success = $this->_update_espresso_configuration(
938
+			$what,
939
+			EE_Registry::instance()->CFG->template_settings,
940
+			__FILE__,
941
+			__FUNCTION__,
942
+			__LINE__
943
+		);
944
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
945
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
946
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
947
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
948
+			);
949
+			$rewrite_rules->flush();
950
+		}
951
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
952
+	}
953
+
954
+
955
+	/**
956
+	 * _premium_event_editor_meta_boxes
957
+	 * add all metaboxes related to the event_editor
958
+	 *
959
+	 * @access protected
960
+	 * @return void
961
+	 * @throws EE_Error
962
+	 * @throws InvalidArgumentException
963
+	 * @throws InvalidDataTypeException
964
+	 * @throws InvalidInterfaceException
965
+	 * @throws ReflectionException
966
+	 */
967
+	protected function _premium_event_editor_meta_boxes()
968
+	{
969
+		$this->verify_cpt_object();
970
+		/** @var FeatureFlags $flags */
971
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
972
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
973
+		if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
974
+			add_meta_box(
975
+				'espresso_event_editor_event_options',
976
+				esc_html__('Event Registration Options', 'event_espresso'),
977
+				[$this, 'registration_options_meta_box'],
978
+				$this->page_slug,
979
+				'side',
980
+				'core'
981
+			);
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 = [
996
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
997
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
998
+		];
999
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1000
+			[
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 = [];
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 = [
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 = [
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(['order_by' => ['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 = [
1196
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1197
+		];
1198
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * get total number of events this month
1204
+	 *
1205
+	 * @access public
1206
+	 * @return int
1207
+	 * @throws EE_Error
1208
+	 * @throws InvalidArgumentException
1209
+	 * @throws InvalidDataTypeException
1210
+	 * @throws InvalidInterfaceException
1211
+	 */
1212
+	public function total_events_this_month()
1213
+	{
1214
+		// Dates
1215
+		$this_year_r = date('Y');
1216
+		$this_month_r = date('m');
1217
+		$days_this_month = date('t');
1218
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1219
+			'DTT_EVT_start',
1220
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1221
+			'Y-m-d H:i:s',
1222
+			'UTC'
1223
+		);
1224
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1225
+			'DTT_EVT_start',
1226
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1227
+			'Y-m-d H:i:s',
1228
+			'UTC'
1229
+		);
1230
+		$where = [
1231
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1232
+		];
1233
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1234
+	}
1235
+
1236
+
1237
+	/** DEFAULT TICKETS STUFF **/
1238
+
1239
+	/**
1240
+	 * Output default tickets list table view.
1241
+	 *
1242
+	 * @throws DomainException
1243
+	 * @throws EE_Error
1244
+	 * @throws InvalidArgumentException
1245
+	 * @throws InvalidDataTypeException
1246
+	 * @throws InvalidInterfaceException
1247
+	 */
1248
+	public function _tickets_overview_list_table()
1249
+	{
1250
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1251
+		$this->display_admin_list_table_page_with_no_sidebar();
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 * @param int  $per_page
1257
+	 * @param bool $count
1258
+	 * @param bool $trashed
1259
+	 * @return EE_Soft_Delete_Base_Class[]|int
1260
+	 * @throws EE_Error
1261
+	 * @throws InvalidArgumentException
1262
+	 * @throws InvalidDataTypeException
1263
+	 * @throws InvalidInterfaceException
1264
+	 */
1265
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1266
+	{
1267
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1268
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1269
+		switch ($orderby) {
1270
+			case 'TKT_name':
1271
+				$orderby = ['TKT_name' => $order];
1272
+				break;
1273
+			case 'TKT_price':
1274
+				$orderby = ['TKT_price' => $order];
1275
+				break;
1276
+			case 'TKT_uses':
1277
+				$orderby = ['TKT_uses' => $order];
1278
+				break;
1279
+			case 'TKT_min':
1280
+				$orderby = ['TKT_min' => $order];
1281
+				break;
1282
+			case 'TKT_max':
1283
+				$orderby = ['TKT_max' => $order];
1284
+				break;
1285
+			case 'TKT_qty':
1286
+				$orderby = ['TKT_qty' => $order];
1287
+				break;
1288
+		}
1289
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1290
+			? $this->_req_data['paged']
1291
+			: 1;
1292
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1293
+			? $this->_req_data['perpage']
1294
+			: $per_page;
1295
+		$_where = [
1296
+			'TKT_is_default' => 1,
1297
+			'TKT_deleted'    => $trashed,
1298
+		];
1299
+		$offset = ($current_page - 1) * $per_page;
1300
+		$limit = [$offset, $per_page];
1301
+		if (isset($this->_req_data['s'])) {
1302
+			$sstr = '%' . $this->_req_data['s'] . '%';
1303
+			$_where['OR'] = [
1304
+				'TKT_name'        => ['LIKE', $sstr],
1305
+				'TKT_description' => ['LIKE', $sstr],
1306
+			];
1307
+		}
1308
+		$query_params = [
1309
+			$_where,
1310
+			'order_by' => $orderby,
1311
+			'limit'    => $limit,
1312
+			'group_by' => 'TKT_ID',
1313
+		];
1314
+		if ($count) {
1315
+			return EEM_Ticket::instance()->count_deleted_and_undeleted([$_where]);
1316
+		}
1317
+		return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1318
+	}
1319
+
1320
+
1321
+	/**
1322
+	 * @param bool $trash
1323
+	 * @throws EE_Error
1324
+	 * @throws InvalidArgumentException
1325
+	 * @throws InvalidDataTypeException
1326
+	 * @throws InvalidInterfaceException
1327
+	 */
1328
+	protected function _trash_or_restore_ticket($trash = false)
1329
+	{
1330
+		$success = 1;
1331
+		$TKT = EEM_Ticket::instance();
1332
+		// checkboxes?
1333
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1334
+			// if array has more than one element then success message should be plural
1335
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1336
+			// cycle thru the boxes
1337
+			foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1338
+				if ($trash) {
1339
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1340
+						$success = 0;
1341
+					}
1342
+				} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1343
+					$success = 0;
1344
+				}
1345
+			}
1346
+		} else {
1347
+			// grab single id and trash
1348
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1349
+			if ($trash) {
1350
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1351
+					$success = 0;
1352
+				}
1353
+			} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1354
+				$success = 0;
1355
+			}
1356
+		}
1357
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1358
+		$query_args = [
1359
+			'action' => 'ticket_list_table',
1360
+			'status' => $trash ? '' : 'trashed',
1361
+		];
1362
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1363
+	}
1364
+
1365
+
1366
+	/**
1367
+	 * Handles trashing default ticket.
1368
+	 *
1369
+	 * @throws EE_Error
1370
+	 * @throws InvalidArgumentException
1371
+	 * @throws InvalidDataTypeException
1372
+	 * @throws InvalidInterfaceException
1373
+	 * @throws ReflectionException
1374
+	 */
1375
+	protected function _delete_ticket()
1376
+	{
1377
+		$success = 1;
1378
+		// checkboxes?
1379
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1380
+			// if array has more than one element then success message should be plural
1381
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1382
+			// cycle thru the boxes
1383
+			foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1384
+				// delete
1385
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1386
+					$success = 0;
1387
+				}
1388
+			}
1389
+		} else {
1390
+			// grab single id and trash
1391
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1392
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1393
+				$success = 0;
1394
+			}
1395
+		}
1396
+		$action_desc = 'deleted';
1397
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1398
+		$ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
1399
+			[['TKT_is_default' => 1]],
1400
+			'TKT_ID',
1401
+			true
1402
+		);
1403
+		$query_args = $ticket_count
1404
+			? []
1405
+			: [
1406
+				'action' => 'ticket_list_table',
1407
+				'status' => 'trashed',
1408
+			];
1409
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1410
+	}
1411
+
1412
+
1413
+	/**
1414
+	 * @param int $TKT_ID
1415
+	 * @return bool|int
1416
+	 * @throws EE_Error
1417
+	 * @throws InvalidArgumentException
1418
+	 * @throws InvalidDataTypeException
1419
+	 * @throws InvalidInterfaceException
1420
+	 * @throws ReflectionException
1421
+	 */
1422
+	protected function _delete_the_ticket($TKT_ID)
1423
+	{
1424
+		$ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1425
+		if (! $ticket instanceof EE_Ticket) {
1426
+			return false;
1427
+		}
1428
+		$ticket->_remove_relations('Datetime');
1429
+		// delete all related prices first
1430
+		$ticket->delete_related_permanently('Price');
1431
+		return $ticket->delete_permanently();
1432
+	}
1433 1433
 }
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.
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.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -38,25 +38,25 @@  discard block
 block discarded – undo
38 38
     {
39 39
         global $wpdb;
40 40
         $this->_pretty_name = __("Answers", "event_espresso");
41
-        $this->_old_table = $wpdb->prefix . "events_answer";
41
+        $this->_old_table = $wpdb->prefix."events_answer";
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
-        $this->_new_answer_table = $wpdb->prefix . "esp_answer";
49
-        $this->_new_question_table = $wpdb->prefix . "esp_question";
48
+        $this->_new_answer_table = $wpdb->prefix."esp_answer";
49
+        $this->_new_question_table = $wpdb->prefix."esp_question";
50 50
         parent::__construct();
51 51
     }
52 52
     protected function _migrate_old_row($old_row)
53 53
     {
54 54
         // get the new REGs for the old answer
55 55
         global $wpdb;
56
-        $old_attendee_table = $wpdb->prefix . "events_attendee";
57
-        $new_reg_table = $wpdb->prefix . "esp_registration";
56
+        $old_attendee_table = $wpdb->prefix."events_attendee";
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
         }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     private function _insert_new_answer($old_answer, $new_reg_id)
76 76
     {
77 77
         global $wpdb;
78
-        $old_question_table = $wpdb->prefix . "events_question";
78
+        $old_question_table = $wpdb->prefix."events_question";
79 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 81
         $question_row = $this->_get_question_type_and_system($new_question_id);
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
             'ANS_value' => $ans_value
97 97
         );
98 98
         $datatypes = array(
99
-            '%d',// REG_ID
100
-            '%d',// QST_ID
101
-            '%s',// ANS_value
99
+            '%d', // REG_ID
100
+            '%d', // QST_ID
101
+            '%s', // ANS_value
102 102
         );
103 103
         $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
-        if (! $success) {
104
+        if ( ! $success) {
105 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 106
             return 0;
107 107
         }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         global $wpdb;
124 124
         $row = $wpdb->get_row(
125 125
             $wpdb->prepare(
126
-                "SELECT QST_type, QST_system FROM " . $this->_new_question_table . " WHERE QST_ID=%d LIMIT 1",
126
+                "SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1",
127 127
                 $question_id
128 128
             ),
129 129
             ARRAY_A
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   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -31,23 +31,23 @@  discard block
 block discarded – undo
31 31
     {
32 32
         global $wpdb;
33 33
         $this->_pretty_name = esc_html__('Checkins', 'event_espresso');
34
-        $this->_old_table = $wpdb->prefix . "events_attendee";
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
-        $this->_new_table = $wpdb->prefix . "esp_checkin";
39
+        $this->_new_table = $wpdb->prefix."esp_checkin";
40 40
         parent::__construct();
41 41
     }
42 42
     protected function _migrate_old_row($old_row)
43 43
     {
44 44
         global $wpdb;
45
-        $new_reg_table = $wpdb->prefix . "esp_registration";
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);
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
         $new_registrations_for_attendee = array_values($new_registrations_for_attendee);
57 57
         $new_checkin_ids = array();
58 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) {
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,7 +81,7 @@  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 87
                     $new_checkin_ids[] = $new_id;
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
     {
112 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) {
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 116
             $this->add_error(
117 117
                 sprintf(
118 118
                     esc_html__(
@@ -132,20 +132,20 @@  discard block
 block discarded – undo
132 132
         $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
133 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";
135
+        $datetime_table = $wpdb->prefix."esp_datetime";
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;
144 144
         do {
145
-            $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1";
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   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
     public function __construct()
59 59
     {
60 60
         global $wpdb;
61
-        $this->_old_table = $wpdb->prefix . "events_detail";
61
+        $this->_old_table = $wpdb->prefix."events_detail";
62 62
         $this->_extra_where_sql = 'WHERE event_status!="D"';
63
-        $this->_new_table = $wpdb->prefix . "esp_event_question_group";
63
+        $this->_new_table = $wpdb->prefix."esp_event_question_group";
64 64
         $this->_pretty_name = __("Question Groups in each Event", "event_espresso");
65 65
         parent::__construct();
66 66
     }
@@ -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   +635 added lines, -640 removed lines patch added patch discarded remove patch
@@ -85,8 +85,6 @@  discard block
 block discarded – undo
85 85
   KEY `submitted` (`submitted`),
86 86
   KEY `likes` (`likes`)
87 87
 ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$
88
-
89
-
90 88
  *
91 89
  * 4.1 Event model:
92 90
  * $this->_tables = array(
@@ -125,7 +123,6 @@  discard block
 block discarded – undo
125 123
                 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', __("Accept Donations?", "event_espresso"), false, false)
126 124
 
127 125
             ));
128
-
129 126
  *
130 127
  * 3.1's start end table
131 128
  *
@@ -138,8 +135,6 @@  discard block
 block discarded – undo
138 135
   PRIMARY KEY (`id`),
139 136
   KEY `event_id` (`event_id`)
140 137
 ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$
141
-
142
-
143 138
  *
144 139
  * and 4.1 Datetime model's tables and fields:
145 140
  * $this->_tables = array(
@@ -161,172 +156,172 @@  discard block
 block discarded – undo
161 156
  */
162 157
 class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage
163 158
 {
164
-    private $_old_table;
165
-    private $_old_start_end_table;
166
-    private $_new_table;
167
-    private $_new_meta_table;
168
-    private $_new_datetime_table;
169
-
170
-
171
-
172
-    /**
173
-     * Just initializes the status of the migration
174
-     * @throws EE_Error
175
-     */
176
-    public function __construct()
177
-    {
178
-        global $wpdb;
179
-        $this->_old_table = $wpdb->prefix . "events_detail";
180
-        $this->_old_start_end_table = $wpdb->prefix . "events_start_end";
181
-        $this->_new_table = $wpdb->prefix . "posts";
182
-        $this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
183
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
184
-        $this->_pretty_name = __("Events", "event_espresso");
185
-        parent::__construct();
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * Counts the records to migrate; the public version may cache it
192
-     * @return int
193
-     */
194
-    public function _count_records_to_migrate()
195
-    {
196
-        global $wpdb;
197
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
198
-        return intval($count);
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
205
-     * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
206
-     * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
207
-     * 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,
208
-     * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
209
-     * @param int $num_items_to_migrate
210
-     * @return int number of items ACTUALLY migrated
211
-     */
212
-    protected function _migration_step($num_items_to_migrate = 50)
213
-    {
214
-        global $wpdb;
215
-        // because the migration of each event can be a LOT more work, make each step smaller
216
-        $num_items_to_migrate = max(1, $num_items_to_migrate / 5);
217
-        $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);
218
-        $items_migrated_this_step = 0;
219
-
220
-        foreach ($events as $event_row) {
221
-            $guid = null;
222
-            // insert new 4.1 Attendee object using $wpdb
223
-            $post_id = $this->_insert_cpt($event_row);
224
-            if ($post_id) {
225
-                $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
226
-                $meta_id = $this->_insert_event_meta($event_row, $post_id);
227
-                if ($meta_id) {
228
-                    $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
229
-                }
230
-                $this->_convert_start_end_times($event_row, $post_id);
231
-                $event_meta = maybe_unserialize($event_row['event_meta']);
232
-                $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
233
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
234
-
235
-                // maybe create a venue from info on the event?
236
-                $new_venue_id = $this->_maybe_create_venue($event_row);
237
-                if ($new_venue_id) {
238
-                    $this->_insert_new_venue_to_event($post_id, $new_venue_id);
239
-                }
240
-                $this->_add_post_metas($event_row, $post_id);
241
-            }
242
-            $items_migrated_this_step++;
243
-            if ($guid) {
244
-                // if we had to check for an image attachment
245
-                // then let's call it a day (avoid timing out, because this took a long time)
246
-                break;
247
-            }
248
-        }
249
-        if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
250
-            $this->set_status(EE_Data_Migration_Manager::status_completed);
251
-        }
252
-        return $items_migrated_this_step;
253
-    }
254
-
255
-    /**
256
-     * Stores any extra 3.1 "event_meta" column things as post meta
257
-     * @param array $old_event
258
-     * @param int $post_id
259
-     * @return void
260
-     */
261
-    private function _add_post_metas($old_event, $post_id)
262
-    {
263
-        $event_meta = maybe_unserialize($old_event['event_meta']);
264
-        if (! $event_meta || ! is_array($event_meta)) {
265
-            return;
266
-        }
267
-        unset($event_meta['date_submitted']);// factored into CPT
268
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
269
-        unset($event_meta['default_payment_status']);// dido
270
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
271
-        foreach ($event_meta as $meta_key => $meta_value) {
272
-            if ($meta_key) {// if the meta key is just an empty string, ignore it
273
-                $success = add_post_meta($post_id, $meta_key, $meta_value, true);
274
-                if (! $success) {
275
-                    $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)));
276
-                }
277
-            }
278
-        }
279
-        if ($old_event['alt_email']) {
280
-            add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
281
-        }
282
-        if ($old_event['recurrence_id']) {
283
-            add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
284
-        }
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Finds a unique slug for this event, given its name (we could have simply used
291
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
292
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
293
-     * @param string $event_name (the name of the event for reading by humans)
294
-     * @param string $old_identifier the old EE3 identifier (a long unique string)
295
-     * @param string $new_post_status a post status
296
-     * @return string
297
-     */
298
-    private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
299
-    {
300
-        $count = 0;
301
-        $original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
302
-        return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
303
-    }
304
-
305
-    /**
306
-     * returns whether or not there is a post that has this same slug (post_title)
307
-     * @global wpdb $wpdb
308
-     * @param string $slug
309
-     * @return boolean
310
-     */
311
-    private function _other_post_exists_with_that_slug($slug)
312
-    {
313
-        global $wpdb;
314
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
315
-        $count = $wpdb->get_var($query);
316
-        return (bool) intval($count);
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * @param $old_event
323
-     * @return int
324
-     */
325
-    private function _insert_cpt($old_event)
326
-    {
327
-        global $wpdb;
328
-        // convert 3.1 event status to 4.1 CPT status
329
-        // for reference, 3.1 event stati available for setting are:
159
+	private $_old_table;
160
+	private $_old_start_end_table;
161
+	private $_new_table;
162
+	private $_new_meta_table;
163
+	private $_new_datetime_table;
164
+
165
+
166
+
167
+	/**
168
+	 * Just initializes the status of the migration
169
+	 * @throws EE_Error
170
+	 */
171
+	public function __construct()
172
+	{
173
+		global $wpdb;
174
+		$this->_old_table = $wpdb->prefix . "events_detail";
175
+		$this->_old_start_end_table = $wpdb->prefix . "events_start_end";
176
+		$this->_new_table = $wpdb->prefix . "posts";
177
+		$this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
178
+		$this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
179
+		$this->_pretty_name = __("Events", "event_espresso");
180
+		parent::__construct();
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Counts the records to migrate; the public version may cache it
187
+	 * @return int
188
+	 */
189
+	public function _count_records_to_migrate()
190
+	{
191
+		global $wpdb;
192
+		$count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
193
+		return intval($count);
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
200
+	 * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
201
+	 * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
202
+	 * 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,
203
+	 * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
204
+	 * @param int $num_items_to_migrate
205
+	 * @return int number of items ACTUALLY migrated
206
+	 */
207
+	protected function _migration_step($num_items_to_migrate = 50)
208
+	{
209
+		global $wpdb;
210
+		// because the migration of each event can be a LOT more work, make each step smaller
211
+		$num_items_to_migrate = max(1, $num_items_to_migrate / 5);
212
+		$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);
213
+		$items_migrated_this_step = 0;
214
+
215
+		foreach ($events as $event_row) {
216
+			$guid = null;
217
+			// insert new 4.1 Attendee object using $wpdb
218
+			$post_id = $this->_insert_cpt($event_row);
219
+			if ($post_id) {
220
+				$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
221
+				$meta_id = $this->_insert_event_meta($event_row, $post_id);
222
+				if ($meta_id) {
223
+					$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
224
+				}
225
+				$this->_convert_start_end_times($event_row, $post_id);
226
+				$event_meta = maybe_unserialize($event_row['event_meta']);
227
+				$guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
228
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
229
+
230
+				// maybe create a venue from info on the event?
231
+				$new_venue_id = $this->_maybe_create_venue($event_row);
232
+				if ($new_venue_id) {
233
+					$this->_insert_new_venue_to_event($post_id, $new_venue_id);
234
+				}
235
+				$this->_add_post_metas($event_row, $post_id);
236
+			}
237
+			$items_migrated_this_step++;
238
+			if ($guid) {
239
+				// if we had to check for an image attachment
240
+				// then let's call it a day (avoid timing out, because this took a long time)
241
+				break;
242
+			}
243
+		}
244
+		if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
245
+			$this->set_status(EE_Data_Migration_Manager::status_completed);
246
+		}
247
+		return $items_migrated_this_step;
248
+	}
249
+
250
+	/**
251
+	 * Stores any extra 3.1 "event_meta" column things as post meta
252
+	 * @param array $old_event
253
+	 * @param int $post_id
254
+	 * @return void
255
+	 */
256
+	private function _add_post_metas($old_event, $post_id)
257
+	{
258
+		$event_meta = maybe_unserialize($old_event['event_meta']);
259
+		if (! $event_meta || ! is_array($event_meta)) {
260
+			return;
261
+		}
262
+		unset($event_meta['date_submitted']);// factored into CPT
263
+		unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
264
+		unset($event_meta['default_payment_status']);// dido
265
+		unset($event_meta['event_thumbnail_url']);// used to find post featured image
266
+		foreach ($event_meta as $meta_key => $meta_value) {
267
+			if ($meta_key) {// if the meta key is just an empty string, ignore it
268
+				$success = add_post_meta($post_id, $meta_key, $meta_value, true);
269
+				if (! $success) {
270
+					$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)));
271
+				}
272
+			}
273
+		}
274
+		if ($old_event['alt_email']) {
275
+			add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
276
+		}
277
+		if ($old_event['recurrence_id']) {
278
+			add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
279
+		}
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * Finds a unique slug for this event, given its name (we could have simply used
286
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
287
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
288
+	 * @param string $event_name (the name of the event for reading by humans)
289
+	 * @param string $old_identifier the old EE3 identifier (a long unique string)
290
+	 * @param string $new_post_status a post status
291
+	 * @return string
292
+	 */
293
+	private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
294
+	{
295
+		$count = 0;
296
+		$original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
297
+		return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
298
+	}
299
+
300
+	/**
301
+	 * returns whether or not there is a post that has this same slug (post_title)
302
+	 * @global wpdb $wpdb
303
+	 * @param string $slug
304
+	 * @return boolean
305
+	 */
306
+	private function _other_post_exists_with_that_slug($slug)
307
+	{
308
+		global $wpdb;
309
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
310
+		$count = $wpdb->get_var($query);
311
+		return (bool) intval($count);
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @param $old_event
318
+	 * @return int
319
+	 */
320
+	private function _insert_cpt($old_event)
321
+	{
322
+		global $wpdb;
323
+		// convert 3.1 event status to 4.1 CPT status
324
+		// for reference, 3.1 event stati available for setting are:
330 325
 //      $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')));
331 326
 //      and the json api uses the following to convert from 3.1 to 4.0
332 327
 //      'S'=>'secondary/waitlist',
@@ -340,487 +335,487 @@  discard block
 block discarded – undo
340 335
 //      4.1 Event Post stati are the normal post statis
341 336
 //      (publish,future,draft,pending,private,trash,auto-draft,inherit)
342 337
 //      and 3 custom ones: cancelled,postponed,sold_out
343
-        $status_conversions = array(
344
-            'R' => 'draft',
345
-            'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
346
-            'P' => 'pending',
347
-            'IA' => 'draft',// draft and in the past
338
+		$status_conversions = array(
339
+			'R' => 'draft',
340
+			'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
341
+			'P' => 'pending',
342
+			'IA' => 'draft',// draft and in the past
348 343
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
349
-            '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'
350
-            'A' => 'publish',
351
-            'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
352
-            'D' => 'trash',
353
-        );
354
-        $post_status = $status_conversions[ $old_event['event_status'] ];
355
-        // check if we've sold out
356
-        if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
357
-            $post_status = 'sold_out';
358
-        }
344
+			'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'
345
+			'A' => 'publish',
346
+			'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
347
+			'D' => 'trash',
348
+		);
349
+		$post_status = $status_conversions[ $old_event['event_status'] ];
350
+		// check if we've sold out
351
+		if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
352
+			$post_status = 'sold_out';
353
+		}
359 354
 //      FYI postponed and cancelled don't exist in 3.1
360
-        $cols_n_values = array(
361
-            'post_title' => stripslashes($old_event['event_name']),// EVT_name
362
-            'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
363
-            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
364
-            'post_date' => $old_event['submitted'],// EVT_created NOT
365
-            'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
366
-            'post_excerpt' => '',// EVT_short_desc
367
-            'post_modified' => $old_event['submitted'],// EVT_modified
368
-            'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
369
-            'post_author' => $old_event['wp_user'],// EVT_wp_user
370
-            'post_parent' => 0,// parent maybe get this from some REM field?
371
-            'menu_order' => 0,// EVT_order
372
-            'post_type' => 'espresso_events',// post_type
373
-            'post_status' => $post_status,// status
374
-        );
375
-        $cols_n_values_with_no_invalid_text = array();
376
-        foreach ($cols_n_values as $col => $value) {
377
-            $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
378
-            if (! is_wp_error($value_sans_invalid_chars)) {
379
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
380
-            } else {
381
-                // otherwise leave it as-is. It will blow everything up and stop the migration
382
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
383
-            }
384
-        }
385
-        $cols_n_values = $cols_n_values_with_no_invalid_text;
386
-        $datatypes = array(
387
-            '%s',// EVT_name
388
-            '%s',// EVT_desc
389
-            '%s',// EVT_slug
390
-            '%s',// EVT_created
391
-            '%s',
392
-            '%s',// EVT_short_desc
393
-            '%s',// EVT_modified
394
-            '%s',
395
-            '%s',// EVT_wp_user
396
-            '%d',// post_parent
397
-            '%d',// EVT_order
398
-            '%s',// post_type
399
-            '%s',// status
400
-        );
401
-        $success = $wpdb->insert(
402
-            $this->_new_table,
403
-            $cols_n_values,
404
-            $datatypes
405
-        );
406
-        if (! $success) {
407
-            $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));
408
-            return 0;
409
-        }
410
-        return $wpdb->insert_id;
411
-    }
412
-
413
-    /**
414
-     * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
415
-     * @global wpdb $wpdb
416
-     * @param int $event_id
417
-     * @return int
418
-     */
419
-    public static function count_registrations($event_id)
420
-    {
421
-        global $wpdb;
422
-        $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
423
-        return intval($count);
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @param $old_event
430
-     * @param $new_cpt_id
431
-     * @return int
432
-     */
433
-    private function _insert_event_meta($old_event, $new_cpt_id)
434
-    {
435
-        global $wpdb;
436
-        $event_meta = maybe_unserialize($old_event['event_meta']);
355
+		$cols_n_values = array(
356
+			'post_title' => stripslashes($old_event['event_name']),// EVT_name
357
+			'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
358
+			'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
359
+			'post_date' => $old_event['submitted'],// EVT_created NOT
360
+			'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
361
+			'post_excerpt' => '',// EVT_short_desc
362
+			'post_modified' => $old_event['submitted'],// EVT_modified
363
+			'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
364
+			'post_author' => $old_event['wp_user'],// EVT_wp_user
365
+			'post_parent' => 0,// parent maybe get this from some REM field?
366
+			'menu_order' => 0,// EVT_order
367
+			'post_type' => 'espresso_events',// post_type
368
+			'post_status' => $post_status,// status
369
+		);
370
+		$cols_n_values_with_no_invalid_text = array();
371
+		foreach ($cols_n_values as $col => $value) {
372
+			$value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
373
+			if (! is_wp_error($value_sans_invalid_chars)) {
374
+				$cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
375
+			} else {
376
+				// otherwise leave it as-is. It will blow everything up and stop the migration
377
+				$cols_n_values_with_no_invalid_text[ $col ] = $value;
378
+			}
379
+		}
380
+		$cols_n_values = $cols_n_values_with_no_invalid_text;
381
+		$datatypes = array(
382
+			'%s',// EVT_name
383
+			'%s',// EVT_desc
384
+			'%s',// EVT_slug
385
+			'%s',// EVT_created
386
+			'%s',
387
+			'%s',// EVT_short_desc
388
+			'%s',// EVT_modified
389
+			'%s',
390
+			'%s',// EVT_wp_user
391
+			'%d',// post_parent
392
+			'%d',// EVT_order
393
+			'%s',// post_type
394
+			'%s',// status
395
+		);
396
+		$success = $wpdb->insert(
397
+			$this->_new_table,
398
+			$cols_n_values,
399
+			$datatypes
400
+		);
401
+		if (! $success) {
402
+			$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));
403
+			return 0;
404
+		}
405
+		return $wpdb->insert_id;
406
+	}
407
+
408
+	/**
409
+	 * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
410
+	 * @global wpdb $wpdb
411
+	 * @param int $event_id
412
+	 * @return int
413
+	 */
414
+	public static function count_registrations($event_id)
415
+	{
416
+		global $wpdb;
417
+		$count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
418
+		return intval($count);
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * @param $old_event
425
+	 * @param $new_cpt_id
426
+	 * @return int
427
+	 */
428
+	private function _insert_event_meta($old_event, $new_cpt_id)
429
+	{
430
+		global $wpdb;
431
+		$event_meta = maybe_unserialize($old_event['event_meta']);
437 432
 //      for reference, 3.1 'default_payment_status' are: $default_payment_status = array(
438 433
 //  array('id' => "", 'text' => 'No Change'),
439 434
 //  array('id' => 'Incomplete', 'text' => 'Incomplete'),
440 435
 //  array('id' => 'Pending', 'text' => 'Pending'),
441 436
 //  //array('id' => 'Completed', 'text' => 'Completed')
442 437
 // );
443
-        $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']));
444
-        $cols_n_values = array(
445
-            'EVT_ID' => $new_cpt_id,// EVT_ID_fk
446
-            'EVT_display_desc' => 'Y' == $old_event['display_desc'],
447
-            'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
448
-            '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
449
-            'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
450
-            'EVT_default_registration_status' => $default_reg_status,
451
-            'EVT_member_only' => $old_event['member_only'],
452
-            'EVT_phone' => $old_event['phone'],
453
-            'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
454
-            'EVT_timezone_string' => $old_event['timezone_string'],
455
-            'EVT_external_URL' => $old_event['externalURL'],
456
-            'EVT_donations' => false// doesnt exist in 3.1
457
-
458
-        );
459
-        $datatypes = array(
460
-            '%s',// EVT_ID
461
-            '%d',// EVT_display_desc
462
-            '%d',// EVT_display_ticket_selector
463
-            '%s',// EVT_visible_on
464
-            '%d',// EVT_additional_limit
465
-            '%s',// EVT_default_registration_status
466
-            '%d',// EVT_member_only
467
-            '%s',// EVT_phone
468
-            '%d',// EVT_allow_overflow
469
-            '%s',// EVT_timezone_string
470
-            '%s',// EVT_external_URL
471
-            '%d',// EVT_donations
472
-        );
473
-        $success = $wpdb->insert(
474
-            $this->_new_meta_table,
475
-            $cols_n_values,
476
-            $datatypes
477
-        );
478
-        if (! $success) {
479
-            $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));
480
-            return 0;
481
-        }
482
-        return $wpdb->insert_id;
483
-    }
484
-
485
-
486
-
487
-    /**
488
-     * @param $old_event
489
-     * @return int
490
-     */
491
-    private function _maybe_create_venue($old_event)
492
-    {
493
-        if (
494
-            $old_event['address'] ||
495
-                $old_event['address2'] ||
496
-                $old_event['city'] ||
497
-                $old_event['state'] ||
498
-                $old_event['zip'] ||
499
-                $old_event['venue_title'] ||
500
-                $old_event['venue_url'] ||
501
-                $old_event['venue_image'] ||
502
-                $old_event['venue_phone'] ||
503
-                $old_event['virtual_url'] ||
504
-                $old_event['virtual_phone']
505
-        ) {
506
-            $old_id = $this->_duplicate_venue_exists($old_event);
507
-            if ($old_id) {
508
-                return $old_id;
509
-            }
510
-            $new_id = $this->_insert_venue_into_posts($old_event);
511
-            if ($new_id) {
512
-                $this->_insert_venue_into_meta_table($new_id, $old_event);
513
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
514
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
515
-            }
516
-            // we don't bother recording the conversion from old events to venues as that
517
-            // will complicate finding the conversion from old venues to new events
518
-            return $new_id;
519
-        } else {
520
-            return 0;
521
-        }
522
-    }
523
-
524
-    /**
525
-     * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
526
-     * If so, return it. Otherwise return NULL.
527
-     * @param array $old_event
528
-     * @return int duplicate venue id
529
-     */
530
-    private function _duplicate_venue_exists($old_event)
531
-    {
532
-        global $wpdb;
533
-        $conditions = array(
534
-            'VNU_address' => $old_event ['address'],
535
-            'VNU_address2' => $old_event['address2'],
536
-            'VNU_city' => $old_event['city'],
537
-            'VNU_zip' => $old_event['zip'],
538
-            'post_title' => $this->_get_venue_title_for_event($old_event),
539
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
540
-            'VNU_url' => $old_event['venue_url'],// VNU_url
541
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
542
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
543
-        );
544
-        $sql_conditions = array();
545
-        foreach ($conditions as $column => $value) {
546
-            $sql_conditions [] = $wpdb->prepare("$column = %s", $value);
547
-        }
548
-        $query = "SELECT VNU_ID
438
+		$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']));
439
+		$cols_n_values = array(
440
+			'EVT_ID' => $new_cpt_id,// EVT_ID_fk
441
+			'EVT_display_desc' => 'Y' == $old_event['display_desc'],
442
+			'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
443
+			'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
444
+			'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
445
+			'EVT_default_registration_status' => $default_reg_status,
446
+			'EVT_member_only' => $old_event['member_only'],
447
+			'EVT_phone' => $old_event['phone'],
448
+			'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
449
+			'EVT_timezone_string' => $old_event['timezone_string'],
450
+			'EVT_external_URL' => $old_event['externalURL'],
451
+			'EVT_donations' => false// doesnt exist in 3.1
452
+
453
+		);
454
+		$datatypes = array(
455
+			'%s',// EVT_ID
456
+			'%d',// EVT_display_desc
457
+			'%d',// EVT_display_ticket_selector
458
+			'%s',// EVT_visible_on
459
+			'%d',// EVT_additional_limit
460
+			'%s',// EVT_default_registration_status
461
+			'%d',// EVT_member_only
462
+			'%s',// EVT_phone
463
+			'%d',// EVT_allow_overflow
464
+			'%s',// EVT_timezone_string
465
+			'%s',// EVT_external_URL
466
+			'%d',// EVT_donations
467
+		);
468
+		$success = $wpdb->insert(
469
+			$this->_new_meta_table,
470
+			$cols_n_values,
471
+			$datatypes
472
+		);
473
+		if (! $success) {
474
+			$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));
475
+			return 0;
476
+		}
477
+		return $wpdb->insert_id;
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * @param $old_event
484
+	 * @return int
485
+	 */
486
+	private function _maybe_create_venue($old_event)
487
+	{
488
+		if (
489
+			$old_event['address'] ||
490
+				$old_event['address2'] ||
491
+				$old_event['city'] ||
492
+				$old_event['state'] ||
493
+				$old_event['zip'] ||
494
+				$old_event['venue_title'] ||
495
+				$old_event['venue_url'] ||
496
+				$old_event['venue_image'] ||
497
+				$old_event['venue_phone'] ||
498
+				$old_event['virtual_url'] ||
499
+				$old_event['virtual_phone']
500
+		) {
501
+			$old_id = $this->_duplicate_venue_exists($old_event);
502
+			if ($old_id) {
503
+				return $old_id;
504
+			}
505
+			$new_id = $this->_insert_venue_into_posts($old_event);
506
+			if ($new_id) {
507
+				$this->_insert_venue_into_meta_table($new_id, $old_event);
508
+				$guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
509
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
510
+			}
511
+			// we don't bother recording the conversion from old events to venues as that
512
+			// will complicate finding the conversion from old venues to new events
513
+			return $new_id;
514
+		} else {
515
+			return 0;
516
+		}
517
+	}
518
+
519
+	/**
520
+	 * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
521
+	 * If so, return it. Otherwise return NULL.
522
+	 * @param array $old_event
523
+	 * @return int duplicate venue id
524
+	 */
525
+	private function _duplicate_venue_exists($old_event)
526
+	{
527
+		global $wpdb;
528
+		$conditions = array(
529
+			'VNU_address' => $old_event ['address'],
530
+			'VNU_address2' => $old_event['address2'],
531
+			'VNU_city' => $old_event['city'],
532
+			'VNU_zip' => $old_event['zip'],
533
+			'post_title' => $this->_get_venue_title_for_event($old_event),
534
+			'VNU_phone' => $old_event['venue_phone'],// VNU_phone
535
+			'VNU_url' => $old_event['venue_url'],// VNU_url
536
+			'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
537
+			'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
538
+		);
539
+		$sql_conditions = array();
540
+		foreach ($conditions as $column => $value) {
541
+			$sql_conditions [] = $wpdb->prepare("$column = %s", $value);
542
+		}
543
+		$query = "SELECT VNU_ID
549 544
 					FROM
550 545
 		{$wpdb->posts} as p INNER JOIN
551 546
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
552 547
 			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
553
-        $id = $wpdb->get_var($query);
554
-        return $id;
555
-    }
556
-
557
-    /**
558
-     * Gets teh venue's title or makes one up if there is none
559
-     * @param array $event_data_array keys are events_details columns and values are their values
560
-     * @return string
561
-     */
562
-    protected function _get_venue_title_for_event($event_data_array)
563
-    {
564
-        return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
565
-    }
566
-
567
-    /**
568
-     * Inserts the CPT
569
-     *
570
-     * @param array $old_event keys are cols, values are col values
571
-     * @return int
572
-     */
573
-    private function _insert_venue_into_posts($old_event)
574
-    {
575
-        global $wpdb;
576
-        $insertion_array = array(
577
-                    'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
578
-                    'post_content' => '',// VNU_desc
579
-                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
580
-                    'post_date' => current_time('mysql'),// VNU_created
581
-                    'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
582
-                    'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
583
-                    'post_modified' => current_time('mysql'),// VNU_modified
584
-                    'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
585
-                    'post_author' => $old_event['wp_user'],// VNU_wp_user
586
-                    'post_parent' => 0,// parent
587
-                    'menu_order' => 0,// VNU_order
588
-                    'post_type' => 'espresso_venues'// post_type
589
-                );
590
-        $datatypes_array = array(
591
-                    '%s',// VNU_name
592
-                    '%s',// VNU_desc
593
-                    '%s',// VNU_identifier
594
-                    '%s',// VNU_created
595
-                    '%s',
596
-                    '%s',// VNU_short_desc
597
-                    '%s',// VNU_modified
598
-                    '%s',
599
-                    '%d',// VNU_wp_user
600
-                    '%d',// parent
601
-                    '%d',// VNU_order
602
-                    '%s',// post_type
603
-                );
604
-        $success = $wpdb->insert(
605
-            $wpdb->posts,
606
-            $insertion_array,
607
-            $datatypes_array
608
-        );
609
-        if (! $success) {
610
-            $this->add_error(
611
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
612
-                    $this->_old_table,
613
-                    $old_event,
614
-                    $this->_new_table,
615
-                    $insertion_array,
616
-                    $datatypes_array
617
-                )
618
-            );
619
-            return 0;
620
-        }
621
-        return $wpdb->insert_id;
622
-    }
623
-
624
-    /**
625
-     * Inserts into the venue_meta table
626
-     * @param int $cpt_id
627
-     * @param array $old_event
628
-     * @return int
629
-     */
630
-    private function _insert_venue_into_meta_table($cpt_id, $old_event)
631
-    {
632
-        global $wpdb;
633
-
634
-        // assume the country is the same as the organization's old settings
635
-        $country_iso = $this->get_migration_script()->get_default_country_iso();
636
-        // find the state from the venue, or the organization, or just guess california
637
-        if (! $old_event['state']) {
638
-            $old_org_options = get_option('events_organization_settings');
639
-            $state_name = stripslashes($old_org_options['organization_state']);
640
-        } else {
641
-            $state_name = $old_event['state'];
642
-        }
643
-        if (! $state_name) {
644
-            $state_name = 'CA';
645
-        }
646
-        // get a state ID with the same name, if possible
647
-        try {
648
-            $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
649
-            $state_id = $state['STA_ID'];
650
-        } catch (EE_Error $e) {
651
-            $this->add_error($e->getMessage());
652
-            $state_id = 0;
653
-        }
654
-        // now insert into meta table
655
-        $insertion_array = array(
656
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
657
-            'VNU_address' => stripslashes($old_event['address']),// VNU_address
658
-            'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
659
-            'VNU_city' => stripslashes($old_event['city']),// VNU_city
660
-            'STA_ID' => $state_id,// STA_ID
661
-            'CNT_ISO' => $country_iso,// CNT_ISO
662
-            'VNU_zip' => $old_event['zip'],// VNU_zip
663
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
664
-            'VNU_capacity' => -1,// VNU_capacity
665
-            'VNU_url' => $old_event['venue_url'],// VNU_url
666
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
667
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
668
-            'VNU_google_map_link' => '',// VNU_google_map_link
669
-            'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
670
-        );
671
-        $datatypes = array(
672
-            '%d',// VNU_ID_fk
673
-            '%s',// VNU_address
674
-            '%s',// VNU_address2
675
-            '%s',// VNU_city
676
-            '%d',// STA_ID
677
-            '%s',// CNT_ISO
678
-            '%s',// VNU_zip
679
-            '%s',// VNU_phone
680
-            '%d',// VNU_capacity
681
-            '%s',// VNU_url
682
-            '%s',// VNU_virtual_phone
683
-            '%s',// VNU_virtual_url
684
-            '%s',// VNU_google_map_link
685
-            '%d',// VNU_enable_for_gmap
686
-        );
687
-        $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
688
-        if (! $success) {
689
-            $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));
690
-            return 0;
691
-        }
692
-        return $wpdb->insert_id;
693
-    }
694
-
695
-
696
-
697
-    /**
698
-     * @param $new_event_id
699
-     * @param $new_venue_id
700
-     * @return int
701
-     */
702
-    private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
703
-    {
704
-        global $wpdb;
705
-        if (! $new_event_id) {
706
-            $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
707
-            return 0;
708
-        }
709
-        if (! $new_venue_id) {
710
-            $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
711
-            return 0;
712
-        }
713
-        $cols_n_values = array(
714
-            'EVT_ID' => $new_event_id,
715
-            'VNU_ID' => $new_venue_id,
716
-            'EVV_primary' => true
717
-        );
718
-        $datatypes = array(
719
-            '%d',// EVT_ID
720
-            '%d',// VNU_ID
721
-            '%d',// EVT_primary
722
-        );
723
-        $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
724
-        if (! $success) {
725
-            $this->add_error(
726
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
727
-                    $this->_old_table,
728
-                    array(),
729
-                    $this->_new_table,
730
-                    $cols_n_values,
731
-                    $datatypes
732
-                )
733
-            );
734
-            return 0;
735
-        }
736
-        return $wpdb->insert_id;
737
-    }
738
-    /**
739
-     * Converts all the 3.1 start-end times for the event to 4.1 datetimes
740
-     * @global wpdb $wpdb
741
-     * @param array $old_event results of get_results(...,ARRAY_A)
742
-     * @param int $new_cpt_id new post ID
743
-     * @return void (if there are errors though, adds them to the stage's error list
744
-     */
745
-    private function _convert_start_end_times($old_event, $new_cpt_id)
746
-    {
747
-        $start_end_times = $this->_get_old_start_end_times($old_event['id']);
748
-        foreach ($start_end_times as $start_end_time) {
749
-            $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
750
-            if ($datetime_id) {
751
-                $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
752
-            }
753
-        }
754
-    }
755
-    /**
756
-     * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
757
-     * @global wpdb $wpdb
758
-     * @param int $old_event_id
759
-     * @return array
760
-     */
761
-    private function _get_old_start_end_times($old_event_id)
762
-    {
763
-        global $wpdb;
764
-        return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
765
-    }
766
-    /**
767
-     * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
768
-     * @param array $start_end_time_row
769
-     * @param array $old_event_row
770
-     * @param int $new_cpt_id
771
-     * @return int ID of new datetime
772
-     */
773
-    private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
774
-    {
775
-        global $wpdb;
776
-        $start_date = $old_event_row['start_date'];
777
-        $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
778
-        $end_date = $old_event_row['end_date'];
779
-        $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
780
-        $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
781
-        $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']);
782
-        $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']);
783
-        $cols_n_values = array(
784
-            'EVT_ID' => $new_cpt_id,// EVT_ID
785
-            'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
786
-            'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
787
-            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
788
-            'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
548
+		$id = $wpdb->get_var($query);
549
+		return $id;
550
+	}
551
+
552
+	/**
553
+	 * Gets teh venue's title or makes one up if there is none
554
+	 * @param array $event_data_array keys are events_details columns and values are their values
555
+	 * @return string
556
+	 */
557
+	protected function _get_venue_title_for_event($event_data_array)
558
+	{
559
+		return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
560
+	}
561
+
562
+	/**
563
+	 * Inserts the CPT
564
+	 *
565
+	 * @param array $old_event keys are cols, values are col values
566
+	 * @return int
567
+	 */
568
+	private function _insert_venue_into_posts($old_event)
569
+	{
570
+		global $wpdb;
571
+		$insertion_array = array(
572
+					'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
573
+					'post_content' => '',// VNU_desc
574
+					'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
575
+					'post_date' => current_time('mysql'),// VNU_created
576
+					'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
577
+					'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
578
+					'post_modified' => current_time('mysql'),// VNU_modified
579
+					'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
580
+					'post_author' => $old_event['wp_user'],// VNU_wp_user
581
+					'post_parent' => 0,// parent
582
+					'menu_order' => 0,// VNU_order
583
+					'post_type' => 'espresso_venues'// post_type
584
+				);
585
+		$datatypes_array = array(
586
+					'%s',// VNU_name
587
+					'%s',// VNU_desc
588
+					'%s',// VNU_identifier
589
+					'%s',// VNU_created
590
+					'%s',
591
+					'%s',// VNU_short_desc
592
+					'%s',// VNU_modified
593
+					'%s',
594
+					'%d',// VNU_wp_user
595
+					'%d',// parent
596
+					'%d',// VNU_order
597
+					'%s',// post_type
598
+				);
599
+		$success = $wpdb->insert(
600
+			$wpdb->posts,
601
+			$insertion_array,
602
+			$datatypes_array
603
+		);
604
+		if (! $success) {
605
+			$this->add_error(
606
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
607
+					$this->_old_table,
608
+					$old_event,
609
+					$this->_new_table,
610
+					$insertion_array,
611
+					$datatypes_array
612
+				)
613
+			);
614
+			return 0;
615
+		}
616
+		return $wpdb->insert_id;
617
+	}
618
+
619
+	/**
620
+	 * Inserts into the venue_meta table
621
+	 * @param int $cpt_id
622
+	 * @param array $old_event
623
+	 * @return int
624
+	 */
625
+	private function _insert_venue_into_meta_table($cpt_id, $old_event)
626
+	{
627
+		global $wpdb;
628
+
629
+		// assume the country is the same as the organization's old settings
630
+		$country_iso = $this->get_migration_script()->get_default_country_iso();
631
+		// find the state from the venue, or the organization, or just guess california
632
+		if (! $old_event['state']) {
633
+			$old_org_options = get_option('events_organization_settings');
634
+			$state_name = stripslashes($old_org_options['organization_state']);
635
+		} else {
636
+			$state_name = $old_event['state'];
637
+		}
638
+		if (! $state_name) {
639
+			$state_name = 'CA';
640
+		}
641
+		// get a state ID with the same name, if possible
642
+		try {
643
+			$state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
644
+			$state_id = $state['STA_ID'];
645
+		} catch (EE_Error $e) {
646
+			$this->add_error($e->getMessage());
647
+			$state_id = 0;
648
+		}
649
+		// now insert into meta table
650
+		$insertion_array = array(
651
+			'VNU_ID' => $cpt_id,// VNU_ID_fk
652
+			'VNU_address' => stripslashes($old_event['address']),// VNU_address
653
+			'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
654
+			'VNU_city' => stripslashes($old_event['city']),// VNU_city
655
+			'STA_ID' => $state_id,// STA_ID
656
+			'CNT_ISO' => $country_iso,// CNT_ISO
657
+			'VNU_zip' => $old_event['zip'],// VNU_zip
658
+			'VNU_phone' => $old_event['venue_phone'],// VNU_phone
659
+			'VNU_capacity' => -1,// VNU_capacity
660
+			'VNU_url' => $old_event['venue_url'],// VNU_url
661
+			'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
662
+			'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
663
+			'VNU_google_map_link' => '',// VNU_google_map_link
664
+			'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
665
+		);
666
+		$datatypes = array(
667
+			'%d',// VNU_ID_fk
668
+			'%s',// VNU_address
669
+			'%s',// VNU_address2
670
+			'%s',// VNU_city
671
+			'%d',// STA_ID
672
+			'%s',// CNT_ISO
673
+			'%s',// VNU_zip
674
+			'%s',// VNU_phone
675
+			'%d',// VNU_capacity
676
+			'%s',// VNU_url
677
+			'%s',// VNU_virtual_phone
678
+			'%s',// VNU_virtual_url
679
+			'%s',// VNU_google_map_link
680
+			'%d',// VNU_enable_for_gmap
681
+		);
682
+		$success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
683
+		if (! $success) {
684
+			$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));
685
+			return 0;
686
+		}
687
+		return $wpdb->insert_id;
688
+	}
689
+
690
+
691
+
692
+	/**
693
+	 * @param $new_event_id
694
+	 * @param $new_venue_id
695
+	 * @return int
696
+	 */
697
+	private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
698
+	{
699
+		global $wpdb;
700
+		if (! $new_event_id) {
701
+			$this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
702
+			return 0;
703
+		}
704
+		if (! $new_venue_id) {
705
+			$this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
706
+			return 0;
707
+		}
708
+		$cols_n_values = array(
709
+			'EVT_ID' => $new_event_id,
710
+			'VNU_ID' => $new_venue_id,
711
+			'EVV_primary' => true
712
+		);
713
+		$datatypes = array(
714
+			'%d',// EVT_ID
715
+			'%d',// VNU_ID
716
+			'%d',// EVT_primary
717
+		);
718
+		$success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
719
+		if (! $success) {
720
+			$this->add_error(
721
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
722
+					$this->_old_table,
723
+					array(),
724
+					$this->_new_table,
725
+					$cols_n_values,
726
+					$datatypes
727
+				)
728
+			);
729
+			return 0;
730
+		}
731
+		return $wpdb->insert_id;
732
+	}
733
+	/**
734
+	 * Converts all the 3.1 start-end times for the event to 4.1 datetimes
735
+	 * @global wpdb $wpdb
736
+	 * @param array $old_event results of get_results(...,ARRAY_A)
737
+	 * @param int $new_cpt_id new post ID
738
+	 * @return void (if there are errors though, adds them to the stage's error list
739
+	 */
740
+	private function _convert_start_end_times($old_event, $new_cpt_id)
741
+	{
742
+		$start_end_times = $this->_get_old_start_end_times($old_event['id']);
743
+		foreach ($start_end_times as $start_end_time) {
744
+			$datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
745
+			if ($datetime_id) {
746
+				$this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
747
+			}
748
+		}
749
+	}
750
+	/**
751
+	 * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
752
+	 * @global wpdb $wpdb
753
+	 * @param int $old_event_id
754
+	 * @return array
755
+	 */
756
+	private function _get_old_start_end_times($old_event_id)
757
+	{
758
+		global $wpdb;
759
+		return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
760
+	}
761
+	/**
762
+	 * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
763
+	 * @param array $start_end_time_row
764
+	 * @param array $old_event_row
765
+	 * @param int $new_cpt_id
766
+	 * @return int ID of new datetime
767
+	 */
768
+	private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
769
+	{
770
+		global $wpdb;
771
+		$start_date = $old_event_row['start_date'];
772
+		$start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
773
+		$end_date = $old_event_row['end_date'];
774
+		$end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
775
+		$existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
776
+		$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']);
777
+		$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']);
778
+		$cols_n_values = array(
779
+			'EVT_ID' => $new_cpt_id,// EVT_ID
780
+			'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
781
+			'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
782
+			'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
783
+			'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
789 784
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
790
-            'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
791
-            'DTT_parent' => 0,
792
-            'DTT_deleted' => false
793
-        );
794
-        $datatypes = array(
795
-            '%d',// EVT_Id
796
-            '%s',// DTT_EVT_start
797
-            '%s',// DTT_EVT_end
798
-            '%d',// DTT_reg_limit
799
-            '%d',// DTT_sold
785
+			'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
786
+			'DTT_parent' => 0,
787
+			'DTT_deleted' => false
788
+		);
789
+		$datatypes = array(
790
+			'%d',// EVT_Id
791
+			'%s',// DTT_EVT_start
792
+			'%s',// DTT_EVT_end
793
+			'%d',// DTT_reg_limit
794
+			'%d',// DTT_sold
800 795
 //          '%d',//DTT_is_primary
801
-            '%d',// DTT_order
802
-            '%d',// DTT_parent
803
-            '%d',// DTT_deleted
804
-        );
805
-        $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
806
-        if (! $success) {
807
-            $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));
808
-            return 0;
809
-        }
810
-        return $wpdb->insert_id;
811
-    }
812
-
813
-    /**
814
-     * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
815
-     * when deciding whether a datetime we're about ot insert should be the 'primary' or not
816
-     * @global wpdb $wpdb
817
-     * @param int $cpt_event_id
818
-     * @return int
819
-     */
820
-    private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
821
-    {
822
-        global $wpdb;
823
-        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
824
-        return intval($count);
825
-    }
796
+			'%d',// DTT_order
797
+			'%d',// DTT_parent
798
+			'%d',// DTT_deleted
799
+		);
800
+		$success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
801
+		if (! $success) {
802
+			$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));
803
+			return 0;
804
+		}
805
+		return $wpdb->insert_id;
806
+	}
807
+
808
+	/**
809
+	 * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
810
+	 * when deciding whether a datetime we're about ot insert should be the 'primary' or not
811
+	 * @global wpdb $wpdb
812
+	 * @param int $cpt_event_id
813
+	 * @return int
814
+	 */
815
+	private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
816
+	{
817
+		global $wpdb;
818
+		$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
819
+		return intval($count);
820
+	}
826 821
 }
Please login to merge, or discard this patch.
Spacing   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
     public function __construct()
177 177
     {
178 178
         global $wpdb;
179
-        $this->_old_table = $wpdb->prefix . "events_detail";
180
-        $this->_old_start_end_table = $wpdb->prefix . "events_start_end";
181
-        $this->_new_table = $wpdb->prefix . "posts";
182
-        $this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
183
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
179
+        $this->_old_table = $wpdb->prefix."events_detail";
180
+        $this->_old_start_end_table = $wpdb->prefix."events_start_end";
181
+        $this->_new_table = $wpdb->prefix."posts";
182
+        $this->_new_meta_table = $wpdb->prefix."esp_event_meta";
183
+        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
184 184
         $this->_pretty_name = __("Events", "event_espresso");
185 185
         parent::__construct();
186 186
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     public function _count_records_to_migrate()
195 195
     {
196 196
         global $wpdb;
197
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
197
+        $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table.' WHERE event_status !="D"');
198 198
         return intval($count);
199 199
     }
200 200
 
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
     private function _add_post_metas($old_event, $post_id)
262 262
     {
263 263
         $event_meta = maybe_unserialize($old_event['event_meta']);
264
-        if (! $event_meta || ! is_array($event_meta)) {
264
+        if ( ! $event_meta || ! is_array($event_meta)) {
265 265
             return;
266 266
         }
267
-        unset($event_meta['date_submitted']);// factored into CPT
268
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
269
-        unset($event_meta['default_payment_status']);// dido
270
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
267
+        unset($event_meta['date_submitted']); // factored into CPT
268
+        unset($event_meta['additional_attendee_reg_info']); // factored into event meta table
269
+        unset($event_meta['default_payment_status']); // dido
270
+        unset($event_meta['event_thumbnail_url']); // used to find post featured image
271 271
         foreach ($event_meta as $meta_key => $meta_value) {
272 272
             if ($meta_key) {// if the meta key is just an empty string, ignore it
273 273
                 $success = add_post_meta($post_id, $meta_key, $meta_value, true);
274
-                if (! $success) {
274
+                if ( ! $success) {
275 275
                     $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)));
276 276
                 }
277 277
             }
@@ -342,68 +342,68 @@  discard block
 block discarded – undo
342 342
 //      and 3 custom ones: cancelled,postponed,sold_out
343 343
         $status_conversions = array(
344 344
             'R' => 'draft',
345
-            '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
+            'X' => 'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
346 346
             'P' => 'pending',
347
-            'IA' => 'draft',// draft and in the past
347
+            'IA' => 'draft', // draft and in the past
348 348
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
349
-            '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
+            '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'
350 350
             'A' => 'publish',
351
-            'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
351
+            'S' => 'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
352 352
             'D' => 'trash',
353 353
         );
354
-        $post_status = $status_conversions[ $old_event['event_status'] ];
354
+        $post_status = $status_conversions[$old_event['event_status']];
355 355
         // check if we've sold out
356 356
         if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
357 357
             $post_status = 'sold_out';
358 358
         }
359 359
 //      FYI postponed and cancelled don't exist in 3.1
360 360
         $cols_n_values = array(
361
-            'post_title' => stripslashes($old_event['event_name']),// EVT_name
362
-            'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
363
-            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
364
-            'post_date' => $old_event['submitted'],// EVT_created NOT
361
+            'post_title' => stripslashes($old_event['event_name']), // EVT_name
362
+            'post_content' => stripslashes($old_event['event_desc']), // EVT_desc
363
+            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug
364
+            'post_date' => $old_event['submitted'], // EVT_created NOT
365 365
             'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
366
-            'post_excerpt' => '',// EVT_short_desc
367
-            'post_modified' => $old_event['submitted'],// EVT_modified
366
+            'post_excerpt' => '', // EVT_short_desc
367
+            'post_modified' => $old_event['submitted'], // EVT_modified
368 368
             'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
369
-            'post_author' => $old_event['wp_user'],// EVT_wp_user
370
-            'post_parent' => 0,// parent maybe get this from some REM field?
371
-            'menu_order' => 0,// EVT_order
372
-            'post_type' => 'espresso_events',// post_type
373
-            'post_status' => $post_status,// status
369
+            'post_author' => $old_event['wp_user'], // EVT_wp_user
370
+            'post_parent' => 0, // parent maybe get this from some REM field?
371
+            'menu_order' => 0, // EVT_order
372
+            'post_type' => 'espresso_events', // post_type
373
+            'post_status' => $post_status, // status
374 374
         );
375 375
         $cols_n_values_with_no_invalid_text = array();
376 376
         foreach ($cols_n_values as $col => $value) {
377 377
             $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
378
-            if (! is_wp_error($value_sans_invalid_chars)) {
379
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
378
+            if ( ! is_wp_error($value_sans_invalid_chars)) {
379
+                $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars;
380 380
             } else {
381 381
                 // otherwise leave it as-is. It will blow everything up and stop the migration
382
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
382
+                $cols_n_values_with_no_invalid_text[$col] = $value;
383 383
             }
384 384
         }
385 385
         $cols_n_values = $cols_n_values_with_no_invalid_text;
386 386
         $datatypes = array(
387
-            '%s',// EVT_name
388
-            '%s',// EVT_desc
389
-            '%s',// EVT_slug
390
-            '%s',// EVT_created
387
+            '%s', // EVT_name
388
+            '%s', // EVT_desc
389
+            '%s', // EVT_slug
390
+            '%s', // EVT_created
391 391
             '%s',
392
-            '%s',// EVT_short_desc
393
-            '%s',// EVT_modified
392
+            '%s', // EVT_short_desc
393
+            '%s', // EVT_modified
394 394
             '%s',
395
-            '%s',// EVT_wp_user
396
-            '%d',// post_parent
397
-            '%d',// EVT_order
398
-            '%s',// post_type
399
-            '%s',// status
395
+            '%s', // EVT_wp_user
396
+            '%d', // post_parent
397
+            '%d', // EVT_order
398
+            '%s', // post_type
399
+            '%s', // status
400 400
         );
401 401
         $success = $wpdb->insert(
402 402
             $this->_new_table,
403 403
             $cols_n_values,
404 404
             $datatypes
405 405
         );
406
-        if (! $success) {
406
+        if ( ! $success) {
407 407
             $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));
408 408
             return 0;
409 409
         }
@@ -442,10 +442,10 @@  discard block
 block discarded – undo
442 442
 // );
443 443
         $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']));
444 444
         $cols_n_values = array(
445
-            'EVT_ID' => $new_cpt_id,// EVT_ID_fk
445
+            'EVT_ID' => $new_cpt_id, // EVT_ID_fk
446 446
             'EVT_display_desc' => 'Y' == $old_event['display_desc'],
447 447
             'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
448
-            '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_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
449 449
             'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
450 450
             'EVT_default_registration_status' => $default_reg_status,
451 451
             'EVT_member_only' => $old_event['member_only'],
@@ -457,25 +457,25 @@  discard block
 block discarded – undo
457 457
 
458 458
         );
459 459
         $datatypes = array(
460
-            '%s',// EVT_ID
461
-            '%d',// EVT_display_desc
462
-            '%d',// EVT_display_ticket_selector
463
-            '%s',// EVT_visible_on
464
-            '%d',// EVT_additional_limit
465
-            '%s',// EVT_default_registration_status
466
-            '%d',// EVT_member_only
467
-            '%s',// EVT_phone
468
-            '%d',// EVT_allow_overflow
469
-            '%s',// EVT_timezone_string
470
-            '%s',// EVT_external_URL
471
-            '%d',// EVT_donations
460
+            '%s', // EVT_ID
461
+            '%d', // EVT_display_desc
462
+            '%d', // EVT_display_ticket_selector
463
+            '%s', // EVT_visible_on
464
+            '%d', // EVT_additional_limit
465
+            '%s', // EVT_default_registration_status
466
+            '%d', // EVT_member_only
467
+            '%s', // EVT_phone
468
+            '%d', // EVT_allow_overflow
469
+            '%s', // EVT_timezone_string
470
+            '%s', // EVT_external_URL
471
+            '%d', // EVT_donations
472 472
         );
473 473
         $success = $wpdb->insert(
474 474
             $this->_new_meta_table,
475 475
             $cols_n_values,
476 476
             $datatypes
477 477
         );
478
-        if (! $success) {
478
+        if ( ! $success) {
479 479
             $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));
480 480
             return 0;
481 481
         }
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
             $new_id = $this->_insert_venue_into_posts($old_event);
511 511
             if ($new_id) {
512 512
                 $this->_insert_venue_into_meta_table($new_id, $old_event);
513
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
513
+                $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null;
514 514
                 $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
515 515
             }
516 516
             // we don't bother recording the conversion from old events to venues as that
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
             'VNU_city' => $old_event['city'],
537 537
             'VNU_zip' => $old_event['zip'],
538 538
             'post_title' => $this->_get_venue_title_for_event($old_event),
539
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
540
-            'VNU_url' => $old_event['venue_url'],// VNU_url
541
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
542
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
539
+            'VNU_phone' => $old_event['venue_phone'], // VNU_phone
540
+            'VNU_url' => $old_event['venue_url'], // VNU_url
541
+            'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone
542
+            'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url
543 543
         );
544 544
         $sql_conditions = array();
545 545
         foreach ($conditions as $column => $value) {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 					FROM
550 550
 		{$wpdb->posts} as p INNER JOIN
551 551
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
552
-			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
552
+			WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1";
553 553
         $id = $wpdb->get_var($query);
554 554
         return $id;
555 555
     }
@@ -574,39 +574,39 @@  discard block
 block discarded – undo
574 574
     {
575 575
         global $wpdb;
576 576
         $insertion_array = array(
577
-                    'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
578
-                    'post_content' => '',// VNU_desc
579
-                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
580
-                    'post_date' => current_time('mysql'),// VNU_created
577
+                    'post_title' => $this->_get_venue_title_for_event($old_event), // VNU_name
578
+                    'post_content' => '', // VNU_desc
579
+                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier
580
+                    'post_date' => current_time('mysql'), // VNU_created
581 581
                     'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
582
-                    'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
583
-                    'post_modified' => current_time('mysql'),// VNU_modified
582
+                    'post_excerpt' => '', // VNU_short_desc arbitrary only 50 characters
583
+                    'post_modified' => current_time('mysql'), // VNU_modified
584 584
                     'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
585
-                    'post_author' => $old_event['wp_user'],// VNU_wp_user
586
-                    'post_parent' => 0,// parent
587
-                    'menu_order' => 0,// VNU_order
585
+                    'post_author' => $old_event['wp_user'], // VNU_wp_user
586
+                    'post_parent' => 0, // parent
587
+                    'menu_order' => 0, // VNU_order
588 588
                     'post_type' => 'espresso_venues'// post_type
589 589
                 );
590 590
         $datatypes_array = array(
591
-                    '%s',// VNU_name
592
-                    '%s',// VNU_desc
593
-                    '%s',// VNU_identifier
594
-                    '%s',// VNU_created
591
+                    '%s', // VNU_name
592
+                    '%s', // VNU_desc
593
+                    '%s', // VNU_identifier
594
+                    '%s', // VNU_created
595 595
                     '%s',
596
-                    '%s',// VNU_short_desc
597
-                    '%s',// VNU_modified
596
+                    '%s', // VNU_short_desc
597
+                    '%s', // VNU_modified
598 598
                     '%s',
599
-                    '%d',// VNU_wp_user
600
-                    '%d',// parent
601
-                    '%d',// VNU_order
602
-                    '%s',// post_type
599
+                    '%d', // VNU_wp_user
600
+                    '%d', // parent
601
+                    '%d', // VNU_order
602
+                    '%s', // post_type
603 603
                 );
604 604
         $success = $wpdb->insert(
605 605
             $wpdb->posts,
606 606
             $insertion_array,
607 607
             $datatypes_array
608 608
         );
609
-        if (! $success) {
609
+        if ( ! $success) {
610 610
             $this->add_error(
611 611
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
612 612
                     $this->_old_table,
@@ -634,13 +634,13 @@  discard block
 block discarded – undo
634 634
         // assume the country is the same as the organization's old settings
635 635
         $country_iso = $this->get_migration_script()->get_default_country_iso();
636 636
         // find the state from the venue, or the organization, or just guess california
637
-        if (! $old_event['state']) {
637
+        if ( ! $old_event['state']) {
638 638
             $old_org_options = get_option('events_organization_settings');
639 639
             $state_name = stripslashes($old_org_options['organization_state']);
640 640
         } else {
641 641
             $state_name = $old_event['state'];
642 642
         }
643
-        if (! $state_name) {
643
+        if ( ! $state_name) {
644 644
             $state_name = 'CA';
645 645
         }
646 646
         // get a state ID with the same name, if possible
@@ -653,39 +653,39 @@  discard block
 block discarded – undo
653 653
         }
654 654
         // now insert into meta table
655 655
         $insertion_array = array(
656
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
657
-            'VNU_address' => stripslashes($old_event['address']),// VNU_address
658
-            'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
659
-            'VNU_city' => stripslashes($old_event['city']),// VNU_city
660
-            'STA_ID' => $state_id,// STA_ID
661
-            'CNT_ISO' => $country_iso,// CNT_ISO
662
-            'VNU_zip' => $old_event['zip'],// VNU_zip
663
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
664
-            'VNU_capacity' => -1,// VNU_capacity
665
-            'VNU_url' => $old_event['venue_url'],// VNU_url
666
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
667
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
668
-            'VNU_google_map_link' => '',// VNU_google_map_link
656
+            'VNU_ID' => $cpt_id, // VNU_ID_fk
657
+            'VNU_address' => stripslashes($old_event['address']), // VNU_address
658
+            'VNU_address2' => stripslashes($old_event['address2']), // VNU_address2
659
+            'VNU_city' => stripslashes($old_event['city']), // VNU_city
660
+            'STA_ID' => $state_id, // STA_ID
661
+            'CNT_ISO' => $country_iso, // CNT_ISO
662
+            'VNU_zip' => $old_event['zip'], // VNU_zip
663
+            'VNU_phone' => $old_event['venue_phone'], // VNU_phone
664
+            'VNU_capacity' => -1, // VNU_capacity
665
+            'VNU_url' => $old_event['venue_url'], // VNU_url
666
+            'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone
667
+            'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url
668
+            'VNU_google_map_link' => '', // VNU_google_map_link
669 669
             'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
670 670
         );
671 671
         $datatypes = array(
672
-            '%d',// VNU_ID_fk
673
-            '%s',// VNU_address
674
-            '%s',// VNU_address2
675
-            '%s',// VNU_city
676
-            '%d',// STA_ID
677
-            '%s',// CNT_ISO
678
-            '%s',// VNU_zip
679
-            '%s',// VNU_phone
680
-            '%d',// VNU_capacity
681
-            '%s',// VNU_url
682
-            '%s',// VNU_virtual_phone
683
-            '%s',// VNU_virtual_url
684
-            '%s',// VNU_google_map_link
685
-            '%d',// VNU_enable_for_gmap
672
+            '%d', // VNU_ID_fk
673
+            '%s', // VNU_address
674
+            '%s', // VNU_address2
675
+            '%s', // VNU_city
676
+            '%d', // STA_ID
677
+            '%s', // CNT_ISO
678
+            '%s', // VNU_zip
679
+            '%s', // VNU_phone
680
+            '%d', // VNU_capacity
681
+            '%s', // VNU_url
682
+            '%s', // VNU_virtual_phone
683
+            '%s', // VNU_virtual_url
684
+            '%s', // VNU_google_map_link
685
+            '%d', // VNU_enable_for_gmap
686 686
         );
687
-        $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
688
-        if (! $success) {
687
+        $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
688
+        if ( ! $success) {
689 689
             $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));
690 690
             return 0;
691 691
         }
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
     private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
703 703
     {
704 704
         global $wpdb;
705
-        if (! $new_event_id) {
705
+        if ( ! $new_event_id) {
706 706
             $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
707 707
             return 0;
708 708
         }
709
-        if (! $new_venue_id) {
709
+        if ( ! $new_venue_id) {
710 710
             $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
711 711
             return 0;
712 712
         }
@@ -716,12 +716,12 @@  discard block
 block discarded – undo
716 716
             'EVV_primary' => true
717 717
         );
718 718
         $datatypes = array(
719
-            '%d',// EVT_ID
720
-            '%d',// VNU_ID
721
-            '%d',// EVT_primary
719
+            '%d', // EVT_ID
720
+            '%d', // VNU_ID
721
+            '%d', // EVT_primary
722 722
         );
723
-        $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
724
-        if (! $success) {
723
+        $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
724
+        if ( ! $success) {
725 725
             $this->add_error(
726 726
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
727 727
                     $this->_old_table,
@@ -781,29 +781,29 @@  discard block
 block discarded – undo
781 781
         $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']);
782 782
         $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']);
783 783
         $cols_n_values = array(
784
-            'EVT_ID' => $new_cpt_id,// EVT_ID
785
-            'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
786
-            'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
787
-            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
788
-            'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
784
+            'EVT_ID' => $new_cpt_id, // EVT_ID
785
+            'DTT_EVT_start' => $start_datetime_utc, // DTT_EVT_start
786
+            'DTT_EVT_end' => $end_datetime_utc, // DTT_EVT_end
787
+            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit
788
+            'DTT_sold' => 0, // note: we will increment this as registrations are added during the migration
789 789
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
790
-            'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
790
+            'DTT_order' => $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist
791 791
             'DTT_parent' => 0,
792 792
             'DTT_deleted' => false
793 793
         );
794 794
         $datatypes = array(
795
-            '%d',// EVT_Id
796
-            '%s',// DTT_EVT_start
797
-            '%s',// DTT_EVT_end
798
-            '%d',// DTT_reg_limit
799
-            '%d',// DTT_sold
795
+            '%d', // EVT_Id
796
+            '%s', // DTT_EVT_start
797
+            '%s', // DTT_EVT_end
798
+            '%d', // DTT_reg_limit
799
+            '%d', // DTT_sold
800 800
 //          '%d',//DTT_is_primary
801
-            '%d',// DTT_order
802
-            '%d',// DTT_parent
803
-            '%d',// DTT_deleted
801
+            '%d', // DTT_order
802
+            '%d', // DTT_parent
803
+            '%d', // DTT_deleted
804 804
         );
805 805
         $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
806
-        if (! $success) {
806
+        if ( ! $success) {
807 807
             $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));
808 808
             return 0;
809 809
         }
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.
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.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -110,8 +110,8 @@  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 116
             if ($option_name == 'surcharge') {
117 117
                 $this->_insert_new_global_surcharge_price($old_org_options);
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
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 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;
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 
299 299
         );
300 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
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 309
         );
310
-        $price_table = $wpdb->prefix . "esp_price";
310
+        $price_table = $wpdb->prefix."esp_price";
311 311
         $success = $wpdb->insert($price_table, $cols_n_values, $datatypes);
312
-        if (! $success) {
312
+        if ( ! $success) {
313 313
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion(
314 314
                 'org_options',
315 315
                 array(
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
       'payment_message',
340 340
       'message',
341 341
       'default_payment_status',
342
-      'surcharge',// unused?
343
-      'country_id',// unused?
342
+      'surcharge', // unused?
343
+      'country_id', // unused?
344 344
       'organization_country',
345 345
 //    'currency_symbol',
346 346
       'expire_on_registration_end',
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
       'show_pending_payment_options',
353 353
       'show_reg_footer',
354 354
       'skip_confirmation_page',
355
-      'allow_mer_discounts',// no equiv
356
-      'allow_mer_vouchers',// no equiv
355
+      'allow_mer_discounts', // no equiv
356
+      'allow_mer_vouchers', // no equiv
357 357
       'display_short_description_in_event_list',
358 358
       'display_description_on_multi_reg_page',
359 359
       'display_address_in_event_list',
360 360
       'display_address_in_regform',
361
-      'use_custom_post_types',// no equiv
361
+      'use_custom_post_types', // no equiv
362 362
       'display_ical_download',
363 363
       'display_featured_image',
364 364
       'themeroller',
@@ -377,11 +377,11 @@  discard block
 block discarded – undo
377 377
       'espresso_dashboard_widget',
378 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
380
+      'use_personnel_manager', // no equiv
381 381
       'use_event_timezones',
382 382
       'full_logging',
383
-      'surcharge_type',// unused
384
-      'surcharge_text',// unused
383
+      'surcharge_type', // unused
384
+      'surcharge_text', // unused
385 385
       'affiliate_id',
386 386
       'site_license_key',
387 387
     );
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   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -105,15 +105,15 @@  discard block
 block discarded – undo
105 105
     {
106 106
         global $wpdb;
107 107
         $this->_pretty_name = __("Prices", "event_espresso");
108
-        $this->_old_table = $wpdb->prefix . "events_prices";
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
-        $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";
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 117
         parent::__construct();
118 118
     }
119 119
     protected function _migrate_old_row($old_row)
@@ -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
         }
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
         } else {// percent surcharge
299 299
             $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100);
300 300
         }
301
-        $start_date = $event_row['registration_start'] . " " . $this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
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']);
303
-        $end_date = $event_row['registration_end'] . " " . $this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
303
+        $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304 304
         $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305 305
         $cols_n_values = array(
306 306
             'TTM_ID' => 0,
@@ -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;
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
     private function _get_event_row($event_id)
414 414
     {
415 415
         global $wpdb;
416
-        $old_event_table = $wpdb->prefix . "events_detail";
416
+        $old_event_table = $wpdb->prefix."events_detail";
417 417
         return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418 418
     }
419 419
     /**
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
     private function _get_datetime_ids_for_old_event_id($old_event_id)
435 435
     {
436 436
         global $wpdb;
437
-        $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_id, $wpdb->posts);
437
+        $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438 438
         $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439 439
         return $datetime_ids;
440 440
     }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_question_group_question.dmsstage.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@
 block discarded – undo
130 130
      * being address info, and 0 being neither)
131 131
      * @global type $wpdb
132 132
      * @param type $new_question_group_id
133
-     * @return boolean
133
+     * @return integer
134 134
      */
135 135
     private function _is_system_question_group($new_question_group_id)
136 136
     {
Please login to merge, or discard this patch.
Indentation   +106 added lines, -108 removed lines patch added patch discarded remove patch
@@ -12,8 +12,6 @@  discard block
 block discarded – undo
12 12
   KEY `group_id` (`group_id`),
13 13
   KEY `question_id` (`question_id`)
14 14
 ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8$$
15
-
16
-
17 15
  * 4.1 question group question model's tables and fields:
18 16
  $this->_tables = array(
19 17
             'Question_Group_Question'=>new EE_Primary_Table('esp_question_group_question','QGQ_ID')
@@ -29,114 +27,114 @@  discard block
 block discarded – undo
29 27
  */
30 28
 class EE_DMS_4_1_0_question_group_question extends EE_Data_Migration_Script_Stage
31 29
 {
32
-    private $_old_table;
33
-    private $_new_table;
34
-    public function _migration_step($num_items = 50)
35
-    {
30
+	private $_old_table;
31
+	private $_new_table;
32
+	public function _migration_step($num_items = 50)
33
+	{
36 34
 
37
-        global $wpdb;
38
-        $start_at_record = $this->count_records_migrated();
39
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
40
-        $items_actually_migrated = 0;
41
-        foreach ($rows as $question_group_question) {
42
-            $this->_insert_new_question_group_question($question_group_question);
43
-            $items_actually_migrated++;
44
-        }
45
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
46
-            $this->set_completed();
47
-        }
48
-        return $items_actually_migrated;
49
-    }
50
-    public function _count_records_to_migrate()
51
-    {
52
-        global $wpdb;
53
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
54
-        return $count;
55
-    }
56
-    public function __construct()
57
-    {
58
-        global $wpdb;
59
-        $this->_old_table = $wpdb->prefix . "events_qst_group_rel";
60
-        $this->_new_table = $wpdb->prefix . "esp_question_group_question";
61
-        $this->_pretty_name = __("Question Group to Question Relations", "event_espresso");
62
-        parent::__construct();
63
-    }
35
+		global $wpdb;
36
+		$start_at_record = $this->count_records_migrated();
37
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
38
+		$items_actually_migrated = 0;
39
+		foreach ($rows as $question_group_question) {
40
+			$this->_insert_new_question_group_question($question_group_question);
41
+			$items_actually_migrated++;
42
+		}
43
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
44
+			$this->set_completed();
45
+		}
46
+		return $items_actually_migrated;
47
+	}
48
+	public function _count_records_to_migrate()
49
+	{
50
+		global $wpdb;
51
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
52
+		return $count;
53
+	}
54
+	public function __construct()
55
+	{
56
+		global $wpdb;
57
+		$this->_old_table = $wpdb->prefix . "events_qst_group_rel";
58
+		$this->_new_table = $wpdb->prefix . "esp_question_group_question";
59
+		$this->_pretty_name = __("Question Group to Question Relations", "event_espresso");
60
+		parent::__construct();
61
+	}
64 62
 
65
-    /**
66
-     * Attempts to insert a new question group inthe new format given an old one
67
-     * @global type $wpdb
68
-     * @param array $old_question_group_question
69
-     * @return int
70
-     */
71
-    private function _insert_new_question_group_question($old_question_group_question)
72
-    {
73
-        global $wpdb;
74
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question");
75
-        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group");
76
-        if (! $new_question_id) {
77
-            $this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
78
-            return 0;
79
-        }
80
-        if (! $new_question_group_id) {
81
-            $this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
82
-            return 0;
83
-        }
84
-        // if it's a system question, it needs to be in the right system group. otherwise no dice!
85
-        if (
86
-            ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
87
-                ||
88
-                ! $this->_is_system_question_for_question_group($new_question_id)
89
-        ) {
90
-            $cols_n_values = array(
91
-                'QSG_ID' => $new_question_group_id,
92
-                'QST_ID' => $new_question_id
93
-            );
94
-            $datatypes = array(
95
-                '%d',// QSG_ID
96
-                '%d',// QST_ID
97
-            );
98
-            $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
99
-            if (! $success) {
100
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
101
-                return 0;
102
-            }
103
-            return $wpdb->insert_id;
104
-        } else {
105
-            return false;
106
-        }
107
-    }
63
+	/**
64
+	 * Attempts to insert a new question group inthe new format given an old one
65
+	 * @global type $wpdb
66
+	 * @param array $old_question_group_question
67
+	 * @return int
68
+	 */
69
+	private function _insert_new_question_group_question($old_question_group_question)
70
+	{
71
+		global $wpdb;
72
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question");
73
+		$new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group");
74
+		if (! $new_question_id) {
75
+			$this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
76
+			return 0;
77
+		}
78
+		if (! $new_question_group_id) {
79
+			$this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
80
+			return 0;
81
+		}
82
+		// if it's a system question, it needs to be in the right system group. otherwise no dice!
83
+		if (
84
+			($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
85
+				||
86
+				! $this->_is_system_question_for_question_group($new_question_id)
87
+		) {
88
+			$cols_n_values = array(
89
+				'QSG_ID' => $new_question_group_id,
90
+				'QST_ID' => $new_question_id
91
+			);
92
+			$datatypes = array(
93
+				'%d',// QSG_ID
94
+				'%d',// QST_ID
95
+			);
96
+			$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
97
+			if (! $success) {
98
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
99
+				return 0;
100
+			}
101
+			return $wpdb->insert_id;
102
+		} else {
103
+			return false;
104
+		}
105
+	}
108 106
 
109
-    /**
110
-     * If this question is a system question, returns the QSG_system number that
111
-     * indicates the question group its permitted in.
112
-     * @global type $wpdb
113
-     * @param type $new_question_id
114
-     * @return int
115
-     */
116
-    private function _is_system_question_for_question_group($new_question_id)
117
-    {
118
-        global $wpdb;
119
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id));
120
-        if (in_array($system_id, array('fname','lname','email'))) {
121
-            return 1;
122
-        } elseif ($system_id != '' && $system_id) {
123
-            return 2;
124
-        } else {
125
-            return 0;
126
-        }
127
-    }
107
+	/**
108
+	 * If this question is a system question, returns the QSG_system number that
109
+	 * indicates the question group its permitted in.
110
+	 * @global type $wpdb
111
+	 * @param type $new_question_id
112
+	 * @return int
113
+	 */
114
+	private function _is_system_question_for_question_group($new_question_id)
115
+	{
116
+		global $wpdb;
117
+		$system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id));
118
+		if (in_array($system_id, array('fname','lname','email'))) {
119
+			return 1;
120
+		} elseif ($system_id != '' && $system_id) {
121
+			return 2;
122
+		} else {
123
+			return 0;
124
+		}
125
+	}
128 126
 
129
-    /**
130
-     * Returns the questino group's QSG_system value (1 meaning personal info, 2
131
-     * being address info, and 0 being neither)
132
-     * @global type $wpdb
133
-     * @param type $new_question_group_id
134
-     * @return boolean
135
-     */
136
-    private function _is_system_question_group($new_question_group_id)
137
-    {
138
-        global $wpdb;
139
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
140
-        return intval($system_id);
141
-    }
127
+	/**
128
+	 * Returns the questino group's QSG_system value (1 meaning personal info, 2
129
+	 * being address info, and 0 being neither)
130
+	 * @global type $wpdb
131
+	 * @param type $new_question_group_id
132
+	 * @return boolean
133
+	 */
134
+	private function _is_system_question_group($new_question_group_id)
135
+	{
136
+		global $wpdb;
137
+		$system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
138
+		return intval($system_id);
139
+	}
142 140
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
     public function _count_records_to_migrate()
51 51
     {
52 52
         global $wpdb;
53
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
53
+        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
54 54
         return $count;
55 55
     }
56 56
     public function __construct()
57 57
     {
58 58
         global $wpdb;
59
-        $this->_old_table = $wpdb->prefix . "events_qst_group_rel";
60
-        $this->_new_table = $wpdb->prefix . "esp_question_group_question";
59
+        $this->_old_table = $wpdb->prefix."events_qst_group_rel";
60
+        $this->_new_table = $wpdb->prefix."esp_question_group_question";
61 61
         $this->_pretty_name = __("Question Group to Question Relations", "event_espresso");
62 62
         parent::__construct();
63 63
     }
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
     private function _insert_new_question_group_question($old_question_group_question)
72 72
     {
73 73
         global $wpdb;
74
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question");
75
-        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group");
76
-        if (! $new_question_id) {
74
+        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question");
75
+        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group");
76
+        if ( ! $new_question_id) {
77 77
             $this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
78 78
             return 0;
79 79
         }
80
-        if (! $new_question_group_id) {
80
+        if ( ! $new_question_group_id) {
81 81
             $this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
82 82
             return 0;
83 83
         }
84 84
         // if it's a system question, it needs to be in the right system group. otherwise no dice!
85 85
         if (
86
-            ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
86
+            ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id))
87 87
                 ||
88 88
                 ! $this->_is_system_question_for_question_group($new_question_id)
89 89
         ) {
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
                 'QST_ID' => $new_question_id
93 93
             );
94 94
             $datatypes = array(
95
-                '%d',// QSG_ID
96
-                '%d',// QST_ID
95
+                '%d', // QSG_ID
96
+                '%d', // QST_ID
97 97
             );
98 98
             $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
99
-            if (! $success) {
99
+            if ( ! $success) {
100 100
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
101 101
                 return 0;
102 102
             }
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
     private function _is_system_question_for_question_group($new_question_id)
117 117
     {
118 118
         global $wpdb;
119
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id));
120
-        if (in_array($system_id, array('fname','lname','email'))) {
119
+        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id));
120
+        if (in_array($system_id, array('fname', 'lname', 'email'))) {
121 121
             return 1;
122 122
         } elseif ($system_id != '' && $system_id) {
123 123
             return 2;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     private function _is_system_question_group($new_question_group_id)
137 137
     {
138 138
         global $wpdb;
139
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
139
+        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
140 140
         return intval($system_id);
141 141
     }
142 142
 }
Please login to merge, or discard this patch.